From e4ecebc23be54b19d496e241492710b3accde230 Mon Sep 17 00:00:00 2001 From: Fahri Ali Rahman Date: Sun, 13 Oct 2024 00:30:35 +0700 Subject: [PATCH] Add radians, degrees, and dstack (#300) * add Pi constants * add radians & degrees * add dstack & column_stack * update tests * fix gcc werror --- include/nmtools/array/array/column_stack.hpp | 24 ++ include/nmtools/array/array/dstack.hpp | 24 ++ .../nmtools/array/array/ufuncs/deg2rad.hpp | 24 ++ .../nmtools/array/array/ufuncs/degrees.hpp | 24 ++ .../nmtools/array/array/ufuncs/rad2deg.hpp | 24 ++ .../nmtools/array/array/ufuncs/radians.hpp | 24 ++ include/nmtools/array/view/column_stack.hpp | 115 +++++++ include/nmtools/array/view/dstack.hpp | 119 ++++++++ include/nmtools/array/view/ufuncs/deg2rad.hpp | 18 ++ include/nmtools/array/view/ufuncs/degrees.hpp | 18 ++ include/nmtools/array/view/ufuncs/rad2deg.hpp | 18 ++ include/nmtools/array/view/ufuncs/radians.hpp | 18 ++ include/nmtools/constants.hpp | 10 + .../testing/data/array/column_stack.hpp | 95 ++++++ .../nmtools/testing/data/array/deg2rad.hpp | 44 +++ .../nmtools/testing/data/array/degrees.hpp | 44 +++ include/nmtools/testing/data/array/dstack.hpp | 285 ++++++++++++++++++ .../nmtools/testing/data/array/rad2deg.hpp | 44 +++ .../nmtools/testing/data/array/radians.hpp | 44 +++ tests/array/CMakeLists.txt | 6 + tests/array/array/column_stack.cpp | 39 +++ tests/array/array/dstack.cpp | 57 ++++ tests/array/array/ufuncs/deg2rad.cpp | 79 +++++ tests/array/array/ufuncs/degrees.cpp | 81 +++++ tests/array/array/ufuncs/rad2deg.cpp | 81 +++++ tests/array/array/ufuncs/radians.cpp | 79 +++++ tests/view/CMakeLists.txt | 6 + tests/view/src/column_stack.cpp | 39 +++ tests/view/src/concatenate.cpp | 33 +- tests/view/src/dstack.cpp | 57 ++++ tests/view/src/ufuncs/deg2rad.cpp | 79 +++++ tests/view/src/ufuncs/degrees.cpp | 81 +++++ tests/view/src/ufuncs/rad2deg.cpp | 81 +++++ tests/view/src/ufuncs/radians.cpp | 79 +++++ 34 files changed, 1861 insertions(+), 32 deletions(-) create mode 100644 include/nmtools/array/array/column_stack.hpp create mode 100644 include/nmtools/array/array/dstack.hpp create mode 100644 include/nmtools/array/array/ufuncs/deg2rad.hpp create mode 100644 include/nmtools/array/array/ufuncs/degrees.hpp create mode 100644 include/nmtools/array/array/ufuncs/rad2deg.hpp create mode 100644 include/nmtools/array/array/ufuncs/radians.hpp create mode 100644 include/nmtools/array/view/column_stack.hpp create mode 100644 include/nmtools/array/view/dstack.hpp create mode 100644 include/nmtools/array/view/ufuncs/deg2rad.hpp create mode 100644 include/nmtools/array/view/ufuncs/degrees.hpp create mode 100644 include/nmtools/array/view/ufuncs/rad2deg.hpp create mode 100644 include/nmtools/array/view/ufuncs/radians.hpp create mode 100644 include/nmtools/testing/data/array/column_stack.hpp create mode 100644 include/nmtools/testing/data/array/deg2rad.hpp create mode 100644 include/nmtools/testing/data/array/degrees.hpp create mode 100644 include/nmtools/testing/data/array/dstack.hpp create mode 100644 include/nmtools/testing/data/array/rad2deg.hpp create mode 100644 include/nmtools/testing/data/array/radians.hpp create mode 100644 tests/array/array/column_stack.cpp create mode 100644 tests/array/array/dstack.cpp create mode 100644 tests/array/array/ufuncs/deg2rad.cpp create mode 100644 tests/array/array/ufuncs/degrees.cpp create mode 100644 tests/array/array/ufuncs/rad2deg.cpp create mode 100644 tests/array/array/ufuncs/radians.cpp create mode 100644 tests/view/src/column_stack.cpp create mode 100644 tests/view/src/dstack.cpp create mode 100644 tests/view/src/ufuncs/deg2rad.cpp create mode 100644 tests/view/src/ufuncs/degrees.cpp create mode 100644 tests/view/src/ufuncs/rad2deg.cpp create mode 100644 tests/view/src/ufuncs/radians.cpp diff --git a/include/nmtools/array/array/column_stack.hpp b/include/nmtools/array/array/column_stack.hpp new file mode 100644 index 000000000..f34a47592 --- /dev/null +++ b/include/nmtools/array/array/column_stack.hpp @@ -0,0 +1,24 @@ +#ifndef NMTOOLS_ARRAY_ARRAY_COLUMN_STACK_HPP +#define NMTOOLS_ARRAY_ARRAY_COLUMN_STACK_HPP + +#include "nmtools/array/view/column_stack.hpp" +#include "nmtools/array/eval.hpp" + +namespace nmtools::array +{ + template + , typename a_t, typename b_t> + constexpr auto column_stack(const a_t& a, const b_t& b + , context_t&& context=context_t{}, output_t&& output=output_t{},meta::as_value resolver=meta::as_value_v) + { + auto array = view::column_stack(a,b); + return eval( + array + , nmtools::forward(context) + , nmtools::forward(output) + , resolver + ); + } +} // nmtools::array + +#endif // NMTOOLS_ARRAY_ARRAY_COLUMN_STACK_HPP \ No newline at end of file diff --git a/include/nmtools/array/array/dstack.hpp b/include/nmtools/array/array/dstack.hpp new file mode 100644 index 000000000..f4df9b856 --- /dev/null +++ b/include/nmtools/array/array/dstack.hpp @@ -0,0 +1,24 @@ +#ifndef NMTOOLS_ARRAY_ARRAY_DSTACK_HPP +#define NMTOOLS_ARRAY_ARRAY_DSTACK_HPP + +#include "nmtools/array/view/dstack.hpp" +#include "nmtools/array/eval.hpp" + +namespace nmtools::array +{ + template + , typename a_t, typename b_t> + constexpr auto dstack(const a_t& a, const b_t& b + , context_t&& context=context_t{}, output_t&& output=output_t{},meta::as_value resolver=meta::as_value_v) + { + auto array = view::dstack(a,b); + return eval( + array + , nmtools::forward(context) + , nmtools::forward(output) + , resolver + ); + } +} // nmtools::array + +#endif // NMTOOLS_ARRAY_ARRAY_DSTACK_HPP \ No newline at end of file diff --git a/include/nmtools/array/array/ufuncs/deg2rad.hpp b/include/nmtools/array/array/ufuncs/deg2rad.hpp new file mode 100644 index 000000000..05319904e --- /dev/null +++ b/include/nmtools/array/array/ufuncs/deg2rad.hpp @@ -0,0 +1,24 @@ +#ifndef NMTOOLS_ARRAY_ARRAY_UFUNCS_DEG2RAD_HPP +#define NMTOOLS_ARRAY_ARRAY_UFUNCS_DEG2RAD_HPP + +#include "nmtools/array/view/ufuncs/deg2rad.hpp" +#include "nmtools/array/eval.hpp" + +namespace nmtools::array +{ + template + , typename array_t> + constexpr auto deg2rad(const array_t& array + , context_t&& context=context_t{}, output_t&& output=output_t{},meta::as_value resolver=meta::as_value_v) + { + auto a = view::deg2rad(array); + return eval( + a + , nmtools::forward(context) + , nmtools::forward(output) + , resolver + ); + } +} // nmtools::array + +#endif // NMTOOLS_ARRAY_ARRAY_UFUNCS_DEG2RAD_HPP \ No newline at end of file diff --git a/include/nmtools/array/array/ufuncs/degrees.hpp b/include/nmtools/array/array/ufuncs/degrees.hpp new file mode 100644 index 000000000..0d4165a9a --- /dev/null +++ b/include/nmtools/array/array/ufuncs/degrees.hpp @@ -0,0 +1,24 @@ +#ifndef NMTOOLS_ARRAY_ARRAY_UFUNCS_DEGREES_HPP +#define NMTOOLS_ARRAY_ARRAY_UFUNCS_DEGREES_HPP + +#include "nmtools/array/view/ufuncs/degrees.hpp" +#include "nmtools/array/eval.hpp" + +namespace nmtools::array +{ + template + , typename array_t> + constexpr auto degrees(const array_t& array + , context_t&& context=context_t{}, output_t&& output=output_t{},meta::as_value resolver=meta::as_value_v) + { + auto a = view::degrees(array); + return eval( + a + , nmtools::forward(context) + , nmtools::forward(output) + , resolver + ); + } +} // nmtools::array + +#endif // NMTOOLS_ARRAY_ARRAY_UFUNCS_DEGREES_HPP \ No newline at end of file diff --git a/include/nmtools/array/array/ufuncs/rad2deg.hpp b/include/nmtools/array/array/ufuncs/rad2deg.hpp new file mode 100644 index 000000000..c7242a4cd --- /dev/null +++ b/include/nmtools/array/array/ufuncs/rad2deg.hpp @@ -0,0 +1,24 @@ +#ifndef NMTOOLS_ARRAY_UFUNCS_RAD2DEG_HPP +#define NMTOOLS_ARRAY_UFUNCS_RAD2DEG_HPP + +#include "nmtools/array/view/ufuncs/rad2deg.hpp" +#include "nmtools/array/eval.hpp" + +namespace nmtools::array +{ + template + , typename array_t> + constexpr auto rad2deg(const array_t& array + , context_t&& context=context_t{}, output_t&& output=output_t{},meta::as_value resolver=meta::as_value_v) + { + auto a = view::rad2deg(array); + return eval( + a + , nmtools::forward(context) + , nmtools::forward(output) + , resolver + ); + } +} // nmtools::array + +#endif // NMTOOLS_ARRAY_UFUNCS_RAD2DEG_HPP \ No newline at end of file diff --git a/include/nmtools/array/array/ufuncs/radians.hpp b/include/nmtools/array/array/ufuncs/radians.hpp new file mode 100644 index 000000000..dd9141e12 --- /dev/null +++ b/include/nmtools/array/array/ufuncs/radians.hpp @@ -0,0 +1,24 @@ +#ifndef NMTOOLS_ARRAY_ARRAY_UFUNCS_RADIANS_HPP +#define NMTOOLS_ARRAY_ARRAY_UFUNCS_RADIANS_HPP + +#include "nmtools/array/view/ufuncs/radians.hpp" +#include "nmtools/array/eval.hpp" + +namespace nmtools::array +{ + template + , typename array_t> + constexpr auto radians(const array_t& array + , context_t&& context=context_t{}, output_t&& output=output_t{},meta::as_value resolver=meta::as_value_v) + { + auto a = view::radians(array); + return eval( + a + , nmtools::forward(context) + , nmtools::forward(output) + , resolver + ); + } +} // nmtools::array + +#endif // NMTOOLS_ARRAY_ARRAY_UFUNCS_RADIANS_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/column_stack.hpp b/include/nmtools/array/view/column_stack.hpp new file mode 100644 index 000000000..94d349bb4 --- /dev/null +++ b/include/nmtools/array/view/column_stack.hpp @@ -0,0 +1,115 @@ +#ifndef NMTOOLS_ARRAY_VIEW_COLUMN_STACK_HPP +#define NMTOOLS_ARRAY_VIEW_COLUMN_STACK_HPP + +#include "nmtools/array/shape.hpp" +#include "nmtools/meta.hpp" + +namespace nmtools::index +{ + struct column_stack_reshape_t {}; + + template + constexpr auto column_stack_reshape(const src_shape_t& src_shape) + { + using result_t = meta::resolve_optype_t; + + auto result = result_t {}; + + if constexpr (!meta::is_fail_v + && !meta::is_constant_index_array_v) + { + auto src_dim = len(src_shape); + [[maybe_unused]] + auto dst_dim = src_dim == 1 ? 2 : src_dim; + + if constexpr (meta::is_resizable_v) { + result.resize(dst_dim); + } + + if (src_dim == 1) { + at(result,meta::ct_v<0>) = at(src_shape,meta::ct_v<0>); + at(result,meta::ct_v<1>) = 1; + } else { + for (nm_size_t i=0; i<(nm_size_t)src_dim; i++) { + at(result,i) = at(src_shape,i); + } + } + } + + return result; + } +} // nmtools::index + +namespace nmtools::meta +{ + namespace error + { + template + struct COLUMN_STACK_RESHAPE_UNSUPPORTED : detail::fail_t {}; + } + + template + struct resolve_optype< + void, index::column_stack_reshape_t, src_shape_t + > { + static constexpr auto vtype = [](){ + if constexpr (!is_index_array_v) { + using type = error::COLUMN_STACK_RESHAPE_UNSUPPORTED; + return as_value_v; + } else if constexpr (is_constant_index_array_v) { + constexpr auto src_shape = to_value_v; + constexpr auto result = index::column_stack_reshape(src_shape); + using nmtools::at, nmtools::len; + return template_reduce([&](auto init, auto I){ + using init_t = type_t; + using type = append_type_t>; + return as_value_v; + }, as_value_v>); + } else { + [[maybe_unused]] + constexpr auto B_DIM = bounded_size_v; + constexpr auto DIM = len_v; + if constexpr (DIM > 0) { + using type = nmtools_array; + return as_value_v; + } else if constexpr (!is_fail_v) { + using type = nmtools_static_vector; + return as_value_v; + } else { + // TODO: support small vector + using type = nmtools_list; + return as_value_v; + } + } + }(); + using type = type_t; + }; // index::colum_stack_reshape_t +} // nmtools::meta + +/********************************************************************************/ + +#include "nmtools/array/view/alias.hpp" +#include "nmtools/array/view/reshape.hpp" +#include "nmtools/array/view/concatenate.hpp" + +namespace nmtools::view +{ + template + constexpr auto column_stack(const a_t& a, const b_t& b) + { + auto aliased = view::aliased(a,b); + auto a_src_shape = shape(a); + auto a_dst_shape = index::column_stack_reshape(a_src_shape); + auto b_src_shape = shape(b); + auto b_dst_shape = index::column_stack_reshape(b_src_shape); + + auto a_reshaped = view::reshape(nmtools::get<0>(aliased),a_dst_shape); + auto b_reshaped = view::reshape(nmtools::get<1>(aliased),b_dst_shape); + + auto axis = meta::ct_v<1>; + + return view::concatenate(a_reshaped,b_reshaped,axis); + } +} // namespace nmtools::view + +#endif // NMTOOLS_ARRAY_VIEW_COLUMN_STACK_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/dstack.hpp b/include/nmtools/array/view/dstack.hpp new file mode 100644 index 000000000..ab188a09d --- /dev/null +++ b/include/nmtools/array/view/dstack.hpp @@ -0,0 +1,119 @@ +#ifndef NMTOOLS_ARRAY_VIEW_DSTACK_HPP +#define NMTOOLS_ARRAY_VIEW_DSTACK_HPP + +#include "nmtools/meta.hpp" +#include "nmtools/array/shape.hpp" + +namespace nmtools::index +{ + struct dstack_reshape_t {}; + + template + constexpr auto dstack_reshape(const src_shape_t& src_shape) + { + using result_t = meta::resolve_optype_t; + + auto result = result_t {}; + + if constexpr (!meta::is_fail_v + && !meta::is_constant_index_array_v) + { + auto src_dim = len(src_shape); + + [[maybe_unused]] + auto dst_dim = src_dim < 3 ? 3 : src_dim; + + if constexpr (meta::is_resizable_v) { + result.resize(dst_dim); + } + + if (src_dim == 1) { + at(result,meta::ct_v<0>) = 1; + at(result,meta::ct_v<1>) = at(src_shape,meta::ct_v<0>); + at(result,meta::ct_v<2>) = 1; + } else if (src_dim == 2) { + at(result,meta::ct_v<0>) = at(src_shape,meta::ct_v<0>); + at(result,meta::ct_v<1>) = at(src_shape,1); // avoid triggering static_assert + at(result,meta::ct_v<2>) = 1; + } else { + for (nm_size_t i=0; i<(nm_size_t)src_dim; i++) { + at(result,i) = at(src_shape,i); + } + } + } + + return result; + } +} // nmtools::index + +namespace nmtools::meta +{ + namespace error + { + template + struct DSTACK_RESHAPE_UNSUPPORTED : detail::fail_t {}; + } + + template + struct resolve_optype< + void, index::dstack_reshape_t, src_shape_t + > { + static constexpr auto vtype = [](){ + if constexpr (!is_index_array_v) { + using type = error::DSTACK_RESHAPE_UNSUPPORTED; + return as_value_v; + } else if constexpr (is_constant_index_array_v) { + constexpr auto src_shape = to_value_v; + constexpr auto result = index::dstack_reshape(src_shape); + using nmtools::at, nmtools::len; + return template_reduce([&](auto init, auto I){ + using init_t = type_t; + using type = append_type_t>; + return as_value_v; + }, as_value_v>); + } else { + [[maybe_unused]] + constexpr auto B_DIM = bounded_size_v; + constexpr auto DIM = len_v; + if constexpr (DIM > 0) { + using type = nmtools_array; + return as_value_v; + } else if constexpr (!is_fail_v) { + using type = nmtools_static_vector; + return as_value_v; + } else { + // TODO: support small vector + using type = nmtools_list; + return as_value_v; + } + } + }(); + using type = type_t; + }; // index::dstack_reshape_t +} // nmtools::meta + +#include "nmtools/array/view/alias.hpp" +#include "nmtools/array/view/reshape.hpp" +#include "nmtools/array/view/concatenate.hpp" + +namespace nmtools::view +{ + template + constexpr auto dstack(const a_t& a, const b_t& b) + { + auto aliased = view::aliased(a,b); + auto a_src_shape = shape(a); + auto a_dst_shape = index::dstack_reshape(a_src_shape); + auto b_src_shape = shape(b); + auto b_dst_shape = index::dstack_reshape(b_src_shape); + + auto a_reshaped = view::reshape(nmtools::get<0>(aliased),a_dst_shape); + auto b_reshaped = view::reshape(nmtools::get<1>(aliased),b_dst_shape); + + auto axis = meta::ct_v<2>; + + return view::concatenate(a_reshaped,b_reshaped,axis); + } +} // nmtools::view + +#endif // NMTOOLS_ARRAY_VIEW_DSTACK_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/deg2rad.hpp b/include/nmtools/array/view/ufuncs/deg2rad.hpp new file mode 100644 index 000000000..7aee19712 --- /dev/null +++ b/include/nmtools/array/view/ufuncs/deg2rad.hpp @@ -0,0 +1,18 @@ +#ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_DEG2RAD_HPP +#define NMTOOLS_ARRAY_VIEW_UFUNCS_DEG2RAD_HPP + +#include "nmtools/constants.hpp" +#include "nmtools/array/view/ufuncs/multiply.hpp" + +namespace nmtools::view +{ + template + constexpr auto deg2rad(const array_t& a) + { + using element_t = meta::get_element_type_t; + constexpr auto b = pi_v / 180; + return view::multiply(a,b); + } +} // nmtools::view + +#endif // NMTOOLS_ARRAY_VIEW_UFUNCS_DEG2RAD_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/degrees.hpp b/include/nmtools/array/view/ufuncs/degrees.hpp new file mode 100644 index 000000000..460ca646a --- /dev/null +++ b/include/nmtools/array/view/ufuncs/degrees.hpp @@ -0,0 +1,18 @@ +#ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_DEGREES_HPP +#define NMTOOLS_ARRAY_VIEW_UFUNCS_DEGREES_HPP + +#include "nmtools/constants.hpp" +#include "nmtools/array/view/ufuncs/multiply.hpp" + +namespace nmtools::view +{ + template + constexpr auto degrees(const array_t& a) + { + using element_t = meta::get_element_type_t; + constexpr auto b = static_cast(180) / pi_v; + return view::multiply(a,b); + } +} // nmtools::view + +#endif // NMTOOLS_ARRAY_VIEW_UFUNCS_DEGREES_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/rad2deg.hpp b/include/nmtools/array/view/ufuncs/rad2deg.hpp new file mode 100644 index 000000000..6f3b04891 --- /dev/null +++ b/include/nmtools/array/view/ufuncs/rad2deg.hpp @@ -0,0 +1,18 @@ +#ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_RAD2DEG_HPP +#define NMTOOLS_ARRAY_VIEW_UFUNCS_RAD2DEG_HPP + +#include "nmtools/constants.hpp" +#include "nmtools/array/view/ufuncs/multiply.hpp" + +namespace nmtools::view +{ + template + constexpr auto rad2deg(const array_t& a) + { + using element_t = meta::get_element_type_t; + constexpr auto b = static_cast(180) / pi_v; + return view::multiply(a,b); + } +} // nmtools::view + +#endif // NMTOOLS_ARRAY_VIEW_UFUNCS_RAD2DEG_HPP \ No newline at end of file diff --git a/include/nmtools/array/view/ufuncs/radians.hpp b/include/nmtools/array/view/ufuncs/radians.hpp new file mode 100644 index 000000000..1634113b8 --- /dev/null +++ b/include/nmtools/array/view/ufuncs/radians.hpp @@ -0,0 +1,18 @@ +#ifndef NMTOOLS_ARRAY_VIEW_UFUNCS_RADIANS_HPP +#define NMTOOLS_ARRAY_VIEW_UFUNCS_RADIANS_HPP + +#include "nmtools/constants.hpp" +#include "nmtools/array/view/ufuncs/multiply.hpp" + +namespace nmtools::view +{ + template + constexpr auto radians(const array_t& a) + { + using element_t = meta::get_element_type_t; + constexpr auto b = pi_v / 180; + return view::multiply(a,b); + } +} // nmtools::view + +#endif // NMTOOLS_ARRAY_VIEW_UFUNCS_RADIANS_HPP \ No newline at end of file diff --git a/include/nmtools/constants.hpp b/include/nmtools/constants.hpp index a7150da51..48423f63a 100644 --- a/include/nmtools/constants.hpp +++ b/include/nmtools/constants.hpp @@ -174,4 +174,14 @@ namespace nmtools::literals } // namespace nmtools::literals +namespace nmtools +{ + template + inline constexpr T pi_v = 3.141592653589793238462643383279502884197; + + inline constexpr auto Pi = pi_v; + + // not everyone has to be saved +} // nmtools + #endif // NMTOOLS_CONSTANTS_HPP \ No newline at end of file diff --git a/include/nmtools/testing/data/array/column_stack.hpp b/include/nmtools/testing/data/array/column_stack.hpp new file mode 100644 index 000000000..def68485c --- /dev/null +++ b/include/nmtools/testing/data/array/column_stack.hpp @@ -0,0 +1,95 @@ +#ifndef NMTOOLS_TESTING_DATA_ARRAY_COLUMN_STACK_HPP +#define NMTOOLS_TESTING_DATA_ARRAY_COLUMN_STACK_HPP + +#include "nmtools/testing/testing.hpp" +#include "nmtools/testing/array_cast.hpp" + +NMTOOLS_TESTING_DECLARE_CASE(array,column_stack) +{ + NMTOOLS_TESTING_DECLARE_ARGS(case1) + { + inline int a[3] = {1,2,3}; + inline int b[3] = {2,3,4}; + NMTOOLS_CAST_ARRAYS(a) + NMTOOLS_CAST_ARRAYS(b) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case1) + { + inline int result[3][2] = { + {1,2}, + {2,3}, + {3,4}, + }; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case2) + { + inline int a[3][2] = { + {0,1}, + {2,3}, + {4,5}, + }; + inline int b[3][2] = { + { 7, 8}, + { 9,10}, + {11,12}, + }; + NMTOOLS_CAST_ARRAYS(a) + NMTOOLS_CAST_ARRAYS(b) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case2) + { + inline int result[3][4] = { + {0,1, 7, 8}, + {2,3, 9,10}, + {4,5,11,12}, + }; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case3) + { + inline int a[3][1][2] = { + { + {0,1}, + }, + { + {2,3}, + }, + { + {4,5}, + } + }; + inline int b[3][1][2] = { + { + {7,8}, + }, + { + {9,10}, + }, + { + {11,12}, + } + }; + NMTOOLS_CAST_ARRAYS(a) + NMTOOLS_CAST_ARRAYS(b) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case3) + { + inline int result[3][2][2] = { + { + {0,1}, + {7,8}, + }, + { + {2, 3}, + {9,10}, + }, + { + { 4, 5}, + {11,12}, + } + }; + } +} + +#endif // NMTOOLS_TESTING_DATA_ARRAY_COLUMN_STACK_HPP \ No newline at end of file diff --git a/include/nmtools/testing/data/array/deg2rad.hpp b/include/nmtools/testing/data/array/deg2rad.hpp new file mode 100644 index 000000000..82f50ce88 --- /dev/null +++ b/include/nmtools/testing/data/array/deg2rad.hpp @@ -0,0 +1,44 @@ +#ifndef NMTOOLS_TESTING_DATA_ARRAY_DEG2RAD_HPP +#define NMTOOLS_TESTING_DATA_ARRAY_DEG2RAD_HPP + +#include "nmtools/testing/testing.hpp" +#include "nmtools/testing/array_cast.hpp" + +NMTOOLS_TESTING_DECLARE_CASE(array,deg2rad) +{ + NMTOOLS_TESTING_DECLARE_ARGS(case1) + { + inline float a[12] = {0., 30., 60., 90., 120., 150., 180., 210., 240., 270., 300., 330.}; + NMTOOLS_CAST_ARRAYS(a) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case1) + { + inline float result[12] = { + 0. , 0.52359878, 1.04719755, 1.57079633, 2.0943951 , + 2.61799388, 3.14159265, 3.66519143, 4.1887902 , 4.71238898, + 5.23598776, 5.75958653 + }; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case2) + { + inline float a[4][3] = { + { 0., 60., 120.}, + {180., 240., 300.}, + {360., 420., 480.}, + {540., 600., 660.} + }; + NMTOOLS_CAST_ARRAYS(a) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case2) + { + inline float result[4][3] = { + { 0. , 1.04719755, 2.0943951 }, + { 3.14159265, 4.1887902 , 5.23598776}, + { 6.28318531, 7.33038286, 8.37758041}, + { 9.42477796, 10.47197551, 11.51917306} + }; + } +} + +#endif // NMTOOLS_TESTING_DATA_ARRAY_DEG2RAD_HPP \ No newline at end of file diff --git a/include/nmtools/testing/data/array/degrees.hpp b/include/nmtools/testing/data/array/degrees.hpp new file mode 100644 index 000000000..abc5b2e05 --- /dev/null +++ b/include/nmtools/testing/data/array/degrees.hpp @@ -0,0 +1,44 @@ +#ifndef NMTOOLS_TESTING_DATA_ARRAY_DEGREES_HPP +#define NMTOOLS_TESTING_DATA_ARRAY_DEGREES_HPP + +#include "nmtools/testing/testing.hpp" +#include "nmtools/testing/array_cast.hpp" + +NMTOOLS_TESTING_DECLARE_CASE(array, degrees) +{ + NMTOOLS_TESTING_DECLARE_ARGS(case1) + { + inline float a[12] = { + 0. , 0.52359878, 1.04719755, 1.57079633, 2.0943951 , + 2.61799388, 3.14159265, 3.66519143, 4.1887902 , 4.71238898, + 5.23598776, 5.75958653 + }; + NMTOOLS_CAST_ARRAYS(a) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case1) + { + inline float result[12] = {0., 30., 60., 90., 120., 150., 180., 210., 240., 270., 300., 330.}; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case2) + { + inline float a[4][3] = { + { 0. , 1.04719755, 2.0943951 }, + { 3.14159265, 4.1887902 , 5.23598776}, + { 6.28318531, 7.33038286, 8.37758041}, + { 9.42477796, 10.47197551, 11.51917306} + }; + NMTOOLS_CAST_ARRAYS(a) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case2) + { + inline float result[4][3] = { + { 0., 60., 120.}, + {180., 240., 300.}, + {360., 420., 480.}, + {540., 600., 660.} + }; + } +} + +#endif // NMTOOLS_TESTING_DATA_ARRAY_DEGREES_HPP \ No newline at end of file diff --git a/include/nmtools/testing/data/array/dstack.hpp b/include/nmtools/testing/data/array/dstack.hpp new file mode 100644 index 000000000..18a35b9b4 --- /dev/null +++ b/include/nmtools/testing/data/array/dstack.hpp @@ -0,0 +1,285 @@ +#ifndef NMTOOLS_TESTING_DATA_ARRAY_DSTACK_HPP +#define NMTOOLS_TESTING_DATA_ARRAY_DSTACK_HPP + +#include "nmtools/testing/testing.hpp" +#include "nmtools/testing/array_cast.hpp" + +NMTOOLS_TESTING_DECLARE_CASE(array,dstack) +{ + NMTOOLS_TESTING_DECLARE_ARGS(case1) + { + inline int a[3] = {1,2,3}; + inline int b[3] = {2,3,4}; + NMTOOLS_CAST_ARRAYS(a) + NMTOOLS_CAST_ARRAYS(b) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case1) + { + inline int result[1][3][2] = { + { + {1,2}, + {2,3}, + {3,4}, + } + }; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case2) + { + inline int a[3][1] = { + {1}, + {2}, + {3}, + }; + inline int b[3][1] = { + {2}, + {3}, + {4}, + }; + NMTOOLS_CAST_ARRAYS(a) + NMTOOLS_CAST_ARRAYS(b) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case2) + { + inline int result[3][1][2] = { + { + {1,2}, + }, + { + {2,3}, + }, + { + {3,4}, + } + }; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case2b) + { + inline int a[2][3] = { + {0,1,2}, + {3,4,5}, + }; + inline int b[2][3] = { + {6, 7, 8}, + {9,10,11}, + }; + NMTOOLS_CAST_ARRAYS(a) + NMTOOLS_CAST_ARRAYS(b) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case2b) + { + inline int result[2][3][2] = { + { + {0,6}, + {1,7}, + {2,8}, + }, + { + {3, 9}, + {4,10}, + {5,11}, + } + }; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case3) + { + inline int a[2][3][1][2] = { + { + { + {0,1}, + }, + { + {2,3}, + }, + { + {4,5}, + }, + }, + { + { + {6,7}, + }, + { + {8,9}, + }, + { + {10,11}, + } + } + }; + inline int b[2][3][1][2] = { + { + { + {12,13}, + }, + { + {14,15}, + }, + { + {16,17}, + } + }, + { + { + {18,19}, + }, + { + {20,21}, + }, + { + {22,23}, + }, + } + }; + NMTOOLS_CAST_ARRAYS(a) + NMTOOLS_CAST_ARRAYS(b) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case3) + { + inline int result[2][3][2][2] = { + { + { + { 0, 1}, + {12,13}, + }, + { + { 2, 3}, + {14,15}, + }, + { + { 4, 5}, + {16,17}, + }, + }, + { + { + { 6, 7}, + {18,19}, + }, + { + { 8, 9}, + {20,21}, + }, + { + {10,11}, + {22,23}, + }, + }, + }; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case4) + { + inline int a[2][1][3][1][2] = { + { + { + { + {0,1}, + }, + { + {2,3}, + }, + { + {4,5}, + }, + } + }, + { + { + { + {6,7}, + }, + { + {8,9}, + }, + { + {10,11}, + } + } + } + }; + inline int b[2][1][3][1][2] = { + { + { + { + {12,13}, + }, + { + {14,15}, + }, + { + {16,17}, + } + } + }, + { + { + { + {18,19}, + }, + { + {20,21}, + }, + { + {22,23}, + }, + } + } + }; + NMTOOLS_CAST_ARRAYS(a) + NMTOOLS_CAST_ARRAYS(b) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case4) + { + inline int result[2][1][6][1][2] = { + { + { + { + {0,1}, + }, + { + {2,3}, + }, + { + {4,5}, + }, + { + {12,13}, + }, + { + {14,15}, + }, + { + {16,17}, + }, + } + }, + { + { + { + {6,7}, + }, + { + {8,9}, + }, + { + {10,11}, + }, + { + {18,19}, + }, + { + {20,21}, + }, + { + {22,23}, + }, + } + } + }; + } +} + +#endif // NMTOOLS_TESTING_DATA_ARRAY_DSTACK_HPP \ No newline at end of file diff --git a/include/nmtools/testing/data/array/rad2deg.hpp b/include/nmtools/testing/data/array/rad2deg.hpp new file mode 100644 index 000000000..70f6b2af5 --- /dev/null +++ b/include/nmtools/testing/data/array/rad2deg.hpp @@ -0,0 +1,44 @@ +#ifndef NMTOOLS_TESTING_DATA_ARRAY_RAD2DEG_HPP +#define NMTOOLS_TESTING_DATA_ARRAY_RAD2DEG_HPP + +#include "nmtools/testing/testing.hpp" +#include "nmtools/testing/array_cast.hpp" + +NMTOOLS_TESTING_DECLARE_CASE(array, rad2deg) +{ + NMTOOLS_TESTING_DECLARE_ARGS(case1) + { + inline float a[12] = { + 0. , 0.52359878, 1.04719755, 1.57079633, 2.0943951 , + 2.61799388, 3.14159265, 3.66519143, 4.1887902 , 4.71238898, + 5.23598776, 5.75958653 + }; + NMTOOLS_CAST_ARRAYS(a) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case1) + { + inline float result[12] = {0., 30., 60., 90., 120., 150., 180., 210., 240., 270., 300., 330.}; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case2) + { + inline float a[4][3] = { + { 0. , 1.04719755, 2.0943951 }, + { 3.14159265, 4.1887902 , 5.23598776}, + { 6.28318531, 7.33038286, 8.37758041}, + { 9.42477796, 10.47197551, 11.51917306} + }; + NMTOOLS_CAST_ARRAYS(a) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case2) + { + inline float result[4][3] = { + { 0., 60., 120.}, + {180., 240., 300.}, + {360., 420., 480.}, + {540., 600., 660.} + }; + } +} + +#endif // NMTOOLS_TESTING_DATA_ARRAY_RAD2DEG_HPP \ No newline at end of file diff --git a/include/nmtools/testing/data/array/radians.hpp b/include/nmtools/testing/data/array/radians.hpp new file mode 100644 index 000000000..baa0250a6 --- /dev/null +++ b/include/nmtools/testing/data/array/radians.hpp @@ -0,0 +1,44 @@ +#ifndef NMTOOLS_TESTING_DATA_ARRAY_RADIANS_HPP +#define NMTOOLS_TESTING_DATA_ARRAY_RADIANS_HPP + +#include "nmtools/testing/testing.hpp" +#include "nmtools/testing/array_cast.hpp" + +NMTOOLS_TESTING_DECLARE_CASE(array,radians) +{ + NMTOOLS_TESTING_DECLARE_ARGS(case1) + { + inline float a[12] = {0., 30., 60., 90., 120., 150., 180., 210., 240., 270., 300., 330.}; + NMTOOLS_CAST_ARRAYS(a) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case1) + { + inline float result[12] = { + 0. , 0.52359878, 1.04719755, 1.57079633, 2.0943951 , + 2.61799388, 3.14159265, 3.66519143, 4.1887902 , 4.71238898, + 5.23598776, 5.75958653 + }; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case2) + { + inline float a[4][3] = { + { 0., 60., 120.}, + {180., 240., 300.}, + {360., 420., 480.}, + {540., 600., 660.} + }; + NMTOOLS_CAST_ARRAYS(a) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case2) + { + inline float result[4][3] = { + { 0. , 1.04719755, 2.0943951 }, + { 3.14159265, 4.1887902 , 5.23598776}, + { 6.28318531, 7.33038286, 8.37758041}, + { 9.42477796, 10.47197551, 11.51917306} + }; + } +} + +#endif // NMTOOLS_TESTING_DATA_ARRAY_RADIANS_HPP \ No newline at end of file diff --git a/tests/array/CMakeLists.txt b/tests/array/CMakeLists.txt index 97008c421..919bd718e 100644 --- a/tests/array/CMakeLists.txt +++ b/tests/array/CMakeLists.txt @@ -96,12 +96,14 @@ set(ARRAY_EVAL_TEST_SOURCES array/atleast_nd.cpp # array/broadcast_arrays.cpp array/broadcast_to.cpp + array/column_stack.cpp array/compress.cpp array/concatenate.cpp array/cumprod.cpp array/cumsum.cpp array/diagflat.cpp array/diagonal.cpp + array/dstack.cpp array/expand_dims.cpp array/expand.cpp array/eye.cpp @@ -169,6 +171,8 @@ set(ARRAY_UFUNCS_TEST_SOURCES # array/ufuncs/clip.cpp array/ufuncs/cos.cpp array/ufuncs/cosh.cpp + array/ufuncs/degrees.cpp + array/ufuncs/deg2rad.cpp array/ufuncs/divide.cpp array/ufuncs/equal.cpp array/ufuncs/exp.cpp @@ -205,6 +209,8 @@ set(ARRAY_UFUNCS_TEST_SOURCES array/ufuncs/not_equal.cpp array/ufuncs/positive.cpp array/ufuncs/power.cpp + array/ufuncs/radians.cpp + array/ufuncs/rad2deg.cpp array/ufuncs/reciprocal.cpp array/ufuncs/right_shift.cpp array/ufuncs/rint.cpp diff --git a/tests/array/array/column_stack.cpp b/tests/array/array/column_stack.cpp new file mode 100644 index 000000000..a6341c48b --- /dev/null +++ b/tests/array/array/column_stack.cpp @@ -0,0 +1,39 @@ +#include "nmtools/array/array/column_stack.hpp" +#include "nmtools/testing/data/array/column_stack.hpp" +#include "nmtools/testing/doctest.hpp" + +#define COLUMN_STACK_SUBCASE( case_name, ... ) \ +SUBCASE(#case_name) \ +{ \ + NMTOOLS_TESTING_USE_CASE( array, column_stack, case_name ); \ + auto result = nmtools::array::column_stack( __VA_ARGS__ ); \ + NMTOOLS_ASSERT_EQUAL( nmtools::shape(result), nmtools::shape(expect::result) ); \ + NMTOOLS_ASSERT_CLOSE( result, expect::result ); \ +} + +TEST_CASE("column_stack(case1)" * doctest::test_suite("array::column_stack")) +{ + COLUMN_STACK_SUBCASE( case1, a, b ); + COLUMN_STACK_SUBCASE( case1, a_a, b_a ); + COLUMN_STACK_SUBCASE( case1, a_f, b_f ); + COLUMN_STACK_SUBCASE( case1, a_h, b_h ); + COLUMN_STACK_SUBCASE( case1, a_d, b_d ); +} + +TEST_CASE("column_stack(case2)" * doctest::test_suite("array::column_stack")) +{ + COLUMN_STACK_SUBCASE( case2, a, b ); + COLUMN_STACK_SUBCASE( case2, a_a, b_a ); + COLUMN_STACK_SUBCASE( case2, a_f, b_f ); + COLUMN_STACK_SUBCASE( case2, a_h, b_h ); + COLUMN_STACK_SUBCASE( case2, a_d, b_d ); +} + +TEST_CASE("column_stack(case3)" * doctest::test_suite("array::column_stack")) +{ + COLUMN_STACK_SUBCASE( case3, a, b ); + COLUMN_STACK_SUBCASE( case3, a_a, b_a ); + COLUMN_STACK_SUBCASE( case3, a_f, b_f ); + COLUMN_STACK_SUBCASE( case3, a_h, b_h ); + COLUMN_STACK_SUBCASE( case3, a_d, b_d ); +} \ No newline at end of file diff --git a/tests/array/array/dstack.cpp b/tests/array/array/dstack.cpp new file mode 100644 index 000000000..beaa0c8a8 --- /dev/null +++ b/tests/array/array/dstack.cpp @@ -0,0 +1,57 @@ +#include "nmtools/array/array/dstack.hpp" +#include "nmtools/testing/data/array/dstack.hpp" +#include "nmtools/testing/doctest.hpp" + +#define DSTACK_SUBCASE( case_name, ... ) \ +SUBCASE(#case_name) \ +{ \ + NMTOOLS_TESTING_USE_CASE( array, dstack, case_name ); \ + auto result = nmtools::array::dstack(__VA_ARGS__); \ + NMTOOLS_ASSERT_EQUAL( nmtools::shape(result), nmtools::shape(expect::result) ); \ + NMTOOLS_ASSERT_CLOSE( result, expect::result ); \ +} + +TEST_CASE("dstack(case1)" * doctest::test_suite("array::dstack")) +{ + DSTACK_SUBCASE( case1, a, b ); + DSTACK_SUBCASE( case1, a_a, b_a ); + DSTACK_SUBCASE( case1, a_f, b_f ); + DSTACK_SUBCASE( case1, a_h, b_h ); + DSTACK_SUBCASE( case1, a_d, b_d ); +} + +TEST_CASE("dstack(case2)" * doctest::test_suite("array::dstack")) +{ + DSTACK_SUBCASE( case2, a, b ); + DSTACK_SUBCASE( case2, a_a, b_a ); + DSTACK_SUBCASE( case2, a_f, b_f ); + DSTACK_SUBCASE( case2, a_h, b_h ); + DSTACK_SUBCASE( case2, a_d, b_d ); +} + +TEST_CASE("dstack(case2b)" * doctest::test_suite("array::dstack")) +{ + DSTACK_SUBCASE( case2b, a, b ); + DSTACK_SUBCASE( case2b, a_a, b_a ); + DSTACK_SUBCASE( case2b, a_f, b_f ); + DSTACK_SUBCASE( case2b, a_h, b_h ); + DSTACK_SUBCASE( case2b, a_d, b_d ); +} + +TEST_CASE("dstack(case3)" * doctest::test_suite("array::dstack")) +{ + DSTACK_SUBCASE( case3, a, b ); + DSTACK_SUBCASE( case3, a_a, b_a ); + DSTACK_SUBCASE( case3, a_f, b_f ); + DSTACK_SUBCASE( case3, a_h, b_h ); + DSTACK_SUBCASE( case3, a_d, b_d ); +} + +TEST_CASE("dstack(case4)" * doctest::test_suite("array::dstack")) +{ + DSTACK_SUBCASE( case4, a, b ); + DSTACK_SUBCASE( case4, a_a, b_a ); + DSTACK_SUBCASE( case4, a_f, b_f ); + DSTACK_SUBCASE( case4, a_h, b_h ); + DSTACK_SUBCASE( case4, a_d, b_d ); +} \ No newline at end of file diff --git a/tests/array/array/ufuncs/deg2rad.cpp b/tests/array/array/ufuncs/deg2rad.cpp new file mode 100644 index 000000000..00331f01d --- /dev/null +++ b/tests/array/array/ufuncs/deg2rad.cpp @@ -0,0 +1,79 @@ +#if 1 +#define NMTOOLS_CAST_ARRAYS_EXTRA(name) \ +inline auto name##_cs_fb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_fb); \ +inline auto name##_cs_hb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_hb); \ +inline auto name##_cs_db = nmtools::cast(name, nmtools::array::kind::ndarray_cs_db); \ +inline auto name##_fs_fb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_fb); \ +inline auto name##_fs_hb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_hb); \ +inline auto name##_fs_db = nmtools::cast(name, nmtools::array::kind::ndarray_cs_db); \ +inline auto name##_hs_fb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_fb); \ +inline auto name##_hs_hb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_hb); \ +inline auto name##_hs_db = nmtools::cast(name, nmtools::array::kind::ndarray_cs_db); \ +inline auto name##_ds_fb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_fb); \ +inline auto name##_ds_hb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_hb); \ +inline auto name##_ds_db = nmtools::cast(name, nmtools::array::kind::ndarray_cs_db); +#endif + +#include "nmtools/array/array/ufuncs/deg2rad.hpp" +#include "nmtools/testing/data/array/deg2rad.hpp" +#include "nmtools/testing/doctest.hpp" + +#define DEG2RAD_SUBCASE(case_name, ...) \ +SUBCASE(#case_name) \ +{ \ + NMTOOLS_TESTING_USE_CASE(array, deg2rad, case_name); \ + using namespace args; \ + auto result = nmtools::array::deg2rad(__VA_ARGS__); \ + NMTOOLS_ASSERT_EQUAL( nmtools::shape(result), nmtools::shape(expect::result) ); \ + NMTOOLS_ASSERT_CLOSE( result, expect::result ); \ +} + +TEST_CASE("deg2rad(case1)" * doctest::test_suite("array::deg2rad")) +{ + DEG2RAD_SUBCASE( case1, a); + DEG2RAD_SUBCASE( case1, a_a); + DEG2RAD_SUBCASE( case1, a_f); + DEG2RAD_SUBCASE( case1, a_d); + DEG2RAD_SUBCASE( case1, a_h); + + DEG2RAD_SUBCASE( case1, a_cs_fb ); + DEG2RAD_SUBCASE( case1, a_cs_hb ); + DEG2RAD_SUBCASE( case1, a_cs_db ); + + DEG2RAD_SUBCASE( case1, a_fs_fb ); + DEG2RAD_SUBCASE( case1, a_fs_hb ); + DEG2RAD_SUBCASE( case1, a_fs_db ); + + DEG2RAD_SUBCASE( case1, a_hs_fb ); + DEG2RAD_SUBCASE( case1, a_hs_hb ); + DEG2RAD_SUBCASE( case1, a_hs_db ); + + DEG2RAD_SUBCASE( case1, a_ds_fb ); + DEG2RAD_SUBCASE( case1, a_ds_hb ); + DEG2RAD_SUBCASE( case1, a_ds_db ); +} + +TEST_CASE("deg2rad(case2)" * doctest::test_suite("array::deg2rad")) +{ + DEG2RAD_SUBCASE( case2, a); + DEG2RAD_SUBCASE( case2, a_a); + DEG2RAD_SUBCASE( case2, a_f); + DEG2RAD_SUBCASE( case2, a_d); + DEG2RAD_SUBCASE( case2, a_h); + + DEG2RAD_SUBCASE( case2, a_cs_fb ); + DEG2RAD_SUBCASE( case2, a_cs_hb ); + DEG2RAD_SUBCASE( case2, a_cs_db ); + + DEG2RAD_SUBCASE( case2, a_fs_fb ); + DEG2RAD_SUBCASE( case2, a_fs_hb ); + DEG2RAD_SUBCASE( case2, a_fs_db ); + + DEG2RAD_SUBCASE( case2, a_hs_fb ); + DEG2RAD_SUBCASE( case2, a_hs_hb ); + DEG2RAD_SUBCASE( case2, a_hs_db ); + + DEG2RAD_SUBCASE( case2, a_ds_fb ); + DEG2RAD_SUBCASE( case2, a_ds_hb ); + DEG2RAD_SUBCASE( case2, a_ds_db ); +} \ No newline at end of file diff --git a/tests/array/array/ufuncs/degrees.cpp b/tests/array/array/ufuncs/degrees.cpp new file mode 100644 index 000000000..0cbcd4ee0 --- /dev/null +++ b/tests/array/array/ufuncs/degrees.cpp @@ -0,0 +1,81 @@ +#if 1 +#define NMTOOLS_CAST_ARRAYS_EXTRA(name) \ +inline auto name##_cs_fb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_fb); \ +inline auto name##_cs_hb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_hb); \ +inline auto name##_cs_db = nmtools::cast(name, nmtools::array::kind::ndarray_cs_db); \ +inline auto name##_fs_fb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_fb); \ +inline auto name##_fs_hb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_hb); \ +inline auto name##_fs_db = nmtools::cast(name, nmtools::array::kind::ndarray_cs_db); \ +inline auto name##_hs_fb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_fb); \ +inline auto name##_hs_hb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_hb); \ +inline auto name##_hs_db = nmtools::cast(name, nmtools::array::kind::ndarray_cs_db); \ +inline auto name##_ds_fb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_fb); \ +inline auto name##_ds_hb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_hb); \ +inline auto name##_ds_db = nmtools::cast(name, nmtools::array::kind::ndarray_cs_db); +#endif + +#define NMTOOLS_TESTING_OUTPUT_PRECISION (1e-3) + +#include "nmtools/array/array/ufuncs/degrees.hpp" +#include "nmtools/testing/data/array/degrees.hpp" +#include "nmtools/testing/doctest.hpp" + +#define DEGREES_SUBCASE(case_name, ...) \ +SUBCASE(#case_name) \ +{ \ + NMTOOLS_TESTING_USE_CASE(array, degrees, case_name); \ + using namespace args; \ + auto result = nmtools::array::degrees(__VA_ARGS__); \ + NMTOOLS_ASSERT_EQUAL( nmtools::shape(result), nmtools::shape(expect::result) ); \ + NMTOOLS_ASSERT_CLOSE( result, expect::result ); \ +} + +TEST_CASE("degrees(case1)" * doctest::test_suite("array::degrees")) +{ + DEGREES_SUBCASE( case1, a); + DEGREES_SUBCASE( case1, a_a); + DEGREES_SUBCASE( case1, a_f); + DEGREES_SUBCASE( case1, a_d); + DEGREES_SUBCASE( case1, a_h); + + DEGREES_SUBCASE( case1, a_cs_fb ); + DEGREES_SUBCASE( case1, a_cs_hb ); + DEGREES_SUBCASE( case1, a_cs_db ); + + DEGREES_SUBCASE( case1, a_fs_fb ); + DEGREES_SUBCASE( case1, a_fs_hb ); + DEGREES_SUBCASE( case1, a_fs_db ); + + DEGREES_SUBCASE( case1, a_hs_fb ); + DEGREES_SUBCASE( case1, a_hs_hb ); + DEGREES_SUBCASE( case1, a_hs_db ); + + DEGREES_SUBCASE( case1, a_ds_fb ); + DEGREES_SUBCASE( case1, a_ds_hb ); + DEGREES_SUBCASE( case1, a_ds_db ); +} + +TEST_CASE("degrees(case2)" * doctest::test_suite("array::degrees")) +{ + DEGREES_SUBCASE( case2, a); + DEGREES_SUBCASE( case2, a_a); + DEGREES_SUBCASE( case2, a_f); + DEGREES_SUBCASE( case2, a_d); + DEGREES_SUBCASE( case2, a_h); + + DEGREES_SUBCASE( case2, a_cs_fb ); + DEGREES_SUBCASE( case2, a_cs_hb ); + DEGREES_SUBCASE( case2, a_cs_db ); + + DEGREES_SUBCASE( case2, a_fs_fb ); + DEGREES_SUBCASE( case2, a_fs_hb ); + DEGREES_SUBCASE( case2, a_fs_db ); + + DEGREES_SUBCASE( case2, a_hs_fb ); + DEGREES_SUBCASE( case2, a_hs_hb ); + DEGREES_SUBCASE( case2, a_hs_db ); + + DEGREES_SUBCASE( case2, a_ds_fb ); + DEGREES_SUBCASE( case2, a_ds_hb ); + DEGREES_SUBCASE( case2, a_ds_db ); +} \ No newline at end of file diff --git a/tests/array/array/ufuncs/rad2deg.cpp b/tests/array/array/ufuncs/rad2deg.cpp new file mode 100644 index 000000000..331501bda --- /dev/null +++ b/tests/array/array/ufuncs/rad2deg.cpp @@ -0,0 +1,81 @@ +#if 1 +#define NMTOOLS_CAST_ARRAYS_EXTRA(name) \ +inline auto name##_cs_fb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_fb); \ +inline auto name##_cs_hb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_hb); \ +inline auto name##_cs_db = nmtools::cast(name, nmtools::array::kind::ndarray_cs_db); \ +inline auto name##_fs_fb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_fb); \ +inline auto name##_fs_hb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_hb); \ +inline auto name##_fs_db = nmtools::cast(name, nmtools::array::kind::ndarray_cs_db); \ +inline auto name##_hs_fb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_fb); \ +inline auto name##_hs_hb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_hb); \ +inline auto name##_hs_db = nmtools::cast(name, nmtools::array::kind::ndarray_cs_db); \ +inline auto name##_ds_fb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_fb); \ +inline auto name##_ds_hb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_hb); \ +inline auto name##_ds_db = nmtools::cast(name, nmtools::array::kind::ndarray_cs_db); +#endif + +#define NMTOOLS_TESTING_OUTPUT_PRECISION (1e-3) + +#include "nmtools/array/array/ufuncs/rad2deg.hpp" +#include "nmtools/testing/data/array/rad2deg.hpp" +#include "nmtools/testing/doctest.hpp" + +#define RAD2DEG_SUBCASE(case_name, ...) \ +SUBCASE(#case_name) \ +{ \ + NMTOOLS_TESTING_USE_CASE(array, rad2deg, case_name); \ + using namespace args; \ + auto result = nmtools::array::rad2deg(__VA_ARGS__); \ + NMTOOLS_ASSERT_EQUAL( nmtools::shape(result), nmtools::shape(expect::result) ); \ + NMTOOLS_ASSERT_CLOSE( result, expect::result ); \ +} + +TEST_CASE("rad2deg(case1)" * doctest::test_suite("array::rad2deg")) +{ + RAD2DEG_SUBCASE( case1, a); + RAD2DEG_SUBCASE( case1, a_a); + RAD2DEG_SUBCASE( case1, a_f); + RAD2DEG_SUBCASE( case1, a_d); + RAD2DEG_SUBCASE( case1, a_h); + + RAD2DEG_SUBCASE( case1, a_cs_fb ); + RAD2DEG_SUBCASE( case1, a_cs_hb ); + RAD2DEG_SUBCASE( case1, a_cs_db ); + + RAD2DEG_SUBCASE( case1, a_fs_fb ); + RAD2DEG_SUBCASE( case1, a_fs_hb ); + RAD2DEG_SUBCASE( case1, a_fs_db ); + + RAD2DEG_SUBCASE( case1, a_hs_fb ); + RAD2DEG_SUBCASE( case1, a_hs_hb ); + RAD2DEG_SUBCASE( case1, a_hs_db ); + + RAD2DEG_SUBCASE( case1, a_ds_fb ); + RAD2DEG_SUBCASE( case1, a_ds_hb ); + RAD2DEG_SUBCASE( case1, a_ds_db ); +} + +TEST_CASE("rad2deg(case2)" * doctest::test_suite("array::rad2deg")) +{ + RAD2DEG_SUBCASE( case2, a); + RAD2DEG_SUBCASE( case2, a_a); + RAD2DEG_SUBCASE( case2, a_f); + RAD2DEG_SUBCASE( case2, a_d); + RAD2DEG_SUBCASE( case2, a_h); + + RAD2DEG_SUBCASE( case2, a_cs_fb ); + RAD2DEG_SUBCASE( case2, a_cs_hb ); + RAD2DEG_SUBCASE( case2, a_cs_db ); + + RAD2DEG_SUBCASE( case2, a_fs_fb ); + RAD2DEG_SUBCASE( case2, a_fs_hb ); + RAD2DEG_SUBCASE( case2, a_fs_db ); + + RAD2DEG_SUBCASE( case2, a_hs_fb ); + RAD2DEG_SUBCASE( case2, a_hs_hb ); + RAD2DEG_SUBCASE( case2, a_hs_db ); + + RAD2DEG_SUBCASE( case2, a_ds_fb ); + RAD2DEG_SUBCASE( case2, a_ds_hb ); + RAD2DEG_SUBCASE( case2, a_ds_db ); +} \ No newline at end of file diff --git a/tests/array/array/ufuncs/radians.cpp b/tests/array/array/ufuncs/radians.cpp new file mode 100644 index 000000000..d1ffe0337 --- /dev/null +++ b/tests/array/array/ufuncs/radians.cpp @@ -0,0 +1,79 @@ +#if 1 +#define NMTOOLS_CAST_ARRAYS_EXTRA(name) \ +inline auto name##_cs_fb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_fb); \ +inline auto name##_cs_hb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_hb); \ +inline auto name##_cs_db = nmtools::cast(name, nmtools::array::kind::ndarray_cs_db); \ +inline auto name##_fs_fb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_fb); \ +inline auto name##_fs_hb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_hb); \ +inline auto name##_fs_db = nmtools::cast(name, nmtools::array::kind::ndarray_cs_db); \ +inline auto name##_hs_fb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_fb); \ +inline auto name##_hs_hb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_hb); \ +inline auto name##_hs_db = nmtools::cast(name, nmtools::array::kind::ndarray_cs_db); \ +inline auto name##_ds_fb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_fb); \ +inline auto name##_ds_hb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_hb); \ +inline auto name##_ds_db = nmtools::cast(name, nmtools::array::kind::ndarray_cs_db); +#endif + +#include "nmtools/array/array/ufuncs/radians.hpp" +#include "nmtools/testing/data/array/radians.hpp" +#include "nmtools/testing/doctest.hpp" + +#define RADIANS_SUBCASE(case_name, ...) \ +SUBCASE(#case_name) \ +{ \ + NMTOOLS_TESTING_USE_CASE(array, radians, case_name); \ + using namespace args; \ + auto result = nmtools::array::radians(__VA_ARGS__); \ + NMTOOLS_ASSERT_EQUAL( nmtools::shape(result), nmtools::shape(expect::result) ); \ + NMTOOLS_ASSERT_CLOSE( result, expect::result ); \ +} + +TEST_CASE("radians(case1)" * doctest::test_suite("array::radians")) +{ + RADIANS_SUBCASE( case1, a); + RADIANS_SUBCASE( case1, a_a); + RADIANS_SUBCASE( case1, a_f); + RADIANS_SUBCASE( case1, a_d); + RADIANS_SUBCASE( case1, a_h); + + RADIANS_SUBCASE( case1, a_cs_fb ); + RADIANS_SUBCASE( case1, a_cs_hb ); + RADIANS_SUBCASE( case1, a_cs_db ); + + RADIANS_SUBCASE( case1, a_fs_fb ); + RADIANS_SUBCASE( case1, a_fs_hb ); + RADIANS_SUBCASE( case1, a_fs_db ); + + RADIANS_SUBCASE( case1, a_hs_fb ); + RADIANS_SUBCASE( case1, a_hs_hb ); + RADIANS_SUBCASE( case1, a_hs_db ); + + RADIANS_SUBCASE( case1, a_ds_fb ); + RADIANS_SUBCASE( case1, a_ds_hb ); + RADIANS_SUBCASE( case1, a_ds_db ); +} + +TEST_CASE("radians(case2)" * doctest::test_suite("array::radians")) +{ + RADIANS_SUBCASE( case2, a); + RADIANS_SUBCASE( case2, a_a); + RADIANS_SUBCASE( case2, a_f); + RADIANS_SUBCASE( case2, a_d); + RADIANS_SUBCASE( case2, a_h); + + RADIANS_SUBCASE( case2, a_cs_fb ); + RADIANS_SUBCASE( case2, a_cs_hb ); + RADIANS_SUBCASE( case2, a_cs_db ); + + RADIANS_SUBCASE( case2, a_fs_fb ); + RADIANS_SUBCASE( case2, a_fs_hb ); + RADIANS_SUBCASE( case2, a_fs_db ); + + RADIANS_SUBCASE( case2, a_hs_fb ); + RADIANS_SUBCASE( case2, a_hs_hb ); + RADIANS_SUBCASE( case2, a_hs_db ); + + RADIANS_SUBCASE( case2, a_ds_fb ); + RADIANS_SUBCASE( case2, a_ds_hb ); + RADIANS_SUBCASE( case2, a_ds_db ); +} \ No newline at end of file diff --git a/tests/view/CMakeLists.txt b/tests/view/CMakeLists.txt index cb6ae0a77..bbf7c89a7 100644 --- a/tests/view/CMakeLists.txt +++ b/tests/view/CMakeLists.txt @@ -62,10 +62,12 @@ set(ARRAY_VIEW_1_TEST_SOURCES src/atleast_nd.cpp src/broadcast_to.cpp src/broadcast_arrays.cpp + src/column_stack.cpp src/concatenate.cpp src/compress.cpp src/diagflat.cpp src/diagonal.cpp + src/dstack.cpp src/expand_dims.cpp src/expand.cpp src/eye.cpp @@ -155,6 +157,8 @@ set(ARRAY_UFUNCS_1_TEST_SOURCES src/ufuncs/bitwise_xor.cpp src/ufuncs/cbrt.cpp src/ufuncs/ceil.cpp + src/ufuncs/degrees.cpp + src/ufuncs/deg2rad.cpp ## TODO: fix # src/ufuncs/clip.cpp src/ufuncs/cos.cpp @@ -198,6 +202,8 @@ set(ARRAY_UFUNCS_2_TEST_SOURCES src/ufuncs/not_equal.cpp src/ufuncs/positive.cpp src/ufuncs/power.cpp + src/ufuncs/radians.cpp + src/ufuncs/rad2deg.cpp src/ufuncs/reciprocal.cpp src/ufuncs/right_shift.cpp src/ufuncs/rint.cpp diff --git a/tests/view/src/column_stack.cpp b/tests/view/src/column_stack.cpp new file mode 100644 index 000000000..b30bb4062 --- /dev/null +++ b/tests/view/src/column_stack.cpp @@ -0,0 +1,39 @@ +#include "nmtools/array/view/column_stack.hpp" +#include "nmtools/testing/data/array/column_stack.hpp" +#include "nmtools/testing/doctest.hpp" + +#define COLUMN_STACK_SUBCASE( case_name, ... ) \ +SUBCASE(#case_name) \ +{ \ + NMTOOLS_TESTING_USE_CASE( array, column_stack, case_name ); \ + auto result = nmtools::view::column_stack( __VA_ARGS__ ); \ + NMTOOLS_ASSERT_EQUAL( nmtools::shape(result), nmtools::shape(expect::result) ); \ + NMTOOLS_ASSERT_CLOSE( result, expect::result ); \ +} + +TEST_CASE("column_stack(case1)" * doctest::test_suite("view::column_stack")) +{ + COLUMN_STACK_SUBCASE( case1, a, b ); + COLUMN_STACK_SUBCASE( case1, a_a, b_a ); + COLUMN_STACK_SUBCASE( case1, a_f, b_f ); + COLUMN_STACK_SUBCASE( case1, a_h, b_h ); + COLUMN_STACK_SUBCASE( case1, a_d, b_d ); +} + +TEST_CASE("column_stack(case2)" * doctest::test_suite("view::column_stack")) +{ + COLUMN_STACK_SUBCASE( case2, a, b ); + COLUMN_STACK_SUBCASE( case2, a_a, b_a ); + COLUMN_STACK_SUBCASE( case2, a_f, b_f ); + COLUMN_STACK_SUBCASE( case2, a_h, b_h ); + COLUMN_STACK_SUBCASE( case2, a_d, b_d ); +} + +TEST_CASE("column_stack(case3)" * doctest::test_suite("view::column_stack")) +{ + COLUMN_STACK_SUBCASE( case3, a, b ); + COLUMN_STACK_SUBCASE( case3, a_a, b_a ); + COLUMN_STACK_SUBCASE( case3, a_f, b_f ); + COLUMN_STACK_SUBCASE( case3, a_h, b_h ); + COLUMN_STACK_SUBCASE( case3, a_d, b_d ); +} \ No newline at end of file diff --git a/tests/view/src/concatenate.cpp b/tests/view/src/concatenate.cpp index 875072a9e..9d2bda1eb 100644 --- a/tests/view/src/concatenate.cpp +++ b/tests/view/src/concatenate.cpp @@ -23,42 +23,11 @@ inline auto name##_ls_db = nmtools::cast(name, nmtools::array::kind::ndarray_ls_ #include "nmtools/constants.hpp" #include "nmtools/testing/doctest.hpp" -#include -#include -#include - -namespace nm = nmtools; -namespace na = nm::array; -namespace view = nm::view; - -#define RUN_impl(...) \ -nm::view::concatenate(__VA_ARGS__); - -#ifdef NMTOOLS_TESTING_ENABLE_BENCHMARKS -#include "nmtools/benchmarks/bench.hpp" -using nm::benchmarks::TrackedBench; -// create immediately invoked lambda -// that packs concatenate fn to callable lambda -#define RUN_concatenate(case_name, ...) \ -[](auto&&...args){ \ - auto title = std::string("concatenate-") + #case_name; \ - auto name = nm::testing::make_func_args("", args...); \ - auto fn = [&](){ \ - return RUN_impl(args...); \ - }; \ - return TrackedBench::run(title, name, fn); \ -}(__VA_ARGS__); -#else -// run normally without benchmarking, ignore case_name -#define RUN_concatenate(case_name, ...) \ -RUN_impl(__VA_ARGS__); -#endif // NMTOOLS_TESTING_ENABLE_BENCHMARKS - #define CONCATENATE_SUBCASE(case_name, lhs, rhs, axis) \ SUBCASE(#case_name) \ { \ NMTOOLS_TESTING_USE_CASE(view, concatenate, case_name); \ - auto array_ref = RUN_concatenate(case_name, args::lhs, args::rhs, args::axis); \ + auto array_ref = nmtools::view::concatenate( args::lhs, args::rhs, args::axis); \ NMTOOLS_ASSERT_EQUAL( nmtools::shape(array_ref), nmtools::shape(expect::expected) ); \ NMTOOLS_ASSERT_CLOSE( array_ref, expect::expected ); \ } diff --git a/tests/view/src/dstack.cpp b/tests/view/src/dstack.cpp new file mode 100644 index 000000000..d0c18b144 --- /dev/null +++ b/tests/view/src/dstack.cpp @@ -0,0 +1,57 @@ +#include "nmtools/array/view/dstack.hpp" +#include "nmtools/testing/data/array/dstack.hpp" +#include "nmtools/testing/doctest.hpp" + +#define DSTACK_SUBCASE( case_name, ... ) \ +SUBCASE(#case_name) \ +{ \ + NMTOOLS_TESTING_USE_CASE( array, dstack, case_name ); \ + auto result = nmtools::view::dstack(__VA_ARGS__); \ + NMTOOLS_ASSERT_EQUAL( nmtools::shape(result), nmtools::shape(expect::result) ); \ + NMTOOLS_ASSERT_CLOSE( result, expect::result ); \ +} + +TEST_CASE("dstack(case1)" * doctest::test_suite("view::dstack")) +{ + DSTACK_SUBCASE( case1, a, b ); + DSTACK_SUBCASE( case1, a_a, b_a ); + DSTACK_SUBCASE( case1, a_f, b_f ); + DSTACK_SUBCASE( case1, a_h, b_h ); + DSTACK_SUBCASE( case1, a_d, b_d ); +} + +TEST_CASE("dstack(case2)" * doctest::test_suite("view::dstack")) +{ + DSTACK_SUBCASE( case2, a, b ); + DSTACK_SUBCASE( case2, a_a, b_a ); + DSTACK_SUBCASE( case2, a_f, b_f ); + DSTACK_SUBCASE( case2, a_h, b_h ); + DSTACK_SUBCASE( case2, a_d, b_d ); +} + +TEST_CASE("dstack(case2b)" * doctest::test_suite("view::dstack")) +{ + DSTACK_SUBCASE( case2b, a, b ); + DSTACK_SUBCASE( case2b, a_a, b_a ); + DSTACK_SUBCASE( case2b, a_f, b_f ); + DSTACK_SUBCASE( case2b, a_h, b_h ); + DSTACK_SUBCASE( case2b, a_d, b_d ); +} + +TEST_CASE("dstack(case3)" * doctest::test_suite("view::dstack")) +{ + DSTACK_SUBCASE( case3, a, b ); + DSTACK_SUBCASE( case3, a_a, b_a ); + DSTACK_SUBCASE( case3, a_f, b_f ); + DSTACK_SUBCASE( case3, a_h, b_h ); + DSTACK_SUBCASE( case3, a_d, b_d ); +} + +TEST_CASE("dstack(case4)" * doctest::test_suite("view::dstack")) +{ + DSTACK_SUBCASE( case4, a, b ); + DSTACK_SUBCASE( case4, a_a, b_a ); + DSTACK_SUBCASE( case4, a_f, b_f ); + DSTACK_SUBCASE( case4, a_h, b_h ); + DSTACK_SUBCASE( case4, a_d, b_d ); +} \ No newline at end of file diff --git a/tests/view/src/ufuncs/deg2rad.cpp b/tests/view/src/ufuncs/deg2rad.cpp new file mode 100644 index 000000000..35cd8d745 --- /dev/null +++ b/tests/view/src/ufuncs/deg2rad.cpp @@ -0,0 +1,79 @@ +#if 1 +#define NMTOOLS_CAST_ARRAYS_EXTRA(name) \ +inline auto name##_cs_fb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_fb); \ +inline auto name##_cs_hb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_hb); \ +inline auto name##_cs_db = nmtools::cast(name, nmtools::array::kind::ndarray_cs_db); \ +inline auto name##_fs_fb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_fb); \ +inline auto name##_fs_hb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_hb); \ +inline auto name##_fs_db = nmtools::cast(name, nmtools::array::kind::ndarray_cs_db); \ +inline auto name##_hs_fb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_fb); \ +inline auto name##_hs_hb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_hb); \ +inline auto name##_hs_db = nmtools::cast(name, nmtools::array::kind::ndarray_cs_db); \ +inline auto name##_ds_fb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_fb); \ +inline auto name##_ds_hb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_hb); \ +inline auto name##_ds_db = nmtools::cast(name, nmtools::array::kind::ndarray_cs_db); +#endif + +#include "nmtools/array/view/ufuncs/deg2rad.hpp" +#include "nmtools/testing/data/array/deg2rad.hpp" +#include "nmtools/testing/doctest.hpp" + +#define DEG2RAD_SUBCASE(case_name, ...) \ +SUBCASE(#case_name) \ +{ \ + NMTOOLS_TESTING_USE_CASE(array, deg2rad, case_name); \ + using namespace args; \ + auto result = nmtools::view::deg2rad(__VA_ARGS__); \ + NMTOOLS_ASSERT_EQUAL( nmtools::shape(result), nmtools::shape(expect::result) ); \ + NMTOOLS_ASSERT_CLOSE( result, expect::result ); \ +} + +TEST_CASE("deg2rad(case1)" * doctest::test_suite("view::deg2rad")) +{ + DEG2RAD_SUBCASE( case1, a); + DEG2RAD_SUBCASE( case1, a_a); + DEG2RAD_SUBCASE( case1, a_f); + DEG2RAD_SUBCASE( case1, a_d); + DEG2RAD_SUBCASE( case1, a_h); + + DEG2RAD_SUBCASE( case1, a_cs_fb ); + DEG2RAD_SUBCASE( case1, a_cs_hb ); + DEG2RAD_SUBCASE( case1, a_cs_db ); + + DEG2RAD_SUBCASE( case1, a_fs_fb ); + DEG2RAD_SUBCASE( case1, a_fs_hb ); + DEG2RAD_SUBCASE( case1, a_fs_db ); + + DEG2RAD_SUBCASE( case1, a_hs_fb ); + DEG2RAD_SUBCASE( case1, a_hs_hb ); + DEG2RAD_SUBCASE( case1, a_hs_db ); + + DEG2RAD_SUBCASE( case1, a_ds_fb ); + DEG2RAD_SUBCASE( case1, a_ds_hb ); + DEG2RAD_SUBCASE( case1, a_ds_db ); +} + +TEST_CASE("deg2rad(case2)" * doctest::test_suite("view::deg2rad")) +{ + DEG2RAD_SUBCASE( case2, a); + DEG2RAD_SUBCASE( case2, a_a); + DEG2RAD_SUBCASE( case2, a_f); + DEG2RAD_SUBCASE( case2, a_d); + DEG2RAD_SUBCASE( case2, a_h); + + DEG2RAD_SUBCASE( case2, a_cs_fb ); + DEG2RAD_SUBCASE( case2, a_cs_hb ); + DEG2RAD_SUBCASE( case2, a_cs_db ); + + DEG2RAD_SUBCASE( case2, a_fs_fb ); + DEG2RAD_SUBCASE( case2, a_fs_hb ); + DEG2RAD_SUBCASE( case2, a_fs_db ); + + DEG2RAD_SUBCASE( case2, a_hs_fb ); + DEG2RAD_SUBCASE( case2, a_hs_hb ); + DEG2RAD_SUBCASE( case2, a_hs_db ); + + DEG2RAD_SUBCASE( case2, a_ds_fb ); + DEG2RAD_SUBCASE( case2, a_ds_hb ); + DEG2RAD_SUBCASE( case2, a_ds_db ); +} \ No newline at end of file diff --git a/tests/view/src/ufuncs/degrees.cpp b/tests/view/src/ufuncs/degrees.cpp new file mode 100644 index 000000000..fb71efff0 --- /dev/null +++ b/tests/view/src/ufuncs/degrees.cpp @@ -0,0 +1,81 @@ +#if 1 +#define NMTOOLS_CAST_ARRAYS_EXTRA(name) \ +inline auto name##_cs_fb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_fb); \ +inline auto name##_cs_hb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_hb); \ +inline auto name##_cs_db = nmtools::cast(name, nmtools::array::kind::ndarray_cs_db); \ +inline auto name##_fs_fb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_fb); \ +inline auto name##_fs_hb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_hb); \ +inline auto name##_fs_db = nmtools::cast(name, nmtools::array::kind::ndarray_cs_db); \ +inline auto name##_hs_fb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_fb); \ +inline auto name##_hs_hb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_hb); \ +inline auto name##_hs_db = nmtools::cast(name, nmtools::array::kind::ndarray_cs_db); \ +inline auto name##_ds_fb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_fb); \ +inline auto name##_ds_hb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_hb); \ +inline auto name##_ds_db = nmtools::cast(name, nmtools::array::kind::ndarray_cs_db); +#endif + +#define NMTOOLS_TESTING_OUTPUT_PRECISION (1e-3) + +#include "nmtools/array/view/ufuncs/degrees.hpp" +#include "nmtools/testing/data/array/degrees.hpp" +#include "nmtools/testing/doctest.hpp" + +#define DEGREES_SUBCASE(case_name, ...) \ +SUBCASE(#case_name) \ +{ \ + NMTOOLS_TESTING_USE_CASE(array, degrees, case_name); \ + using namespace args; \ + auto result = nmtools::view::degrees(__VA_ARGS__); \ + NMTOOLS_ASSERT_EQUAL( nmtools::shape(result), nmtools::shape(expect::result) ); \ + NMTOOLS_ASSERT_CLOSE( result, expect::result ); \ +} + +TEST_CASE("degrees(case1)" * doctest::test_suite("view::degrees")) +{ + DEGREES_SUBCASE( case1, a); + DEGREES_SUBCASE( case1, a_a); + DEGREES_SUBCASE( case1, a_f); + DEGREES_SUBCASE( case1, a_d); + DEGREES_SUBCASE( case1, a_h); + + DEGREES_SUBCASE( case1, a_cs_fb ); + DEGREES_SUBCASE( case1, a_cs_hb ); + DEGREES_SUBCASE( case1, a_cs_db ); + + DEGREES_SUBCASE( case1, a_fs_fb ); + DEGREES_SUBCASE( case1, a_fs_hb ); + DEGREES_SUBCASE( case1, a_fs_db ); + + DEGREES_SUBCASE( case1, a_hs_fb ); + DEGREES_SUBCASE( case1, a_hs_hb ); + DEGREES_SUBCASE( case1, a_hs_db ); + + DEGREES_SUBCASE( case1, a_ds_fb ); + DEGREES_SUBCASE( case1, a_ds_hb ); + DEGREES_SUBCASE( case1, a_ds_db ); +} + +TEST_CASE("degrees(case2)" * doctest::test_suite("view::degrees")) +{ + DEGREES_SUBCASE( case2, a); + DEGREES_SUBCASE( case2, a_a); + DEGREES_SUBCASE( case2, a_f); + DEGREES_SUBCASE( case2, a_d); + DEGREES_SUBCASE( case2, a_h); + + DEGREES_SUBCASE( case2, a_cs_fb ); + DEGREES_SUBCASE( case2, a_cs_hb ); + DEGREES_SUBCASE( case2, a_cs_db ); + + DEGREES_SUBCASE( case2, a_fs_fb ); + DEGREES_SUBCASE( case2, a_fs_hb ); + DEGREES_SUBCASE( case2, a_fs_db ); + + DEGREES_SUBCASE( case2, a_hs_fb ); + DEGREES_SUBCASE( case2, a_hs_hb ); + DEGREES_SUBCASE( case2, a_hs_db ); + + DEGREES_SUBCASE( case2, a_ds_fb ); + DEGREES_SUBCASE( case2, a_ds_hb ); + DEGREES_SUBCASE( case2, a_ds_db ); +} \ No newline at end of file diff --git a/tests/view/src/ufuncs/rad2deg.cpp b/tests/view/src/ufuncs/rad2deg.cpp new file mode 100644 index 000000000..f4bbc2950 --- /dev/null +++ b/tests/view/src/ufuncs/rad2deg.cpp @@ -0,0 +1,81 @@ +#if 1 +#define NMTOOLS_CAST_ARRAYS_EXTRA(name) \ +inline auto name##_cs_fb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_fb); \ +inline auto name##_cs_hb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_hb); \ +inline auto name##_cs_db = nmtools::cast(name, nmtools::array::kind::ndarray_cs_db); \ +inline auto name##_fs_fb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_fb); \ +inline auto name##_fs_hb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_hb); \ +inline auto name##_fs_db = nmtools::cast(name, nmtools::array::kind::ndarray_cs_db); \ +inline auto name##_hs_fb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_fb); \ +inline auto name##_hs_hb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_hb); \ +inline auto name##_hs_db = nmtools::cast(name, nmtools::array::kind::ndarray_cs_db); \ +inline auto name##_ds_fb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_fb); \ +inline auto name##_ds_hb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_hb); \ +inline auto name##_ds_db = nmtools::cast(name, nmtools::array::kind::ndarray_cs_db); +#endif + +#define NMTOOLS_TESTING_OUTPUT_PRECISION (1e-3) + +#include "nmtools/array/view/ufuncs/rad2deg.hpp" +#include "nmtools/testing/data/array/rad2deg.hpp" +#include "nmtools/testing/doctest.hpp" + +#define RAD2DEG_SUBCASE(case_name, ...) \ +SUBCASE(#case_name) \ +{ \ + NMTOOLS_TESTING_USE_CASE(array, rad2deg, case_name); \ + using namespace args; \ + auto result = nmtools::view::rad2deg(__VA_ARGS__); \ + NMTOOLS_ASSERT_EQUAL( nmtools::shape(result), nmtools::shape(expect::result) ); \ + NMTOOLS_ASSERT_CLOSE( result, expect::result ); \ +} + +TEST_CASE("rad2deg(case1)" * doctest::test_suite("view::rad2deg")) +{ + RAD2DEG_SUBCASE( case1, a); + RAD2DEG_SUBCASE( case1, a_a); + RAD2DEG_SUBCASE( case1, a_f); + RAD2DEG_SUBCASE( case1, a_d); + RAD2DEG_SUBCASE( case1, a_h); + + RAD2DEG_SUBCASE( case1, a_cs_fb ); + RAD2DEG_SUBCASE( case1, a_cs_hb ); + RAD2DEG_SUBCASE( case1, a_cs_db ); + + RAD2DEG_SUBCASE( case1, a_fs_fb ); + RAD2DEG_SUBCASE( case1, a_fs_hb ); + RAD2DEG_SUBCASE( case1, a_fs_db ); + + RAD2DEG_SUBCASE( case1, a_hs_fb ); + RAD2DEG_SUBCASE( case1, a_hs_hb ); + RAD2DEG_SUBCASE( case1, a_hs_db ); + + RAD2DEG_SUBCASE( case1, a_ds_fb ); + RAD2DEG_SUBCASE( case1, a_ds_hb ); + RAD2DEG_SUBCASE( case1, a_ds_db ); +} + +TEST_CASE("rad2deg(case2)" * doctest::test_suite("view::rad2deg")) +{ + RAD2DEG_SUBCASE( case2, a); + RAD2DEG_SUBCASE( case2, a_a); + RAD2DEG_SUBCASE( case2, a_f); + RAD2DEG_SUBCASE( case2, a_d); + RAD2DEG_SUBCASE( case2, a_h); + + RAD2DEG_SUBCASE( case2, a_cs_fb ); + RAD2DEG_SUBCASE( case2, a_cs_hb ); + RAD2DEG_SUBCASE( case2, a_cs_db ); + + RAD2DEG_SUBCASE( case2, a_fs_fb ); + RAD2DEG_SUBCASE( case2, a_fs_hb ); + RAD2DEG_SUBCASE( case2, a_fs_db ); + + RAD2DEG_SUBCASE( case2, a_hs_fb ); + RAD2DEG_SUBCASE( case2, a_hs_hb ); + RAD2DEG_SUBCASE( case2, a_hs_db ); + + RAD2DEG_SUBCASE( case2, a_ds_fb ); + RAD2DEG_SUBCASE( case2, a_ds_hb ); + RAD2DEG_SUBCASE( case2, a_ds_db ); +} \ No newline at end of file diff --git a/tests/view/src/ufuncs/radians.cpp b/tests/view/src/ufuncs/radians.cpp new file mode 100644 index 000000000..1c8ef7ec6 --- /dev/null +++ b/tests/view/src/ufuncs/radians.cpp @@ -0,0 +1,79 @@ +#if 1 +#define NMTOOLS_CAST_ARRAYS_EXTRA(name) \ +inline auto name##_cs_fb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_fb); \ +inline auto name##_cs_hb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_hb); \ +inline auto name##_cs_db = nmtools::cast(name, nmtools::array::kind::ndarray_cs_db); \ +inline auto name##_fs_fb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_fb); \ +inline auto name##_fs_hb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_hb); \ +inline auto name##_fs_db = nmtools::cast(name, nmtools::array::kind::ndarray_cs_db); \ +inline auto name##_hs_fb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_fb); \ +inline auto name##_hs_hb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_hb); \ +inline auto name##_hs_db = nmtools::cast(name, nmtools::array::kind::ndarray_cs_db); \ +inline auto name##_ds_fb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_fb); \ +inline auto name##_ds_hb = nmtools::cast(name, nmtools::array::kind::ndarray_cs_hb); \ +inline auto name##_ds_db = nmtools::cast(name, nmtools::array::kind::ndarray_cs_db); +#endif + +#include "nmtools/array/view/ufuncs/radians.hpp" +#include "nmtools/testing/data/array/radians.hpp" +#include "nmtools/testing/doctest.hpp" + +#define RADIANS_SUBCASE(case_name, ...) \ +SUBCASE(#case_name) \ +{ \ + NMTOOLS_TESTING_USE_CASE(array, radians, case_name); \ + using namespace args; \ + auto result = nmtools::view::radians(__VA_ARGS__); \ + NMTOOLS_ASSERT_EQUAL( nmtools::shape(result), nmtools::shape(expect::result) ); \ + NMTOOLS_ASSERT_CLOSE( result, expect::result ); \ +} + +TEST_CASE("radians(case1)" * doctest::test_suite("view::radians")) +{ + RADIANS_SUBCASE( case1, a); + RADIANS_SUBCASE( case1, a_a); + RADIANS_SUBCASE( case1, a_f); + RADIANS_SUBCASE( case1, a_d); + RADIANS_SUBCASE( case1, a_h); + + RADIANS_SUBCASE( case1, a_cs_fb ); + RADIANS_SUBCASE( case1, a_cs_hb ); + RADIANS_SUBCASE( case1, a_cs_db ); + + RADIANS_SUBCASE( case1, a_fs_fb ); + RADIANS_SUBCASE( case1, a_fs_hb ); + RADIANS_SUBCASE( case1, a_fs_db ); + + RADIANS_SUBCASE( case1, a_hs_fb ); + RADIANS_SUBCASE( case1, a_hs_hb ); + RADIANS_SUBCASE( case1, a_hs_db ); + + RADIANS_SUBCASE( case1, a_ds_fb ); + RADIANS_SUBCASE( case1, a_ds_hb ); + RADIANS_SUBCASE( case1, a_ds_db ); +} + +TEST_CASE("radians(case2)" * doctest::test_suite("view::radians")) +{ + RADIANS_SUBCASE( case2, a); + RADIANS_SUBCASE( case2, a_a); + RADIANS_SUBCASE( case2, a_f); + RADIANS_SUBCASE( case2, a_d); + RADIANS_SUBCASE( case2, a_h); + + RADIANS_SUBCASE( case2, a_cs_fb ); + RADIANS_SUBCASE( case2, a_cs_hb ); + RADIANS_SUBCASE( case2, a_cs_db ); + + RADIANS_SUBCASE( case2, a_fs_fb ); + RADIANS_SUBCASE( case2, a_fs_hb ); + RADIANS_SUBCASE( case2, a_fs_db ); + + RADIANS_SUBCASE( case2, a_hs_fb ); + RADIANS_SUBCASE( case2, a_hs_hb ); + RADIANS_SUBCASE( case2, a_hs_db ); + + RADIANS_SUBCASE( case2, a_ds_fb ); + RADIANS_SUBCASE( case2, a_ds_hb ); + RADIANS_SUBCASE( case2, a_ds_db ); +} \ No newline at end of file