From b40141a6192932116072fa6db7113ba0ed35a2d6 Mon Sep 17 00:00:00 2001 From: Kor de Jong Date: Wed, 14 Aug 2024 10:02:09 +0200 Subject: [PATCH] Run all pre-commit hooks on all files --- .pre-commit-config.yaml | 1 + .../gdal/include/lue/gdal/library.hpp | 19 ++++++--------- .../hdf5/include/lue/hdf5/offset.hpp | 24 +++++++++---------- source/framework/api/c/doc/index.md | 1 + .../api/c/include/lue/framework/api/c/io.h | 2 +- source/framework/api/c/src/field.cpp | 2 +- source/framework/api/c/src/future.cpp | 2 +- source/framework/api/c/src/io.cpp | 8 +++---- .../framework/api/c/src/local_operation.cpp | 2 +- .../api/c/test/local_operation_test.cpp | 1 - source/framework/api/cxx/doc/index.md | 19 +++++++++++---- .../include/lue/framework/api/cxx/literal.hpp | 1 - .../include/lue/framework/api/cxx/scalar.hpp | 3 +-- .../lue/framework/api/cxx/variant_wrapper.hpp | 23 ++++++++++-------- .../framework/api/cxx/src/create_scalar.cpp | 7 ++---- .../api/cxx/test/create_scalar_test.cpp | 2 +- source/framework/api/python/doc/index.md | 1 + source/framework/api/python/src/scalar.cpp | 9 +++---- 18 files changed, 63 insertions(+), 64 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 406648480..587ab52fc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -71,6 +71,7 @@ repos: exclude: | (?x)^( source/data_model/cxx/.*| + source/data_model/gdal/include/lue/gdal/library.hpp| source/data_model/hl/.*| source/data_model/python/.*| source/data_model/test/.*| diff --git a/source/data_model/gdal/include/lue/gdal/library.hpp b/source/data_model/gdal/include/lue/gdal/library.hpp index c2c90b6ee..edd3a721b 100644 --- a/source/data_model/gdal/include/lue/gdal/library.hpp +++ b/source/data_model/gdal/include/lue/gdal/library.hpp @@ -14,22 +14,17 @@ namespace lue::gdal { template void verify_support() { - if constexpr ( - (std::is_same_v || std::is_same_v) && - !supports_64bit_integers) + if constexpr ((std::is_same_v || + std::is_same_v)&&!supports_64bit_integers) { - throw std::runtime_error( - "The GDAL library doesn't support I/O of 64-bit integrals. " - "Upgrade GDAL to version ≥ 3.5.0."); + throw std::runtime_error("The GDAL library doesn't support I/O of 64-bit integrals. " + "Upgrade GDAL to version ≥ 3.5.0."); } - if constexpr ( - std::is_same_v && - !supports_8bit_signed_integers) + if constexpr (std::is_same_v && !supports_8bit_signed_integers) { - throw std::runtime_error( - "The GDAL library doesn't support I/O of signed 8-bit integrals. " - "Upgrade GDAL to version ≥ 3.7.0."); + throw std::runtime_error("The GDAL library doesn't support I/O of signed 8-bit integrals. " + "Upgrade GDAL to version ≥ 3.7.0."); } } diff --git a/source/data_model/hdf5/include/lue/hdf5/offset.hpp b/source/data_model/hdf5/include/lue/hdf5/offset.hpp index 75ebbf8e8..602408c43 100644 --- a/source/data_model/hdf5/include/lue/hdf5/offset.hpp +++ b/source/data_model/hdf5/include/lue/hdf5/offset.hpp @@ -3,19 +3,17 @@ #include -namespace lue { - namespace hdf5 { +namespace lue::hdf5 { - /*! - @brief Class for instances representing offsets in each dimension - @sa Stride, Count + /*! + @brief Class for instances representing offsets in each dimension + @sa Stride, Count - Using this class instead of HDF5's `hsize_t const*` is more type-safe. - */ - class Offset: public std::vector<::hsize_t> - { - using std::vector<::hsize_t>::vector; - }; + Using this class instead of HDF5's `hsize_t const*` is more type-safe. + */ + class Offset: public std::vector<::hsize_t> + { + using std::vector<::hsize_t>::vector; + }; - } // namespace hdf5 -} // namespace lue +} // namespace lue::hdf5 diff --git a/source/framework/api/c/doc/index.md b/source/framework/api/c/doc/index.md index 401fb64e7..21c715674 100644 --- a/source/framework/api/c/doc/index.md +++ b/source/framework/api/c/doc/index.md @@ -1,3 +1,4 @@ Inspiration: + - https://isocpp.org/wiki/faq/mixing-c-and-cpp - https://nachtimwald.com/2017/08/18/wrapping-c-objects-in-c/ diff --git a/source/framework/api/c/include/lue/framework/api/c/io.h b/source/framework/api/c/include/lue/framework/api/c/io.h index f34a6de7a..343ffbf30 100644 --- a/source/framework/api/c/include/lue/framework/api/c/io.h +++ b/source/framework/api/c/include/lue/framework/api/c/io.h @@ -10,7 +10,7 @@ extern "C" { LUE_FCAPI_EXPORT Field* from_gdal(char const* name); -LUE_FCAPI_EXPORT void to_gdal(Field const* field, char const* name, char const* clone_name=nullptr); +LUE_FCAPI_EXPORT void to_gdal(Field const* field, char const* name, char const* clone_name = nullptr); #ifdef __cplusplus diff --git a/source/framework/api/c/src/field.cpp b/source/framework/api/c/src/field.cpp index 664e22015..e3adae254 100644 --- a/source/framework/api/c/src/field.cpp +++ b/source/framework/api/c/src/field.cpp @@ -1,6 +1,6 @@ #include "lue/framework/api/c/field.h" -#include "lue/framework/api/cxx/field.hpp" #include "field.hpp" +#include "lue/framework/api/cxx/field.hpp" void destruct_field(Field* field) diff --git a/source/framework/api/c/src/future.cpp b/source/framework/api/c/src/future.cpp index f4f810415..5cf5b2ce1 100644 --- a/source/framework/api/c/src/future.cpp +++ b/source/framework/api/c/src/future.cpp @@ -1,6 +1,6 @@ #include "lue/framework/api/c/future.h" -#include "lue/framework/api/cxx/future.hpp" #include "future.hpp" +#include "lue/framework/api/cxx/future.hpp" void destruct_future(Future* future) diff --git a/source/framework/api/c/src/io.cpp b/source/framework/api/c/src/io.cpp index 752cda99b..15818b369 100644 --- a/source/framework/api/c/src/io.cpp +++ b/source/framework/api/c/src/io.cpp @@ -1,6 +1,6 @@ #include "lue/framework/api/c/io.h" -#include "lue/framework/api/cxx/io.hpp" #include "field.hpp" +#include "lue/framework/api/cxx/io.hpp" auto from_gdal(char const* name) -> Field* @@ -14,9 +14,9 @@ auto from_gdal(char const* name) -> Field* void to_gdal(Field* field, char const* name, char const* clone_name) { hpx::future result = clone_name == nullptr - ? lue::api::to_gdal(as_cxx_field(field), name) - : lue::api::to_gdal(as_cxx_field(field), name, clone_name); - ; + ? lue::api::to_gdal(as_cxx_field(field), name) + : lue::api::to_gdal(as_cxx_field(field), name, clone_name); + ; // TODO What to return? The caller may need the future... /* return new Future{.instance = new hpx::future{std::move(result)}}; */ diff --git a/source/framework/api/c/src/local_operation.cpp b/source/framework/api/c/src/local_operation.cpp index 697d7f624..7c0055280 100644 --- a/source/framework/api/c/src/local_operation.cpp +++ b/source/framework/api/c/src/local_operation.cpp @@ -1,6 +1,6 @@ #include "lue/framework/api/c/local_operation.h" -#include "lue/framework/api/cxx/local_operation.hpp" #include "field.hpp" +#include "lue/framework/api/cxx/local_operation.hpp" auto add(Field const* field1, Field const* field2) -> Field* diff --git a/source/framework/api/c/test/local_operation_test.cpp b/source/framework/api/c/test/local_operation_test.cpp index 8aae3471b..4a754db6c 100644 --- a/source/framework/api/c/test/local_operation_test.cpp +++ b/source/framework/api/c/test/local_operation_test.cpp @@ -9,7 +9,6 @@ BOOST_AUTO_TEST_CASE(add_raster_raster) } - // #include "lue/framework/api/c/local_operation.h" // // diff --git a/source/framework/api/cxx/doc/index.md b/source/framework/api/cxx/doc/index.md index 5c5c00691..da0dc33df 100644 --- a/source/framework/api/cxx/doc/index.md +++ b/source/framework/api/cxx/doc/index.md @@ -5,16 +5,19 @@ keeps attached to variables as long as possible. 1. Keep type info as long as possible -2. Support easy conversion from specialized types to general types: +1. Support easy conversion from specialized types to general types: + - scalar / array → field - The other way around is not needed(?) - → Is this permanent? Maybe the specialized type is still needed? + - Is this permanent? Maybe the specialized type is still needed? + - Can we store a variant in a variant and have the visit recurse to the leave type? - `Field = variant` - → Maybe have an overload ourselves that calls visit on the joint variant of any variants and concrete + - Maybe have an overload ourselves that calls visit on the joint variant of any variants and concrete types passed in + 1. Define Field variant as a combinations of Array and Scalar variants, and concrete types - 2. Before using a Field instance, `flatten` the Field variant type to a variant type that does not + 1. Before using a Field instance, `flatten` the Field variant type to a variant type that does not contain nested variants. The API user use Field, Array, Scalar instances, but the algorithms use concrete types. The C++ API must translate types from general to concrete and call the correct overloads. @@ -22,12 +25,14 @@ - C++: automatic conversion(?) - Python: automatic conversion(?) - C: + - `auto scalar_as_field(scalar) -> Field` - `auto array_as_field(array) -> Field` - How about the element type info? A scalar / array is still a family of concrete types. Don't mix: + - construct / destruct - create / destroy - new / delete @@ -35,17 +40,21 @@ Don't mix: C++ variant types (Scalar, Array, ...) can be created using a `create_` function, returning an instance of that variant type. + - Python: Use this function in the custom constructor of a class wrapper - C: Use this function from the C equivalent of the `create_` function -→ Pro: no need for templates, single create function for given set of arguments +- → Pro: no need for templates, single create function for given set of arguments Destruction happens in the destructor of the variant type: + - Python: happens automatically - C: Call `destroy_ @@ -31,7 +31,6 @@ namespace lue::api { public: using VariantWrapper::VariantWrapper; - }; } // namespace lue::api diff --git a/source/framework/api/cxx/include/lue/framework/api/cxx/variant_wrapper.hpp b/source/framework/api/cxx/include/lue/framework/api/cxx/variant_wrapper.hpp index c8d15ee42..00a5f4052 100644 --- a/source/framework/api/cxx/include/lue/framework/api/cxx/variant_wrapper.hpp +++ b/source/framework/api/cxx/include/lue/framework/api/cxx/variant_wrapper.hpp @@ -1,23 +1,24 @@ #pragma once -#include #include +#include namespace lue::api { namespace detail { - template struct is_one_of; + template + struct is_one_of; template inline constexpr bool is_one_of_v = is_one_of::value; - template - struct is_one_of>: - std::bool_constant<(std::is_same_v || ...)> - { }; + template + struct is_one_of>: std::bool_constant<(std::is_same_v || ...)> + { + }; - } + } // namespace detail /*! @@ -31,7 +32,10 @@ namespace lue::api { Copying is disabled. */ - template class VariantWrapper { public: + template + class VariantWrapper + { + public: using Variant = std::variant; @@ -46,8 +50,7 @@ namespace lue::api { template - requires is_allowed_v - VariantWrapper(T&& value): + requires is_allowed_v VariantWrapper(T&& value): _variant{std::forward(value)} diff --git a/source/framework/api/cxx/src/create_scalar.cpp b/source/framework/api/cxx/src/create_scalar.cpp index c01700496..da192a136 100644 --- a/source/framework/api/cxx/src/create_scalar.cpp +++ b/source/framework/api/cxx/src/create_scalar.cpp @@ -6,8 +6,7 @@ namespace lue { - template< - Arithmetic T> + template auto create_scalar(T const& value) -> lue::Scalar { return lue::Scalar{value}; @@ -22,9 +21,7 @@ namespace lue { auto create_scalar(Literal const& value) -> Field { return std::visit( - overload{[](auto const& value) -> Field { - return lue::create_scalar(value); - }}, + overload{[](auto const& value) -> Field { return lue::create_scalar(value); }}, value.variant()); } diff --git a/source/framework/api/cxx/test/create_scalar_test.cpp b/source/framework/api/cxx/test/create_scalar_test.cpp index eb6127ad0..d10de91ea 100644 --- a/source/framework/api/cxx/test/create_scalar_test.cpp +++ b/source/framework/api/cxx/test/create_scalar_test.cpp @@ -1,6 +1,6 @@ #define BOOST_TEST_MODULE lue framework api cxx create_scalar -#include "lue/framework/api/cxx/create_scalar.hpp" #include "lue/framework/algorithm/scalar.hpp" +#include "lue/framework/api/cxx/create_scalar.hpp" #include "lue/framework/test/hpx_unit_test.hpp" diff --git a/source/framework/api/python/doc/index.md b/source/framework/api/python/doc/index.md index 916b6934e..54cd475ba 100644 --- a/source/framework/api/python/doc/index.md +++ b/source/framework/api/python/doc/index.md @@ -1,4 +1,5 @@ Goals: + - Keep the amount of code needed to get the Python package working correctly and conveniently as small as possible - Keep the amount of (public) documentation needed as small as possible diff --git a/source/framework/api/python/src/scalar.cpp b/source/framework/api/python/src/scalar.cpp index b54068808..f02329736 100644 --- a/source/framework/api/python/src/scalar.cpp +++ b/source/framework/api/python/src/scalar.cpp @@ -1,5 +1,5 @@ -#include "lue/framework/api/cxx/create_scalar.hpp" #include "lue/framework/api/cxx/scalar.hpp" +#include "lue/framework/api/cxx/create_scalar.hpp" #include #include @@ -90,8 +90,7 @@ namespace lue::api { if (!field) { - throw std::runtime_error(fmt::format("Unsupported dtype (kind={}, itemsize={})", kind, - size)); + throw std::runtime_error(fmt::format("Unsupported dtype (kind={}, itemsize={})", kind, size)); } return std::move(*field); @@ -104,9 +103,7 @@ namespace lue::api { { module.def( "create_scalar", - []( - double const value, - pybind11::object const& dtype_args) -> Field + [](double const value, pybind11::object const& dtype_args) -> Field { pybind11::dtype const dtype{pybind11::dtype::from_args(dtype_args)};