From 75243e9d0850c7d213f0390fd574b9dddfd0867f Mon Sep 17 00:00:00 2001 From: CHatingPython Date: Sun, 1 Nov 2026 09:59:06 +0100 Subject: [PATCH] feat(math): add with_storage template to tensor --- include/cenet/math/tensor.hpp | 3 +++ include/cenet/math/tensor_fwd.hpp | 3 +++ include/cenet/math/tensor_traits.hpp | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/include/cenet/math/tensor.hpp b/include/cenet/math/tensor.hpp index dfaa9e4..e8efbc3 100644 --- a/include/cenet/math/tensor.hpp +++ b/include/cenet/math/tensor.hpp @@ -25,6 +25,9 @@ public: using view_type = tensor_view; using constant_view_type = tensor_view; using shape_type = std::conditional_t, static_shape>; +public: + template + using with_storage = typename traits::template with_storage_t; public: tensor() { if constexpr (traits::dynamic) { diff --git a/include/cenet/math/tensor_fwd.hpp b/include/cenet/math/tensor_fwd.hpp index 9e3a92c..d42ae42 100644 --- a/include/cenet/math/tensor_fwd.hpp +++ b/include/cenet/math/tensor_fwd.hpp @@ -14,6 +14,9 @@ struct inline_storage { using value_type = T; }; +struct heap_storage_tag {}; +struct inline_storage_tag {}; + template class tensor_view; diff --git a/include/cenet/math/tensor_traits.hpp b/include/cenet/math/tensor_traits.hpp index 46997cb..5a410df 100644 --- a/include/cenet/math/tensor_traits.hpp +++ b/include/cenet/math/tensor_traits.hpp @@ -73,6 +73,25 @@ struct is_tensor_dynamic> : std::true_type {} template static constexpr auto is_tensor_dynamic_v = is_tensor_dynamic::value; +namespace detail { + +template +struct tensor_with_storage {}; + +template <> +struct tensor_with_storage { + template + using type = tensor, Dims...>; +}; + +template <> +struct tensor_with_storage { + template + using type = tensor>, Dims...>; +}; + +} // namespace detail + template struct tensor_traits {}; @@ -91,6 +110,9 @@ struct tensor_traits> { static constexpr std::enable_if_t<(sizeof...(Dims) > 0), std::size_t[sizeof...(Dims)]> dimensions = { Dims... }; static constexpr std::size_t size = dynamic ? dynamic_extent : (Dims * ... * 1); + + template + using with_storage_t = typename detail::tensor_with_storage::type; }; } // namespace math