From 08e373383837a070e6dd89fd0f7fb83c744e5b10 Mon Sep 17 00:00:00 2001 From: Fahri Ali Rahman Date: Sat, 23 Mar 2024 00:03:45 +0700 Subject: [PATCH] Ufuncs, reduce, outer, accumulate: view attribute initializer, generalized functors, more useful specialized utils functions (#269) * add missing include for cuda context * add unary_ufunc, binary_ufunc, broadcast_binary_ufunc view entrypoint * add unary_ufunc, binary_ufunc, and broadcast_binary_ufunc functors * add accumulate functor * add outer functor * add reduce functor * simplify various ufunc functors * add accumulate view attribute initializer * add outer view attribute initializer * add reduce view attribute initializer * add ufunc view attribute initializer * refactor various ufunc, reduce, outer, accumulate views * refactor various utils for easier specialization * add functor isequal specialization * update tests * try to fix build * fix tests * fix adaptivecpp installs scripts * fix sycl dockerfile deps installation * fix simd ufunc specialization * fix simd ufunc specialization * fix sycl dockerfile deps installation * fix build * fix build * fix build --- .github/workflows/gcc.yml | 2 +- .github/workflows/sycl.yml | 2 +- docker/sycl.dockerfile | 21 +- include/nmtools/array/eval/cuda/context.hpp | 1 + .../array/eval/simd/simde_avx512/ufunc.hpp | 12 +- include/nmtools/array/eval/simd/ufunc.hpp | 36 +- .../array/functional/activations/celu.hpp | 31 +- .../array/functional/activations/elu.hpp | 30 +- .../functional/activations/hardshrink.hpp | 30 +- .../functional/activations/hardswish.hpp | 30 +- .../array/functional/activations/hardtanh.hpp | 30 +- .../functional/activations/leaky_relu.hpp | 30 +- .../functional/activations/log_sigmoid.hpp | 30 +- .../array/functional/activations/mish.hpp | 30 +- .../array/functional/activations/prelu.hpp | 30 +- .../array/functional/activations/relu.hpp | 30 +- .../array/functional/activations/relu6.hpp | 30 +- .../array/functional/activations/selu.hpp | 30 +- .../array/functional/activations/sigmoid.hpp | 30 +- .../array/functional/activations/silu.hpp | 30 +- .../array/functional/activations/softplus.hpp | 30 +- .../functional/activations/softshrink.hpp | 30 +- .../array/functional/activations/softsign.hpp | 30 +- .../functional/activations/tanhshrink.hpp | 30 +- include/nmtools/array/functional/functor.hpp | 75 ++- .../array/functional/ufunc/accumulate.hpp | 83 +++ .../nmtools/array/functional/ufunc/outer.hpp | 83 +++ .../nmtools/array/functional/ufunc/reduce.hpp | 83 +++ .../nmtools/array/functional/ufunc/ufunc.hpp | 216 ++++++++ .../nmtools/array/functional/ufuncs/add.hpp | 133 +---- .../array/functional/ufuncs/arccos.hpp | 30 +- .../array/functional/ufuncs/arccosh.hpp | 30 +- .../array/functional/ufuncs/arcsin.hpp | 30 +- .../array/functional/ufuncs/arcsinh.hpp | 29 +- .../array/functional/ufuncs/arctan.hpp | 30 +- .../array/functional/ufuncs/arctanh.hpp | 30 +- .../nmtools/array/functional/ufuncs/cbrt.hpp | 30 +- .../nmtools/array/functional/ufuncs/ceil.hpp | 30 +- .../nmtools/array/functional/ufuncs/cos.hpp | 30 +- .../nmtools/array/functional/ufuncs/cosh.hpp | 30 +- .../array/functional/ufuncs/divide.hpp | 37 +- .../nmtools/array/functional/ufuncs/exp.hpp | 30 +- .../nmtools/array/functional/ufuncs/exp2.hpp | 29 +- .../nmtools/array/functional/ufuncs/expm1.hpp | 29 +- .../nmtools/array/functional/ufuncs/fabs.hpp | 30 +- .../nmtools/array/functional/ufuncs/floor.hpp | 30 +- .../array/functional/ufuncs/invert.hpp | 30 +- .../array/functional/ufuncs/isfinite.hpp | 30 +- .../nmtools/array/functional/ufuncs/isinf.hpp | 30 +- .../nmtools/array/functional/ufuncs/isnan.hpp | 30 +- .../nmtools/array/functional/ufuncs/log.hpp | 30 +- .../nmtools/array/functional/ufuncs/log10.hpp | 30 +- .../nmtools/array/functional/ufuncs/log1p.hpp | 30 +- .../nmtools/array/functional/ufuncs/log2.hpp | 30 +- .../array/functional/ufuncs/maximum.hpp | 133 +---- .../array/functional/ufuncs/minimum.hpp | 133 +---- .../array/functional/ufuncs/multiply.hpp | 134 +---- .../array/functional/ufuncs/negative.hpp | 30 +- .../array/functional/ufuncs/positive.hpp | 30 +- .../array/functional/ufuncs/reciprocal.hpp | 30 +- .../nmtools/array/functional/ufuncs/rint.hpp | 30 +- .../array/functional/ufuncs/signbit.hpp | 30 +- .../nmtools/array/functional/ufuncs/sin.hpp | 30 +- .../nmtools/array/functional/ufuncs/sinh.hpp | 30 +- .../nmtools/array/functional/ufuncs/sqrt.hpp | 30 +- .../array/functional/ufuncs/square.hpp | 30 +- .../array/functional/ufuncs/subtract.hpp | 163 +----- .../nmtools/array/functional/ufuncs/tan.hpp | 30 +- .../nmtools/array/functional/ufuncs/tanh.hpp | 30 +- .../nmtools/array/view/activations/celu.hpp | 55 +- .../nmtools/array/view/activations/elu.hpp | 55 +- .../array/view/activations/hardshrink.hpp | 54 +- .../array/view/activations/hardswish.hpp | 32 +- .../array/view/activations/hardtanh.hpp | 65 ++- .../array/view/activations/leaky_relu.hpp | 54 +- .../array/view/activations/log_sigmoid.hpp | 32 +- .../nmtools/array/view/activations/mish.hpp | 34 +- .../nmtools/array/view/activations/prelu.hpp | 54 +- .../nmtools/array/view/activations/relu.hpp | 32 +- .../nmtools/array/view/activations/relu6.hpp | 32 +- .../nmtools/array/view/activations/selu.hpp | 32 +- .../array/view/activations/sigmoid.hpp | 36 +- .../nmtools/array/view/activations/silu.hpp | 34 +- .../array/view/activations/softplus.hpp | 82 ++- .../array/view/activations/softshrink.hpp | 55 +- .../array/view/activations/softsign.hpp | 32 +- .../array/view/activations/tanhshrink.hpp | 32 +- include/nmtools/array/view/prod.hpp | 8 +- include/nmtools/array/view/sum.hpp | 8 +- include/nmtools/array/view/ufunc.hpp | 236 ++++++++- .../nmtools/array/view/ufunc/accumulate.hpp | 75 ++- include/nmtools/array/view/ufunc/outer.hpp | 80 ++- include/nmtools/array/view/ufunc/reduce.hpp | 136 ++++- include/nmtools/array/view/ufunc/ufunc.hpp | 34 +- include/nmtools/array/view/ufuncs/add.hpp | 65 ++- include/nmtools/array/view/ufuncs/arccos.hpp | 34 +- include/nmtools/array/view/ufuncs/arccosh.hpp | 34 +- include/nmtools/array/view/ufuncs/arcsin.hpp | 34 +- include/nmtools/array/view/ufuncs/arcsinh.hpp | 35 +- include/nmtools/array/view/ufuncs/arctan.hpp | 34 +- include/nmtools/array/view/ufuncs/arctan2.hpp | 34 +- include/nmtools/array/view/ufuncs/arctanh.hpp | 34 +- .../nmtools/array/view/ufuncs/bitwise_and.hpp | 34 +- .../nmtools/array/view/ufuncs/bitwise_or.hpp | 34 +- .../nmtools/array/view/ufuncs/bitwise_xor.hpp | 34 +- include/nmtools/array/view/ufuncs/cbrt.hpp | 34 +- include/nmtools/array/view/ufuncs/ceil.hpp | 32 +- include/nmtools/array/view/ufuncs/cos.hpp | 34 +- include/nmtools/array/view/ufuncs/cosh.hpp | 34 +- include/nmtools/array/view/ufuncs/divide.hpp | 34 +- include/nmtools/array/view/ufuncs/equal.hpp | 33 +- include/nmtools/array/view/ufuncs/exp.hpp | 34 +- include/nmtools/array/view/ufuncs/exp2.hpp | 34 +- include/nmtools/array/view/ufuncs/expm1.hpp | 34 +- include/nmtools/array/view/ufuncs/fabs.hpp | 34 +- include/nmtools/array/view/ufuncs/floor.hpp | 34 +- include/nmtools/array/view/ufuncs/fmax.hpp | 16 +- include/nmtools/array/view/ufuncs/fmin.hpp | 16 +- include/nmtools/array/view/ufuncs/fmod.hpp | 16 +- include/nmtools/array/view/ufuncs/greater.hpp | 34 +- .../array/view/ufuncs/greater_equal.hpp | 33 +- include/nmtools/array/view/ufuncs/hypot.hpp | 33 +- include/nmtools/array/view/ufuncs/invert.hpp | 45 +- .../nmtools/array/view/ufuncs/isfinite.hpp | 34 +- include/nmtools/array/view/ufuncs/isinf.hpp | 34 +- include/nmtools/array/view/ufuncs/isnan.hpp | 32 +- include/nmtools/array/view/ufuncs/ldexp.hpp | 33 +- .../nmtools/array/view/ufuncs/left_shift.hpp | 16 +- include/nmtools/array/view/ufuncs/less.hpp | 34 +- .../nmtools/array/view/ufuncs/less_equal.hpp | 34 +- include/nmtools/array/view/ufuncs/log.hpp | 34 +- include/nmtools/array/view/ufuncs/log10.hpp | 34 +- include/nmtools/array/view/ufuncs/log1p.hpp | 34 +- include/nmtools/array/view/ufuncs/log2.hpp | 34 +- .../nmtools/array/view/ufuncs/logical_and.hpp | 34 +- .../nmtools/array/view/ufuncs/logical_not.hpp | 35 +- .../nmtools/array/view/ufuncs/logical_or.hpp | 34 +- .../nmtools/array/view/ufuncs/logical_xor.hpp | 34 +- include/nmtools/array/view/ufuncs/maximum.hpp | 16 +- include/nmtools/array/view/ufuncs/minimum.hpp | 16 +- include/nmtools/array/view/ufuncs/mod.hpp | 34 +- .../nmtools/array/view/ufuncs/multiply.hpp | 74 ++- .../nmtools/array/view/ufuncs/negative.hpp | 34 +- .../nmtools/array/view/ufuncs/not_equal.hpp | 34 +- .../nmtools/array/view/ufuncs/positive.hpp | 34 +- include/nmtools/array/view/ufuncs/power.hpp | 20 +- .../nmtools/array/view/ufuncs/reciprocal.hpp | 34 +- .../nmtools/array/view/ufuncs/right_shift.hpp | 16 +- include/nmtools/array/view/ufuncs/rint.hpp | 34 +- include/nmtools/array/view/ufuncs/signbit.hpp | 34 +- include/nmtools/array/view/ufuncs/sin.hpp | 34 +- include/nmtools/array/view/ufuncs/sinh.hpp | 34 +- include/nmtools/array/view/ufuncs/sqrt.hpp | 34 +- include/nmtools/array/view/ufuncs/square.hpp | 34 +- .../nmtools/array/view/ufuncs/subtract.hpp | 63 ++- include/nmtools/array/view/ufuncs/tan.hpp | 34 +- include/nmtools/array/view/ufuncs/tanh.hpp | 34 +- include/nmtools/array/view/ufuncs/trunc.hpp | 34 +- .../nmtools/meta/bits/traits/is_attribute.hpp | 21 + include/nmtools/meta/common.hpp | 4 + include/nmtools/meta/expr.hpp | 9 + include/nmtools/meta/traits.hpp | 1 + include/nmtools/testing/doctest.hpp | 3 + include/nmtools/testing/string.hpp | 2 + include/nmtools/testing/testing.hpp | 9 + include/nmtools/utils/isclose.hpp | 76 +-- include/nmtools/utils/isclose/isclose.hpp | 15 + include/nmtools/utils/isequal.hpp | 63 ++- include/nmtools/utils/isequal/isequal.hpp | 15 + include/nmtools/utils/to_string.hpp | 489 +----------------- .../nmtools/utils/to_string/common_types.hpp | 270 ++++++++++ include/nmtools/utils/to_string/functor.hpp | 164 ++++++ include/nmtools/utils/to_string/to_string.hpp | 104 ++++ include/nmtools/utils/to_string/ufunc.hpp | 141 +++++ scripts/install_llvm_spirv.sh | 4 +- scripts/install_opensycl.sh | 57 +- scripts/install_pocl.sh | 9 +- tests/cuda/CMakeLists.txt | 1 + tests/cuda/composition/add_tanh.cpp | 40 ++ tests/functional/CMakeLists.txt | 14 +- tests/functional/src/activations/celu.cpp | 50 +- tests/functional/src/activations/elu.cpp | 119 ++++- .../functional/src/activations/hardshrink.cpp | 48 +- .../functional/src/activations/hardswish.cpp | 15 + tests/functional/src/activations/hardtanh.cpp | 42 +- .../functional/src/activations/leaky_relu.cpp | 42 +- .../src/activations/log_sigmoid.cpp | 15 + tests/functional/src/activations/mish.cpp | 15 + tests/functional/src/activations/prelu.cpp | 42 +- tests/functional/src/activations/relu.cpp | 15 + tests/functional/src/activations/relu6.cpp | 15 + tests/functional/src/activations/selu.cpp | 15 + tests/functional/src/activations/sigmoid.cpp | 15 + tests/functional/src/activations/silu.cpp | 15 + tests/functional/src/activations/softplus.cpp | 43 +- .../functional/src/activations/softshrink.cpp | 52 +- tests/functional/src/activations/softsign.cpp | 15 + .../functional/src/activations/tanhshrink.cpp | 15 + tests/functional/src/composition/add_tanh.cpp | 5 +- .../src/composition/divide_subtract.cpp | 7 +- .../src/composition/fabs_square.cpp | 3 +- .../src/composition/fabs_square_sum.cpp | 6 +- .../src/composition/multiply_add.cpp | 3 +- .../src/composition/multiply_add_tanh.cpp | 28 +- .../src/composition/multiply_tanh.cpp | 3 +- .../src/composition/reduce_add_divide.cpp | 4 +- .../src/composition/reduce_add_tanh.cpp | 10 +- .../composition/reduce_maximum_subtract.cpp | 4 +- .../reduce_maximum_subtract_exp.cpp | 6 +- .../functional/src/composition/square_sum.cpp | 5 +- .../src/composition/square_sum_divide.cpp | 28 +- .../src/composition/subtract_exp.cpp | 3 +- .../src/composition/subtract_fabs.cpp | 3 +- .../src/composition/subtract_fabs_square.cpp | 4 +- .../functional/src/composition/sum_divide.cpp | 4 +- tests/functional/src/mean.cpp | 3 + tests/functional/src/ufuncs/add.cpp | 2 +- tests/functional/src/ufuncs/arccos.cpp | 16 + tests/functional/src/ufuncs/arccosh.cpp | 13 + tests/functional/src/ufuncs/arcsin.cpp | 13 + tests/functional/src/ufuncs/arcsinh.cpp | 13 + tests/functional/src/ufuncs/arctan.cpp | 13 + tests/functional/src/ufuncs/arctanh.cpp | 13 + tests/functional/src/ufuncs/cbrt.cpp | 13 + tests/functional/src/ufuncs/ceil.cpp | 13 + tests/functional/src/ufuncs/cos.cpp | 13 + tests/functional/src/ufuncs/cosh.cpp | 13 + tests/functional/src/ufuncs/exp.cpp | 13 + tests/functional/src/ufuncs/exp2.cpp | 13 + tests/functional/src/ufuncs/expm1.cpp | 13 + tests/functional/src/ufuncs/fabs.cpp | 13 + tests/functional/src/ufuncs/floor.cpp | 13 + tests/functional/src/ufuncs/invert.cpp | 14 + tests/functional/src/ufuncs/isfinite.cpp | 13 + tests/functional/src/ufuncs/isinf.cpp | 13 + tests/functional/src/ufuncs/isnan.cpp | 13 + tests/functional/src/ufuncs/log.cpp | 13 + tests/functional/src/ufuncs/log10.cpp | 13 + tests/functional/src/ufuncs/log1p.cpp | 13 + tests/functional/src/ufuncs/log2.cpp | 13 + tests/functional/src/ufuncs/multiply.cpp | 232 ++++++++- tests/functional/src/ufuncs/negative.cpp | 13 + tests/functional/src/ufuncs/positive.cpp | 13 + tests/functional/src/ufuncs/reciprocal.cpp | 13 + tests/functional/src/ufuncs/rint.cpp | 13 + tests/functional/src/ufuncs/signbit.cpp | 13 + tests/functional/src/ufuncs/sin.cpp | 13 + tests/functional/src/ufuncs/sinh.cpp | 13 + tests/functional/src/ufuncs/sqrt.cpp | 13 + tests/functional/src/ufuncs/tan.cpp | 13 + tests/functional/src/ufuncs/tanh.cpp | 13 + tests/meta/array/eval/reduce.cpp | 18 +- tests/meta/array/eval/ufunc.cpp | 14 +- tests/meta/array/view/broadcast_to.cpp | 20 +- tests/meta/array/view/reduce.cpp | 56 +- tests/meta/array/view/ufunc.cpp | 96 ++-- 256 files changed, 6189 insertions(+), 3335 deletions(-) create mode 100644 include/nmtools/array/functional/ufunc/accumulate.hpp create mode 100644 include/nmtools/array/functional/ufunc/outer.hpp create mode 100644 include/nmtools/array/functional/ufunc/reduce.hpp create mode 100644 include/nmtools/meta/bits/traits/is_attribute.hpp create mode 100644 include/nmtools/utils/isclose/isclose.hpp create mode 100644 include/nmtools/utils/isequal/isequal.hpp create mode 100644 include/nmtools/utils/to_string/common_types.hpp create mode 100644 include/nmtools/utils/to_string/functor.hpp create mode 100644 include/nmtools/utils/to_string/to_string.hpp create mode 100644 include/nmtools/utils/to_string/ufunc.hpp create mode 100644 tests/cuda/composition/add_tanh.cpp diff --git a/.github/workflows/gcc.yml b/.github/workflows/gcc.yml index ab4ac864d..d0bceb450 100644 --- a/.github/workflows/gcc.yml +++ b/.github/workflows/gcc.yml @@ -117,7 +117,7 @@ jobs: ./dockcross-${{ matrix.name }} bash -c 'build/${{ matrix.name }}/tests/index/numeric-tests-index-doctest' dockcross-gcc-functional: - name: ${{ matrix.name }}-index + name: ${{ matrix.name }}-functional runs-on: ubuntu-20.04 strategy: matrix: diff --git a/.github/workflows/sycl.yml b/.github/workflows/sycl.yml index 757430695..e711b4ab6 100644 --- a/.github/workflows/sycl.yml +++ b/.github/workflows/sycl.yml @@ -29,4 +29,4 @@ jobs: - uses: actions/checkout@v2 - name: build docker run: | - docker build . --tag nmtools:sycl-clang14-cuda --file docker/sycl-cuda.dockerfile \ No newline at end of file + docker build . --tag nmtools:sycl-clang14-cuda --build-arg BASE=nvidia/cuda:11.8.0-devel-ubuntu22.04 --build-arg cuda_backend=ON --build-arg toolchain=sycl-clang14-cuda --file docker/sycl.dockerfile \ No newline at end of file diff --git a/docker/sycl.dockerfile b/docker/sycl.dockerfile index 98da03b6c..dd457d0d1 100644 --- a/docker/sycl.dockerfile +++ b/docker/sycl.dockerfile @@ -1,4 +1,6 @@ -from ubuntu:jammy as dev +# ARG BASE=nvidia/cuda:11.8.0-devel-ubuntu22.04 +ARG BASE=ubuntu:jammy +from ${BASE} as dev ARG DEBIAN_FRONTEND=noninteractive ENV TZ=Asia @@ -46,9 +48,21 @@ COPY scripts/install_doctest.sh scripts/install_doctest.sh RUN bash scripts/install_doctest.sh RUN apt install -y libclang-dev clang-tools libomp-dev llvm-dev lld libboost-dev libboost-fiber-dev libboost-context-dev -RUN bash scripts/install_opensycl.sh + +ARG opencl_backend=OFF +ENV OPENCL_BACKEND=${opencl_backend} + +ARG cuda_backend=OFF +ENV CUDA_BACKEND=${cuda_backend} + +ARG level_zero_backend=OFF +ENV LEVEL_ZERO_BACKEND=${level_zero_backend} ARG toolchain=sycl-clang14-omp +ENV TOOLCHAIN=${toolchain} + +RUN bash scripts/install_opensycl.sh + RUN mkdir -p build/${toolchain} && cd build/${toolchain} \ && cmake -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/${toolchain}.cmake \ -DNMTOOLS_BUILD_META_TESTS=OFF -DNMTOOLS_BUILD_UTL_TESTS=OFF -DNMTOOLS_TEST_ALL=OFF \ @@ -56,5 +70,4 @@ RUN mkdir -p build/${toolchain} && cd build/${toolchain} \ ../.. \ && make -j2 VERBOSE=1 numeric-tests-sycl-doctest -ENV toolchain=${toolchain} -CMD ["sh", "-c", "/workspace/nmtools/build/${toolchain}/tests/sycl/numeric-tests-sycl-doctest"] \ No newline at end of file +CMD ["sh", "-c", "/workspace/nmtools/build/${TOOLCHAIN}/tests/sycl/numeric-tests-sycl-doctest"] \ No newline at end of file diff --git a/include/nmtools/array/eval/cuda/context.hpp b/include/nmtools/array/eval/cuda/context.hpp index 9c53e71cf..25a462b90 100644 --- a/include/nmtools/array/eval/cuda/context.hpp +++ b/include/nmtools/array/eval/cuda/context.hpp @@ -5,6 +5,7 @@ #include "nmtools/meta.hpp" #include "nmtools/array/eval/kernel_helper.hpp" #include "nmtools/utility/tuple_cat.hpp" +#include "nmtools/array/functional/functor.hpp" #include template - struct ufunc_simd_t,simde_avx512_t,data_t> : simd_op_t + template + struct ufunc_simd_t,simde_avx512_t,data_t> : simd_op_t { using simd_t = simd_op_t; using simd_dtype_t = decltype(simd_t::set1(0)); - using ufunc_op_t = view::softshrink_t; + using ufunc_op_t = view::softshrink_t; const simd_dtype_t zero = simd_t::set1(0); const simd_dtype_t one = simd_t::set1(1); @@ -56,12 +56,12 @@ namespace nmtools::array::simd } }; // ufunc_simd_t - template - struct ufunc_simd_t,simde_avx512_t,data_t> : simd_op_t + template + struct ufunc_simd_t,simde_avx512_t,data_t> : simd_op_t { using simd_t = simd_op_t; using simd_dtype_t = decltype(simd_t::set1(0)); - using ufunc_op_t = view::hardshrink_t; + using ufunc_op_t = view::hardshrink_t; const simd_dtype_t zero = simd_t::set1(0); const simd_dtype_t pos_lambda; diff --git a/include/nmtools/array/eval/simd/ufunc.hpp b/include/nmtools/array/eval/simd/ufunc.hpp index 60a9d6189..2f07fa096 100644 --- a/include/nmtools/array/eval/simd/ufunc.hpp +++ b/include/nmtools/array/eval/simd/ufunc.hpp @@ -158,12 +158,12 @@ namespace nmtools::array::simd } }; // ufunc_simd_t - template - struct ufunc_simd_t,simd_tag_t,data_t> : simd_op_t + template + struct ufunc_simd_t,simd_tag_t,data_t> : simd_op_t { using simd_t = simd_op_t; using simd_dtype_t = decltype(simd_t::set1(0)); - using ufunc_op_t = view::hardtanh_t; + using ufunc_op_t = view::hardtanh_t; const simd_dtype_t min_val; const simd_dtype_t max_val; @@ -180,12 +180,12 @@ namespace nmtools::array::simd } }; // ufunc_simd_t - template - struct ufunc_simd_t,simd_tag_t,data_t> : simd_op_t + template + struct ufunc_simd_t,simd_tag_t,data_t> : simd_op_t { using simd_t = simd_op_t; using simd_dtype_t = decltype(simd_t::set1(0)); - using ufunc_op_t = view::leaky_relu_t; + using ufunc_op_t = view::leaky_relu_t; const simd_dtype_t zero = simd_t::set1(0); const simd_dtype_t negative_slope; @@ -203,12 +203,12 @@ namespace nmtools::array::simd } }; // ufunc_simd_t - template - struct ufunc_simd_t,simd_tag_t,data_t> : simd_op_t + template + struct ufunc_simd_t,simd_tag_t,data_t> : simd_op_t { using simd_t = simd_op_t; using simd_dtype_t = decltype(simd_t::set1(0)); - using ufunc_op_t = view::prelu_t; + using ufunc_op_t = view::prelu_t; const simd_dtype_t zero = simd_t::set1(0); const simd_dtype_t alpha; @@ -226,12 +226,12 @@ namespace nmtools::array::simd } }; // ufunc_simd_t - template - struct ufunc_simd_t,simd_tag_t,data_t> : simd_op_t + template + struct ufunc_simd_t,simd_tag_t,data_t> : simd_op_t { using simd_t = simd_op_t; using simd_dtype_t = decltype(simd_t::set1(0)); - using ufunc_op_t = view::softshrink_t; + using ufunc_op_t = view::softshrink_t; const simd_dtype_t zero = simd_t::set1(0); const simd_dtype_t pos_lambda; @@ -289,12 +289,12 @@ namespace nmtools::array::simd } }; // ufunc_simd_t - template - struct ufunc_simd_t,simd_tag_t,data_t> : simd_op_t + template + struct ufunc_simd_t,simd_tag_t,data_t> : simd_op_t { using simd_t = simd_op_t; using simd_dtype_t = decltype(simd_t::set1(0)); - using ufunc_op_t = view::hardshrink_t; + using ufunc_op_t = view::hardshrink_t; const simd_dtype_t zero = simd_t::set1(0); const simd_dtype_t pos_lambda; @@ -340,12 +340,12 @@ namespace nmtools::array::simd } }; - template - struct ufunc_simd_t,simd_tag_t,data_t> : simd_op_t + template + struct ufunc_simd_t,simd_tag_t,data_t> : simd_op_t { using simd_t = simd_op_t; using simd_dtype_t = decltype(simd_t::set1(data_t{0})); - using ufunc_op_t = view::add_t; + using ufunc_op_t = view::add_t; ufunc_simd_t([[maybe_unused]] ufunc_op_t op) {} diff --git a/include/nmtools/array/functional/activations/celu.hpp b/include/nmtools/array/functional/activations/celu.hpp index 0bf8c6acf..554fe0cb2 100644 --- a/include/nmtools/array/functional/activations/celu.hpp +++ b/include/nmtools/array/functional/activations/celu.hpp @@ -3,39 +3,20 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/activations/celu.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct celu_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::celu(args...); - } - }; + using celu = fun::unary_ufunc>; } - constexpr inline auto celu = functor_t(unary_fmap_t{}); - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::celu_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::celu_t, arrays_t... - >; + // we want celu[alpha] to works, so do not use fun::unary_ufunc>; + constexpr inline auto celu = functor_t(unary_fmap_t{}); - view_type view; - - constexpr auto operator()() const noexcept - { - return celu[view.op.alpha]; - } - }; + // using lambda breaks boost type index: Type name demangling failed + // constexpr inline auto celu = functor_t(unary_fmap_t{celu_fun}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/activations/elu.hpp b/include/nmtools/array/functional/activations/elu.hpp index 89a1316e9..cef257e45 100644 --- a/include/nmtools/array/functional/activations/elu.hpp +++ b/include/nmtools/array/functional/activations/elu.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/activations/elu.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct elu_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::elu(args...); - } - }; + using elu = fun::unary_ufunc>; } - constexpr inline auto elu = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::elu_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::elu_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return elu[view.op.alpha]; - } - }; + constexpr inline auto elu = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/activations/hardshrink.hpp b/include/nmtools/array/functional/activations/hardshrink.hpp index 9d29a43ca..0d3c93dfa 100644 --- a/include/nmtools/array/functional/activations/hardshrink.hpp +++ b/include/nmtools/array/functional/activations/hardshrink.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/activations/hardshrink.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct hardshrink_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::hardshrink(args...); - } - }; + using hardshrink = fun::unary_ufunc>; } - constexpr inline auto hardshrink = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::hardshrink_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::hardshrink_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return hardshrink[view.op.lambda]; - } - }; + constexpr inline auto hardshrink = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/activations/hardswish.hpp b/include/nmtools/array/functional/activations/hardswish.hpp index c305a15af..7cc0ea61d 100644 --- a/include/nmtools/array/functional/activations/hardswish.hpp +++ b/include/nmtools/array/functional/activations/hardswish.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/activations/hardswish.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct hardswish_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::hardswish(args...); - } - }; + using hardswish = fun::unary_ufunc; } - constexpr inline auto hardswish = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::hardswish_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::hardswish_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return hardswish; - } - }; + constexpr inline auto hardswish = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/activations/hardtanh.hpp b/include/nmtools/array/functional/activations/hardtanh.hpp index e1d77c9e6..cf3a5311a 100644 --- a/include/nmtools/array/functional/activations/hardtanh.hpp +++ b/include/nmtools/array/functional/activations/hardtanh.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/activations/hardtanh.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct hardtanh_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::hardtanh(args...); - } - }; + using hardtanh = fun::unary_ufunc>; } - constexpr inline auto hardtanh = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::hardtanh_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::hardtanh_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return hardtanh[view.op.min_val][view.op.max_val]; - } - }; + constexpr inline auto hardtanh = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/activations/leaky_relu.hpp b/include/nmtools/array/functional/activations/leaky_relu.hpp index 7b2cd73e7..6ea385f2b 100644 --- a/include/nmtools/array/functional/activations/leaky_relu.hpp +++ b/include/nmtools/array/functional/activations/leaky_relu.hpp @@ -3,39 +3,15 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/activations/leaky_relu.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct leaky_relu_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::leaky_relu(args...); - } - }; + using leaky_relu = fun::unary_ufunc>; } - constexpr inline auto leaky_relu = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::leaky_relu_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::leaky_relu_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return leaky_relu[view.op.negative_slope]; - } - }; + constexpr inline auto leaky_relu = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/activations/log_sigmoid.hpp b/include/nmtools/array/functional/activations/log_sigmoid.hpp index 24f8878fb..ae0f512ba 100644 --- a/include/nmtools/array/functional/activations/log_sigmoid.hpp +++ b/include/nmtools/array/functional/activations/log_sigmoid.hpp @@ -3,39 +3,15 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/activations/log_sigmoid.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct log_sigmoid_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::log_sigmoid(args...); - } - }; + using log_sigmoid = fun::unary_ufunc; } - constexpr inline auto log_sigmoid = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::log_sigmoid_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::log_sigmoid_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const - { - return log_sigmoid; - } - }; + constexpr inline auto log_sigmoid = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/activations/mish.hpp b/include/nmtools/array/functional/activations/mish.hpp index a421abbf1..fa4d8a092 100644 --- a/include/nmtools/array/functional/activations/mish.hpp +++ b/include/nmtools/array/functional/activations/mish.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/activations/mish.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct mish_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::mish(args...); - } - }; + using mish = fun::unary_ufunc; } - constexpr inline auto mish = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::mish_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::mish_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return mish; - } - }; + constexpr inline auto mish = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/activations/prelu.hpp b/include/nmtools/array/functional/activations/prelu.hpp index 2321a3dc1..1301fac4d 100644 --- a/include/nmtools/array/functional/activations/prelu.hpp +++ b/include/nmtools/array/functional/activations/prelu.hpp @@ -3,39 +3,15 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/activations/prelu.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct prelu_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::prelu(args...); - } - }; + using prelu = fun::unary_ufunc>; } - constexpr inline auto prelu = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::prelu_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::prelu_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return prelu[view.op.alpha]; - } - }; + constexpr inline auto prelu = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/activations/relu.hpp b/include/nmtools/array/functional/activations/relu.hpp index ccab55f1d..dd3b26204 100644 --- a/include/nmtools/array/functional/activations/relu.hpp +++ b/include/nmtools/array/functional/activations/relu.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/activations/relu.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct relu_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::relu(args...); - } - }; + using relu = fun::unary_ufunc; } // namespace fun - constexpr inline auto relu = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::relu_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::relu_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return relu; - } - }; + constexpr inline auto relu = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/activations/relu6.hpp b/include/nmtools/array/functional/activations/relu6.hpp index 6b3d859e5..2418f1355 100644 --- a/include/nmtools/array/functional/activations/relu6.hpp +++ b/include/nmtools/array/functional/activations/relu6.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/activations/relu6.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct relu6_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::relu6(args...); - } - }; + using relu6 = fun::unary_ufunc; } // namespace fun - constexpr inline auto relu6 = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::relu6_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::relu6_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return relu6; - } - }; + constexpr inline auto relu6 = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/activations/selu.hpp b/include/nmtools/array/functional/activations/selu.hpp index 08d2430c9..f1f335828 100644 --- a/include/nmtools/array/functional/activations/selu.hpp +++ b/include/nmtools/array/functional/activations/selu.hpp @@ -3,39 +3,15 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/activations/selu.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct selu_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::selu(args...); - } - }; + using selu = fun::unary_ufunc; } - constexpr inline auto selu = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::selu_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::selu_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return selu; - } - }; + constexpr inline auto selu = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/activations/sigmoid.hpp b/include/nmtools/array/functional/activations/sigmoid.hpp index 9d9bb075b..4b372a920 100644 --- a/include/nmtools/array/functional/activations/sigmoid.hpp +++ b/include/nmtools/array/functional/activations/sigmoid.hpp @@ -3,39 +3,15 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/activations/sigmoid.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct sigmoid_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::sigmoid(args...); - } - }; + using sigmoid = fun::unary_ufunc; } - constexpr inline auto sigmoid = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::sigmoid_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::sigmoid_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return sigmoid; - } - }; + constexpr inline auto sigmoid = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/activations/silu.hpp b/include/nmtools/array/functional/activations/silu.hpp index 85538e071..a2b0e3b0e 100644 --- a/include/nmtools/array/functional/activations/silu.hpp +++ b/include/nmtools/array/functional/activations/silu.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/activations/silu.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct silu_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::silu(args...); - } - }; + using silu = fun::unary_ufunc; } - constexpr inline auto silu = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::silu_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::silu_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return silu; - } - }; + constexpr inline auto silu = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/activations/softplus.hpp b/include/nmtools/array/functional/activations/softplus.hpp index 323bf6709..1fc298774 100644 --- a/include/nmtools/array/functional/activations/softplus.hpp +++ b/include/nmtools/array/functional/activations/softplus.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/activations/softplus.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct softplus_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::softplus(args...); - } - }; + using softplus = fun::unary_ufunc>; } - constexpr inline auto softplus = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::softplus_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::softplus_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return softplus[view.op.beta][view.op.threshold]; - } - }; + constexpr inline auto softplus = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/activations/softshrink.hpp b/include/nmtools/array/functional/activations/softshrink.hpp index 922f6b30d..a798ac3d9 100644 --- a/include/nmtools/array/functional/activations/softshrink.hpp +++ b/include/nmtools/array/functional/activations/softshrink.hpp @@ -3,39 +3,15 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/activations/softshrink.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct softshrink_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::softshrink(args...); - } - }; + using softshrink = fun::unary_ufunc>; } - constexpr inline auto softshrink = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::softshrink_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::softshrink_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return softshrink[view.op.lambda]; - } - }; + constexpr inline auto softshrink = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/activations/softsign.hpp b/include/nmtools/array/functional/activations/softsign.hpp index dd6530f61..138f407e3 100644 --- a/include/nmtools/array/functional/activations/softsign.hpp +++ b/include/nmtools/array/functional/activations/softsign.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/activations/softsign.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct softsign_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::softsign(args...); - } - }; + using softsign = fun::unary_ufunc; } - constexpr inline auto softsign = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::softsign_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::softsign_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return softsign; - } - }; + constexpr inline auto softsign = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/activations/tanhshrink.hpp b/include/nmtools/array/functional/activations/tanhshrink.hpp index e9f0ea98d..5ab8fe8dc 100644 --- a/include/nmtools/array/functional/activations/tanhshrink.hpp +++ b/include/nmtools/array/functional/activations/tanhshrink.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/activations/tanhshrink.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct tanhshrink_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::tanhshrink(args...); - } - }; + using tanhshrink = fun::unary_ufunc; } - constexpr inline auto tanhshrink = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::tanhshrink_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::tanhshrink_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const - { - return tanhshrink; - } - }; + constexpr inline auto tanhshrink = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/functor.hpp b/include/nmtools/array/functional/functor.hpp index 6be827409..1e3d3ade3 100644 --- a/include/nmtools/array/functional/functor.hpp +++ b/include/nmtools/array/functional/functor.hpp @@ -6,12 +6,11 @@ #include "nmtools/array/view/alias.hpp" #include "nmtools/utility/ct_map.hpp" #include "nmtools/utility/ct_digraph.hpp" +#include "nmtools/utils/isequal/isequal.hpp" +#include "nmtools/utils/isclose/isclose.hpp" namespace nmtools::meta { - struct empty_operands_t {}; - struct empty_attributes_t {}; - using view::resolve_array_type; using view::resolve_array_type_t; @@ -725,4 +724,74 @@ namespace nmtools::functional }; } // namespace nmtools::functional +namespace nmtools::utils +{ + template < + typename F, typename lhs_operands_t, typename lhs_attributes_t + , typename G, typename rhs_operands_t, typename rhs_attributes_t> + constexpr auto isequal( + const functional::functor_t& lhs + , const functional::functor_t& rhs + ) { + if constexpr ( !meta::is_same_v || + !meta::is_same_v + ) { + // TODO: also check the values of operands + return false; + } else if constexpr ( + !meta::is_same_v + && !meta::is_same_v + ) { + constexpr auto M = meta::len_v; + constexpr auto N = meta::len_v; + if constexpr (M != N) { + return false; + } else { + auto equal = true; + meta::template_for([&](auto index){ + auto equal_attribute = [&](){ + auto lhs_attribute = at(lhs.attributes,index); + auto rhs_attribute = at(rhs.attributes,index); + if constexpr (meta::is_floating_point_v + && meta::is_floating_point_v) + { + return isclose(lhs_attribute,rhs_attribute); + } else { + return isequal(lhs_attribute,rhs_attribute); + } + }(); + equal = equal && equal_attribute; + }); + return equal; + } + } else if constexpr ( meta::is_same_v + && meta::is_same_v + && meta::is_same_v + ) { + return true; + } else { + return false; + } + } + + template < + templatetypename lhs_tuple, typename...lhs_functors_t, typename lhs_operands_t, + templatetypename rhs_tuple, typename...rhs_functors_t, typename rhs_operands_t + > + constexpr auto isequal( + const functional::functor_composition_t,lhs_operands_t>& lhs + , const functional::functor_composition_t,rhs_operands_t>& rhs + ) { + constexpr auto N_LHS = meta::len_v; + constexpr auto N_RHS = meta::len_v; + + auto equal = N_LHS == N_RHS; + constexpr auto N = (N_LHS < N_RHS) ? N_LHS : N_RHS; + meta::template_for([&](auto index){ + equal = equal && isequal(at(lhs.functors,index),at(rhs.functors,index)); + }); + return equal; + } +} + #endif // NMTOOLS_ARRAY_FUNCTIONAL_FUNCTOR_HPP \ No newline at end of file diff --git a/include/nmtools/array/functional/ufunc/accumulate.hpp b/include/nmtools/array/functional/ufunc/accumulate.hpp new file mode 100644 index 000000000..54921c703 --- /dev/null +++ b/include/nmtools/array/functional/ufunc/accumulate.hpp @@ -0,0 +1,83 @@ +#ifndef NMTOOLS_ARRAY_FUNCTIONAL_UFUNC_ACCUMULATE_HPP +#define NMTOOLS_ARRAY_FUNCTIONAL_UFUNC_ACCUMULATE_HPP + +#include "nmtools/utils/to_string/to_string.hpp" +#include "nmtools/array/functional/functor.hpp" +#include "nmtools/array/view/ufunc.hpp" + +namespace nmtools::functional::fun +{ + template + struct accumulate + { + template + constexpr auto operator()(const args_t&...args) const + { + if constexpr (is_none_v) { + return view::accumulate(args...); + } else { + return view::accumulate(op_t{},args...); + } + } + }; +} + +namespace nmtools::functional +{ + constexpr inline auto accumulate = functor_t(unary_fmap_t>{}); + + template + struct get_function_t< + view::decorator_t< + view::accumulate_t, args_t... + > + > { + using view_type = view::decorator_t< + view::accumulate_t, args_t... + >; + + view_type view; + + constexpr auto operator()() const noexcept + { + return accumulate[view.attributes()]; + } + }; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template + struct to_string_t< + functional::fun::accumulate, none_t + > { + using ufunc_type = functional::fun::accumulate; + + auto operator()(const ufunc_type&) const noexcept + { + auto op_str = nmtools_string(""); + + if constexpr (!is_none_v) { + op_str = to_string(op_t{}); + + if (op_str.empty()) { + op_str += NMTOOLS_TYPENAME_TO_STRING(op_t); + } + } + + auto str = nmtools_string(""); + + str += "accumulate("; + str += op_str; + str += ")"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING + +#endif // NMTOOLS_ARRAY_FUNCTIONAL_UFUNC_ACCUMULATE_HPP \ No newline at end of file diff --git a/include/nmtools/array/functional/ufunc/outer.hpp b/include/nmtools/array/functional/ufunc/outer.hpp new file mode 100644 index 000000000..36e5ff56e --- /dev/null +++ b/include/nmtools/array/functional/ufunc/outer.hpp @@ -0,0 +1,83 @@ +#ifndef NMTOOLS_ARRAY_FUNCTIONAL_UFUNC_OUTER_HPP +#define NMTOOLS_ARRAY_FUNCTIONAL_UFUNC_OUTER_HPP + +#include "nmtools/utils/to_string/to_string.hpp" +#include "nmtools/array/functional/functor.hpp" +#include "nmtools/array/view/ufunc.hpp" + +namespace nmtools::functional::fun +{ + template + struct outer + { + template + constexpr auto operator()(const args_t&...args) const + { + if constexpr (is_none_v) { + return view::outer(args...); + } else { + return view::outer(op_t{},args...); + } + } + }; +} + +namespace nmtools::functional +{ + constexpr inline auto outer = functor_t(binary_fmap_t>{}); + + template + struct get_function_t< + view::decorator_t< + view::outer_t, args_t... + > + > { + using view_type = view::decorator_t< + view::outer_t, args_t... + >; + + view_type view; + + constexpr auto operator()() const noexcept + { + return outer[view.attributes()]; + } + }; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template + struct to_string_t< + functional::fun::outer, none_t + > { + using ufunc_type = functional::fun::outer; + + auto operator()(const ufunc_type&) const noexcept + { + auto op_str = nmtools_string(""); + + if constexpr (!is_none_v) { + op_str = to_string(op_t{}); + + if (op_str.empty()) { + op_str += NMTOOLS_TYPENAME_TO_STRING(op_t); + } + } + + auto str = nmtools_string(""); + + str += "outer("; + str += op_str; + str += ")"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING + +#endif // NMTOOLS_ARRAY_FUNCTIONAL_UFUNC_OUTER_HPP \ No newline at end of file diff --git a/include/nmtools/array/functional/ufunc/reduce.hpp b/include/nmtools/array/functional/ufunc/reduce.hpp new file mode 100644 index 000000000..f611a5420 --- /dev/null +++ b/include/nmtools/array/functional/ufunc/reduce.hpp @@ -0,0 +1,83 @@ +#ifndef NMTOOLS_ARRAY_FUNCTIONAL_UFUNC_REDUCE_HPP +#define NMTOOLS_ARRAY_FUNCTIONAL_UFUNC_REDUCE_HPP + +#include "nmtools/utils/to_string/to_string.hpp" +#include "nmtools/array/functional/functor.hpp" +#include "nmtools/array/view/ufunc.hpp" + +namespace nmtools::functional::fun +{ + template + struct reduce + { + template + constexpr auto operator()(const args_t&...args) const + { + if constexpr (is_none_v) { + return view::reduce(args...); + } else { + return view::reduce(op_t{},args...); + } + } + }; +} + +namespace nmtools::functional +{ + constexpr inline auto reduce = functor_t(unary_fmap_t>{}); + + template + struct get_function_t< + view::decorator_t< + view::reduce_t, args_t... + > + > { + using view_type = view::decorator_t< + view::reduce_t, args_t... + >; + + view_type view; + + constexpr auto operator()() const noexcept + { + return reduce[view.attributes()]; + } + }; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template + struct to_string_t< + functional::fun::reduce, none_t + > { + using ufunc_type = functional::fun::reduce; + + auto operator()(const ufunc_type&) const noexcept + { + auto op_str = nmtools_string(""); + + if constexpr (!is_none_v) { + op_str = to_string(op_t{}); + + if (op_str.empty()) { + op_str += NMTOOLS_TYPENAME_TO_STRING(op_t); + } + } + + auto str = nmtools_string(""); + + str += "reduce("; + str += op_str; + str += ")"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING + +#endif // NMTOOLS_ARRAY_FUNCTIONAL_UFUNC_REDUCE_HPP \ No newline at end of file diff --git a/include/nmtools/array/functional/ufunc/ufunc.hpp b/include/nmtools/array/functional/ufunc/ufunc.hpp index bee19bde8..cada1b3ce 100644 --- a/include/nmtools/array/functional/ufunc/ufunc.hpp +++ b/include/nmtools/array/functional/ufunc/ufunc.hpp @@ -4,6 +4,131 @@ #include "nmtools/array/view/ufunc/ufunc.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/array/functional/functor.hpp" +#include "nmtools/utils/to_string/to_string.hpp" +#include "nmtools/utils/to_string/common_types.hpp" + +#include "nmtools/utils/isequal.hpp" + +namespace nmtools::functional::fun +{ + template + struct broadcast_binary_ufunc + { + template + constexpr auto operator()(const args_t&...args) const + { + if constexpr (is_none_v) { + return view::broadcast_binary_ufunc(args...); + } else { + return view::broadcast_binary_ufunc(op_t{},args...); + } + } + }; + + template + struct binary_ufunc + { + template + constexpr auto operator()(const args_t&...args) const + { + if constexpr (is_none_v) { + return view::binary_ufunc(args...); + } else { + return view::binary_ufunc(op_t{},args...); + } + } + }; + + template + struct unary_ufunc + { + using op_type = op_t; + + template + constexpr auto operator()(const args_t&...args) const + { + if constexpr (is_none_v) { + return view::unary_ufunc(args...); + } else { + return view::unary_ufunc(op_type{},args...); + } + } + }; +} // namespace nmtools::functional::fun + +namespace nmtools::utils +{ + using functional::fun::unary_ufunc; + using functional::unary_fmap_t; + using functional::functor_t; + + template < + typename F, typename lhs_operands_t, typename lhs_attributes_t + , typename G, typename rhs_operands_t, typename rhs_attributes_t> + constexpr auto isequal( + [[maybe_unused]] const functor_t>,lhs_operands_t,lhs_attributes_t>& lhs + , [[maybe_unused]] const functor_t>,rhs_operands_t,rhs_attributes_t>& rhs + ) + -> meta::enable_if_t<(is_none_v || is_none_v) && !meta::is_same_v,bool> + { + // unfortunately the easiest way to compare is getting the view and extract the function composition + using dummy_i_array_t = nmtools_array; + using dummy_f_array_t = nmtools_array; + constexpr auto can_call_float = meta::expression_check_v; + using dummy_type = meta::conditional_t< + can_call_float, dummy_f_array_t, dummy_i_array_t + >; + auto dummy_array = dummy_type{1}; + + // the following should have same op, regardless how many attributes configuration + auto lhs_view = lhs (dummy_array); + auto rhs_view = rhs (dummy_array); + + // return isequal(lhs_view.attributes(),rhs_view.attributes()); + return lhs_view.attributes() == rhs_view.attributes(); + } +} // namespace nmtools::utils + +namespace nmtools::functional +{ + constexpr inline auto unary_ufunc = functor_t(unary_fmap_t>{}); + constexpr inline auto binary_ufunc = functor_t(binary_fmap_t>{}); + constexpr inline auto broadcast_binary_ufunc = functor_t(binary_fmap_t>{}); + + template + struct get_function_t< + view::decorator_t< + view::ufunc_t, op_t, lhs_t, rhs_t + > + > { + using view_type = view::decorator_t< + view::ufunc_t, op_t, lhs_t, rhs_t + >; + + view_type view; + constexpr auto operator()() const noexcept + { + return broadcast_binary_ufunc[view.attributes()]; + } + }; + + template + struct get_function_t< + view::decorator_t< + view::ufunc_t, op_t, array_t + > + > { + using view_type = view::decorator_t< + view::ufunc_t, op_t, array_t + >; + + view_type view; + constexpr auto operator()() const noexcept + { + return unary_ufunc[view.attributes()]; + } + }; +} // namespace nmtools::functional namespace nmtools::functional { @@ -196,4 +321,95 @@ namespace nmtools::functional }; } +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template + struct to_string_t< + functional::fun::unary_ufunc, none_t + > { + using ufunc_type = functional::fun::unary_ufunc; + + auto operator()(const ufunc_type&) const noexcept + { + auto op_str = nmtools_string(""); + + if constexpr (!is_none_v) { + op_str = to_string(op_t{}); + + if (op_str.empty()) { + op_str += NMTOOLS_TYPENAME_TO_STRING(op_t); + } + } + + auto str = nmtools_string(""); + + str += "ufunc("; + str += op_str; + str += ")"; + + return str; + } + }; + + template + struct to_string_t< + functional::fun::binary_ufunc, none_t + > { + using ufunc_type = functional::fun::binary_ufunc; + + auto operator()(const ufunc_type&) const noexcept + { + auto op_str = nmtools_string(""); + + if constexpr (!is_none_v) { + op_str = to_string(op_t{}); + + if (op_str.empty()) { + op_str += NMTOOLS_TYPENAME_TO_STRING(op_t); + } + } + + auto str = nmtools_string(""); + + str += "ufunc("; + str += op_str; + str += ")"; + + return str; + } + }; + + template + struct to_string_t< + functional::fun::broadcast_binary_ufunc, none_t + > { + using ufunc_type = functional::fun::broadcast_binary_ufunc; + + auto operator()(const ufunc_type&) const noexcept + { + auto op_str = nmtools_string(""); + + if constexpr (!is_none_v) { + op_str = to_string(op_t{}); + + if (op_str.empty()) { + op_str += NMTOOLS_TYPENAME_TO_STRING(op_t); + } + } + + auto str = nmtools_string(""); + + str += "broadcast_ufunc("; + str += op_str; + str += ")"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif /// NMTOOLS_HAS_STRING + #endif // NMTOOLS_ARRAY_FUNCTIONAL_UFUNC_UFUNC_HPP \ No newline at end of file diff --git a/include/nmtools/array/functional/ufuncs/add.hpp b/include/nmtools/array/functional/ufuncs/add.hpp index e8d7c0eb6..2d4df380c 100644 --- a/include/nmtools/array/functional/ufuncs/add.hpp +++ b/include/nmtools/array/functional/ufuncs/add.hpp @@ -3,134 +3,25 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/add.hpp" +#include "nmtools/array/functional/ufunc/accumulate.hpp" +#include "nmtools/array/functional/ufunc/reduce.hpp" +#include "nmtools/array/functional/ufunc/outer.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct add_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::add(args...); - } - }; - - struct reduce_add_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::reduce_add(args...); - } - }; - - struct outer_add_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::outer_add(args...); - } - }; - - struct accumulate_add_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::accumulate_add(args...); - } - }; + using add = fun::broadcast_binary_ufunc>; + using reduce_add = fun::reduce>; + using outer_add = fun::outer>; + using accumulate_add = fun::accumulate>; } - constexpr inline auto add = functor_t(binary_fmap_t{}); - - constexpr inline auto reduce_add = functor_t(unary_fmap_t{}); - - constexpr inline auto outer_add = functor_t(binary_fmap_t{}); - - constexpr inline auto accumulate_add = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::add_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::add_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return add; - } - }; - - template - struct get_function_t< - view::decorator_t< - view::reduce_t, view::add_t, args_t... - > - > { - using view_type = view::decorator_t< - view::reduce_t, view::add_t, args_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - auto dtype = [](){ - if constexpr (is_none_v) { - return res_t{}; - } else { - return dtype_t{}; - } - }(); - return reduce_add[view.axis][dtype][view.initial][view.keepdims]; - } - }; - - template - struct get_function_t< - view::decorator_t< - view::outer_t, view::add_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::outer_t, view::add_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return outer_add; - } - }; - - template - struct get_function_t< - view::decorator_t< - view::accumulate_t, view::add_t, args_t... - > - > { - using view_type = view::decorator_t< - view::accumulate_t, view::add_t, args_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return accumulate_add[view.axis]; - } - }; + constexpr inline auto add = functor_t(binary_fmap_t{}); + constexpr inline auto reduce_add = functor_t(unary_fmap_t{}); + constexpr inline auto outer_add = functor_t(binary_fmap_t{}); + constexpr inline auto accumulate_add = functor_t(unary_fmap_t{}); } // namespace nmtools::functional #endif // NMTOOLS_ARRAY_FUNCTIONAL_UFUNCS_ADD_HPP \ No newline at end of file diff --git a/include/nmtools/array/functional/ufuncs/arccos.hpp b/include/nmtools/array/functional/ufuncs/arccos.hpp index bb8970db6..24aafd8b4 100644 --- a/include/nmtools/array/functional/ufuncs/arccos.hpp +++ b/include/nmtools/array/functional/ufuncs/arccos.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/arccos.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct arccos_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::arccos(args...); - } - }; + using arccos = fun::unary_ufunc; } - constexpr inline auto arccos = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::arccos_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::arccos_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return arccos; - } - }; + constexpr inline auto arccos = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/arccosh.hpp b/include/nmtools/array/functional/ufuncs/arccosh.hpp index b7eaf17a6..f86e44231 100644 --- a/include/nmtools/array/functional/ufuncs/arccosh.hpp +++ b/include/nmtools/array/functional/ufuncs/arccosh.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/arccosh.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct arccosh_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::arccosh(args...); - } - }; + using arccosh = fun::unary_ufunc; } - constexpr inline auto arccosh = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::arccosh_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::arccosh_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return arccosh; - } - }; + constexpr inline auto arccosh = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/arcsin.hpp b/include/nmtools/array/functional/ufuncs/arcsin.hpp index 6844b42c4..070cd5b7b 100644 --- a/include/nmtools/array/functional/ufuncs/arcsin.hpp +++ b/include/nmtools/array/functional/ufuncs/arcsin.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/arcsin.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct arcsin_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::arcsin(args...); - } - }; + using arcsin = fun::unary_ufunc; } - constexpr inline auto arcsin = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::arcsin_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::arcsin_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return arcsin; - } - }; + constexpr inline auto arcsin = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/arcsinh.hpp b/include/nmtools/array/functional/ufuncs/arcsinh.hpp index ecdabdc64..aaedbee37 100644 --- a/include/nmtools/array/functional/ufuncs/arcsinh.hpp +++ b/include/nmtools/array/functional/ufuncs/arcsinh.hpp @@ -3,39 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/arcsinh.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct arcsinh_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::arcsinh(args...); - } - }; + using arcsinh = fun::unary_ufunc; } - constexpr inline auto arcsinh = functor_t(unary_fmap_t{}); - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::arcsinh_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::arcsinh_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return arcsinh; - } - }; + constexpr inline auto arcsinh = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/arctan.hpp b/include/nmtools/array/functional/ufuncs/arctan.hpp index 8efc4397d..c119ad478 100644 --- a/include/nmtools/array/functional/ufuncs/arctan.hpp +++ b/include/nmtools/array/functional/ufuncs/arctan.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/arctan.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct arctan_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::arctan(args...); - } - }; + using arctan = fun::unary_ufunc; } - constexpr inline auto arctan = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::arctan_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::arctan_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return arctan; - } - }; + constexpr inline auto arctan = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/arctanh.hpp b/include/nmtools/array/functional/ufuncs/arctanh.hpp index f20f38e9d..1b7b494f5 100644 --- a/include/nmtools/array/functional/ufuncs/arctanh.hpp +++ b/include/nmtools/array/functional/ufuncs/arctanh.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/arctanh.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct arctanh_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::arctanh(args...); - } - }; + using arctanh = fun::unary_ufunc; } - constexpr inline auto arctanh = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::arctanh_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::arctanh_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return arctanh; - } - }; + constexpr inline auto arctanh = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/cbrt.hpp b/include/nmtools/array/functional/ufuncs/cbrt.hpp index ad2abbccf..7f3be60b7 100644 --- a/include/nmtools/array/functional/ufuncs/cbrt.hpp +++ b/include/nmtools/array/functional/ufuncs/cbrt.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/cbrt.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct cbrt_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::cbrt(args...); - } - }; + using cbrt = fun::unary_ufunc; } - constexpr inline auto cbrt = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::cbrt_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::cbrt_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return cbrt; - } - }; + constexpr inline auto cbrt = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/ceil.hpp b/include/nmtools/array/functional/ufuncs/ceil.hpp index 815d738ae..fbc044b15 100644 --- a/include/nmtools/array/functional/ufuncs/ceil.hpp +++ b/include/nmtools/array/functional/ufuncs/ceil.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/ceil.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct ceil_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::ceil(args...); - } - }; + using ceil = fun::unary_ufunc; } - constexpr inline auto ceil = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::ceil_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::ceil_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return ceil; - } - }; + constexpr inline auto ceil = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/cos.hpp b/include/nmtools/array/functional/ufuncs/cos.hpp index 863a41857..1f6c0bf24 100644 --- a/include/nmtools/array/functional/ufuncs/cos.hpp +++ b/include/nmtools/array/functional/ufuncs/cos.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/cos.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct cos_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::cos(args...); - } - }; + using cos = fun::unary_ufunc; } - constexpr inline auto cos = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::cos_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::cos_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return cos; - } - }; + constexpr inline auto cos = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/cosh.hpp b/include/nmtools/array/functional/ufuncs/cosh.hpp index 5b86b15bc..95f33fa49 100644 --- a/include/nmtools/array/functional/ufuncs/cosh.hpp +++ b/include/nmtools/array/functional/ufuncs/cosh.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/cosh.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct cosh_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::cosh(args...); - } - }; + using cosh = fun::unary_ufunc; } - constexpr inline auto cosh = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::cosh_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::cosh_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return cosh; - } - }; + constexpr inline auto cosh = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/divide.hpp b/include/nmtools/array/functional/ufuncs/divide.hpp index 4d40bbfd5..65fd2ed47 100644 --- a/include/nmtools/array/functional/ufuncs/divide.hpp +++ b/include/nmtools/array/functional/ufuncs/divide.hpp @@ -3,47 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/divide.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct divide_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::divide(args...); - } - }; + using divide = fun::broadcast_binary_ufunc; } - constexpr inline auto divide = functor_t(binary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::divide_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::divide_t, arrays_t... - >; - using array_type = typename view_type::array_type; - using lhs_array_type = meta::at_t; - using rhs_array_type = meta::at_t; - - view_type view; - - constexpr auto operator()() const noexcept - { - if constexpr (meta::is_view_v && !meta::is_same_view_v) { - return divide * get_function(nmtools::get<0>(view.array)); - } else { - return divide; - } - } - }; + constexpr inline auto divide = functor_t(binary_fmap_t{}); } // namespace nmtools::functional #endif // NMTOOLS_ARRAY_FUNCTIONAL_UFUNCS_DIVIDE_HPP \ No newline at end of file diff --git a/include/nmtools/array/functional/ufuncs/exp.hpp b/include/nmtools/array/functional/ufuncs/exp.hpp index b9db919b5..763b8e219 100644 --- a/include/nmtools/array/functional/ufuncs/exp.hpp +++ b/include/nmtools/array/functional/ufuncs/exp.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/exp.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct exp_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::exp(args...); - } - }; + using exp = fun::unary_ufunc; } - constexpr inline auto exp = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::exp_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::exp_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return exp; - } - }; + constexpr inline auto exp = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/exp2.hpp b/include/nmtools/array/functional/ufuncs/exp2.hpp index 2f172287a..2d0273b47 100644 --- a/include/nmtools/array/functional/ufuncs/exp2.hpp +++ b/include/nmtools/array/functional/ufuncs/exp2.hpp @@ -3,39 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/exp2.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct exp2_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::exp2(args...); - } - }; + using exp2 = fun::unary_ufunc; } - constexpr inline auto exp2 = functor_t(unary_fmap_t{}); - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::exp2_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::exp2_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return exp2; - } - }; + constexpr inline auto exp2 = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/expm1.hpp b/include/nmtools/array/functional/ufuncs/expm1.hpp index 000c1d743..64e6e0f1d 100644 --- a/include/nmtools/array/functional/ufuncs/expm1.hpp +++ b/include/nmtools/array/functional/ufuncs/expm1.hpp @@ -3,39 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/expm1.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct expm1_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::expm1(args...); - } - }; + using expm1 = fun::unary_ufunc; } - constexpr inline auto expm1 = functor_t(unary_fmap_t{}); - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::expm1_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::expm1_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return expm1; - } - }; + constexpr inline auto expm1 = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/fabs.hpp b/include/nmtools/array/functional/ufuncs/fabs.hpp index cca9da875..32db476d8 100644 --- a/include/nmtools/array/functional/ufuncs/fabs.hpp +++ b/include/nmtools/array/functional/ufuncs/fabs.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/fabs.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct fabs_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::fabs(args...); - } - }; + using fabs = fun::unary_ufunc; } - constexpr inline auto fabs = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::fabs_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::fabs_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return fabs; - } - }; + constexpr inline auto fabs = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/floor.hpp b/include/nmtools/array/functional/ufuncs/floor.hpp index 79a3d35fb..4576146de 100644 --- a/include/nmtools/array/functional/ufuncs/floor.hpp +++ b/include/nmtools/array/functional/ufuncs/floor.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/floor.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct floor_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::floor(args...); - } - }; + using floor = fun::unary_ufunc; } - constexpr inline auto floor = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::floor_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::floor_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return floor; - } - }; + constexpr inline auto floor = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/invert.hpp b/include/nmtools/array/functional/ufuncs/invert.hpp index f2b965641..1ec0602b2 100644 --- a/include/nmtools/array/functional/ufuncs/invert.hpp +++ b/include/nmtools/array/functional/ufuncs/invert.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/invert.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct invert_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::invert(args...); - } - }; + using invert = fun::unary_ufunc; } - constexpr inline auto invert = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::invert_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::invert_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return invert; - } - }; + constexpr inline auto invert = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/isfinite.hpp b/include/nmtools/array/functional/ufuncs/isfinite.hpp index 4fbeab618..01c4644e1 100644 --- a/include/nmtools/array/functional/ufuncs/isfinite.hpp +++ b/include/nmtools/array/functional/ufuncs/isfinite.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/isfinite.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct isfinite_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::isfinite(args...); - } - }; + using isfinite = fun::unary_ufunc; } - constexpr inline auto isfinite = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::isfinite_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::isfinite_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return isfinite; - } - }; + constexpr inline auto isfinite = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/isinf.hpp b/include/nmtools/array/functional/ufuncs/isinf.hpp index f6c44cb08..c6642b162 100644 --- a/include/nmtools/array/functional/ufuncs/isinf.hpp +++ b/include/nmtools/array/functional/ufuncs/isinf.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/isinf.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct isinf_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::isinf(args...); - } - }; + using isinf = fun::unary_ufunc; } - constexpr inline auto isinf = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::isinf_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::isinf_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return isinf; - } - }; + constexpr inline auto isinf = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/isnan.hpp b/include/nmtools/array/functional/ufuncs/isnan.hpp index b84fd7878..de8638843 100644 --- a/include/nmtools/array/functional/ufuncs/isnan.hpp +++ b/include/nmtools/array/functional/ufuncs/isnan.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/isnan.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct isnan_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::isnan(args...); - } - }; + using isnan = fun::unary_ufunc; } - constexpr inline auto isnan = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::isnan_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::isnan_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return isnan; - } - }; + constexpr inline auto isnan = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/log.hpp b/include/nmtools/array/functional/ufuncs/log.hpp index 35c5c874b..e0377e53f 100644 --- a/include/nmtools/array/functional/ufuncs/log.hpp +++ b/include/nmtools/array/functional/ufuncs/log.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/log.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct log_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::log(args...); - } - }; + using log = fun::unary_ufunc; } - constexpr inline auto log = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::log_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::log_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return log; - } - }; + constexpr inline auto log = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/log10.hpp b/include/nmtools/array/functional/ufuncs/log10.hpp index a972475af..74e80bbde 100644 --- a/include/nmtools/array/functional/ufuncs/log10.hpp +++ b/include/nmtools/array/functional/ufuncs/log10.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/log10.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct log10_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::log10(args...); - } - }; + using log10 = fun::unary_ufunc; } - constexpr inline auto log10 = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::log10_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::log10_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return log10; - } - }; + constexpr inline auto log10 = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/log1p.hpp b/include/nmtools/array/functional/ufuncs/log1p.hpp index a38f21f1b..c5294fa4b 100644 --- a/include/nmtools/array/functional/ufuncs/log1p.hpp +++ b/include/nmtools/array/functional/ufuncs/log1p.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/log1p.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct log1p_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::log1p(args...); - } - }; + using log1p = fun::unary_ufunc; } - constexpr inline auto log1p = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::log1p_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::log1p_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return log1p; - } - }; + constexpr inline auto log1p = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/log2.hpp b/include/nmtools/array/functional/ufuncs/log2.hpp index 4359e1dc0..03f3cbf80 100644 --- a/include/nmtools/array/functional/ufuncs/log2.hpp +++ b/include/nmtools/array/functional/ufuncs/log2.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/log2.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct log2_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::log2(args...); - } - }; + using log2 = fun::unary_ufunc; } - constexpr inline auto log2 = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::log2_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::log2_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return log2; - } - }; + constexpr inline auto log2 = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/maximum.hpp b/include/nmtools/array/functional/ufuncs/maximum.hpp index 4f300d504..f35f5db0c 100644 --- a/include/nmtools/array/functional/ufuncs/maximum.hpp +++ b/include/nmtools/array/functional/ufuncs/maximum.hpp @@ -3,134 +3,25 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/maximum.hpp" +#include "nmtools/array/functional/ufunc/accumulate.hpp" +#include "nmtools/array/functional/ufunc/reduce.hpp" +#include "nmtools/array/functional/ufunc/outer.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct maximum_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::maximum(args...); - } - }; - - struct reduce_maximum_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::reduce_maximum(args...); - } - }; - - struct outer_maximum_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::outer_maximum(args...); - } - }; - - struct accumulate_maximum_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::accumulate_maximum(args...); - } - }; + using maximum = fun::broadcast_binary_ufunc>; + using reduce_maximum = fun::reduce>; + using outer_maximum = fun::outer>; + using accumulate_maximum = fun::accumulate>; } - constexpr inline auto maximum = functor_t(binary_fmap_t{}); - - constexpr inline auto reduce_maximum = functor_t(unary_fmap_t{}); - - constexpr inline auto outer_maximum = functor_t(binary_fmap_t{}); - - constexpr inline auto accumulate_maximum = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::maximum_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::maximum_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return maximum; - } - }; - - template - struct get_function_t< - view::decorator_t< - view::reduce_t, view::maximum_t, args_t... - > - > { - using view_type = view::decorator_t< - view::reduce_t, view::maximum_t, args_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - auto dtype = [](){ - if constexpr (is_none_v) { - return res_t{}; - } else { - return dtype_t{}; - } - }(); - return reduce_maximum[view.axis][dtype][view.initial][view.keepdims]; - } - }; - - template - struct get_function_t< - view::decorator_t< - view::outer_t, view::maximum_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::outer_t, view::maximum_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return outer_maximum; - } - }; - - template - struct get_function_t< - view::decorator_t< - view::accumulate_t, view::maximum_t, args_t... - > - > { - using view_type = view::decorator_t< - view::accumulate_t, view::maximum_t, args_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return accumulate_maximum[view.axis]; - } - }; + constexpr inline auto maximum = functor_t(binary_fmap_t{}); + constexpr inline auto reduce_maximum = functor_t(unary_fmap_t{}); + constexpr inline auto outer_maximum = functor_t(binary_fmap_t{}); + constexpr inline auto accumulate_maximum = functor_t(unary_fmap_t{}); } // namespace nmtools::functional #endif // NMTOOLS_ARRAY_FUNCTIONAL_UFUNCS_MAXIMUM_HPP \ No newline at end of file diff --git a/include/nmtools/array/functional/ufuncs/minimum.hpp b/include/nmtools/array/functional/ufuncs/minimum.hpp index bb186eeec..c61d8edcd 100644 --- a/include/nmtools/array/functional/ufuncs/minimum.hpp +++ b/include/nmtools/array/functional/ufuncs/minimum.hpp @@ -3,134 +3,25 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/minimum.hpp" +#include "nmtools/array/functional/ufunc/accumulate.hpp" +#include "nmtools/array/functional/ufunc/reduce.hpp" +#include "nmtools/array/functional/ufunc/outer.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct minimum_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::minimum(args...); - } - }; - - struct reduce_minimum_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::reduce_minimum(args...); - } - }; - - struct outer_minimum_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::outer_minimum(args...); - } - }; - - struct accumulate_minimum_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::accumulate_minimum(args...); - } - }; + using minimum = fun::broadcast_binary_ufunc>; + using reduce_minimum = fun::reduce>; + using outer_minimum = fun::outer>; + using accumulate_minimum = fun::accumulate>; } - constexpr inline auto minimum = functor_t(binary_fmap_t{}); - - constexpr inline auto reduce_minimum = functor_t(unary_fmap_t{}); - - constexpr inline auto outer_minimum = functor_t(binary_fmap_t{}); - - constexpr inline auto accumulate_minimum = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::minimum_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::minimum_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return minimum; - } - }; - - template - struct get_function_t< - view::decorator_t< - view::reduce_t, view::minimum_t, args_t... - > - > { - using view_type = view::decorator_t< - view::reduce_t, view::minimum_t, args_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - auto dtype = [](){ - if constexpr (is_none_v) { - return res_t{}; - } else { - return dtype_t{}; - } - }(); - return reduce_minimum[view.axis][dtype][view.initial][view.keepdims]; - } - }; - - template - struct get_function_t< - view::decorator_t< - view::outer_t, view::minimum_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::outer_t, view::minimum_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return outer_minimum; - } - }; - - template - struct get_function_t< - view::decorator_t< - view::accumulate_t, view::minimum_t, args_t... - > - > { - using view_type = view::decorator_t< - view::accumulate_t, view::minimum_t, args_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return accumulate_minimum[view.axis]; - } - }; + constexpr inline auto minimum = functor_t(binary_fmap_t{}); + constexpr inline auto reduce_minimum = functor_t(unary_fmap_t{}); + constexpr inline auto outer_minimum = functor_t(binary_fmap_t{}); + constexpr inline auto accumulate_minimum = functor_t(unary_fmap_t{}); } // namespace nmtools::functional #endif // NMTOOLS_ARRAY_FUNCTIONAL_UFUNCS_MINIMUM_HPP \ No newline at end of file diff --git a/include/nmtools/array/functional/ufuncs/multiply.hpp b/include/nmtools/array/functional/ufuncs/multiply.hpp index cb0c7649a..095e00069 100644 --- a/include/nmtools/array/functional/ufuncs/multiply.hpp +++ b/include/nmtools/array/functional/ufuncs/multiply.hpp @@ -2,136 +2,26 @@ #define NMTOOLS_ARRAY_FUNCTIONAL_UFUNCS_MULTIPLY_HPP #include "nmtools/array/functional/functor.hpp" -#include "nmtools/array/functional/ufunc/ufunc.hpp" #include "nmtools/array/view/ufuncs/multiply.hpp" +#include "nmtools/array/functional/ufunc/accumulate.hpp" +#include "nmtools/array/functional/ufunc/reduce.hpp" +#include "nmtools/array/functional/ufunc/outer.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct multiply_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::multiply(args...); - } - }; - - struct reduce_multiply_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::reduce_multiply(args...); - } - }; - - struct outer_multiply_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::outer_multiply(args...); - } - }; - - struct accumulate_multiply_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::accumulate_multiply(args...); - } - }; + using multiply = fun::broadcast_binary_ufunc>; + using reduce_multiply = fun::reduce>; + using outer_multiply = fun::outer>; + using accumulate_multiply = fun::accumulate>; } - constexpr inline auto multiply = functor_t(binary_fmap_t{}); - - constexpr inline auto reduce_multiply = functor_t(unary_fmap_t{}); - - constexpr inline auto outer_multiply = functor_t(binary_fmap_t{}); - - constexpr inline auto accumulate_multiply = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::multiply_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::multiply_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return multiply; - } - }; - - template - struct get_function_t< - view::decorator_t< - view::reduce_t, view::multiply_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::reduce_t, view::multiply_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - auto dtype = [](){ - if constexpr (is_none_v) { - return res_t{}; - } else { - return dtype_t{}; - } - }(); - return reduce_multiply[view.axis][dtype][view.initial][view.keepdims]; - } - }; - - template - struct get_function_t< - view::decorator_t< - view::outer_t, view::multiply_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::outer_t, view::multiply_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return outer_multiply; - } - }; - - template - struct get_function_t< - view::decorator_t< - view::accumulate_t, view::multiply_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::accumulate_t, view::multiply_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return accumulate_multiply[view.axis]; - } - }; + constexpr inline auto multiply = functor_t(binary_fmap_t{}); + constexpr inline auto reduce_multiply = functor_t(unary_fmap_t{}); + constexpr inline auto outer_multiply = functor_t(binary_fmap_t{}); + constexpr inline auto accumulate_multiply = functor_t(unary_fmap_t{}); } // namespace nmtools::functional #endif // NMTOOLS_ARRAY_FUNCTIONAL_UFUNCS_MULTIPLY_HPP \ No newline at end of file diff --git a/include/nmtools/array/functional/ufuncs/negative.hpp b/include/nmtools/array/functional/ufuncs/negative.hpp index 24bc77e39..6e4229260 100644 --- a/include/nmtools/array/functional/ufuncs/negative.hpp +++ b/include/nmtools/array/functional/ufuncs/negative.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/negative.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct negative_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::negative(args...); - } - }; + using negative = fun::unary_ufunc; } - constexpr inline auto negative = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::negative_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::negative_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return negative; - } - }; + constexpr inline auto negative = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/positive.hpp b/include/nmtools/array/functional/ufuncs/positive.hpp index ce3a234b4..531ad8571 100644 --- a/include/nmtools/array/functional/ufuncs/positive.hpp +++ b/include/nmtools/array/functional/ufuncs/positive.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/positive.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct positive_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::positive(args...); - } - }; + using positive = fun::unary_ufunc; } - constexpr inline auto positive = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::positive_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::positive_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return positive; - } - }; + constexpr inline auto positive = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/reciprocal.hpp b/include/nmtools/array/functional/ufuncs/reciprocal.hpp index 38ddf6752..101d9eb08 100644 --- a/include/nmtools/array/functional/ufuncs/reciprocal.hpp +++ b/include/nmtools/array/functional/ufuncs/reciprocal.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/reciprocal.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct reciprocal_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::reciprocal(args...); - } - }; + using reciprocal = fun::unary_ufunc; } - constexpr inline auto reciprocal = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::reciprocal_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::reciprocal_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return reciprocal; - } - }; + constexpr inline auto reciprocal = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/rint.hpp b/include/nmtools/array/functional/ufuncs/rint.hpp index d109052ac..2e4c14166 100644 --- a/include/nmtools/array/functional/ufuncs/rint.hpp +++ b/include/nmtools/array/functional/ufuncs/rint.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/rint.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct rint_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::rint(args...); - } - }; + using rint = fun::unary_ufunc; } - constexpr inline auto rint = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::rint_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::rint_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return rint; - } - }; + constexpr inline auto rint = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/signbit.hpp b/include/nmtools/array/functional/ufuncs/signbit.hpp index cfac57885..17b2c3de6 100644 --- a/include/nmtools/array/functional/ufuncs/signbit.hpp +++ b/include/nmtools/array/functional/ufuncs/signbit.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/signbit.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct signbit_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::signbit(args...); - } - }; + using signbit = fun::unary_ufunc; } - constexpr inline auto signbit = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::signbit_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::signbit_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return signbit; - } - }; + constexpr inline auto signbit = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/sin.hpp b/include/nmtools/array/functional/ufuncs/sin.hpp index c4faaa44c..b183b513f 100644 --- a/include/nmtools/array/functional/ufuncs/sin.hpp +++ b/include/nmtools/array/functional/ufuncs/sin.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/sin.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct sin_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::sin(args...); - } - }; + using sin = fun::unary_ufunc; } - constexpr inline auto sin = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::sin_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::sin_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return sin; - } - }; + constexpr inline auto sin = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/sinh.hpp b/include/nmtools/array/functional/ufuncs/sinh.hpp index 46222c94b..d1ed2e9f5 100644 --- a/include/nmtools/array/functional/ufuncs/sinh.hpp +++ b/include/nmtools/array/functional/ufuncs/sinh.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/sinh.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct sinh_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::sinh(args...); - } - }; + using sinh = fun::unary_ufunc; } - constexpr inline auto sinh = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::sinh_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::sinh_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return sinh; - } - }; + constexpr inline auto sinh = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/sqrt.hpp b/include/nmtools/array/functional/ufuncs/sqrt.hpp index 624c99ae8..e566289d7 100644 --- a/include/nmtools/array/functional/ufuncs/sqrt.hpp +++ b/include/nmtools/array/functional/ufuncs/sqrt.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/sqrt.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct sqrt_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::sqrt(args...); - } - }; + using sqrt = fun::unary_ufunc; } - constexpr inline auto sqrt = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::sqrt_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::sqrt_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return sqrt; - } - }; + constexpr inline auto sqrt = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/square.hpp b/include/nmtools/array/functional/ufuncs/square.hpp index f4f99536a..8f26ad375 100644 --- a/include/nmtools/array/functional/ufuncs/square.hpp +++ b/include/nmtools/array/functional/ufuncs/square.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/square.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct square_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::square(args...); - } - }; + using square = fun::unary_ufunc; } - constexpr inline auto square = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::square_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::square_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return square; - } - }; + constexpr inline auto square = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/subtract.hpp b/include/nmtools/array/functional/ufuncs/subtract.hpp index 7d673fe2a..3b70c4db5 100644 --- a/include/nmtools/array/functional/ufuncs/subtract.hpp +++ b/include/nmtools/array/functional/ufuncs/subtract.hpp @@ -3,164 +3,25 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/subtract.hpp" +#include "nmtools/array/functional/ufunc/accumulate.hpp" +#include "nmtools/array/functional/ufunc/reduce.hpp" +#include "nmtools/array/functional/ufunc/outer.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct subtract_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::subtract(args...); - } - }; - - struct reduce_subtract_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::reduce_subtract(args...); - } - }; - - struct outer_subtract_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::outer_subtract(args...); - } - }; - - struct accumulate_subtract_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::accumulate_subtract(args...); - } - }; + using subtract = fun::broadcast_binary_ufunc>; + using reduce_subtract = fun::reduce>; + using outer_subtract = fun::outer>; + using accumulate_subtract = fun::accumulate>; } - constexpr inline auto subtract = functor_t(binary_fmap_t{}); - - constexpr inline auto reduce_subtract = functor_t(unary_fmap_t{}); - - constexpr inline auto outer_subtract = functor_t(binary_fmap_t{}); - - constexpr inline auto accumulate_subtract = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::subtract_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::subtract_t, arrays_t... - >; - using array_type = typename view_type::array_type; - using lhs_array_type = meta::at_t; - using rhs_array_type = meta::at_t; - - view_type view; - - constexpr auto operator()() const noexcept - { - if constexpr ( - meta::is_view_v - && meta::is_view_v - && !meta::is_same_view_v - && !meta::is_same_view_v - ) { - return subtract - * get_function(nmtools::get<1>(view.array)) - * get_function(nmtools::get<0>(view.array)) - ; - } else if constexpr ( - meta::is_view_v - && !meta::is_same_view_v - ) { - return subtract - * get_function(nmtools::get<0>(view.array)) - ; - } else if constexpr ( - meta::is_view_v - && !meta::is_same_view_v - ) { - // TODO: reverse operands - return subtract - * get_function(nmtools::get<1>(view.array)) - ; - } else { - return subtract; - } - } - }; - - template - struct get_function_t< - view::decorator_t< - view::reduce_t, view::subtract_t, args_t... - > - > { - using view_type = view::decorator_t< - view::reduce_t, view::subtract_t, args_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - auto dtype = [](){ - if constexpr (is_none_v) { - return res_t{}; - } else { - return dtype_t{}; - } - }(); - return reduce_subtract[view.axis][dtype][view.initial][view.keepdims]; - } - }; - - template - struct get_function_t< - view::decorator_t< - view::outer_t, view::subtract_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::outer_t, view::subtract_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return outer_subtract; - } - }; - - template - struct get_function_t< - view::decorator_t< - view::accumulate_t, view::subtract_t, args_t... - > - > { - using view_type = view::decorator_t< - view::accumulate_t, view::subtract_t, args_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return accumulate_subtract[view.axis]; - } - }; + constexpr inline auto subtract = functor_t(binary_fmap_t{}); + constexpr inline auto reduce_subtract = functor_t(unary_fmap_t{}); + constexpr inline auto outer_subtract = functor_t(binary_fmap_t{}); + constexpr inline auto accumulate_subtract = functor_t(unary_fmap_t{}); } // namespace nmtools::functional #endif // NMTOOLS_ARRAY_FUNCTIONAL_UFUNCS_SUBTRACT_HPP \ No newline at end of file diff --git a/include/nmtools/array/functional/ufuncs/tan.hpp b/include/nmtools/array/functional/ufuncs/tan.hpp index 136552641..7e86a93b2 100644 --- a/include/nmtools/array/functional/ufuncs/tan.hpp +++ b/include/nmtools/array/functional/ufuncs/tan.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/tan.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct tan_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::tan(args...); - } - }; + using tan = fun::unary_ufunc; } - constexpr inline auto tan = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::tan_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::tan_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return tan; - } - }; + constexpr inline auto tan = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/functional/ufuncs/tanh.hpp b/include/nmtools/array/functional/ufuncs/tanh.hpp index 1119cc661..d34d57a7f 100644 --- a/include/nmtools/array/functional/ufuncs/tanh.hpp +++ b/include/nmtools/array/functional/ufuncs/tanh.hpp @@ -3,40 +3,16 @@ #include "nmtools/array/functional/functor.hpp" #include "nmtools/array/view/ufuncs/tanh.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" namespace nmtools::functional { namespace fun { - struct tanh_t - { - template - constexpr auto operator()(const args_t&...args) const - { - return view::tanh(args...); - } - }; + using tanh = fun::unary_ufunc; } - constexpr inline auto tanh = functor_t(unary_fmap_t{}); - - template - struct get_function_t< - view::decorator_t< - view::ufunc_t, view::tanh_t, arrays_t... - > - > { - using view_type = view::decorator_t< - view::ufunc_t, view::tanh_t, arrays_t... - >; - - view_type view; - - constexpr auto operator()() const noexcept - { - return tanh; - } - }; + constexpr inline auto tanh = functor_t(unary_fmap_t{}); } // namespace nmtools::functional diff --git a/include/nmtools/array/view/activations/celu.hpp b/include/nmtools/array/view/activations/celu.hpp index 0d2a9e0bb..c33ae2692 100644 --- a/include/nmtools/array/view/activations/celu.hpp +++ b/include/nmtools/array/view/activations/celu.hpp @@ -2,9 +2,11 @@ #define NMTOOLS_ARRAY_VIEW_ACTIVATIONS_CELU_HPP #include "nmtools/array/view/ufunc.hpp" +#include "nmtools/utils/isclose.hpp" +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { /** * @brief Function object for ufunc celu view. @@ -12,7 +14,7 @@ namespace nmtools::view * @tparam alpha_t */ template - struct celu_t + struct celu { const alpha_t alpha = 1.0; @@ -24,7 +26,46 @@ namespace nmtools::view constexpr auto zero = static_cast(0); return math::max(zero,t) + math::min(zero,alpha*(math::exp(t / alpha)-1)); } // operator() - }; // celu_t + + template typename tuple, typename T> + constexpr auto operator[](const tuple& t) const noexcept + { + return celu{nmtools::get<0>(t)}; + } + + template + constexpr auto operator==(const celu other) const + { + return utils::isclose(alpha,other.alpha); + } + }; // celu +} // namespace nmtools::view::fun + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template + struct to_string_t,none_t> + { + auto operator()(view::fun::celu op) const + { + nmtools_string str; + str += "celu{.alpha="; + str += to_string(op.alpha); + str += "}"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING + +namespace nmtools::view +{ + template + using celu_t = fun::celu; /** * @brief Create element-wise celu ufunc view. @@ -42,6 +83,14 @@ namespace nmtools::view { return ufunc(celu_t{{alpha}},array); } // celu + + template + nmtools_func_attribute + NMTOOLS_UFUNC_CONSTEXPR + auto celu(const array_t& array, fun::celu op) + { + return ufunc(op,array); + } // celu } // namespace nmtools::view diff --git a/include/nmtools/array/view/activations/elu.hpp b/include/nmtools/array/view/activations/elu.hpp index 86f673ae2..4f642e8c7 100644 --- a/include/nmtools/array/view/activations/elu.hpp +++ b/include/nmtools/array/view/activations/elu.hpp @@ -2,9 +2,11 @@ #define NMTOOLS_ARRAY_VIEW_ACTIVATIONS_ELU_HPP #include "nmtools/array/view/ufunc.hpp" +#include "nmtools/utils/isclose.hpp" +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { /** * @brief Function object for ELU ufunc. @@ -12,7 +14,7 @@ namespace nmtools::view * @tparam alpha_t */ template - struct elu_t + struct elu { const alpha_t alpha = 1.0; @@ -23,7 +25,46 @@ namespace nmtools::view { return (t > 0? t : alpha * (math::exp(t)-1)); } // operator() - }; // elu_t + + template typename tuple, typename T> + constexpr auto operator[](const tuple& t) const noexcept + { + return elu{nmtools::get<0>(t)}; + } + + template + constexpr auto operator==(const elu other) const + { + return utils::isclose(alpha,other.alpha); + } + }; // elu +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template + struct to_string_t,none_t> + { + auto operator()(view::fun::elu op) const noexcept + { + nmtools_string str; + str += "elu{.alpha="; + str += to_string(op.alpha); + str += "}"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING + +namespace nmtools::view +{ + template + using elu_t = fun::elu; /** * @brief Create element-wise ELU ufunc view. @@ -41,6 +82,14 @@ namespace nmtools::view { return ufunc(elu_t{{alpha}}, array); } // elu + + template + nmtools_func_attribute + NMTOOLS_UFUNC_CONSTEXPR + auto elu(const array_t& array, fun::elu op) + { + return ufunc(op,array); + } } // namespace nmtools::view diff --git a/include/nmtools/array/view/activations/hardshrink.hpp b/include/nmtools/array/view/activations/hardshrink.hpp index 0b067779e..503b6d79c 100644 --- a/include/nmtools/array/view/activations/hardshrink.hpp +++ b/include/nmtools/array/view/activations/hardshrink.hpp @@ -1,9 +1,11 @@ #ifndef NMTOOLS_ARRAY_VIEW_ACTIVATION_HARDSHRINK_HPP #define NMTOOLS_ARRAY_VIEW_ACTIVATION_HARDSHRINK_HPP +#include "nmtools/utils/isclose.hpp" +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" -namespace nmtools::view +namespace nmtools::view::fun { /** * @brief Function object for hardshrink ufunc. @@ -11,7 +13,7 @@ namespace nmtools::view * @tparam lambda_t */ template - struct hardshrink_t + struct hardshrink { const lambda_t lambda = 0.5; @@ -24,7 +26,47 @@ namespace nmtools::view } return x; } // operator() - }; // hardshrink_t + + template typename tuple, typename T> + constexpr auto operator[](const tuple& t) const noexcept + { + return hardshrink{nmtools::get<0>(t)}; + } + + template + constexpr auto operator==(const hardshrink other) const + { + return utils::isclose(lambda,other.lambda); + } + }; // hardshrink +} // namespace nmtools::view::fun + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template + struct to_string_t,none_t> + { + auto operator()(view::fun::hardshrink op) const + { + nmtools_string str; + + str += "hardshrink{.lambda="; + str += to_string(op.lambda); + str += "}"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING + +namespace nmtools::view +{ + template + using hardshrink_t = fun::hardshrink; /** * @brief Creates element-wise hardshrink ufunc view. @@ -40,6 +82,12 @@ namespace nmtools::view { return ufunc(hardshrink_t{{lambda}},array); } // hardshrink + + template + constexpr auto hardshrink(const array_t& array, fun::hardshrink op) + { + return ufunc(op,array); + } // hardshrink } // namespace nmtools::view #endif // NMTOOLS_ARRAY_VIEW_ACTIVATION_HARDSHRINK_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/activations/hardswish.hpp b/include/nmtools/array/view/activations/hardswish.hpp index 296ba0bee..961881607 100644 --- a/include/nmtools/array/view/activations/hardswish.hpp +++ b/include/nmtools/array/view/activations/hardswish.hpp @@ -2,14 +2,15 @@ #define NMTOOLS_ARRAY_VIEW_ACTIVATIONS_HARDSWISH_HPP #include "nmtools/array/view/ufunc.hpp" +#include "nmtools/utils/to_string/to_string.hpp" -namespace nmtools::view +namespace nmtools::view::fun { /** * @brief Function object for hardswish ufunc. * */ - struct hardswish_t + struct hardswish { template constexpr auto operator()(const T& x) const @@ -22,7 +23,32 @@ namespace nmtools::view return x * (x + 3) / 6; } } // operator() - }; // hardswish_t + }; // hardswish +} // namespace nmtools::view::fun + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::hardswish) const + { + nmtools_string str; + + str += "hardswish"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING + +namespace nmtools::view +{ + using hardswish_t = fun::hardswish; /** * @brief Create element-wise hardswish ufunc view. diff --git a/include/nmtools/array/view/activations/hardtanh.hpp b/include/nmtools/array/view/activations/hardtanh.hpp index 17f1da730..737d903e7 100644 --- a/include/nmtools/array/view/activations/hardtanh.hpp +++ b/include/nmtools/array/view/activations/hardtanh.hpp @@ -1,9 +1,11 @@ #ifndef NMTOOLS_ARRAY_VIEW_ACTIVATIONS_HARDTANH_HPP #define NMTOOLS_ARRAY_VIEW_ACTIVATIONS_HARDTANH_HPP +#include "nmtools/utils/isclose.hpp" +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" -namespace nmtools::view +namespace nmtools::view::fun { /** * @brief Function object for hardtanh ufunc. @@ -12,7 +14,7 @@ namespace nmtools::view * @tparam max_val_t */ template - struct hardtanh_t + struct hardtanh { const min_val_t min_val = -1.0; const max_val_t max_val = 1.0; @@ -28,11 +30,56 @@ namespace nmtools::view return t; } } // operator() - }; // hardtanh_t + template typename tuple, typename T, typename U> + constexpr auto operator[](const tuple& t) const noexcept + { + return hardtanh{nmtools::get<0>(t),nmtools::get<1>(t)}; + } + + template typename tuple, typename T> + constexpr auto operator[](const tuple& t) const noexcept + { + return hardtanh{nmtools::get<0>(t)}; + } + + template + constexpr auto operator==(const hardtanh other) const + { + return utils::isclose(min_val,other.min_val) + && utils::isclose(max_val,other.max_val); + } + }; // hardtanh +} // namespace nmtools::view::fun + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ template - nmtools_func_attribute - hardtanh_t(min_val_t,max_val_t) -> hardtanh_t; + struct to_string_t,none_t> + { + auto operator()(view::fun::hardtanh op) const + { + nmtools_string str; + + str += "hardtanh{.min_val="; + str += to_string(op.min_val); + str += ",.max_val="; + str += to_string(op.max_val); + str += "}"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING + +namespace nmtools::view +{ + template + using hardtanh_t = fun::hardtanh; /** * @brief Create element-wise hardtanh ufunc view. @@ -49,7 +96,13 @@ namespace nmtools::view constexpr auto hardtanh(const array_t& array, const min_val_t min_val=min_val_t{-1.0}, const max_val_t max_val=max_val_t{1.0}) { - return ufunc(hardtanh_t{min_val,max_val},array); + return ufunc(hardtanh_t{min_val,max_val},array); + } // hardtanh + + template + constexpr auto hardtanh(const array_t& array, fun::hardtanh op) + { + return ufunc(op,array); } // hardtanh } // namespace nmtools::view diff --git a/include/nmtools/array/view/activations/leaky_relu.hpp b/include/nmtools/array/view/activations/leaky_relu.hpp index 65c479237..c3d65618a 100644 --- a/include/nmtools/array/view/activations/leaky_relu.hpp +++ b/include/nmtools/array/view/activations/leaky_relu.hpp @@ -1,9 +1,11 @@ #ifndef NMTOOLS_ARRAY_VIEW_ACTIVATIONS_LEAKY_RELU_HPP #define NMTOOLS_ARRAY_VIEW_ACTIVATIONS_LEAKY_RELU_HPP +#include "nmtools/utils/isclose.hpp" +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" -namespace nmtools::view +namespace nmtools::view::fun { /** * @brief Function object for leaky relu ufunc @@ -11,7 +13,7 @@ namespace nmtools::view * @tparam negative_slope_t */ template - struct leaky_relu_t + struct leaky_relu { const negative_slope_t negative_slope = 0.01; @@ -20,7 +22,47 @@ namespace nmtools::view { return (t >= 0? t : negative_slope * t); } // operator() - }; // leaky_relu_t + + template typename tuple, typename T> + constexpr auto operator[](const tuple& t) const noexcept + { + return leaky_relu{nmtools::get<0>(t)}; + } + + template + constexpr auto operator==(const leaky_relu other) const + { + return utils::isclose(negative_slope,other.negative_slope); + } + }; // leaky_relu +} // namespace nmtools::view::fun + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template + struct to_string_t,none_t> + { + auto operator()(view::fun::leaky_relu op) const + { + nmtools_string str; + + str += "leaky_relu{.negative_slope="; + str += to_string(op.negative_slope); + str += "}"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING + +namespace nmtools::view +{ + template + using leaky_relu_t = fun::leaky_relu; /** * @brief Create element-wise leaky relu ufunc view. @@ -36,6 +78,12 @@ namespace nmtools::view { return ufunc(leaky_relu_t{{negative_slope}},array); } // leaky_relu + + template + constexpr auto leaky_relu(const array_t& array, fun::leaky_relu op) + { + return ufunc(op,array); + } // leaky_relu } // namespace nmtools::view #endif // NMTOOLS_ARRAY_VIEW_ACTIVATIONS_LEAKY_RELU_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/activations/log_sigmoid.hpp b/include/nmtools/array/view/activations/log_sigmoid.hpp index e5ce0b950..931681d70 100644 --- a/include/nmtools/array/view/activations/log_sigmoid.hpp +++ b/include/nmtools/array/view/activations/log_sigmoid.hpp @@ -2,15 +2,16 @@ #define NMTOOLS_ARRAY_VIEW_ACTIVATIONS_LOG_SIGMOID_HPP #include "nmtools/array/view/ufunc.hpp" +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { /** * @brief Function object for log sigmoid ufunc. * */ - struct log_sigmoid_t + struct log_sigmoid { template nmtools_func_attribute @@ -20,7 +21,32 @@ namespace nmtools::view auto one = static_cast(1); return math::log(one / (one + math::exp(-t))); } // operator() - }; // log_sigmoid_t + }; // log_sigmoid +} // namespace nmtools::view::fun + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::log_sigmoid) const + { + nmtools_string str; + + str += "log_sigmoid"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING + +namespace nmtools::view +{ + using log_sigmoid_t = fun::log_sigmoid; /** * @brief Create element-wise log sigmoid ufunc view. diff --git a/include/nmtools/array/view/activations/mish.hpp b/include/nmtools/array/view/activations/mish.hpp index f093a8918..90dcf8862 100644 --- a/include/nmtools/array/view/activations/mish.hpp +++ b/include/nmtools/array/view/activations/mish.hpp @@ -2,25 +2,51 @@ #define NMTOOLS_ARRAY_VIEW_ACTIVATIONS_MISH_HPP #include "nmtools/array/view/ufunc.hpp" +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/activations/softplus.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { /** * @brief Function object for mish ufunc * */ - struct mish_t + struct mish { template nmtools_func_attribute NMTOOLS_UFUNC_CONSTEXPR auto operator()(const T& t) const { - return t * math::tanh(softplus_t<>::softplus(t)); + return t * math::tanh(softplus<>::eval(t)); } // operator() - }; // mish_t + }; // mish +} // namespace nmtools::view::fun + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::mish) const + { + nmtools_string str; + + str += "mish"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING + +namespace nmtools::view +{ + using mish_t = fun::mish; /** * @brief Create element-wise mish ufunc view diff --git a/include/nmtools/array/view/activations/prelu.hpp b/include/nmtools/array/view/activations/prelu.hpp index 1d048771e..df15a38cd 100644 --- a/include/nmtools/array/view/activations/prelu.hpp +++ b/include/nmtools/array/view/activations/prelu.hpp @@ -1,9 +1,11 @@ #ifndef NMTOOLS_ARRAY_VIEW_ACTIVATIONS_PRELU_HPP #define NMTOOLS_ARRAY_VIEW_ACTIVATIONS_PRELU_HPP +#include "nmtools/utils/isclose.hpp" +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" -namespace nmtools::view +namespace nmtools::view::fun { /** * @brief Function object for prelu ufunc @@ -11,7 +13,7 @@ namespace nmtools::view * @tparam alpha_t */ template - struct prelu_t + struct prelu { const alpha_t alpha = 0.25; @@ -24,7 +26,47 @@ namespace nmtools::view return alpha * t; } } // operator() - }; // prelu_t + + template typename tuple, typename T> + constexpr auto operator[](const tuple& t) const noexcept + { + return prelu{nmtools::get<0>(t)}; + } + + template + constexpr auto operator==(const prelu other) const + { + return utils::isclose(alpha,other.alpha); + } + }; // prelu +} // namespace nmtools::view::fun + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template + struct to_string_t,none_t> + { + auto operator()(view::fun::prelu op) const + { + nmtools_string str; + + str += "prelu{.alpha="; + str += to_string(op.alpha); + str += "}"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING + +namespace nmtools::view +{ + template + using prelu_t = fun::prelu; /** * @brief Create element-wise prelu ufunc view @@ -40,6 +82,12 @@ namespace nmtools::view { return ufunc(prelu_t{{alpha}},array); } // prelu + + template + constexpr auto prelu(const array_t& array, fun::prelu op) + { + return ufunc(op,array); + } // prelu } // namespace nmtools::view diff --git a/include/nmtools/array/view/activations/relu.hpp b/include/nmtools/array/view/activations/relu.hpp index 793e1e1e5..62ff0aa5d 100644 --- a/include/nmtools/array/view/activations/relu.hpp +++ b/include/nmtools/array/view/activations/relu.hpp @@ -1,22 +1,48 @@ #ifndef NMTOOLS_ARRAY_VIEW_ACTIVATIONS_RELU_HPP #define NMTOOLS_ARRAY_VIEW_ACTIVATIONS_RELU_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" -namespace nmtools::view +namespace nmtools::view::fun { /** * @brief Function object for ufunc relu view * */ - struct relu_t + struct relu { template constexpr auto operator()(const T& x) const { return static_cast(x > 0? x : 0); } // operator() - }; // relu_t + }; // relu +} // namespace nmtools::view::fun + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::relu) const + { + nmtools_string str; + + str += "relu"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING + +namespace nmtools::view +{ + using relu_t = fun::relu; /** * @brief Creates element-wise ufunc relu view diff --git a/include/nmtools/array/view/activations/relu6.hpp b/include/nmtools/array/view/activations/relu6.hpp index eec204ee2..6ea37b7b6 100644 --- a/include/nmtools/array/view/activations/relu6.hpp +++ b/include/nmtools/array/view/activations/relu6.hpp @@ -1,11 +1,12 @@ #ifndef NMTOOLS_ARRAY_VIEW_ACTIVATIONS_RELU6_HPP #define NMTOOLS_ARRAY_VIEW_ACTIVATIONS_RELU6_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct relu6_t + struct relu6 { template constexpr auto operator()(const T& t) const @@ -18,7 +19,32 @@ namespace nmtools::view } return x; } // operator() - }; // relu6_t + }; // relu6 +} // namespace nmtools::view::fun + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::relu6) const + { + nmtools_string str; + + str += "relu6"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING + +namespace nmtools::view +{ + using relu6_t = fun::relu6; template constexpr auto relu6(const array_t& array) diff --git a/include/nmtools/array/view/activations/selu.hpp b/include/nmtools/array/view/activations/selu.hpp index 2531b31b9..85a2a14cc 100644 --- a/include/nmtools/array/view/activations/selu.hpp +++ b/include/nmtools/array/view/activations/selu.hpp @@ -1,16 +1,17 @@ #ifndef NMTOOLS_ARRAY_VIEW_ACTIVATIONS_SELU_HPP #define NMTOOLS_ARRAY_VIEW_ACTIVATIONS_SELU_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { /** * @brief Function object for selu ufunc * */ - struct selu_t + struct selu { template nmtools_func_attribute @@ -22,7 +23,32 @@ namespace nmtools::view constexpr auto zero = static_cast(0); return scale * (math::max(t,zero) + math::min(alpha * (math::exp(t) - 1), zero)); } // operator() - }; // selu_t + }; // selu +} // namespace nmtools::view::fun + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::selu) const + { + nmtools_string str; + + str += "selu"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING + +namespace nmtools::view +{ + using selu_t = fun::selu; /** * @brief Create element-wise selu ufunc view. diff --git a/include/nmtools/array/view/activations/sigmoid.hpp b/include/nmtools/array/view/activations/sigmoid.hpp index 287312403..7d47edc6b 100644 --- a/include/nmtools/array/view/activations/sigmoid.hpp +++ b/include/nmtools/array/view/activations/sigmoid.hpp @@ -1,21 +1,22 @@ #ifndef NMTOOLS_ARRAY_VIEW_ACTIVATIONS_SIGMOID_HPP #define NMTOOLS_ARRAY_VIEW_ACTIVATIONS_SIGMOID_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { /** * @brief Function object for sigmoid ufunc * */ - struct sigmoid_t + struct sigmoid { template nmtools_func_attribute NMTOOLS_UFUNC_CONSTEXPR - static auto sigmoid(const T& t) + static auto eval(const T& t) { auto one = static_cast(1); return one / (one + math::exp(-t)); @@ -26,9 +27,34 @@ namespace nmtools::view NMTOOLS_UFUNC_CONSTEXPR auto operator()(const T& t) const { - return sigmoid(t); + return eval(t); } // operator() - }; // sigmoid_t + }; // sigmoid +} // namespace nmtools::view::fun + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::sigmoid) const + { + nmtools_string str; + + str += "sigmoid"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING + +namespace nmtools::view +{ + using sigmoid_t = fun::sigmoid; /** * @brief Create element-wise sigmoid ufunc view diff --git a/include/nmtools/array/view/activations/silu.hpp b/include/nmtools/array/view/activations/silu.hpp index 8d7cb3533..aa19eac4e 100644 --- a/include/nmtools/array/view/activations/silu.hpp +++ b/include/nmtools/array/view/activations/silu.hpp @@ -1,25 +1,51 @@ #ifndef NMTOOLS_ARRAY_VIEW_ACTIVATIONS_SILU_HPP #define NMTOOLS_ARRAY_VIEW_ACTIVATIONS_SILU_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/array/view/activations/sigmoid.hpp" -namespace nmtools::view +namespace nmtools::view::fun { /** * @brief Function object for silu ufunc * */ - struct silu_t : sigmoid_t + struct silu : sigmoid { template nmtools_func_attribute NMTOOLS_UFUNC_CONSTEXPR auto operator()(const T& t) const { - return t * sigmoid(t); + return t * sigmoid::eval(t); } // operator() - }; // silu_t + }; // silu +} // namespace nmtools::view::fun + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::silu) const + { + nmtools_string str; + + str += "silu"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING + +namespace nmtools::view +{ + using silu_t = fun::silu; /** * @brief Create element-wise Sigmoid Linear Unit (SiLU) ufunc view. diff --git a/include/nmtools/array/view/activations/softplus.hpp b/include/nmtools/array/view/activations/softplus.hpp index 581f4bf6a..88a0af171 100644 --- a/include/nmtools/array/view/activations/softplus.hpp +++ b/include/nmtools/array/view/activations/softplus.hpp @@ -1,10 +1,12 @@ #ifndef NMTOOLS_ARRAY_VIEW_ACTIVATIONS_SOFTPLUS_HPP #define NMTOOLS_ARRAY_VIEW_ACTIVATIONS_SOFTPLUS_HPP +#include "nmtools/utils/isclose.hpp" +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { /** * @brief Function object for softplus ufunc @@ -12,8 +14,8 @@ namespace nmtools::view * @tparam beta_t * @tparam threshold_t */ - template - struct softplus_t + template + struct softplus { const beta_t beta = 1; const threshold_t threshold = 20; @@ -21,28 +23,75 @@ namespace nmtools::view template nmtools_func_attribute NMTOOLS_UFUNC_CONSTEXPR - static auto softplus(const T& x, beta_type beta=beta_type{1}, threshold_type threshold=threshold_type{20}) + static auto eval(const T& x, beta_type beta=beta_type{1}, threshold_type threshold=threshold_type{20}) { - auto t_times_beta = x * beta; + using result_t = decltype(math::exp(x)); + result_t res = x; + auto t_times_beta = res * beta; if (t_times_beta > threshold) { - return x; + return res; } else { - return math::log(1 + math::exp(t_times_beta)) / beta; + return static_cast(math::log(1 + math::exp(t_times_beta)) / beta); } - } // softplus + } // eval template nmtools_func_attribute NMTOOLS_UFUNC_CONSTEXPR auto operator()(const T& x) const { - return softplus(x,beta,threshold); + return eval(x,beta,threshold); } // operator() - }; // softplus_t + template typename tuple, typename T, typename U> + constexpr auto operator[](const tuple& x) const noexcept + { + return softplus{nmtools::get<0>(x),nmtools::get<1>(x)}; + } + + template typename tuple, typename T> + constexpr auto operator[](const tuple& x) const noexcept + { + return softplus{nmtools::get<0>(x)}; + } + + template + constexpr auto operator==(const softplus other) const + { + return utils::isclose(beta,other.beta) + && utils::isclose(threshold,other.threshold); + } + }; // softplus +} // namespace nmtools::view::fun + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ template - nmtools_func_attribute - softplus_t(beta_t,threshold_t) -> softplus_t; + struct to_string_t,none_t> + { + auto operator()(view::fun::softplus op) const + { + nmtools_string str; + + str += "softplus{.beta="; + str += to_string(op.beta); + str += ",.threshold="; + str += to_string(op.threshold); + str += "}"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING + +namespace nmtools::view +{ + template + using softplus_t = fun::softplus; /** * @brief Create element-wise softplus ufunc view. @@ -60,9 +109,16 @@ namespace nmtools::view NMTOOLS_UFUNC_CONSTEXPR auto softplus(const array_t& array, beta_t beta=beta_t{1}, threshold_t threshold=threshold_t{20}) { - return ufunc(softplus_t{beta,threshold},array); + return ufunc(softplus_t{beta,threshold},array); } // softplus + template + nmtools_func_attribute + NMTOOLS_UFUNC_CONSTEXPR + auto softplus(const array_t& array, fun::softplus op) + { + return ufunc(op,array); + } // softplus } // namespace nmtools::view #endif // NMTOOLS_ARRAY_VIEW_ACTIVATIONS_SOFTPLUS_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/activations/softshrink.hpp b/include/nmtools/array/view/activations/softshrink.hpp index 5bec3ca25..d5da7d795 100644 --- a/include/nmtools/array/view/activations/softshrink.hpp +++ b/include/nmtools/array/view/activations/softshrink.hpp @@ -2,8 +2,11 @@ #define NMTOOLS_ARRAY_VIEW_ACTIVATIONS_SOFTSHRINK_HPP #include "nmtools/array/view/ufunc.hpp" +// TODO: maybe do not include all parts of isclose here, refactor to isclose_t maybe +#include "nmtools/utils/isclose.hpp" +#include "nmtools/utils/to_string/to_string.hpp" -namespace nmtools::view +namespace nmtools::view::fun { /** * @brief Function object for softshrink ufunc @@ -11,7 +14,7 @@ namespace nmtools::view * @tparam lambda_t */ template - struct softshrink_t + struct softshrink { const lambda_t lambda = 0.5; @@ -26,7 +29,47 @@ namespace nmtools::view return static_cast(0); } } // operator() - }; // softshrink_t + + template typename tuple, typename T> + constexpr auto operator[](const tuple args) const noexcept + { + return softshrink{nmtools::get<0>(args)}; + } + + template + constexpr auto operator==(const softshrink other) const + { + return utils::isclose(lambda,other.lambda); + } + }; // softshrink +} // namespace nmtools::view::fun + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template + struct to_string_t,none_t> + { + auto operator()(view::fun::softshrink op) const + { + nmtools_string str; + + str += "softshrink{.lambda="; + str += to_string(op.lambda); + str += "}"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING + +namespace nmtools::view +{ + template + using softshrink_t = fun::softshrink; /** * @brief Create element-wise softshrink ufunc view. @@ -42,6 +85,12 @@ namespace nmtools::view { return ufunc(softshrink_t{{lambda}},array); } // softshrink + + template + constexpr auto softshrink(const array_t& array, fun::softshrink op) + { + return ufunc(op,array); + } // softshrink } // namespace nmtools::view diff --git a/include/nmtools/array/view/activations/softsign.hpp b/include/nmtools/array/view/activations/softsign.hpp index a19667eed..b066c4b92 100644 --- a/include/nmtools/array/view/activations/softsign.hpp +++ b/include/nmtools/array/view/activations/softsign.hpp @@ -1,15 +1,16 @@ #ifndef NMTOOLS_ARRAY_VIEW_ACTIVATION_SOFTSIGN_HPP #define NMTOOLS_ARRAY_VIEW_ACTIVATION_SOFTSIGN_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" -namespace nmtools::view +namespace nmtools::view::fun { /** * @brief Function object for softsign ufunc * */ - struct softsign_t + struct softsign { template constexpr auto operator()(const T& x) const @@ -17,7 +18,32 @@ namespace nmtools::view auto abs_x = x > 0 ? x : -x; return x / (1 + abs_x); } // operator() - }; // softsign_t + }; // softsign +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::softsign) const + { + nmtools_string str; + + str += "softsign"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING + +namespace nmtools::view +{ + using softsign_t = fun::softsign; /** * @brief Create element-wise softsign ufunc view diff --git a/include/nmtools/array/view/activations/tanhshrink.hpp b/include/nmtools/array/view/activations/tanhshrink.hpp index c77d53fe3..3df0a58a3 100644 --- a/include/nmtools/array/view/activations/tanhshrink.hpp +++ b/include/nmtools/array/view/activations/tanhshrink.hpp @@ -2,15 +2,16 @@ #define NMTOOLS_ARRAY_VIEW_ACTIVATIONS_TANHSHRINK_HPP #include "nmtools/array/view/ufunc.hpp" +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { /** * @brief Function object for tanhshrink ufunc * */ - struct tanhshrink_t + struct tanhshrink { template NMTOOLS_UFUNC_CONSTEXPR @@ -19,7 +20,32 @@ namespace nmtools::view { return x - math::tanh(x); } // operator() - }; // tanhshrink_t + }; // tanhshrink +} // namespace nmtools::view::fun + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::tanhshrink) const + { + nmtools_string str; + + str += "tanhshrink"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING + +namespace nmtools::view +{ + using tanhshrink_t = fun::tanhshrink; /** * @brief Create element-wise tanhshrink ufunc view diff --git a/include/nmtools/array/view/prod.hpp b/include/nmtools/array/view/prod.hpp index 979d6fd18..4fa2f9951 100644 --- a/include/nmtools/array/view/prod.hpp +++ b/include/nmtools/array/view/prod.hpp @@ -24,19 +24,19 @@ namespace nmtools::view * @return constexpr auto */ template - constexpr auto prod(const left_t& a, const axis_t& axis, dtype_t, initial_t initial, keepdims_t keepdims) + constexpr auto prod(const left_t& a, const axis_t& axis, dtype_t dtype, initial_t initial, keepdims_t keepdims) { using res_t = get_dtype_t; using op_t = multiply_t; - return reduce(op_t{},a,axis,initial,keepdims); + return reduce(op_t{},a,axis,dtype,initial,keepdims); } // prod template - constexpr auto prod(const left_t& a, const axis_t& axis, dtype_t, initial_t initial) + constexpr auto prod(const left_t& a, const axis_t& axis, dtype_t dtype, initial_t initial) { using res_t = get_dtype_t; using op_t = multiply_t; - return reduce(op_t{},a,axis,initial); + return reduce(op_t{},a,axis,dtype,initial); } // prod template diff --git a/include/nmtools/array/view/sum.hpp b/include/nmtools/array/view/sum.hpp index f4a249d21..2ff552f5b 100644 --- a/include/nmtools/array/view/sum.hpp +++ b/include/nmtools/array/view/sum.hpp @@ -24,19 +24,19 @@ namespace nmtools::view * @return constexpr auto */ template - constexpr auto sum(const left_t& a, const axis_t& axis, dtype_t, initial_t initial, keepdims_t keepdims) + constexpr auto sum(const left_t& a, const axis_t& axis, dtype_t dtype, initial_t initial, keepdims_t keepdims) { using res_t = get_dtype_t; using op_t = add_t; - return reduce(op_t{},a,axis,initial,keepdims); + return reduce(op_t{},a,axis,dtype,initial,keepdims); } // add template - constexpr auto sum(const left_t& a, const axis_t& axis, dtype_t, initial_t initial) + constexpr auto sum(const left_t& a, const axis_t& axis, dtype_t dtype, initial_t initial) { using res_t = get_dtype_t; using op_t = add_t; - return reduce(op_t{},a,axis,initial); + return reduce(op_t{},a,axis,dtype,initial); } // add template diff --git a/include/nmtools/array/view/ufunc.hpp b/include/nmtools/array/view/ufunc.hpp index 16f926cac..b0ca5b79c 100644 --- a/include/nmtools/array/view/ufunc.hpp +++ b/include/nmtools/array/view/ufunc.hpp @@ -14,6 +14,8 @@ namespace nmtools::view template typename tuple, typename op_t, typename...arrays_t> ufunc_t(op_t, tuple) -> ufunc_t; + // TODO: remove + #if 1 template typename tuple, typename...arrays_t, size_t...Is> constexpr auto _ufunc(op_t op, const tuple& func, meta::index_sequence) { @@ -28,7 +30,7 @@ namespace nmtools::view }; // _ufunc /** - * @brief Creates unfunc_t object, given op and arrays. + * @brief Creates ufunc_t object, given op and arrays. * * @tparam op_t * @tparam array_t @@ -103,6 +105,155 @@ namespace nmtools::view #endif // NMTOOLS_NO_BASE_ACCESS } } // ufunc + #endif + + // TODO: handle optional + template + constexpr auto unary_ufunc(op_t op, const array_t& array, op_args_t...op_args) + { + if constexpr (sizeof...(op_args)) { + return unary_ufunc(op[nmtools_tuple{op_args...}],array); + } else if constexpr (meta::is_num_v) { + using view_t = decorator_t; + return view_t{{op,array}}; + } else { + using result_t = decorator_t; + return result_t{{op,array}}; + } + } // unary_ufunc + + // TODO: handle optional lhs, rhs + template + constexpr auto binary_ufunc(op_t op, const lhs_t& lhs, const rhs_t& rhs) + { + if constexpr (meta::is_either_v) { + using l_lhs_t = meta::get_either_left_t; + using l_rhs_t = meta::get_either_right_t; + using lhs_ufunc_t = decltype(binary_ufunc(op,meta::declval(),rhs)); + using rhs_ufunc_t = decltype(binary_ufunc(op,meta::declval(),rhs)); + using result_t = meta::replace_either_t; + if (auto lptr = nmtools::get_if(&lhs)) { + return result_t{binary_ufunc(op,*lptr,rhs)}; + } else { + auto rptr = nmtools::get_if(&lhs); + return result_t{binary_ufunc(op,*rptr,rhs)}; + } + } else if constexpr (meta::is_either_v) { + using r_lhs_t = meta::get_either_left_t; + using r_rhs_t = meta::get_either_right_t; + using lhs_ufunc_t = decltype(binary_ufunc(op,lhs,meta::declval())); + using rhs_ufunc_t = decltype(binary_ufunc(op,lhs,meta::declval())); + using result_t = meta::replace_either_t; + if (auto lptr = nmtools::get_if(&rhs)) { + return result_t{binary_ufunc(op,lhs,*lptr)}; + } else { + auto rptr = nmtools::get_if(&rhs); + return result_t{binary_ufunc(op,lhs,*rptr)}; + } + } else if constexpr (meta::is_num_v && meta::is_num_v) { + // all rhs are numeric, use scalar_ufunc instead + using view_t = decorator_t; + return view_t{{op,lhs,rhs}}; + } else { + using result_t = decorator_t; + return result_t{{op,lhs,rhs}}; + } + } // binary_ufunc + + template typename tuple, typename lhs_t, typename rhs_t> + constexpr auto binary_ufunc(op_t op, const tuple& arrays) + { + return binary_ufunc(op,nmtools::get<0>(arrays),nmtools::get<1>(arrays)); + } // binary_ufunc + + // TODO: handle optional lhs, rhs + /** + * @brief Creates ufunc_t object, given op and arrays. + * + * @tparam op_t + * @tparam lhs_t + * @tparam rhs_t + * @param op + * @param lhs + * @param rhs + * @return constexpr auto + */ + template + constexpr auto broadcast_binary_ufunc(op_t op, const lhs_t& lhs, const rhs_t& rhs) + { + if constexpr (meta::is_either_v) { + using l_lhs_t = meta::get_either_left_t; + using l_rhs_t = meta::get_either_right_t; + using lhs_ufunc_t = decltype(broadcast_binary_ufunc(op,meta::declval(),rhs)); + using rhs_ufunc_t = decltype(broadcast_binary_ufunc(op,meta::declval(),rhs)); + using result_t = meta::replace_either_t; + if (auto lptr = nmtools::get_if(&lhs)) { + static_assert( meta::is_pointer_v + , "nmtools internal error" ); + static_assert( meta::is_same_v,l_lhs_t> + , "nmtools internal error" ); + return result_t{broadcast_binary_ufunc(op,*lptr,rhs)}; + } else { + auto rptr = nmtools::get_if(&lhs); + static_assert( meta::is_pointer_v + , "nmtools internal error" ); + static_assert( meta::is_same_v,l_rhs_t> + , "nmtools internal error" ); + return result_t{broadcast_binary_ufunc(op,*rptr,rhs)}; + } + } else if constexpr (meta::is_either_v) { + using r_lhs_t = meta::get_either_left_t; + using r_rhs_t = meta::get_either_right_t; + using lhs_ufunc_t = decltype(broadcast_binary_ufunc(op,lhs,meta::declval())); + using rhs_ufunc_t = decltype(broadcast_binary_ufunc(op,lhs,meta::declval())); + using result_t = meta::replace_either_t; + if (auto lptr = nmtools::get_if(&rhs)) { + static_assert( meta::is_pointer_v + , "nmtools internal error" ); + static_assert( meta::is_same_v,r_lhs_t> + , "nmtools internal error" ); + return result_t{broadcast_binary_ufunc(op,lhs,*lptr)}; + } else { + auto rptr = nmtools::get_if(&rhs); + static_assert( meta::is_pointer_v + , "nmtools internal error" ); + static_assert( meta::is_same_v,r_rhs_t> + , "nmtools internal error" ); + return result_t{broadcast_binary_ufunc(op,lhs,*rptr)}; + } + } else if constexpr (meta::is_num_v && meta::is_num_v) { + // all rhs are numeric, use scalar_ufunc instead + using view_t = decorator_t; + return view_t{{op,lhs,rhs}}; + } else { + auto broadcasted_arrays = broadcast_arrays(lhs, rhs); + return binary_ufunc(op, broadcasted_arrays); + } + } // broadcast_binary_ufunc + + template + constexpr auto unary_ufunc(const array_t& array, args::ufunc attributes, args_t...args) + { + return unary_ufunc(attributes.op,array,args...); + } // unary_ufunc + + template + constexpr auto binary_ufunc(const lhs_t& lhs, const rhs_t& rhs, args::ufunc attributes) + { + return binary_ufunc(attributes.op,lhs,rhs); + } // binary_ufunc + + template typename tuple, typename lhs_t, typename rhs_t> + constexpr auto binary_ufunc(const tuple& arrays, args::ufunc attributes) + { + return binary_ufunc(attributes.op,arrays); + } // binary_ufunc + + template + constexpr auto broadcast_binary_ufunc(const lhs_t& lhs, const rhs_t& rhs, args::ufunc attributes) + { + return broadcast_binary_ufunc(attributes.op,lhs,rhs); + } // broadcast_binary_ufunc /** * @brief Create reduce_t object given op, array, axis and initial value. @@ -118,8 +269,8 @@ namespace nmtools::view * @param keepdims keep reduced axes in the result as dimensions with size one. * @return constexpr auto */ - template - constexpr auto reduce(op_t op, const array_t& array, const axis_t& axis, initial_t initial, keepdims_t keepdims=keepdims_t{}) + template + constexpr auto reduce(op_t op, const array_t& array, const axis_t& axis, dtype_t dtype=dtype_t{}, initial_t initial=initial_t{}, keepdims_t keepdims=keepdims_t{}) { // note: here, axis as reference to prevent array decays // the view type may decide wether to take ref or copy @@ -128,14 +279,14 @@ namespace nmtools::view if constexpr (meta::is_either_v) { using left_t = meta::get_either_left_t; using right_t = meta::get_either_right_t; - using ret_left_t = decltype(reduce(op,meta::declval(),axis,initial,keepdims)); - using ret_right_t = decltype(reduce(op,meta::declval(),axis,initial,keepdims)); + using ret_left_t = decltype(reduce(op,meta::declval(),axis,dtype,initial,keepdims)); + using ret_right_t = decltype(reduce(op,meta::declval(),axis,dtype,initial,keepdims)); using either_t = meta::replace_either_t; if (auto l_ptr = nmtools::get_if(&array)) { - return either_t{reduce(op,*l_ptr,axis,initial,keepdims)}; + return either_t{reduce(op,*l_ptr,axis,dtype,initial,keepdims)}; } else /* if (auto r_ptr = nmtools::get_if(&array)) */ { auto r_ptr = nmtools::get_if(&array); - return either_t{reduce(op,*r_ptr,axis,initial,keepdims)}; + return either_t{reduce(op,*r_ptr,axis,dtype,initial,keepdims)}; } } // keepdims is runtime value, @@ -145,22 +296,36 @@ namespace nmtools::view // use variant to tell that the return value may be scalar or ndarray, // depending on the value of keepdims at runtime else if constexpr (meta::is_boolean_v) { - using left_t = decltype(reduce(op,array,axis,initial,True)); - using right_t = decltype(reduce(op,array,axis,initial,False)); + using left_t = decltype(reduce(op,array,axis,dtype,initial,True)); + using right_t = decltype(reduce(op,array,axis,dtype,initial,False)); using either_t = meta::make_either_type_t; return ( keepdims ? - either_t{reduce(op,array,axis,initial,True)} - : either_t{reduce(op,array,axis,initial,False)} + either_t{reduce(op,array,axis,dtype,initial,True)} + : either_t{reduce(op,array,axis,dtype,initial,False)} ); } // otherwise simply use as it is else { - using view_t = decorator_t; - return view_t{{op,array,axis,initial,keepdims}}; + using view_t = decorator_t; + return view_t{{op,array,axis,initial,keepdims,dtype}}; } } // reduce + template + constexpr auto reduce(const array_t& array, const args::reduce& attributes) + { + using view_t = decorator_t; + return view_t{{array,attributes}}; + } + + template + constexpr auto reduce(const array_t& array, op_t op, const args::reduce& attributes) + { + using view_t = decorator_t; + return view_t{{op,array,attributes.axis,attributes.initial,attributes.keepdims,attributes.dtype}}; + } + /** * @brief Create accumulate_t object given op, array and axis. * @@ -172,12 +337,26 @@ namespace nmtools::view * @param axis * @return constexpr auto */ - template - constexpr auto accumulate(op_t op, const array_t& array, axis_t axis) + template + constexpr auto accumulate(op_t op, const array_t& array, axis_t axis, dtype_t dtype=dtype_t{}) { // note: axis as reference to prevent array decays - using view_t = decorator_t; - return view_t{{op,array,axis}}; + using view_t = decorator_t; + return view_t{{op,array,axis,dtype}}; + } // accumulate + + template + constexpr auto accumulate(const array_t& array, const args::accumulate& attributes) + { + // TODO: call overloaded accumulate version, to make it easier for maybe/either + using view_t = decorator_t; + return view_t{{array,attributes}}; + } // accumulate + + template + constexpr auto accumulate(const array_t& array, op_t op, const args::accumulate& attributes) + { + return accumulate(array, args::accumulate{attributes.axis,attributes.dtype,op}); } // accumulate /** @@ -191,12 +370,25 @@ namespace nmtools::view * @param rhs rhs array * @return constexpr auto */ - template - constexpr auto outer(op_t op, const lhs_t& lhs, const rhs_t& rhs) + template + constexpr auto outer(op_t op, const lhs_t& lhs, const rhs_t& rhs, dtype_t dtype=dtype_t{}) { - using view_t = decorator_t; - return view_t{{op,lhs,rhs}}; - } + using view_t = decorator_t; + return view_t{{op,lhs,rhs,dtype}}; + } // outer + + template + constexpr auto outer(const lhs_t& lhs, const rhs_t& rhs, const args::outer& attributes) + { + using view_t = decorator_t; + return view_t{{lhs,rhs,attributes}}; + } // outer + + template + constexpr auto outer(const array_t& array, op_t op, const args::outer& attributes) + { + return outer(array,args::outer{attributes.dtype,op}); + } // outer } // namespace nmtools::view #endif // NMTOOLS_ARRAY_VIEW_UFUNC_HPP diff --git a/include/nmtools/array/view/ufunc/accumulate.hpp b/include/nmtools/array/view/ufunc/accumulate.hpp index 3f453222d..6bb52e36e 100644 --- a/include/nmtools/array/view/ufunc/accumulate.hpp +++ b/include/nmtools/array/view/ufunc/accumulate.hpp @@ -18,7 +18,49 @@ #include "nmtools/array/eval.hpp" #include "nmtools/constants.hpp" +#include "nmtools/array/view/ufunc/reduce.hpp" #include "nmtools/array/view/ufunc/detail.hpp" +#include "nmtools/utils/isequal.hpp" + +namespace nmtools::args +{ + template < + typename axis_t + , typename dtype_t + , typename op_t=none_t> + struct accumulate + { + using op_type = op_t; + using axis_type = axis_t; + using dtype_type = dtype_t; + + axis_type axis = {}; + dtype_type dtype = {}; + op_type op = {}; + + template + constexpr auto operator==(const accumulate& other) const + { + using other_type = accumulate; + return utils::isequal(axis,other.axis) + && meta::is_same_v + // TODO: check for dtype + ; + } + }; + + template + accumulate(args_t...) -> accumulate; +} // namespace nmtools::args + +namespace nmtools::meta +{ + template < + typename axis_t + , typename dtype_t + , typename op_t> + struct is_attribute> : true_type {}; +} // namespace nmtools::meta namespace nmtools::view { @@ -31,7 +73,7 @@ namespace nmtools::view * @tparam array_t array type * @tparam axis_t axis type */ - template + template struct accumulate_t { using array_type = resolve_array_type_t; @@ -39,9 +81,12 @@ namespace nmtools::view using op_type = op_t; using reducer_type = reducer_t; using element_type = meta::get_element_type_t; + using dtype_type = dtype_t; using result_type = meta::type_t>; + using attributes_type = args::accumulate; + using shape_type = decltype(nmtools::shape(meta::declval())); using size_type = decltype(nmtools::size(meta::declval())); @@ -51,14 +96,25 @@ namespace nmtools::view reducer_type reducer; shape_type shape_; size_type size_; + dtype_type dtype; - constexpr accumulate_t(op_type op, const array_t& array_, const axis_t& axis) + constexpr accumulate_t(op_t op, const array_t& array_, const axis_t& axis, dtype_t dtype={}) : op(op) , array(initialize(array_)) , axis(init_attribute(axis)) , reducer{op} , shape_(nmtools::shape(array_)) , size_(nmtools::size(array_)) + , dtype(dtype) + {} + + constexpr accumulate_t(const array_t& array_, const args::accumulate& attributes) + : accumulate_t( + attributes.op + , array_ + , attributes.axis + , attributes.dtype + ) {} constexpr auto operands() const noexcept @@ -66,6 +122,11 @@ namespace nmtools::view return nmtools_tuple{array}; } + constexpr auto attributes() const noexcept + { + return attributes_type{axis,dtype,op}; + } + constexpr auto shape() const { return shape_; @@ -135,21 +196,21 @@ namespace nmtools::view namespace nmtools::meta { - template + template struct is_ndarray< - view::decorator_t< view::accumulate_t, op_t, array_t, axis_t > + view::decorator_t< view::accumulate_t, op_t, array_t, axis_t, dtype_t > > { static constexpr auto value = is_ndarray_v; }; // provide specialization for reducer - template + template struct get_element_type< - view::decorator_t< view::accumulate_t, op_t, array_t, axis_t > + view::decorator_t< view::accumulate_t, op_t, array_t, axis_t, dtype_t > > { - using type = typename view::accumulate_t::result_type; + using type = typename view::accumulate_t::result_type; }; } // namespace nmtools::meta diff --git a/include/nmtools/array/view/ufunc/outer.hpp b/include/nmtools/array/view/ufunc/outer.hpp index b95242172..9dd8399d2 100644 --- a/include/nmtools/array/view/ufunc/outer.hpp +++ b/include/nmtools/array/view/ufunc/outer.hpp @@ -20,6 +20,33 @@ #include "nmtools/array/view/ufunc/detail.hpp" +namespace nmtools::args +{ + template + struct outer + { + using op_type = op_t; + using dtype_type = dtype_t; + + dtype_type dtype = {}; + op_type op = {}; + + constexpr auto operator==(const outer&) const + { + return true; + } + }; + + template + outer(args_t...) -> outer; +} // namespace nmtools::args + +namespace nmtools::meta +{ + template + struct is_attribute> : true_type {}; +} // namespace nmtools::meta + namespace nmtools::view { /** @@ -31,7 +58,7 @@ namespace nmtools::view * @tparam lhs_t * @tparam rhs_t */ - template + template struct outer_t { using operands_type = detail::get_operands_type_t; @@ -40,6 +67,9 @@ namespace nmtools::view using lhs_element_type = meta::get_element_type_t; using rhs_element_type = meta::get_element_type_t; using result_type = detail::get_ufunc_result_type_t; + using dtype_type = dtype_t; + + using attributes_type = args::outer; using lhs_shape_type = decltype(nmtools::shape(meta::declval())); using rhs_shape_type = decltype(nmtools::shape(meta::declval())); @@ -53,7 +83,9 @@ namespace nmtools::view dst_shape_type shape_; dst_size_type size_; + dtype_type dtype; + // TODO: move to common decorator.hpp // the following is needed because cant use view::initialize<...> // can't handle tuple yet static constexpr auto initialize_array(const lhs_t& lhs, const rhs_t& rhs) @@ -71,11 +103,21 @@ namespace nmtools::view } } // initialize_array - constexpr outer_t(op_type op, const lhs_t& lhs, const rhs_t& rhs) + constexpr outer_t(op_t op, const lhs_t& lhs, const rhs_t& rhs, dtype_t dtype) : op(op) , array(initialize_array(lhs,rhs)) , shape_(index::shape_outer(nmtools::shape(lhs),nmtools::shape(rhs))) , size_(index::size_outer(shape_,nmtools::size(lhs),nmtools::size(rhs))) + , dtype(dtype) + {} + + constexpr outer_t(const lhs_t& lhs, const rhs_t& rhs, const args::outer& attributes) + : outer_t( + attributes.op + , lhs + , rhs + , attributes.dtype + ) {} constexpr auto operands() const noexcept @@ -85,7 +127,7 @@ namespace nmtools::view constexpr auto attributes() const noexcept { - return nmtools_tuple{}; + return attributes_type{dtype,op}; } constexpr auto shape() const @@ -114,8 +156,8 @@ namespace nmtools::view const auto& b = nmtools::get<1>(array); auto ashape = detail::shape(a); auto bshape = detail::shape(b); - const auto [aidx, bidx] = index::outer(indices_,ashape,bshape); - return op(view::detail::apply_at(a,aidx),view::detail::apply_at(b,bidx)); + const auto [a_idx, b_idx] = index::outer(indices_,ashape,bshape); + return op(view::detail::apply_at(a,a_idx),view::detail::apply_at(b,b_idx)); } // operator() }; // outer_t } // namespace nmtools::view @@ -123,42 +165,48 @@ namespace nmtools::view namespace nmtools::meta { - template + namespace error + { + template + struct OUTER_BOUNDED_SIZE_UNSUPPORTED : detail::fail_t {}; + } + + template struct is_outer< - view::decorator_t< view::outer_t, op_t, lhs_t, rhs_t > + view::decorator_t< view::outer_t, op_t, lhs_t, rhs_t, dtype_t > > : true_type {}; - template + template struct bounded_size< - view::decorator_t< view::outer_t, op_t, lhs_t, rhs_t > + view::decorator_t< view::outer_t, op_t, lhs_t, rhs_t, dtype_t > > { - using view_type = view::decorator_t< view::outer_t, op_t, lhs_t, rhs_t >; + using view_type = view::decorator_t< view::outer_t, op_t, lhs_t, rhs_t, dtype_t >; static constexpr auto value = [](){ if constexpr (is_bounded_size_v && is_bounded_size_v) { return bounded_size_v * bounded_size_v; } else { - return error::BOUNDED_SIZE_UNSUPPORTED{}; + return error::OUTER_BOUNDED_SIZE_UNSUPPORTED{}; } }(); }; // bounded_size - template + template struct is_ndarray< - view::decorator_t< view::outer_t, op_t, lhs_t, rhs_t > + view::decorator_t< view::outer_t, op_t, lhs_t, rhs_t, dtype_t > > { static constexpr auto value = is_ndarray_v && is_ndarray_v; }; // provide specialization for reducer - template + template struct get_element_type< - view::decorator_t< view::outer_t, op_t, lhs_t, rhs_t > + view::decorator_t< view::outer_t, op_t, lhs_t, rhs_t, dtype_t > > { - using type = typename view::outer_t::result_type; + using type = typename view::outer_t::result_type; }; } // namespace nmtools::meta diff --git a/include/nmtools/array/view/ufunc/reduce.hpp b/include/nmtools/array/view/ufunc/reduce.hpp index 26dba2a9d..e2645e447 100644 --- a/include/nmtools/array/view/ufunc/reduce.hpp +++ b/include/nmtools/array/view/ufunc/reduce.hpp @@ -20,6 +20,7 @@ #include "nmtools/constants.hpp" #include "nmtools/array/view/ufunc/detail.hpp" +#include "nmtools/utils/isequal.hpp" namespace nmtools::view::detail { @@ -144,6 +145,58 @@ namespace nmtools::view::detail } // make_reduction_slices } // namespace nmtools::view::detail +namespace nmtools::args +{ + template < + typename axis_t + , typename dtype_t + , typename initial_t + , typename keepdims_t + , typename op_t=none_t> + struct reduce + { + using op_type = op_t; + using axis_type = axis_t; + using dtype_type = dtype_t; + using initial_type = initial_t; + using keepdims_type = keepdims_t; + + axis_type axis = {}; + dtype_type dtype = {}; + initial_type initial = {}; + keepdims_type keepdims = {}; + op_type op = {}; + + template + constexpr auto operator==(const reduce& other) const + { + using other_type = reduce; + return utils::isequal(axis,other.axis) + && utils::isequal(initial,other.initial) + && utils::isequal(keepdims,other.keepdims) + && meta::is_same_v + // TODO: check for dtype + ; + } + }; + + template + reduce(args_t...) -> reduce; +} // namespace nmtools::args + +namespace nmtools::meta +{ + template < + typename axis_t + , typename dtype_t + , typename initial_t + , typename keepdims_t + , typename op_t> + struct is_attribute< + args::reduce + > : true_type {}; +} // namespace nmtools::meta + namespace nmtools::view { namespace error @@ -213,7 +266,7 @@ namespace nmtools::view * @tparam initial_t * @tparam keepdims_t */ - template + template struct reduce_t { // if given array is a view, just use value instead of reference @@ -225,6 +278,9 @@ namespace nmtools::view using reducer_type = reducer_t; using element_type = meta::get_element_type_t; using keepdims_type = keepdims_t; + using dtype_type = dtype_t; + + using attributes_type = args::reduce; using src_shape_type = decltype(nmtools::shape(meta::declval())); using dst_shape_type = const meta::resolve_optype_t; @@ -237,23 +293,41 @@ namespace nmtools::view initial_type initial; reducer_type reducer; keepdims_type keepdims; + dtype_type dtype; dst_shape_type shape_; - constexpr reduce_t(op_type op, const array_t& array_, const axis_t& axis_, initial_type initial, keepdims_type keepdims_) + constexpr reduce_t(op_type op, const array_t& array_, const axis_t& axis_, initial_type initial, keepdims_type keepdims_, dtype_type dtype=dtype_type{}) : op(op), array(initialize(array_)) , axis(init_attribute(axis_)) , initial(initial) , reducer{op} // TODO: remove, recurse to scalar reduce ufunc instead of using reducer , keepdims(keepdims_) + , dtype(dtype) , shape_(index::remove_dims(nmtools::shape(array_),axis_,keepdims_)) {} + constexpr reduce_t(const array_t& array_, const args::reduce& attributes) + : reduce_t( + attributes.op + , array_ + , attributes.axis + , attributes.initial + , attributes.keepdims + , attributes.dtype + ) + {} + constexpr auto operands() const noexcept { return nmtools_tuple{array}; } + constexpr auto attributes() const noexcept + { + return attributes_type{axis, dtype, initial, keepdims, op}; + } + constexpr auto shape() const { return shape_; @@ -324,7 +398,7 @@ namespace nmtools::view // maybe encountered when reducing scalar type. // following numpy, reducing scalar is allowed. static constexpr auto num_vtype = [](){ - using view_t = view::decorator_t< view::reduce_t, op_t, array_t, axis_t, initial_t, keepdims_t >; + using view_t = view::decorator_t< view::reduce_t, op_t, array_t, axis_t, initial_t, keepdims_t, dtype_t >; if constexpr (meta::is_num_v) { return meta::as_value_v; } else { @@ -367,8 +441,8 @@ namespace nmtools::view * @tparam initial_t * @tparam keepdims_t */ - template - struct reduce_t + template + struct reduce_t { using array_type = resolve_array_type_t; // use reference for now since raw array decays to pointer @@ -378,6 +452,9 @@ namespace nmtools::view using reducer_type = reducer_t; using element_type = meta::get_element_type_t; using keepdims_type = keepdims_t; + using dtype_type = dtype_t; + + using attributes_type = args::reduce; using src_shape_type = decltype(nmtools::shape(meta::declval())); using dst_shape_type = const meta::resolve_optype_t; @@ -390,18 +467,41 @@ namespace nmtools::view initial_type initial; reducer_type reducer; keepdims_type keepdims; + dtype_type dtype; dst_shape_type shape_; - constexpr reduce_t(op_type op, const array_t& array_, axis_type axis_, initial_type initial, keepdims_type keepdims_) + constexpr reduce_t(op_type op, const array_t& array_, axis_type axis_, initial_type initial, keepdims_type keepdims_, dtype_type dtype=dtype_type{}) : op(op) , array(initialize(array_)) , axis(axis_) , initial(initial) , reducer{op} , keepdims(keepdims_) + , dtype(dtype) , shape_(index::remove_dims(nmtools::shape(array_),axis_,keepdims_)) {} + + constexpr reduce_t(const array_t& array_, const args::reduce& attributes) + : reduce_t( + attributes.op + , array_ + , attributes.axis + , attributes.initial + , attributes.keepdims + , attributes.dtype + ) + {} + + constexpr auto operands() const noexcept + { + return nmtools_tuple{array}; + } + + constexpr auto attributes() const noexcept + { + return attributes_type{axis, dtype, initial, keepdims, op}; + } constexpr auto shape() const { @@ -462,14 +562,14 @@ namespace nmtools::view namespace nmtools::meta { - template + template struct is_reduction< - view::decorator_t< view::reduce_t, op_t, array_t, axis_t, initial_t, keepdims_t > + view::decorator_t< view::reduce_t, op_t, array_t, axis_t, initial_t, keepdims_t, dtype_t > > : true_type {}; - template + template struct is_num< - view::decorator_t< view::reduce_t, op_t, array_t, axis_t, initial_t, keepdims_t > + view::decorator_t< view::reduce_t, op_t, array_t, axis_t, initial_t, keepdims_t, dtype_t > > { static constexpr auto value = [](){ @@ -513,13 +613,13 @@ namespace nmtools::meta }(); }; - template + template struct fixed_size< - view::decorator_t< view::reduce_t, op_t, array_t, axis_t, initial_t, keepdims_t > + view::decorator_t< view::reduce_t, op_t, array_t, axis_t, initial_t, keepdims_t, dtype_t > // , enable_if_t> > { - using view_type = view::decorator_t< view::reduce_t, op_t, array_t, axis_t, initial_t, keepdims_t >; + using view_type = view::decorator_t< view::reduce_t, op_t, array_t, axis_t, initial_t, keepdims_t, dtype_t >; using shape_type = decltype(declval().shape()); using size_type = decltype(declval().size()); @@ -535,19 +635,19 @@ namespace nmtools::meta }(); }; // fixed_size - template + template struct is_ndarray< - view::decorator_t< view::reduce_t, op_t, array_t, axis_t, initial_t, keepdims_t > + view::decorator_t< view::reduce_t, op_t, array_t, axis_t, initial_t, keepdims_t, dtype_t > > { - using view_t = view::decorator_t< view::reduce_t, op_t, array_t, axis_t, initial_t, keepdims_t >; + using view_t = view::decorator_t< view::reduce_t, op_t, array_t, axis_t, initial_t, keepdims_t, dtype_t >; static constexpr auto value = is_ndarray_v && !is_num_v; }; // provide specialization for reducer - template + template struct get_element_type< - view::decorator_t< view::reduce_t, op_t, array_t, axis_t, initial_t, keepdims_t > + view::decorator_t< view::reduce_t, op_t, array_t, axis_t, initial_t, keepdims_t, dtype_t > > { using type = typename view::reduce_t::result_type; diff --git a/include/nmtools/array/view/ufunc/ufunc.hpp b/include/nmtools/array/view/ufunc/ufunc.hpp index 750d2fe27..5fc11637b 100644 --- a/include/nmtools/array/view/ufunc/ufunc.hpp +++ b/include/nmtools/array/view/ufunc/ufunc.hpp @@ -21,6 +21,38 @@ #include "nmtools/array/view/ufunc/detail.hpp" +namespace nmtools::args +{ + template + struct ufunc + { + using op_type = op_t; + + op_type op = {}; + + template + constexpr auto operator==(const ufunc& other) const + { + if constexpr (meta::expression_check_v) { + return op == other.op; + } else { + return meta::is_same_v; + } + } + }; + + template + ufunc(args_t...) -> ufunc; +} // namespace nmtools::args + +namespace nmtools::meta +{ + template + struct is_attribute< + args::ufunc + > : true_type {}; +} // namespace nmtools::meta + namespace nmtools::view { /** @@ -116,7 +148,7 @@ namespace nmtools::view constexpr auto attributes() const noexcept { - return nmtools_tuple{op}; + return args::ufunc{op}; } constexpr auto shape() const diff --git a/include/nmtools/array/view/ufuncs/add.hpp b/include/nmtools/array/view/ufuncs/add.hpp index edca8d6f1..1c9e70566 100644 --- a/include/nmtools/array/view/ufuncs/add.hpp +++ b/include/nmtools/array/view/ufuncs/add.hpp @@ -1,9 +1,10 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_ADD_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_ADD_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" -namespace nmtools::view +namespace nmtools::view::fun { template < typename lhs_t=none_t, @@ -11,7 +12,7 @@ namespace nmtools::view typename res_t=none_t, typename=void > - struct add_t + struct add { // NOTE: tried to disable but not successful // TODO: remove by unifying with primary template @@ -37,13 +38,13 @@ namespace nmtools::view return static_cast(t + u); } } // operator() - }; // add_t + }; // add // NOTE: tried to disable but not successful // TODO: remove by unifying with primary template #if 1 template - struct add_t> > { @@ -54,8 +55,18 @@ namespace nmtools::view { return t + u; } // operator() - }; // add_t + }; // add #endif +} + +namespace nmtools::view +{ + template < + typename lhs_t=none_t, + typename rhs_t=none_t, + typename res_t=none_t + > + using add_t = fun::add; template constexpr auto add(const left_t& a, const right_t& b, casting_t=casting_t{}) @@ -75,19 +86,19 @@ namespace nmtools::view } // add template - constexpr auto reduce_add(const left_t& a, const axis_t& axis, dtype_t /*dtype*/, initial_t initial, keepdims_t keepdims) + constexpr auto reduce_add(const left_t& a, const axis_t& axis, dtype_t dtype, initial_t initial, keepdims_t keepdims) { using res_t = get_dtype_t; using op_t = add_t; - return reduce(op_t{},a,axis,initial,keepdims); + return reduce(op_t{},a,axis,dtype,initial,keepdims); } // add template - constexpr auto reduce_add(const left_t& a, const axis_t& axis, dtype_t /*dtype*/, initial_t initial) + constexpr auto reduce_add(const left_t& a, const axis_t& axis, dtype_t dtype, initial_t initial) { using res_t = get_dtype_t; using op_t = add_t; - return reduce(op_t{},a,axis,initial); + return reduce(op_t{},a,axis,dtype,initial); } // add template @@ -103,11 +114,11 @@ namespace nmtools::view } // add template - constexpr auto accumulate_add(const left_t& a, axis_t axis, dtype_t /*dtype*/) + constexpr auto accumulate_add(const left_t& a, axis_t axis, dtype_t dtype) { using res_t = get_dtype_t; using op_t = add_t; - return accumulate(op_t{},a,axis); + return accumulate(op_t{},a,axis,dtype); } // accumulate_add template @@ -117,12 +128,38 @@ namespace nmtools::view } // accumulate_add template - constexpr auto outer_add(const left_t& a, const right_t& b, dtype_t /*dtype*/=dtype_t{}) + constexpr auto outer_add(const left_t& a, const right_t& b, dtype_t dtype=dtype_t{}) { using res_t = get_dtype_t; using op_t = add_t; - return outer(op_t{},a,b); + return outer(op_t{},a,b,dtype); } // outer_add -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template < + typename lhs_t, + typename rhs_t, + typename res_t + > + struct to_string_t,none_t> + { + auto operator()(view::fun::add) const + { + auto str = nmtools_string(); + + str += "add"; + + return str; + } + }; + + +} + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_ADD_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/arccos.hpp b/include/nmtools/array/view/ufuncs/arccos.hpp index 99bf3114f..3241317b3 100644 --- a/include/nmtools/array/view/ufuncs/arccos.hpp +++ b/include/nmtools/array/view/ufuncs/arccos.hpp @@ -1,12 +1,13 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_ARCCOS_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_ARCCOS_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct arccos_t + struct arccos { template nmtools_func_attribute @@ -15,7 +16,12 @@ namespace nmtools::view { return math::acos(t); } // operator() - }; // arccos_t + }; // arccos +} // namespace nmtools::view::fun + +namespace nmtools::view +{ + using arccos_t = fun::arccos; template nmtools_func_attribute @@ -24,6 +30,26 @@ namespace nmtools::view { return ufunc(arccos_t{},a); } // arccos -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::arccos) const + { + nmtools_string str; + + str += "arccos"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_ARCCOS_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/arccosh.hpp b/include/nmtools/array/view/ufuncs/arccosh.hpp index c165743e1..8bc33f734 100644 --- a/include/nmtools/array/view/ufuncs/arccosh.hpp +++ b/include/nmtools/array/view/ufuncs/arccosh.hpp @@ -1,12 +1,13 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_ARCCOSH_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_ARCCOSH_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct arccosh_t + struct arccosh { template nmtools_func_attribute @@ -15,7 +16,12 @@ namespace nmtools::view { return math::acosh(t); } // operator() - }; // arccosh_t + }; // arccosh +} // namespace nmtools::view::fun + +namespace nmtools::view +{ + using arccosh_t = fun::arccosh; template nmtools_func_attribute @@ -24,6 +30,26 @@ namespace nmtools::view { return ufunc(arccosh_t{},a); } // arccosh -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::arccosh) const + { + nmtools_string str; + + str += "arccosh"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_ARCCOSH_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/arcsin.hpp b/include/nmtools/array/view/ufuncs/arcsin.hpp index 0554814e4..f004c6f8a 100644 --- a/include/nmtools/array/view/ufuncs/arcsin.hpp +++ b/include/nmtools/array/view/ufuncs/arcsin.hpp @@ -1,12 +1,13 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_ARCSIN_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_ARCSIN_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct arcsin_t + struct arcsin { template nmtools_func_attribute @@ -15,7 +16,12 @@ namespace nmtools::view { return math::asin(t); } // operator() - }; // arcsin_t + }; // arcsin +} // nmtools::view::fun + +namespace nmtools::view +{ + using arcsin_t = fun::arcsin; template nmtools_func_attribute @@ -24,6 +30,26 @@ namespace nmtools::view { return ufunc(arcsin_t{},a); } // arcsin -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::arcsin) const + { + nmtools_string str; + + str += "arcsin"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_ARCSIN_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/arcsinh.hpp b/include/nmtools/array/view/ufuncs/arcsinh.hpp index 8997bc9df..a408de1d9 100644 --- a/include/nmtools/array/view/ufuncs/arcsinh.hpp +++ b/include/nmtools/array/view/ufuncs/arcsinh.hpp @@ -1,12 +1,13 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_ARCSINH_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_ARCSINH_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct arcsinh_t + struct arcsinh { template nmtools_func_attribute @@ -15,7 +16,12 @@ namespace nmtools::view { return math::asinh(t); } // operator() - }; // arcsinh_t + }; // arcsinh +} // namespace nmtools::view::fun + +namespace nmtools::view +{ + using arcsinh_t = fun::arcsinh; template nmtools_func_attribute @@ -24,6 +30,27 @@ namespace nmtools::view { return ufunc(arcsinh_t{},a); } // arcsinh -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::arcsinh) const + { + nmtools_string str; + + str += "arcsinh"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING + #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_ARCSINH_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/arctan.hpp b/include/nmtools/array/view/ufuncs/arctan.hpp index 75a397c8b..ac5ea66e5 100644 --- a/include/nmtools/array/view/ufuncs/arctan.hpp +++ b/include/nmtools/array/view/ufuncs/arctan.hpp @@ -1,12 +1,13 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_ARCTAN_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_ARCTAN_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct arctan_t + struct arctan { template nmtools_func_attribute @@ -15,7 +16,12 @@ namespace nmtools::view { return math::atan(t); } // operator() - }; // arctan_t + }; // arctan +} // namespace nmtools::view::fun + +namespace nmtools::view +{ + using arctan_t = fun::arctan; template nmtools_func_attribute @@ -24,6 +30,26 @@ namespace nmtools::view { return ufunc(arctan_t{},a); } // arctan -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::arctan) const + { + nmtools_string str; + + str += "arctan"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_ARCTAN_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/arctan2.hpp b/include/nmtools/array/view/ufuncs/arctan2.hpp index 2a35d96b5..51779533f 100644 --- a/include/nmtools/array/view/ufuncs/arctan2.hpp +++ b/include/nmtools/array/view/ufuncs/arctan2.hpp @@ -1,12 +1,13 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_ARCTAN2_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_ARCTAN2_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct arctan2_t + struct arctan2 { template nmtools_func_attribute @@ -15,7 +16,12 @@ namespace nmtools::view { return math::atan2(t,u); } // operator() - }; // arctan2_t + }; // arctan2 +} + +namespace nmtools::view +{ + using arctan2_t = fun::arctan2; template nmtools_func_attribute @@ -24,6 +30,26 @@ namespace nmtools::view { return ufunc(arctan2_t{},a,b); } // arctan2 -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::arctan2) const + { + auto str = nmtools_string(); + + str += "arctan2"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_ARCTAN2_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/arctanh.hpp b/include/nmtools/array/view/ufuncs/arctanh.hpp index 6f3e3fb62..12fbaa5b5 100644 --- a/include/nmtools/array/view/ufuncs/arctanh.hpp +++ b/include/nmtools/array/view/ufuncs/arctanh.hpp @@ -1,12 +1,13 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_ARCTANH_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_ARCTANH_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct arctanh_t + struct arctanh { template nmtools_func_attribute @@ -15,7 +16,12 @@ namespace nmtools::view { return math::atanh(t); } // operator() - }; // arctanh_t + }; // arctanh +} // namespace nmtools::view::fun + +namespace nmtools::view +{ + using arctanh_t = fun::arctanh; template nmtools_func_attribute @@ -24,6 +30,26 @@ namespace nmtools::view { return ufunc(arctanh_t{},a); } // arctanh -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::arctanh) const + { + nmtools_string str; + + str += "arctanh"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_ARCTANH_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/bitwise_and.hpp b/include/nmtools/array/view/ufuncs/bitwise_and.hpp index 31c2bc6ff..4f166a25d 100644 --- a/include/nmtools/array/view/ufuncs/bitwise_and.hpp +++ b/include/nmtools/array/view/ufuncs/bitwise_and.hpp @@ -1,24 +1,50 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_BITWISE_AND_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_BITWISE_AND_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct bitwise_and_t + struct bitwise_and { template constexpr auto operator()(const T& t, const U& u) const { return t & u; } // operator() - }; // bitwise_and_t + }; // bitwise_and +} + +namespace nmtools::view +{ + using bitwise_and_t = fun::bitwise_and; template constexpr auto bitwise_and(const left_t& a, const right_t& b) { return ufunc(bitwise_and_t{},a,b); } // bitwise_and -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::bitwise_and) const + { + auto str = nmtools_string(); + + str += "bitwise_and"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_BITWISE_AND_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/bitwise_or.hpp b/include/nmtools/array/view/ufuncs/bitwise_or.hpp index 77921405e..d9dbfba44 100644 --- a/include/nmtools/array/view/ufuncs/bitwise_or.hpp +++ b/include/nmtools/array/view/ufuncs/bitwise_or.hpp @@ -1,24 +1,50 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_BITWISE_OR_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_BITWISE_OR_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct bitwise_or_t + struct bitwise_or { template constexpr auto operator()(const T& t, const U& u) const { return t | u; } // operator() - }; // bitwise_or_t + }; // bitwise_or +} + +namespace nmtools::view +{ + using bitwise_or_t = fun::bitwise_or; template constexpr auto bitwise_or(const left_t& a, const right_t& b) { return ufunc(bitwise_or_t{},a,b); } // bitwise_or -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::bitwise_or) const + { + auto str = nmtools_string(); + + str += "bitwise_or"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_BITWISE_OR_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/bitwise_xor.hpp b/include/nmtools/array/view/ufuncs/bitwise_xor.hpp index e208d6fdb..f67ca2d69 100644 --- a/include/nmtools/array/view/ufuncs/bitwise_xor.hpp +++ b/include/nmtools/array/view/ufuncs/bitwise_xor.hpp @@ -1,24 +1,50 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_BITWISE_XOR_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_BITWISE_XOR_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct bitwise_xor_t + struct bitwise_xor { template constexpr auto operator()(const T& t, const U& u) const { return t ^ u; } // operator() - }; // bitwise_xor_t + }; // bitwise_xor +} + +namespace nmtools::view +{ + using bitwise_xor_t = fun::bitwise_xor; template constexpr auto bitwise_xor(const left_t& a, const right_t& b) { return ufunc(bitwise_xor_t{},a,b); } // bitwise_xor -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::bitwise_xor) const + { + auto str = nmtools_string(); + + str += "bitwise_xor"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_BITWISE_XOR_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/cbrt.hpp b/include/nmtools/array/view/ufuncs/cbrt.hpp index a4eefeedc..84178267c 100644 --- a/include/nmtools/array/view/ufuncs/cbrt.hpp +++ b/include/nmtools/array/view/ufuncs/cbrt.hpp @@ -1,12 +1,13 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_CBRT_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_CBRT_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct cbrt_t + struct cbrt { template nmtools_func_attribute @@ -15,7 +16,12 @@ namespace nmtools::view { return math::cbrt(t); } // operator() - }; // cbrt_t + }; // cbrt +} // namespace nmtools::view::fun + +namespace nmtools::view +{ + using cbrt_t = fun::cbrt; template nmtools_func_attribute @@ -24,6 +30,26 @@ namespace nmtools::view { return ufunc(cbrt_t{},a); } // cbrt -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::cbrt) const + { + nmtools_string str; + + str += "cbrt"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_CBRT_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/ceil.hpp b/include/nmtools/array/view/ufuncs/ceil.hpp index ee668ce99..197311ef4 100644 --- a/include/nmtools/array/view/ufuncs/ceil.hpp +++ b/include/nmtools/array/view/ufuncs/ceil.hpp @@ -1,12 +1,13 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_CEIL_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_CEIL_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct ceil_t + struct ceil { template nmtools_func_attribute @@ -15,7 +16,12 @@ namespace nmtools::view { return math::ceil(t); } // operator() - }; // ceil_t + }; // ceil +} // namespace nmtools::view::fun + +namespace nmtools::view +{ + using ceil_t = fun::ceil; template nmtools_func_attribute @@ -26,4 +32,24 @@ namespace nmtools::view } // ceil }; +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::ceil) const + { + nmtools_string str; + + str += "ceil"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING + #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_CEIL_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/cos.hpp b/include/nmtools/array/view/ufuncs/cos.hpp index 925751402..5fcfa3c58 100644 --- a/include/nmtools/array/view/ufuncs/cos.hpp +++ b/include/nmtools/array/view/ufuncs/cos.hpp @@ -1,12 +1,13 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_COS_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_COS_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct cos_t + struct cos { template nmtools_func_attribute @@ -15,7 +16,12 @@ namespace nmtools::view { return math::cos(t); } // operator() - }; // cos_t + }; // cos +} // namespace nmtools::view::fun + +namespace nmtools::view +{ + using cos_t = fun::cos; template nmtools_func_attribute @@ -24,6 +30,26 @@ namespace nmtools::view { return ufunc(cos_t{},a); } // cos -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::cos) const + { + nmtools_string str; + + str += "cos"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_COS_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/cosh.hpp b/include/nmtools/array/view/ufuncs/cosh.hpp index f7c29e226..b4f16916a 100644 --- a/include/nmtools/array/view/ufuncs/cosh.hpp +++ b/include/nmtools/array/view/ufuncs/cosh.hpp @@ -1,12 +1,13 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_COSH_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_COSH_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct cosh_t + struct cosh { template nmtools_func_attribute @@ -15,7 +16,12 @@ namespace nmtools::view { return math::cosh(t); } // operator() - }; // cosh_t + }; // cosh +} // namespace nmtools::view::fun + +namespace nmtools::view +{ + using cosh_t = fun::cosh; template nmtools_func_attribute @@ -24,6 +30,26 @@ namespace nmtools::view { return ufunc(cosh_t{},a); } // cosh -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::cosh) const + { + nmtools_string str; + + str += "cosh"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_COSH_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/divide.hpp b/include/nmtools/array/view/ufuncs/divide.hpp index b9faa11ac..476c7bc2b 100644 --- a/include/nmtools/array/view/ufuncs/divide.hpp +++ b/include/nmtools/array/view/ufuncs/divide.hpp @@ -1,24 +1,50 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_DIVIDE_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_DIVIDE_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct divide_t + struct divide { template constexpr auto operator()(const T& t, const U& u) const { return t / u; } // operator() - }; // divide_t + }; // divide +} + +namespace nmtools::view +{ + using divide_t = fun::divide; template constexpr auto divide(const left_t& a, const right_t& b) { return ufunc(divide_t{},a,b); } // divide -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::divide) const + { + auto str = nmtools_string(); + + str += "divide"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_DIVIDE_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/equal.hpp b/include/nmtools/array/view/ufuncs/equal.hpp index 09bf580b6..2eebea8ba 100644 --- a/include/nmtools/array/view/ufuncs/equal.hpp +++ b/include/nmtools/array/view/ufuncs/equal.hpp @@ -3,22 +3,47 @@ #include "nmtools/array/view/ufunc.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct equal_t + struct equal { template constexpr auto operator()(const T& t, const U& u) const { return t == u; } // operator() - }; // equal_t + }; // equal +} + +namespace nmtools::view +{ + using equal_t = fun::equal; template constexpr auto equal(const left_t& a, const right_t& b) { return ufunc(equal_t{},a,b); } // equal -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::equal) const + { + auto str = nmtools_string(); + + str += "equal"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_EQUAL_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/exp.hpp b/include/nmtools/array/view/ufuncs/exp.hpp index 0ed8e7816..8771288e1 100644 --- a/include/nmtools/array/view/ufuncs/exp.hpp +++ b/include/nmtools/array/view/ufuncs/exp.hpp @@ -1,12 +1,13 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_EXP_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_EXP_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct exp_t + struct exp { template nmtools_func_attribute @@ -15,7 +16,12 @@ namespace nmtools::view { return math::exp(t); } // operator() - }; // exp_t + }; // exp +} // namespace nmtools::view::fun + +namespace nmtools::view +{ + using exp_t = fun::exp; template nmtools_func_attribute @@ -24,6 +30,26 @@ namespace nmtools::view { return ufunc(exp_t{},a); } // exp -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::exp) const + { + nmtools_string str; + + str += "exp"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_EXP_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/exp2.hpp b/include/nmtools/array/view/ufuncs/exp2.hpp index bf04d13d8..a8b6c9cdc 100644 --- a/include/nmtools/array/view/ufuncs/exp2.hpp +++ b/include/nmtools/array/view/ufuncs/exp2.hpp @@ -1,12 +1,13 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_EXP2_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_EXP2_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct exp2_t + struct exp2 { template nmtools_func_attribute @@ -15,7 +16,12 @@ namespace nmtools::view { return math::exp2(t); } // operator() - }; // exp2_t + }; // exp2 +} // namespace nmtools::view::fun + +namespace nmtools::view +{ + using exp2_t = fun::exp2; template nmtools_func_attribute @@ -24,6 +30,26 @@ namespace nmtools::view { return ufunc(exp2_t{},a); } // exp2 -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::exp2) const + { + nmtools_string str; + + str += "exp2"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_EXP2_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/expm1.hpp b/include/nmtools/array/view/ufuncs/expm1.hpp index 4cff2fd60..f40ef384d 100644 --- a/include/nmtools/array/view/ufuncs/expm1.hpp +++ b/include/nmtools/array/view/ufuncs/expm1.hpp @@ -1,12 +1,13 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_EXPM1_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_EXPM1_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct expm1_t + struct expm1 { template nmtools_func_attribute @@ -15,7 +16,12 @@ namespace nmtools::view { return math::expm1(t); } // operator() - }; // expm1_t + }; // expm1 +} // namespace nmtools::view::fun + +namespace nmtools::view +{ + using expm1_t = fun::expm1; template nmtools_func_attribute @@ -24,6 +30,26 @@ namespace nmtools::view { return ufunc(expm1_t{},a); } // expm1 -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::expm1) const + { + nmtools_string str; + + str += "expm1"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_EXPM1_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/fabs.hpp b/include/nmtools/array/view/ufuncs/fabs.hpp index e7811da65..ecda7d170 100644 --- a/include/nmtools/array/view/ufuncs/fabs.hpp +++ b/include/nmtools/array/view/ufuncs/fabs.hpp @@ -1,12 +1,13 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_FABS_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_FABS_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct fabs_t + struct fabs { template nmtools_func_attribute @@ -15,7 +16,12 @@ namespace nmtools::view { return math::fabs(t); } // operator() - }; // fabs_t + }; // fabs +} // namespace nmtools::view::fun + +namespace nmtools::view +{ + using fabs_t = fun::fabs; template nmtools_func_attribute @@ -24,6 +30,26 @@ namespace nmtools::view { return ufunc(fabs_t{},a); } // fabs -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::fabs) const + { + nmtools_string str; + + str += "fabs"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_FABS_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/floor.hpp b/include/nmtools/array/view/ufuncs/floor.hpp index 33dfc5704..7fd3809c2 100644 --- a/include/nmtools/array/view/ufuncs/floor.hpp +++ b/include/nmtools/array/view/ufuncs/floor.hpp @@ -1,12 +1,13 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_FLOOR_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_FLOOR_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct floor_t + struct floor { template nmtools_func_attribute @@ -15,7 +16,12 @@ namespace nmtools::view { return math::floor(t); } // operator() - }; // floor_t + }; // floor +} + +namespace nmtools::view +{ + using floor_t = fun::floor; template nmtools_func_attribute @@ -24,6 +30,26 @@ namespace nmtools::view { return ufunc(floor_t{},a); } // floor -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::floor) const + { + nmtools_string str; + + str += "floor"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_FLOOR_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/fmax.hpp b/include/nmtools/array/view/ufuncs/fmax.hpp index 2404818fe..bc7eecb60 100644 --- a/include/nmtools/array/view/ufuncs/fmax.hpp +++ b/include/nmtools/array/view/ufuncs/fmax.hpp @@ -47,20 +47,20 @@ namespace nmtools::view template NMTOOLS_UFUNC_CONSTEXPR - auto reduce_fmax(const left_t& a, const axis_t& axis, dtype_t, initial_t init, keepdims_t keepdims) + auto reduce_fmax(const left_t& a, const axis_t& axis, dtype_t dtype, initial_t init, keepdims_t keepdims) { using res_t = get_dtype_t; using op_t = fmax_t; - return reduce(op_t{},a,axis,init,keepdims); + return reduce(op_t{},a,axis,dtype,init,keepdims); } // reduce_fmax template NMTOOLS_UFUNC_CONSTEXPR - auto reduce_fmax(const left_t& a, const axis_t& axis, dtype_t, initial_t init) + auto reduce_fmax(const left_t& a, const axis_t& axis, dtype_t dtype, initial_t init) { using res_t = get_dtype_t; using op_t = fmax_t; - return reduce(op_t{},a,axis,init); + return reduce(op_t{},a,axis,dtype,init); } // reduce_fmax template @@ -80,11 +80,11 @@ namespace nmtools::view template NMTOOLS_UFUNC_CONSTEXPR - auto accumulate_fmax(const left_t& a, const axis_t& axis, dtype_t) + auto accumulate_fmax(const left_t& a, const axis_t& axis, dtype_t dtype) { using res_t = get_dtype_t; using op_t = fmax_t; - return accumulate(op_t{},a,axis); + return accumulate(op_t{},a,axis,dtype); } // accumulate_fmax template @@ -96,11 +96,11 @@ namespace nmtools::view template NMTOOLS_UFUNC_CONSTEXPR - auto outer_fmax(const left_t& a, const right_t& b, dtype_t=dtype_t{}) + auto outer_fmax(const left_t& a, const right_t& b, dtype_t dtype=dtype_t{}) { using res_t = get_dtype_t; using op_t = fmax_t; - return outer(op_t{},a,b); + return outer(op_t{},a,b,dtype); } // outer_fmax }; diff --git a/include/nmtools/array/view/ufuncs/fmin.hpp b/include/nmtools/array/view/ufuncs/fmin.hpp index 1972f4262..94ef9090b 100644 --- a/include/nmtools/array/view/ufuncs/fmin.hpp +++ b/include/nmtools/array/view/ufuncs/fmin.hpp @@ -47,20 +47,20 @@ namespace nmtools::view template NMTOOLS_UFUNC_CONSTEXPR - auto reduce_fmin(const left_t& a, const axis_t& axis, dtype_t, initial_t init, keepdims_t keepdims) + auto reduce_fmin(const left_t& a, const axis_t& axis, dtype_t dtype, initial_t init, keepdims_t keepdims) { using res_t = get_dtype_t; using op_t = fmin_t; - return reduce(op_t{},a,axis,init,keepdims); + return reduce(op_t{},a,axis,dtype,init,keepdims); } // reduce_fmin template NMTOOLS_UFUNC_CONSTEXPR - auto reduce_fmin(const left_t& a, const axis_t& axis, dtype_t, initial_t init) + auto reduce_fmin(const left_t& a, const axis_t& axis, dtype_t dtype, initial_t init) { using res_t = get_dtype_t; using op_t = fmin_t; - return reduce(op_t{},a,axis,init); + return reduce(op_t{},a,axis,dtype,init); } // reduce_fmin template @@ -80,11 +80,11 @@ namespace nmtools::view template NMTOOLS_UFUNC_CONSTEXPR - auto accumulate_fmin(const left_t& a, const axis_t& axis, dtype_t) + auto accumulate_fmin(const left_t& a, const axis_t& axis, dtype_t dtype) { using res_t = get_dtype_t; using op_t = fmin_t; - return accumulate(op_t{},a,axis); + return accumulate(op_t{},a,axis,dtype); } // accumulate_fmin template @@ -96,11 +96,11 @@ namespace nmtools::view template NMTOOLS_UFUNC_CONSTEXPR - auto outer_fmin(const left_t& a, const right_t& b, dtype_t=dtype_t{}) + auto outer_fmin(const left_t& a, const right_t& b, dtype_t dtype=dtype_t{}) { using res_t = get_dtype_t; using op_t = fmin_t; - return outer(op_t{},a,b); + return outer(op_t{},a,b,dtype); } // outer_fmin }; diff --git a/include/nmtools/array/view/ufuncs/fmod.hpp b/include/nmtools/array/view/ufuncs/fmod.hpp index 833889076..a5ecc1205 100644 --- a/include/nmtools/array/view/ufuncs/fmod.hpp +++ b/include/nmtools/array/view/ufuncs/fmod.hpp @@ -46,7 +46,7 @@ namespace nmtools::view template NMTOOLS_UFUNC_CONSTEXPR - auto reduce_fmod(const left_t& a, const axis_t& axis, dtype_t, initial_t initial, keepdims_t keepdims) + auto reduce_fmod(const left_t& a, const axis_t& axis, dtype_t dtype, initial_t initial, keepdims_t keepdims) { static_assert( meta::is_integral_v , "reduce_fmod only support single axis with integral type" @@ -56,12 +56,12 @@ namespace nmtools::view // to match the signature of reduce_t using res_t = get_dtype_t; using op_t = fmod_t; - return reduce(op_t{},a,axis,initial,keepdims); + return reduce(op_t{},a,axis,dtype,initial,keepdims); } // reduce_fmod template NMTOOLS_UFUNC_CONSTEXPR - auto reduce_fmod(const left_t& a, const axis_t& axis, dtype_t, initial_t initial) + auto reduce_fmod(const left_t& a, const axis_t& axis, dtype_t dtype, initial_t initial) { static_assert( meta::is_integral_v , "reduce_fmod only support single axis with integral type" @@ -71,7 +71,7 @@ namespace nmtools::view // to match the signature of reduce_t using res_t = get_dtype_t; using op_t = fmod_t; - return reduce(op_t{},a,axis,initial); + return reduce(op_t{},a,axis,dtype,initial); } // reduce_fmod template @@ -91,11 +91,11 @@ namespace nmtools::view template NMTOOLS_UFUNC_CONSTEXPR - auto accumulate_fmod(const left_t& a, const axis_t& axis, dtype_t) + auto accumulate_fmod(const left_t& a, const axis_t& axis, dtype_t dtype) { using res_t = get_dtype_t; using op_t = fmod_t; - return accumulate(op_t{},a,axis); + return accumulate(op_t{},a,axis,dtype); } // accumulate_fmod template @@ -107,11 +107,11 @@ namespace nmtools::view template NMTOOLS_UFUNC_CONSTEXPR - auto outer_fmod(const left_t& a, const right_t& b, dtype_t=dtype_t{}) + auto outer_fmod(const left_t& a, const right_t& b, dtype_t dtype=dtype_t{}) { using res_t = get_dtype_t; using op_t = fmod_t; - return outer(op_t{},a,b); + return outer(op_t{},a,b,dtype); } // outer_fmod }; diff --git a/include/nmtools/array/view/ufuncs/greater.hpp b/include/nmtools/array/view/ufuncs/greater.hpp index 7469b093d..c77185ee1 100644 --- a/include/nmtools/array/view/ufuncs/greater.hpp +++ b/include/nmtools/array/view/ufuncs/greater.hpp @@ -1,24 +1,50 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_GREATER_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_GREATER_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct greater_t + struct greater { template constexpr auto operator()(const T& t, const U& u) const { return t > u; } // operator() - }; // greater_t + }; // greater +} + +namespace nmtools::view +{ + using greater_t = fun::greater; template constexpr auto greater(const left_t& a, const right_t& b) { return ufunc(greater_t{},a,b); } // greater -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::greater) const + { + auto str = nmtools_string(); + + str += "greater"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_GREATER_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/greater_equal.hpp b/include/nmtools/array/view/ufuncs/greater_equal.hpp index ac2d5665e..1da252f19 100644 --- a/include/nmtools/array/view/ufuncs/greater_equal.hpp +++ b/include/nmtools/array/view/ufuncs/greater_equal.hpp @@ -3,22 +3,47 @@ #include "nmtools/array/view/ufunc.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct greater_equal_t + struct greater_equal { template constexpr auto operator()(const T& t, const U& u) const { return t >= u; } // operator() - }; // greater_equal_t + }; // greater_equal +} + +namespace nmtools::view +{ + using greater_equal_t = fun::greater_equal; template constexpr auto greater_equal(const left_t& a, const right_t& b) { return ufunc(greater_equal_t{},a,b); } // greater_equal -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::greater_equal) const + { + auto str = nmtools_string(); + + str += "greater_equal"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_GREATER_EQUAL_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/hypot.hpp b/include/nmtools/array/view/ufuncs/hypot.hpp index c794867f0..69b75253d 100644 --- a/include/nmtools/array/view/ufuncs/hypot.hpp +++ b/include/nmtools/array/view/ufuncs/hypot.hpp @@ -4,9 +4,9 @@ #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct hypot_t + struct hypot { template NMTOOLS_UFUNC_CONSTEXPR @@ -14,7 +14,12 @@ namespace nmtools::view { return math::hypot(t,u); } // operator() - }; // hypot_t + }; // hypot +} + +namespace nmtools::view +{ + using hypot_t = fun::hypot; template NMTOOLS_UFUNC_CONSTEXPR @@ -22,6 +27,26 @@ namespace nmtools::view { return ufunc(hypot_t{},a,b); } // hypot -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::hypot) const + { + auto str = nmtools_string(); + + str += "hypot"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_HYPOT_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/invert.hpp b/include/nmtools/array/view/ufuncs/invert.hpp index d1dec9847..3ebf7d765 100644 --- a/include/nmtools/array/view/ufuncs/invert.hpp +++ b/include/nmtools/array/view/ufuncs/invert.hpp @@ -1,24 +1,59 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_INVERT_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_INVERT_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" -namespace nmtools::view +namespace nmtools::meta::error +{ + template + struct INVERT_UNSUPPORTED : detail::fail_t {}; +} + +namespace nmtools::view::fun { - struct invert_t + struct invert { template constexpr auto operator()(const T& t) const { - return ~t; + if constexpr (meta::expression_check_v) { + return ~t; + } else { + return meta::error::INVERT_UNSUPPORTED{}; + } } // operator() - }; // invert_t + }; // invert +} // namespace nmtools::view::fun +namespace nmtools::view +{ + using invert_t = fun::invert; template constexpr auto invert(const left_t& a) { return ufunc(invert_t{},a); } // invert -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::invert) const + { + nmtools_string str; + + str += "invert"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_INVERT_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/isfinite.hpp b/include/nmtools/array/view/ufuncs/isfinite.hpp index d0f581288..f8115a9b8 100644 --- a/include/nmtools/array/view/ufuncs/isfinite.hpp +++ b/include/nmtools/array/view/ufuncs/isfinite.hpp @@ -1,12 +1,13 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_ISFINITE_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_ISFINITE_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct isfinite_t + struct isfinite { template nmtools_func_attribute @@ -15,7 +16,12 @@ namespace nmtools::view { return math::isfinite(t); } // operator() - }; // isfinite_t + }; // isfinite +} + +namespace nmtools::view +{ + using isfinite_t = fun::isfinite; template nmtools_func_attribute @@ -24,6 +30,26 @@ namespace nmtools::view { return ufunc(isfinite_t{},a); } // isfinite -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::isfinite) const + { + nmtools_string str; + + str += "isfinite"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_ISFINITE_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/isinf.hpp b/include/nmtools/array/view/ufuncs/isinf.hpp index dc786191d..29eccc360 100644 --- a/include/nmtools/array/view/ufuncs/isinf.hpp +++ b/include/nmtools/array/view/ufuncs/isinf.hpp @@ -1,12 +1,13 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_ISINF_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_ISINF_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct isinf_t + struct isinf { template nmtools_func_attribute @@ -15,7 +16,12 @@ namespace nmtools::view { return math::isinf(t); } // operator() - }; // isinf_t + }; // isinf +} + +namespace nmtools::view +{ + using isinf_t = fun::isinf; template nmtools_func_attribute @@ -24,6 +30,26 @@ namespace nmtools::view { return ufunc(isinf_t{},a); } // isinf -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::isinf) const + { + nmtools_string str; + + str += "isinf"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_ISINF_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/isnan.hpp b/include/nmtools/array/view/ufuncs/isnan.hpp index 3c5351c3e..b78785daf 100644 --- a/include/nmtools/array/view/ufuncs/isnan.hpp +++ b/include/nmtools/array/view/ufuncs/isnan.hpp @@ -1,12 +1,13 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_ISNAN_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_ISNAN_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct isnan_t + struct isnan { template nmtools_func_attribute @@ -15,7 +16,12 @@ namespace nmtools::view { return math::isnan(t); } // operator() - }; // isnan_t + }; // isnan +} + +namespace nmtools::view +{ + using isnan_t = fun::isnan; template nmtools_func_attribute @@ -26,4 +32,24 @@ namespace nmtools::view } // isnan }; +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::isnan) const + { + nmtools_string str; + + str += "isnan"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING + #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_ISNAN_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/ldexp.hpp b/include/nmtools/array/view/ufuncs/ldexp.hpp index 00a536561..b25248276 100644 --- a/include/nmtools/array/view/ufuncs/ldexp.hpp +++ b/include/nmtools/array/view/ufuncs/ldexp.hpp @@ -1,12 +1,13 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_LDEXP_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_LDEXP_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct ldexp_t + struct ldexp { template NMTOOLS_UFUNC_CONSTEXPR @@ -14,7 +15,11 @@ namespace nmtools::view { return math::ldexp(t,u); } // operator() - }; // ldexp_t + }; // ldexp +} +namespace nmtools::view +{ + using ldexp_t = fun::ldexp; template NMTOOLS_UFUNC_CONSTEXPR @@ -22,6 +27,26 @@ namespace nmtools::view { return ufunc(ldexp_t{},a,b); } // ldexp -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::ldexp) const + { + auto str = nmtools_string(); + + str += "ldexp"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_LDEXP_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/left_shift.hpp b/include/nmtools/array/view/ufuncs/left_shift.hpp index e1b095842..853857649 100644 --- a/include/nmtools/array/view/ufuncs/left_shift.hpp +++ b/include/nmtools/array/view/ufuncs/left_shift.hpp @@ -42,7 +42,7 @@ namespace nmtools::view } // left_shift template - constexpr auto reduce_left_shift(const left_t& a, const axis_t& axis, dtype_t, initial_t initial, keepdims_t keepdims) + constexpr auto reduce_left_shift(const left_t& a, const axis_t& axis, dtype_t dtype, initial_t initial, keepdims_t keepdims) { static_assert( meta::is_integral_v , "reduce_left_shift only support single axis with integral type" @@ -52,11 +52,11 @@ namespace nmtools::view // to match the signature of reduce_t using res_t = get_dtype_t; using op_t = left_shift_t; - return reduce(op_t{},a,axis,initial,keepdims); + return reduce(op_t{},a,axis,dtype,initial,keepdims); } // reduce_left_shift template - constexpr auto reduce_left_shift(const left_t& a, const axis_t& axis, dtype_t, initial_t initial) + constexpr auto reduce_left_shift(const left_t& a, const axis_t& axis, dtype_t dtype, initial_t initial) { static_assert( meta::is_integral_v , "reduce_left_shift only support single axis with integral type" @@ -66,7 +66,7 @@ namespace nmtools::view // to match the signature of reduce_t using res_t = get_dtype_t; using op_t = left_shift_t; - return reduce(op_t{},a,axis,initial); + return reduce(op_t{},a,axis,dtype,initial); } // reduce_left_shift template @@ -82,11 +82,11 @@ namespace nmtools::view } // reduce_left_shift template - auto accumulate_left_shift(const left_t& a, const axis_t& axis, dtype_t) + auto accumulate_left_shift(const left_t& a, const axis_t& axis, dtype_t dtype) { using res_t = get_dtype_t; using op_t = left_shift_t; - return accumulate(op_t{},a,axis); + return accumulate(op_t{},a,axis,dtype); } // accumulate_left_shift template @@ -96,11 +96,11 @@ namespace nmtools::view } // accumulate_left_shift template - constexpr auto outer_left_shift(const left_t& a, const right_t& b, dtype_t=dtype_t{}) + constexpr auto outer_left_shift(const left_t& a, const right_t& b, dtype_t dtype=dtype_t{}) { using res_t = get_dtype_t; using op_t = left_shift_t; - return outer(op_t{},a,b); + return outer(op_t{},a,b,dtype); } // outer_left_shift }; diff --git a/include/nmtools/array/view/ufuncs/less.hpp b/include/nmtools/array/view/ufuncs/less.hpp index 4a4a89e9a..e1eda18aa 100644 --- a/include/nmtools/array/view/ufuncs/less.hpp +++ b/include/nmtools/array/view/ufuncs/less.hpp @@ -1,24 +1,50 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_LESS_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_LESS_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct less_t + struct less { template constexpr auto operator()(const T& t, const U& u) const { return t < u; } // operator() - }; // less_t + }; // less +} + +namespace nmtools::view +{ + using less_t = fun::less; template constexpr auto less(const left_t& a, const right_t& b) { return ufunc(less_t{},a,b); } // less -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::less) const + { + auto str = nmtools_string(); + + str += "less"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_LESS_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/less_equal.hpp b/include/nmtools/array/view/ufuncs/less_equal.hpp index 6fa7e7e4f..398a5ee60 100644 --- a/include/nmtools/array/view/ufuncs/less_equal.hpp +++ b/include/nmtools/array/view/ufuncs/less_equal.hpp @@ -1,24 +1,50 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_LESS_EQUAL_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_LESS_EQUAL_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct less_equal_t + struct less_equal { template constexpr auto operator()(const T& t, const U& u) const { return t <= u; } // operator() - }; // less_equal_t + }; // less_equal +} + +namespace nmtools::view +{ + using less_equal_t = fun::less_equal; template constexpr auto less_equal(const left_t& a, const right_t& b) { return ufunc(less_equal_t{},a,b); } // less_equal -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::less_equal) const + { + auto str = nmtools_string(); + + str += "less_equal"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_LESS_EQUAL_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/log.hpp b/include/nmtools/array/view/ufuncs/log.hpp index 0b211cd88..4a0a2359a 100644 --- a/include/nmtools/array/view/ufuncs/log.hpp +++ b/include/nmtools/array/view/ufuncs/log.hpp @@ -1,12 +1,13 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_LOG_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_LOG_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct log_t + struct log { template nmtools_func_attribute @@ -15,7 +16,12 @@ namespace nmtools::view { return math::log(t); } // operator() - }; // log_t + }; // log +} + +namespace nmtools::view +{ + using log_t = fun::log; template nmtools_func_attribute @@ -24,6 +30,26 @@ namespace nmtools::view { return ufunc(log_t{},a); } // log -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::log) const + { + nmtools_string str; + + str += "log"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_LOG_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/log10.hpp b/include/nmtools/array/view/ufuncs/log10.hpp index b95db8b5c..2e87761d7 100644 --- a/include/nmtools/array/view/ufuncs/log10.hpp +++ b/include/nmtools/array/view/ufuncs/log10.hpp @@ -1,12 +1,13 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_LOG10_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_LOG10_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct log10_t + struct log10 { template nmtools_func_attribute @@ -15,7 +16,12 @@ namespace nmtools::view { return math::log10(t); } // operator() - }; // log10_t + }; // log10 +} + +namespace nmtools::view +{ + using log10_t = fun::log10; template nmtools_func_attribute @@ -24,6 +30,26 @@ namespace nmtools::view { return ufunc(log10_t{},a); } // log10 -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::log10) const + { + nmtools_string str; + + str += "log10"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_LOG10_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/log1p.hpp b/include/nmtools/array/view/ufuncs/log1p.hpp index 0bd78b35d..3de3fec63 100644 --- a/include/nmtools/array/view/ufuncs/log1p.hpp +++ b/include/nmtools/array/view/ufuncs/log1p.hpp @@ -1,12 +1,13 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_LOG1P_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_LOG1P_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct log1p_t + struct log1p { template nmtools_func_attribute @@ -15,7 +16,12 @@ namespace nmtools::view { return math::log1p(t); } // operator() - }; // log1p_t + }; // log1p +} + +namespace nmtools::view +{ + using log1p_t = fun::log1p; template nmtools_func_attribute @@ -24,6 +30,26 @@ namespace nmtools::view { return ufunc(log1p_t{},a); } // log1p -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::log1p) const + { + nmtools_string str; + + str += "log1p"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_LOG1P_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/log2.hpp b/include/nmtools/array/view/ufuncs/log2.hpp index 741a92948..d20da60e0 100644 --- a/include/nmtools/array/view/ufuncs/log2.hpp +++ b/include/nmtools/array/view/ufuncs/log2.hpp @@ -1,12 +1,13 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_LOG2_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_LOG2_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct log2_t + struct log2 { template nmtools_func_attribute @@ -15,7 +16,12 @@ namespace nmtools::view { return math::log2(t); } // operator() - }; // log2_t + }; // log2 +} + +namespace nmtools::view +{ + using log2_t = fun::log2; template nmtools_func_attribute @@ -24,6 +30,26 @@ namespace nmtools::view { return ufunc(log2_t{},a); } // log2 -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::log2) const + { + nmtools_string str; + + str += "log2"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_LOG2_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/logical_and.hpp b/include/nmtools/array/view/ufuncs/logical_and.hpp index f7f7314cf..2ecc24355 100644 --- a/include/nmtools/array/view/ufuncs/logical_and.hpp +++ b/include/nmtools/array/view/ufuncs/logical_and.hpp @@ -1,18 +1,24 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_LOGICAL_AND_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_LOGICAL_AND_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct logical_and_t + struct logical_and { template constexpr auto operator()(const T& t, const U& u) const { return static_cast(t) && static_cast(u); } // operator() - }; // logical_and_t + }; // logical_and +} + +namespace nmtools::view +{ + using logical_and_t = fun::logical_and; template constexpr auto logical_and(const left_t& a, const right_t& b) @@ -26,6 +32,26 @@ namespace nmtools::view auto init = true; return reduce(logical_and_t{},a,axis,init); } // reduce_logical_and -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::logical_and) const + { + auto str = nmtools_string(); + + str += "logical_and"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_LOGICAL_AND_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/logical_not.hpp b/include/nmtools/array/view/ufuncs/logical_not.hpp index 2995f0420..d5a63e66b 100644 --- a/include/nmtools/array/view/ufuncs/logical_not.hpp +++ b/include/nmtools/array/view/ufuncs/logical_not.hpp @@ -1,24 +1,51 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_LOGICAL_NOT_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_LOGICAL_NOT_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct logical_not_t + struct logical_not { template constexpr auto operator()(const T& t) const { return !static_cast(t); } // operator() - }; // logical_not_t + }; // logical_not +} + +namespace nmtools::view +{ + using logical_not_t = fun::logical_not; template constexpr auto logical_not(const left_t& a) { return ufunc(logical_not_t{},a); } // logical_not -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::logical_not) const + { + auto str = nmtools_string(); + + str += "logical_not"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING + #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_LOGICAL_NOT_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/logical_or.hpp b/include/nmtools/array/view/ufuncs/logical_or.hpp index d74efe737..1854427e5 100644 --- a/include/nmtools/array/view/ufuncs/logical_or.hpp +++ b/include/nmtools/array/view/ufuncs/logical_or.hpp @@ -1,18 +1,24 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_LOGICAL_OR_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_LOGICAL_OR_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct logical_or_t + struct logical_or { template constexpr auto operator()(const T& t, const U& u) const { return static_cast(t) || static_cast(u); } // operator() - }; // logical_or_t + }; // logical_or +} + +namespace nmtools::view +{ + using logical_or_t = fun::logical_or; template constexpr auto logical_or(const left_t& a, const right_t& b) @@ -26,6 +32,26 @@ namespace nmtools::view auto init = false; return reduce(logical_or_t{},a,axis,init); } // reduce_logical_or -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::logical_or) const + { + auto str = nmtools_string(); + + str += "logical_or"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_LOGICAL_OR_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/logical_xor.hpp b/include/nmtools/array/view/ufuncs/logical_xor.hpp index 218dd78a2..e30335b89 100644 --- a/include/nmtools/array/view/ufuncs/logical_xor.hpp +++ b/include/nmtools/array/view/ufuncs/logical_xor.hpp @@ -1,18 +1,24 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_LOGICAL_XOR_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_LOGICAL_XOR_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct logical_xor_t + struct logical_xor { template constexpr auto operator()(const T& t, const U& u) const { return static_cast(t) ^ static_cast(u); } // operator() - }; // logical_xor_t + }; // logical_xor +} + +namespace nmtools::view +{ + using logical_xor_t = fun::logical_xor; template constexpr auto logical_xor(const left_t& a, const right_t& b) @@ -26,6 +32,26 @@ namespace nmtools::view auto init = false; return reduce(logical_xor_t{},a,axis,init); } // reduce_logical_xor -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::logical_xor) const + { + auto str = nmtools_string(); + + str += "logical_xor"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_LOGICAL_XOR_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/maximum.hpp b/include/nmtools/array/view/ufuncs/maximum.hpp index b44966187..ce414d0c3 100644 --- a/include/nmtools/array/view/ufuncs/maximum.hpp +++ b/include/nmtools/array/view/ufuncs/maximum.hpp @@ -43,19 +43,19 @@ namespace nmtools::view } // maximum template - constexpr auto reduce_maximum(const left_t& a, const axis_t& axis, dtype_t, initial_t initial, keepdims_t keepdims) + constexpr auto reduce_maximum(const left_t& a, const axis_t& axis, dtype_t dtype, initial_t initial, keepdims_t keepdims) { using res_t = get_dtype_t; using op_t = maximum_t; - return reduce(op_t{},a,axis,initial,keepdims); + return reduce(op_t{},a,axis,dtype,initial,keepdims); } // reduce_maximum template - constexpr auto reduce_maximum(const left_t& a, const axis_t& axis, dtype_t, initial_t initial) + constexpr auto reduce_maximum(const left_t& a, const axis_t& axis, dtype_t dtype, initial_t initial) { using res_t = get_dtype_t; using op_t = maximum_t; - return reduce(op_t{},a,axis,initial); + return reduce(op_t{},a,axis,dtype,initial); } // reduce_maximum template @@ -72,11 +72,11 @@ namespace nmtools::view } // reduce_maximum template - auto accumulate_maximum(const left_t& a, const axis_t& axis, dtype_t) + auto accumulate_maximum(const left_t& a, const axis_t& axis, dtype_t dtype) { using res_t = get_dtype_t; using op_t = maximum_t; - return accumulate(op_t{},a,axis); + return accumulate(op_t{},a,axis,dtype); } // accumulate_maximum template @@ -86,11 +86,11 @@ namespace nmtools::view } // accumulate_maximum template - constexpr auto outer_maximum(const left_t& a, const right_t& b, dtype_t=dtype_t{}) + constexpr auto outer_maximum(const left_t& a, const right_t& b, dtype_t dtype=dtype_t{}) { using res_t = get_dtype_t; using op_t = maximum_t; - return outer(op_t{},a,b); + return outer(op_t{},a,b,dtype); } // outer_maximum }; diff --git a/include/nmtools/array/view/ufuncs/minimum.hpp b/include/nmtools/array/view/ufuncs/minimum.hpp index 7fd18fd7c..72de4a8b0 100644 --- a/include/nmtools/array/view/ufuncs/minimum.hpp +++ b/include/nmtools/array/view/ufuncs/minimum.hpp @@ -43,19 +43,19 @@ namespace nmtools::view } // minimum template - constexpr auto reduce_minimum(const left_t& a, const axis_t& axis, dtype_t, initial_t initial, keepdims_t keepdims) + constexpr auto reduce_minimum(const left_t& a, const axis_t& axis, dtype_t dtype, initial_t initial, keepdims_t keepdims) { using res_t = get_dtype_t; using op_t = minimum_t; - return reduce(op_t{},a,axis,initial,keepdims); + return reduce(op_t{},a,axis,dtype,initial,keepdims); } // reduce_minimum template - constexpr auto reduce_minimum(const left_t& a, const axis_t& axis, dtype_t, initial_t initial) + constexpr auto reduce_minimum(const left_t& a, const axis_t& axis, dtype_t dtype, initial_t initial) { using res_t = get_dtype_t; using op_t = minimum_t; - return reduce(op_t{},a,axis,initial); + return reduce(op_t{},a,axis,dtype,initial); } // reduce_minimum template @@ -72,11 +72,11 @@ namespace nmtools::view } // reduce_minimum template - auto accumulate_minimum(const left_t& a, const axis_t& axis, dtype_t) + auto accumulate_minimum(const left_t& a, const axis_t& axis, dtype_t dtype) { using res_t = get_dtype_t; using op_t = minimum_t; - return accumulate(op_t{},a,axis); + return accumulate(op_t{},a,axis,dtype); } // accumulate_minimum template @@ -86,11 +86,11 @@ namespace nmtools::view } // accumulate_minimum template - constexpr auto outer_minimum(const left_t& a, const right_t& b, dtype_t=dtype_t{}) + constexpr auto outer_minimum(const left_t& a, const right_t& b, dtype_t dtype=dtype_t{}) { using res_t = get_dtype_t; using op_t = minimum_t; - return outer(op_t{},a,b); + return outer(op_t{},a,b,dtype); } // outer_minimum }; diff --git a/include/nmtools/array/view/ufuncs/mod.hpp b/include/nmtools/array/view/ufuncs/mod.hpp index 80721798a..2edfb2576 100644 --- a/include/nmtools/array/view/ufuncs/mod.hpp +++ b/include/nmtools/array/view/ufuncs/mod.hpp @@ -1,24 +1,50 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_MOD_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_MOD_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct mod_t + struct mod { template constexpr auto operator()(const T& t, const U& u) const { return t % u; } // operator() - }; // mod_t + }; // mod +} + +namespace nmtools::view +{ + using mod_t = fun::mod; template constexpr auto mod(const left_t& a, const right_t& b) { return ufunc(mod_t{},a,b); } // mod -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::mod) const + { + auto str = nmtools_string(); + + str += "mod"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_MOD_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/multiply.hpp b/include/nmtools/array/view/ufuncs/multiply.hpp index 76008826b..d267fa752 100644 --- a/include/nmtools/array/view/ufuncs/multiply.hpp +++ b/include/nmtools/array/view/ufuncs/multiply.hpp @@ -1,10 +1,11 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_MULTIPLY_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_MULTIPLY_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/constants.hpp" -namespace nmtools::view +namespace nmtools::view::fun { template < typename lhs_t=none_t, @@ -12,7 +13,7 @@ namespace nmtools::view typename res_t=none_t, typename=void > - struct multiply_t + struct multiply { static constexpr auto identity() @@ -48,13 +49,13 @@ namespace nmtools::view return static_cast(t * u); } } // operator() - }; // multiply_t + }; // multiply // NOTE: tried to disable but not successful // TODO: remove by unifying with primary template #if 1 template - struct multiply_t> > { @@ -65,8 +66,18 @@ namespace nmtools::view { return t * u; } // operator() - }; // multiply_t + }; // multiply #endif +} + +namespace nmtools::view +{ + template < + typename lhs_t=none_t, + typename rhs_t=none_t, + typename res_t=none_t + > + using multiply_t = fun::multiply; template constexpr auto multiply(const left_t& a, const right_t& b, casting_t=casting_t{}) @@ -86,19 +97,30 @@ namespace nmtools::view } // multiply template - constexpr auto reduce_multiply(const left_t& a, const axis_t& axis, dtype_t /*dtype*/, initial_t initial, keepdims_t keepdims) + constexpr auto reduce_multiply(const left_t& a, const axis_t& axis, dtype_t dtype, initial_t initial, keepdims_t keepdims) { using res_t = get_dtype_t; using op_t = multiply_t; - return reduce(op_t{},a,axis,initial,keepdims); + return reduce(op_t{},a,axis,dtype,initial,keepdims); } // reduce_multiply + template + constexpr auto reduce_multiply(const left_t& a, const args::reduce& attributes) + { + return reduce_multiply(a + , attributes.axis + , attributes.dtype + , attributes.initial + , attributes.keepdims + ); + } + template - constexpr auto reduce_multiply(const left_t& a, const axis_t& axis, dtype_t /*dtype*/, initial_t initial) + constexpr auto reduce_multiply(const left_t& a, const axis_t& axis, dtype_t dtype, initial_t initial) { using res_t = get_dtype_t; using op_t = multiply_t; - return reduce(op_t{},a,axis,initial); + return reduce(op_t{},a,axis,dtype,initial); } // reduce_multiply template @@ -115,11 +137,11 @@ namespace nmtools::view } // reduce_multiply template - constexpr auto accumulate_multiply(const left_t& a, const axis_t& axis, dtype_t) + constexpr auto accumulate_multiply(const left_t& a, const axis_t& axis, dtype_t dtype) { using res_t = get_dtype_t; using op_t = multiply_t; - return accumulate(op_t{},a,axis); + return accumulate(op_t{},a,axis,dtype); } // accumulate_multiply template @@ -129,12 +151,36 @@ namespace nmtools::view } // accumulate_multiply template - constexpr auto outer_multiply(const left_t& a, const right_t& b, dtype_t=dtype_t{}) + constexpr auto outer_multiply(const left_t& a, const right_t& b, dtype_t dtype=dtype_t{}) { using res_t = get_dtype_t; using op_t = multiply_t; - return outer(op_t{},a,b); + return outer(op_t{},a,b,dtype); } // outer_multiply -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template < + typename lhs_t, + typename rhs_t, + typename res_t + > + struct to_string_t,none_t> + { + auto operator()(view::fun::multiply) const + { + auto str = nmtools_string(); + + str += "multiply"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_MULTIPLY_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/negative.hpp b/include/nmtools/array/view/ufuncs/negative.hpp index 75b365f08..88a9eea40 100644 --- a/include/nmtools/array/view/ufuncs/negative.hpp +++ b/include/nmtools/array/view/ufuncs/negative.hpp @@ -1,24 +1,50 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_NEGATIVE_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_NEGATIVE_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct negative_t + struct negative { template constexpr auto operator()(const T& t) const { return -t; } // operator() - }; // negative_t + }; // negative +} + +namespace nmtools::view +{ + using negative_t = fun::negative; template constexpr auto negative(const left_t& a) { return ufunc(negative_t{},a); } // negative -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::negative) const + { + nmtools_string str; + + str += "negative"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_NEGATIVE_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/not_equal.hpp b/include/nmtools/array/view/ufuncs/not_equal.hpp index bf76bbc45..b9f68b85a 100644 --- a/include/nmtools/array/view/ufuncs/not_equal.hpp +++ b/include/nmtools/array/view/ufuncs/not_equal.hpp @@ -1,24 +1,50 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_NOT_EQUAL_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_NOT_EQUAL_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct not_equal_t + struct not_equal { template constexpr auto operator()(const T& t, const U& u) const { return t != u; } // operator() - }; // not_equal_t + }; // not_equal +} + +namespace nmtools::view +{ + using not_equal_t = fun::not_equal; template constexpr auto not_equal(const left_t& a, const right_t& b) { return ufunc(not_equal_t{},a,b); } // not_equal -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::not_equal) const + { + auto str = nmtools_string(); + + str += "not_equal"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_NOT_EQUAL_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/positive.hpp b/include/nmtools/array/view/ufuncs/positive.hpp index 07650c868..bf3557f18 100644 --- a/include/nmtools/array/view/ufuncs/positive.hpp +++ b/include/nmtools/array/view/ufuncs/positive.hpp @@ -1,24 +1,50 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_POSITIVE_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_POSITIVE_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct positive_t + struct positive { template constexpr auto operator()(const T& t) const { return +t; } // operator() - }; // positive_t + }; // positive +} + +namespace nmtools::view +{ + using positive_t = fun::positive; template constexpr auto positive(const left_t& a) { return ufunc(positive_t{},a); } // positive -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::positive) const + { + nmtools_string str; + + str += "positive"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_POSITIVE_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/power.hpp b/include/nmtools/array/view/ufuncs/power.hpp index 684c039d3..018323227 100644 --- a/include/nmtools/array/view/ufuncs/power.hpp +++ b/include/nmtools/array/view/ufuncs/power.hpp @@ -59,38 +59,38 @@ namespace nmtools::view template NMTOOLS_UFUNC_CONSTEXPR - auto reduce_power(const left_t& a, const axis_t& axis, dtype_t, initial_t initial, keepdims_t keepdims) + auto reduce_power(const left_t& a, const axis_t& axis, dtype_t dtype, initial_t initial, keepdims_t keepdims) { static_assert( meta::is_integral_v , "reduce_power only support single axis with integral type" ); using res_t = get_dtype_t; using op_t = power_t; - return reduce(op_t{},a,axis,initial,keepdims); + return reduce(op_t{},a,axis,dtype,initial,keepdims); } // reduce_power template NMTOOLS_UFUNC_CONSTEXPR - auto reduce_power(const left_t& a, const axis_t& axis, dtype_t, initial_t initial) + auto reduce_power(const left_t& a, const axis_t& axis, dtype_t dtype, initial_t initial) { static_assert( meta::is_integral_v , "reduce_power only support single axis with integral type" ); using res_t = get_dtype_t; using op_t = power_t; - return reduce(op_t{},a,axis,initial); + return reduce(op_t{},a,axis,dtype,initial); } // reduce_power template NMTOOLS_UFUNC_CONSTEXPR - auto reduce_power(const left_t& a, const axis_t& axis, dtype_t) + auto reduce_power(const left_t& a, const axis_t& axis, dtype_t dtype) { static_assert( meta::is_integral_v , "reduce_power only support single axis with integral type" ); using res_t = get_dtype_t; using op_t = power_t; - return reduce(op_t{},a,axis,None); + return reduce(op_t{},a,axis,dtype,None); } // reduce_power // TODO: use default args, instead of overload! @@ -103,11 +103,11 @@ namespace nmtools::view template NMTOOLS_UFUNC_CONSTEXPR - auto accumulate_power(const left_t& a, const axis_t& axis, dtype_t) + auto accumulate_power(const left_t& a, const axis_t& axis, dtype_t dtype) { using res_t = get_dtype_t; using op_t = power_t; - return accumulate(op_t{},a,axis); + return accumulate(op_t{},a,axis,dtype); } // accumulate_power template @@ -119,11 +119,11 @@ namespace nmtools::view template NMTOOLS_UFUNC_CONSTEXPR - auto outer_power(const left_t& a, const right_t& b, dtype_t=dtype_t{}) + auto outer_power(const left_t& a, const right_t& b, dtype_t dtype=dtype_t{}) { using res_t = get_dtype_t; using op_t = power_t; - return outer(op_t{},a,b); + return outer(op_t{},a,b,dtype); } // outer_power } diff --git a/include/nmtools/array/view/ufuncs/reciprocal.hpp b/include/nmtools/array/view/ufuncs/reciprocal.hpp index b9d3ab184..200af735d 100644 --- a/include/nmtools/array/view/ufuncs/reciprocal.hpp +++ b/include/nmtools/array/view/ufuncs/reciprocal.hpp @@ -1,24 +1,50 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_RECIPROCAL_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_RECIPROCAL_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct reciprocal_t + struct reciprocal { template constexpr auto operator()(const T& t) const { return 1/t; } // operator() - }; // reciprocal_t + }; // reciprocal +} + +namespace nmtools::view +{ + using reciprocal_t = fun::reciprocal; template constexpr auto reciprocal(const left_t& a) { return ufunc(reciprocal_t{},a); } // reciprocal -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::reciprocal) const + { + nmtools_string str; + + str += "reciprocal"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_RECIPROCAL_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/right_shift.hpp b/include/nmtools/array/view/ufuncs/right_shift.hpp index 45575c2dc..603835e22 100644 --- a/include/nmtools/array/view/ufuncs/right_shift.hpp +++ b/include/nmtools/array/view/ufuncs/right_shift.hpp @@ -43,7 +43,7 @@ namespace nmtools::view } // right_shift template - constexpr auto reduce_right_shift(const left_t& a, const axis_t& axis, dtype_t, initial_t initial, keepdims_t keepdims) + constexpr auto reduce_right_shift(const left_t& a, const axis_t& axis, dtype_t dtype, initial_t initial, keepdims_t keepdims) { static_assert( meta::is_integral_v , "reduce_right_shift only support single axis with integral type" @@ -53,11 +53,11 @@ namespace nmtools::view // to match the signature of reduce_t using res_t = get_dtype_t; using op_t = right_shift_t; - return reduce(op_t{},a,axis,initial,keepdims); + return reduce(op_t{},a,axis,dtype,initial,keepdims); } // reduce_right_shift template - constexpr auto reduce_right_shift(const left_t& a, const axis_t& axis, dtype_t, initial_t initial) + constexpr auto reduce_right_shift(const left_t& a, const axis_t& axis, dtype_t dtype, initial_t initial) { static_assert( meta::is_integral_v , "reduce_right_shift only support single axis with integral type" @@ -67,7 +67,7 @@ namespace nmtools::view // to match the signature of reduce_t using res_t = get_dtype_t; using op_t = right_shift_t; - return reduce(op_t{},a,axis,initial); + return reduce(op_t{},a,axis,dtype,initial); } // reduce_right_shift template @@ -84,11 +84,11 @@ namespace nmtools::view } // reduce_right_shift template - auto accumulate_right_shift(const left_t& a, const axis_t& axis, dtype_t) + auto accumulate_right_shift(const left_t& a, const axis_t& axis, dtype_t dtype) { using res_t = get_dtype_t; using op_t = right_shift_t; - return accumulate(op_t{},a,axis); + return accumulate(op_t{},a,axis,dtype); } // accumulate_right_shift template @@ -98,11 +98,11 @@ namespace nmtools::view } // accumulate_right_shift template - constexpr auto outer_right_shift(const left_t& a, const right_t& b, dtype_t=dtype_t{}) + constexpr auto outer_right_shift(const left_t& a, const right_t& b, dtype_t dtype=dtype_t{}) { using res_t = get_dtype_t; using op_t = right_shift_t; - return outer(op_t{},a,b); + return outer(op_t{},a,b,dtype); } // outer_right_shift }; diff --git a/include/nmtools/array/view/ufuncs/rint.hpp b/include/nmtools/array/view/ufuncs/rint.hpp index 39aba00a4..0260694ef 100644 --- a/include/nmtools/array/view/ufuncs/rint.hpp +++ b/include/nmtools/array/view/ufuncs/rint.hpp @@ -1,12 +1,13 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_RINT_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_RINT_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct rint_t + struct rint { template nmtools_func_attribute @@ -15,7 +16,12 @@ namespace nmtools::view { return math::rint(t); } // operator() - }; // rint_t + }; // rint +} + +namespace nmtools::view +{ + using rint_t = fun::rint; template nmtools_func_attribute @@ -24,6 +30,26 @@ namespace nmtools::view { return ufunc(rint_t{},a); } // rint -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::rint) const + { + nmtools_string str; + + str += "rint"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_RINT_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/signbit.hpp b/include/nmtools/array/view/ufuncs/signbit.hpp index 5a0af1082..eb0740ba0 100644 --- a/include/nmtools/array/view/ufuncs/signbit.hpp +++ b/include/nmtools/array/view/ufuncs/signbit.hpp @@ -1,12 +1,13 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_SIGNBIT_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_SIGNBIT_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct signbit_t + struct signbit { template nmtools_func_attribute @@ -15,7 +16,12 @@ namespace nmtools::view { return math::signbit(t); } // operator() - }; // signbit_t + }; // signbit +} + +namespace nmtools::view +{ + using signbit_t = fun::signbit; template nmtools_func_attribute @@ -24,6 +30,26 @@ namespace nmtools::view { return ufunc(signbit_t{},a); } // signbit -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::signbit) const + { + nmtools_string str; + + str += "signbit"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_SIGNBIT_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/sin.hpp b/include/nmtools/array/view/ufuncs/sin.hpp index dd850d449..95a39b171 100644 --- a/include/nmtools/array/view/ufuncs/sin.hpp +++ b/include/nmtools/array/view/ufuncs/sin.hpp @@ -1,12 +1,13 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_SIN_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_SIN_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct sin_t + struct sin { template nmtools_func_attribute @@ -15,7 +16,12 @@ namespace nmtools::view { return math::sin(t); } // operator() - }; // sin_t + }; // sin +} + +namespace nmtools::view +{ + using sin_t = fun::sin; template nmtools_func_attribute @@ -24,6 +30,26 @@ namespace nmtools::view { return ufunc(sin_t{},a); } // sin -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::sin) const + { + nmtools_string str; + + str += "sin"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_SIN_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/sinh.hpp b/include/nmtools/array/view/ufuncs/sinh.hpp index 875df5953..9696ad101 100644 --- a/include/nmtools/array/view/ufuncs/sinh.hpp +++ b/include/nmtools/array/view/ufuncs/sinh.hpp @@ -1,12 +1,13 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_SINH_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_SINH_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct sinh_t + struct sinh { template nmtools_func_attribute @@ -15,7 +16,12 @@ namespace nmtools::view { return math::sinh(t); } // operator() - }; // sinh_t + }; // sinh +} + +namespace nmtools::view +{ + using sinh_t = fun::sinh; template nmtools_func_attribute @@ -24,6 +30,26 @@ namespace nmtools::view { return ufunc(sinh_t{},a); } // sinh -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::sinh) const + { + nmtools_string str; + + str += "sinh"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_SINH_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/sqrt.hpp b/include/nmtools/array/view/ufuncs/sqrt.hpp index 81d460b29..e933d3bab 100644 --- a/include/nmtools/array/view/ufuncs/sqrt.hpp +++ b/include/nmtools/array/view/ufuncs/sqrt.hpp @@ -1,12 +1,13 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_SQRT_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_SQRT_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct sqrt_t + struct sqrt { template nmtools_func_attribute @@ -15,7 +16,12 @@ namespace nmtools::view { return math::sqrt(t); } // operator() - }; // sqrt_t + }; // sqrt +} + +namespace nmtools::view +{ + using sqrt_t = fun::sqrt; template nmtools_func_attribute @@ -24,6 +30,26 @@ namespace nmtools::view { return ufunc(sqrt_t{},a); } // sqrt -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::sqrt) const + { + nmtools_string str; + + str += "sqrt"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_SQRT_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/square.hpp b/include/nmtools/array/view/ufuncs/square.hpp index 0948c8bda..9caf0a42e 100644 --- a/include/nmtools/array/view/ufuncs/square.hpp +++ b/include/nmtools/array/view/ufuncs/square.hpp @@ -1,24 +1,50 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_SQUARE_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_SQUARE_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct square_t + struct square { template constexpr auto operator()(const T& t) const { return t * t; } // operator() - }; // square_t + }; // square +} + +namespace nmtools::view +{ + using square_t = fun::square; template constexpr auto square(const left_t& a) { return ufunc(square_t{},a); } // square -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::square) const + { + nmtools_string str; + + str += "square"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_SQUARE_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/subtract.hpp b/include/nmtools/array/view/ufuncs/subtract.hpp index 2480926ef..08e82adbb 100644 --- a/include/nmtools/array/view/ufuncs/subtract.hpp +++ b/include/nmtools/array/view/ufuncs/subtract.hpp @@ -1,9 +1,10 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_SUBTRACT_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_SUBTRACT_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" -namespace nmtools::view +namespace nmtools::view::fun { template < typename lhs_t=none_t, @@ -11,7 +12,7 @@ namespace nmtools::view typename res_t=none_t, typename=void > - struct subtract_t + struct subtract { // NOTE: tried to disable but not successful // TODO: remove by unifying with primary template @@ -37,13 +38,13 @@ namespace nmtools::view return static_cast(t - u); } } // operator() - }; // subtract_t + }; // subtract // NOTE: tried to disable but not successful // TODO: remove by unifying with primary template #if 1 template - struct subtract_t> > { @@ -54,8 +55,18 @@ namespace nmtools::view { return t - u; } // operator() - }; // subtract_t + }; // subtract #endif +} + +namespace nmtools::view +{ + template < + typename lhs_t=none_t, + typename rhs_t=none_t, + typename res_t=none_t + > + using subtract_t = fun::subtract; template constexpr auto subtract(const left_t& a, const right_t& b, casting_t=casting_t{}) @@ -75,7 +86,7 @@ namespace nmtools::view } // subtract template - constexpr auto reduce_subtract(const left_t& a, const axis_t& axis, dtype_t, initial_t initial, keepdims_t keepdims) + constexpr auto reduce_subtract(const left_t& a, const axis_t& axis, dtype_t dtype, initial_t initial, keepdims_t keepdims) { static_assert( meta::is_integral_v , "reduce_subtract only support single axis with integral type" @@ -85,11 +96,11 @@ namespace nmtools::view // to match the signature of reduce_t using res_t = get_dtype_t; using op_t = subtract_t; - return reduce(op_t{},a,axis,initial,keepdims); + return reduce(op_t{},a,axis,dtype,initial,keepdims); } // reduce_subtract template - constexpr auto reduce_subtract(const left_t& a, const axis_t& axis, dtype_t, initial_t initial) + constexpr auto reduce_subtract(const left_t& a, const axis_t& axis, dtype_t dtype, initial_t initial) { static_assert( meta::is_integral_v , "reduce_subtract only support single axis with integral type" @@ -99,7 +110,7 @@ namespace nmtools::view // to match the signature of reduce_t using res_t = get_dtype_t; using op_t = subtract_t; - return reduce(op_t{},a,axis,initial); + return reduce(op_t{},a,axis,dtype,initial); } // reduce_subtract template @@ -116,11 +127,11 @@ namespace nmtools::view } // reduce_subtract template - auto accumulate_subtract(const left_t& a, const axis_t& axis, dtype_t) + auto accumulate_subtract(const left_t& a, const axis_t& axis, dtype_t dtype) { using res_t = get_dtype_t; using op_t = subtract_t; - return accumulate(op_t{},a,axis); + return accumulate(op_t{},a,axis,dtype); } // accumulate_subtract template @@ -130,12 +141,36 @@ namespace nmtools::view } // accumulate_subtract template - constexpr auto outer_subtract(const left_t& a, const right_t& b, dtype_t=dtype_t{}) + constexpr auto outer_subtract(const left_t& a, const right_t& b, dtype_t dtype=dtype_t{}) { using res_t = get_dtype_t; using op_t = subtract_t; - return outer(op_t{},a,b); + return outer(op_t{},a,b,dtype); } // outer_subtract -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template < + typename lhs_t, + typename rhs_t, + typename res_t + > + struct to_string_t,none_t> + { + auto operator()(view::fun::subtract) const + { + auto str = nmtools_string(); + + str += "subtract"; + + return str; + } + }; +} + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_SUBTRACT_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/tan.hpp b/include/nmtools/array/view/ufuncs/tan.hpp index 8787b5acb..1f7bd99b5 100644 --- a/include/nmtools/array/view/ufuncs/tan.hpp +++ b/include/nmtools/array/view/ufuncs/tan.hpp @@ -1,12 +1,13 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_TAN_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_TAN_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct tan_t + struct tan { template nmtools_func_attribute @@ -15,7 +16,12 @@ namespace nmtools::view { return math::tan(t); } // operator() - }; // tan_t + }; // tan +} + +namespace nmtools::view +{ + using tan_t = fun::tan; template nmtools_func_attribute @@ -24,6 +30,26 @@ namespace nmtools::view { return ufunc(tan_t{},a); } // tan -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::tan) const + { + nmtools_string str; + + str += "tan"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_TAN_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/tanh.hpp b/include/nmtools/array/view/ufuncs/tanh.hpp index 7f7944891..45a8333d3 100644 --- a/include/nmtools/array/view/ufuncs/tanh.hpp +++ b/include/nmtools/array/view/ufuncs/tanh.hpp @@ -1,12 +1,13 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_TANH_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_TANH_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct tanh_t + struct tanh { template nmtools_func_attribute @@ -15,7 +16,12 @@ namespace nmtools::view { return math::tanh(t); } // operator() - }; // tanh_t + }; // tanh +} + +namespace nmtools::view +{ + using tanh_t = fun::tanh; template nmtools_func_attribute @@ -24,6 +30,26 @@ namespace nmtools::view { return ufunc(tanh_t{},a); } // tanh -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::tanh) const + { + nmtools_string str; + + str += "tanh"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_TANH_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/trunc.hpp b/include/nmtools/array/view/ufuncs/trunc.hpp index cb14e0fe8..2be82c4ba 100644 --- a/include/nmtools/array/view/ufuncs/trunc.hpp +++ b/include/nmtools/array/view/ufuncs/trunc.hpp @@ -1,12 +1,13 @@ #ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_TRUNC_HPP #define NMTOOLS_ARRAY_VIEW_UFUNCS_TRUNC_HPP +#include "nmtools/utils/to_string/to_string.hpp" #include "nmtools/array/view/ufunc.hpp" #include "nmtools/math.hpp" -namespace nmtools::view +namespace nmtools::view::fun { - struct trunc_t + struct trunc { template NMTOOLS_UFUNC_CONSTEXPR @@ -14,7 +15,12 @@ namespace nmtools::view { return math::trunc(t); } // operator() - }; // trunc_t + }; // trunc +} + +namespace nmtools::view +{ + using trunc_t = fun::trunc; template NMTOOLS_UFUNC_CONSTEXPR @@ -22,6 +28,26 @@ namespace nmtools::view { return ufunc(trunc_t{},a); } // trunc -}; +} + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template <> + struct to_string_t + { + auto operator()(view::fun::trunc) const + { + nmtools_string str; + + str += "trunc"; + + return str; + } + }; +} // namespace nmtools::utils::impl + +#endif // NMTOOLS_HAS_STRING #endif // NMTOOLS_ARRAY_VIEW_UFUNCS_TRUNC_HPP \ No newline at end of file diff --git a/include/nmtools/meta/bits/traits/is_attribute.hpp b/include/nmtools/meta/bits/traits/is_attribute.hpp new file mode 100644 index 000000000..9693a16a3 --- /dev/null +++ b/include/nmtools/meta/bits/traits/is_attribute.hpp @@ -0,0 +1,21 @@ +#ifndef NMTOOLS_META_BITS_TRAITS_IS_ATTRIBUTE_HPP +#define NMTOOLS_META_BITS_TRAITS_IS_ATTRIBUTE_HPP + +#include "nmtools/meta/common.hpp" + +namespace nmtools::meta +{ + template + struct is_attribute : false_type {}; + + template + constexpr inline auto is_attribute_v = is_attribute::value; + + template + struct is_attribute : is_attribute {}; + + template + struct is_attribute : is_attribute {}; +} // namespace nmtools::meta + +#endif // NMTOOLS_META_BITS_TRAITS_IS_ATTRIBUTE_HPP \ No newline at end of file diff --git a/include/nmtools/meta/common.hpp b/include/nmtools/meta/common.hpp index 05d8b4da9..4d468b777 100644 --- a/include/nmtools/meta/common.hpp +++ b/include/nmtools/meta/common.hpp @@ -178,6 +178,10 @@ namespace nmtools::meta template constexpr inline auto ct_v = ct{}; + + // used mostly by functional module + struct empty_operands_t {}; + struct empty_attributes_t {}; } // nmtools::meta namespace nmtools::meta diff --git a/include/nmtools/meta/expr.hpp b/include/nmtools/meta/expr.hpp index 3629cf789..a61a83b9f 100644 --- a/include/nmtools/meta/expr.hpp +++ b/include/nmtools/meta/expr.hpp @@ -29,6 +29,15 @@ namespace nmtools::meta template using funcnd = decltype(declval().operator()(declval()...)); + template + using callable = decltype(declval()(declval()...)); + + template + using equal = decltype(declval()==declval()); + + template + using invert = decltype(~declval()); + /** * @brief helper alias template to check if given type T has operator [] overload * that takes size_types as arguments. diff --git a/include/nmtools/meta/traits.hpp b/include/nmtools/meta/traits.hpp index 01c4e488b..0b94a239b 100644 --- a/include/nmtools/meta/traits.hpp +++ b/include/nmtools/meta/traits.hpp @@ -21,6 +21,7 @@ #include "nmtools/meta/bits/traits/has_type.hpp" #include "nmtools/meta/bits/traits/has_value_type.hpp" #include "nmtools/meta/bits/traits/is_assignable.hpp" +#include "nmtools/meta/bits/traits/is_attribute.hpp" #include "nmtools/meta/bits/traits/is_bit_reference.hpp" #include "nmtools/meta/bits/traits/is_boolean.hpp" #include "nmtools/meta/bits/traits/is_bounded_array.hpp" diff --git a/include/nmtools/testing/doctest.hpp b/include/nmtools/testing/doctest.hpp index f916c609a..04c70196e 100644 --- a/include/nmtools/testing/doctest.hpp +++ b/include/nmtools/testing/doctest.hpp @@ -9,6 +9,9 @@ #undef NMTOOLS_ASSERT_EQUAL #define NMTOOLS_ASSERT_EQUAL NMTOOLS_ASSERT_EQUAL_DOCTEST +#undef NMTOOLS_ASSERT_NOT_EQUAL +#define NMTOOLS_ASSERT_NOT_EQUAL NMTOOLS_ASSERT_NOT_EQUAL_DOCTEST + #define NMTOOLS_REQUIRE_EQUAL(lhs, rhs) \ { \ auto lhs_str = nmtools::utils::to_string(lhs); \ diff --git a/include/nmtools/testing/string.hpp b/include/nmtools/testing/string.hpp index 644cf5a5d..fb6ac62cc 100644 --- a/include/nmtools/testing/string.hpp +++ b/include/nmtools/testing/string.hpp @@ -6,6 +6,8 @@ #include "nmtools/utils/to_string.hpp" +#define NMTOOLS_TESTING_GET_TYPENAME NMTOOLS_TYPENAME_TO_STRING + #ifndef NMTOOLS_DISABLE_STL #include #include diff --git a/include/nmtools/testing/testing.hpp b/include/nmtools/testing/testing.hpp index 076f64b52..bc06c9e5e 100644 --- a/include/nmtools/testing/testing.hpp +++ b/include/nmtools/testing/testing.hpp @@ -94,6 +94,15 @@ CHECK_MESSAGE(isequal(result,expect), \ ) \ ); +#define NMTOOLS_ASSERT_NOT_EQUAL_DOCTEST(result,expect) \ +CHECK_MESSAGE(!isequal(result,expect), \ + ( \ + std::string{} \ + + "\n\tActual : " + STRINGIFY(result) \ + + "\n\tExpected: " + STRINGIFY(expect) \ + ) \ +) + #define NMTOOLS_STATIC_ASSERT_EQUAL_DOCTEST(result,expect) \ { \ [[maybe_unused]] constexpr auto result_ = isequal(result,expect); \ diff --git a/include/nmtools/utils/isclose.hpp b/include/nmtools/utils/isclose.hpp index dc100c7a7..e43f36be6 100644 --- a/include/nmtools/utils/isclose.hpp +++ b/include/nmtools/utils/isclose.hpp @@ -20,6 +20,7 @@ #include "nmtools/utils/isequal.hpp" #include "nmtools/math.hpp" #include "nmtools/platform/math/constexpr.hpp" +#include "nmtools/utils/isclose/isclose.hpp" #ifndef NMTOOLS_ISCLOSE_NAN_HANDLING #define NMTOOLS_ISCLOSE_NAN_HANDLING 0 @@ -267,10 +268,10 @@ namespace nmtools::utils auto abs_diff = constexpr_fabs(static_cast(t)-static_cast(u)); auto result = abs_diff < static_cast(eps); #if NMTOOLS_ISCLOSE_NAN_HANDLING - result = result || (math::isnan(t) && math::isnan(u)); + result = result || (math::isnan(static_cast(t)) && math::isnan(static_cast(u))); #endif #if NMTOOLS_ISCLOSE_INF_HANDLING - result = result || (math::isinf(t) && math::isinf(u)); + result = result || (math::isinf(static_cast(t)) && math::isinf(static_cast(u))); #endif return result; } @@ -310,8 +311,8 @@ namespace nmtools::utils * @param eps epsilon * @return constexpr auto */ - template - constexpr auto isclose(const T& t, const U& u, E eps=static_cast(1e-6)) + template + constexpr auto isclose(const T& t, const U& u, E eps) { // TODO: remove tuple_size metafunctions // check if tuple_size for T & U is available @@ -336,73 +337,6 @@ namespace nmtools::utils } else return detail::isclose(t,u,eps); } // isclose - - template < - typename F, typename lhs_operands_t, typename lhs_attributes_t - , typename G, typename rhs_operands_t, typename rhs_attributes_t> - constexpr auto isequal( - const functional::functor_t& lhs - , const functional::functor_t& rhs - ) { - if constexpr ( !meta::is_same_v || - !meta::is_same_v - ) { - // TODO: also check the values of operands - return false; - } else if constexpr ( - !meta::is_same_v - && !meta::is_same_v - ) { - constexpr auto M = meta::len_v; - constexpr auto N = meta::len_v; - if constexpr (M != N) { - return false; - } else { - auto equal = true; - meta::template_for([&](auto index){ - auto equal_attribute = [&](){ - auto lhs_attribute = at(lhs.attributes,index); - auto rhs_attribute = at(rhs.attributes,index); - if constexpr (meta::is_floating_point_v - && meta::is_floating_point_v) - { - return isclose(lhs_attribute,rhs_attribute); - } else { - return isequal(lhs_attribute,rhs_attribute); - } - }(); - equal = equal && equal_attribute; - }); - return equal; - } - } else if constexpr ( meta::is_same_v - && meta::is_same_v - && meta::is_same_v - ) { - return true; - } else { - return false; - } - } - - template < - templatetypename lhs_tuple, typename...lhs_functors_t, typename lhs_operands_t, - templatetypename rhs_tuple, typename...rhs_functors_t, typename rhs_operands_t - > - constexpr auto isequal( - const functional::functor_composition_t,lhs_operands_t>& lhs - , const functional::functor_composition_t,rhs_operands_t>& rhs - ) { - constexpr auto N_LHS = meta::len_v; - constexpr auto N_RHS = meta::len_v; - - auto equal = N_LHS == N_RHS; - constexpr auto N = (N_LHS < N_RHS) ? N_LHS : N_RHS; - meta::template_for([&](auto index){ - equal = equal && isequal(at(lhs.functors,index),at(rhs.functors,index)); - }); - return equal; - } } // namespace nmtools::utils #endif // NMTOOLS_UTILS_ISCLOSE_HPP \ No newline at end of file diff --git a/include/nmtools/utils/isclose/isclose.hpp b/include/nmtools/utils/isclose/isclose.hpp new file mode 100644 index 000000000..f3fca3bad --- /dev/null +++ b/include/nmtools/utils/isclose/isclose.hpp @@ -0,0 +1,15 @@ +#ifndef NMTOOLS_UTILS_ISCLOSE_ISCLOSE_HPP +#define NMTOOLS_UTILS_ISCLOSE_ISCLOSE_HPP + +#include "nmtools/meta.hpp" + +namespace nmtools::utils +{ + template + struct isclose_t; + + template + constexpr auto isclose(const lhs_t& lhs, const rhs_t& rhs, epsilon_t=static_cast(1e-6)); +} // namespace nmtools::utils + +#endif // NMTOOLS_UTILS_ISCLOSE_ISCLOSE_HPP \ No newline at end of file diff --git a/include/nmtools/utils/isequal.hpp b/include/nmtools/utils/isequal.hpp index 7232923bb..8b9f7ce60 100644 --- a/include/nmtools/utils/isequal.hpp +++ b/include/nmtools/utils/isequal.hpp @@ -1,13 +1,3 @@ -/** - * @file isequal.hpp - * @author Fahri Ali Rahman (ali.rahman.fahri@gmail.com) - * @brief Contains definition of isequal - * @version 0.1 - * @date 2020-11-17 - * - * @copyright Copyright (c) 2020 - * - */ #ifndef NMTOOLS_UTILS_ISEQUAL_HPP #define NMTOOLS_UTILS_ISEQUAL_HPP @@ -15,8 +5,8 @@ #include "nmtools/assert.hpp" #include "nmtools/array/shape.hpp" #include "nmtools/array/index/ndindex.hpp" -#include "nmtools/array/functional/functor.hpp" #include "nmtools/array/utility/apply_at.hpp" +#include "nmtools/utils/isequal/isequal.hpp" namespace nmtools::utils { @@ -140,23 +130,42 @@ namespace nmtools::utils // allow none, integer, or ndarray // for ndarray, the element type must be integral - auto is_none = is_none_v && is_none_v; - auto is_ellipsis = is_ellipsis_v && is_ellipsis_v; - auto is_integer = (meta::is_integer_v || meta::is_integral_constant_v) + auto is_none = + is_none_v + && is_none_v; + auto is_ellipsis = + is_ellipsis_v + && is_ellipsis_v; + auto is_integer = + (meta::is_integer_v || meta::is_integral_constant_v) && (meta::is_integer_v || meta::is_integral_constant_v); - auto is_num_or_array = (meta::is_num_v && meta::is_num_v) + auto is_num_or_array = + (meta::is_num_v && meta::is_num_v) || (meta::is_ndarray_v && meta::is_ndarray_v); - auto is_index_constant = meta::is_index_array_v && meta::is_index_array_v; - auto element_is_integer = meta::is_integer_v && meta::is_integer_v; - auto is_slice = meta::is_slice_index_v && meta::is_slice_index_v; - auto is_slice_array = meta::is_slice_index_array_v && meta::is_slice_index_array_v; + auto is_index_constant = + meta::is_index_array_v + && meta::is_index_array_v; + auto element_is_integer = + meta::is_integer_v + && meta::is_integer_v; + auto is_slice = + meta::is_slice_index_v + && meta::is_slice_index_v; + auto is_slice_array = + meta::is_slice_index_array_v + && meta::is_slice_index_array_v; + auto is_attribute = + meta::is_attribute_v + && meta::is_attribute_v; return (is_num_or_array && element_is_integer) || is_integer || is_index_constant || is_none || is_ellipsis || is_slice - || is_slice_array; + || is_slice_array + || is_attribute + ; } // constrained(T1,T2) /** @@ -257,7 +266,7 @@ namespace nmtools::utils return (has_value ? isequal(t,*u) : false); } // both are either type - // match left with left, or right with right, then recursively call isclose + // match left with left, or right with right, then recursively call isequal else if constexpr (meta::is_either_v && meta::is_either_v) { // get the left and right types for corresponding either type using tlhs_t = meta::get_either_left_t; @@ -273,7 +282,7 @@ namespace nmtools::utils using tuple_lhs_t = meta::make_tuple_type_t; using tuple_rhs_t = meta::make_tuple_type_t; auto same = false; - // under the hood, recursively call isclose to properly handle view type + // under the hood, recursively call isequal to properly handle view type if (const auto [tptr, uptr] = tuple_lhs_t{get_if(&t), get_if(&u)}; tptr && uptr) same = isequal(*tptr,*uptr); else if (const auto [tptr, uptr] = tuple_rhs_t{get_if(&t),get_if(&u)}; tptr && uptr) @@ -423,6 +432,9 @@ namespace nmtools::utils else if constexpr (meta::is_slice_index_v && meta::is_slice_index_v) { return meta::is_same_v; } + else if constexpr (meta::is_attribute_v && meta::is_attribute_v) { + return t == u; + } // assume both T and U is ndarray else { bool equal = true; @@ -495,7 +507,14 @@ namespace nmtools::utils }); return equal; } + #if 0 + else { + auto isequal_impl = isequal_t{}; + return isequal_impl(t,u); + } + #else else return detail::isequal(t,u); + #endif } // isequal template diff --git a/include/nmtools/utils/isequal/isequal.hpp b/include/nmtools/utils/isequal/isequal.hpp new file mode 100644 index 000000000..efed219b7 --- /dev/null +++ b/include/nmtools/utils/isequal/isequal.hpp @@ -0,0 +1,15 @@ +#ifndef NMTOOLS_UTILS_ISEQUAL_ISEQUAL_HPP +#define NMTOOLS_UTILS_ISEQUAL_ISEQUAL_HPP + +#include "nmtools/meta.hpp" + +namespace nmtools::utils +{ + template + struct isequal_t; + + template + constexpr auto isequal(const lhs_t&, const rhs_t&); +} // namespace nmtools::utils + +#endif // NMTOOLS_UTILS_ISEQUAL_ISEQUAL_HPP \ No newline at end of file diff --git a/include/nmtools/utils/to_string.hpp b/include/nmtools/utils/to_string.hpp index e2f07dc4d..07df0dfea 100644 --- a/include/nmtools/utils/to_string.hpp +++ b/include/nmtools/utils/to_string.hpp @@ -1,490 +1,9 @@ -/** - * @file to_string.hpp - * @author Fahri Ali Rahman (ali.rahman.fahri@gmail.com) - * @brief Contains definition of to_string - * @version 0.1 - * @date 2020-11-17 - * - * @copyright Copyright (c) 2020 - * - */ #ifndef NMTOOLS_UTILS_TO_STRING_HPP #define NMTOOLS_UTILS_TO_STRING_HPP -#if __has_include() - #define HAS_STRING true - #include - #define nmtools_string std::string - // NOTE: quick hack, arduino (esp. atmel avr) doesn't have std::to_string - // TODO: find better alternative - #define nmtools_to_string std::to_string -#elif defined(ARDUINO) - // TODO: do not include arduino here (?) - #include - #define HAS_STRING true - #define nmtools_string String - // NOTE: quick hack - // TODO: find better alternative - #define nmtools_to_string String -#else -#define HAS_STRING false -#endif - -#if __has_include() -#include -#define NMTOOLS_HAS_SSTREAM true -#define nmtools_sstream ::std::stringstream -#else -#define NMTOOLS_HAS_SSTREAM false -#endif - -#if defined(__clang__) - #if __has_feature(cxx_rtti) - #define NMTOOLS_HAS_RTTI - #endif -#elif defined(__GNUG__) - #if defined(__GXX_RTTI) - #define NMTOOLS_HAS_RTTI - #endif -#elif defined(_MSC_VER) - #if defined(_CPPRTTI) - #define NMTOOLS_HAS_RTTI - #endif -#endif - - -#if __has_include() - #include - #define NMTOOLS_TESTING_GET_TYPENAME(type) \ - boost::typeindex::type_id().pretty_name() -#elif defined(NMTOOLS_HAS_RTTI) - #define NMTOOLS_TESTING_GET_TYPENAME(type) \ - typeid(type).name() -#else - #define NMTOOLS_TESTING_GET_TYPENAME(type) "" -#endif - -#if HAS_STRING - -#include "nmtools/meta.hpp" -#include "nmtools/array/utility.hpp" -#include "nmtools/array/shape.hpp" -#include "nmtools/array/index/ndindex.hpp" -#include "nmtools/array/ndarray.hpp" -#include "nmtools/array/utility/apply_at.hpp" -#include "nmtools/array/functional/functor.hpp" - -namespace nmtools::utils -{ - // NOTE: forward declare function here to allow function object to_string_t to - // call the function, - // this is because to_string_t can't deduce template args automatically (no constructor, and operator() cant be static) - // TODO: revisit this and maybe refactor - template - auto to_string(const T& array, formatter_t=formatter_t{}); - - /** - * @brief Quick workaround to remove substring from string - * - * @tparam string - * @param str - * @param substr - * @return auto - */ - template - inline auto remove_string(string& str, const string& substr) - { - // NOTE: quick workaround for checkif if we have full std string features - // maybe not available on arduino - #if (NMTOOLS_HAS_SSTREAM) - auto start_pos = string::npos; - do { - start_pos = str.find(substr); - if (start_pos != string::npos) { - str.erase(start_pos, substr.size()); - } - } while (start_pos != string::npos); - #endif // NMTOOLS_HAS_SSTREAM - } - - struct graphviz_t {}; - - constexpr inline auto Graphviz = graphviz_t {}; -} - -namespace nmtools::utils::impl -{ -template -struct to_string_t; - -} -namespace nmtools::utils -{ - /** - * @brief to_string given array to given stream type. - * - * @tparam stream_t stream type, e.g. std::stringstream, - * @tparam T array-like, 2d, 1d, or scalar - * @param array array to to_string - * @return auto stream with type of stream_t - */ - template - auto to_string(const T& array, formatter_t) - { - constexpr auto to_string = impl::to_string_t{}; - return to_string(array); - } // auto to_string -} // namespace nmtools::utils - -namespace nmtools::utils::impl -{ -template -struct to_string_t -{ - auto operator()(const T& array) const noexcept - { - nmtools_string str; - using ::nmtools::index::ndindex; - - if constexpr (is_ellipsis_v) - str += "..."; - else if constexpr (is_none_v) - str += "None"; - else if constexpr (meta::is_either_v) { - using lhs_t = meta::get_either_left_t; - using rhs_t = meta::get_either_right_t; - // assume get_if(&array) is available for either type - if (auto l_ptr = nmtools::get_if(&array)) { - // NOTE: this call require forward declaration of to_string above - str += to_string(*l_ptr); - } else { - auto r_ptr = nmtools::get_if(&array); - str += to_string(*r_ptr); - } - } - else if constexpr (meta::is_nothing_v) { - str += "Nothing"; - } - else if constexpr (meta::is_maybe_v) { - // for maybe type, - // assume casting to bool checks if the objects contains a value - // which is supported by std::optional - if (static_cast(array)) - str += to_string(*array); - else str += "Nothing"; - } - else if constexpr (meta::is_num_v) { - // allow view type - using type_t = meta::get_element_type_t; - str += nmtools_to_string(static_cast(array)); - } - else if constexpr (meta::is_integral_constant_v) { - str += nmtools_to_string(T::value); - } // is_integral_constant - else if constexpr (meta::is_ndarray_v) { - // TODO: do not use as array - /** - * @brief helper lambda to make sure to return array (instead of tuple) - * this simplify indexing, since tuple must be unrolled (can't use runtime index) - * - */ - auto as_array = [](auto shape_){ - using shape_t = decltype(shape_); - using index_t = meta::get_element_or_common_type_t; - if constexpr (meta::is_constant_index_array_v) { - return meta::to_value_v; - } else if constexpr (meta::is_tuple_v) { - constexpr auto N = meta::len_v; - using array_t = meta::make_array_type_t; - auto array = array_t{}; - meta::template_for([&](auto i){ - at(array,i) = at(shape_,i); - }); - return array; - } else { - return shape_; - } - }; - - auto shape_ = shape(array); - auto s = as_array(shape_); - auto indices = ndindex(s); - - // print empty ndarray - if (!len(indices)) - str = "[]"; - - for (size_t i=0; i<(size_t)len(indices); i++) { - auto idx_ = indices[i]; - auto idx = as_array(idx_); - // TODO: support tuple for apply_at - auto a = apply_at(array, idx); - - // check if we should print open bracket - // only add open bracket up to axis n - // that is equal to zero, starting from last axis - for (int ii=len(idx)-1; ii>=0; ii--) { - if (at(idx,ii)==0) - str += "["; - else break; - } - - str += "\t"; - str += to_string(a); - - int print_comma = 0; - // check if we should print closing bracket - // only add open bracket up to axis n - // that is equal to shape[n]-1, starting from last axis - for (int ii=(int)len(idx)-1; ii>=0; ii--) { - // for simplicity just use int - if ((int)at(idx,ii)==(int)(at(s,ii)-1)) { - str += "]"; - // also count how much newline to be printed - print_comma++; - } - else break; - } - if (print_comma && i - // TODO: remove tuple_size metafunctions - // handle packed type (e.g. tuple), recursively call to_string for each elements - else if constexpr (meta::has_tuple_size_v) { - constexpr auto N = meta::len_v; - str += "("; - meta::template_for([&](auto index){ - constexpr auto i = decltype(index)::value; - const auto& a = nmtools::get(array); - str += to_string(a); - if constexpr (i<(N-1)) - str += ",\t"; - }); - str += ")"; - } - else if constexpr (meta::is_list_v) { - auto dim = len(array); - for (size_t i=0; i<(size_t)dim; i++) { - if (i==0) { - str += "["; - } - str += "\t"; - str += to_string(at(array,i)); - if (i==(size_t)(dim-1)) { - str += "]"; - } - } - } - #if NMTOOLS_HAS_SSTREAM - else if constexpr (meta::is_pointer_v) { - nmtools_sstream ss; - auto type_name = NMTOOLS_TESTING_GET_TYPENAME(T); - ss << "<" << type_name << ">" << "(" << array << ")"; - - str += ss.str(); - } - #endif - return str; - } // operator() -}; // struct to_string_t - -template < - typename buffer_t - , typename shape_buffer_t - , template typename stride_buffer_t - , template typename compute_offset_t -> -struct to_string_t< - array::ndarray_t *, none_t, void -> { - using array_type = array::ndarray_t; - - auto operator()(const array_type* ptr) const noexcept - { - auto ptr_str = nmtools_string(""); - - #if NMTOOLS_HAS_SSTREAM - - nmtools_sstream ss; - auto buffer_name = NMTOOLS_TESTING_GET_TYPENAME(buffer_t); - auto shape_name = NMTOOLS_TESTING_GET_TYPENAME(shape_buffer_t); - ss << "(" << ptr << ")\n" - << " >"; - - ptr_str += ss.str(); - - #endif // NMTOOLS_HAS_SSTREAM - - return ptr_str; - } -}; - -template < - typename buffer_t - , typename shape_buffer_t - , template typename stride_buffer_t - , template typename compute_offset_t -> -struct to_string_t< - const array::ndarray_t *, none_t, void -> : to_string_t *, none_t> {}; - -template -struct to_string_t,none_t,void> -{ - using functor_type = functional::functor_t; - - auto operator()(const functor_type& functor) const noexcept - { - auto fmap_str = NMTOOLS_TESTING_GET_TYPENAME(decltype(functor.fmap)); - - auto attr_str = nmtools_string(""); - attr_str += "[{"; - constexpr auto N = meta::len_v; - meta::template_for([&](auto index){ - attr_str += to_string(nmtools::at(functor.attributes,index)); - if (index < (N-1)) { - attr_str += ","; - } - }); - attr_str += "}]"; - - return fmap_str + attr_str; - } -}; - -template typename tuple, typename...functors_t, typename operands_t> -struct to_string_t< - functional::functor_composition_t,operands_t>, none_t, void -> { - using composition_type = functional::functor_composition_t,operands_t>; - - auto operator()(const composition_type& composition) const noexcept - { - auto composition_str = nmtools_string(""); - constexpr auto N = sizeof...(functors_t); - meta::template_for([&](auto index){ - composition_str += to_string(at(composition.functors,index)); - if (index < (N-1)) { - composition_str += " * "; - } - }); - return composition_str; - } -}; - -template -struct to_string_t< - functional::node_t, none_t, void -> { - using node_type = functional::node_t; - - auto operator()(const node_type& node) const noexcept - { - auto node_str = nmtools_string(""); - node_str += to_string(node.functor); - return node_str; - } -}; - -template -struct to_string_t< - // functional::compute_graph_t, none_t, void - utility::ct_digraph, graphviz_t, void -> { - // using graph_type = functional::compute_graph_t; - using graph_type = utility::ct_digraph; - - auto operator()(const graph_type& graph) const noexcept - { - auto graphviz = nmtools_string("digraph G"); - graphviz += "{"; - - { - auto out_edges = graph.out_edges(); - constexpr auto N = meta::len_v; - meta::template_for([&](auto index){ - auto out_edge = nmtools::at(out_edges,index); - auto src_edge = nmtools::get<0>(out_edge); - auto dst_edge = nmtools::get<1>(out_edge); - - graphviz += to_string(src_edge); - graphviz += " -> "; - graphviz += to_string(dst_edge); - graphviz += "\n"; - }); - } - - { - auto nodes = graph.nodes(); - constexpr auto N = meta::len_v; - meta::template_for([&](auto index){ - auto node_id = nmtools::at(nodes,index); - auto node = graph.nodes(node_id); - - auto node_id_str = to_string(node_id); - graphviz += node_id_str; - graphviz += "["; - graphviz += "label="; - graphviz += "\""; - graphviz += "{id: "; - graphviz += node_id_str; - graphviz += "}\n"; - graphviz += to_string(node); - graphviz += "\""; - graphviz += "]\n"; - }); - } - - graphviz += "}"; - - remove_string(graphviz, nmtools_string("nmtools::")); - remove_string(graphviz, nmtools_string("array::")); - remove_string(graphviz, nmtools_string("std::")); - - return graphviz; - } -}; - -#define NMTOOLS_DTYPE_TO_STRING_CASE(T,type,string) \ -if constexpr (meta::is_same_v) { \ - return nmtools_string(string); \ -} - -template -struct to_string_t< - dtype_t, none_t, void -> -{ - auto operator()(dtype_t) const noexcept - { - NMTOOLS_DTYPE_TO_STRING_CASE(T,float,"float32") - else NMTOOLS_DTYPE_TO_STRING_CASE(T,double,"float64") - else NMTOOLS_DTYPE_TO_STRING_CASE(T,int64_t,"int64") - else NMTOOLS_DTYPE_TO_STRING_CASE(T,int32_t,"int32") - else NMTOOLS_DTYPE_TO_STRING_CASE(T,int16_t,"int16") - else NMTOOLS_DTYPE_TO_STRING_CASE(T,int8_t,"int8") - else NMTOOLS_DTYPE_TO_STRING_CASE(T,uint64_t,"uint64") - else NMTOOLS_DTYPE_TO_STRING_CASE(T,uint32_t,"uint32") - else NMTOOLS_DTYPE_TO_STRING_CASE(T,uint16_t,"uint16") - else NMTOOLS_DTYPE_TO_STRING_CASE(T,uint8_t,"uint8") - else return nmtools_string(""); - } -}; - -#undef NMTOOLS_DTYPE_TO_STRING_CASE - -template -struct to_string_t< - functional::compute_graph_t, graphviz_t, void -> : to_string_t, graphviz_t, void> -{}; - -} -#endif // HAS_STRING +#include "nmtools/utils/to_string/to_string.hpp" +#include "nmtools/utils/to_string/common_types.hpp" +#include "nmtools/utils/to_string/functor.hpp" +#include "nmtools/utils/to_string/ufunc.hpp" #endif // NMTOOLS_UTILS_TO_STRING_HPP \ No newline at end of file diff --git a/include/nmtools/utils/to_string/common_types.hpp b/include/nmtools/utils/to_string/common_types.hpp new file mode 100644 index 000000000..03cda293e --- /dev/null +++ b/include/nmtools/utils/to_string/common_types.hpp @@ -0,0 +1,270 @@ +#ifndef NMTOOLS_UTILS_TO_STRING_COMMON_TYPES_HPP +#define NMTOOLS_UTILS_TO_STRING_COMMON_TYPES_HPP + +#include "nmtools/utils/to_string/to_string.hpp" + +#if NMTOOLS_HAS_STRING + +#include "nmtools/meta.hpp" +#include "nmtools/array/utility.hpp" +#include "nmtools/array/shape.hpp" +#include "nmtools/array/index/ndindex.hpp" +#include "nmtools/array/ndarray.hpp" +#include "nmtools/array/utility/apply_at.hpp" + +namespace nmtools::utils +{ + /** + * @brief Quick workaround to remove substring from string + * + * @tparam string + * @param str + * @param substr + * @return auto + */ + template + inline auto remove_string(string& str, const string& substr) + { + // NOTE: quick workaround for checkif if we have full std string features + // maybe not available on arduino + #if (NMTOOLS_HAS_SSTREAM) + auto start_pos = string::npos; + do { + start_pos = str.find(substr); + if (start_pos != string::npos) { + str.erase(start_pos, substr.size()); + } + } while (start_pos != string::npos); + #endif // NMTOOLS_HAS_SSTREAM + } +} + +namespace nmtools::utils::impl +{ + template < + typename buffer_t + , typename shape_buffer_t + , template typename stride_buffer_t + , template typename compute_offset_t + > + struct to_string_t< + const array::ndarray_t *, none_t, void + > : to_string_t *, none_t> {}; + + template + struct to_string_t + { + auto operator()(const T& array) const noexcept + { + nmtools_string str; + using ::nmtools::index::ndindex; + + if constexpr (is_ellipsis_v) + str += "..."; + else if constexpr (is_none_v) + str += "None"; + else if constexpr (meta::is_either_v) { + using lhs_t = meta::get_either_left_t; + using rhs_t = meta::get_either_right_t; + // assume get_if(&array) is available for either type + if (auto l_ptr = nmtools::get_if(&array)) { + // NOTE: this call require forward declaration of to_string above + str += to_string(*l_ptr); + } else { + auto r_ptr = nmtools::get_if(&array); + str += to_string(*r_ptr); + } + } + else if constexpr (meta::is_nothing_v) { + str += "Nothing"; + } + else if constexpr (meta::is_maybe_v) { + // for maybe type, + // assume casting to bool checks if the objects contains a value + // which is supported by std::optional + if (static_cast(array)) + str += to_string(*array); + else str += "Nothing"; + } + else if constexpr (meta::is_num_v) { + // allow view type + using type_t = meta::get_element_type_t; + str += nmtools_to_string(static_cast(array)); + } + else if constexpr (meta::is_integral_constant_v) { + str += nmtools_to_string(T::value); + } // is_integral_constant + else if constexpr (meta::is_ndarray_v) { + // TODO: do not use as array + /** + * @brief helper lambda to make sure to return array (instead of tuple) + * this simplify indexing, since tuple must be unrolled (can't use runtime index) + * + */ + auto as_array = [](auto shape_){ + using shape_t = decltype(shape_); + using index_t = meta::get_element_or_common_type_t; + if constexpr (meta::is_constant_index_array_v) { + return meta::to_value_v; + } else if constexpr (meta::is_tuple_v) { + constexpr auto N = meta::len_v; + using array_t = meta::make_array_type_t; + auto array = array_t{}; + meta::template_for([&](auto i){ + at(array,i) = at(shape_,i); + }); + return array; + } else { + return shape_; + } + }; + + auto shape_ = shape(array); + auto s = as_array(shape_); + auto indices = ndindex(s); + + // print empty ndarray + if (!len(indices)) + str = "[]"; + + for (size_t i=0; i<(size_t)len(indices); i++) { + auto idx_ = indices[i]; + auto idx = as_array(idx_); + // TODO: support tuple for apply_at + auto a = apply_at(array, idx); + + // check if we should print open bracket + // only add open bracket up to axis n + // that is equal to zero, starting from last axis + for (int ii=len(idx)-1; ii>=0; ii--) { + if (at(idx,ii)==0) + str += "["; + else break; + } + + str += "\t"; + str += to_string(a); + + int print_comma = 0; + // check if we should print closing bracket + // only add open bracket up to axis n + // that is equal to shape[n]-1, starting from last axis + for (int ii=(int)len(idx)-1; ii>=0; ii--) { + // for simplicity just use int + if ((int)at(idx,ii)==(int)(at(s,ii)-1)) { + str += "]"; + // also count how much newline to be printed + print_comma++; + } + else break; + } + if (print_comma && i + // TODO: remove tuple_size metafunctions + // handle packed type (e.g. tuple), recursively call to_string for each elements + else if constexpr (meta::has_tuple_size_v) { + constexpr auto N = meta::len_v; + str += "("; + meta::template_for([&](auto index){ + constexpr auto i = decltype(index)::value; + const auto& a = nmtools::get(array); + str += to_string(a); + if constexpr (i<(N-1)) + str += ",\t"; + }); + str += ")"; + } + else if constexpr (meta::is_list_v) { + auto dim = len(array); + for (size_t i=0; i<(size_t)dim; i++) { + if (i==0) { + str += "["; + } + str += "\t"; + str += to_string(at(array,i)); + if (i==(size_t)(dim-1)) { + str += "]"; + } + } + } + #if NMTOOLS_HAS_SSTREAM + else if constexpr (meta::is_pointer_v) { + nmtools_sstream ss; + auto type_name = NMTOOLS_TYPENAME_TO_STRING(T); + ss << "<" << type_name << ">" << "(" << array << ")"; + + str += ss.str(); + } + #endif + return str; + } // operator() + }; // struct to_string_t + + template < + typename buffer_t + , typename shape_buffer_t + , template typename stride_buffer_t + , template typename compute_offset_t + > + struct to_string_t< + array::ndarray_t *, none_t, void + > { + using array_type = array::ndarray_t; + + auto operator()(const array_type* ptr) const noexcept + { + auto ptr_str = nmtools_string(""); + + #if NMTOOLS_HAS_SSTREAM + + nmtools_sstream ss; + auto buffer_name = NMTOOLS_TYPENAME_TO_STRING(buffer_t); + auto shape_name = NMTOOLS_TYPENAME_TO_STRING(shape_buffer_t); + ss << "(" << ptr << ")\n" + << " >"; + + ptr_str += ss.str(); + + #endif // NMTOOLS_HAS_SSTREAM + + return ptr_str; + } + }; + + #define NMTOOLS_DTYPE_TO_STRING_CASE(T,type,string) \ + if constexpr (meta::is_same_v) { \ + return nmtools_string(string); \ + } + + template + struct to_string_t< + dtype_t, none_t, void + > + { + auto operator()(dtype_t) const noexcept + { + NMTOOLS_DTYPE_TO_STRING_CASE(T,float,"float32") + else NMTOOLS_DTYPE_TO_STRING_CASE(T,double,"float64") + else NMTOOLS_DTYPE_TO_STRING_CASE(T,int64_t,"int64") + else NMTOOLS_DTYPE_TO_STRING_CASE(T,int32_t,"int32") + else NMTOOLS_DTYPE_TO_STRING_CASE(T,int16_t,"int16") + else NMTOOLS_DTYPE_TO_STRING_CASE(T,int8_t,"int8") + else NMTOOLS_DTYPE_TO_STRING_CASE(T,uint64_t,"uint64") + else NMTOOLS_DTYPE_TO_STRING_CASE(T,uint32_t,"uint32") + else NMTOOLS_DTYPE_TO_STRING_CASE(T,uint16_t,"uint16") + else NMTOOLS_DTYPE_TO_STRING_CASE(T,uint8_t,"uint8") + else return nmtools_string(""); + } + }; + + #undef NMTOOLS_DTYPE_TO_STRING_CASE + +} +#endif // NMTOOLS_HAS_STRING + +#endif // NMTOOLS_UTILS_TO_STRING_COMMON_TYPES_HPP \ No newline at end of file diff --git a/include/nmtools/utils/to_string/functor.hpp b/include/nmtools/utils/to_string/functor.hpp new file mode 100644 index 000000000..b3357456f --- /dev/null +++ b/include/nmtools/utils/to_string/functor.hpp @@ -0,0 +1,164 @@ +#ifndef NMTOOLS_UTILS_TO_STRING_FUNCTOR_HPP +#define NMTOOLS_UTILS_TO_STRING_FUNCTOR_HPP + +#include "nmtools/utils/to_string/to_string.hpp" +#include "nmtools/utils/to_string/common_types.hpp" +#include "nmtools/array/functional/functor.hpp" + +#if NMTOOLS_HAS_STRING + +namespace nmtools::utils::impl +{ + template + struct to_string_t< + functional::fmap_t, none_t + > { + using fmap_type = functional::fmap_t; + + auto operator()(const fmap_type& fmap) const noexcept + { + auto fmap_str = to_string(fmap.fn); + + if (fmap_str.empty()) { + fmap_str += NMTOOLS_TYPENAME_TO_STRING(F); + } + + auto str = nmtools_string(""); + + str += "fmap("; + str += fmap_str; + str += ","; + str += to_string(Arity); + str += "_ct)"; + + return str; + } + }; + + template + struct to_string_t,none_t,void> + { + using functor_type = functional::functor_t; + + auto operator()(const functor_type& functor) const noexcept + { + auto fmap_str = to_string(functor.fmap); + + auto attr_str = nmtools_string(""); + attr_str += "[{"; + constexpr auto N = meta::len_v; + meta::template_for([&](auto index){ + attr_str += to_string(nmtools::at(functor.attributes,index)); + if (index < (N-1)) { + attr_str += ","; + } + }); + attr_str += "}]"; + + return fmap_str + attr_str; + } + }; + + template typename tuple, typename...functors_t, typename operands_t> + struct to_string_t< + functional::functor_composition_t,operands_t>, none_t, void + > { + using composition_type = functional::functor_composition_t,operands_t>; + + auto operator()(const composition_type& composition) const noexcept + { + auto composition_str = nmtools_string(""); + constexpr auto N = sizeof...(functors_t); + meta::template_for([&](auto index){ + composition_str += to_string(at(composition.functors,index)); + if (index < (N-1)) { + composition_str += " * "; + } + }); + return composition_str; + } + }; + + template + struct to_string_t< + functional::node_t, none_t, void + > { + using node_type = functional::node_t; + + auto operator()(const node_type& node) const noexcept + { + auto node_str = nmtools_string(""); + node_str += to_string(node.functor); + return node_str; + } + }; + + template + struct to_string_t< + // functional::compute_graph_t, none_t, void + utility::ct_digraph, graphviz_t, void + > { + // using graph_type = functional::compute_graph_t; + using graph_type = utility::ct_digraph; + + auto operator()(const graph_type& graph) const noexcept + { + auto graphviz = nmtools_string("digraph G"); + graphviz += "{"; + + { + auto out_edges = graph.out_edges(); + constexpr auto N = meta::len_v; + meta::template_for([&](auto index){ + auto out_edge = nmtools::at(out_edges,index); + auto src_edge = nmtools::get<0>(out_edge); + auto dst_edge = nmtools::get<1>(out_edge); + + graphviz += to_string(src_edge); + graphviz += " -> "; + graphviz += to_string(dst_edge); + graphviz += "\n"; + }); + } + + { + auto nodes = graph.nodes(); + constexpr auto N = meta::len_v; + meta::template_for([&](auto index){ + auto node_id = nmtools::at(nodes,index); + auto node = graph.nodes(node_id); + + auto node_id_str = to_string(node_id); + graphviz += node_id_str; + graphviz += "["; + graphviz += "label="; + graphviz += "\""; + graphviz += "{id: "; + graphviz += node_id_str; + graphviz += "}\n"; + graphviz += to_string(node); + graphviz += "\""; + graphviz += "]\n"; + }); + } + + graphviz += "}"; + + remove_string(graphviz, nmtools_string("nmtools::")); + remove_string(graphviz, nmtools_string("array::")); + remove_string(graphviz, nmtools_string("std::")); + + return graphviz; + } + }; + + template + struct to_string_t< + functional::compute_graph_t, graphviz_t, void + > : to_string_t, graphviz_t, void> + {}; +} + +#endif // NMTOOLS_HAS_STRING + +#endif // NMTOOLS_UTILS_TO_STRING_FUNCTOR_HPP \ No newline at end of file diff --git a/include/nmtools/utils/to_string/to_string.hpp b/include/nmtools/utils/to_string/to_string.hpp new file mode 100644 index 000000000..c2483557c --- /dev/null +++ b/include/nmtools/utils/to_string/to_string.hpp @@ -0,0 +1,104 @@ +#ifndef NMTOOLS_UTILS_TO_STRING_TO_STRING_HPP +#define NMTOOLS_UTILS_TO_STRING_TO_STRING_HPP + +#if __has_include() + #define NMTOOLS_HAS_STRING true + #include + #define nmtools_string std::string + // NOTE: quick hack, arduino (esp. atmel avr) doesn't have std::to_string + // TODO: find better alternative + #define nmtools_to_string std::to_string +#elif defined(ARDUINO) + // TODO: do not include arduino here (?) + #include + #define NMTOOLS_HAS_STRING true + #define nmtools_string String + // NOTE: quick hack + // TODO: find better alternative + #define nmtools_to_string String +#else +#define NMTOOLS_HAS_STRING false +#endif + +// TODO: remove this HAS_STRING macro, prefer NMTOOLS_HAS_STRING +#define HAS_STRING NMTOOLS_HAS_STRING + +#if __has_include() +#include +#define NMTOOLS_HAS_SSTREAM true +#define nmtools_sstream ::std::stringstream +#else +#define NMTOOLS_HAS_SSTREAM false +#endif + +#if defined(__clang__) + #if __has_feature(cxx_rtti) + #define NMTOOLS_HAS_RTTI + #endif +#elif defined(__GNUG__) + #if defined(__GXX_RTTI) + #define NMTOOLS_HAS_RTTI + #endif +#elif defined(_MSC_VER) + #if defined(_CPPRTTI) + #define NMTOOLS_HAS_RTTI + #endif +#endif + + +#if __has_include() + #include + #define NMTOOLS_TYPENAME_TO_STRING(type) \ + boost::typeindex::type_id().pretty_name() +#elif defined(NMTOOLS_HAS_RTTI) + #define NMTOOLS_TYPENAME_TO_STRING(type) \ + typeid(type).name() +#else + #define NMTOOLS_TYPENAME_TO_STRING(type) "" +#endif + +#include "nmtools/meta.hpp" + +#if NMTOOLS_HAS_STRING +namespace nmtools::utils +{ + #if 0 + // NOTE: forward declare function here to allow function object to_string_t to + // call the function, + // this is because to_string_t can't deduce template args automatically (no constructor, and operator() cant be static) + // TODO: revisit this and maybe refactor + template + auto to_string(const T& array, formatter_t=formatter_t{}) -> nmtools_string; + #endif + + struct graphviz_t {}; + + constexpr inline auto Graphviz = graphviz_t {}; +} + +namespace nmtools::utils::impl +{ + template + struct to_string_t; +} + +namespace nmtools::utils +{ + /** + * @brief to_string given array to given stream type. + * + * @tparam stream_t stream type, e.g. std::stringstream, + * @tparam T array-like, 2d, 1d, or scalar + * @param array array to to_string + * @return auto stream with type of stream_t + */ + template + auto to_string(const T& array, formatter_t=formatter_t{}) -> nmtools_string + { + constexpr auto to_string_impl = impl::to_string_t{}; + return to_string_impl(array); + } // auto to_string +} // namespace nmtools::utils +#endif // NMTOOLS_HAS_STRING + +#endif // NMTOOLS_UTILS_TO_STRING_TO_STRING_HPP \ No newline at end of file diff --git a/include/nmtools/utils/to_string/ufunc.hpp b/include/nmtools/utils/to_string/ufunc.hpp new file mode 100644 index 000000000..09f878e38 --- /dev/null +++ b/include/nmtools/utils/to_string/ufunc.hpp @@ -0,0 +1,141 @@ +#ifndef NMTOOLS_UTILS_TO_STRING_UFUNC_HPP +#define NMTOOLS_UTILS_TO_STRING_UFUNC_HPP + +#include "nmtools/array/view/ufunc/ufunc.hpp" +#include "nmtools/array/view/ufunc/outer.hpp" +#include "nmtools/array/view/ufunc/reduce.hpp" +#include "nmtools/array/view/ufunc/accumulate.hpp" + +namespace nmtools::utils::impl +{ + template + struct to_string_t< + args::ufunc, none_t, void + > + { + using attribute_type = args::ufunc; + + auto operator()([[maybe_unused]] const attribute_type& attribute) const noexcept + { + nmtools_string str; + + auto op_str = to_string(attribute.op); + if (op_str.empty()) { + op_str = NMTOOLS_TYPENAME_TO_STRING(op_t); + } + + str += "{"; + + str += ".op="; + str += op_str; + + str += "}"; + + return str; + } + }; + + template + struct to_string_t< + args::reduce, none_t, void + > + { + using attribute_type = args::reduce; + + auto operator()(const attribute_type& attribute) const noexcept + { + nmtools_string str; + + auto op_str = to_string(attribute.op); + if (op_str.empty()) { + op_str = NMTOOLS_TYPENAME_TO_STRING(op_t); + } + + str += "{"; + + str += ".op="; + str += op_str; + str += ",.axis="; + str += to_string(attribute.axis); + str += ",.dtype="; + str += to_string(attribute.dtype); + str += ",.initial="; + str += to_string(attribute.initial); + str += ",.keepdims="; + str += to_string(attribute.keepdims); + + str += "}"; + + return str; + } + }; + + template + struct to_string_t< + args::outer, none_t, void + > + { + using attribute_type = args::outer; + + auto operator()(const attribute_type& attribute) const noexcept + { + nmtools_string str; + + auto op_str = to_string(attribute.op); + if (op_str.empty()) { + op_str = NMTOOLS_TYPENAME_TO_STRING(op_t); + } + + str += "{"; + + str += ".op="; + str += op_str; + str += ",.dtype="; + str += to_string(attribute.dtype); + + str += "}"; + + return str; + } + }; + + template + struct to_string_t< + args::accumulate, none_t, void + > + { + using attribute_type = args::accumulate; + + auto operator()(const attribute_type& attribute) const noexcept + { + nmtools_string str; + + auto op_str = to_string(attribute.op); + if (op_str.empty()) { + op_str = NMTOOLS_TYPENAME_TO_STRING(op_t); + } + + str += "{"; + + str += ".op="; + str += op_str; + str += ",.axis="; + str += to_string(attribute.axis); + str += ",.dtype="; + str += to_string(attribute.dtype); + + str += "}"; + + return str; + } + }; +} + +#endif // NMTOOLS_UTILS_TO_STRING_UFUNC_HPP \ No newline at end of file diff --git a/scripts/install_llvm_spirv.sh b/scripts/install_llvm_spirv.sh index 68ca10934..1a432a86e 100644 --- a/scripts/install_llvm_spirv.sh +++ b/scripts/install_llvm_spirv.sh @@ -1,14 +1,14 @@ #!/bin/bash if [[ -z "${LLVM_VERSION}" ]]; then - LLVM_VERSION="15" + LLVM_VERSION="14" else LLVM_VERSION="${LLVM_VERSION}" echo "set LLVM_VERSION from env: ${LLVM_VERSION}" fi if [[ -z "${LLVM_SPV_VERSION}" ]]; then - LLVM_SPV_VERSION="v15.0.0" + LLVM_SPV_VERSION="v14.0.0" else LLVM_SPV_VERSION="${LLVM_SPV_VERSION}" echo "set LLVM_SPV_VERSION from env: ${LLVM_SPV_VERSION}" diff --git a/scripts/install_opensycl.sh b/scripts/install_opensycl.sh index ae066bae4..b0813a80c 100644 --- a/scripts/install_opensycl.sh +++ b/scripts/install_opensycl.sh @@ -1,11 +1,59 @@ #!/usr/bin/bash +if [[ -z "${LLVM_VERSION}" ]]; then + LLVM_VERSION="14" +else + LLVM_VERSION="${LLVM_VERSION}" + echo "set LLVM_VERSION from env" +fi + +if [[ -z "${ACCELERATED_CPU}" ]]; then + ACCELERATED_CPU="ON" +else + ACCELERATED_CPU="${ACCELERATED_CPU}" + echo "set ACCELERATED_CPU from env" +fi + +if [[ -z "${OPENCL_BACKEND}" ]]; then + OPENCL_BACKEND="OFF" +else + OPENCL_BACKEND="${OPENCL_BACKEND}" + echo "set OPENCL_BACKEND from env" +fi + +if [[ -z "${CUDA_BACKEND}" ]]; then + CUDA_BACKEND="OFF" +else + CUDA_BACKEND="${CUDA_BACKEND}" + echo "set CUDA_BACKEND from env" +fi + +if [[ -z "${LEVEL_ZERO_BACKEND}" ]]; then + LEVEL_ZERO_BACKEND="OFF" +else + LEVEL_ZERO_BACKEND="${LEVEL_ZERO_BACKEND}" + echo "set LEVEL_ZERO_BACKEND from env" +fi + +if [[ -z "${BUILD_TYPE}" ]]; then + BUILD_TYPE="Release" +else + BUILD_TYPE="${BUILD_TYPE}" + echo "set BUILD_TYPE from env" +fi + +echo "using LLVM_VERSION=${LLVM_VERSION}" +echo "using ACCELERATED_CPU=${ACCELERATED_CPU}" +echo "using OPENCL_BACKEND=${OPENCL_BACKEND}" +echo "using CUDA_BACKEND=${CUDA_BACKEND}" + DIR=OpenSYCL GIT_REPOSITORY=https://github.com/OpenSYCL/OpenSYCL # VERSION=v0.9.4 # DIR=AdaptiveCpp # GIT_REPOSITORY=https://github.com/AdaptiveCpp/AdaptiveCpp.git VERSION=v23.10.0 + if [[ -d "$DIR" ]]; then echo "$DIR exists. skipping cloning" else @@ -19,9 +67,12 @@ mkdir -p build cd build cmake \ - -DLLVM_DIR=/usr/lib/llvm-14/cmake \ - -DWITH_ACCELERATED_CPU=ON \ - -DCMAKE_BUILD_TYPE=Release \ + -DLLVM_DIR=/usr/lib/llvm-${LLVM_VERSION}/cmake \ + -DWITH_ACCELERATED_CPU=${ACCELERATED_CPU} \ + -DWITH_OPENCL_BACKEND=${OPENCL_BACKEND} \ + -DWITH_CUDA_BACKEND=${CUDA_BACKEND} \ + -DWITH_LEVEL_ZERO_BACKEND=${LEVEL_ZERO_BACKEND} \ + -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \ .. make -j2 VERBOSE=1 make install \ No newline at end of file diff --git a/scripts/install_pocl.sh b/scripts/install_pocl.sh index 377d7183b..9ddd81ecb 100644 --- a/scripts/install_pocl.sh +++ b/scripts/install_pocl.sh @@ -1,7 +1,7 @@ #!/bin/bash if [[ -z "${LLVM_VERSION}" ]]; then - LLVM_VERSION="15" + LLVM_VERSION="14" else LLVM_VERSION="${LLVM_VERSION}" echo "set LLVM_VERSION from env" @@ -42,5 +42,10 @@ apt install -y xxd python3-dev libpython3-dev build-essential ocl-icd-libopencl1 cd ${DIR} git fetch && git checkout ${POCL_VERSION} -mkdir -p build && cd build && cmake -DCMAKE_BUILD_TYPE=${POCL_BUILD_TYPE} -DENABLE_TESTS=OFF -DENABLE_CUDA=OFF -DSPIRV=ON -DLLVM_SPIRV=/usr/local/bin/llvm-spirv -DCMAKE_INSTALL_PREFIX=/usr .. \ +mkdir -p build && cd build \ + && cmake -DCMAKE_BUILD_TYPE=${POCL_BUILD_TYPE} \ + -DENABLE_TESTS=OFF \ + -DENABLE_CUDA=OFF \ + -DSPIRV=ON -DLLVM_SPIRV=/usr/local/bin/llvm-spirv \ + -DCMAKE_INSTALL_PREFIX=/usr .. \ && make -j2 && make install \ No newline at end of file diff --git a/tests/cuda/CMakeLists.txt b/tests/cuda/CMakeLists.txt index 2273ffd46..a3c479848 100644 --- a/tests/cuda/CMakeLists.txt +++ b/tests/cuda/CMakeLists.txt @@ -122,6 +122,7 @@ set(NMTOOLS_CUDA_TEST_SOURCES ${NMTOOLS_CUDA_TEST_SOURCES} array/cumprod.cpp array/mean.cpp + composition/add_tanh.cpp # composition/mean_subtract.cpp # composition/reduce_add_divide.cpp ) diff --git a/tests/cuda/composition/add_tanh.cpp b/tests/cuda/composition/add_tanh.cpp new file mode 100644 index 000000000..d659c9310 --- /dev/null +++ b/tests/cuda/composition/add_tanh.cpp @@ -0,0 +1,40 @@ +#include "nmtools/array/array/ufuncs/add.hpp" +#include "nmtools/array/array/ufuncs/tanh.hpp" +#include "nmtools/array/array/arange.hpp" +#include "nmtools/array/array/reshape.hpp" +#include "nmtools/array/eval/cuda.hpp" +#include "nmtools/testing/doctest.hpp" +#include "nmtools/testing/data/array/arange.hpp" +#include "nmtools/array/functional/ufuncs/add.hpp" +#include "nmtools/array/functional/ufuncs/tanh.hpp" + +namespace nm = nmtools; +namespace na = nmtools::array; +namespace ix = nmtools::index; +namespace fn = nmtools::functional; +namespace view = nm::view; + +#define CUDA_SUBCASE(...) \ +{ \ + auto result = na::eval(__VA_ARGS__, na::cuda::default_context()); \ + auto expect = na::eval(__VA_ARGS__); \ + NMTOOLS_ASSERT_EQUAL( nm::shape(result), nm::shape(expect) ); \ + NMTOOLS_ASSERT_CLOSE( result, expect ); \ +} + +TEST_CASE("add_tanh(case1)" * doctest::test_suite("array::add_tanh")) +{ + auto a_shape = nmtools_array{128}; + auto a_numel = ix::product(a_shape); + auto a_start = 0; + auto a_stop = a_start + a_numel; + auto a_step = 1; + auto a_flat = na::arange(a_start,a_stop,a_step); + + auto a = na::reshape(a_flat,a_shape); + + auto x = view::add(a,0.5f); + auto y = view::tanh(x); + + CUDA_SUBCASE( y ); +} \ No newline at end of file diff --git a/tests/functional/CMakeLists.txt b/tests/functional/CMakeLists.txt index 5a9f52397..f9ce229c8 100644 --- a/tests/functional/CMakeLists.txt +++ b/tests/functional/CMakeLists.txt @@ -170,7 +170,13 @@ add_executable(${PROJECT_NAME}-doctest tests.cpp ${FUNCTIONAL_TEST_SOURCES} ) -target_compile_features(${PROJECT_NAME}-doctest PRIVATE cxx_std_17) +option( NMTOOLS_KWARGS_INIT "enable kwargs tests using designated initializers (c++20)" OFF) +if (NMTOOLS_KWARGS_INIT) + target_compile_features(${PROJECT_NAME}-doctest PRIVATE cxx_std_20) + target_compile_definitions( ${PROJECT_NAME}-doctest PRIVATE NMTOOLS_TESTING_KWARGS_INIT ) +else () + target_compile_features(${PROJECT_NAME}-doctest PRIVATE cxx_std_17) +endif () if (doctest_FOUND) target_link_libraries(${PROJECT_NAME}-doctest PRIVATE doctest::doctest) endif() @@ -186,4 +192,8 @@ target_include_directories( if (NMTOOLS_CODE_COVERAGE) target_link_libraries(numeric-tests-doctest PUBLIC coverage_config) -endif (NMTOOLS_CODE_COVERAGE) \ No newline at end of file +endif (NMTOOLS_CODE_COVERAGE) +target_compile_definitions(${PROJECT_NAME}-doctest PRIVATE + # NMTOOLS_ISCLOSE_NAN_HANDLING=1 + NMTOOLS_ISCLOSE_INF_HANDLING=1 +) \ No newline at end of file diff --git a/tests/functional/src/activations/celu.cpp b/tests/functional/src/activations/celu.cpp index 1c72a858e..23baf03d2 100644 --- a/tests/functional/src/activations/celu.cpp +++ b/tests/functional/src/activations/celu.cpp @@ -50,4 +50,52 @@ TEST_CASE("celu" * doctest::test_suite("functional::get_function_composition")) auto expect = fn::celu[alpha]; NMTOOLS_ASSERT_EQUAL( function, expect ); -} \ No newline at end of file + NMTOOLS_ASSERT_CLOSE( function (a), array ); +} + +TEST_CASE("celu" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(activations,celu,case2); + using namespace args; + + auto array = view::celu(a,alpha); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + + NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); +} + +namespace kwargs = nmtools::args; +namespace fun = view::fun; + +#ifdef NMTOOLS_TESTING_KWARGS_INIT +#ifndef __clang__ + +TEST_CASE("celu" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(activations,celu,case2); + using namespace args; + + auto array = view::celu(a,{.alpha=alpha}); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[kwargs::ufunc{ + .op=fun::celu{.alpha=alpha} + }]; + // TODO: make the following expression accepted + // auto expect = fn::unary_ufunc[{ + // .op=fun::celu{.alpha=alpha} + // }]; + + // NOTE: the following should be invalid, but current functors is very permissive + // auto expect = fn::celu[fun::celu{.alpha=alpha}]; + + NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); + NMTOOLS_ASSERT_CLOSE( expect (a), array ); +} + +#endif // __clang__ +#endif // NMTOOLS_TESTING_KWARGS_INIT \ No newline at end of file diff --git a/tests/functional/src/activations/elu.cpp b/tests/functional/src/activations/elu.cpp index f413baf13..9b12bbcbd 100644 --- a/tests/functional/src/activations/elu.cpp +++ b/tests/functional/src/activations/elu.cpp @@ -39,6 +39,24 @@ TEST_CASE("elu(case2)" * doctest::test_suite("functional::elu")) namespace view = nmtools::view; +namespace kwargs = nmtools::args; +namespace fun = view::fun; + +TEST_CASE("elu" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(activations,elu,case2); + using namespace args; + + auto array = view::elu(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::elu; + + NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); + NMTOOLS_ASSERT_CLOSE( expect (a), array ); +} + TEST_CASE("elu" * doctest::test_suite("functional::get_function_composition")) { NMTOOLS_TESTING_DECLARE_NS(activations,elu,case2); @@ -50,4 +68,103 @@ TEST_CASE("elu" * doctest::test_suite("functional::get_function_composition")) auto expect = fn::elu[alpha]; NMTOOLS_ASSERT_EQUAL( function, expect ); -} \ No newline at end of file + NMTOOLS_ASSERT_CLOSE( function (a), array ); + NMTOOLS_ASSERT_CLOSE( expect (a), array ); +} + +TEST_CASE("elu" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(activations,elu,case2); + using namespace args; + + auto array = view::elu(a,alpha); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + + NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); + NMTOOLS_ASSERT_CLOSE( expect (a), array ); +} + +#ifdef NMTOOLS_TESTING_KWARGS_INIT +#ifndef __clang__ + +TEST_CASE("elu" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(activations,elu,case2); + using namespace args; + + auto array = view::elu(a,{.alpha=alpha}); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[kwargs::ufunc{ + .op=fun::elu{.alpha=alpha} + }]; + + NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); + NMTOOLS_ASSERT_CLOSE( expect (a), array ); + + NMTOOLS_ASSERT_NOT_EQUAL( fn::elu[1.f], fn::elu[0.1f] ); + NMTOOLS_ASSERT_NOT_EQUAL( fn::unary_ufunc[kwargs::ufunc{fun::elu{1.f}}], fn::elu[0.1f] ); + NMTOOLS_ASSERT_NOT_EQUAL( fn::elu[0.1f], fn::unary_ufunc[kwargs::ufunc{fun::elu{1.f}}] ); + NMTOOLS_ASSERT_NOT_EQUAL( fn::elu, fn::unary_ufunc[kwargs::ufunc{fun::elu{0.1f}}] ); + + NMTOOLS_ASSERT_EQUAL( fn::elu, fn::unary_ufunc[kwargs::ufunc{fun::elu{}}] ); + NMTOOLS_ASSERT_EQUAL( fn::elu[0.1f], fn::unary_ufunc[kwargs::ufunc{fun::elu{}}][0.1f] ); + // NMTOOLS_ASSERT_EQUAL( fn::elu, fn::unary_ufunc[kwargs::ufunc{}][fun::elu{}] ); +} + +TEST_CASE("elu" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(activations,elu,case2); + using namespace args; + + auto array = view::elu(a,{.alpha=0.1f}); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[kwargs::ufunc{ + .op=fun::elu{.alpha=0.1f} + }]; + + NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); + NMTOOLS_ASSERT_CLOSE( expect (a), array ); +} + +TEST_CASE("elu" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(activations,elu,case2); + using namespace args; + + auto array = view::elu(a,{.alpha=0.1f}); + + auto function = fn::get_function_composition(array); + auto expect = fn::elu[0.1f]; + // auto expect = fn::elu[kwargs::ufunc{ + // .op=fun::elu{.alpha=0.1f} + // }]; + + NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); + NMTOOLS_ASSERT_CLOSE( expect (a), array ); +} + +TEST_CASE("elu" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(activations,elu,case2); + using namespace args; + + auto array = view::elu(a,{.alpha=0.1f}); + + auto function = fn::get_function_composition(array); + auto expect = fn::elu[0.1f]; + + NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); + NMTOOLS_ASSERT_CLOSE( expect (a), array ); +} + +#endif // __clang__ +#endif // NMTOOLS_TESTING_KWARGS_INIT \ No newline at end of file diff --git a/tests/functional/src/activations/hardshrink.cpp b/tests/functional/src/activations/hardshrink.cpp index f5033570f..372d50990 100644 --- a/tests/functional/src/activations/hardshrink.cpp +++ b/tests/functional/src/activations/hardshrink.cpp @@ -50,4 +50,50 @@ TEST_CASE("hardshrink" * doctest::test_suite("functional::get_function_compositi auto expect = fn::hardshrink[lambda]; NMTOOLS_ASSERT_EQUAL( function, expect ); -} \ No newline at end of file + NMTOOLS_ASSERT_CLOSE( function (a), array ); +} + +TEST_CASE("hardshrink" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(activations,hardshrink,case2); + using namespace args; + + auto array = view::hardshrink(a,lambda); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + + NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); +} + +namespace kwargs = nmtools::args; +namespace fun = view::fun; + + + +#ifdef NMTOOLS_TESTING_KWARGS_INIT +#ifndef __clang__ + +TEST_CASE("hardshrink" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(activations,hardshrink,case2); + using namespace args; + + auto array = view::hardshrink(a,{.lambda=lambda}); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[kwargs::ufunc{ + .op=fun::hardshrink{.lambda=lambda} + }]; + // TODO: make the following expression accepted + // auto expect = fn::unary_ufunc[{ + // .op=fun::hardshrink{.lambda=lambda} + // }]; + + NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); +} + +#endif // __clang__ +#endif // NMTOOLS_TESTING_KWARGS_INIT \ No newline at end of file diff --git a/tests/functional/src/activations/hardswish.cpp b/tests/functional/src/activations/hardswish.cpp index bb4e6c954..267af3a4d 100644 --- a/tests/functional/src/activations/hardswish.cpp +++ b/tests/functional/src/activations/hardswish.cpp @@ -38,4 +38,19 @@ TEST_CASE("hardswish" * doctest::test_suite("functional::get_function_compositio auto expect = fn::hardswish; NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); +} + +TEST_CASE("hardswish" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(activations,hardswish,case1); + using namespace args; + + auto array = view::hardswish(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + + NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); } \ No newline at end of file diff --git a/tests/functional/src/activations/hardtanh.cpp b/tests/functional/src/activations/hardtanh.cpp index 99262c6f6..58296b113 100644 --- a/tests/functional/src/activations/hardtanh.cpp +++ b/tests/functional/src/activations/hardtanh.cpp @@ -38,4 +38,44 @@ TEST_CASE("hardtanh" * doctest::test_suite("functional::get_function_composition auto expect = fn::hardtanh[-1.][1.]; NMTOOLS_ASSERT_EQUAL( function, expect ); -} \ No newline at end of file + NMTOOLS_ASSERT_CLOSE( function (a), array ); +} + +TEST_CASE("hardtanh" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(activations,hardtanh,case1); + using namespace args; + + auto array = view::hardtanh(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + + NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); +} + +namespace kwargs = nmtools::args; +namespace fun = view::fun; + + + +#ifdef NMTOOLS_TESTING_KWARGS_INIT +#ifndef __clang__ + +TEST_CASE("hardtanh" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(activations,hardtanh,case1); + using namespace args; + + auto array = view::hardtanh(a,{.min_val=-1.,.max_val=1.}); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + + NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); +} + +#endif +#endif \ No newline at end of file diff --git a/tests/functional/src/activations/leaky_relu.cpp b/tests/functional/src/activations/leaky_relu.cpp index f8b41b6c3..7ae8657b0 100644 --- a/tests/functional/src/activations/leaky_relu.cpp +++ b/tests/functional/src/activations/leaky_relu.cpp @@ -38,4 +38,44 @@ TEST_CASE("leaky_relu" * doctest::test_suite("functional::get_function_compositi auto expect = fn::leaky_relu[0.01]; NMTOOLS_ASSERT_EQUAL( function, expect ); -} \ No newline at end of file + NMTOOLS_ASSERT_CLOSE( function (a), array ); +} + +TEST_CASE("leaky_relu" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(activations,leaky_relu,case1); + using namespace args; + + auto array = view::leaky_relu(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + + NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); +} + +namespace kwargs = nmtools::args; +namespace fun = view::fun; + + + +#ifdef NMTOOLS_TESTING_KWARGS_INIT +#ifndef __clang__ + +TEST_CASE("leaky_relu" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(activations,leaky_relu,case1); + using namespace args; + + auto array = view::leaky_relu(a,{.negative_slope=0.01}); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + + NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); +} + +#endif +#endif \ No newline at end of file diff --git a/tests/functional/src/activations/log_sigmoid.cpp b/tests/functional/src/activations/log_sigmoid.cpp index 1d75a2074..6794fb457 100644 --- a/tests/functional/src/activations/log_sigmoid.cpp +++ b/tests/functional/src/activations/log_sigmoid.cpp @@ -38,4 +38,19 @@ TEST_CASE("log_sigmoid" * doctest::test_suite("functional::get_function_composit auto expect = fn::log_sigmoid; NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); +} + +TEST_CASE("log_sigmoid" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(activations,log_sigmoid,case1); + using namespace args; + + auto array = view::log_sigmoid(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + + NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); } \ No newline at end of file diff --git a/tests/functional/src/activations/mish.cpp b/tests/functional/src/activations/mish.cpp index 9c541ec3f..f7eb75a90 100644 --- a/tests/functional/src/activations/mish.cpp +++ b/tests/functional/src/activations/mish.cpp @@ -38,4 +38,19 @@ TEST_CASE("mish" * doctest::test_suite("functional::get_function_composition")) auto expect = fn::mish; NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); +} + +TEST_CASE("mish" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(activations,mish,case1); + using namespace args; + + auto array = view::mish(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + + NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); } \ No newline at end of file diff --git a/tests/functional/src/activations/prelu.cpp b/tests/functional/src/activations/prelu.cpp index ed9c4a3d9..867a59791 100644 --- a/tests/functional/src/activations/prelu.cpp +++ b/tests/functional/src/activations/prelu.cpp @@ -38,4 +38,44 @@ TEST_CASE("prelu" * doctest::test_suite("functional::get_function_composition")) auto expect = fn::prelu[0.25]; NMTOOLS_ASSERT_EQUAL( function, expect ); -} \ No newline at end of file + NMTOOLS_ASSERT_CLOSE( function (a), array ); +} + +TEST_CASE("prelu" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(activations,prelu,case1); + using namespace args; + + auto array = view::prelu(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + + NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); +} + +namespace kwargs = nmtools::args; +namespace fun = view::fun; + + + +#ifdef NMTOOLS_TESTING_KWARGS_INIT +#ifndef __clang__ + +TEST_CASE("prelu" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(activations,prelu,case1); + using namespace args; + + auto array = view::prelu(a,{.alpha=0.25}); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + + NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); +} + +#endif +#endif \ No newline at end of file diff --git a/tests/functional/src/activations/relu.cpp b/tests/functional/src/activations/relu.cpp index 6bdcc05b3..c267bdf72 100644 --- a/tests/functional/src/activations/relu.cpp +++ b/tests/functional/src/activations/relu.cpp @@ -38,4 +38,19 @@ TEST_CASE("relu" * doctest::test_suite("functional::get_function_composition")) auto expect = fn::relu; NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); +} + +TEST_CASE("relu" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(activations,relu,case1); + using namespace args; + + auto array = view::relu(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + + NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); } \ No newline at end of file diff --git a/tests/functional/src/activations/relu6.cpp b/tests/functional/src/activations/relu6.cpp index 169ad5fa4..fe801414c 100644 --- a/tests/functional/src/activations/relu6.cpp +++ b/tests/functional/src/activations/relu6.cpp @@ -39,4 +39,19 @@ TEST_CASE("relu6" * doctest::test_suite("functional::get_function_composition")) auto expect = fn::relu6; NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); +} + +TEST_CASE("relu6" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(activations,relu6,case1); + using namespace args; + + auto array = view::relu6(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + + NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); } \ No newline at end of file diff --git a/tests/functional/src/activations/selu.cpp b/tests/functional/src/activations/selu.cpp index 8068d5689..c1b495a8a 100644 --- a/tests/functional/src/activations/selu.cpp +++ b/tests/functional/src/activations/selu.cpp @@ -38,4 +38,19 @@ TEST_CASE("selu" * doctest::test_suite("functional::get_function_composition")) auto expect = fn::selu; NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); +} + +TEST_CASE("selu" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(activations,selu,case1); + using namespace args; + + auto array = view::selu(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + + NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); } \ No newline at end of file diff --git a/tests/functional/src/activations/sigmoid.cpp b/tests/functional/src/activations/sigmoid.cpp index 74080ea98..5a6add9ec 100644 --- a/tests/functional/src/activations/sigmoid.cpp +++ b/tests/functional/src/activations/sigmoid.cpp @@ -38,4 +38,19 @@ TEST_CASE("sigmoid" * doctest::test_suite("functional::get_function_composition" auto expect = fn::sigmoid; NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); +} + +TEST_CASE("sigmoid" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(activations,sigmoid,case1); + using namespace args; + + auto array = view::sigmoid(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + + NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); } \ No newline at end of file diff --git a/tests/functional/src/activations/silu.cpp b/tests/functional/src/activations/silu.cpp index 11f5c0325..30fc11519 100644 --- a/tests/functional/src/activations/silu.cpp +++ b/tests/functional/src/activations/silu.cpp @@ -38,4 +38,19 @@ TEST_CASE("silu" * doctest::test_suite("functional::get_function_composition")) auto expect = fn::silu; NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); +} + +TEST_CASE("silu" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(activations,silu,case1); + using namespace args; + + auto array = view::silu(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + + NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); } \ No newline at end of file diff --git a/tests/functional/src/activations/softplus.cpp b/tests/functional/src/activations/softplus.cpp index efff10c07..c6c1b2b14 100644 --- a/tests/functional/src/activations/softplus.cpp +++ b/tests/functional/src/activations/softplus.cpp @@ -35,7 +35,48 @@ TEST_CASE("softplus" * doctest::test_suite("functional::get_function_composition auto array = view::softplus(a); auto function = fn::get_function_composition(array); + // TODO: make comparison fn::unary_ufunc[fun::softplus()][...] == fn::softplus[...] auto expect = fn::softplus[1.][20.]; NMTOOLS_ASSERT_EQUAL( function, expect ); -} \ No newline at end of file + NMTOOLS_ASSERT_CLOSE( function (a), array ); +} + +TEST_CASE("softplus" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(activations,softplus,case1); + using namespace args; + + auto array = view::softplus(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + + NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); +} + +namespace kwargs = nmtools::args; +namespace fun = view::fun; + + + +#ifdef NMTOOLS_TESTING_KWARGS_INIT +#ifndef __clang__ + +TEST_CASE("softplus" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(activations,softplus,case1); + using namespace args; + + auto array = view::softplus(a,{.beta=1.,.threshold=20.}); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + + NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); +} + +#endif +#endif \ No newline at end of file diff --git a/tests/functional/src/activations/softshrink.cpp b/tests/functional/src/activations/softshrink.cpp index f905221fa..eb968727c 100644 --- a/tests/functional/src/activations/softshrink.cpp +++ b/tests/functional/src/activations/softshrink.cpp @@ -38,4 +38,54 @@ TEST_CASE("softshrink" * doctest::test_suite("functional::get_function_compositi auto expect = fn::softshrink[0.5]; NMTOOLS_ASSERT_EQUAL( function, expect ); -} \ No newline at end of file + NMTOOLS_ASSERT_CLOSE( function (a), array ); +} + +TEST_CASE("softshrink" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(activations,softshrink,case1); + using namespace args; + + auto array = view::softshrink(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + + NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); +} + +namespace kwargs = nmtools::args; +namespace fun = view::fun; + + + +#ifdef NMTOOLS_TESTING_KWARGS_INIT +#ifndef __clang__ + +TEST_CASE("softshrink" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(activations,softshrink,case1); + using namespace args; + + // NOTE: the following lambda deduced as double + // auto array = view::softshrink(a,fun::softshrink{.lambda=double(0.5)}); + // NOTE: while the following lambda deduced as float + // auto array = view::softshrink(a,{.lambda=double(0.5)}); + auto array = view::softshrink(a,{.lambda=0.5}); + + auto function = fn::get_function_composition(array); + // auto expect = fn::unary_ufunc[array.attributes()]; + auto expect = fn::unary_ufunc[kwargs::ufunc{ + .op=fun::softshrink{.lambda=0.5} + }]; + + // static_assert( std::is_same_v ); + static_assert( std::is_same_v ); + + NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); +} + +#endif // __clang__ +#endif // NMTOOLS_TESTING_KWARGS_INIT \ No newline at end of file diff --git a/tests/functional/src/activations/softsign.cpp b/tests/functional/src/activations/softsign.cpp index 8ffa7a218..5082473fd 100644 --- a/tests/functional/src/activations/softsign.cpp +++ b/tests/functional/src/activations/softsign.cpp @@ -38,4 +38,19 @@ TEST_CASE("softsign" * doctest::test_suite("functional::get_function_composition auto expect = fn::softsign; NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); +} + +TEST_CASE("softsign" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(activations,softsign,case1); + using namespace args; + + auto array = view::softsign(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + + NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); } \ No newline at end of file diff --git a/tests/functional/src/activations/tanhshrink.cpp b/tests/functional/src/activations/tanhshrink.cpp index d83fcae31..f571b2162 100644 --- a/tests/functional/src/activations/tanhshrink.cpp +++ b/tests/functional/src/activations/tanhshrink.cpp @@ -38,4 +38,19 @@ TEST_CASE("tanhshrink" * doctest::test_suite("functional::get_function_compositi auto expect = fn::tanhshrink; NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); +} + +TEST_CASE("tanhshrink" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(activations,tanhshrink,case1); + using namespace args; + + auto array = view::tanhshrink(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + + NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_CLOSE( function (a), array ); } \ No newline at end of file diff --git a/tests/functional/src/composition/add_tanh.cpp b/tests/functional/src/composition/add_tanh.cpp index 8a82b186a..8654a7024 100644 --- a/tests/functional/src/composition/add_tanh.cpp +++ b/tests/functional/src/composition/add_tanh.cpp @@ -19,8 +19,11 @@ TEST_CASE("add_tanh" * doctest::test_suite("functional::get_function_composition auto function = fn::get_function_composition(z); auto expect = - fn::tanh * fn::add + fn::unary_ufunc[z.attributes()] + * fn::broadcast_binary_ufunc[y.attributes()] ; + + // TODO: make fn::tanh == fn::unary_ufunc[view::tanh_{}] NMTOOLS_ASSERT_EQUAL( function, expect ); NMTOOLS_ASSERT_CLOSE( function (a) (b), z ); } diff --git a/tests/functional/src/composition/divide_subtract.cpp b/tests/functional/src/composition/divide_subtract.cpp index bd2e46cc0..ba0a866fd 100644 --- a/tests/functional/src/composition/divide_subtract.cpp +++ b/tests/functional/src/composition/divide_subtract.cpp @@ -21,8 +21,8 @@ TEST_CASE("divide_subtract" * doctest::test_suite("functional::get_function_comp auto function = fn::get_function_composition(y); auto expect = - fn::subtract - * fn::divide + fn::broadcast_binary_ufunc[y.attributes()] + * fn::broadcast_binary_ufunc[x.attributes()] ; NMTOOLS_ASSERT_EQUAL( function, expect ); @@ -40,7 +40,8 @@ TEST_CASE("divide_subtract" * doctest::test_suite("functional::get_function_comp auto function = fn::get_function_composition(y); auto expect = - fn::subtract * fn::divide + fn::broadcast_binary_ufunc[y.attributes()] + * fn::broadcast_binary_ufunc[x.attributes()] ; NMTOOLS_ASSERT_EQUAL( function, expect ); diff --git a/tests/functional/src/composition/fabs_square.cpp b/tests/functional/src/composition/fabs_square.cpp index 85a18b25c..44ea278e5 100644 --- a/tests/functional/src/composition/fabs_square.cpp +++ b/tests/functional/src/composition/fabs_square.cpp @@ -17,7 +17,8 @@ TEST_CASE("fabs_square" * doctest::test_suite("functional::get_function_composit auto function = fn::get_function_composition(y); auto expect = - fn::square * fn::fabs + fn::unary_ufunc[y.attributes()] + * fn::unary_ufunc[x.attributes()] ; NMTOOLS_ASSERT_EQUAL( function, expect ); diff --git a/tests/functional/src/composition/fabs_square_sum.cpp b/tests/functional/src/composition/fabs_square_sum.cpp index 98553bd67..c699cae16 100644 --- a/tests/functional/src/composition/fabs_square_sum.cpp +++ b/tests/functional/src/composition/fabs_square_sum.cpp @@ -15,7 +15,6 @@ TEST_CASE("fabs_square_sum" * doctest::test_suite("functional::get_function_comp NMTOOLS_TESTING_DECLARE_NS(view,fabs,case1); using namespace args; - auto dtype = nm::None; auto axis = 0; auto x = view::fabs(a); auto y = view::square(x); @@ -23,8 +22,9 @@ TEST_CASE("fabs_square_sum" * doctest::test_suite("functional::get_function_comp auto function = fn::get_function_composition(z); auto expect = - fn::reduce_add[z.axis][dtype][z.initial][z.keepdims] - * fn::square * fn::fabs + fn::reduce[z.attributes()] + * fn::unary_ufunc[y.attributes()] + * fn::unary_ufunc[x.attributes()] ; NMTOOLS_ASSERT_EQUAL( function, expect ); diff --git a/tests/functional/src/composition/multiply_add.cpp b/tests/functional/src/composition/multiply_add.cpp index 6e5f1d999..5c6c31aa2 100644 --- a/tests/functional/src/composition/multiply_add.cpp +++ b/tests/functional/src/composition/multiply_add.cpp @@ -17,7 +17,8 @@ TEST_CASE("multiply_add" * doctest::test_suite("functional::get_function_composi auto function = fn::get_function_composition(y); auto expect = - fn::add * fn::multiply + fn::broadcast_binary_ufunc[y.attributes()] + * fn::broadcast_binary_ufunc[x.attributes()] ; NMTOOLS_ASSERT_EQUAL( function, expect ); diff --git a/tests/functional/src/composition/multiply_add_tanh.cpp b/tests/functional/src/composition/multiply_add_tanh.cpp index c29bae0fc..f423b15e5 100644 --- a/tests/functional/src/composition/multiply_add_tanh.cpp +++ b/tests/functional/src/composition/multiply_add_tanh.cpp @@ -20,34 +20,20 @@ TEST_CASE("multiply_add_tanh" * doctest::test_suite("functional::get_function_co auto y = view::add(x,b); auto z = view::tanh(y); - NMTOOLS_ASSERT_EQUAL( fn::get_function(z), fn::tanh ); - NMTOOLS_ASSERT_EQUAL( fn::get_function(y), fn::add ); - NMTOOLS_ASSERT_EQUAL( fn::get_function(x), fn::multiply ); - - auto z_operands = fn::get_operands(z); - NMTOOLS_ASSERT_EQUAL( nm::len(z_operands), 1 ); - // NMTOOLS_STATIC_CHECK_IS_SAME( decltype(z_operands), nmtools_tuple ); - - auto z_operand = at(z_operands,0_ct); - using z_operand_t = meta::remove_cvref_pointer_t; - NMTOOLS_ASSERT_EQUAL( meta::is_view_v, true ); - NMTOOLS_ASSERT_EQUAL( fn::get_function(z_operand), fn::add ); - - auto z_sub_operands = fn::get_operands(z_operand); - NMTOOLS_ASSERT_EQUAL( nm::len(z_sub_operands), 2 ); - - auto z_sub_operand_0 = at(z_sub_operands,0_ct); - using z_sub_operand_0_t = meta::remove_cvref_pointer_t; - NMTOOLS_STATIC_CHECK_TRAIT( meta::is_view, z_sub_operand_0_t ); + NMTOOLS_ASSERT_EQUAL( fn::get_function(z), fn::unary_ufunc[z.attributes()] ); + NMTOOLS_ASSERT_EQUAL( fn::get_function(y), fn::broadcast_binary_ufunc[y.attributes()] ); + NMTOOLS_ASSERT_EQUAL( fn::get_function(x), fn::broadcast_binary_ufunc[x.attributes()] ); auto function = fn::get_function_composition(z); auto expect = - fn::tanh * fn::add * fn::multiply + fn::unary_ufunc[z.attributes()] + * fn::broadcast_binary_ufunc[y.attributes()] + * fn::broadcast_binary_ufunc[x.attributes()] ; NMTOOLS_ASSERT_EQUAL( function, expect ); static_assert( decltype(expect)::arity == 3 ); static_assert( decltype(function)::arity == 3 ); - // NMTOOLS_ASSERT_CLOSE( function (a) (b) (3), z ); + NMTOOLS_ASSERT_CLOSE( function (a) (b) (b), z ); } TEST_CASE("multiply_add_tanh" * doctest::test_suite("functional::get_function_operands")) diff --git a/tests/functional/src/composition/multiply_tanh.cpp b/tests/functional/src/composition/multiply_tanh.cpp index 0b2a8416e..fae172980 100644 --- a/tests/functional/src/composition/multiply_tanh.cpp +++ b/tests/functional/src/composition/multiply_tanh.cpp @@ -17,7 +17,8 @@ TEST_CASE("multiply_tanh" * doctest::test_suite("functional::get_function_compos auto function = fn::get_function_composition(y); auto expect = - fn::tanh * fn::multiply + fn::unary_ufunc[y.attributes()] + * fn::broadcast_binary_ufunc[x.attributes()] ; NMTOOLS_ASSERT_EQUAL( function, expect ); diff --git a/tests/functional/src/composition/reduce_add_divide.cpp b/tests/functional/src/composition/reduce_add_divide.cpp index b4469ff69..5bbf60429 100644 --- a/tests/functional/src/composition/reduce_add_divide.cpp +++ b/tests/functional/src/composition/reduce_add_divide.cpp @@ -18,8 +18,8 @@ TEST_CASE("reduce_add_divide" * doctest::test_suite("functional::get_function_co auto function = fn::get_function_composition(y); auto expect = - fn::divide - * fn::reduce_add[axis][dtype][initial][keepdims] + fn::broadcast_binary_ufunc[y.attributes()] + * fn::reduce[x.attributes()] ; NMTOOLS_ASSERT_EQUAL( function, expect ); diff --git a/tests/functional/src/composition/reduce_add_tanh.cpp b/tests/functional/src/composition/reduce_add_tanh.cpp index e35db7a1c..ad131f07a 100644 --- a/tests/functional/src/composition/reduce_add_tanh.cpp +++ b/tests/functional/src/composition/reduce_add_tanh.cpp @@ -6,9 +6,7 @@ namespace fn = nmtools::functional; namespace view = nmtools::view; -// NOTE: somehow get_function_composition produces wrong result for 3(+?) functions -// TODO: fix -TEST_CASE("reduce_add_tanh" * doctest::test_suite("functional::get_function_composition") * doctest::may_fail()) +TEST_CASE("reduce_add_tanh" * doctest::test_suite("functional::get_function_composition")) { NMTOOLS_TESTING_DECLARE_NS(view,reduce_add,case9); using namespace args; @@ -18,10 +16,12 @@ TEST_CASE("reduce_add_tanh" * doctest::test_suite("functional::get_function_comp auto function = fn::get_function_composition(y); auto expect = - fn::tanh - * fn::reduce_add[axis][dtype][initial][keepdims] + fn::unary_ufunc[y.attributes()] + * fn::reduce[x.attributes()] ; + // TODO: make fn::tanh == fn::unary_ufunc[view::tanh_t{}] + NMTOOLS_ASSERT_EQUAL( function, expect ); NMTOOLS_ASSERT_CLOSE( function (a), y ); } diff --git a/tests/functional/src/composition/reduce_maximum_subtract.cpp b/tests/functional/src/composition/reduce_maximum_subtract.cpp index f511f41a1..254a91e5e 100644 --- a/tests/functional/src/composition/reduce_maximum_subtract.cpp +++ b/tests/functional/src/composition/reduce_maximum_subtract.cpp @@ -22,8 +22,8 @@ TEST_CASE("reduce_maximum_subtract" * doctest::test_suite("functional::get_funct auto function = fn::get_function_composition(y); auto expect = - fn::subtract - * fn::reduce_maximum[x.axis][dtype][x.initial][x.keepdims] + fn::broadcast_binary_ufunc[y.attributes()] + * fn::reduce[x.attributes()] ; NMTOOLS_ASSERT_EQUAL( function, expect ); diff --git a/tests/functional/src/composition/reduce_maximum_subtract_exp.cpp b/tests/functional/src/composition/reduce_maximum_subtract_exp.cpp index 387e65d59..de79a6d50 100644 --- a/tests/functional/src/composition/reduce_maximum_subtract_exp.cpp +++ b/tests/functional/src/composition/reduce_maximum_subtract_exp.cpp @@ -24,9 +24,9 @@ TEST_CASE("reduce_maximum_subtract_exp" * doctest::test_suite("functional::get_f auto function = fn::get_function_composition(z); auto expect = - fn::exp - * fn::subtract - * fn::reduce_maximum[x.axis][dtype][x.initial][x.keepdims] + fn::unary_ufunc[z.attributes()] + * fn::broadcast_binary_ufunc[y.attributes()] + * fn::reduce[x.attributes()] ; NMTOOLS_ASSERT_EQUAL( function, expect ); diff --git a/tests/functional/src/composition/square_sum.cpp b/tests/functional/src/composition/square_sum.cpp index f056bd84a..bddaf4b61 100644 --- a/tests/functional/src/composition/square_sum.cpp +++ b/tests/functional/src/composition/square_sum.cpp @@ -13,7 +13,6 @@ TEST_CASE("square_sum" * doctest::test_suite("functional::get_function_compositi NMTOOLS_TESTING_DECLARE_NS(view,square,case1); using namespace args; - auto dtype = nm::None; auto axis = 0; auto x = view::square(a); @@ -21,8 +20,8 @@ TEST_CASE("square_sum" * doctest::test_suite("functional::get_function_compositi auto function = fn::get_function_composition(y); auto expect = - fn::reduce_add[y.axis][dtype][y.initial][y.keepdims] - * fn::square + fn::reduce[y.attributes()] + * fn::unary_ufunc[x.attributes()] ; NMTOOLS_ASSERT_EQUAL( function, expect ); diff --git a/tests/functional/src/composition/square_sum_divide.cpp b/tests/functional/src/composition/square_sum_divide.cpp index 8f8ddd69e..5ffecb19b 100644 --- a/tests/functional/src/composition/square_sum_divide.cpp +++ b/tests/functional/src/composition/square_sum_divide.cpp @@ -9,9 +9,7 @@ namespace fn = nmtools::functional; namespace view = nmtools::view; -// NOTE: somehow get_function_composition produces wrong result for 3(+?) functions -// TODO: fix -TEST_CASE("square_sum_divide" * doctest::test_suite("functional::get_function_composition") * doctest::may_fail()) +TEST_CASE("square_sum_divide" * doctest::test_suite("functional::get_function_composition")) { NMTOOLS_TESTING_DECLARE_NS(view,square,case1); using namespace args; @@ -26,18 +24,16 @@ TEST_CASE("square_sum_divide" * doctest::test_suite("functional::get_function_co auto function = fn::get_function_composition(z); auto expect = - fn::divide - * fn::reduce_add[y.axis][dtype][y.initial][y.keepdims] - * fn::square + fn::broadcast_binary_ufunc[z.attributes()] + * fn::reduce[y.attributes()] + * fn::unary_ufunc[x.attributes()] ; NMTOOLS_ASSERT_EQUAL( function, expect ); - // NMTOOLS_ASSERT_CLOSE( function (a) (divisor), z ); + NMTOOLS_ASSERT_CLOSE( function (a) (divisor), z ); } -// NOTE: somehow get_function_composition produces wrong result for 3(+?) functions -// TODO: fix -TEST_CASE("square_sum_divide" * doctest::test_suite("functional::get_function_composition") * doctest::may_fail()) +TEST_CASE("square_sum_divide" * doctest::test_suite("functional::get_function_composition")) { NMTOOLS_TESTING_DECLARE_NS(view,square,case1); using namespace args; @@ -53,13 +49,13 @@ TEST_CASE("square_sum_divide" * doctest::test_suite("functional::get_function_co auto function = fn::get_function_composition(z); auto expect = - fn::divide - * fn::reduce_add[y.axis][dtype][y.initial][y.keepdims] - * fn::square + fn::broadcast_binary_ufunc[z.attributes()] + * fn::reduce[y.attributes()] + * fn::unary_ufunc[x.attributes()] ; NMTOOLS_ASSERT_EQUAL( function, expect ); - // NMTOOLS_ASSERT_CLOSE( function (a) (a), z ); + NMTOOLS_ASSERT_CLOSE( function (a) (a), z ); } using namespace nmtools::literals; @@ -85,9 +81,7 @@ TEST_CASE("square_sum_divide" * doctest::test_suite("functional::get_function_op CHECK( &nm::at(operands,1_ct) == &nm::at(expect,1_ct) ); } -// NOTE: somehow get_function_composition produces wrong result for 3(+?) functions -// TODO: fix -TEST_CASE("square_sum_divide" * doctest::test_suite("functional::apply") * doctest::skip()) +TEST_CASE("square_sum_divide" * doctest::test_suite("functional::apply")) { NMTOOLS_TESTING_DECLARE_NS(view,square,case1); using namespace args; diff --git a/tests/functional/src/composition/subtract_exp.cpp b/tests/functional/src/composition/subtract_exp.cpp index e126c4cdf..f6e386e27 100644 --- a/tests/functional/src/composition/subtract_exp.cpp +++ b/tests/functional/src/composition/subtract_exp.cpp @@ -17,7 +17,8 @@ TEST_CASE("subtract_exp" * doctest::test_suite("functional::get_function_composi auto function = fn::get_function_composition(y); auto expect = - fn::exp * fn::subtract + fn::unary_ufunc[y.attributes()] + * fn::broadcast_binary_ufunc[x.attributes()] ; NMTOOLS_ASSERT_EQUAL( function, expect ); diff --git a/tests/functional/src/composition/subtract_fabs.cpp b/tests/functional/src/composition/subtract_fabs.cpp index a80f4f1cd..e33d644a3 100644 --- a/tests/functional/src/composition/subtract_fabs.cpp +++ b/tests/functional/src/composition/subtract_fabs.cpp @@ -19,7 +19,8 @@ TEST_CASE("subtract_fabs" * doctest::test_suite("functional::get_function_compos auto function = fn::get_function_composition(y); auto expect = - fn::fabs * fn::subtract + fn::unary_ufunc[y.attributes()] + * fn::broadcast_binary_ufunc[x.attributes()] ; NMTOOLS_ASSERT_EQUAL( function, expect ); diff --git a/tests/functional/src/composition/subtract_fabs_square.cpp b/tests/functional/src/composition/subtract_fabs_square.cpp index 0bc9f0934..dda6f7271 100644 --- a/tests/functional/src/composition/subtract_fabs_square.cpp +++ b/tests/functional/src/composition/subtract_fabs_square.cpp @@ -19,7 +19,9 @@ TEST_CASE("subtract_fabs_square" * doctest::test_suite("functional::get_function auto function = fn::get_function_composition(z); auto expect = - fn::square * fn::fabs * fn::subtract + fn::unary_ufunc[z.attributes()] + * fn::unary_ufunc[y.attributes()] + * fn::broadcast_binary_ufunc[x.attributes()] ; NMTOOLS_ASSERT_EQUAL( function, expect ); diff --git a/tests/functional/src/composition/sum_divide.cpp b/tests/functional/src/composition/sum_divide.cpp index 11bd66bdb..c6add800b 100644 --- a/tests/functional/src/composition/sum_divide.cpp +++ b/tests/functional/src/composition/sum_divide.cpp @@ -23,8 +23,8 @@ TEST_CASE("sum_divide" * doctest::test_suite("functional::get_function_compositi auto function = fn::get_function_composition(y); auto expect = - fn::divide - * fn::reduce_add[x.axis][dtype][x.initial][x.keepdims] + fn::broadcast_binary_ufunc[y.attributes()] + * fn::reduce[x.attributes()] ; NMTOOLS_ASSERT_EQUAL( function, expect ); diff --git a/tests/functional/src/mean.cpp b/tests/functional/src/mean.cpp index 7504d0907..7a022dacd 100644 --- a/tests/functional/src/mean.cpp +++ b/tests/functional/src/mean.cpp @@ -50,6 +50,8 @@ TEST_CASE("mean(case6)" * doctest::test_suite("functional::mean")) FUNCTIONAL_SUBCASE( "case6", fn::mean[axis][nm::None][keepdims], a_d ); } +// TODO: fix +#if 0 TEST_CASE("mean(case7)" * doctest::test_suite("functional::mean")) { NMTOOLS_TESTING_DECLARE_NS(array, mean, case7); @@ -67,6 +69,7 @@ TEST_CASE("mean(case7)" * doctest::test_suite("functional::mean")) FUNCTIONAL_SUBCASE( "case7", fn::mean[axis][nm::None][keepdims], a_d ); #endif // NMTOOLS_DISABLE_STL } +#endif TEST_CASE("mean(case9)" * doctest::test_suite("functional::mean")) { diff --git a/tests/functional/src/ufuncs/add.cpp b/tests/functional/src/ufuncs/add.cpp index 8a98aa247..1c8963719 100644 --- a/tests/functional/src/ufuncs/add.cpp +++ b/tests/functional/src/ufuncs/add.cpp @@ -130,7 +130,7 @@ TEST_CASE("add" * doctest::test_suite("functional::get_function_composition")) auto array = view::add(a,b); auto function = fn::get_function_composition(array); - auto expect = fn::add; + auto expect = fn::broadcast_binary_ufunc[array.attributes()]; NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/arccos.cpp b/tests/functional/src/ufuncs/arccos.cpp index 8fc6c140c..f5a1a3d9b 100644 --- a/tests/functional/src/ufuncs/arccos.cpp +++ b/tests/functional/src/ufuncs/arccos.cpp @@ -26,6 +26,9 @@ TEST_CASE("arccos(case1)" * doctest::test_suite("functional::arccos")) } namespace view = nmtools::view; +namespace fun = view::fun; + +using nmtools::args::ufunc; TEST_CASE("arccos" * doctest::test_suite("functional::get_function_composition")) { @@ -37,5 +40,18 @@ TEST_CASE("arccos" * doctest::test_suite("functional::get_function_composition") auto function = fn::get_function_composition(array); auto expect = fn::arccos; + NMTOOLS_ASSERT_EQUAL( function, expect ); +} + +TEST_CASE("arccos" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,arccos,case1); + using namespace args; + + auto array = view::arccos(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[ufunc{fun::arccos()}]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/arccosh.cpp b/tests/functional/src/ufuncs/arccosh.cpp index 4c874bdf5..367d9f2a1 100644 --- a/tests/functional/src/ufuncs/arccosh.cpp +++ b/tests/functional/src/ufuncs/arccosh.cpp @@ -37,5 +37,18 @@ TEST_CASE("arccosh" * doctest::test_suite("functional::get_function_composition" auto function = fn::get_function_composition(array); auto expect = fn::arccosh; + NMTOOLS_ASSERT_EQUAL( function, expect ); +} + +TEST_CASE("arccosh" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,arccosh,case1); + using namespace args; + + auto array = view::arccosh(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/arcsin.cpp b/tests/functional/src/ufuncs/arcsin.cpp index 448d45dae..3b7fb39fc 100644 --- a/tests/functional/src/ufuncs/arcsin.cpp +++ b/tests/functional/src/ufuncs/arcsin.cpp @@ -38,5 +38,18 @@ TEST_CASE("arcsin" * doctest::test_suite("functional::get_function_composition") auto function = fn::get_function_composition(array); auto expect = fn::arcsin; + NMTOOLS_ASSERT_EQUAL( function, expect ); +} + +TEST_CASE("arcsin" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,arcsin,case1); + using namespace args; + + auto array = view::arcsin(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/arcsinh.cpp b/tests/functional/src/ufuncs/arcsinh.cpp index cc59d17fd..b3abd7ecb 100644 --- a/tests/functional/src/ufuncs/arcsinh.cpp +++ b/tests/functional/src/ufuncs/arcsinh.cpp @@ -38,5 +38,18 @@ TEST_CASE("arcsinh" * doctest::test_suite("functional::get_function_composition" auto function = fn::get_function_composition(array); auto expect = fn::arcsinh; + NMTOOLS_ASSERT_EQUAL( function, expect ); +} + +TEST_CASE("arcsinh" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,arcsinh,case1); + using namespace args; + + auto array = view::arcsinh(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/arctan.cpp b/tests/functional/src/ufuncs/arctan.cpp index cc2e6ed98..492f0b060 100644 --- a/tests/functional/src/ufuncs/arctan.cpp +++ b/tests/functional/src/ufuncs/arctan.cpp @@ -38,5 +38,18 @@ TEST_CASE("arctan" * doctest::test_suite("functional::get_function_composition") auto function = fn::get_function_composition(array); auto expect = fn::arctan; + NMTOOLS_ASSERT_EQUAL( function, expect ); +} + +TEST_CASE("arctan" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,arctan,case1); + using namespace args; + + auto array = view::arctan(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/arctanh.cpp b/tests/functional/src/ufuncs/arctanh.cpp index fbfd6f4a3..004aafd5d 100644 --- a/tests/functional/src/ufuncs/arctanh.cpp +++ b/tests/functional/src/ufuncs/arctanh.cpp @@ -38,5 +38,18 @@ TEST_CASE("arctanh" * doctest::test_suite("functional::get_function_composition" auto function = fn::get_function_composition(array); auto expect = fn::arctanh; + NMTOOLS_ASSERT_EQUAL( function, expect ); +} + +TEST_CASE("arctanh" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,arctanh,case1); + using namespace args; + + auto array = view::arctanh(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/cbrt.cpp b/tests/functional/src/ufuncs/cbrt.cpp index 21f52b2a4..79365d464 100644 --- a/tests/functional/src/ufuncs/cbrt.cpp +++ b/tests/functional/src/ufuncs/cbrt.cpp @@ -38,5 +38,18 @@ TEST_CASE("cbrt" * doctest::test_suite("functional::get_function_composition")) auto function = fn::get_function_composition(array); auto expect = fn::cbrt; + NMTOOLS_ASSERT_EQUAL( function, expect ); +} + +TEST_CASE("cbrt" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,cbrt,case1); + using namespace args; + + auto array = view::cbrt(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/ceil.cpp b/tests/functional/src/ufuncs/ceil.cpp index 4d5c39d69..aeb2e2a6e 100644 --- a/tests/functional/src/ufuncs/ceil.cpp +++ b/tests/functional/src/ufuncs/ceil.cpp @@ -38,5 +38,18 @@ TEST_CASE("ceil" * doctest::test_suite("functional::get_function_composition")) auto function = fn::get_function_composition(array); auto expect = fn::ceil; + NMTOOLS_ASSERT_EQUAL( function, expect ); +} + +TEST_CASE("ceil" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,ceil,case1); + using namespace args; + + auto array = view::ceil(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/cos.cpp b/tests/functional/src/ufuncs/cos.cpp index 3d62728ed..71f16899e 100644 --- a/tests/functional/src/ufuncs/cos.cpp +++ b/tests/functional/src/ufuncs/cos.cpp @@ -38,5 +38,18 @@ TEST_CASE("cos" * doctest::test_suite("functional::get_function_composition")) auto function = fn::get_function_composition(array); auto expect = fn::cos; + NMTOOLS_ASSERT_EQUAL( function, expect ); +} + +TEST_CASE("cos" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,cos,case1); + using namespace args; + + auto array = view::cos(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/cosh.cpp b/tests/functional/src/ufuncs/cosh.cpp index 514317edf..1ebfefa46 100644 --- a/tests/functional/src/ufuncs/cosh.cpp +++ b/tests/functional/src/ufuncs/cosh.cpp @@ -41,5 +41,18 @@ TEST_CASE("cosh" * doctest::test_suite("functional::get_function_composition")) auto function = fn::get_function_composition(array); auto expect = fn::cosh; + NMTOOLS_ASSERT_EQUAL( function, expect ); +} + +TEST_CASE("cosh" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,cosh,case1); + using namespace args; + + auto array = view::cosh(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/exp.cpp b/tests/functional/src/ufuncs/exp.cpp index 7c39b27cc..178e1dcae 100644 --- a/tests/functional/src/ufuncs/exp.cpp +++ b/tests/functional/src/ufuncs/exp.cpp @@ -38,5 +38,18 @@ TEST_CASE("exp" * doctest::test_suite("functional::get_function_composition")) auto function = fn::get_function_composition(array); auto expect = fn::exp; + NMTOOLS_ASSERT_EQUAL( function, expect ); +} + +TEST_CASE("exp" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,exp,case1); + using namespace args; + + auto array = view::exp(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/exp2.cpp b/tests/functional/src/ufuncs/exp2.cpp index 432b25ab8..b73dd004e 100644 --- a/tests/functional/src/ufuncs/exp2.cpp +++ b/tests/functional/src/ufuncs/exp2.cpp @@ -38,5 +38,18 @@ TEST_CASE("exp2" * doctest::test_suite("functional::get_function_composition")) auto function = fn::get_function_composition(array); auto expect = fn::exp2; + NMTOOLS_ASSERT_EQUAL( function, expect ); +} + +TEST_CASE("exp2" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,exp2,case1); + using namespace args; + + auto array = view::exp2(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/expm1.cpp b/tests/functional/src/ufuncs/expm1.cpp index 642dab1b7..cc7f5414c 100644 --- a/tests/functional/src/ufuncs/expm1.cpp +++ b/tests/functional/src/ufuncs/expm1.cpp @@ -38,5 +38,18 @@ TEST_CASE("expm1" * doctest::test_suite("functional::get_function_composition")) auto function = fn::get_function_composition(array); auto expect = fn::expm1; + NMTOOLS_ASSERT_EQUAL( function, expect ); +} + +TEST_CASE("expm1" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,expm1,case1); + using namespace args; + + auto array = view::expm1(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/fabs.cpp b/tests/functional/src/ufuncs/fabs.cpp index d9f3ed77f..1d59914bc 100644 --- a/tests/functional/src/ufuncs/fabs.cpp +++ b/tests/functional/src/ufuncs/fabs.cpp @@ -38,5 +38,18 @@ TEST_CASE("fabs" * doctest::test_suite("functional::get_function_composition")) auto function = fn::get_function_composition(array); auto expect = fn::fabs; + NMTOOLS_ASSERT_EQUAL( function, expect ); +} + +TEST_CASE("fabs" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,fabs,case1); + using namespace args; + + auto array = view::fabs(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/floor.cpp b/tests/functional/src/ufuncs/floor.cpp index 37273422d..a9799ce9a 100644 --- a/tests/functional/src/ufuncs/floor.cpp +++ b/tests/functional/src/ufuncs/floor.cpp @@ -38,5 +38,18 @@ TEST_CASE("floor" * doctest::test_suite("functional::get_function_composition")) auto function = fn::get_function_composition(array); auto expect = fn::floor; + NMTOOLS_ASSERT_EQUAL( function, expect ); +} + +TEST_CASE("floor" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,floor,case1); + using namespace args; + + auto array = view::floor(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/invert.cpp b/tests/functional/src/ufuncs/invert.cpp index e05de85b8..be74f283c 100644 --- a/tests/functional/src/ufuncs/invert.cpp +++ b/tests/functional/src/ufuncs/invert.cpp @@ -38,5 +38,19 @@ TEST_CASE("invert" * doctest::test_suite("functional::get_function_composition") auto function = fn::get_function_composition(array); auto expect = fn::invert; + NMTOOLS_ASSERT_EQUAL( function, expect ); + NMTOOLS_ASSERT_EQUAL( function (a), array ); +} + +TEST_CASE("invert" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,invert,case1); + using namespace args; + + auto array = view::invert(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/isfinite.cpp b/tests/functional/src/ufuncs/isfinite.cpp index eeb64ea31..dadaf7c3c 100644 --- a/tests/functional/src/ufuncs/isfinite.cpp +++ b/tests/functional/src/ufuncs/isfinite.cpp @@ -37,5 +37,18 @@ TEST_CASE("isfinite" * doctest::test_suite("functional::get_function_composition auto function = fn::get_function_composition(array); auto expect = fn::isfinite; + NMTOOLS_ASSERT_EQUAL( function, expect ); +} + +TEST_CASE("isfinite" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,isfinite,case1); + using namespace args; + + auto array = view::isfinite(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/isinf.cpp b/tests/functional/src/ufuncs/isinf.cpp index ad82c83c0..e51c8f20d 100644 --- a/tests/functional/src/ufuncs/isinf.cpp +++ b/tests/functional/src/ufuncs/isinf.cpp @@ -37,5 +37,18 @@ TEST_CASE("isinf" * doctest::test_suite("functional::get_function_composition")) auto function = fn::get_function_composition(array); auto expect = fn::isinf; + NMTOOLS_ASSERT_EQUAL( function, expect ); +} + +TEST_CASE("isinf" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,isinf,case1); + using namespace args; + + auto array = view::isinf(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/isnan.cpp b/tests/functional/src/ufuncs/isnan.cpp index 427229cd2..fe5a74f27 100644 --- a/tests/functional/src/ufuncs/isnan.cpp +++ b/tests/functional/src/ufuncs/isnan.cpp @@ -37,5 +37,18 @@ TEST_CASE("isnan" * doctest::test_suite("functional::get_function_composition")) auto function = fn::get_function_composition(array); auto expect = fn::isnan; + NMTOOLS_ASSERT_EQUAL( function, expect ); +} + +TEST_CASE("isnan" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,isnan,case1); + using namespace args; + + auto array = view::isnan(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/log.cpp b/tests/functional/src/ufuncs/log.cpp index df8ee9d52..9f5a28641 100644 --- a/tests/functional/src/ufuncs/log.cpp +++ b/tests/functional/src/ufuncs/log.cpp @@ -37,5 +37,18 @@ TEST_CASE("log" * doctest::test_suite("functional::get_function_composition")) auto function = fn::get_function_composition(array); auto expect = fn::log; + NMTOOLS_ASSERT_EQUAL( function, expect ); +} + +TEST_CASE("log" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,log,case1); + using namespace args; + + auto array = view::log(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/log10.cpp b/tests/functional/src/ufuncs/log10.cpp index 0c5b29b0a..ec9246305 100644 --- a/tests/functional/src/ufuncs/log10.cpp +++ b/tests/functional/src/ufuncs/log10.cpp @@ -37,5 +37,18 @@ TEST_CASE("log10" * doctest::test_suite("functional::get_function_composition")) auto function = fn::get_function_composition(array); auto expect = fn::log10; + NMTOOLS_ASSERT_EQUAL( function, expect ); +} + +TEST_CASE("log10" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,log10,case1); + using namespace args; + + auto array = view::log10(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/log1p.cpp b/tests/functional/src/ufuncs/log1p.cpp index b4e2fd45e..c7bad284e 100644 --- a/tests/functional/src/ufuncs/log1p.cpp +++ b/tests/functional/src/ufuncs/log1p.cpp @@ -37,5 +37,18 @@ TEST_CASE("log1p" * doctest::test_suite("functional::get_function_composition")) auto function = fn::get_function_composition(array); auto expect = fn::log1p; + NMTOOLS_ASSERT_EQUAL( function, expect ); +} + +TEST_CASE("log1p" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,log1p,case1); + using namespace args; + + auto array = view::log1p(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/log2.cpp b/tests/functional/src/ufuncs/log2.cpp index ddadd4505..ae79df9dc 100644 --- a/tests/functional/src/ufuncs/log2.cpp +++ b/tests/functional/src/ufuncs/log2.cpp @@ -37,5 +37,18 @@ TEST_CASE("log2" * doctest::test_suite("functional::get_function_composition")) auto function = fn::get_function_composition(array); auto expect = fn::log2; + NMTOOLS_ASSERT_EQUAL( function, expect ); +} + +TEST_CASE("log2" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,log2,case1); + using namespace args; + + auto array = view::log2(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/multiply.cpp b/tests/functional/src/ufuncs/multiply.cpp index b7980ca4d..9c513d7b7 100644 --- a/tests/functional/src/ufuncs/multiply.cpp +++ b/tests/functional/src/ufuncs/multiply.cpp @@ -132,12 +132,13 @@ TEST_CASE("multiply" * doctest::test_suite("functional::get_function_composition auto array = view::multiply(a,b); auto function = fn::get_function_composition(array); - auto expect = fn::multiply; + auto expect = fn::broadcast_binary_ufunc[array.attributes()]; NMTOOLS_ASSERT_EQUAL( function, expect ); } namespace view = nmtools::view; +namespace kwargs = nmtools::args; TEST_CASE("reduce_multiply" * doctest::test_suite("functional::get_function_composition")) { @@ -147,7 +148,230 @@ TEST_CASE("reduce_multiply" * doctest::test_suite("functional::get_function_comp auto array = view::reduce_multiply(a,axis,dtype,initial,keepdims); auto function = fn::get_function_composition(array); - auto expect = fn::reduce_multiply[axis][dtype][initial][keepdims]; + auto expected = fn::reduce[kwargs::reduce{ + axis + , dtype + , initial + , keepdims + , view::multiply_t<>{} + }]; - NMTOOLS_ASSERT_EQUAL( function, expect ); -} \ No newline at end of file + NMTOOLS_ASSERT_EQUAL( function, expected ); + NMTOOLS_ASSERT_CLOSE( function (a), expect::result ); +} + +TEST_CASE("reduce_multiply" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,reduce_multiply,case9); + using namespace args; + + auto op = view::multiply_t<>{}; + auto array = view::reduce(a,op,kwargs::reduce{axis,dtype,initial,keepdims}); + + auto function = fn::get_function_composition(array); + auto expected = fn::reduce[kwargs::reduce{ + axis + , dtype + , initial + , keepdims + , op + }]; + + NMTOOLS_ASSERT_EQUAL( function, expected ); + NMTOOLS_ASSERT_CLOSE( function (a), expect::result ); +} + +TEST_CASE("reduce_multiply" * doctest::test_suite("functional::get_function_composition") * doctest::may_fail()) +{ + NMTOOLS_TESTING_DECLARE_NS(view,reduce_multiply,case9); + using namespace args; + + auto op = view::multiply_t<>{}; + auto array = view::reduce(a,op,kwargs::reduce{axis,dtype,initial,keepdims}); + + auto function = fn::get_function_composition(array); + auto expected = fn::reduce[op][kwargs::reduce{ + axis + , dtype + , initial + , keepdims + }]; + + NMTOOLS_ASSERT_EQUAL( function, expected ); + NMTOOLS_ASSERT_CLOSE( function (a), expect::result ); +} + + + +#ifdef NMTOOLS_TESTING_KWARGS_INIT +#ifndef __clang__ +TEST_CASE("reduce_multiply" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,reduce_multiply,case9); + using namespace args; + + auto kwargs = kwargs::reduce{ + .axis=axis + , .dtype=dtype + , .initial=initial + , .keepdims=keepdims + , .op=view::multiply_t<>{} + }; + + auto array = view::reduce_multiply(a,axis,dtype,initial,keepdims); + + auto function = fn::get_function_composition(array); + auto expected = fn::reduce[kwargs]; + + NMTOOLS_ASSERT_EQUAL( function, expected ); + NMTOOLS_ASSERT_CLOSE( function (a), expect::result ); +} + +TEST_CASE("reduce_multiply" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,reduce_multiply,case9); + using namespace args; + + auto array = view::reduce_multiply(a,axis,dtype,initial,keepdims); + + auto function = fn::get_function_composition(array); + auto expected = fn::reduce[kwargs::reduce{ + .axis=axis + , .dtype=dtype + , .initial=initial + , .keepdims=keepdims + , .op=view::multiply_t<>{} + }]; + + NMTOOLS_ASSERT_EQUAL( function, expected ); + NMTOOLS_ASSERT_CLOSE( function (a), expect::result ); +} + +TEST_CASE("reduce_multiply" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,reduce_multiply,case9); + using namespace args; + + auto op = view::multiply_t<>{}; + + auto array = view::reduce(a,kwargs::reduce{axis,dtype,initial,keepdims,op}); + + auto function = fn::get_function_composition(array); + auto expected = fn::reduce[kwargs::reduce{ + .axis=axis + , .dtype=dtype + , .initial=initial + , .keepdims=keepdims + , .op=view::multiply_t<>{} + }]; + + NMTOOLS_ASSERT_EQUAL( function, expected ); + NMTOOLS_ASSERT_CLOSE( function (a), expect::result ); +} + +TEST_CASE("reduce_multiply" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,reduce_multiply,case9); + using namespace args; + + auto op = view::multiply_t<>{}; + + auto array = view::reduce(a,kwargs::reduce{ + .axis=axis + , .dtype=dtype + , .initial=initial + , .keepdims=keepdims + , .op=op + }); + + auto function = fn::get_function_composition(array); + auto expected = fn::reduce[kwargs::reduce{ + .axis=axis + , .dtype=dtype + , .initial=initial + , .keepdims=keepdims + , .op=view::multiply_t{} + }]; + + NMTOOLS_ASSERT_EQUAL( function, expected ); + NMTOOLS_ASSERT_CLOSE( function (a), expect::result ); +} + +TEST_CASE("reduce_multiply" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,reduce_multiply,case9); + using namespace args; + + auto array = view::reduce_multiply(a,kwargs::reduce{ + .axis=axis + , .dtype=dtype + , .initial=initial + , .keepdims=keepdims + }); + + auto function = fn::get_function_composition(array); + auto expected = fn::reduce[kwargs::reduce{ + .axis=axis + , .dtype=dtype + , .initial=initial + , .keepdims=keepdims + , .op=view::multiply_t{} + }]; + + NMTOOLS_ASSERT_EQUAL( function, expected ); + NMTOOLS_ASSERT_CLOSE( function (a), expect::result ); +} + +TEST_CASE("reduce_multiply" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,reduce_multiply,case9); + using namespace args; + + auto op = view::multiply_t{}; + auto array = view::reduce(a,op,kwargs::reduce{ + .axis=axis + , .dtype=dtype + , .initial=initial + , .keepdims=keepdims + }); + + auto function = fn::get_function_composition(array); + auto expected = fn::reduce[kwargs::reduce{ + .axis=axis + , .dtype=dtype + , .initial=initial + , .keepdims=keepdims + , .op=op + }]; + + NMTOOLS_ASSERT_EQUAL( function, expected ); + NMTOOLS_ASSERT_CLOSE( function (a), expect::result ); +} + +TEST_CASE("reduce_multiply" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,reduce_multiply,case9); + using namespace args; + + auto op = view::multiply_t{}; + auto array = view::reduce(a,op,kwargs::reduce{ + .axis=axis + , .dtype=dtype + , .initial=initial + , .keepdims=keepdims + }); + + auto function = fn::get_function_composition(array); + auto expected = fn::reduce[op][kwargs::reduce{ + .axis=axis + , .dtype=dtype + , .initial=initial + , .keepdims=keepdims + }]; + + NMTOOLS_ASSERT_EQUAL( function, expected ); + NMTOOLS_ASSERT_CLOSE( function (a), expect::result ); +} + +#endif // __clang__ +#endif // NMTOOLS_TESTING_KWARGS_INIT \ No newline at end of file diff --git a/tests/functional/src/ufuncs/negative.cpp b/tests/functional/src/ufuncs/negative.cpp index 530dc2ac3..9faec8ad9 100644 --- a/tests/functional/src/ufuncs/negative.cpp +++ b/tests/functional/src/ufuncs/negative.cpp @@ -38,5 +38,18 @@ TEST_CASE("negative" * doctest::test_suite("functional::get_function_composition auto function = fn::get_function_composition(array); auto expect = fn::negative; + NMTOOLS_ASSERT_EQUAL( function, expect ); +} + +TEST_CASE("negative" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,negative,case1); + using namespace args; + + auto array = view::negative(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/positive.cpp b/tests/functional/src/ufuncs/positive.cpp index d166e23f6..19694e0ae 100644 --- a/tests/functional/src/ufuncs/positive.cpp +++ b/tests/functional/src/ufuncs/positive.cpp @@ -37,5 +37,18 @@ TEST_CASE("positive" * doctest::test_suite("functional::get_function_composition auto function = fn::get_function_composition(array); auto expect = fn::positive; + NMTOOLS_ASSERT_EQUAL( function, expect ); +} + +TEST_CASE("positive" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,positive,case1); + using namespace args; + + auto array = view::positive(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/reciprocal.cpp b/tests/functional/src/ufuncs/reciprocal.cpp index a373f7d8f..f3da6ab5f 100644 --- a/tests/functional/src/ufuncs/reciprocal.cpp +++ b/tests/functional/src/ufuncs/reciprocal.cpp @@ -37,5 +37,18 @@ TEST_CASE("reciprocal" * doctest::test_suite("functional::get_function_compositi auto function = fn::get_function_composition(array); auto expect = fn::reciprocal; + NMTOOLS_ASSERT_EQUAL( function, expect ); +} + +TEST_CASE("reciprocal" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,reciprocal,case1); + using namespace args; + + auto array = view::reciprocal(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/rint.cpp b/tests/functional/src/ufuncs/rint.cpp index a6c2c32ee..c37501dde 100644 --- a/tests/functional/src/ufuncs/rint.cpp +++ b/tests/functional/src/ufuncs/rint.cpp @@ -37,5 +37,18 @@ TEST_CASE("rint" * doctest::test_suite("functional::get_function_composition")) auto function = fn::get_function_composition(array); auto expect = fn::rint; + NMTOOLS_ASSERT_EQUAL( function, expect ); +} + +TEST_CASE("rint" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,rint,case1); + using namespace args; + + auto array = view::rint(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/signbit.cpp b/tests/functional/src/ufuncs/signbit.cpp index 36f383533..f09f23358 100644 --- a/tests/functional/src/ufuncs/signbit.cpp +++ b/tests/functional/src/ufuncs/signbit.cpp @@ -37,5 +37,18 @@ TEST_CASE("signbit" * doctest::test_suite("functional::get_function_composition" auto function = fn::get_function_composition(array); auto expect = fn::signbit; + NMTOOLS_ASSERT_EQUAL( function, expect ); +} + +TEST_CASE("signbit" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,signbit,case1); + using namespace args; + + auto array = view::signbit(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/sin.cpp b/tests/functional/src/ufuncs/sin.cpp index 54649673a..9b8c79bf2 100644 --- a/tests/functional/src/ufuncs/sin.cpp +++ b/tests/functional/src/ufuncs/sin.cpp @@ -37,5 +37,18 @@ TEST_CASE("sin" * doctest::test_suite("functional::get_function_composition")) auto function = fn::get_function_composition(array); auto expect = fn::sin; + NMTOOLS_ASSERT_EQUAL( function, expect ); +} + +TEST_CASE("sin" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,sin,case1); + using namespace args; + + auto array = view::sin(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/sinh.cpp b/tests/functional/src/ufuncs/sinh.cpp index d18903d9d..16085d92a 100644 --- a/tests/functional/src/ufuncs/sinh.cpp +++ b/tests/functional/src/ufuncs/sinh.cpp @@ -41,5 +41,18 @@ TEST_CASE("sinh" * doctest::test_suite("functional::get_function_composition")) auto function = fn::get_function_composition(array); auto expect = fn::sinh; + NMTOOLS_ASSERT_EQUAL( function, expect ); +} + +TEST_CASE("sinh" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,sinh,case1); + using namespace args; + + auto array = view::sinh(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/sqrt.cpp b/tests/functional/src/ufuncs/sqrt.cpp index 369f6833c..b534d69f4 100644 --- a/tests/functional/src/ufuncs/sqrt.cpp +++ b/tests/functional/src/ufuncs/sqrt.cpp @@ -37,5 +37,18 @@ TEST_CASE("sqrt" * doctest::test_suite("functional::get_function_composition")) auto function = fn::get_function_composition(array); auto expect = fn::sqrt; + NMTOOLS_ASSERT_EQUAL( function, expect ); +} + +TEST_CASE("sqrt" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,sqrt,case1); + using namespace args; + + auto array = view::sqrt(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/tan.cpp b/tests/functional/src/ufuncs/tan.cpp index 38fa0910c..c1987a324 100644 --- a/tests/functional/src/ufuncs/tan.cpp +++ b/tests/functional/src/ufuncs/tan.cpp @@ -37,5 +37,18 @@ TEST_CASE("tan" * doctest::test_suite("functional::get_function_composition")) auto function = fn::get_function_composition(array); auto expect = fn::tan; + NMTOOLS_ASSERT_EQUAL( function, expect ); +} + +TEST_CASE("tan" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,tan,case1); + using namespace args; + + auto array = view::tan(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/functional/src/ufuncs/tanh.cpp b/tests/functional/src/ufuncs/tanh.cpp index 05d1880d4..a070c58ca 100644 --- a/tests/functional/src/ufuncs/tanh.cpp +++ b/tests/functional/src/ufuncs/tanh.cpp @@ -37,5 +37,18 @@ TEST_CASE("tanh" * doctest::test_suite("functional::get_function_composition")) auto function = fn::get_function_composition(array); auto expect = fn::tanh; + NMTOOLS_ASSERT_EQUAL( function, expect ); +} + +TEST_CASE("tanh" * doctest::test_suite("functional::get_function_composition")) +{ + NMTOOLS_TESTING_DECLARE_NS(view,tanh,case1); + using namespace args; + + auto array = view::tanh(a); + + auto function = fn::get_function_composition(array); + auto expect = fn::unary_ufunc[array.attributes()]; + NMTOOLS_ASSERT_EQUAL( function, expect ); } \ No newline at end of file diff --git a/tests/meta/array/eval/reduce.cpp b/tests/meta/array/eval/reduce.cpp index ec35e0472..e04e06b94 100644 --- a/tests/meta/array/eval/reduce.cpp +++ b/tests/meta/array/eval/reduce.cpp @@ -19,25 +19,25 @@ TEST_CASE("eval(reduce)" * doctest::test_suite("eval")) SUBCASE("add") { { - using view_t = view::decorator_t< view::reduce_t, view::add_t<>, int[2][3], none_t, none_t, none_t>; + using view_t = view::decorator_t< view::reduce_t, view::add_t<>, int[2][3], none_t, none_t, none_t, none_t>; using eval_t = meta::resolve_optype_t< na::eval_result_t<>, view_t, none_t >; using expected_t = int; NMTOOLS_STATIC_CHECK_IS_SAME( eval_t, expected_t ); } { - using view_t = view::decorator_t< view::reduce_t, view::add_t<>, int[2][3], int, none_t, none_t>; + using view_t = view::decorator_t< view::reduce_t, view::add_t<>, int[2][3], int, none_t, none_t, none_t>; using eval_t = meta::resolve_optype_t< na::eval_result_t<>, view_t, none_t >; using expected_t = na::ndarray_t,nmtools_array>; NMTOOLS_STATIC_CHECK_IS_SAME( eval_t, expected_t ); } { - using view_t = view::decorator_t< view::reduce_t, view::add_t<>, na::hybrid_ndarray, none_t, none_t, none_t >; + using view_t = view::decorator_t< view::reduce_t, view::add_t<>, na::hybrid_ndarray, none_t, none_t, none_t, none_t >; using eval_t = meta::resolve_optype_t< na::eval_result_t<>, view_t, none_t >; using expected_t = int; NMTOOLS_STATIC_CHECK_IS_SAME( eval_t, expected_t ); } { - using view_t = view::decorator_t< view::reduce_t, view::add_t<>, na::hybrid_ndarray, int, none_t, none_t >; + using view_t = view::decorator_t< view::reduce_t, view::add_t<>, na::hybrid_ndarray, int, none_t, none_t, none_t >; using eval_t = meta::resolve_optype_t< na::eval_result_t<>, view_t, none_t >; using expected_t = na::ndarray_t,nmtools_array>; NMTOOLS_STATIC_CHECK_IS_SAME( eval_t, expected_t ); @@ -49,7 +49,7 @@ TEST_CASE("eval(reduce)" * doctest::test_suite("eval")) { using array_t = int[2][3]; using axis_t = decltype(0_ct); - using view_t = view::decorator_t< view::reduce_t, view::add_t<>, array_t, axis_t, none_t, none_t>; + using view_t = view::decorator_t< view::reduce_t, view::add_t<>, array_t, axis_t, none_t, none_t, none_t>; using eval_t = meta::resolve_optype_t< na::eval_result_t<>, view_t, none_t >; using expected_t = na::ndarray_t,decltype(nmtools_tuple{3_ct})>; NMTOOLS_STATIC_CHECK_IS_SAME( eval_t, expected_t ); @@ -57,7 +57,7 @@ TEST_CASE("eval(reduce)" * doctest::test_suite("eval")) { using array_t = nmtools_array,2>; using axis_t = decltype(0_ct); - using view_t = view::decorator_t< view::reduce_t, view::add_t<>, array_t, axis_t, none_t, none_t>; + using view_t = view::decorator_t< view::reduce_t, view::add_t<>, array_t, axis_t, none_t, none_t, none_t>; using eval_t = meta::resolve_optype_t< na::eval_result_t<>, view_t, none_t >; using expected_t = na::ndarray_t,decltype(nmtools_tuple{3_ct})>; NMTOOLS_STATIC_CHECK_IS_SAME( eval_t, expected_t ); @@ -66,7 +66,7 @@ TEST_CASE("eval(reduce)" * doctest::test_suite("eval")) { using array_t = na::fixed_ndarray; using axis_t = decltype(0_ct); - using view_t = view::decorator_t< view::reduce_t, view::add_t<>, array_t, axis_t, none_t, none_t>; + using view_t = view::decorator_t< view::reduce_t, view::add_t<>, array_t, axis_t, none_t, none_t, none_t>; using eval_t = meta::resolve_optype_t< na::eval_result_t<>, view_t, none_t >; using expected_t = na::ndarray_t,decltype(nmtools_tuple{3_ct})>; NMTOOLS_STATIC_CHECK_IS_SAME( eval_t, expected_t ); @@ -74,7 +74,7 @@ TEST_CASE("eval(reduce)" * doctest::test_suite("eval")) { using array_t = na::hybrid_ndarray; using axis_t = decltype(0_ct); - using view_t = view::decorator_t< view::reduce_t, view::add_t<>, array_t, axis_t, none_t, none_t >; + using view_t = view::decorator_t< view::reduce_t, view::add_t<>, array_t, axis_t, none_t, none_t, none_t >; using eval_t = meta::resolve_optype_t< na::eval_result_t<>, view_t, none_t >; using expected_t = na::ndarray_t,nmtools_array>; NMTOOLS_STATIC_CHECK_IS_SAME( eval_t, expected_t ); @@ -82,7 +82,7 @@ TEST_CASE("eval(reduce)" * doctest::test_suite("eval")) { using array_t = na::dynamic_ndarray; using axis_t = decltype(0_ct); - using view_t = view::decorator_t< view::reduce_t, view::add_t<>, array_t, axis_t, none_t, none_t >; + using view_t = view::decorator_t< view::reduce_t, view::add_t<>, array_t, axis_t, none_t, none_t, none_t >; using eval_t = meta::resolve_optype_t< na::eval_result_t<>, view_t, none_t >; using expected_t = na::ndarray_t,nmtools_list>; NMTOOLS_STATIC_CHECK_IS_SAME( eval_t, expected_t ); diff --git a/tests/meta/array/eval/ufunc.cpp b/tests/meta/array/eval/ufunc.cpp index 36a6a43bf..a84e31eae 100644 --- a/tests/meta/array/eval/ufunc.cpp +++ b/tests/meta/array/eval/ufunc.cpp @@ -3,9 +3,7 @@ #include "nmtools/array/view/ufuncs/add.hpp" #include "nmtools/array/view/ufuncs/sin.hpp" #include "nmtools/array/view/ufuncs/clip.hpp" -#include "nmtools/array/ndarray/fixed.hpp" -#include "nmtools/array/ndarray/hybrid.hpp" -#include "nmtools/array/ndarray/dynamic.hpp" +#include "nmtools/array/ndarray.hpp" #include "nmtools/testing/doctest.hpp" namespace nm = nmtools; @@ -162,7 +160,7 @@ TEST_CASE("eval(ufunc)" * doctest::test_suite("eval")) TEST_CASE("eval(outer_ufunc)" * doctest::test_suite("eval")) { { - using view_t = view::decorator_t, int [2][3], int [3]>; + using view_t = view::decorator_t, int [2][3], int [3], none_t>; using eval_t = meta::resolve_optype_t< na::eval_result_t<>, view_t, none_t >; using expected_t = na::ndarray_t,decltype(nmtools_tuple{2_ct,3_ct,3_ct})>; NMTOOLS_STATIC_CHECK_IS_SAME( eval_t, expected_t ); @@ -171,7 +169,7 @@ TEST_CASE("eval(outer_ufunc)" * doctest::test_suite("eval")) { using lhs_t = na::hybrid_ndarray; using rhs_t = na::hybrid_ndarray; - using view_t = view::decorator_t< view::outer_t, view::add_t<>, lhs_t, rhs_t >; + using view_t = view::decorator_t< view::outer_t, view::add_t<>, lhs_t, rhs_t, none_t >; using eval_t = meta::resolve_optype_t< na::eval_result_t<>, view_t, none_t >; using expected_t = na::ndarray_t,nmtools_array>; NMTOOLS_STATIC_CHECK_IS_SAME( eval_t, expected_t ); @@ -185,7 +183,7 @@ TEST_CASE("eval(outer_ufunc)" * doctest::test_suite("eval")) { using lhs_t = na::ndarray_t, nmtools_array>; using rhs_t = na::ndarray_t, nmtools_array>; - using view_t = view::decorator_t< view::outer_t, view::add_t<>, lhs_t, rhs_t >; + using view_t = view::decorator_t< view::outer_t, view::add_t<>, lhs_t, rhs_t, none_t >; using eval_t = meta::resolve_optype_t< na::eval_result_t<>, view_t, none_t >; using expected_t = na::ndarray_t,nmtools_array>; NMTOOLS_STATIC_CHECK_IS_SAME( eval_t, expected_t ); @@ -193,7 +191,7 @@ TEST_CASE("eval(outer_ufunc)" * doctest::test_suite("eval")) { using lhs_t = na::ndarray_t, na::static_vector>; using rhs_t = na::ndarray_t, na::static_vector>; - using view_t = view::decorator_t< view::outer_t, view::add_t<>, lhs_t, rhs_t >; + using view_t = view::decorator_t< view::outer_t, view::add_t<>, lhs_t, rhs_t, none_t >; using eval_t = meta::resolve_optype_t< na::eval_result_t<>, view_t, none_t >; using expected_t = na::ndarray_t,na::static_vector>; NMTOOLS_STATIC_CHECK_IS_SAME( eval_t, expected_t ); @@ -202,7 +200,7 @@ TEST_CASE("eval(outer_ufunc)" * doctest::test_suite("eval")) using lhs_shape_t = nmtools_tuple,nm::clipped_size_t<3>>; using lhs_t = na::ndarray_t, lhs_shape_t>; using rhs_t = na::ndarray_t, na::static_vector>; - using view_t = view::decorator_t< view::outer_t, view::add_t<>, lhs_t, rhs_t >; + using view_t = view::decorator_t< view::outer_t, view::add_t<>, lhs_t, rhs_t, none_t >; using eval_t = meta::resolve_optype_t< na::eval_result_t<>, view_t, none_t >; using expected_t = na::ndarray_t,na::static_vector>; NMTOOLS_STATIC_CHECK_IS_SAME( eval_t, expected_t ); diff --git a/tests/meta/array/view/broadcast_to.cpp b/tests/meta/array/view/broadcast_to.cpp index 76d31b2f3..955fe2f72 100644 --- a/tests/meta/array/view/broadcast_to.cpp +++ b/tests/meta/array/view/broadcast_to.cpp @@ -32,41 +32,41 @@ TEST_CASE("is_fixed_shape" * doctest::test_suite("view")) { // reduce add, as needed by mean view { - using op_t = view::add_t; + using op_t = view::add_t; using array_t = int[3][2]; - using view_t = view::decorator_t; + using view_t = view::decorator_t; using shape_t = nmtools_tuple >; using broadcasted_t = decltype(view::broadcast_to(declval(view_t),declval(shape_t))); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_shape, broadcasted_t ); } { - using op_t = view::add_t; + using op_t = view::add_t; using array_t = nmtools_array,3>; - using view_t = view::decorator_t; + using view_t = view::decorator_t; using shape_t = nmtools_tuple >; using broadcasted_t = decltype(view::broadcast_to(declval(view_t),declval(shape_t))); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_shape, broadcasted_t ); } { - using op_t = view::add_t; + using op_t = view::add_t; using array_t = na::fixed_ndarray; - using view_t = view::decorator_t; + using view_t = view::decorator_t; using shape_t = nmtools_tuple >; using broadcasted_t = decltype(view::broadcast_to(declval(view_t),declval(shape_t))); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_shape, broadcasted_t ); } { - using op_t = view::add_t; + using op_t = view::add_t; using array_t = na::hybrid_ndarray; - using view_t = view::decorator_t; + using view_t = view::decorator_t; using shape_t = nmtools_tuple >; using broadcasted_t = decltype(view::broadcast_to(declval(view_t),declval(shape_t))); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_shape, broadcasted_t ); } { - using op_t = view::add_t; + using op_t = view::add_t; using array_t = na::dynamic_ndarray; - using view_t = view::decorator_t; + using view_t = view::decorator_t; using shape_t = nmtools_tuple >; using broadcasted_t = decltype(view::broadcast_to(declval(view_t),declval(shape_t))); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_shape, broadcasted_t ); diff --git a/tests/meta/array/view/reduce.cpp b/tests/meta/array/view/reduce.cpp index aa7bbd9e3..c7ef032bf 100644 --- a/tests/meta/array/view/reduce.cpp +++ b/tests/meta/array/view/reduce.cpp @@ -28,49 +28,49 @@ TEST_CASE("is_fixed_shape" * doctest::test_suite("view::reduce")) { // reduce add, as needed by mean view { - using op_t = view::add_t; + using op_t = view::add_t; using array_t = int[3][2]; using axis_t = decltype(0_ct); - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_shape, view_t ); } { - using op_t = view::add_t; + using op_t = view::add_t; using array_t = na::fixed_ndarray; using axis_t = decltype(0_ct); - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_shape, view_t ); } { - using op_t = view::add_t; + using op_t = view::add_t; using array_t = nmtools_array,3>; using axis_t = decltype(0_ct); - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_shape, view_t ); } { - using op_t = view::add_t; + using op_t = view::add_t; using array_t = na::hybrid_ndarray; using axis_t = decltype(0_ct); - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_shape, view_t ); } { - using op_t = view::add_t; + using op_t = view::add_t; using array_t = na::dynamic_ndarray; using axis_t = decltype(0_ct); - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_shape, view_t ); } // keepdims { - using op_t = view::add_t; + using op_t = view::add_t; using array_t = int[3][2]; using axis_t = none_t; using dtype_t = none_t; using keepdims_t = true_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_shape, view_t ); } } @@ -79,28 +79,28 @@ TEST_CASE("fixed_ndarray_shape" * doctest::test_suite("view::reduce")) { // reduce add, as needed by mean view { - using op_t = view::add_t; + using op_t = view::add_t; using array_t = int[3][2]; using axis_t = decltype(0_ct); - using view_t = view::decorator_t; + using view_t = view::decorator_t; constexpr auto shape = meta::fixed_shape_v; constexpr auto expected = nmtools_array{2ul}; NMTOOLS_STATIC_ASSERT_EQUAL( shape, expected ); } { - using op_t = view::add_t; + using op_t = view::add_t; using array_t = na::fixed_ndarray; using axis_t = decltype(0_ct); - using view_t = view::decorator_t; + using view_t = view::decorator_t; constexpr auto shape = meta::fixed_shape_v; constexpr auto expected = nmtools_array{2ul}; NMTOOLS_STATIC_ASSERT_EQUAL( shape, expected ); } { - using op_t = view::add_t; + using op_t = view::add_t; using array_t = nmtools_array,3>; using axis_t = decltype(0_ct); - using view_t = view::decorator_t; + using view_t = view::decorator_t; constexpr auto shape = meta::fixed_shape_v; constexpr auto expected = nmtools_array{2ul}; NMTOOLS_STATIC_ASSERT_EQUAL( shape, expected ); @@ -110,38 +110,38 @@ TEST_CASE("fixed_ndarray_shape" * doctest::test_suite("view::reduce")) TEST_CASE("is_fixed_dim_ndarray" * doctest::test_suite("view::reduce")) { { - using op_t = view::add_t; + using op_t = view::add_t; using array_t = int[3][2]; using axis_t = decltype(0_ct); - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_dim_ndarray, view_t ); } { - using op_t = view::add_t; + using op_t = view::add_t; using array_t = na::fixed_ndarray; using axis_t = decltype(0_ct); - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_dim_ndarray, view_t ); } { - using op_t = view::add_t; + using op_t = view::add_t; using array_t = nmtools_array,3>; using axis_t = decltype(0_ct); - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_dim_ndarray, view_t ); } { - using op_t = view::add_t; + using op_t = view::add_t; using array_t = na::hybrid_ndarray; using axis_t = decltype(0_ct); - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_dim_ndarray, view_t ); } { - using op_t = view::add_t; + using op_t = view::add_t; using array_t = na::dynamic_ndarray; using axis_t = decltype(0_ct); - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_dim_ndarray, view_t ); } } diff --git a/tests/meta/array/view/ufunc.cpp b/tests/meta/array/view/ufunc.cpp index 3b60b9da3..5a03ee836 100644 --- a/tests/meta/array/view/ufunc.cpp +++ b/tests/meta/array/view/ufunc.cpp @@ -52,63 +52,63 @@ TEST_CASE("reduce" * doctest::test_suite("view")) using array_t = int[2][3][2]; using axis_t = none_t; using keepdims_t = meta::true_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_dim_ndarray, view_t ); } { using array_t = int[2][3][2]; using axis_t = none_t; using keepdims_t = meta::false_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_dim_ndarray, view_t ); } { using array_t = int[2][3][2]; using axis_t = int; using keepdims_t = meta::true_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_dim_ndarray, view_t ); } { using array_t = int[2][3][2]; using axis_t = int; using keepdims_t = meta::false_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_dim_ndarray, view_t ); } { using array_t = int[2][3][2]; using axis_t = none_t; using keepdims_t = meta::false_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_dim_ndarray, view_t ); } { using array_t = int[2][3][2]; using axis_t = int[3]; using keepdims_t = meta::true_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_dim_ndarray, view_t ); } { using array_t = int[2][3][2]; using axis_t = int[3]; using keepdims_t = meta::false_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_dim_ndarray, view_t ); } { using array_t = int[2][3][2]; using axis_t = int[2]; using keepdims_t = meta::false_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_dim_ndarray, view_t ); } { using array_t = int[2][3][2]; using axis_t = int[3]; using keepdims_t = meta::false_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_dim_ndarray, view_t ); } @@ -116,42 +116,42 @@ TEST_CASE("reduce" * doctest::test_suite("view")) using array_t = nmtools_array,3>,2>; using axis_t = none_t; using keepdims_t = meta::true_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_dim_ndarray, view_t ); } { using array_t = nmtools_array,3>,2>; using axis_t = none_t; using keepdims_t = meta::false_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_dim_ndarray, view_t ); } { using array_t = nmtools_array,3>,2>; using axis_t = int[3]; using keepdims_t = meta::true_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_dim_ndarray, view_t ); } { using array_t = nmtools_array,3>,2>; using axis_t = int[3]; using keepdims_t = meta::false_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_dim_ndarray, view_t ); } { using array_t = nmtools_array,3>,2>; using axis_t = int[2]; using keepdims_t = meta::false_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_dim_ndarray, view_t ); } { using array_t = nmtools_array,3>,2>; using axis_t = int[3]; using keepdims_t = meta::false_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_dim_ndarray, view_t ); } } @@ -164,7 +164,7 @@ TEST_CASE("reduce" * doctest::test_suite("view")) using array_t = int[2][3][2]; using axis_t = none_t; using keepdims_t = meta::false_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT( meta::is_num, view_t ); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_ndarray, view_t ); } @@ -172,7 +172,7 @@ TEST_CASE("reduce" * doctest::test_suite("view")) using array_t = int[2][3][2]; using axis_t = none_t; using keepdims_t = meta::true_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_num, view_t ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_ndarray, view_t ); } @@ -180,7 +180,7 @@ TEST_CASE("reduce" * doctest::test_suite("view")) using array_t = int[2][3][2]; using axis_t = int; using keepdims_t = meta::false_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_num, view_t ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_ndarray, view_t ); } @@ -188,7 +188,7 @@ TEST_CASE("reduce" * doctest::test_suite("view")) using array_t = int[2][3][2]; using axis_t = int; using keepdims_t = meta::true_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_num, view_t ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_ndarray, view_t ); } @@ -196,7 +196,7 @@ TEST_CASE("reduce" * doctest::test_suite("view")) using array_t = int[2]; using axis_t = int; using keepdims_t = meta::false_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT( meta::is_num, view_t ); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_ndarray, view_t ); } @@ -204,7 +204,7 @@ TEST_CASE("reduce" * doctest::test_suite("view")) using array_t = int[2]; using axis_t = int; using keepdims_t = meta::true_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_num, view_t ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_ndarray, view_t ); } @@ -212,7 +212,7 @@ TEST_CASE("reduce" * doctest::test_suite("view")) using array_t = int[2][3][2]; using axis_t = int[3]; using keepdims_t = meta::false_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT( meta::is_num, view_t ); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_ndarray, view_t ); } @@ -220,7 +220,7 @@ TEST_CASE("reduce" * doctest::test_suite("view")) using array_t = int[2][3][2]; using axis_t = int[3]; using keepdims_t = meta::true_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_num, view_t ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_ndarray, view_t ); } @@ -228,7 +228,7 @@ TEST_CASE("reduce" * doctest::test_suite("view")) using array_t = int[2][3][2]; using axis_t = int[2]; using keepdims_t = meta::false_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_num, view_t ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_ndarray, view_t ); } @@ -236,7 +236,7 @@ TEST_CASE("reduce" * doctest::test_suite("view")) using array_t = int[2][3][2]; using axis_t = int[1]; using keepdims_t = meta::false_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_num, view_t ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_ndarray, view_t ); } @@ -245,7 +245,7 @@ TEST_CASE("reduce" * doctest::test_suite("view")) using array_t = na::fixed_ndarray; using axis_t = none_t; using keepdims_t = meta::false_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT( meta::is_num, view_t ); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_ndarray, view_t ); } @@ -253,7 +253,7 @@ TEST_CASE("reduce" * doctest::test_suite("view")) using array_t = na::fixed_ndarray; using axis_t = none_t; using keepdims_t = meta::true_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_num, view_t ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_ndarray, view_t ); } @@ -261,7 +261,7 @@ TEST_CASE("reduce" * doctest::test_suite("view")) using array_t = na::fixed_ndarray; using axis_t = int[3]; using keepdims_t = meta::false_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT( meta::is_num, view_t ); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_ndarray, view_t ); } @@ -269,7 +269,7 @@ TEST_CASE("reduce" * doctest::test_suite("view")) using array_t = na::fixed_ndarray; using axis_t = int[3]; using keepdims_t = meta::true_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_num, view_t ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_ndarray, view_t ); } @@ -277,7 +277,7 @@ TEST_CASE("reduce" * doctest::test_suite("view")) using array_t = na::fixed_ndarray; using axis_t = nmtools_array; using keepdims_t = meta::false_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT( meta::is_num, view_t ); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_ndarray, view_t ); } @@ -285,7 +285,7 @@ TEST_CASE("reduce" * doctest::test_suite("view")) using array_t = na::fixed_ndarray; using axis_t = nmtools_array; using keepdims_t = meta::true_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_num, view_t ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_ndarray, view_t ); } @@ -293,7 +293,7 @@ TEST_CASE("reduce" * doctest::test_suite("view")) using array_t = na::fixed_ndarray; using axis_t = int[2]; using keepdims_t = meta::false_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_num, view_t ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_ndarray, view_t ); } @@ -301,7 +301,7 @@ TEST_CASE("reduce" * doctest::test_suite("view")) using array_t = na::fixed_ndarray; using axis_t = int[1]; using keepdims_t = meta::false_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_num, view_t ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_ndarray, view_t ); } @@ -310,7 +310,7 @@ TEST_CASE("reduce" * doctest::test_suite("view")) using array_t = na::hybrid_ndarray; using axis_t = none_t; using keepdims_t = meta::false_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT( meta::is_num, view_t ); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_ndarray, view_t ); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_bounded_size, view_t ); @@ -319,7 +319,7 @@ TEST_CASE("reduce" * doctest::test_suite("view")) using array_t = na::hybrid_ndarray; using axis_t = none_t; using keepdims_t = meta::true_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_num, view_t ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_ndarray, view_t ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_bounded_size, view_t ); @@ -328,7 +328,7 @@ TEST_CASE("reduce" * doctest::test_suite("view")) using array_t = na::hybrid_ndarray; using axis_t = int[3]; using keepdims_t = meta::false_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT( meta::is_num, view_t ); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_ndarray, view_t ); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_bounded_size, view_t ); @@ -337,7 +337,7 @@ TEST_CASE("reduce" * doctest::test_suite("view")) using array_t = na::hybrid_ndarray; using axis_t = int[3]; using keepdims_t = meta::true_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_num, view_t ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_ndarray, view_t ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_bounded_size, view_t ); @@ -346,7 +346,7 @@ TEST_CASE("reduce" * doctest::test_suite("view")) using array_t = na::hybrid_ndarray; using axis_t = nmtools_array; using keepdims_t = meta::false_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT( meta::is_num, view_t ); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_ndarray, view_t ); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_bounded_size, view_t ); @@ -355,7 +355,7 @@ TEST_CASE("reduce" * doctest::test_suite("view")) using array_t = na::hybrid_ndarray; using axis_t = nmtools_array; using keepdims_t = meta::true_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_num, view_t ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_ndarray, view_t ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_bounded_size, view_t ); @@ -364,7 +364,7 @@ TEST_CASE("reduce" * doctest::test_suite("view")) using array_t = na::hybrid_ndarray; using axis_t = int[2]; using keepdims_t = meta::false_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_num, view_t ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_ndarray, view_t ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_bounded_size, view_t ); @@ -373,7 +373,7 @@ TEST_CASE("reduce" * doctest::test_suite("view")) using array_t = na::hybrid_ndarray; using axis_t = int[1]; using keepdims_t = meta::false_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_num, view_t ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_ndarray, view_t ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_bounded_size, view_t ); @@ -383,7 +383,7 @@ TEST_CASE("reduce" * doctest::test_suite("view")) using array_t = nmtools_array,3>,2>; using axis_t = none_t; using keepdims_t = meta::false_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT( meta::is_num, view_t ); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_ndarray, view_t ); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_bounded_size, view_t ); @@ -392,7 +392,7 @@ TEST_CASE("reduce" * doctest::test_suite("view")) using array_t = nmtools_array,3>,2>; using axis_t = none_t; using keepdims_t = meta::true_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_num, view_t ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_ndarray, view_t ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_bounded_size, view_t ); @@ -401,7 +401,7 @@ TEST_CASE("reduce" * doctest::test_suite("view")) using array_t = nmtools_array,3>,2>; using axis_t = nmtools_array; using keepdims_t = meta::false_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT( meta::is_num, view_t ); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_ndarray, view_t ); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_bounded_size, view_t ); @@ -410,7 +410,7 @@ TEST_CASE("reduce" * doctest::test_suite("view")) using array_t = nmtools_array,3>,2>; using axis_t = nmtools_array; using keepdims_t = meta::true_type; - using view_t = view::decorator_t; + using view_t = view::decorator_t; NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_num, view_t ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_ndarray, view_t ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_bounded_size, view_t ); @@ -454,7 +454,7 @@ TEST_CASE("is_fixed_size_ndarray" * doctest::test_suite("view")) { { // divide * reduce_add - using lhs_t = view::decorator_t, int[3][2], size_t, none_t, false_type>; + using lhs_t = view::decorator_t, int[3][2], size_t, none_t, false_type, none_t>; using rhs_t = size_t; // using view_t = decltype(view::divide(declval(lhs_t),declval(rhs_t))); using view_t = view::decorator_t< view::ufunc_t, view::divide_t, lhs_t, rhs_t >; @@ -462,7 +462,7 @@ TEST_CASE("is_fixed_size_ndarray" * doctest::test_suite("view")) } { // divide * reduce_add - using lhs_t = view::decorator_t, int[3][2], size_t, none_t, false_type>; + using lhs_t = view::decorator_t, int[3][2], size_t, none_t, false_type, none_t>; using rhs_t = size_t; using view_t = decltype(view::divide(declval(lhs_t),declval(rhs_t))); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_size_ndarray, view_t ); @@ -471,7 +471,7 @@ TEST_CASE("is_fixed_size_ndarray" * doctest::test_suite("view")) SUBCASE("multiply") { { - using lhs_t = view::decorator_t, int[3][2], size_t, none_t, false_type>; + using lhs_t = view::decorator_t, int[3][2], size_t, none_t, false_type, none_t>; using rhs_t = size_t; using view_t = decltype(view::multiply(declval(lhs_t),declval(rhs_t))); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_size_ndarray, view_t );