diff --git a/apis/python/setup.py b/apis/python/setup.py index ba43f201bf..1f9d314462 100644 --- a/apis/python/setup.py +++ b/apis/python/setup.py @@ -325,7 +325,7 @@ def run(self): library_dirs=LIB_DIRS, libraries=["tiledbsoma"] + (["tiledb"] if os.name == "nt" else []), extra_link_args=CXX_FLAGS, - extra_compile_args=["-std=c++20" if os.name != "nt" else "/std:c++20"] + extra_compile_args=["-std=c++17" if os.name != "nt" else "/std:c++17"] + CXX_FLAGS, language="c++", ) diff --git a/apis/python/src/tiledbsoma/fastercsx.cc b/apis/python/src/tiledbsoma/fastercsx.cc index 767210bf92..d3add6613e 100644 --- a/apis/python/src/tiledbsoma/fastercsx.cc +++ b/apis/python/src/tiledbsoma/fastercsx.cc @@ -36,7 +36,6 @@ /* #define FASTERCSX__DEBUGGING_HOOKS 1 */ #include -#include #include "common.h" namespace libtiledbsomacpp { @@ -76,36 +75,36 @@ std::vector to_vector_(const py::tuple& tup) { */ template -std::span make_span_(py::array arr) { +tcb::span make_span_(py::array arr) { assert(py::isinstance>(arr)); - return std::span(arr.unchecked().data(0), arr.size()); + return tcb::span(arr.unchecked().data(0), arr.size()); } template -std::span make_mutable_span_(py::array arr) { +tcb::span make_mutable_span_(py::array arr) { assert(py::isinstance>(arr)); - return std::span( + return tcb::span( arr.mutable_unchecked().mutable_data(0), arr.size()); } template -std::span make_casted_span_(py::array arr) { +tcb::span make_casted_span_(py::array arr) { static_assert(sizeof(T) == sizeof(R)); assert(py::isinstance>(arr)); std::remove_cv_t* p = (std::remove_cv_t*)arr .unchecked, 1>() .data(0); - return std::span(reinterpret_cast(p), arr.size()); + return tcb::span(reinterpret_cast(p), arr.size()); } template -std::span make_mutable_casted_span_(py::array arr) { +tcb::span make_mutable_casted_span_(py::array arr) { static_assert(sizeof(T) == sizeof(R)); assert(py::isinstance>(arr)); std::remove_cv_t* p = (std::remove_cv_t*)arr .mutable_unchecked, 1>() .data(0); - return std::span(reinterpret_cast(p), arr.size()); + return tcb::span(reinterpret_cast(p), arr.size()); } /* @@ -351,8 +350,8 @@ void compress_coo( typename decltype(csx_minor_index_type)::type; using VALUE = typename decltype(value_type)::type; - std::vector> Ai_views, Aj_views; - std::vector const>> Ad_views; + std::vector> Ai_views, Aj_views; + std::vector const>> Ad_views; for (size_t i = 0; i < Ai.size(); ++i) { Ai_views.push_back(make_span_(Ai[i])); Aj_views.push_back(make_span_(Aj[i])); @@ -552,7 +551,7 @@ void count_rows( using CSX_MAJOR_INDEX = typename decltype(csx_major_index_type)::type; - std::vector> Ai_views, Aj_views; + std::vector> Ai_views, Aj_views; for (size_t i = 0; i < Ai.size(); ++i) { Ai_views.push_back(make_span_(Ai[i])); } diff --git a/apis/r/configure b/apis/r/configure index 1948835b94..7cc96e400f 100755 --- a/apis/r/configure +++ b/apis/r/configure @@ -18,11 +18,11 @@ if [ $? -eq 0 ]; then pkgcflags=`pkg-config --cflags tiledb tiledbsoma` pkglibs=`pkg-config --libs tiledb tiledbsoma` - ## substitute them in (leaving @tiledb_rpath@ and @cxx20_macos@ alone for now) + ## substitute them in (leaving @tiledb_rpath@ and @cxx17_macos@ alone for now) sed -e "s|@tiledb_include@|$pkgcflags |" \ -e "s|@tiledb_libs@|$pkglibs|" \ -e "s|@tiledb_rpath@||" \ - -e "s|@cxx20_macos@||" \ + -e "s|@cxx17_macos@||" \ src/Makevars.in > src/Makevars echo "** updated src/Makevars for system library via pkg-config" @@ -54,10 +54,10 @@ tools/build_libtiledbsoma.sh pkgincl="-I../inst/tiledb/include -I../inst/tiledbsoma/include -I../inst/tiledbsoma/include/tiledbsoma" pkglibs="-ltiledb -L../inst/tiledb/lib -ltiledbsoma -L../inst/tiledbsoma/lib" rpath="-Wl,-rpath,'\$\$ORIGIN/../tiledb/lib' -Wl,-rpath,'\$\$ORIGIN/../tiledbsoma/lib'" -macosver=`${R_HOME}/bin/Rscript -e 'if (Sys.info()["sysname"] == "Darwin") cat("-mmacosx-version-min=13.3") else cat("")'` +macosver=`${R_HOME}/bin/Rscript -e 'if (Sys.info()["sysname"] == "Darwin") cat("-mmacosx-version-min=11.0") else cat("")'` sed -e "s|@tiledb_include@|$pkgincl |" \ -e "s|@tiledb_libs@|$pkglibs|" \ -e "s|@tiledb_rpath@|$rpath|" \ - -e "s|@cxx20_macos@|$macosver|" \ + -e "s|@cxx17_macos@|$macosver|" \ src/Makevars.in > src/Makevars diff --git a/apis/r/inst/AUTHORS b/apis/r/inst/AUTHORS index 0bb862d417..0022a95185 100644 --- a/apis/r/inst/AUTHORS +++ b/apis/r/inst/AUTHORS @@ -11,6 +11,16 @@ The package also includes code written by other contributors as detailed below: +-- libtiledbsoma/src/external/include/span/span.hpp --------------------------------------------- +The span.hpp implements std::span, part of C++20, for use by C++11 or later. It +was written by Tristan Brindle and is released at https://github.com/tcbrindle/span + +// Copyright Tristan Brindle 2018. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file ../../LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + + -- libtiledbsoma/src/external/{src,include}/thread_pool/ ---------------------------------------- The thread_pool implementation is from TileDB, Inc., and part of TileDB Embedded released at https://github.com/tiledb-inc/tiledb diff --git a/apis/r/src/Makevars.in b/apis/r/src/Makevars.in index 991205747d..cf0130f377 100644 --- a/apis/r/src/Makevars.in +++ b/apis/r/src/Makevars.in @@ -1,10 +1,10 @@ -CXX_STD = CXX20 +CXX_STD = CXX17 ## We need the TileDB Headers, and for macOS aka Darwin need to set minimum version 10.14 for macOS -PKG_CPPFLAGS = -I. -I../inst/include/ @tiledb_include@ @cxx20_macos@ -D SPDLOG_USE_STD_FORMAT +PKG_CPPFLAGS = -I. -I../inst/include/ @tiledb_include@ @cxx17_macos@ ## We also need the TileDB library -PKG_LIBS = @cxx20_macos@ @tiledb_libs@ @tiledb_rpath@ +PKG_LIBS = @cxx17_macos@ @tiledb_libs@ @tiledb_rpath@ all: $(SHLIB) # On macOS aka Darwin we call install_name_tool diff --git a/libtiledbsoma/CMakeLists.txt b/libtiledbsoma/CMakeLists.txt index 915449f756..8ac2acb30a 100644 --- a/libtiledbsoma/CMakeLists.txt +++ b/libtiledbsoma/CMakeLists.txt @@ -82,7 +82,7 @@ if(CCACHE_FOUND) endif() # Set C++20 as required standard for all C++ targets (C++17 minimum is required to use the TileDB C++ API). -set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) # Don't use GNU extensions @@ -218,7 +218,7 @@ if(MSVC) ) else() - set(TILEDBSOMA_COMPILE_OPTIONS -Wall -Wextra -DSPDLOG_USE_STD_FORMAT) + set(TILEDBSOMA_COMPILE_OPTIONS -Wall -Wextra) if(${TILEDBSOMA_ENABLE_WERROR}) set(TILEDBSOMA_WERROR_OPTION -Werror) diff --git a/libtiledbsoma/README.md b/libtiledbsoma/README.md index bc23d784b3..648a1f623f 100644 --- a/libtiledbsoma/README.md +++ b/libtiledbsoma/README.md @@ -2,7 +2,7 @@ ## System Dependencies -* C++20 compiler +* C++17 compiler * Python 3.9+ Run these commands to setup a fresh Ubuntu 22.04 instance (tested on x86 and Arm): diff --git a/libtiledbsoma/src/CMakeLists.txt b/libtiledbsoma/src/CMakeLists.txt index c896a8b018..a6d233df3a 100644 --- a/libtiledbsoma/src/CMakeLists.txt +++ b/libtiledbsoma/src/CMakeLists.txt @@ -242,6 +242,11 @@ install(FILES DESTINATION "include/tiledbsoma/utils" ) +install(FILES + ${CMAKE_CURRENT_SOURCE_DIR}/external/include/span/span.hpp + DESTINATION "include/tiledbsoma/soma/span" +) + install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/external/include/nanoarrow/nanoarrow.h ${CMAKE_CURRENT_SOURCE_DIR}/external/include/nanoarrow/nanoarrow.hpp diff --git a/libtiledbsoma/src/cli/cli.cc b/libtiledbsoma/src/cli/cli.cc index 96f6fe26de..4f698ed3a8 100644 --- a/libtiledbsoma/src/cli/cli.cc +++ b/libtiledbsoma/src/cli/cli.cc @@ -30,7 +30,6 @@ * This file is currently a sandbox for C++ API experiments */ -#include #include "soma/enums.h" #include "soma/soma_array.h" #include "utils/arrow_adapter.h" @@ -78,8 +77,8 @@ void test_sdf(const std::string& uri) { total_num_rows += (*batch)->num_rows(); } - LOG_INFO(std::format("X/data rows = {}", total_num_rows)); - LOG_INFO(std::format(" batches = {}", batches)); + LOG_INFO(fmt::format("X/data rows = {}", total_num_rows)); + LOG_INFO(fmt::format(" batches = {}", batches)); } namespace tdbs = tiledbsoma; @@ -90,10 +89,10 @@ void test_arrow(const std::string& uri) { // Getting next batch: std::optional> auto obs_data = obs->read_next(); if (!obs->results_complete()) { - tdbs::LOG_WARN(std::format("Read of '{}' incomplete", uri)); + tdbs::LOG_WARN(fmt::format("Read of '{}' incomplete", uri)); exit(-1); } - tdbs::LOG_INFO(std::format( + tdbs::LOG_INFO(fmt::format( "Read complete with {} obs and {} cols", obs_data->get()->num_rows(), obs_data->get()->names().size())); @@ -102,7 +101,7 @@ void test_arrow(const std::string& uri) { auto buf = obs_data->get()->at(nm); auto pp = tdbs::ArrowAdapter::to_arrow(buf); ArrowSchema* schema = pp.second.get(); - tdbs::LOG_INFO(std::format( + tdbs::LOG_INFO(fmt::format( "Accessing '{}', retrieved '{}', n_children {}", nm, schema->name, diff --git a/libtiledbsoma/src/external/include/span/span.hpp b/libtiledbsoma/src/external/include/span/span.hpp index e69de29bb2..58fabe326b 100644 --- a/libtiledbsoma/src/external/include/span/span.hpp +++ b/libtiledbsoma/src/external/include/span/span.hpp @@ -0,0 +1,618 @@ + +/* +This is an implementation of C++20's std::span +http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/n4820.pdf +*/ + +// Copyright Tristan Brindle 2018. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file ../../LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +#ifndef TCB_SPAN_HPP_INCLUDED +#define TCB_SPAN_HPP_INCLUDED + +#include +#include +#include +#include + +#ifndef TCB_SPAN_NO_EXCEPTIONS +// Attempt to discover whether we're being compiled with exception support +#if !(defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) +#define TCB_SPAN_NO_EXCEPTIONS +#endif +#endif + +#ifndef TCB_SPAN_NO_EXCEPTIONS +#include +#include +#endif + +// Various feature test macros + +#ifndef TCB_SPAN_NAMESPACE_NAME +#define TCB_SPAN_NAMESPACE_NAME tcb +#endif + +#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) +#define TCB_SPAN_HAVE_CPP17 +#endif + +#if __cplusplus >= 201402L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L) +#define TCB_SPAN_HAVE_CPP14 +#endif + +namespace TCB_SPAN_NAMESPACE_NAME { + +// Establish default contract checking behavior +#if !defined(TCB_SPAN_THROW_ON_CONTRACT_VIOLATION) && \ + !defined(TCB_SPAN_TERMINATE_ON_CONTRACT_VIOLATION) && \ + !defined(TCB_SPAN_NO_CONTRACT_CHECKING) +#if defined(NDEBUG) || !defined(TCB_SPAN_HAVE_CPP14) +#define TCB_SPAN_NO_CONTRACT_CHECKING +#else +#define TCB_SPAN_TERMINATE_ON_CONTRACT_VIOLATION +#endif +#endif + +#if defined(TCB_SPAN_THROW_ON_CONTRACT_VIOLATION) +struct contract_violation_error : std::logic_error { + explicit contract_violation_error(const char* msg) + : std::logic_error(msg) { + } +}; + +inline void contract_violation(const char* msg) { + throw contract_violation_error(msg); +} + +#elif defined(TCB_SPAN_TERMINATE_ON_CONTRACT_VIOLATION) +[[noreturn]] inline void contract_violation(const char* /*unused*/) { + std::terminate(); +} +#endif + +#if !defined(TCB_SPAN_NO_CONTRACT_CHECKING) +#define TCB_SPAN_STRINGIFY(cond) #cond +#define TCB_SPAN_EXPECT(cond) \ + cond ? (void)0 : contract_violation("Expected " TCB_SPAN_STRINGIFY(cond)) +#else +#define TCB_SPAN_EXPECT(cond) +#endif + +#if defined(TCB_SPAN_HAVE_CPP17) || defined(__cpp_inline_variables) +#define TCB_SPAN_INLINE_VAR inline +#else +#define TCB_SPAN_INLINE_VAR +#endif + +#if defined(TCB_SPAN_HAVE_CPP14) || \ + (defined(__cpp_constexpr) && __cpp_constexpr >= 201304) +#define TCB_SPAN_HAVE_CPP14_CONSTEXPR +#endif + +#if defined(TCB_SPAN_HAVE_CPP14_CONSTEXPR) +#define TCB_SPAN_CONSTEXPR14 constexpr +#else +#define TCB_SPAN_CONSTEXPR14 +#endif + +#if defined(TCB_SPAN_HAVE_CPP14_CONSTEXPR) && \ + (!defined(_MSC_VER) || _MSC_VER > 1900) +#define TCB_SPAN_CONSTEXPR_ASSIGN constexpr +#else +#define TCB_SPAN_CONSTEXPR_ASSIGN +#endif + +#if defined(TCB_SPAN_NO_CONTRACT_CHECKING) +#define TCB_SPAN_CONSTEXPR11 constexpr +#else +#define TCB_SPAN_CONSTEXPR11 TCB_SPAN_CONSTEXPR14 +#endif + +#if defined(TCB_SPAN_HAVE_CPP17) || defined(__cpp_deduction_guides) +#define TCB_SPAN_HAVE_DEDUCTION_GUIDES +#endif + +#if defined(TCB_SPAN_HAVE_CPP17) || defined(__cpp_lib_byte) +#define TCB_SPAN_HAVE_STD_BYTE +#endif + +#if defined(TCB_SPAN_HAVE_CPP17) || defined(__cpp_lib_array_constexpr) +#define TCB_SPAN_HAVE_CONSTEXPR_STD_ARRAY_ETC +#endif + +#if defined(TCB_SPAN_HAVE_CONSTEXPR_STD_ARRAY_ETC) +#define TCB_SPAN_ARRAY_CONSTEXPR constexpr +#else +#define TCB_SPAN_ARRAY_CONSTEXPR +#endif + +#ifdef TCB_SPAN_HAVE_STD_BYTE +using byte = std::byte; +#else +using byte = unsigned char; +#endif + +#if defined(TCB_SPAN_HAVE_CPP17) +#define TCB_SPAN_NODISCARD [[nodiscard]] +#else +#define TCB_SPAN_NODISCARD +#endif + +TCB_SPAN_INLINE_VAR constexpr std::size_t dynamic_extent = SIZE_MAX; + +template +class span; + +namespace detail { + +template +struct span_storage { + constexpr span_storage() noexcept = default; + + constexpr span_storage(E* p_ptr, std::size_t /*unused*/) noexcept + : ptr(p_ptr) { + } + + E* ptr = nullptr; + static constexpr std::size_t size = S; +}; + +template +struct span_storage { + constexpr span_storage() noexcept = default; + + constexpr span_storage(E* p_ptr, std::size_t p_size) noexcept + : ptr(p_ptr) + , size(p_size) { + } + + E* ptr = nullptr; + std::size_t size = 0; +}; + +// Reimplementation of C++17 std::size() and std::data() +#if defined(TCB_SPAN_HAVE_CPP17) || \ + defined(__cpp_lib_nonmember_container_access) +using std::data; +using std::size; +#else +template +constexpr auto size(const C& c) -> decltype(c.size()) { + return c.size(); +} + +template +constexpr std::size_t size(const T (&)[N]) noexcept { + return N; +} + +template +constexpr auto data(C& c) -> decltype(c.data()) { + return c.data(); +} + +template +constexpr auto data(const C& c) -> decltype(c.data()) { + return c.data(); +} + +template +constexpr T* data(T (&array)[N]) noexcept { + return array; +} + +template +constexpr const E* data(std::initializer_list il) noexcept { + return il.begin(); +} +#endif // TCB_SPAN_HAVE_CPP17 + +#if defined(TCB_SPAN_HAVE_CPP17) || defined(__cpp_lib_void_t) +using std::void_t; +#else +template +using void_t = void; +#endif + +template +using uncvref_t = + typename std::remove_cv::type>::type; + +template +struct is_span : std::false_type {}; + +template +struct is_span> : std::true_type {}; + +template +struct is_std_array : std::false_type {}; + +template +struct is_std_array> : std::true_type {}; + +template +struct has_size_and_data : std::false_type {}; + +template +struct has_size_and_data< + T, + void_t< + decltype(detail::size(std::declval())), + decltype(detail::data(std::declval()))>> : std::true_type {}; + +template > +struct is_container { + static constexpr bool value = !is_span::value && !is_std_array::value && + !std::is_array::value && + has_size_and_data::value; +}; + +template +using remove_pointer_t = typename std::remove_pointer::type; + +template +struct is_container_element_type_compatible : std::false_type {}; + +template +struct is_container_element_type_compatible< + T, + E, + typename std::enable_if< + !std::is_same< + typename std::remove_cv()))>::type, + void>::value && + std::is_convertible< + remove_pointer_t()))> (*)[], + E (*)[]>::value>::type> : std::true_type {}; + +template +struct is_complete : std::false_type {}; + +template +struct is_complete : std::true_type {}; + +} // namespace detail + +template +class span { + static_assert( + std::is_object::value, + "A span's ElementType must be an object type (not a " + "reference type or void)"); + static_assert( + detail::is_complete::value, + "A span's ElementType must be a complete type (not a forward " + "declaration)"); + static_assert( + !std::is_abstract::value, + "A span's ElementType cannot be an abstract class type"); + + using storage_type = detail::span_storage; + + public: + // constants and types + using element_type = ElementType; + using value_type = typename std::remove_cv::type; + using size_type = std::size_t; + using difference_type = std::ptrdiff_t; + using pointer = element_type*; + using const_pointer = const element_type*; + using reference = element_type&; + using const_reference = const element_type&; + using iterator = pointer; + using reverse_iterator = std::reverse_iterator; + + static constexpr size_type extent = Extent; + + // [span.cons], span constructors, copy, assignment, and destructor + template < + std::size_t E = Extent, + typename std::enable_if<(E == dynamic_extent || E <= 0), int>::type = 0> + constexpr span() noexcept { + } + + TCB_SPAN_CONSTEXPR11 span(pointer ptr, size_type count) + : storage_(ptr, count) { + TCB_SPAN_EXPECT(extent == dynamic_extent || count == extent); + } + + TCB_SPAN_CONSTEXPR11 span(pointer first_elem, pointer last_elem) + : storage_(first_elem, last_elem - first_elem) { + TCB_SPAN_EXPECT( + extent == dynamic_extent || + last_elem - first_elem == static_cast(extent)); + } + + template < + std::size_t N, + std::size_t E = Extent, + typename std::enable_if< + (E == dynamic_extent || N == E) && + detail::is_container_element_type_compatible< + element_type (&)[N], + ElementType>::value, + int>::type = 0> + constexpr span(element_type (&arr)[N]) noexcept + : storage_(arr, N) { + } + + template < + std::size_t N, + std::size_t E = Extent, + typename std::enable_if< + (E == dynamic_extent || N == E) && + detail::is_container_element_type_compatible< + std::array&, + ElementType>::value, + int>::type = 0> + TCB_SPAN_ARRAY_CONSTEXPR span(std::array& arr) noexcept + : storage_(arr.data(), N) { + } + + template < + std::size_t N, + std::size_t E = Extent, + typename std::enable_if< + (E == dynamic_extent || N == E) && + detail::is_container_element_type_compatible< + const std::array&, + ElementType>::value, + int>::type = 0> + TCB_SPAN_ARRAY_CONSTEXPR span(const std::array& arr) noexcept + : storage_(arr.data(), N) { + } + + template < + typename Container, + std::size_t E = Extent, + typename std::enable_if< + E == dynamic_extent && detail::is_container::value && + detail::is_container_element_type_compatible< + Container&, + ElementType>::value, + int>::type = 0> + constexpr span(Container& cont) + : storage_(detail::data(cont), detail::size(cont)) { + } + + template < + typename Container, + std::size_t E = Extent, + typename std::enable_if< + E == dynamic_extent && detail::is_container::value && + detail::is_container_element_type_compatible< + const Container&, + ElementType>::value, + int>::type = 0> + constexpr span(const Container& cont) + : storage_(detail::data(cont), detail::size(cont)) { + } + + constexpr span(const span& other) noexcept = default; + + template < + typename OtherElementType, + std::size_t OtherExtent, + typename std::enable_if< + (Extent == OtherExtent || Extent == dynamic_extent) && + std::is_convertible:: + value, + int>::type = 0> + constexpr span(const span& other) noexcept + : storage_(other.data(), other.size()) { + } + + ~span() noexcept = default; + + TCB_SPAN_CONSTEXPR_ASSIGN span& operator=(const span& other) noexcept = + default; + + // [span.sub], span subviews + template + TCB_SPAN_CONSTEXPR11 span first() const { + TCB_SPAN_EXPECT(Count <= size()); + return {data(), Count}; + } + + template + TCB_SPAN_CONSTEXPR11 span last() const { + TCB_SPAN_EXPECT(Count <= size()); + return {data() + (size() - Count), Count}; + } + + template + using subspan_return_t = span< + ElementType, + Count != dynamic_extent ? + Count : + (Extent != dynamic_extent ? Extent - Offset : dynamic_extent)>; + + template + TCB_SPAN_CONSTEXPR11 subspan_return_t subspan() const { + TCB_SPAN_EXPECT( + Offset <= size() && + (Count == dynamic_extent || Offset + Count <= size())); + return {data() + Offset, Count != dynamic_extent ? Count : size() - Offset}; + } + + TCB_SPAN_CONSTEXPR11 span first( + size_type count) const { + TCB_SPAN_EXPECT(count <= size()); + return {data(), count}; + } + + TCB_SPAN_CONSTEXPR11 span last( + size_type count) const { + TCB_SPAN_EXPECT(count <= size()); + return {data() + (size() - count), count}; + } + + TCB_SPAN_CONSTEXPR11 span subspan( + size_type offset, size_type count = dynamic_extent) const { + TCB_SPAN_EXPECT( + offset <= size() && + (count == dynamic_extent || offset + count <= size())); + return {data() + offset, count == dynamic_extent ? size() - offset : count}; + } + + // [span.obs], span observers + constexpr size_type size() const noexcept { + return storage_.size; + } + + constexpr size_type size_bytes() const noexcept { + return size() * sizeof(element_type); + } + + TCB_SPAN_NODISCARD constexpr bool empty() const noexcept { + return size() == 0; + } + + // [span.elem], span element access + TCB_SPAN_CONSTEXPR11 reference operator[](size_type idx) const { + TCB_SPAN_EXPECT(idx < size()); + return *(data() + idx); + } + + TCB_SPAN_CONSTEXPR11 reference front() const { + TCB_SPAN_EXPECT(!empty()); + return *data(); + } + + TCB_SPAN_CONSTEXPR11 reference back() const { + TCB_SPAN_EXPECT(!empty()); + return *(data() + (size() - 1)); + } + + constexpr pointer data() const noexcept { + return storage_.ptr; + } + + // [span.iterators], span iterator support + constexpr iterator begin() const noexcept { + return data(); + } + + constexpr iterator end() const noexcept { + return data() + size(); + } + + TCB_SPAN_ARRAY_CONSTEXPR reverse_iterator rbegin() const noexcept { + return reverse_iterator(end()); + } + + TCB_SPAN_ARRAY_CONSTEXPR reverse_iterator rend() const noexcept { + return reverse_iterator(begin()); + } + + private: + storage_type storage_{}; +}; + +#ifdef TCB_SPAN_HAVE_DEDUCTION_GUIDES + +/* Deduction Guides */ +template +span(T (&)[N])->span; + +template +span(std::array&)->span; + +template +span(const std::array&)->span; + +template +span(Container&)->span; + +template +span(const Container&)->span; + +#endif // TCB_HAVE_DEDUCTION_GUIDES + +template +constexpr span make_span( + span s) noexcept { + return s; +} + +template +constexpr span make_span(T (&arr)[N]) noexcept { + return {arr}; +} + +template +TCB_SPAN_ARRAY_CONSTEXPR span make_span(std::array& arr) noexcept { + return {arr}; +} + +template +TCB_SPAN_ARRAY_CONSTEXPR span make_span( + const std::array& arr) noexcept { + return {arr}; +} + +template +constexpr span make_span(Container& cont) { + return {cont}; +} + +template +constexpr span make_span( + const Container& cont) { + return {cont}; +} + +template +span< + const byte, + ((Extent == dynamic_extent) ? dynamic_extent : + sizeof(ElementType) * Extent)> +as_bytes(span s) noexcept { + return {reinterpret_cast(s.data()), s.size_bytes()}; +} + +template < + class ElementType, + size_t Extent, + typename std::enable_if::value, int>::type = 0> +span< + byte, + ((Extent == dynamic_extent) ? dynamic_extent : + sizeof(ElementType) * Extent)> +as_writable_bytes(span s) noexcept { + return {reinterpret_cast(s.data()), s.size_bytes()}; +} + +template +constexpr auto get(span s) -> decltype(s[N]) { + return s[N]; +} + +} // namespace TCB_SPAN_NAMESPACE_NAME + +namespace std { + +template +class tuple_size> + : public integral_constant {}; + +template +class tuple_size>; // not defined + +template +class tuple_element> { + public: + static_assert( + Extent != TCB_SPAN_NAMESPACE_NAME::dynamic_extent && I < Extent, ""); + using type = ElementType; +}; + +} // end namespace std + +#endif // TCB_SPAN_HPP_INCLUDED diff --git a/libtiledbsoma/src/reindexer/reindexer.cc b/libtiledbsoma/src/reindexer/reindexer.cc index 562a4155a9..ea243189b0 100644 --- a/libtiledbsoma/src/reindexer/reindexer.cc +++ b/libtiledbsoma/src/reindexer/reindexer.cc @@ -60,7 +60,7 @@ void IntIndexer::map_locations(const int64_t* keys, size_t size) { int64_t counter = 0; // Hash map construction LOG_DEBUG( - std::format("[Re-indexer] Start of Map locations with {} keys", size)); + fmt::format("[Re-indexer] Start of Map locations with {} keys", size)); for (size_t i = 0; i < size; i++) { k = kh_put(m64, hash_, keys[i], &ret); assert(k != kh_end(hash_)); @@ -71,10 +71,10 @@ void IntIndexer::map_locations(const int64_t* keys, size_t size) { throw std::runtime_error("There are duplicate keys."); } auto hsize = kh_size(hash_); - LOG_DEBUG(std::format("[Re-indexer] khash size = {}", hsize)); + LOG_DEBUG(fmt::format("[Re-indexer] khash size = {}", hsize)); LOG_DEBUG( - std::format("[Re-indexer] Thread pool started and hash table created")); + fmt::format("[Re-indexer] Thread pool started and hash table created")); } void IntIndexer::lookup(const int64_t* keys, int64_t* results, size_t size) { @@ -95,7 +95,7 @@ void IntIndexer::lookup(const int64_t* keys, int64_t* results, size_t size) { } return; } - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "Lookup with thread concurrency {} on data size {}", context_->thread_pool()->concurrency_level(), size)); @@ -114,7 +114,7 @@ void IntIndexer::lookup(const int64_t* keys, int64_t* results, size_t size) { if (end > size) { end = size; } - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "Creating tileDB task for the range from {} to {} ", start, end)); tiledbsoma::ThreadPool::Task task = context_->thread_pool()->execute( [this, start, end, &results, &keys]() { @@ -131,7 +131,7 @@ void IntIndexer::lookup(const int64_t* keys, int64_t* results, size_t size) { }); assert(task.valid()); tasks.emplace_back(std::move(task)); - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "Task for the range from {} to {} inserted in the queue", start, end)); diff --git a/libtiledbsoma/src/soma/array_buffers.cc b/libtiledbsoma/src/soma/array_buffers.cc index 35bf0d36f8..a55d107c59 100644 --- a/libtiledbsoma/src/soma/array_buffers.cc +++ b/libtiledbsoma/src/soma/array_buffers.cc @@ -33,8 +33,6 @@ #include "array_buffers.h" #include "../utils/logger.h" -#include - namespace tiledbsoma { using namespace tiledb; @@ -42,7 +40,7 @@ using namespace tiledb; std::shared_ptr ArrayBuffers::at(const std::string& name) { if (!contains(name)) { throw TileDBSOMAError( - std::format("[ArrayBuffers] column '{}' does not exist", name)); + fmt::format("[ArrayBuffers] column '{}' does not exist", name)); } return buffers_[name]; } @@ -51,7 +49,7 @@ void ArrayBuffers::emplace( const std::string& name, std::shared_ptr buffer) { if (contains(name)) { throw TileDBSOMAError( - std::format("[ArrayBuffers] column '{}' already exists", name)); + fmt::format("[ArrayBuffers] column '{}' already exists", name)); } names_.push_back(name); buffers_.emplace(name, buffer); diff --git a/libtiledbsoma/src/soma/column_buffer.cc b/libtiledbsoma/src/soma/column_buffer.cc index af2e85c0b8..74fb4e47d8 100644 --- a/libtiledbsoma/src/soma/column_buffer.cc +++ b/libtiledbsoma/src/soma/column_buffer.cc @@ -33,8 +33,6 @@ #include "column_buffer.h" #include "../utils/logger.h" -#include - namespace tiledbsoma { using namespace tiledb; @@ -105,7 +103,7 @@ std::shared_ptr ColumnBuffer::create( throw TileDBSOMAError("[ColumnBuffer] Column name not found: " + name_str); } -void ColumnBuffer::to_bitmap(std::span bytemap) { +void ColumnBuffer::to_bitmap(tcb::span bytemap) { int i_dst = 0; for (unsigned int i_src = 0; i_src < bytemap.size(); i_src++) { // Overwrite every 8 bytes with a one-byte bitmap @@ -143,7 +141,7 @@ ColumnBuffer::ColumnBuffer( , is_nullable_(is_nullable) , enumeration_(enumeration) , is_ordered_(is_ordered) { - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[ColumnBuffer] '{}' {} bytes is_var={} is_nullable={}", name, num_bytes, @@ -162,7 +160,7 @@ ColumnBuffer::ColumnBuffer( } ColumnBuffer::~ColumnBuffer() { - LOG_TRACE(std::format("[ColumnBuffer] release '{}'", name_)); + LOG_TRACE(fmt::format("[ColumnBuffer] release '{}'", name_)); } void ColumnBuffer::attach(Query& query, std::optional subarray) { @@ -301,7 +299,7 @@ std::shared_ptr ColumnBuffer::alloc( try { num_bytes = std::stoull(value_str); } catch (const std::exception& e) { - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "[ColumnBuffer] Error parsing {}: '{}' ({})", CONFIG_KEY_INIT_BYTES, value_str, diff --git a/libtiledbsoma/src/soma/column_buffer.h b/libtiledbsoma/src/soma/column_buffer.h index b1920e61b4..a356d3c386 100644 --- a/libtiledbsoma/src/soma/column_buffer.h +++ b/libtiledbsoma/src/soma/column_buffer.h @@ -33,8 +33,8 @@ #ifndef COLUMN_BUFFER_H #define COLUMN_BUFFER_H -#include #include // for windows: error C2039: 'runtime_error': is not a member of 'std' +#include "span/span.hpp" #include #include @@ -80,7 +80,7 @@ class ColumnBuffer { * @brief Convert a bytemap to a bitmap in place. * */ - static void to_bitmap(std::span bytemap); + static void to_bitmap(tcb::span bytemap); //=================================================================== //= public non-static @@ -188,11 +188,11 @@ class ColumnBuffer { * @brief Return a view of the ColumnBuffer data. * * @tparam T Data type - * @return std::span data view + * @return tcb::span data view */ template - std::span data() { - return std::span((T*)data_.data(), num_cells_); + tcb::span data() { + return tcb::span((T*)data_.data(), num_cells_); } /** @@ -220,28 +220,28 @@ class ColumnBuffer { /** * @brief Return a view of the ColumnBuffer offsets. * - * @return std::span offsets view + * @return tcb::span offsets view */ - std::span offsets() { + tcb::span offsets() { if (!is_var_) { throw TileDBSOMAError( "[ColumnBuffer] Offsets buffer not defined for " + name_); } - return std::span(offsets_.data(), num_cells_); + return tcb::span(offsets_.data(), num_cells_); } /** * @brief Return a view of the validity buffer. * - * @return std::span validity view + * @return tcb::span validity view */ - std::span validity() { + tcb::span validity() { if (!is_nullable_) { throw TileDBSOMAError( "[ColumnBuffer] Validity buffer not defined for " + name_); } - return std::span(validity_.data(), num_cells_); + return tcb::span(validity_.data(), num_cells_); } /** @@ -346,24 +346,24 @@ class ColumnBuffer { * @brief Return optional enumeration offsets vector * */ - std::span enum_offsets() { + tcb::span enum_offsets() { if (!has_enumeration_) { throw TileDBSOMAError( "[ColumnBuffer] No enumeration defined for " + name_); } - return std::span(enum_offsets_.data(), enum_offsets_.size()); + return tcb::span(enum_offsets_.data(), enum_offsets_.size()); } /** * @brief Return optional enumeration string * */ - std::span enum_string() { + tcb::span enum_string() { if (!has_enumeration_) { throw TileDBSOMAError( "[ColumnBuffer] No enumeration defined for " + name_); } - return std::span(enum_str_.data(), enum_str_.length()); + return tcb::span(enum_str_.data(), enum_str_.length()); } /** diff --git a/libtiledbsoma/src/soma/managed_query.cc b/libtiledbsoma/src/soma/managed_query.cc index 3b89c9a9a6..7aad1e67fc 100644 --- a/libtiledbsoma/src/soma/managed_query.cc +++ b/libtiledbsoma/src/soma/managed_query.cc @@ -34,7 +34,6 @@ #include #include -#include #include "soma_array.h" #include "utils/common.h" #include "utils/logger.h" @@ -101,7 +100,7 @@ void ManagedQuery::set_layout(ResultOrder layout) { query_->set_layout(TILEDB_COL_MAJOR); break; default: - throw std::invalid_argument(std::format( + throw std::invalid_argument(fmt::format( "[ManagedQuery] invalid ResultOrder({}) passed", static_cast(layout))); } @@ -119,7 +118,7 @@ void ManagedQuery::select_columns( // Name is not an attribute or dimension. if (!schema_->has_attribute(name) && !schema_->domain().has_dimension(name)) { - LOG_WARN(std::format( + LOG_WARN(fmt::format( "[TileDB-SOMA::ManagedQuery] [{}] Invalid column selected: {}", name_, name)); @@ -164,7 +163,7 @@ void ManagedQuery::setup_read() { LOG_TRACE("[ManagedQuery] allocate new buffers"); buffers_ = std::make_shared(); for (auto& name : columns_) { - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[ManagedQuery] [{}] Adding buffer for column '{}'", name_, name)); buffers_->emplace(name, ColumnBuffer::create(array_, name)); buffers_->at(name)->attach(*query_); @@ -228,14 +227,14 @@ std::optional> ManagedQuery::read_next() { }); if (query_future_.valid()) { - LOG_DEBUG(std::format("[ManagedQuery] [{}] Waiting for query", name_)); + LOG_DEBUG(fmt::format("[ManagedQuery] [{}] Waiting for query", name_)); query_future_.wait(); LOG_DEBUG( - std::format("[ManagedQuery] [{}] Done waiting for query", name_)); + fmt::format("[ManagedQuery] [{}] Done waiting for query", name_)); auto retval = query_future_.get(); if (!retval.succeeded()) { - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "[ManagedQuery] [{}] Query FAILED: {}", name_, retval.message())); @@ -243,14 +242,14 @@ std::optional> ManagedQuery::read_next() { } else { throw TileDBSOMAError( - std::format("[ManagedQuery] [{}] 'query_future_' invalid", name_)); + fmt::format("[ManagedQuery] [{}] 'query_future_' invalid", name_)); } auto status = query_->query_status(); if (status == Query::Status::FAILED) { throw TileDBSOMAError( - std::format("[ManagedQuery] [{}] Query FAILED", name_)); + fmt::format("[ManagedQuery] [{}] Query FAILED", name_)); } // If the query was ever incomplete, the result buffers contents are not @@ -265,7 +264,7 @@ std::optional> ManagedQuery::read_next() { size_t num_cells = 0; for (auto& name : buffers_->names()) { num_cells = buffers_->at(name)->update_size(*query_); - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[ManagedQuery] [{}] Buffer {} cells={}", name_, name, num_cells)); } total_num_cells_ += num_cells; @@ -273,7 +272,7 @@ std::optional> ManagedQuery::read_next() { // TODO: retry the query with larger buffers if (status == Query::Status::INCOMPLETE && !num_cells) { throw TileDBSOMAError( - std::format("[ManagedQuery] [{}] Buffers are too small.", name_)); + fmt::format("[ManagedQuery] [{}] Buffers are too small.", name_)); } // Visit all attributes and retrieve enumeration vectors @@ -292,7 +291,7 @@ std::optional> ManagedQuery::read_next() { } auto colbuf = buffers_->at(attrname); colbuf->add_enumeration(enumvec); - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[ManagedQuery] got Enumeration '{}' for attribute '{}'", enumname.value(), attrname)); @@ -370,7 +369,7 @@ void ManagedQuery::_fill_in_subarrays_if_dense_without_new_shape(bool is_read) { } subarray_->add_range(0, array_shape.first, array_shape.second); - LOG_TRACE(std::format( + LOG_TRACE(fmt::format( "[ManagedQuery] Add full range to dense subarray dim0 = ({}, {})", array_shape.first, array_shape.second)); @@ -394,7 +393,7 @@ void ManagedQuery::_fill_in_subarrays_if_dense_with_new_shape( for (const auto& dim : schema.domain().dimensions()) { std::string dim_name = dim.name(); if (subarray_range_set_[dim_name]) { - LOG_TRACE(std::format( + LOG_TRACE(fmt::format( "[ManagedQuery] _fill_in_subarrays continue {}", dim_name)); continue; } @@ -403,11 +402,11 @@ void ManagedQuery::_fill_in_subarrays_if_dense_with_new_shape( // Per the spec DenseNDArray must only have dims named // soma_dim_{i} with i=0,1,2,...,n-1, of type int64. if (dim_name.rfind("soma_dim_", 0) != 0) { - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "found dense array with unexpected dim name {}", dim_name)); } if (dim.type() != TILEDB_INT64) { - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "expected dense arrays to have int64 dims; got {} for {}", tiledb::impl::to_str(dim.type()), dim_name)); @@ -419,7 +418,7 @@ void ManagedQuery::_fill_in_subarrays_if_dense_with_new_shape( int64_t lo = cd_lo; int64_t hi = cd_hi; - LOG_TRACE(std::format( + LOG_TRACE(fmt::format( "[ManagedQuery] _fill_in_subarrays_if_dense_with_new_shape dim " "name {} current domain ({}, {})", dim_name, @@ -443,14 +442,14 @@ void ManagedQuery::_fill_in_subarrays_if_dense_with_new_shape( &ned, &is_empty)); if (is_empty == 1) { - LOG_TRACE(std::format( + LOG_TRACE(fmt::format( "[ManagedQuery] _fill_in_subarrays_if_dense_with_new_shape " "dim name {} non-empty domain is absent", dim_name)); } else { int64_t ned_lo = ned[0]; int64_t ned_hi = ned[1]; - LOG_TRACE(std::format( + LOG_TRACE(fmt::format( "[ManagedQuery] _fill_in_subarrays_if_dense_with_new_shape " "dim name {} non-empty domain ({}, {})", dim_name, @@ -465,7 +464,7 @@ void ManagedQuery::_fill_in_subarrays_if_dense_with_new_shape( } } - LOG_TRACE(std::format( + LOG_TRACE(fmt::format( "[ManagedQuery] _fill_in_subarrays_if_dense_with_new_shape dim " "name {} select ({}, {})", dim_name, @@ -484,14 +483,14 @@ std::shared_ptr ManagedQuery::results() { } if (query_future_.valid()) { - LOG_DEBUG(std::format("[ManagedQuery] [{}] Waiting for query", name_)); + LOG_DEBUG(fmt::format("[ManagedQuery] [{}] Waiting for query", name_)); query_future_.wait(); LOG_DEBUG( - std::format("[ManagedQuery] [{}] Done waiting for query", name_)); + fmt::format("[ManagedQuery] [{}] Done waiting for query", name_)); auto retval = query_future_.get(); if (!retval.succeeded()) { - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "[ManagedQuery] [{}] Query FAILED: {}", name_, retval.message())); @@ -499,14 +498,14 @@ std::shared_ptr ManagedQuery::results() { } else { throw TileDBSOMAError( - std::format("[ManagedQuery] [{}] 'query_future_' invalid", name_)); + fmt::format("[ManagedQuery] [{}] 'query_future_' invalid", name_)); } auto status = query_->query_status(); if (status == Query::Status::FAILED) { throw TileDBSOMAError( - std::format("[ManagedQuery] [{}] Query FAILED", name_)); + fmt::format("[ManagedQuery] [{}] Query FAILED", name_)); } // If the query was ever incomplete, the result buffers contents are not @@ -521,7 +520,7 @@ std::shared_ptr ManagedQuery::results() { size_t num_cells = 0; for (auto& name : buffers_->names()) { num_cells = buffers_->at(name)->update_size(*query_); - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[ManagedQuery] [{}] Buffer {} cells={}", name_, name, num_cells)); } total_num_cells_ += num_cells; @@ -529,7 +528,7 @@ std::shared_ptr ManagedQuery::results() { // TODO: retry the query with larger buffers if (status == Query::Status::INCOMPLETE && !num_cells) { throw TileDBSOMAError( - std::format("[ManagedQuery] [{}] Buffers are too small.", name_)); + fmt::format("[ManagedQuery] [{}] Buffers are too small.", name_)); } // Visit all attributes and retrieve enumeration vectors @@ -548,7 +547,7 @@ std::shared_ptr ManagedQuery::results() { } auto colbuf = buffers_->at(attrname); colbuf->add_enumeration(enumvec); - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[ManagedQuery] got Enumeration '{}' for attribute '{}'", enumname.value(), attrname)); @@ -559,7 +558,7 @@ std::shared_ptr ManagedQuery::results() { void ManagedQuery::check_column_name(const std::string& name) { if (!buffers_->contains(name)) { - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "[ManagedQuery] Column '{}' is not available in the query " "results.", name)); @@ -694,7 +693,7 @@ bool ManagedQuery::_cast_column( case TILEDB_FLOAT64: return _cast_column_aux(schema, array, se); default: - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "Saw invalid TileDB user type when attempting to cast table: " "{}", tiledb::impl::type_to_str(user_type))); @@ -760,7 +759,7 @@ void ManagedQuery::_promote_indexes_to_values( case TILEDB_FLOAT64: return _cast_dictionary_values(schema, array); default: - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "Saw invalid TileDB value type when attempting to promote " "indexes to values: {}", tiledb::impl::type_to_str(value_type))); @@ -1056,7 +1055,7 @@ bool ManagedQuery::_extend_enumeration( return _extend_and_evolve_schema( value_schema, value_array, index_schema, index_array, se); default: - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "ArrowAdapter: Unsupported TileDB dict datatype: {} ", tiledb::impl::type_to_str(value_type))); } diff --git a/libtiledbsoma/src/soma/managed_query.h b/libtiledbsoma/src/soma/managed_query.h index b35b9c767f..ab76a48482 100644 --- a/libtiledbsoma/src/soma/managed_query.h +++ b/libtiledbsoma/src/soma/managed_query.h @@ -34,9 +34,9 @@ #define MANAGED_QUERY_H #include -#include #include // for windows: error C2039: 'runtime_error': is not a member of 'std' #include +#include "span/span.hpp" #include @@ -193,7 +193,7 @@ class ManagedQuery { * @param points Vector of dimension points */ template - void select_points(const std::string& dim, const std::span points) { + void select_points(const std::string& dim, const tcb::span points) { subarray_range_set_[dim] = true; subarray_range_empty_[dim] = true; for (auto& point : points) { @@ -326,10 +326,10 @@ class ManagedQuery { * * @tparam T Data type * @param name Column name - * @return std::span Data view + * @return tcb::span Data view */ template - std::span data(const std::string& name) { + tcb::span data(const std::string& name) { check_column_name(name); return buffers_->at(name)->data(); } @@ -338,9 +338,9 @@ class ManagedQuery { * @brief Return a view of validity values for column `name`. * * @param name Column name - * @return std::span Validity view + * @return tcb::span Validity view */ - const std::span validity(const std::string& name) { + const tcb::span validity(const std::string& name) { check_column_name(name); return buffers_->at(name)->validity(); } diff --git a/libtiledbsoma/src/soma/soma_array.cc b/libtiledbsoma/src/soma/soma_array.cc index e25958b460..e1d5a74f6e 100644 --- a/libtiledbsoma/src/soma/soma_array.cc +++ b/libtiledbsoma/src/soma/soma_array.cc @@ -34,8 +34,6 @@ #include "../utils/logger.h" #include "../utils/util.h" -#include - namespace tiledbsoma { using namespace tiledb; @@ -89,7 +87,7 @@ std::unique_ptr SOMAArray::open( ResultOrder result_order, std::optional timestamp) { LOG_DEBUG( - std::format("[SOMAArray] static method 'cfg' opening array '{}'", uri)); + fmt::format("[SOMAArray] static method 'cfg' opening array '{}'", uri)); return std::make_unique( mode, uri, @@ -111,7 +109,7 @@ std::unique_ptr SOMAArray::open( ResultOrder result_order, std::optional timestamp) { LOG_DEBUG( - std::format("[SOMAArray] static method 'ctx' opening array '{}'", uri)); + fmt::format("[SOMAArray] static method 'ctx' opening array '{}'", uri)); return std::make_unique( mode, uri, @@ -420,7 +418,7 @@ void SOMAArray::validate( auto tdb_mode = mode == OpenMode::read ? TILEDB_READ : TILEDB_WRITE; try { - LOG_DEBUG(std::format("[SOMAArray] opening array '{}'", uri_)); + LOG_DEBUG(fmt::format("[SOMAArray] opening array '{}'", uri_)); if (timestamp) { arr_ = std::make_shared( *ctx_->tiledb_ctx(), @@ -431,14 +429,14 @@ void SOMAArray::validate( } else { arr_ = std::make_shared(*ctx_->tiledb_ctx(), uri_, tdb_mode); } - LOG_TRACE(std::format("[SOMAArray] loading enumerations")); + LOG_TRACE(fmt::format("[SOMAArray] loading enumerations")); ArrayExperimental::load_all_enumerations( *ctx_->tiledb_ctx(), *(arr_.get())); schema_ = std::make_shared(arr_->schema()); mq_ = std::make_unique(arr_, ctx_->tiledb_ctx(), name); } catch (const std::exception& e) { throw TileDBSOMAError( - std::format("Error opening array: '{}'\n {}", uri_, e.what())); + fmt::format("Error opening array: '{}'\n {}", uri_, e.what())); } } @@ -554,7 +552,7 @@ ArrowTable SOMAArray::_get_core_domainish(enum Domainish which_kind) { break; default: - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "SOMAArray::_get_core_domainish:dim {} has unhandled type " "{}", core_dim.name(), @@ -577,7 +575,7 @@ uint64_t SOMAArray::nnz() { FragmentInfo fragment_info(*ctx_->tiledb_ctx(), uri_); fragment_info.load(); - LOG_DEBUG(std::format("[SOMAArray] Fragment info for array '{}'", uri_)); + LOG_DEBUG(fmt::format("[SOMAArray] Fragment info for array '{}'", uri_)); if (LOG_DEBUG_ENABLED()) { fragment_info.dump(); } @@ -641,7 +639,7 @@ uint64_t SOMAArray::nnz() { auto type_code = dim.type(); if ((dim_name != "soma_joinid" && dim_name != "soma_dim_0") || type_code != TILEDB_INT64) { - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[SOMAArray::nnz] dim 0 (type={} name={}) isn't int64 " "soma_joinid or int64 soma_dim_0: using _nnz_slow", tiledb::impl::type_to_str(type_code), @@ -658,7 +656,7 @@ uint64_t SOMAArray::nnz() { fragment_info.get_non_empty_domain( relevant_fragments[i], 0, &non_empty_domains[i]); - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[SOMAArray] fragment {} non-empty domain = [{}, {}]", i, non_empty_domains[i][0], @@ -672,7 +670,7 @@ uint64_t SOMAArray::nnz() { // the next non-empty domain, there is an overlap bool overlap = false; for (uint32_t i = 0; i < fragment_count - 1; i++) { - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[SOMAArray] Checking {} < {}", non_empty_domains[i][1], non_empty_domains[i + 1][0])); @@ -741,7 +739,7 @@ StatusAndReason SOMAArray::_can_set_shape_helper( if (array_ndim != arg_ndim) { return std::pair( false, - std::format( + fmt::format( "{}: provided shape has ndim {}, while the array has {}", function_name_for_messages, arg_ndim, @@ -758,7 +756,7 @@ StatusAndReason SOMAArray::_can_set_shape_helper( if (!has_shape) { return std::pair( false, - std::format( + fmt::format( "{}: array currently has no shape: please " "upgrade the array.", function_name_for_messages)); @@ -769,7 +767,7 @@ StatusAndReason SOMAArray::_can_set_shape_helper( if (has_shape) { return std::pair( false, - std::format( + fmt::format( "{}: array already has a shape: please use resize", function_name_for_messages)); } @@ -823,7 +821,7 @@ StatusAndReason SOMAArray::_can_set_shape_domainish_subhelper( // multi-type dims, need to go through upgrade_domain -- and this is // library-internal code, it's not the user's fault if we got here. if (dim.type() != TILEDB_INT64) { - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "{}: internal error: expected {} dim to be {}; got {}", function_name_for_messages, dim_name, @@ -839,7 +837,7 @@ StatusAndReason SOMAArray::_can_set_shape_domainish_subhelper( if (newshape[i] < old_dim_shape) { return std::pair( false, - std::format( + fmt::format( "{} for {}: new {} < existing shape {}", function_name_for_messages, dim_name, @@ -855,7 +853,7 @@ StatusAndReason SOMAArray::_can_set_shape_domainish_subhelper( if (newshape[i] > old_dim_shape) { return std::pair( false, - std::format( + fmt::format( "{} for {}: new {} < maxshape {}", function_name_for_messages, dim_name, @@ -878,7 +876,7 @@ StatusAndReason SOMAArray::_can_set_soma_joinid_shape_helper( if (has_current_domain()) { return std::pair( false, - std::format( + fmt::format( "{}: dataframe already has its domain set.", function_name_for_messages)); } @@ -889,7 +887,7 @@ StatusAndReason SOMAArray::_can_set_soma_joinid_shape_helper( if (!has_current_domain()) { return std::pair( false, - std::format( + fmt::format( "{}: dataframe currently has no domain set.", function_name_for_messages)); } @@ -907,7 +905,7 @@ StatusAndReason SOMAArray::_can_set_soma_joinid_shape_helper( if (newshape < cur_dom_lo_hi.second) { return std::pair( false, - std::format( + fmt::format( "{}: new soma_joinid shape {} < existing shape {}", function_name_for_messages, newshape, @@ -920,7 +918,7 @@ StatusAndReason SOMAArray::_can_set_soma_joinid_shape_helper( if (newshape > dom_lo_hi.second) { return std::pair( false, - std::format( + fmt::format( "{}: new soma_joinid shape {} > maxshape {}", function_name_for_messages, newshape, @@ -936,7 +934,7 @@ void SOMAArray::_set_shape_helper( bool must_already_have, std::string function_name_for_messages) { if (arr_->query_type() != TILEDB_WRITE) { - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "{} array must be opened in write mode", function_name_for_messages)); } @@ -944,14 +942,14 @@ void SOMAArray::_set_shape_helper( if (!must_already_have) { // Upgrading an array to install a current domain if (!_get_current_domain().is_empty()) { - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "{}: array must not already have a shape: please upgrade it", function_name_for_messages)); } } else { // Expanding an array's current domain if (_get_current_domain().is_empty()) { - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "{} array must already have a shape: please upgrade it", function_name_for_messages)); } @@ -970,7 +968,7 @@ void SOMAArray::_set_shape_helper( unsigned n = domain.ndim(); if ((unsigned)newshape.size() != n) { - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "[SOMAArray::resize]: newshape has dimension count {}; array has " "{} ", newshape.size(), @@ -992,7 +990,7 @@ void SOMAArray::_set_soma_joinid_shape_helper( bool must_already_have, std::string function_name_for_messages) { if (arr_->query_type() != TILEDB_WRITE) { - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "{}: array must be opened in write mode", function_name_for_messages)); } @@ -1000,14 +998,14 @@ void SOMAArray::_set_soma_joinid_shape_helper( if (!must_already_have) { // Upgrading an array to install a current domain if (!_get_current_domain().is_empty()) { - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "{}: array must not already have a shape", function_name_for_messages)); } } else { // Expanding an array's current domain if (_get_current_domain().is_empty()) { - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "{} array must already have a shape", function_name_for_messages)); } @@ -1031,7 +1029,7 @@ void SOMAArray::_set_soma_joinid_shape_helper( const std::string dim_name = dim.name(); if (dim_name == "soma_joinid") { if (dim.type() != TILEDB_INT64) { - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "{}: expected soma_joinid to be of type {}; got {}", function_name_for_messages, tiledb::impl::type_to_str(TILEDB_INT64), @@ -1134,7 +1132,7 @@ void SOMAArray::_set_soma_joinid_shape_helper( dim.domain().second); break; default: - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "{}: internal error: unhandled type {} for {}.", function_name_for_messages, tiledb::impl::type_to_str(dim.type()), @@ -1178,7 +1176,7 @@ StatusAndReason SOMAArray::_can_set_domain_helper( if (!has_current_domain()) { return std::pair( false, - std::format( + fmt::format( "{}: dataframe does not have a domain: please upgrade it", function_name_for_messages)); } @@ -1186,7 +1184,7 @@ StatusAndReason SOMAArray::_can_set_domain_helper( if (has_current_domain()) { return std::pair( false, - std::format( + fmt::format( "{}: dataframe already has a domain", function_name_for_messages)); } @@ -1239,7 +1237,7 @@ StatusAndReason SOMAArray::_can_set_dataframe_domainish_subhelper( if (new_domain_schema->n_children != domain.ndim()) { return std::pair( false, - std::format( + fmt::format( "{}: requested domain has ndim={} but the dataframe has " "ndim={}", function_name_for_messages, @@ -1250,7 +1248,7 @@ StatusAndReason SOMAArray::_can_set_dataframe_domainish_subhelper( if (new_domain_schema->n_children != new_domain_array->n_children) { return std::pair( false, - std::format( + fmt::format( "{}: internal coding error", function_name_for_messages)); } @@ -1345,7 +1343,7 @@ StatusAndReason SOMAArray::_can_set_dataframe_domainish_subhelper( double>(check_current_domain, newdomain, dim.name()); break; default: - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "{}: saw invalid TileDB type when attempting to cast " "domain information: {}", function_name_for_messages, @@ -1355,7 +1353,7 @@ StatusAndReason SOMAArray::_can_set_dataframe_domainish_subhelper( if (status_and_reason.first == false) { return std::pair( false, - std::format( + fmt::format( "{} for {}: {}", function_name_for_messages, dim.name(), @@ -1370,20 +1368,20 @@ void SOMAArray::_set_domain_helper( bool must_already_have, std::string function_name_for_messages) { if (arr_->query_type() != TILEDB_WRITE) { - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "{}: array must be opened in write mode", function_name_for_messages)); } if (must_already_have) { if (!has_current_domain()) { - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "{}: dataframe does not have a domain: please upgrade it", function_name_for_messages)); } } else { if (has_current_domain()) { - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "{}: dataframe already has a domain", function_name_for_messages)); } @@ -1395,7 +1393,7 @@ void SOMAArray::_set_domain_helper( ArrowSchema* new_domain_schema = newdomain.second.get(); if (new_domain_schema->n_children != domain.ndim()) { - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "{}: requested domain has ndim={} but the dataframe has " "ndim={}", function_name_for_messages, @@ -1404,7 +1402,7 @@ void SOMAArray::_set_domain_helper( } if (new_domain_schema->n_children != new_domain_array->n_children) { - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "{}: internal coding error", function_name_for_messages)); } @@ -1430,7 +1428,7 @@ void SOMAArray::_set_domain_helper( // See comments in soma_array.h. ndrect.set_range(dim_name, "", "\x7f"); } else { - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "domain (\"{}\", \"{}\") cannot be set for " "string index columns: please use " "(\"\", \"\")", @@ -1513,7 +1511,7 @@ void SOMAArray::_set_domain_helper( ndrect.set_range(dim_name, lo_hi[0], lo_hi[1]); } break; default: - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "{}: internal error: unhandled type {} for {}.", function_name_for_messages, tiledb::impl::type_to_str(dim.type()), @@ -1604,7 +1602,7 @@ std::optional SOMAArray::_maybe_soma_joinid_tiledb_current_domain() { auto dim = dom.dimension(dim_name); if (dim.type() != TILEDB_INT64) { - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "expected {} dim to be {}; got {}", dim_name, tiledb::impl::type_to_str(TILEDB_INT64), @@ -1626,7 +1624,7 @@ std::optional SOMAArray::_maybe_soma_joinid_tiledb_domain() { auto dim = dom.dimension(dim_name); if (dim.type() != TILEDB_INT64) { - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "expected {} dim to be {}; got {}", dim_name, tiledb::impl::type_to_str(TILEDB_INT64), diff --git a/libtiledbsoma/src/soma/soma_array.h b/libtiledbsoma/src/soma/soma_array.h index eff4ffbd77..06d5b46cb8 100644 --- a/libtiledbsoma/src/soma/soma_array.h +++ b/libtiledbsoma/src/soma/soma_array.h @@ -35,9 +35,8 @@ #include // for windows: error C2039: 'runtime_error': is not a member of 'std' -#include #include -#include +#include "span/span.hpp" #include #include @@ -374,16 +373,18 @@ class SOMAArray : public SOMAObject { template void set_dim_points( const std::string& dim, - const std::span points, + const tcb::span points, int partition_index, int partition_count) { // Validate partition inputs if (partition_index >= partition_count) { - throw TileDBSOMAError(std::format( - "[SOMAArray] partition_index ({}) must be < partition_count " - "({})", - partition_index, - partition_count)); + // TODO this use to be formatted with fmt::format which is part of + // internal header spd/log/fmt/fmt.h and should not be used. + // In C++20, this can be replaced with fmt::format. + std::ostringstream err; + err << "[SOMAArray] partition_index (" << partition_index + << ") must be < partition_count (" << partition_count; + throw TileDBSOMAError(err.str()); } if (partition_count > 1) { @@ -395,19 +396,20 @@ class SOMAArray : public SOMAObject { partition_size = points.size() - start; } - LOG_DEBUG(std::format( - "[SOMAArray] set_dim_points partitioning: sizeof(T)={} dim={} " - "index={} count={} range =[{}, {}] of {} points", - sizeof(T), - dim, - partition_index, - partition_count, - start, - start + partition_size - 1, - points.size())); + // TODO this use to be formatted with fmt::format which is part of + // internal header spd/log/fmt/fmt.h and should not be used. + // In C++20, this can be replaced with fmt::format. + std::ostringstream log_dbg; + log_dbg << "[SOMAArray] set_dim_points partitioning:" + << " sizeof(T)=" << sizeof(T) << " dim=" << dim + << " index=" << partition_index + << " count=" << partition_count << " range =[" << start + << ", " << start + partition_size - 1 << "] of " + << points.size() << "points"; + LOG_DEBUG(log_dbg.str()); mq_->select_points( - dim, std::span{&points[start], partition_size}); + dim, tcb::span{&points[start], partition_size}); } else { mq_->select_points(dim, points); } diff --git a/libtiledbsoma/src/soma/soma_context.cc b/libtiledbsoma/src/soma/soma_context.cc index 69b066b01d..34644c844e 100644 --- a/libtiledbsoma/src/soma/soma_context.cc +++ b/libtiledbsoma/src/soma/soma_context.cc @@ -49,7 +49,7 @@ std::shared_ptr& SOMAContext::thread_pool() { try { concurrency = std::stoull(value_str); } catch (const std::exception& e) { - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "[SOMAContext] Error parsing {}: '{}' ({}) - must be a " "postive integer.", CONFIG_KEY_COMPUTE_CONCURRENCY_LEVEL, diff --git a/libtiledbsoma/src/soma/soma_dataframe.cc b/libtiledbsoma/src/soma/soma_dataframe.cc index 92c042a7d3..d7feb8a552 100644 --- a/libtiledbsoma/src/soma/soma_dataframe.cc +++ b/libtiledbsoma/src/soma/soma_dataframe.cc @@ -95,7 +95,7 @@ void SOMADataFrame::update_dataframe_schema( std::map> add_enmrs) { ArraySchemaEvolution se(*ctx->tiledb_ctx()); for (auto key_name : drop_attrs) { - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[SOMADataFrame::update_dataframe_schema] drop col name {}", key_name)); se.drop_attribute(key_name); @@ -158,7 +158,7 @@ void SOMADataFrame::update_dataframe_schema( if (has_enmr) { auto [enmr_type, ordered] = enmr_it->second; - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[SOMADataFrame::update_dataframe_schema] add col name {} " "index_type " "{} value_type {} ordered {}", @@ -178,7 +178,7 @@ void SOMADataFrame::update_dataframe_schema( AttributeExperimental::set_enumeration_name( *ctx->tiledb_ctx(), attr, attr_name); } else { - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[SOMADataFrame::update_dataframe_schema] add col name {} type " "{}", attr_name, diff --git a/libtiledbsoma/src/utils/arrow_adapter.cc b/libtiledbsoma/src/utils/arrow_adapter.cc index d601719abf..31f545d157 100644 --- a/libtiledbsoma/src/utils/arrow_adapter.cc +++ b/libtiledbsoma/src/utils/arrow_adapter.cc @@ -42,17 +42,17 @@ void ArrowAdapter::release_schema(struct ArrowSchema* schema) { std::string name_for_log( schema->name == nullptr ? "anonymous" : schema->name); if (schema->name != nullptr) - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[ArrowAdapter] release_schema start for {}", schema->name)); if (schema->name != nullptr) { - LOG_TRACE(std::format( + LOG_TRACE(fmt::format( "[ArrowAdapter] release_schema schema->name {}", schema->name)); free((void*)schema->name); schema->name = nullptr; } if (schema->format != nullptr) { - LOG_TRACE(std::format( + LOG_TRACE(fmt::format( "[ArrowAdapter] release_schema name {} schema->format {}", name_for_log, schema->format)); @@ -60,7 +60,7 @@ void ArrowAdapter::release_schema(struct ArrowSchema* schema) { schema->format = nullptr; } if (schema->metadata != nullptr) { - LOG_TRACE(std::format( + LOG_TRACE(fmt::format( "[ArrowAdapter] release_schema name {} schema->metadata", name_for_log)); free((void*)schema->metadata); @@ -68,7 +68,7 @@ void ArrowAdapter::release_schema(struct ArrowSchema* schema) { } if (schema->children != nullptr) { - LOG_TRACE(std::format( + LOG_TRACE(fmt::format( "[ArrowAdapter] release_schema name {} n_children {} begin " "recurse ", name_for_log, @@ -77,7 +77,7 @@ void ArrowAdapter::release_schema(struct ArrowSchema* schema) { for (auto i = 0; i < schema->n_children; i++) { if (schema->children[i] != nullptr) { if (schema->children[i]->release != nullptr) { - LOG_TRACE(std::format( + LOG_TRACE(fmt::format( "[ArrowAdapter] release_schema name {} schema->child " "{} " "release", @@ -85,7 +85,7 @@ void ArrowAdapter::release_schema(struct ArrowSchema* schema) { i)); release_schema(schema->children[i]); } - LOG_TRACE(std::format( + LOG_TRACE(fmt::format( "[ArrowAdapter] release_schema name {} schema->child {} " "free", name_for_log, @@ -95,7 +95,7 @@ void ArrowAdapter::release_schema(struct ArrowSchema* schema) { } } - LOG_TRACE(std::format( + LOG_TRACE(fmt::format( "[ArrowAdapter] release_schema name {} n_children {} end recurse ", name_for_log, schema->n_children)); @@ -106,12 +106,12 @@ void ArrowAdapter::release_schema(struct ArrowSchema* schema) { if (schema->dictionary != nullptr) { if (schema->dictionary->release != nullptr) { - LOG_TRACE(std::format( + LOG_TRACE(fmt::format( "[ArrowAdapter] release_schema name {} schema->dict release", name_for_log)); release_schema(schema->dictionary); } - LOG_TRACE(std::format( + LOG_TRACE(fmt::format( "[ArrowAdapter] release_schema name {} schema->dict free", name_for_log)); free(schema->dictionary); @@ -119,14 +119,14 @@ void ArrowAdapter::release_schema(struct ArrowSchema* schema) { } schema->release = nullptr; - LOG_TRACE(std::format( + LOG_TRACE(fmt::format( "[ArrowAdapter] release_schema name {} done", name_for_log)); } void ArrowAdapter::release_array(struct ArrowArray* array) { auto arrow_buffer = static_cast(array->private_data); if (arrow_buffer != nullptr) { - LOG_TRACE(std::format( + LOG_TRACE(fmt::format( "[ArrowAdapter] release_array {} use_count={}", arrow_buffer->buffer_->name(), arrow_buffer->buffer_.use_count())); @@ -146,12 +146,12 @@ void ArrowAdapter::release_array(struct ArrowArray* array) { for (auto i = 0; i < array->n_children; i++) { if (array->children[i] != nullptr) { if (array->children[i]->release != nullptr) { - LOG_TRACE(std::format( + LOG_TRACE(fmt::format( "[ArrowAdapter] release_schema array->child {} release", i)); release_array(array->children[i]); } - LOG_TRACE(std::format( + LOG_TRACE(fmt::format( "[ArrowAdapter] release_schema array->child {} free", i)); free(array->children[i]); array->children[i] = nullptr; @@ -175,7 +175,7 @@ void ArrowAdapter::release_array(struct ArrowArray* array) { } array->release = nullptr; - LOG_TRACE(std::format("[ArrowAdapter] release_array done")); + LOG_TRACE(fmt::format("[ArrowAdapter] release_array done")); } PlatformConfig ArrowAdapter::platform_config_from_tiledb_schema( @@ -345,7 +345,7 @@ std::unique_ptr ArrowAdapter::arrow_schema_from_tiledb_array( arrow_schema->children = (ArrowSchema**)malloc( arrow_schema->n_children * sizeof(ArrowSchema*)); - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[ArrowAdapter] arrow_schema_from_tiledb_array n_children {}", arrow_schema->n_children)); @@ -365,7 +365,7 @@ std::unique_ptr ArrowAdapter::arrow_schema_from_tiledb_array( child->dictionary = nullptr; child->release = &ArrowAdapter::release_schema; child->private_data = nullptr; - LOG_TRACE(std::format( + LOG_TRACE(fmt::format( "[ArrowAdapter] arrow_schema_from_tiledb_array dim {} format {} " "name {}", i, @@ -393,7 +393,7 @@ std::unique_ptr ArrowAdapter::arrow_schema_from_tiledb_array( child->release = &ArrowAdapter::release_schema; child->private_data = nullptr; - LOG_TRACE(std::format( + LOG_TRACE(fmt::format( "[ArrowAdapter] arrow_schema_from_tiledb_array attr {} format {} " "name {}", i, @@ -553,7 +553,7 @@ void ArrowAdapter::_append_to_filter_list( filter_list.add_filter(filter); } } catch (std::out_of_range& e) { - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "Invalid filter {} passed to PlatformConfig", std::string(value))); } } @@ -604,7 +604,7 @@ void ArrowAdapter::_set_filter_option( break; default: throw TileDBSOMAError( - std::format("Invalid option {} passed to filter", option_name)); + fmt::format("Invalid option {} passed to filter", option_name)); } } @@ -631,7 +631,7 @@ Dimension ArrowAdapter::_create_dim( // #include arrow_adapter.h. Hence the code duplication in // logging statements. :( uint64_t* b = (uint64_t*)buff; - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "_create_dim name={} b={} b1={} b2={}", name, b[0], @@ -641,7 +641,7 @@ Dimension ArrowAdapter::_create_dim( } case TILEDB_INT8: { int8_t* b = (int8_t*)buff; - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "_create_dim name={} b={} b1={} b2={}", name, b[0], @@ -651,7 +651,7 @@ Dimension ArrowAdapter::_create_dim( } case TILEDB_UINT8: { uint8_t* b = (uint8_t*)buff; - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "_create_dim name={} b={} b1={} b2={}", name, b[0], @@ -661,7 +661,7 @@ Dimension ArrowAdapter::_create_dim( } case TILEDB_INT16: { int16_t* b = (int16_t*)buff; - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "_create_dim name={} b={} b1={} b2={}", name, b[0], @@ -671,7 +671,7 @@ Dimension ArrowAdapter::_create_dim( } case TILEDB_UINT16: { uint16_t* b = (uint16_t*)buff; - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "_create_dim name={} b={} b1={} b2={}", name, b[0], @@ -681,7 +681,7 @@ Dimension ArrowAdapter::_create_dim( } case TILEDB_INT32: { int32_t* b = (int32_t*)buff; - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "_create_dim name={} b={} b1={} b2={}", name, b[0], @@ -691,7 +691,7 @@ Dimension ArrowAdapter::_create_dim( } case TILEDB_UINT32: { uint32_t* b = (uint32_t*)buff; - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "_create_dim name={} b={} b1={} b2={}", name, b[0], @@ -701,7 +701,7 @@ Dimension ArrowAdapter::_create_dim( } case TILEDB_INT64: { int64_t* b = (int64_t*)buff; - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "_create_dim name={} b={} b1={} b2={}", name, b[0], @@ -711,7 +711,7 @@ Dimension ArrowAdapter::_create_dim( } case TILEDB_UINT64: { uint64_t* b = (uint64_t*)buff; - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "_create_dim name={} b={} b1={} b2={}", name, b[0], @@ -721,7 +721,7 @@ Dimension ArrowAdapter::_create_dim( } case TILEDB_FLOAT32: { float* b = (float*)buff; - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "_create_dim name={} b={} b1={} b2={}", name, b[0], @@ -731,7 +731,7 @@ Dimension ArrowAdapter::_create_dim( } case TILEDB_FLOAT64: { double* b = (double*)buff; - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "_create_dim name={} b={} b1={} b2={}", name, b[0], @@ -740,7 +740,7 @@ Dimension ArrowAdapter::_create_dim( return ArrowAdapter::_create_dim_aux(ctx, name, (double*)buff); } default: - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "ArrowAdapter: Unsupported TileDB dimension: {} ", tiledb::impl::type_to_str(type))); } @@ -775,7 +775,7 @@ void ArrowAdapter::_set_current_domain_slot( uint64_t lo = ((uint64_t*)buff)[3]; uint64_t hi = ((uint64_t*)buff)[4]; ndrect.set_range(name, lo, hi); - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[ArrowAdapter] {} current_domain uint64_t {} to {}", name, lo, @@ -785,7 +785,7 @@ void ArrowAdapter::_set_current_domain_slot( int8_t lo = ((int8_t*)buff)[3]; int8_t hi = ((int8_t*)buff)[4]; ndrect.set_range(name, lo, hi); - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[ArrowAdapter] {} current_domain int8_t {} to {}", name, lo, @@ -795,7 +795,7 @@ void ArrowAdapter::_set_current_domain_slot( uint8_t lo = ((uint8_t*)buff)[3]; uint8_t hi = ((uint8_t*)buff)[4]; ndrect.set_range(name, lo, hi); - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[ArrowAdapter] {} current_domain uint8_t {} to {}", name, lo, @@ -805,7 +805,7 @@ void ArrowAdapter::_set_current_domain_slot( int16_t lo = ((int16_t*)buff)[3]; int16_t hi = ((int16_t*)buff)[4]; ndrect.set_range(name, lo, hi); - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[ArrowAdapter] {} current_domain int16_t {} to {}", name, lo, @@ -815,7 +815,7 @@ void ArrowAdapter::_set_current_domain_slot( uint16_t lo = ((uint16_t*)buff)[3]; uint16_t hi = ((uint16_t*)buff)[4]; ndrect.set_range(name, lo, hi); - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[ArrowAdapter] {} current_domain uint16_t {} to {}", name, lo, @@ -825,7 +825,7 @@ void ArrowAdapter::_set_current_domain_slot( int32_t lo = ((int32_t*)buff)[3]; int32_t hi = ((int32_t*)buff)[4]; ndrect.set_range(name, lo, hi); - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[ArrowAdapter] {} current_domain int32_t {} to {}", name, lo, @@ -835,7 +835,7 @@ void ArrowAdapter::_set_current_domain_slot( uint32_t lo = ((uint32_t*)buff)[3]; uint32_t hi = ((uint32_t*)buff)[4]; ndrect.set_range(name, lo, hi); - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[ArrowAdapter] {} current_domain uint32_t {} to {}", name, lo, @@ -845,7 +845,7 @@ void ArrowAdapter::_set_current_domain_slot( int64_t lo = ((int64_t*)buff)[3]; int64_t hi = ((int64_t*)buff)[4]; ndrect.set_range(name, lo, hi); - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[ArrowAdapter] {} current_domain int64_t {} to {}", name, lo, @@ -855,7 +855,7 @@ void ArrowAdapter::_set_current_domain_slot( uint64_t lo = ((uint64_t*)buff)[3]; uint64_t hi = ((uint64_t*)buff)[4]; ndrect.set_range(name, lo, hi); - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[ArrowAdapter] {} current_domain uint64_t {} to {}", name, lo, @@ -865,7 +865,7 @@ void ArrowAdapter::_set_current_domain_slot( float lo = ((float*)buff)[3]; float hi = ((float*)buff)[4]; ndrect.set_range(name, lo, hi); - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[ArrowAdapter] {} current_domain float {} to {}", name, lo, @@ -875,14 +875,14 @@ void ArrowAdapter::_set_current_domain_slot( double lo = ((double*)buff)[3]; double hi = ((double*)buff)[4]; ndrect.set_range(name, lo, hi); - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[ArrowAdapter] {} current_domain double {} to {}", name, lo, hi)); } break; default: - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "ArrowAdapter: Unsupported TileDB dimension: {} ", tiledb::impl::type_to_str(type))); } @@ -910,7 +910,7 @@ tiledb_layout_t ArrowAdapter::_get_order(std::string order) { return convert_order[order]; } catch (const std::out_of_range& e) { throw TileDBSOMAError( - std::format("Invalid order {} passed to PlatformConfig", order)); + fmt::format("Invalid order {} passed to PlatformConfig", order)); } } @@ -970,7 +970,7 @@ ArraySchema ArrowAdapter::tiledb_schema_from_arrow_schema( type_metadata = std::string_view(out.data, out.size_bytes); } - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[ArrowAdapter] schema pass for child {} name {}", sch_idx, std::string(child->name))); @@ -1020,14 +1020,14 @@ ArraySchema ArrowAdapter::tiledb_schema_from_arrow_schema( } LOG_DEBUG( - std::format("[ArrowAdapter] adding attribute {}", child->name)); + fmt::format("[ArrowAdapter] adding attribute {}", child->name)); schema.add_attribute(attr.first); } } for (int64_t i = 0; i < index_column_schema->n_children; ++i) { - LOG_DEBUG(std::format("[ArrowAdapter] child {}", i)); + LOG_DEBUG(fmt::format("[ArrowAdapter] child {}", i)); auto col_name = index_column_schema->children[i]->name; if (strcmp(col_name, SOMA_GEOMETRY_COLUMN_NAME.c_str()) == 0) { for (auto& dim : dims) { @@ -1048,10 +1048,10 @@ ArraySchema ArrowAdapter::tiledb_schema_from_arrow_schema( } } - LOG_DEBUG(std::format("[ArrowAdapter] set_domain")); + LOG_DEBUG(fmt::format("[ArrowAdapter] set_domain")); schema.set_domain(domain); - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[ArrowAdapter] index_column_info length {}", index_column_array->length)); @@ -1106,7 +1106,7 @@ ArraySchema ArrowAdapter::tiledb_schema_from_arrow_schema( strings = ArrowAdapter::get_array_string_column( child_array, child_schema); if (strings.size() != 5) { - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "ArrowAdapter::tiledb_schema_from_arrow_schema: " "internal error: " "expected 5 strings, got {}", @@ -1121,12 +1121,12 @@ ArraySchema ArrowAdapter::tiledb_schema_from_arrow_schema( ndrect.set_range(col_name, "", "\x7f"); } else { ndrect.set_range(col_name, lo, hi); - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[ArrowAdapter] index_column_info nbuf {}", index_column_array->children[i]->n_buffers)); } - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[ArrowAdapter] current domain {} \"{}\"-\"{}\"", child_schema->name, lo, @@ -1141,16 +1141,16 @@ ArraySchema ArrowAdapter::tiledb_schema_from_arrow_schema( current_domain.set_ndrectangle(ndrect); - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[ArrowAdapter] before setting current_domain from ndrect")); ArraySchemaExperimental::set_current_domain(*ctx, schema, current_domain); LOG_DEBUG( - std::format("[ArrowAdapter] after setting current_domain from ndrect")); + fmt::format("[ArrowAdapter] after setting current_domain from ndrect")); - LOG_DEBUG(std::format("[ArrowAdapter] check")); + LOG_DEBUG(fmt::format("[ArrowAdapter] check")); schema.check(); - LOG_DEBUG(std::format("[ArrowAdapter] returning")); + LOG_DEBUG(fmt::format("[ArrowAdapter] returning")); return schema; } @@ -1175,7 +1175,7 @@ Dimension ArrowAdapter::tiledb_dimension_from_arrow_schema( col_name, platform_config, soma_type, ctx); if (array->length != 5) { - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "ArrowAdapter: unexpected length {} != 5 for name " "{}", array->length, @@ -1200,7 +1200,7 @@ ArrowAdapter::tiledb_attribute_from_arrow_schema( if (type_metadata.compare("WKB") == 0) { type = TILEDB_GEOM_WKB; } else { - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "ArrowAdapter::tiledb_attribute_from_arrow_schema: " "Unkwown type metadata for `{}`: " "Expected 'WKB', got {}", @@ -1238,7 +1238,7 @@ ArrowAdapter::tiledb_attribute_from_arrow_schema( arrow_schema->flags & ARROW_FLAG_DICTIONARY_ORDERED); AttributeExperimental::set_enumeration_name( *ctx, attr, arrow_schema->name); - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[ArrowAdapter] dictionary for {} as {} {}", std::string(arrow_schema->name), tiledb::impl::type_to_str(enmr_type), @@ -1319,7 +1319,7 @@ std::pair ArrowAdapter::_get_data_and_length( ArrowAdapter::_fill_data_buffer(data, dst), data.size()); } default: - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "ArrowAdapter: Unsupported TileDB dict datatype: {} ", tiledb::impl::type_to_str(enmr.type()))); } @@ -1328,7 +1328,7 @@ std::pair ArrowAdapter::_get_data_and_length( inline void exitIfError(const ArrowErrorCode ec, const std::string& msg) { if (ec != NANOARROW_OK) throw TileDBSOMAError( - std::format("ArrowAdapter: Arrow Error {} ", msg)); + fmt::format("ArrowAdapter: Arrow Error {} ", msg)); } std::pair, std::unique_ptr> @@ -1366,7 +1366,7 @@ ArrowAdapter::to_arrow(std::shared_ptr column) { exitIfError(ArrowArrayAllocateChildren(arr, 0), "Bad array children alloc"); array->length = column->size(); - LOG_TRACE(std::format( + LOG_TRACE(fmt::format( "[ArrowAdapter] column type {} name {} nbuf {} {} nullable {}", to_arrow_format(column->type()).data(), column->name().data(), @@ -1375,7 +1375,7 @@ ArrowAdapter::to_arrow(std::shared_ptr column) { column->is_nullable())); if (array->n_buffers != n_buffers) { - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "[ArrowAdapter] expected array n_buffers {} for column {}; got {}", n_buffers, column->name(), @@ -1390,7 +1390,7 @@ ArrowAdapter::to_arrow(std::shared_ptr column) { } // assigning our ArrowBuffer pointer array->private_data = (void*)arrow_buffer; - LOG_TRACE(std::format( + LOG_TRACE(fmt::format( "[ArrowAdapter] create array name='{}' use_count={}", column->name(), column.use_count())); @@ -1535,7 +1535,7 @@ std::string_view ArrowAdapter::to_arrow_format( try { return _to_arrow_format_map.at(tiledb_dtype); } catch (const std::out_of_range& e) { - throw std::out_of_range(std::format( + throw std::out_of_range(fmt::format( "ArrowAdapter: Unsupported TileDB type: {} ", tiledb::impl::type_to_str(tiledb_dtype))); } @@ -1569,7 +1569,7 @@ tiledb_datatype_t ArrowAdapter::to_tiledb_format( return dtype; } catch (const std::out_of_range& e) { - throw std::out_of_range(std::format( + throw std::out_of_range(fmt::format( "ArrowAdapter: Unsupported Arrow type: {} ", arrow_dtype)); } } @@ -1618,7 +1618,7 @@ enum ArrowType ArrowAdapter::to_nanoarrow_type(std::string_view sv) { return NANOARROW_TYPE_LARGE_BINARY; else throw TileDBSOMAError( - std::format("ArrowAdapter: Unsupported Arrow format: {} ", sv)); + fmt::format("ArrowAdapter: Unsupported Arrow format: {} ", sv)); } std::unique_ptr ArrowAdapter::make_arrow_schema( @@ -1628,7 +1628,7 @@ std::unique_ptr ArrowAdapter::make_arrow_schema( auto num_types = tiledb_datatypes.size(); if (num_names != num_types) { - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "ArrowAdapter::make_arrow_schema: internal coding error: num_types " "{} != num_names {}", num_names, @@ -1647,7 +1647,7 @@ std::unique_ptr ArrowAdapter::make_arrow_schema( arrow_schema->release = &ArrowAdapter::release_schema; arrow_schema->private_data = nullptr; - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[ArrowAdapter] make_arrow_schema n_children {}", arrow_schema->n_children)); @@ -1666,7 +1666,7 @@ std::unique_ptr ArrowAdapter::make_arrow_schema( dim_schema->private_data = nullptr; arrow_schema->children[i] = dim_schema; - LOG_TRACE(std::format( + LOG_TRACE(fmt::format( "[ArrowAdapter] make_arrow_schema child {} format {} name {}", i, dim_schema->format, @@ -1711,7 +1711,7 @@ std::unique_ptr ArrowAdapter::make_arrow_array_parent( arrow_array->children[i] = nullptr; } - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "[ArrowAdapter] make_arrow_array n_children {}", arrow_array->n_children)); @@ -1719,7 +1719,7 @@ std::unique_ptr ArrowAdapter::make_arrow_array_parent( } void ArrowAdapter::log_make_arrow_array_child(ArrowArray* child) { - LOG_TRACE(std::format( + LOG_TRACE(fmt::format( "[ArrowAdapter] make_arrow_array_child length {} n_buffers {}", child->length, child->n_buffers)); @@ -1756,7 +1756,7 @@ int64_t ArrowAdapter::_get_column_index_from_name( } } - throw std::runtime_error(std::format( + throw std::runtime_error(fmt::format( "ArrowAdapter::_check_shapes: column {} not found", column_name)); } @@ -1766,7 +1766,7 @@ ArrowArray* ArrowAdapter::_get_and_check_column( int64_t expected_n_buffers) { ArrowArray* arrow_array = arrow_table.first.get(); if (column_index < 0 || column_index >= arrow_array->n_children) { - throw std::runtime_error(std::format( + throw std::runtime_error(fmt::format( "ArrowAdapter::_get_and_check_column: column index {} out of " "bounds {}..{}", column_index, @@ -1777,7 +1777,7 @@ ArrowArray* ArrowAdapter::_get_and_check_column( ArrowArray* child = arrow_array->children[column_index]; if (child->n_children != 0) { - throw std::runtime_error(std::format( + throw std::runtime_error(fmt::format( "ArrowAdapter::_get_and_check_column: column index {} is " "non-terminal", column_index)); @@ -1785,7 +1785,7 @@ ArrowArray* ArrowAdapter::_get_and_check_column( if (expected_n_buffers == 2) { if (child->n_buffers != 2) { - throw std::runtime_error(std::format( + throw std::runtime_error(fmt::format( "ArrowAdapter::_get_and_check_column: column index {} " "has buffer count {}; expected 2 for non-string data", column_index, @@ -1794,7 +1794,7 @@ ArrowArray* ArrowAdapter::_get_and_check_column( } else if (expected_n_buffers == 3) { if (child->n_buffers != 3) { - throw std::runtime_error(std::format( + throw std::runtime_error(fmt::format( "ArrowAdapter::_get_and_check_column: column index {} is " "has buffer count {}; expected 3 for string data", column_index, @@ -1802,7 +1802,7 @@ ArrowArray* ArrowAdapter::_get_and_check_column( } } else { - throw std::runtime_error(std::format( + throw std::runtime_error(fmt::format( "ArrowAdapter::_get_and_check_column: internal coding error: " "expected_n_buffers {} is " "neither 2 nor 3.", @@ -1820,7 +1820,7 @@ void ArrowAdapter::_set_spatial_dimensions( std::shared_ptr ctx, PlatformConfig platform_config) { if (type_metadata.compare("WKB") != 0) { - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "ArrowAdapter::tiledb_attribute_from_arrow_schema: " "Unkwown type metadata for `{}`: " "Expected 'WKB', got {}", diff --git a/libtiledbsoma/src/utils/fastercsx.h b/libtiledbsoma/src/utils/fastercsx.h index 915e04b3b2..7ec624a6f5 100644 --- a/libtiledbsoma/src/utils/fastercsx.h +++ b/libtiledbsoma/src/utils/fastercsx.h @@ -33,7 +33,7 @@ #include #include #include -#include +#include "span/span.hpp" #include "parallel_functions.h" @@ -72,9 +72,9 @@ std::pair get_split_(T n_elements, T n_sections, T section) noexcept { * @brief Sum size over all elements in vector - used only in asserts. */ template -size_t sum_over_size_(const std::vector>& v) noexcept { +size_t sum_over_size_(const std::vector>& v) noexcept { return std::transform_reduce( - v.cbegin(), v.cend(), 0ul, std::plus<>{}, [](std::span a) { + v.cbegin(), v.cend(), 0ul, std::plus<>{}, [](tcb::span a) { return a.size(); }); } @@ -95,13 +95,13 @@ size_t sum_over_size_(const std::vector>& v) noexcept { template struct Partition { size_t size; // sum of views[n].size for all n - std::vector> views; + std::vector> views; }; template void bin_view_( std::vector>& partitions, - const std::span& view) { + const tcb::span& view) { // find minimum size partition and add the span to that partition. size_t min_idx = 0; for (size_t pidx = 1; pidx < partitions.size(); ++pidx) { @@ -114,7 +114,7 @@ void bin_view_( template std::vector> partition_views_( - std::vector> const& Ai, + std::vector> const& Ai, const size_t max_partitions, const size_t partition_size) { assert(max_partitions > 0); @@ -149,8 +149,8 @@ void count_rows_( ThreadPool* const tp, uint64_t n_row, uint64_t nnz, - std::vector> const& Ai, - std::span& Bp) { + std::vector> const& Ai, + tcb::span& Bp) { assert(nnz == sum_over_size_(Ai)); assert(Bp.size() == n_row + 1); assert(tp->concurrency_level() >= 1); @@ -216,7 +216,7 @@ void count_rows_( * always zero). */ template -void sum_rows_to_pointers_(std::span& Bp) { +void sum_rows_to_pointers_(tcb::span& Bp) { CSX_MAJOR_IDX cumsum = 0; for (uint64_t i = 0; i < Bp.size(); i++) { auto temp = Bp[i]; @@ -234,12 +234,12 @@ void compress_coo_inner_left_( const uint64_t& row_partition, const int& partition_bits, const uint64_t& n_col, - std::span& Ai_, - std::span& Aj_, - std::span& Ad_, - std::span& Bp, - std::span& Bj, - std::span& Bd) { + tcb::span& Ai_, + tcb::span& Aj_, + tcb::span& Ad_, + tcb::span& Bp, + tcb::span& Bj, + tcb::span& Bd) { for (auto n = 0UL; n < (Ai_.size() / 2); ++n) { const std::make_unsigned_t row = Ai_[n]; if ((row >> partition_bits) != row_partition) @@ -266,12 +266,12 @@ void compress_coo_inner_right_( unsigned int row_partition, unsigned int partition_bits, uint64_t n_col, - std::span& Ai_, - std::span& Aj_, - std::span& Ad_, - std::span& Bp, - std::span& Bj, - std::span& Bd) { + tcb::span& Ai_, + tcb::span& Aj_, + tcb::span& Ad_, + tcb::span& Bp, + tcb::span& Bj, + tcb::span& Bd) { for (auto n = (Ai_.size() / 2); n < Ai_.size(); ++n) { const std::make_unsigned_t row = Ai_[n]; if ((row >> partition_bits) != row_partition) { @@ -312,12 +312,12 @@ void compress_coo( ThreadPool* const tp, const Shape& shape, uint64_t nnz, - const std::vector>& Ai, - const std::vector>& Aj, - const std::vector>& Ad, - std::span Bp, - std::span Bj, - std::span Bd) { + const std::vector>& Ai, + const std::vector>& Aj, + const std::vector>& Ad, + tcb::span Bp, + tcb::span Bj, + tcb::span Bd) { auto n_row = shape.first; auto n_col = shape.second; assert(Ai.size() == Aj.size() && Aj.size() == Ad.size()); @@ -336,8 +336,8 @@ void compress_coo( std::vector Bp_left(Bp.begin(), Bp.end() - 1); std::vector Bp_right(Bp.begin() + 1, Bp.end()); - std::span Bp_left_span{Bp_left}; - std::span Bp_right_span{Bp_right}; + tcb::span Bp_left_span{Bp_left}; + tcb::span Bp_right_span{Bp_right}; // Parallel, lock-free copy of all minor index and data values. Partitioned // by contiguous major dimension (Ai) values, minimizing the write @@ -420,9 +420,9 @@ void sort_csx_indices( ThreadPool* const tp, uint64_t n_row, uint64_t nnz, - const std::span Bp, - std::span Bj, - std::span Bd) { + const tcb::span Bp, + tcb::span Bj, + tcb::span Bd) { assert(Bp.size() == n_row + 1); assert(Bj.size() == nnz); assert(Bd.size() == nnz); @@ -467,10 +467,10 @@ void copy_csx_to_dense( uint64_t major_end, const Shape& shape, Format cm_format, - const std::span& Bp, - const std::span& Bj, - const std::span& Bd, - std::span out) { + const tcb::span& Bp, + const tcb::span& Bj, + const tcb::span& Bd, + tcb::span out) { auto [n_row, n_col] = shape; assert(Bp.size() > ((cm_format == Format::CSR) ? n_row : n_col)); assert(major_start <= ((cm_format == Format::CSR) ? n_row : n_col)); diff --git a/libtiledbsoma/src/utils/util.cc b/libtiledbsoma/src/utils/util.cc index ea8a01ff83..550aa593d6 100644 --- a/libtiledbsoma/src/utils/util.cc +++ b/libtiledbsoma/src/utils/util.cc @@ -76,7 +76,7 @@ std::string rstrip_uri(std::string_view uri) { std::vector cast_bit_to_uint8(ArrowSchema* schema, ArrowArray* array) { if (strcmp(schema->format, "b") != 0) { - throw TileDBSOMAError(std::format( + throw TileDBSOMAError(fmt::format( "_cast_bit_to_uint8 expected column format to be 'b' but saw {}", schema->format)); } diff --git a/libtiledbsoma/src/utils/util.h b/libtiledbsoma/src/utils/util.h index 249e1b407c..25a3a3cf3d 100644 --- a/libtiledbsoma/src/utils/util.h +++ b/libtiledbsoma/src/utils/util.h @@ -34,8 +34,8 @@ #define UTIL_H #include -#include #include // for windows: error C2039: 'runtime_error': is not a member of 'std' +#include "span/span.hpp" #include "arrow_adapter.h" #include "common.h" @@ -48,7 +48,7 @@ template VarlenBufferPair to_varlen_buffers(std::vector data, bool arrow = true); template -std::vector to_vector(const std::span& s) { +std::vector to_vector(const tcb::span& s) { return std::vector(s.begin(), s.end()); } diff --git a/libtiledbsoma/src/utils/version.cc b/libtiledbsoma/src/utils/version.cc index 23ff1ff471..7e69e1c4cc 100644 --- a/libtiledbsoma/src/utils/version.cc +++ b/libtiledbsoma/src/utils/version.cc @@ -38,7 +38,7 @@ namespace tiledbsoma::version { std::string as_string() { int major, minor, patch; tiledb_version(&major, &minor, &patch); - return std::format("libtiledb={}.{}.{}", major, minor, patch); + return fmt::format("libtiledb={}.{}.{}", major, minor, patch); } std::tuple embedded_version_triple() { diff --git a/libtiledbsoma/test/common.cc b/libtiledbsoma/test/common.cc index d194626783..650cd0781a 100644 --- a/libtiledbsoma/test/common.cc +++ b/libtiledbsoma/test/common.cc @@ -123,7 +123,7 @@ create_arrow_schema_and_index_columns( // Create index-column info only, no schema involving the attrs ArrowTable create_column_index_info(const std::vector& dim_infos) { for (auto info : dim_infos) { - LOG_DEBUG(std::format( + LOG_DEBUG(fmt::format( "create_column_index_info name={} type={} dim_max={}", info.name, tiledb::impl::to_str(info.tiledb_datatype), diff --git a/libtiledbsoma/test/unit_soma_array.cc b/libtiledbsoma/test/unit_soma_array.cc index d5f09b719f..afed51ba76 100644 --- a/libtiledbsoma/test/unit_soma_array.cc +++ b/libtiledbsoma/test/unit_soma_array.cc @@ -39,7 +39,6 @@ #include #include #include -#include #include #include @@ -191,11 +190,14 @@ TEST_CASE("SOMAArray: nnz") { const char* dim_name = "d0"; const char* attr_name = "a0"; - SECTION(std::format( - "- fragments={}, overlap={}, allow_duplicates={}", - num_fragments, - overlap, - allow_duplicates)) { + // TODO this use to be formatted with fmt::format which is part of internal + // header spd/log/fmt/fmt.h and should not be used. In C++20, this can be + // replaced with std::format. + std::ostringstream section; + section << "- fragments=" << num_fragments << ", overlap" << overlap + << ", allow_duplicates=" << allow_duplicates; + + SECTION(section.str()) { auto ctx = std::make_shared(); // Create array @@ -262,11 +264,14 @@ TEST_CASE("SOMAArray: nnz with timestamp") { auto allow_duplicates = true; int num_cells_per_fragment = 128; - SECTION(std::format( - "- fragments={}, overlap={}, allow_duplicates={}", - num_fragments, - overlap, - allow_duplicates)) { + // TODO this use to be formatted with fmt::format which is part of internal + // header spd/log/fmt/fmt.h and should not be used. In C++20, this can be + // replaced with std::format. + std::ostringstream section; + section << "- fragments=" << num_fragments << ", overlap" << overlap + << ", allow_duplicates=" << allow_duplicates; + + SECTION(section.str()) { auto ctx = std::make_shared(); // Create array @@ -312,11 +317,14 @@ TEST_CASE("SOMAArray: nnz with consolidation") { auto vacuum = GENERATE(false, true); int num_cells_per_fragment = 128; - SECTION(std::format( - "- fragments={}, overlap={}, allow_duplicates={}", - num_fragments, - overlap, - allow_duplicates)) { + // TODO this use to be formatted with fmt::format which is part of internal + // header spd/log/fmt/fmt.h and should not be used. In C++20, this can be + // replaced with std::format. + std::ostringstream section; + section << "- fragments=" << num_fragments << ", overlap" << overlap + << ", allow_duplicates=" << allow_duplicates; + + SECTION(section.str()) { auto ctx = std::make_shared(); // Create array diff --git a/libtiledbsoma/test/unit_soma_collection.cc b/libtiledbsoma/test/unit_soma_collection.cc index abcf1678f9..53293deb20 100644 --- a/libtiledbsoma/test/unit_soma_collection.cc +++ b/libtiledbsoma/test/unit_soma_collection.cc @@ -32,8 +32,6 @@ #include "common.h" -#include - static const int64_t DIM_MAX = 999; TEST_CASE("SOMACollection: basic") { diff --git a/libtiledbsoma/test/unit_soma_dataframe.cc b/libtiledbsoma/test/unit_soma_dataframe.cc index a1e28aaab2..a3529ca60d 100644 --- a/libtiledbsoma/test/unit_soma_dataframe.cc +++ b/libtiledbsoma/test/unit_soma_dataframe.cc @@ -30,7 +30,6 @@ * This file manages unit tests for the SOMADataFrame class */ -#include #include "common.h" const int64_t SOMA_JOINID_DIM_MAX = 99; @@ -294,7 +293,13 @@ TEST_CASE_METHOD( std::make_pair(R"("BYTESHUFFLE")", TILEDB_FILTER_BYTESHUFFLE), std::make_pair(R"("NOOP")", TILEDB_FILTER_NONE)); - SECTION(std::format("- filter={}", filter.first)) { + // TODO this used to be formatted with fmt::format which is part of internal + // header spd/log/fmt/fmt.h and should not be used. In C++20, this can be + // replaced with std::format. + std::ostringstream section; + section << "- filter=" << filter.first; + + SECTION(section.str()) { set_up( std::make_shared(), "mem://unit-test-dataframe-platform-config"); diff --git a/libtiledbsoma/test/unit_soma_dense_ndarray.cc b/libtiledbsoma/test/unit_soma_dense_ndarray.cc index 4d1aae7f9c..e366d2d178 100644 --- a/libtiledbsoma/test/unit_soma_dense_ndarray.cc +++ b/libtiledbsoma/test/unit_soma_dense_ndarray.cc @@ -30,7 +30,6 @@ * This file manages unit tests for the SOMADenseNDArray class */ -#include #include "common.h" TEST_CASE("SOMADenseNDArray: basic", "[SOMADenseNDArray]") { diff --git a/libtiledbsoma/test/unit_soma_geometry_dataframe.cc b/libtiledbsoma/test/unit_soma_geometry_dataframe.cc index b0c40eff6b..2afa6b2bdf 100644 --- a/libtiledbsoma/test/unit_soma_geometry_dataframe.cc +++ b/libtiledbsoma/test/unit_soma_geometry_dataframe.cc @@ -30,7 +30,6 @@ * This file manages unit tests for the SOMAGeometryDataFrame class */ -#include #include #include "../src/geometry/geometry.h" #include "../src/geometry/operators/io/write.h" diff --git a/libtiledbsoma/test/unit_soma_point_cloud_dataframe.cc b/libtiledbsoma/test/unit_soma_point_cloud_dataframe.cc index 3c3da91258..f603f4660a 100644 --- a/libtiledbsoma/test/unit_soma_point_cloud_dataframe.cc +++ b/libtiledbsoma/test/unit_soma_point_cloud_dataframe.cc @@ -30,7 +30,6 @@ * This file manages unit tests for the SOMAPointCloudDataFrame class */ -#include #include "common.h" const int64_t SOMA_JOINID_DIM_MAX = 99; diff --git a/libtiledbsoma/test/unit_soma_sparse_ndarray.cc b/libtiledbsoma/test/unit_soma_sparse_ndarray.cc index b386443213..9e5aa49537 100644 --- a/libtiledbsoma/test/unit_soma_sparse_ndarray.cc +++ b/libtiledbsoma/test/unit_soma_sparse_ndarray.cc @@ -30,7 +30,6 @@ * This file manages unit tests for the SOMASparseNDArray class */ -#include #include "common.h" TEST_CASE("SOMASparseNDArray: basic", "[SOMASparseNDArray]") {