Skip to content

Commit

Permalink
added xtensor concepts to helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-urban committed Sep 25, 2024
1 parent c8836cf commit eaa8fa9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ project(
'cpp',
license: 'MPL-2.0',

version: '0.26.0',
version: '0.26.1',
default_options: ['warning_level=2', 'buildtype=release', 'cpp_std=c++20'],
meson_version: '>=1.3.2' #first version with clang-cl openmp support,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//sourcehash: a92c6b06219423591cb330310b5abe491e03ee9d8aa81f35033deac7fed4254b
//sourcehash: 602bf533885ae0824124a7b756e69a5f9dc17740156c1fe014ceebfd78e6e36f

/*
This file contains docstrings for use in the Python bindings.
Expand Down Expand Up @@ -38,6 +38,8 @@
#endif


static const char *__doc_themachinethatgoesping_tools_helper_xtensor_datatype = R"doc()doc";

#if defined(__GNUG__)
#pragma GCC diagnostic pop
#endif
Expand Down
37 changes: 31 additions & 6 deletions src/themachinethatgoesping/tools/helper/xtensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,37 @@
#include <xtensor/xcontainer.hpp>

namespace themachinethatgoesping {
namespace tools {
namespace helper {
namespace tools {
namespace helper {

// define a xcontainer concept that works for both xtensor and pytensor
// // define a xcontainer concept that works for both xtensor and pytensor
// template<typename T>
// concept XContainerConcept = std::is_base_of<xt::xcontainer<T>, T>::value;

template<typename T>
concept c_xtensor = requires {
{ std::derived_from<T, xt::xexpression<typename T::derived_type>> };
{ std::tuple_size<typename T::shape_type>::value } -> std::convertible_to<std::size_t>;
};

template<typename T>
concept c_xtensor_2d =
c_xtensor<T> && requires { requires std::tuple_size<typename T::shape_type>::value == 2; };

template<typename T>
concept c_xtensor_1d =
c_xtensor<T> && requires { requires std::tuple_size<typename T::shape_type>::value == 1; };

// Type trait to extract the data type from an xtensor
template <typename T>
concept XContainerConcept = std::is_base_of<xt::xcontainer<T>, T>::value;
}
}
struct xtensor_datatype {
using type = std::decay_t<decltype(std::declval<T>()(0))>;
};

// Helper alias template
template <typename T>
using xtensor_datatype_t = typename xtensor_datatype<T>::type;

}
}
}

0 comments on commit eaa8fa9

Please sign in to comment.