Skip to content

Commit

Permalink
Run all pre-commit hooks on all files
Browse files Browse the repository at this point in the history
  • Loading branch information
kordejong committed Aug 14, 2024
1 parent c7c98a2 commit b40141a
Show file tree
Hide file tree
Showing 18 changed files with 63 additions and 64 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/.*|
Expand Down
19 changes: 7 additions & 12 deletions source/data_model/gdal/include/lue/gdal/library.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,17 @@ namespace lue::gdal {
template<typename Element>
void verify_support()
{
if constexpr (
(std::is_same_v<Element, std::int64_t> || std::is_same_v<Element, std::uint64_t>) &&
!supports_64bit_integers)
if constexpr ((std::is_same_v<Element, std::int64_t> ||
std::is_same_v<Element, std::uint64_t>)&&!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<Element, std::int8_t> &&
!supports_8bit_signed_integers)
if constexpr (std::is_same_v<Element, std::int8_t> && !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.");
}
}

Expand Down
24 changes: 11 additions & 13 deletions source/data_model/hdf5/include/lue/hdf5/offset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@
#include <vector>


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
1 change: 1 addition & 0 deletions source/framework/api/c/doc/index.md
Original file line number Diff line number Diff line change
@@ -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/
2 changes: 1 addition & 1 deletion source/framework/api/c/include/lue/framework/api/c/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion source/framework/api/c/src/field.cpp
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion source/framework/api/c/src/future.cpp
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
8 changes: 4 additions & 4 deletions source/framework/api/c/src/io.cpp
Original file line number Diff line number Diff line change
@@ -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*
Expand All @@ -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<void> 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<void>...
/* return new Future{.instance = new hpx::future<void>{std::move(result)}}; */
Expand Down
2 changes: 1 addition & 1 deletion source/framework/api/c/src/local_operation.cpp
Original file line number Diff line number Diff line change
@@ -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*
Expand Down
1 change: 0 additions & 1 deletion source/framework/api/c/test/local_operation_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ BOOST_AUTO_TEST_CASE(add_raster_raster)
}



// #include "lue/framework/api/c/local_operation.h"
//
//
Expand Down
19 changes: 14 additions & 5 deletions source/framework/api/cxx/doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,56 @@
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<Array, Scalar, Literal>`
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.

- 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
- alloc / free

C++ variant types (Scalar, Array, ...) can be created using a `create_<variant_type>` 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_<variant_type>` 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_<variant_type`, which can call `delete` on the layered opaque pointer

20240710

- Having different types for Literal, Scalar, Array, Field gets us into overload hell again. What about only
using Field instances and let overload resolution figure out what is supported (and document this so users
know what to expect).

- A field is a value that varies through time and over space, or not
- Some functions require a field's value to not vary
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ namespace lue::api {
public:

using VariantWrapper::VariantWrapper;

};

} // namespace lue::api
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include "lue/framework/api/cxx/variant_wrapper.hpp"
#include "lue/framework/algorithm/scalar.hpp"
#include "lue/framework/api/cxx/variant_wrapper.hpp"
#include <cstdint>


Expand Down Expand Up @@ -31,7 +31,6 @@ namespace lue::api {
public:

using VariantWrapper::VariantWrapper;

};

} // namespace lue::api
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
#pragma once
#include <variant>
#include <type_traits>
#include <variant>


namespace lue::api {

namespace detail {

template <class T, class U> struct is_one_of;
template<class T, class U>
struct is_one_of;

template<typename T, typename U>
inline constexpr bool is_one_of_v = is_one_of<T, U>::value;

template <class T, class... Ts>
struct is_one_of<T, std::variant<Ts...>>:
std::bool_constant<(std::is_same_v<T, Ts> || ...)>
{ };
template<class T, class... Ts>
struct is_one_of<T, std::variant<Ts...>>: std::bool_constant<(std::is_same_v<T, Ts> || ...)>
{
};

}
} // namespace detail


/*!
Expand All @@ -31,7 +32,10 @@ namespace lue::api {
Copying is disabled.
*/
template<typename... Ts> class VariantWrapper { public:
template<typename... Ts>
class VariantWrapper
{
public:

using Variant = std::variant<Ts...>;

Expand All @@ -46,8 +50,7 @@ namespace lue::api {


template<typename T>
requires is_allowed_v<T>
VariantWrapper(T&& value):
requires is_allowed_v<T> VariantWrapper(T&& value):

_variant{std::forward<T>(value)}

Expand Down
7 changes: 2 additions & 5 deletions source/framework/api/cxx/src/create_scalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

namespace lue {

template<
Arithmetic T>
template<Arithmetic T>
auto create_scalar(T const& value) -> lue::Scalar<T>
{
return lue::Scalar<T>{value};
Expand All @@ -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());
}

Expand Down
2 changes: 1 addition & 1 deletion source/framework/api/cxx/test/create_scalar_test.cpp
Original file line number Diff line number Diff line change
@@ -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"


Expand Down
1 change: 1 addition & 0 deletions source/framework/api/python/doc/index.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 3 additions & 6 deletions source/framework/api/python/src/scalar.cpp
Original file line number Diff line number Diff line change
@@ -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 <fmt/format.h>
#include <pybind11/numpy.h>

Expand Down Expand Up @@ -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);
Expand All @@ -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)};

Expand Down

0 comments on commit b40141a

Please sign in to comment.