kfr

Fast, modern C++ DSP framework, FFT, Sample Rate Conversion, FIR/IIR/Biquad Filters (SSE, AVX, AVX-512, ARM NEON)
Log | Files | Refs | README

commit 666320a28dc73b9b7d540dc1d02482b982101160
parent bf4b0e1189aa6a5e81ef97cfaec6bf694bf38c8b
Author: d.levin256@gmail.com <d.levin256@gmail.com>
Date:   Sat, 12 Nov 2022 22:48:18 +0000

Rename shapeof -> get_shape

Diffstat:
Mdocs/docs/expressions.md | 12++++++------
Minclude/kfr/base/basic_expressions.hpp | 84++++++++++++++++++++++++++++++++++++++++++-------------------------------------
Minclude/kfr/base/expression.hpp | 63++++++++++++++++++++++++++++++++-------------------------------
Minclude/kfr/base/filter.hpp | 2+-
Minclude/kfr/base/generators.hpp | 4++--
Minclude/kfr/base/handle.hpp | 12++++++------
Minclude/kfr/base/random.hpp | 8++++----
Minclude/kfr/base/reduce.hpp | 4++--
Minclude/kfr/base/tensor.hpp | 10+++++-----
Minclude/kfr/base/univector.hpp | 12++++++------
Minclude/kfr/dft/impl/dft-impl.hpp | 4++--
Minclude/kfr/dsp/delay.hpp | 12++++++------
Minclude/kfr/dsp/window.hpp | 4++--
Minclude/kfr/except.hpp | 1-
Mtests/unit/base/basic_expressions.cpp | 24++++++++++++------------
Mtests/unit/base/tensor.cpp | 22+++++++++++-----------
16 files changed, 142 insertions(+), 136 deletions(-)

diff --git a/docs/docs/expressions.md b/docs/docs/expressions.md @@ -104,12 +104,12 @@ struct expression_traits<identity_matrix<T, Size>> : expression_traits_defaults constexpr static size_t dims = 2; // function to retrieve shape (size) of matrix, runtime version - constexpr static shape<2> shapeof(const identity_matrix<T, Size>& self) { return { Size, Size }; } + constexpr static shape<2> get_shape(const identity_matrix<T, Size>& self) { return { Size, Size }; } // function to retrieve shape (size) of matrix, compile time version // if the size is unknown at compile time the function must be still defined // but return undefined_size for every axis with unknown size - constexpr static shape<2> shapeof() { return { Size, Size }; } + constexpr static shape<2> get_shape() { return { Size, Size }; } }; template <typename T, index_t Size, index_t Axis, size_t N> @@ -157,8 +157,8 @@ struct identity_matrix : expression_traits_defaults using value_type = T; constexpr static size_t dims = 2; - constexpr static shape<2> shapeof(const identity_matrix& self) { return { Size, Size }; } - constexpr static shape<2> shapeof() { return { Size, Size }; } + constexpr static shape<2> get_shape(const identity_matrix& self) { return { Size, Size }; } + constexpr static shape<2> get_shape() { return { Size, Size }; } template <index_t Axis, size_t N> friend vec<T, N> get_elements(const identity_matrix& self, const shape<2>& index, @@ -179,9 +179,9 @@ struct identity_matrix : expression_traits_defaults using value_type = T; constexpr static size_t dims = 2; - constexpr static shape<2> shapeof(const identity_matrix& self) { return { self.size, self.size }; } + constexpr static shape<2> get_shape(const identity_matrix& self) { return { self.size, self.size }; } // undefined_size means size is not known at compile time - constexpr static shape<2> shapeof() { return { undefined_size, undefined_size }; } + constexpr static shape<2> get_shape() { return { undefined_size, undefined_size }; } template <index_t Axis, size_t N> friend vec<T, N> get_elements(const identity_matrix& self, const shape<2>& index, diff --git a/include/kfr/base/basic_expressions.hpp b/include/kfr/base/basic_expressions.hpp @@ -43,8 +43,8 @@ struct expression_traits<expression_scalar<T>> : expression_traits_defaults using value_type = T; constexpr static size_t dims = 0; - constexpr static shape<0> shapeof(const expression_scalar<T>& self) { return {}; } - constexpr static shape<0> shapeof() { return {}; } + constexpr static shape<0> get_shape(const expression_scalar<T>& self) { return {}; } + constexpr static shape<0> get_shape() { return {}; } }; template <typename T> @@ -93,11 +93,11 @@ struct expression_traits<expression_counter<T, Dims>> : expression_traits_defaul using value_type = T; constexpr static size_t dims = Dims; - constexpr static shape<dims> shapeof(const expression_counter<T, Dims>& self) + constexpr static shape<dims> get_shape(const expression_counter<T, Dims>& self) { return shape<dims>(infinite_size); } - constexpr static shape<dims> shapeof() { return shape<dims>(infinite_size); } + constexpr static shape<dims> get_shape() { return shape<dims>(infinite_size); } }; template <typename T = int, typename Arg = T, typename... Args, @@ -162,11 +162,11 @@ struct expression_traits<expression_slice<Arg>> : expression_traits_defaults constexpr static size_t dims = ArgTraits::dims; constexpr static bool random_access = ArgTraits::random_access; - KFR_MEM_INTRINSIC constexpr static shape<dims> shapeof(const expression_slice<Arg>& self) + KFR_MEM_INTRINSIC constexpr static shape<dims> get_shape(const expression_slice<Arg>& self) { - return min(sub_shape(ArgTraits::shapeof(self.first()), self.start), self.size); + return min(sub_shape(ArgTraits::get_shape(self.first()), self.start), self.size); } - KFR_MEM_INTRINSIC constexpr static shape<dims> shapeof() { return shape<dims>(undefined_size); } + KFR_MEM_INTRINSIC constexpr static shape<dims> get_shape() { return shape<dims>(undefined_size); } }; template <typename Arg, KFR_ACCEPT_EXPRESSIONS(Arg), index_t Dims = expression_dims<Arg>> @@ -221,11 +221,11 @@ struct expression_traits<expression_cast<T, Arg>> : expression_traits_defaults constexpr static size_t dims = ArgTraits::dims; constexpr static bool random_access = ArgTraits::random_access; - KFR_MEM_INTRINSIC constexpr static shape<dims> shapeof(const expression_cast<T, Arg>& self) + KFR_MEM_INTRINSIC constexpr static shape<dims> get_shape(const expression_cast<T, Arg>& self) { - return ArgTraits::shapeof(self.first()); + return ArgTraits::get_shape(self.first()); } - KFR_MEM_INTRINSIC constexpr static shape<dims> shapeof() { return ArgTraits::shapeof(); } + KFR_MEM_INTRINSIC constexpr static shape<dims> get_shape() { return ArgTraits::get_shape(); } }; template <typename T, typename Arg, KFR_ACCEPT_EXPRESSIONS(Arg)> @@ -273,11 +273,11 @@ struct expression_traits<expression_lambda<T, Dims, Fn, Rnd>> : expression_trait constexpr static size_t dims = Dims; constexpr static inline bool random_access = Rnd; - KFR_MEM_INTRINSIC constexpr static shape<Dims> shapeof(const expression_lambda<T, Dims, Fn, Rnd>& self) + KFR_MEM_INTRINSIC constexpr static shape<Dims> get_shape(const expression_lambda<T, Dims, Fn, Rnd>& self) { return shape<Dims>(infinite_size); } - KFR_MEM_INTRINSIC constexpr static shape<Dims> shapeof() { return shape<Dims>(infinite_size); } + KFR_MEM_INTRINSIC constexpr static shape<Dims> get_shape() { return shape<Dims>(infinite_size); } }; template <typename T, index_t Dims = 1, typename Fn, bool RandomAccess = true> @@ -346,7 +346,7 @@ struct expression_padded : public expression_with_arguments<Arg> KFR_MEM_INTRINSIC expression_padded(Arg&& arg, typename ArgTraits::value_type fill_value) : expression_with_arguments<Arg>{ std::forward<Arg>(arg) }, fill_value(std::move(fill_value)), - input_shape(ArgTraits::shapeof(this->first())) + input_shape(ArgTraits::get_shape(this->first())) { } }; @@ -367,11 +367,11 @@ struct expression_traits<expression_padded<Arg>> : expression_traits_defaults constexpr static size_t dims = ArgTraits::dims; constexpr static bool random_access = ArgTraits::random_access; - KFR_MEM_INTRINSIC constexpr static shape<dims> shapeof(const expression_padded<Arg>& self) + KFR_MEM_INTRINSIC constexpr static shape<dims> get_shape(const expression_padded<Arg>& self) { return shape<dims>(infinite_size); } - KFR_MEM_INTRINSIC constexpr static shape<dims> shapeof() { return shape<dims>(infinite_size); } + KFR_MEM_INTRINSIC constexpr static shape<dims> get_shape() { return shape<dims>(infinite_size); } }; inline namespace CMT_ARCH_NAME @@ -415,7 +415,7 @@ struct expression_reverse : public expression_with_arguments<Arg> KFR_MEM_INTRINSIC expression_reverse(Arg&& arg) : expression_with_arguments<Arg>{ std::forward<Arg>(arg) }, - input_shape(ArgTraits::shapeof(this->first())) + input_shape(ArgTraits::get_shape(this->first())) { } }; @@ -436,11 +436,11 @@ struct expression_traits<expression_reverse<Arg>> : expression_traits_defaults constexpr static size_t dims = ArgTraits::dims; static_assert(ArgTraits::random_access, "expression_reverse requires an expression with random access"); - KFR_MEM_INTRINSIC constexpr static shape<dims> shapeof(const expression_reverse<Arg>& self) + KFR_MEM_INTRINSIC constexpr static shape<dims> get_shape(const expression_reverse<Arg>& self) { - return ArgTraits::shapeof(self.first()); + return ArgTraits::get_shape(self.first()); } - KFR_MEM_INTRINSIC constexpr static shape<dims> shapeof() { return ArgTraits::shapeof(); } + KFR_MEM_INTRINSIC constexpr static shape<dims> get_shape() { return ArgTraits::get_shape(); } }; inline namespace CMT_ARCH_NAME @@ -495,12 +495,15 @@ struct expression_traits<expression_fixshape<Arg, fixed_shape_t<ShapeValues...>> constexpr static size_t dims = sizeof...(ShapeValues); // ArgTraits::dims; constexpr static bool random_access = ArgTraits::random_access; - KFR_MEM_INTRINSIC constexpr static shape<dims> shapeof( + KFR_MEM_INTRINSIC constexpr static shape<dims> get_shape( const expression_fixshape<Arg, fixed_shape_t<ShapeValues...>>& self) { return fixed_shape_t<ShapeValues...>::get(); } - KFR_MEM_INTRINSIC constexpr static shape<dims> shapeof() { return fixed_shape_t<ShapeValues...>::get(); } + KFR_MEM_INTRINSIC constexpr static shape<dims> get_shape() + { + return fixed_shape_t<ShapeValues...>::get(); + } }; inline namespace CMT_ARCH_NAME @@ -544,7 +547,7 @@ struct expression_reshape : public expression_with_arguments<Arg> shape<OutDims> out_shape; KFR_MEM_INTRINSIC expression_reshape(Arg&& arg, const shape<OutDims>& out_shape) - : expression_with_arguments<Arg>{ std::forward<Arg>(arg) }, in_shape(ArgTraits::shapeof(arg)), + : expression_with_arguments<Arg>{ std::forward<Arg>(arg) }, in_shape(ArgTraits::get_shape(arg)), out_shape(out_shape) { } @@ -565,11 +568,11 @@ struct expression_traits<expression_reshape<Arg, OutDims>> : expression_traits_d constexpr static size_t dims = OutDims; constexpr static bool random_access = ArgTraits::random_access; - KFR_MEM_INTRINSIC constexpr static shape<dims> shapeof(const expression_reshape<Arg, OutDims>& self) + KFR_MEM_INTRINSIC constexpr static shape<dims> get_shape(const expression_reshape<Arg, OutDims>& self) { return self.out_shape; } - KFR_MEM_INTRINSIC constexpr static shape<dims> shapeof() { return shape<dims>{ undefined_size }; } + KFR_MEM_INTRINSIC constexpr static shape<dims> get_shape() { return shape<dims>{ undefined_size }; } }; inline namespace CMT_ARCH_NAME @@ -712,11 +715,14 @@ struct expression_traits<expression_linspace<T, truncated>> : expression_traits_ using value_type = T; constexpr static size_t dims = 1; - constexpr static shape<dims> shapeof(const expression_linspace<T, truncated>& self) + constexpr static shape<dims> get_shape(const expression_linspace<T, truncated>& self) { return shape<dims>(truncated ? self.size : infinite_size); } - constexpr static shape<dims> shapeof() { return shape<dims>(truncated ? undefined_size : infinite_size); } + constexpr static shape<dims> get_shape() + { + return shape<dims>(truncated ? undefined_size : infinite_size); + } }; /** @brief Returns evenly spaced numbers over a specified interval. @@ -775,7 +781,7 @@ struct expression_concatenate : public expression_with_arguments<Arg1, Arg2> KFR_MEM_INTRINSIC expression_concatenate(Arg1&& arg1, Arg2&& arg2) : expression_with_arguments<Arg1, Arg2>{ std::forward<Arg1>(arg1), std::forward<Arg2>(arg2) }, - size1(expression_traits<Arg1>::shapeof(arg1)) + size1(expression_traits<Arg1>::get_shape(arg1)) { } }; @@ -798,15 +804,15 @@ struct expression_traits<expression_concatenate<Arg1, Arg2, ConcatAxis>> : expre return result; } - KFR_MEM_INTRINSIC constexpr static shape<dims> shapeof( + KFR_MEM_INTRINSIC constexpr static shape<dims> get_shape( const expression_concatenate<Arg1, Arg2, ConcatAxis>& self) { - return concat_shape(ArgTraits1::shapeof(std::get<0>(self.args)), - ArgTraits2::shapeof(std::get<1>(self.args))); + return concat_shape(ArgTraits1::get_shape(std::get<0>(self.args)), + ArgTraits2::get_shape(std::get<1>(self.args))); } - KFR_MEM_INTRINSIC constexpr static shape<dims> shapeof() + KFR_MEM_INTRINSIC constexpr static shape<dims> get_shape() { - return concat_shape(ArgTraits1::shapeof(), ArgTraits2::shapeof()); + return concat_shape(ArgTraits1::get_shape(), ArgTraits2::get_shape()); } }; @@ -915,11 +921,11 @@ struct expression_unpack : expression_with_arguments<E...>, expression_traits_de static_assert(((expression_dims<E> == dims) && ...)); static_assert(((std::is_same_v<expression_value_type<E>, first_value_type>)&&...)); - constexpr static shape<dims> shapeof(const expression_unpack& self) + constexpr static shape<dims> get_shape(const expression_unpack& self) { - return first_arg_traits::shapeof(self.first()); + return first_arg_traits::get_shape(self.first()); } - constexpr static shape<dims> shapeof() { return first_arg_traits::shapeof(); } + constexpr static shape<dims> get_shape() { return first_arg_traits::get_shape(); } expression_unpack(E&&... e) : expression_with_arguments<E...>(std::forward<E>(e)...) {} @@ -1032,13 +1038,13 @@ struct expression_dimensions : public expression_with_traits<E> constexpr static inline index_t dims = Dims; using first_arg_traits = typename expression_with_traits<E>::first_arg_traits; - constexpr static shape<dims> shapeof(const expression_dimensions& self) + constexpr static shape<dims> get_shape(const expression_dimensions& self) { - return first_arg_traits::shapeof(self.first()).template extend<dims>(infinite_size); + return first_arg_traits::get_shape(self.first()).template extend<dims>(infinite_size); } - constexpr static shape<dims> shapeof() + constexpr static shape<dims> get_shape() { - return first_arg_traits::shapeof().template extend<dims>(infinite_size); + return first_arg_traits::get_shape().template extend<dims>(infinite_size); } template <size_t N, index_t VecAxis> diff --git a/include/kfr/base/expression.hpp b/include/kfr/base/expression.hpp @@ -70,14 +70,14 @@ template <typename T> constexpr inline size_t expression_dims = expression_traits<T>::dims; template <typename T> -constexpr inline shape<expression_dims<T>> shapeof(T&& expr) +constexpr inline shape<expression_dims<T>> get_shape(T&& expr) { - return expression_traits<T>::shapeof(expr); + return expression_traits<T>::get_shape(expr); } template <typename T> -constexpr inline shape<expression_dims<T>> shapeof() +constexpr inline shape<expression_dims<T>> get_shape() { - return expression_traits<T>::shapeof(); + return expression_traits<T>::get_shape(); } template <typename T> @@ -104,12 +104,12 @@ struct expression_traits<const T&&, std::void_t<typename expression_traits<T>::v // This allows old style expressions+traits template <typename T> -struct expression_traits<T, std::void_t<decltype(T::random_access), decltype(T::shapeof())>> +struct expression_traits<T, std::void_t<decltype(T::random_access), decltype(T::get_shape())>> { using value_type = typename T::value_type; constexpr static size_t dims = T::dims; - constexpr static shape<dims> shapeof(const T& self) { return T::shapeof(self); } - constexpr static shape<dims> shapeof() { return T::shapeof(); } + constexpr static shape<dims> get_shape(const T& self) { return T::get_shape(self); } + constexpr static shape<dims> get_shape() { return T::get_shape(); } constexpr static inline bool explicit_operand = T::explicit_operand; constexpr static inline bool random_access = T::random_access; @@ -119,8 +119,8 @@ struct expression_traits_defaults { // using value_type = accepts_any; // constexpr static size_t dims = 0; - // constexpr static shape<dims> shapeof(const T&); - // constexpr static shape<dims> shapeof(); + // constexpr static shape<dims> get_shape(const T&); + // constexpr static shape<dims> get_shape(); constexpr static inline bool explicit_operand = true; constexpr static inline bool random_access = true; @@ -193,7 +193,7 @@ template <typename T> constexpr inline bool is_expr_element = std::is_same_v<std::remove_cv_t<T>, T>&& is_vec_element<T>; template <typename E> -constexpr inline bool is_infinite = expression_traits<E>::shapeof().has_infinity(); +constexpr inline bool is_infinite = expression_traits<E>::get_shape().has_infinity(); template <typename T> struct expression_traits<T, std::enable_if_t<is_expr_element<T>>> : expression_traits_defaults @@ -202,8 +202,8 @@ struct expression_traits<T, std::enable_if_t<is_expr_element<T>>> : expression_t constexpr static size_t dims = 0; constexpr static inline bool explicit_operand = false; - KFR_MEM_INTRINSIC constexpr static shape<0> shapeof(const T& self) { return {}; } - KFR_MEM_INTRINSIC constexpr static shape<0> shapeof() { return {}; } + KFR_MEM_INTRINSIC constexpr static shape<0> get_shape(const T& self) { return {}; } + KFR_MEM_INTRINSIC constexpr static shape<0> get_shape() { return {}; } }; template <typename E, enable_if_input_expression<E>* = nullptr, index_t Dims = expression_dims<E>> @@ -310,9 +310,9 @@ struct expression_with_arguments } else { - if constexpr (Traits::shapeof().cproduct() > 0) + if constexpr (Traits::get_shape().cproduct() > 0) { - return Traits::shapeof().tomask(); + return Traits::get_shape().tomask(); } else { @@ -338,7 +338,7 @@ struct expression_with_arguments [&](auto idx_) CMT_INLINE_LAMBDA { constexpr size_t idx = val_of(decltype(idx_)()); - shape sh = expression_traits<nth<idx>>::shapeof(std::get<idx>(this->args)); + shape sh = expression_traits<nth<idx>>::get_shape(std::get<idx>(this->args)); masks[idx] = sh.tomask(); }); } @@ -422,11 +422,11 @@ struct expression_with_traits : expression_with_arguments<Arg> using first_arg_traits = expression_traits<Arg>; using value_type = typename first_arg_traits::value_type; constexpr static size_t dims = first_arg_traits::dims; - constexpr static shape<dims> shapeof(const expression_with_traits& self) + constexpr static shape<dims> get_shape(const expression_with_traits& self) { - return first_arg_traits::shapeof(self.first()); + return first_arg_traits::get_shape(self.first()); } - constexpr static shape<dims> shapeof() { return first_arg_traits::shapeof(); } + constexpr static shape<dims> get_shape() { return first_arg_traits::get_shape(); } using expression_with_arguments<Arg>::expression_with_arguments; }; @@ -446,7 +446,7 @@ struct expression_function : expression_with_arguments<Args...>, expression_trai constexpr auto operator()(csize_t<idx>...) const { return internal_generic::common_shape( - expression_traits<typename expression_function::template nth<idx>>::shapeof()...); + expression_traits<typename expression_function::template nth<idx>>::get_shape()...); } }; struct lambda_get_shape_self @@ -455,27 +455,28 @@ struct expression_function : expression_with_arguments<Args...>, expression_trai template <typename... TArgs> constexpr auto operator()(const TArgs&... args) const { - return internal_generic::common_shape<true>(expression_traits<Args>::shapeof(args)...); + return internal_generic::common_shape<true>(expression_traits<Args>::get_shape(args)...); } }; - constexpr static shape<dims> shapeof(const expression_function& self) + constexpr static shape<dims> get_shape(const expression_function& self) { return self.fold(lambda_get_shape_self{ self }); } - constexpr static shape<dims> shapeof() { return expression_function::fold_idx(lambda_get_shape{}); } + constexpr static shape<dims> get_shape() { return expression_function::fold_idx(lambda_get_shape{}); } #else - constexpr static shape<dims> shapeof(const expression_function& self) + constexpr static shape<dims> get_shape(const expression_function& self) { return self.fold([&](auto&&... args) CMT_INLINE_LAMBDA constexpr->auto { - return internal_generic::common_shape<true>(expression_traits<decltype(args)>::shapeof(args)...); + return internal_generic::common_shape<true>( + expression_traits<decltype(args)>::get_shape(args)...); }); } - constexpr static shape<dims> shapeof() + constexpr static shape<dims> get_shape() { return expression_function::fold_idx([&](auto... args) CMT_INLINE_LAMBDA constexpr->auto { return internal_generic::common_shape( expression_traits< - typename expression_function::template nth<val_of(decltype(args)())>>::shapeof()...); + typename expression_function::template nth<val_of(decltype(args)())>>::get_shape()...); }); } #endif @@ -544,7 +545,7 @@ KFR_MEM_INTRINSIC vec<typename Traits::value_type, N> get_arg(const expression_f else { auto indices = internal_generic::adapt<Traits::dims>(index, self.getmask(csize<idx>)); - constexpr index_t last_dim = Traits::shapeof().back(); + constexpr index_t last_dim = Traits::get_shape().back(); if constexpr (last_dim != undefined_size) { constexpr index_t last_dim_pot = prev_poweroftwo(last_dim); @@ -724,7 +725,7 @@ static auto process(Out&& out, In&& in, shape<outdims> start = shape<outdims>(0) constexpr index_t indims = expression_dims<In>; static_assert(outdims >= indims); - constexpr index_t last_dim_size = prev_poweroftwo(Trout::shapeof().back()); + constexpr index_t last_dim_size = prev_poweroftwo(Trout::get_shape().back()); #ifdef NDEBUG constexpr size_t vec_width = maximum_vector_size<Tin>; @@ -737,8 +738,8 @@ static auto process(Out&& out, In&& in, shape<outdims> start = shape<outdims>(0) constexpr index_t out_axis = internal::select_axis(outdims, Axis); constexpr index_t in_axis = out_axis + indims - outdims; - const shape<outdims> outshape = Trout::shapeof(out); - const shape<indims> inshape = Trin::shapeof(in); + const shape<outdims> outshape = Trout::get_shape(out); + const shape<indims> inshape = Trin::get_shape(in); if (CMT_UNLIKELY(!internal_generic::can_assign_from(outshape, inshape))) return shape<outdims>{ 0 }; shape<outdims> stop = min(min(add_shape(start, size), outshape), inshape.template extend<outdims>()); @@ -863,7 +864,7 @@ void test_expression(const E& expr, size_t size, Fn&& fn, const char* expression { static_assert(expression_dims<E> == 1, "CHECK_EXPRESSION supports only 1-dim expressions"); using T = expression_value_type<E>; - size_t expr_size = shapeof(expr).front(); + size_t expr_size = get_shape(expr).front(); ::testo::test_case* test = ::testo::active_test(); auto&& c = ::testo::make_comparison(); test->check(c <= expr_size == size, expression, file, line); diff --git a/include/kfr/base/filter.hpp b/include/kfr/base/filter.hpp @@ -92,7 +92,7 @@ public: void apply(univector<T, Tag>& dest, const Expr& src) { static_assert(expression_dims<Expr> == 1); - process_expression(dest.data(), to_handle(src), size_min(dest.size(), shapeof(src).front())); + process_expression(dest.data(), to_handle(src), size_min(dest.size(), get_shape(src).front())); } template <typename Expr, KFR_ENABLE_IF(is_input_expression<Expr>)> diff --git a/include/kfr/base/generators.hpp b/include/kfr/base/generators.hpp @@ -54,8 +54,8 @@ struct generator : public expression_traits_defaults { using value_type = T; constexpr static size_t dims = 1; - constexpr static shape<1> shapeof(const Class&) { return infinite_size; } - constexpr static shape<1> shapeof() { return infinite_size; } + constexpr static shape<1> get_shape(const Class&) { return infinite_size; } + constexpr static shape<1> get_shape() { return infinite_size; } constexpr static inline bool random_access = false; diff --git a/include/kfr/base/handle.hpp b/include/kfr/base/handle.hpp @@ -127,7 +127,7 @@ struct expression_vtable template <typename Expression> static void static_shapeof(void* instance, shape<Dims>& result) { - result = expression_traits<Expression>::shapeof(*static_cast<Expression*>(instance)); + result = expression_traits<Expression>::get_shape(*static_cast<Expression*>(instance)); } template <typename Expression> static bool static_substitute(void* instance, expression_handle<T, Dims> ptr) @@ -203,13 +203,13 @@ struct expression_traits<expression_handle<T, Dims>> : expression_traits_default { using value_type = T; constexpr static size_t dims = Dims; - constexpr static shape<dims> shapeof(const expression_handle<T, Dims>& self) + constexpr static shape<dims> get_shape(const expression_handle<T, Dims>& self) { shape<dims> result; self.vtable->fn_shapeof(self.instance, result); return result; } - constexpr static shape<dims> shapeof() { return shape<dims>(undefined_size); } + constexpr static shape<dims> get_shape() { return shape<dims>(undefined_size); } constexpr static inline bool random_access = false; }; @@ -322,11 +322,11 @@ struct expression_traits<expression_placeholder<T, Dims, Key>> : public expressi { using value_type = T; constexpr static size_t dims = Dims; - constexpr static shape<dims> shapeof(const expression_placeholder<T, Dims, Key>& self) + constexpr static shape<dims> get_shape(const expression_placeholder<T, Dims, Key>& self) { - return self.handle ? ::kfr::shapeof(self.handle) : shape<dims>(infinite_size); + return self.handle ? ::kfr::get_shape(self.handle) : shape<dims>(infinite_size); } - constexpr static shape<dims> shapeof() { return shape<dims>(undefined_size); } + constexpr static shape<dims> get_shape() { return shape<dims>(undefined_size); } }; inline namespace CMT_ARCH_NAME diff --git a/include/kfr/base/random.hpp b/include/kfr/base/random.hpp @@ -81,11 +81,11 @@ struct expression_random_uniform : expression_traits_defaults { using value_type = T; constexpr static size_t dims = Dims; - constexpr static shape<dims> shapeof(const expression_random_uniform&) + constexpr static shape<dims> get_shape(const expression_random_uniform&) { return shape<dims>(infinite_size); } - constexpr static shape<dims> shapeof() { return shape<dims>(infinite_size); } + constexpr static shape<dims> get_shape() { return shape<dims>(infinite_size); } mutable state_holder<random_state, Reference> state; @@ -102,11 +102,11 @@ struct expression_random_range : expression_traits_defaults { using value_type = T; constexpr static size_t dims = Dims; - constexpr static shape<dims> shapeof(const expression_random_range&) + constexpr static shape<dims> get_shape(const expression_random_range&) { return shape<dims>(infinite_size); } - constexpr static shape<dims> shapeof() { return shape<dims>(infinite_size); } + constexpr static shape<dims> get_shape() { return shape<dims>(infinite_size); } mutable state_holder<random_state, Reference> state; T min; diff --git a/include/kfr/base/reduce.hpp b/include/kfr/base/reduce.hpp @@ -69,8 +69,8 @@ struct expression_reduce : public expression_traits_defaults { using value_type = Tin; constexpr static size_t dims = Dims; - constexpr static shape<dims> shapeof(const expression_reduce&) { return shape<dims>(infinite_size); } - constexpr static shape<dims> shapeof() { return shape<dims>(infinite_size); } + constexpr static shape<dims> get_shape(const expression_reduce&) { return shape<dims>(infinite_size); } + constexpr static shape<dims> get_shape() { return shape<dims>(infinite_size); } constexpr static size_t width = vector_width<Tin> * bitness_const(1, 2); diff --git a/include/kfr/base/tensor.hpp b/include/kfr/base/tensor.hpp @@ -829,11 +829,11 @@ struct expression_traits<tensor<T, Dims>> : expression_traits_defaults using value_type = T; constexpr static size_t dims = Dims; - KFR_MEM_INTRINSIC constexpr static shape<dims> shapeof(const tensor<T, Dims>& self) + KFR_MEM_INTRINSIC constexpr static shape<dims> get_shape(const tensor<T, Dims>& self) { return self.shape(); } - KFR_MEM_INTRINSIC constexpr static shape<dims> shapeof() { return shape<dims>{ undefined_size }; } + KFR_MEM_INTRINSIC constexpr static shape<dims> get_shape() { return shape<dims>{ undefined_size }; } }; inline namespace CMT_ARCH_NAME @@ -897,8 +897,8 @@ tensor<T, outdims> tapply(const tensor<T, dims1>& x, const tensor<T, dims2>& y, template <size_t width = 0, index_t Axis = infinite_size, typename E, typename Traits = expression_traits<E>> tensor<typename Traits::value_type, Traits::dims> trender(const E& expr) { - static_assert(!Traits::shapeof().has_infinity()); - shape sh = Traits::shapeof(expr); + static_assert(!Traits::get_shape().has_infinity()); + shape sh = Traits::get_shape(expr); tensor<typename Traits::value_type, Traits::dims> result(sh); process<width, Axis>(result, expr); return result; @@ -907,7 +907,7 @@ tensor<typename Traits::value_type, Traits::dims> trender(const E& expr) template <size_t width = 0, index_t Axis = infinite_size, typename E, typename Traits = expression_traits<E>> tensor<typename Traits::value_type, Traits::dims> trender(const E& expr, shape<Traits::dims> size) { - shape sh = min(Traits::shapeof(expr), size); + shape sh = min(Traits::get_shape(expr), size); tensor<typename Traits::value_type, Traits::dims> result(sh); process<width, Axis>(result, expr, shape<Traits::dims>{ 0 }, sh); return result; diff --git a/include/kfr/base/univector.hpp b/include/kfr/base/univector.hpp @@ -412,7 +412,7 @@ struct univector<T, tag_dynamic_vector> static_assert(dims <= 1, "univector accepts only expressions with dims <= 1"); if constexpr (dims > 0) { - this->resize(shapeof(input).front()); + this->resize(get_shape(input).front()); } this->assign_expr(std::forward<Input>(input)); } @@ -457,8 +457,8 @@ struct univector<T, tag_dynamic_vector> static_assert(dims <= 1, "univector accepts only expressions with dims <= 1"); if constexpr (dims > 0) { - if (shapeof(input).front() != infinite_size) - this->resize(shapeof(input).front()); + if (get_shape(input).front() != infinite_size) + this->resize(get_shape(input).front()); } this->assign_expr(std::forward<Input>(input)); return *this; @@ -470,8 +470,8 @@ struct expression_traits<univector<T, Tag>> : public expression_traits_defaults { using value_type = std::remove_const_t<T>; constexpr static size_t dims = 1; - constexpr static shape<dims> shapeof(const univector<T, Tag>& u) { return shape<1>(u.size()); } - constexpr static shape<dims> shapeof() + constexpr static shape<dims> get_shape(const univector<T, Tag>& u) { return shape<1>(u.size()); } + constexpr static shape<dims> get_shape() { if constexpr (univector<T, Tag>::size_known) return shape<1>{ univector<T, Tag>::static_size }; @@ -641,7 +641,7 @@ KFR_INTRINSIC univector<T> render(Expr&& expr) static_assert(!is_infinite<Expr>, "render: Can't process infinite expressions. Pass size as a second argument to render."); univector<T> result; - result.resize(shapeof(expr).front()); + result.resize(get_shape(expr).front()); result = expr; return result; } diff --git a/include/kfr/dft/impl/dft-impl.hpp b/include/kfr/dft/impl/dft-impl.hpp @@ -169,7 +169,7 @@ struct fft_inverse : expression_with_traits<E> friend KFR_INTRINSIC vec<value_type, 1> get_elements(const fft_inverse& self, shape<1> index, axis_params<0, 1>) { - const size_t size = shapeof(self).front(); + const size_t size = get_shape(self).front(); return get_elements(self.first(), index.front() == 0 ? 0 : size - index, axis_params<0, 1>()); } @@ -177,7 +177,7 @@ struct fft_inverse : expression_with_traits<E> friend KFR_MEM_INTRINSIC vec<value_type, N> get_elements(const fft_inverse& self, shape<1> index, axis_params<0, N>) { - const size_t size = shapeof(self).front(); + const size_t size = get_shape(self).front(); if (index.front() == 0) { return concat(get_elements(self.first(), index, axis_params<0, 1>()), diff --git a/include/kfr/dsp/delay.hpp b/include/kfr/dsp/delay.hpp @@ -65,11 +65,11 @@ struct expression_delay : expression_with_arguments<E>, public expression_traits static_assert(ArgTraits::dims == 1, "expression_delay requires argument with dims == 1"); using value_type = typename ArgTraits::value_type; constexpr static size_t dims = 1; - constexpr static shape<dims> shapeof(const expression_delay& self) + constexpr static shape<dims> get_shape(const expression_delay& self) { - return ArgTraits::shapeof(self.first()); + return ArgTraits::get_shape(self.first()); } - constexpr static shape<dims> shapeof() { return ArgTraits::shapeof(); } + constexpr static shape<dims> get_shape() { return ArgTraits::get_shape(); } constexpr static inline bool random_access = false; using T = value_type; @@ -121,11 +121,11 @@ struct expression_delay<1, E, stateless, STag> : expression_with_arguments<E>, e static_assert(ArgTraits::dims == 1, "expression_delay requires argument with dims == 1"); using value_type = typename ArgTraits::value_type; constexpr static size_t dims = 1; - constexpr static shape<dims> shapeof(const expression_delay& self) + constexpr static shape<dims> get_shape(const expression_delay& self) { - return ArgTraits::shapeof(self.first()); + return ArgTraits::get_shape(self.first()); } - constexpr static shape<dims> shapeof() { return ArgTraits::shapeof(); } + constexpr static shape<dims> get_shape() { return ArgTraits::get_shape(); } constexpr static inline bool random_access = false; using T = value_type; diff --git a/include/kfr/dsp/window.hpp b/include/kfr/dsp/window.hpp @@ -127,11 +127,11 @@ struct expression_window : expression_traits_defaults { using value_type = T; constexpr static size_t dims = 1; - constexpr static shape<dims> shapeof(const expression_window<T>& self) + constexpr static shape<dims> get_shape(const expression_window<T>& self) { return shape<dims>(self.m_size); } - constexpr static shape<dims> shapeof() { return shape<1>(undefined_size); } + constexpr static shape<dims> get_shape() { return shape<1>(undefined_size); } constexpr expression_window(size_t size) : m_size(size) {} diff --git a/include/kfr/except.hpp b/include/kfr/except.hpp @@ -79,7 +79,6 @@ public: if (CMT_UNLIKELY(!(cond))) \ KFR_REPORT_ERROR(kind, __VA_ARGS__); \ } while (0) - #define KFR_REPORT_RUNTIME_ERROR(...) KFR_REPORT_ERROR(runtime, __VA_ARGS__) diff --git a/tests/unit/base/basic_expressions.cpp b/tests/unit/base/basic_expressions.cpp @@ -19,7 +19,7 @@ TEST(linspace) testo::eplison_scope<> eps(10); CHECK_EXPRESSION(linspace(0.0, 1.0, 5, true, ctrue), { 0.0, 0.25, 0.50, 0.75, 1.0 }); CHECK_EXPRESSION(linspace(0.0, 1.0, 4, false, ctrue), { 0.0, 0.25, 0.50, 0.75 }); - CHECK(shapeof(linspace(0.0, 1.0, 5, true, cfalse)) == shape{ infinite_size }); + CHECK(get_shape(linspace(0.0, 1.0, 5, true, cfalse)) == shape{ infinite_size }); CHECK_EXPRESSION(linspace(0.0, 1.0, 4, false, ctrue), { 0.0, 0.25, 0.50, 0.75 }); CHECK_EXPRESSION(symmlinspace(3.0, 4, ctrue), { -3.0, -1.00, 1.00, 3.00 }); @@ -29,10 +29,10 @@ TEST(linspace) TEST(counter_shape) { - CHECK(shapeof(1) == shape{}); - CHECK(shapeof(counter()) == shape{ infinite_size }); - CHECK(shapeof(counter() + 1) == shape{ infinite_size }); - CHECK(shapeof(counter(0, 1, 1)) == shape{ infinite_size, infinite_size }); + CHECK(get_shape(1) == shape{}); + CHECK(get_shape(counter()) == shape{ infinite_size }); + CHECK(get_shape(counter() + 1) == shape{ infinite_size }); + CHECK(get_shape(counter(0, 1, 1)) == shape{ infinite_size, infinite_size }); } TEST(pack) @@ -60,9 +60,9 @@ TEST(dimensions) static_assert(expression_dims<decltype(scalar(0))> == 0); static_assert(expression_dims<decltype(dimensions<1>(scalar(0)))> == 1); - static_assert(shapeof<decltype(scalar(0))>() == shape{}); - static_assert(shapeof<decltype(dimensions<1>(scalar(0)))>() == shape{ infinite_size }); - static_assert(shapeof<decltype(dimensions<2>(dimensions<1>(scalar(0))))>() == + static_assert(get_shape<decltype(scalar(0))>() == shape{}); + static_assert(get_shape<decltype(dimensions<1>(scalar(0)))>() == shape{ infinite_size }); + static_assert(get_shape<decltype(dimensions<2>(dimensions<1>(scalar(0))))>() == shape{ infinite_size, infinite_size }); CHECK_EXPRESSION(truncate(dimensions<1>(scalar(1)), 10), { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }); } @@ -110,13 +110,13 @@ TEST(test_arg_access) TEST(size_calc) { auto a = counter(); - CHECK(shapeof(a) == shape{ infinite_size }); + CHECK(get_shape(a) == shape{ infinite_size }); auto b = slice(counter(), 100); - CHECK(shapeof(b) == shape{ infinite_size }); + CHECK(get_shape(b) == shape{ infinite_size }); auto c = slice(counter(), 100, 1000); - CHECK(shapeof(c) == shape{ 1000 }); + CHECK(get_shape(c) == shape{ 1000 }); auto d = slice(c, 100); - CHECK(shapeof(d) == shape{ 900 }); + CHECK(get_shape(d) == shape{ 900 }); } TEST(reverse_expression) diff --git a/tests/unit/base/tensor.cpp b/tests/unit/base/tensor.cpp @@ -164,8 +164,8 @@ struct expression_traits<std::array<T, N1>> : expression_traits_defaults using value_type = T; constexpr static size_t dims = 1; - constexpr static shape<1> shapeof(const std::array<T, N1>& self) { return shape<1>{ N1 }; } - constexpr static shape<1> shapeof() { return shape<1>{ N1 }; } + constexpr static shape<1> get_shape(const std::array<T, N1>& self) { return shape<1>{ N1 }; } + constexpr static shape<1> get_shape() { return shape<1>{ N1 }; } }; template <typename T, size_t N1, size_t N2> @@ -174,11 +174,11 @@ struct expression_traits<std::array<std::array<T, N1>, N2>> : expression_traits_ using value_type = T; constexpr static size_t dims = 2; - constexpr static shape<2> shapeof(const std::array<std::array<T, N1>, N2>& self) + constexpr static shape<2> get_shape(const std::array<std::array<T, N1>, N2>& self) { return shape<2>{ N2, N1 }; } - constexpr static shape<2> shapeof() { return shape<2>{ N2, N1 }; } + constexpr static shape<2> get_shape() { return shape<2>{ N2, N1 }; } }; inline namespace CMT_ARCH_NAME @@ -272,12 +272,12 @@ TEST(tensor_expressions2) { auto aa = std::array<std::array<double, 2>, 2>{ { { { 1, 2 } }, { { 3, 4 } } } }; static_assert(expression_traits<decltype(aa)>::dims == 2); - CHECK(expression_traits<decltype(aa)>::shapeof(aa) == shape{ 2, 2 }); + CHECK(expression_traits<decltype(aa)>::get_shape(aa) == shape{ 2, 2 }); CHECK(get_elements(aa, { 1, 1 }, axis_params<1, 1>{}) == vec{ 4. }); CHECK(get_elements(aa, { 1, 0 }, axis_params<1, 2>{}) == vec{ 3., 4. }); static_assert(expression_traits<decltype(1234.f)>::dims == 0); - CHECK(expression_traits<decltype(1234.f)>::shapeof(1234.f) == shape{}); + CHECK(expression_traits<decltype(1234.f)>::get_shape(1234.f) == shape{}); CHECK(get_elements(1234.f, {}, axis_params<0, 3>{}) == vec{ 1234.f, 1234.f, 1234.f }); process(aa, 123.45f); @@ -358,7 +358,7 @@ TEST(xfunction_test) std::array{ 1.f, 2.f, 3.f, 4.f, 5.f }; std::array<std::array<float, 5>, 5> v4; - CHECK(expression_traits<decltype(f4)>::shapeof(f4) == shape{ 5, 5 }); + CHECK(expression_traits<decltype(f4)>::get_shape(f4) == shape{ 5, 5 }); process(v4, f4); CHECK(v4 == std::array<std::array<float, 5>, 5>{ { { { 101.f, 102.f, 103.f, 104.f, 105.f } }, { { 201.f, 202.f, 203.f, 204.f, 205.f } }, @@ -693,8 +693,8 @@ struct expression_traits<val> : expression_traits_defaults { using value_type = float; constexpr static size_t dims = 0; - constexpr static shape<dims> shapeof(const val&) { return {}; } - constexpr static shape<dims> shapeof() { return {}; } + constexpr static shape<dims> get_shape(const val&) { return {}; } + constexpr static shape<dims> get_shape() { return {}; } }; inline namespace CMT_ARCH_NAME @@ -808,8 +808,8 @@ struct expression_traits<identity_matrix<T, Size>> : expression_traits_defaults { using value_type = T; constexpr static size_t dims = 2; - constexpr static shape<2> shapeof(const identity_matrix<T, Size>& self) { return { Size, Size }; } - constexpr static shape<2> shapeof() { return { Size, Size }; } + constexpr static shape<2> get_shape(const identity_matrix<T, Size>& self) { return { Size, Size }; } + constexpr static shape<2> get_shape() { return { Size, Size }; } }; template <typename T, index_t Size, index_t Axis, size_t N>