feat(math): add with_storage template to tensor
This commit is contained in:
@@ -73,6 +73,25 @@ struct is_tensor_dynamic<tensor<T, dynamic_extent, Rest...>> : std::true_type {}
|
||||
template <typename T>
|
||||
static constexpr auto is_tensor_dynamic_v = is_tensor_dynamic<T>::value;
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <typename>
|
||||
struct tensor_with_storage {};
|
||||
|
||||
template <>
|
||||
struct tensor_with_storage<heap_storage_tag> {
|
||||
template <typename T, std::size_t... Dims>
|
||||
using type = tensor<detach_storage_t<T>, Dims...>;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct tensor_with_storage<inline_storage_tag> {
|
||||
template <typename T, std::size_t... Dims>
|
||||
using type = tensor<inline_storage<detach_storage_t<T>>, Dims...>;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <typename T>
|
||||
struct tensor_traits {};
|
||||
|
||||
@@ -91,6 +110,9 @@ struct tensor_traits<tensor<T, Dims...>> {
|
||||
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 <typename ST>
|
||||
using with_storage_t = typename detail::tensor_with_storage<ST>::type;
|
||||
};
|
||||
|
||||
} // namespace math
|
||||
|
||||
Reference in New Issue
Block a user