diff --git a/include/nmtools/testing/data/array/diagonal.hpp b/include/nmtools/testing/data/array/diagonal.hpp index 7dd7d94a0..3e2972f2b 100644 --- a/include/nmtools/testing/data/array/diagonal.hpp +++ b/include/nmtools/testing/data/array/diagonal.hpp @@ -6,6 +6,8 @@ NMTOOLS_TESTING_DECLARE_CASE(array,diagonal) { + using namespace literals; + NMTOOLS_TESTING_DECLARE_ARGS(case1) { inline int a[2][2] = { @@ -31,6 +33,9 @@ NMTOOLS_TESTING_DECLARE_CASE(array,diagonal) inline int offset = 1; // inline int axis1 = 0; // inline int axis2 = 1; + + inline auto offset_ct = 1_ct; + NMTOOLS_CAST_ARRAYS(a) } NMTOOLS_TESTING_DECLARE_EXPECT(case2) @@ -55,6 +60,10 @@ NMTOOLS_TESTING_DECLARE_CASE(array,diagonal) inline int offset = 0; inline int axis1 = 0; inline int axis2 = 1; + + inline auto offset_ct = 0_ct; + inline auto axis1_ct = 0_ct; + inline auto axis2_ct = 1_ct; NMTOOLS_CAST_ARRAYS(a) } @@ -84,6 +93,10 @@ NMTOOLS_TESTING_DECLARE_CASE(array,diagonal) inline int axis1 = 1; inline int axis2 = 2; + inline auto offset_ct = 0_ct; + inline auto axis1_ct = 1_ct; + inline auto axis2_ct = 2_ct; + NMTOOLS_CAST_ARRAYS(a) } NMTOOLS_TESTING_DECLARE_EXPECT(case4) @@ -112,6 +125,10 @@ NMTOOLS_TESTING_DECLARE_CASE(array,diagonal) inline int axis1 = 2; inline int axis2 = 0; + inline auto offset_ct = 0_ct; + inline auto axis1_ct = 2_ct; + inline auto axis2_ct = 0_ct; + NMTOOLS_CAST_ARRAYS(a) } NMTOOLS_TESTING_DECLARE_EXPECT(case5) @@ -141,6 +158,10 @@ NMTOOLS_TESTING_DECLARE_CASE(array,diagonal) inline int axis1 = -1; inline int axis2 = -3; + inline auto offset_ct = 0_ct; + inline auto axis1_ct = "-1"_ct; + inline auto axis2_ct = "-3"_ct; + NMTOOLS_CAST_ARRAYS(a) } NMTOOLS_TESTING_DECLARE_EXPECT(case6) @@ -151,6 +172,317 @@ NMTOOLS_TESTING_DECLARE_CASE(array,diagonal) {4,11}, }; } + + NMTOOLS_TESTING_DECLARE_ARGS(case7) + { + inline int a[2][3][2] = { + { + {0,1}, + {2,3}, + {4,5}, + }, + { + { 6, 7}, + { 8, 9}, + {10,11}, + } + }; + inline int offset = 1; + inline int axis1 = 0; + inline int axis2 = 2; + + inline auto offset_ct = 1_ct; + inline auto axis1_ct = 0_ct; + inline auto axis2_ct = 2_ct; + + NMTOOLS_CAST_ARRAYS(a) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case7) + { + inline int result[3][1] = { + {1}, + {3}, + {5}, + }; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case8) + { + inline int a[2][3][2] = { + { + {0,1}, + {2,3}, + {4,5}, + }, + { + { 6, 7}, + { 8, 9}, + {10,11}, + } + }; + inline int offset = 1; + inline int axis1 = 0; + inline int axis2 = 1; + + inline auto offset_ct = 1_ct; + inline auto axis1_ct = 0_ct; + inline auto axis2_ct = 1_ct; + + NMTOOLS_CAST_ARRAYS(a) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case8) + { + inline int result[2][2] = { + {2,10}, + {3,11} + }; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case9) + { + inline int a[2][3][2] = { + { + {0,1}, + {2,3}, + {4,5}, + }, + { + { 6, 7}, + { 8, 9}, + {10,11}, + } + }; + inline int offset = 2; + inline int axis1 = 0; + inline int axis2 = 1; + + inline auto offset_ct = 2_ct; + inline auto axis1_ct = 0_ct; + inline auto axis2_ct = 1_ct; + + NMTOOLS_CAST_ARRAYS(a) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case9) + { + inline int result[2][1] = { + {4}, + {5}, + }; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case10) + { + inline int a[1][2][3][4] = { + { + { + {0,1, 2, 3}, + {4,5, 6, 7}, + {8,9,10,11}, + }, + { + {12,13,14,15}, + {16,17,18,19}, + {20,21,22,23}, + } + } + }; + inline int offset = 0; + inline int axis1 = 0; + inline int axis2 = 1; + + inline auto offset_ct = 0_ct; + inline auto axis1_ct = 0_ct; + inline auto axis2_ct = 1_ct; + + NMTOOLS_CAST_ARRAYS(a) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case10) + { + inline int result[3][4][1] = { + { + {0}, + {1}, + {2}, + {3}, + }, + { + {4}, + {5}, + {6}, + {7}, + }, + { + { 8}, + { 9}, + {10}, + {11}, + }, + }; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case11) + { + inline int a[1][2][3][4] = { + { + { + {0,1, 2, 3}, + {4,5, 6, 7}, + {8,9,10,11}, + }, + { + {12,13,14,15}, + {16,17,18,19}, + {20,21,22,23}, + } + } + }; + inline int offset = 1; + inline int axis1 = 0; + inline int axis2 = 1; + + inline auto offset_ct = 1_ct; + inline auto axis1_ct = 0_ct; + inline auto axis2_ct = 1_ct; + + NMTOOLS_CAST_ARRAYS(a) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case11) + { + inline int result[3][4][1] = { + { + {12}, + {13}, + {14}, + {15}, + }, + { + {16}, + {17}, + {18}, + {19}, + }, + { + {20}, + {21}, + {22}, + {23}, + }, + }; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case12) + { + inline int a[1][2][3][4] = { + { + { + {0,1, 2, 3}, + {4,5, 6, 7}, + {8,9,10,11}, + }, + { + {12,13,14,15}, + {16,17,18,19}, + {20,21,22,23}, + } + } + }; + inline int offset = 0; + inline int axis1 = 1; + inline int axis2 = 2; + + inline auto offset_ct = 0_ct; + inline auto axis1_ct = 1_ct; + inline auto axis2_ct = 2_ct; + + NMTOOLS_CAST_ARRAYS(a) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case12) + { + inline int result[1][4][2] = { + { + {0,16}, + {1,17}, + {2,18}, + {3,19}, + } + }; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case13) + { + inline int a[1][2][3][4] = { + { + { + {0,1, 2, 3}, + {4,5, 6, 7}, + {8,9,10,11}, + }, + { + {12,13,14,15}, + {16,17,18,19}, + {20,21,22,23}, + } + } + }; + inline int offset = 1; + inline int axis1 = 1; + inline int axis2 = 2; + + inline auto offset_ct = 1_ct; + inline auto axis1_ct = 1_ct; + inline auto axis2_ct = 2_ct; + + NMTOOLS_CAST_ARRAYS(a) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case13) + { + inline int result[1][4][2] = { + { + {4,20}, + {5,21}, + {6,22}, + {7,23}, + } + }; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case14) + { + inline int a[1][2][3][4] = { + { + { + {0,1, 2, 3}, + {4,5, 6, 7}, + {8,9,10,11}, + }, + { + {12,13,14,15}, + {16,17,18,19}, + {20,21,22,23}, + } + } + }; + inline int offset = 2; + inline int axis1 = 1; + inline int axis2 = 2; + + inline auto offset_ct = 2_ct; + inline auto axis1_ct = 1_ct; + inline auto axis2_ct = 2_ct; + + NMTOOLS_CAST_ARRAYS(a) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case14) + { + inline int result[1][4][1] = { + { + { 8}, + { 9}, + {10}, + {11}, + } + }; + } } #endif // NMTOOLS_TESTING_DATA_ARRAY_DIAGONAL_HPP \ No newline at end of file diff --git a/include/nmtools/testing/data/index/diagonal.hpp b/include/nmtools/testing/data/index/diagonal.hpp index f1f4765d0..34a8e86a7 100644 --- a/include/nmtools/testing/data/index/diagonal.hpp +++ b/include/nmtools/testing/data/index/diagonal.hpp @@ -198,6 +198,44 @@ NMTOOLS_TESTING_DECLARE_CASE(index,shape_diagonal) inline int result[2] = {3,2}; } + NMTOOLS_TESTING_DECLARE_ARGS(case2g) + { + inline int src_shape[3] = {2,3,2}; + inline int offset = 2; + inline int axis1 = 0; + inline int axis2 = 1; + + inline auto src_shape_ct = nmtools_tuple{2_ct,3_ct,2_ct}; + inline int offset_ct = 2_ct; + inline int axis1_ct = 0_ct; + inline int axis2_ct = 1_ct; + + NMTOOLS_CAST_INDEX_ARRAYS(src_shape) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case2g) + { + inline int result[2] = {2,1}; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case2h) + { + inline int src_shape[3] = {2,3,2}; + inline int offset = 1; + inline int axis1 = 0; + inline int axis2 = 1; + + inline auto src_shape_ct = nmtools_tuple{2_ct,3_ct,2_ct}; + inline int offset_ct = 1_ct; + inline int axis1_ct = 0_ct; + inline int axis2_ct = 1_ct; + + NMTOOLS_CAST_INDEX_ARRAYS(src_shape) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case2h) + { + inline int result[2] = {2,2}; + } + NMTOOLS_TESTING_DECLARE_ARGS(case3a) { inline int src_shape[4] = {2,1,3,5}; @@ -235,8 +273,86 @@ NMTOOLS_TESTING_DECLARE_CASE(index,shape_diagonal) { inline int result[3] = {2,5,1}; } + + NMTOOLS_TESTING_DECLARE_ARGS(case3c) + { + inline int src_shape[4] = {1,2,3,4}; + inline int offset = 0; + inline int axis1 = 0; + inline int axis2 = 1; + + inline auto src_shape_ct = nmtools_tuple{1_ct,2_ct,3_ct,4_ct}; + inline auto offset_ct = 0_ct; + inline auto axis1_ct = 0_ct; + inline auto axis2_ct = 1_ct; + + NMTOOLS_CAST_INDEX_ARRAYS(src_shape) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case3c) + { + inline int result[3] = {3,4,1}; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case3d) + { + inline int src_shape[4] = {1,2,3,4}; + inline int offset = 1; + inline int axis1 = 0; + inline int axis2 = 1; + + inline auto src_shape_ct = nmtools_tuple{1_ct,2_ct,3_ct,4_ct}; + inline auto offset_ct = 1_ct; + inline auto axis1_ct = 0_ct; + inline auto axis2_ct = 1_ct; + + NMTOOLS_CAST_INDEX_ARRAYS(src_shape) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case3d) + { + inline int result[3] = {3,4,1}; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case3e) + { + inline int src_shape[4] = {1,2,3,4}; + inline int offset = 0; + inline int axis1 = 1; + inline int axis2 = 2; + + inline auto src_shape_ct = nmtools_tuple{1_ct,2_ct,3_ct,4_ct}; + inline auto offset_ct = 0_ct; + inline auto axis1_ct = 1_ct; + inline auto axis2_ct = 2_ct; + + NMTOOLS_CAST_INDEX_ARRAYS(src_shape) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case3e) + { + inline int result[3] = {1,4,2}; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case3f) + { + inline int src_shape[4] = {1,2,3,4}; + inline int offset = 1; + inline int axis1 = 1; + inline int axis2 = 2; + + inline auto src_shape_ct = nmtools_tuple{1_ct,2_ct,3_ct,4_ct}; + inline auto offset_ct = 1_ct; + inline auto axis1_ct = 1_ct; + inline auto axis2_ct = 2_ct; + + NMTOOLS_CAST_INDEX_ARRAYS(src_shape) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case3f) + { + inline int result[3] = {1,4,2}; + } } +/******************************************************************************/ + NMTOOLS_TESTING_DECLARE_CASE(index,diagonal) { NMTOOLS_TESTING_DECLARE_ARGS(case1a) @@ -246,6 +362,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index,diagonal) inline int offset = 0; inline int axis1 = 0; inline int axis2 = 1; + + NMTOOLS_CAST_INDEX_ARRAYS(src_shape) + NMTOOLS_CAST_INDEX_ARRAYS(indices) } NMTOOLS_TESTING_DECLARE_EXPECT(case1a) { @@ -259,6 +378,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index,diagonal) inline int offset = 0; inline int axis1 = 0; inline int axis2 = 1; + + NMTOOLS_CAST_INDEX_ARRAYS(src_shape) + NMTOOLS_CAST_INDEX_ARRAYS(indices) } NMTOOLS_TESTING_DECLARE_EXPECT(case1b) { @@ -272,6 +394,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index,diagonal) inline int offset = 1; inline int axis1 = 0; inline int axis2 = 1; + + NMTOOLS_CAST_INDEX_ARRAYS(src_shape) + NMTOOLS_CAST_INDEX_ARRAYS(indices) } NMTOOLS_TESTING_DECLARE_EXPECT(case2a) { @@ -285,6 +410,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index,diagonal) inline int offset = 0; inline int axis1 = 0; inline int axis2 = 1; + + NMTOOLS_CAST_INDEX_ARRAYS(src_shape) + NMTOOLS_CAST_INDEX_ARRAYS(indices) } NMTOOLS_TESTING_DECLARE_EXPECT(case3a) { @@ -298,6 +426,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index,diagonal) inline int offset = 0; inline int axis1 = 0; inline int axis2 = 1; + + NMTOOLS_CAST_INDEX_ARRAYS(src_shape) + NMTOOLS_CAST_INDEX_ARRAYS(indices) } NMTOOLS_TESTING_DECLARE_EXPECT(case3b) { @@ -311,6 +442,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index,diagonal) inline int offset = 0; inline int axis1 = 0; inline int axis2 = 1; + + NMTOOLS_CAST_INDEX_ARRAYS(src_shape) + NMTOOLS_CAST_INDEX_ARRAYS(indices) } NMTOOLS_TESTING_DECLARE_EXPECT(case3c) { @@ -324,6 +458,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index,diagonal) inline int offset = 0; inline int axis1 = 0; inline int axis2 = 1; + + NMTOOLS_CAST_INDEX_ARRAYS(src_shape) + NMTOOLS_CAST_INDEX_ARRAYS(indices) } NMTOOLS_TESTING_DECLARE_EXPECT(case3d) { @@ -335,8 +472,11 @@ NMTOOLS_TESTING_DECLARE_CASE(index,diagonal) inline int src_shape[3] = {2,3,2}; inline int indices[2] = {0,0}; inline int offset = 0; - inline int axsi1 = 1; + inline int axis1 = 1; inline int axis2 = 2; + + NMTOOLS_CAST_INDEX_ARRAYS(src_shape) + NMTOOLS_CAST_INDEX_ARRAYS(indices) } NMTOOLS_TESTING_DECLARE_EXPECT(case4a) { @@ -350,6 +490,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index,diagonal) inline int offset = 0; inline int axis1 = 1; inline int axis2 = 2; + + NMTOOLS_CAST_INDEX_ARRAYS(src_shape) + NMTOOLS_CAST_INDEX_ARRAYS(indices) } NMTOOLS_TESTING_DECLARE_EXPECT(case4b) { @@ -363,6 +506,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index,diagonal) inline int offset = 0; inline int axis1 = 1; inline int axis2 = 2; + + NMTOOLS_CAST_INDEX_ARRAYS(src_shape) + NMTOOLS_CAST_INDEX_ARRAYS(indices) } NMTOOLS_TESTING_DECLARE_EXPECT(case4c) { @@ -376,6 +522,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index,diagonal) inline int offset = 0; inline int axis1 = 1; inline int axis2 = 2; + + NMTOOLS_CAST_INDEX_ARRAYS(src_shape) + NMTOOLS_CAST_INDEX_ARRAYS(indices) } NMTOOLS_TESTING_DECLARE_EXPECT(case4d) { @@ -389,8 +538,11 @@ NMTOOLS_TESTING_DECLARE_CASE(index,diagonal) inline int offset = 0; inline int axis1 = 2; inline int axis2 = 0; + + NMTOOLS_CAST_INDEX_ARRAYS(src_shape) + NMTOOLS_CAST_INDEX_ARRAYS(indices) } - NMTOOLS_TESITNG_DECLARE_EXPECT(case5a) + NMTOOLS_TESTING_DECLARE_EXPECT(case5a) { inline int result[3] = {0,0,0}; } @@ -402,6 +554,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index,diagonal) inline int offset = 0; inline int axis1 = 2; inline int axis2 = 0; + + NMTOOLS_CAST_INDEX_ARRAYS(src_shape) + NMTOOLS_CAST_INDEX_ARRAYS(indices) } NMTOOLS_TESTING_DECLARE_EXPECT(case5b) { @@ -415,6 +570,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index,diagonal) inline int offset = 0; inline int axis1 = 2; inline int axis2 = 0; + + NMTOOLS_CAST_INDEX_ARRAYS(src_shape) + NMTOOLS_CAST_INDEX_ARRAYS(indices) } NMTOOLS_TESTING_DECLARE_EXPECT(case5c) { @@ -428,6 +586,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index,diagonal) inline int offset = 0; inline int axis1 = 2; inline int axis2 = 0; + + NMTOOLS_CAST_INDEX_ARRAYS(src_shape) + NMTOOLS_CAST_INDEX_ARRAYS(indices) } NMTOOLS_TESTING_DECLARE_EXPECT(case5d) { @@ -441,6 +602,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index,diagonal) inline int offset = 0; inline int axis1 = 2; inline int axis2 = 0; + + NMTOOLS_CAST_INDEX_ARRAYS(src_shape) + NMTOOLS_CAST_INDEX_ARRAYS(indices) } NMTOOLS_TESTING_DECLARE_EXPECT(case5e) { @@ -454,11 +618,62 @@ NMTOOLS_TESTING_DECLARE_CASE(index,diagonal) inline int offset = 0; inline int axis1 = 2; inline int axis2 = 0; + + NMTOOLS_CAST_INDEX_ARRAYS(src_shape) + NMTOOLS_CAST_INDEX_ARRAYS(indices) } - NMTOOLS_TESITNG_DECLARE_EXPECT(case5f) + NMTOOLS_TESTING_DECLARE_EXPECT(case5f) { inline int result[3] = {1,2,1}; } + + NMTOOLS_TESTING_DECLARE_ARGS(case7a) + { + inline int src_shape[3] = {2,3,2}; + inline int indices[2] = {0,0}; + inline int offset = 1; + inline int axis1 = 2; + inline int axis2 = 0; + + NMTOOLS_CAST_INDEX_ARRAYS(src_shape) + NMTOOLS_CAST_INDEX_ARRAYS(indices) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case7a) + { + inline int result[3] = {1,0,0}; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case7b) + { + inline int src_shape[3] = {2,3,2}; + inline int indices[2] = {1,0}; + inline int offset = 1; + inline int axis1 = 2; + inline int axis2 = 0; + + NMTOOLS_CAST_INDEX_ARRAYS(src_shape) + NMTOOLS_CAST_INDEX_ARRAYS(indices) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case7b) + { + inline int result[3] = {1,1,0}; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case7c) + { + inline int src_shape[3] = {2,3,2}; + inline int indices[2] = {2,0}; + inline int offset = 1; + inline int axis1 = 2; + inline int axis2 = 0; + + NMTOOLS_CAST_INDEX_ARRAYS(src_shape) + NMTOOLS_CAST_INDEX_ARRAYS(indices) + } + NMTOOLS_TESTING_DECLARE_EXPECT(case7c) + { + inline int result[3] = {1,2,0}; + } } #endif // NMTOOLS_TESTING_DATA_INDEX_DIAGONAL_HPP \ No newline at end of file diff --git a/tests/array/CMakeLists.txt b/tests/array/CMakeLists.txt index df2fccf2e..ea27db2ad 100644 --- a/tests/array/CMakeLists.txt +++ b/tests/array/CMakeLists.txt @@ -101,6 +101,7 @@ set(ARRAY_EVAL_TEST_SOURCES array/cumprod.cpp array/cumsum.cpp array/diagflat.cpp + array/diagonal.cpp array/expand_dims.cpp array/expand.cpp array/eye.cpp diff --git a/tests/array/array/diagonal.cpp b/tests/array/array/diagonal.cpp new file mode 100644 index 000000000..682936155 --- /dev/null +++ b/tests/array/array/diagonal.cpp @@ -0,0 +1,158 @@ +#if defined(NMTOOLS_TESTING_GENERIC_NDARRAY) +#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_fs_fb); \ +inline auto name##_fs_hb = nmtools::cast(name, nmtools::array::kind::ndarray_fs_hb); \ +inline auto name##_fs_db = nmtools::cast(name, nmtools::array::kind::ndarray_fs_db); \ +inline auto name##_hs_fb = nmtools::cast(name, nmtools::array::kind::ndarray_hs_fb); \ +inline auto name##_hs_hb = nmtools::cast(name, nmtools::array::kind::ndarray_hs_hb); \ +inline auto name##_hs_db = nmtools::cast(name, nmtools::array::kind::ndarray_hs_db); \ +inline auto name##_ds_fb = nmtools::cast(name, nmtools::array::kind::ndarray_ds_fb); \ +inline auto name##_ds_hb = nmtools::cast(name, nmtools::array::kind::ndarray_ds_hb); \ +inline auto name##_ds_db = nmtools::cast(name, nmtools::array::kind::ndarray_ds_db); \ +inline auto name##_ls_fb = nmtools::cast(name, nmtools::array::kind::ndarray_ls_fb); \ +inline auto name##_ls_hb = nmtools::cast(name, nmtools::array::kind::ndarray_ls_hb); \ +inline auto name##_ls_db = nmtools::cast(name, nmtools::array::kind::ndarray_ls_db); +#endif + +#include "nmtools/array/array/diagonal.hpp" +#include "nmtools/testing/data/array/diagonal.hpp" +#include "nmtools/testing/doctest.hpp" + +#define DIAGONAL_SUBCASE(case_name, ...) \ +SUBCASE(#case_name) \ +{ \ + NMTOOLS_TESTING_USE_CASE( array, diagonal, case_name ); \ + using namespace args; \ + auto result = nmtools::array::diagonal(__VA_ARGS__); \ + NMTOOLS_ASSERT_EQUAL( nmtools::shape(result), nmtools::shape(expect::result) ); \ + NMTOOLS_ASSERT_CLOSE( result, expect::result ); \ +} + +TEST_CASE("diagonal(case1)" * doctest::test_suite("array::diagonal")) +{ + DIAGONAL_SUBCASE( case1, a ); + DIAGONAL_SUBCASE( case1, a_a ); + DIAGONAL_SUBCASE( case1, a_f ); + DIAGONAL_SUBCASE( case1, a_h ); + DIAGONAL_SUBCASE( case1, a_d ); +} + +TEST_CASE("diagonal(case2)" * doctest::test_suite("array::diagonal")) +{ + // DIAGONAL_SUBCASE( case2, a, offset ); + DIAGONAL_SUBCASE( case2, a_a, offset ); + DIAGONAL_SUBCASE( case2, a_f, offset ); + DIAGONAL_SUBCASE( case2, a_h, offset ); + DIAGONAL_SUBCASE( case2, a_d, offset ); +} + +TEST_CASE("diagonal(case3)" * doctest::test_suite("array::diagonal")) +{ + DIAGONAL_SUBCASE( case3, a, offset ); + DIAGONAL_SUBCASE( case3, a_a, offset ); + DIAGONAL_SUBCASE( case3, a_f, offset ); + DIAGONAL_SUBCASE( case3, a_h, offset ); + DIAGONAL_SUBCASE( case3, a_d, offset ); +} + +TEST_CASE("diagonal(case4)" * doctest::test_suite("array::diagonal")) +{ + DIAGONAL_SUBCASE( case4, a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case4, a_a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case4, a_f, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case4, a_h, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case4, a_d, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case5)" * doctest::test_suite("array::diagonal")) +{ + DIAGONAL_SUBCASE( case5, a, offset, axis1,axis2 ); + DIAGONAL_SUBCASE( case5, a_a, offset, axis1,axis2 ); + DIAGONAL_SUBCASE( case5, a_f, offset, axis1,axis2 ); + DIAGONAL_SUBCASE( case5, a_h, offset, axis1,axis2 ); + DIAGONAL_SUBCASE( case5, a_d, offset, axis1,axis2 ); +} + +TEST_CASE("diagonal(case6)" * doctest::test_suite("array::diagonal")) +{ + DIAGONAL_SUBCASE( case6, a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case6, a_a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case6, a_f, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case6, a_h, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case6, a_d, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case7)" * doctest::test_suite("array::diagonal")) +{ + DIAGONAL_SUBCASE( case7, a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case7, a_a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case7, a_f, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case7, a_h, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case7, a_d, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case8)" * doctest::test_suite("array::diagonal")) +{ + DIAGONAL_SUBCASE( case8, a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case8, a_a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case8, a_f, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case8, a_h, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case8, a_d, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case9)" * doctest::test_suite("array::diagonal")) +{ + DIAGONAL_SUBCASE( case9, a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case9, a_a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case9, a_f, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case9, a_h, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case9, a_d, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case10)" * doctest::test_suite("array::diagonal")) +{ + DIAGONAL_SUBCASE( case10, a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case10, a_a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case10, a_f, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case10, a_h, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case10, a_d, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case11)" * doctest::test_suite("array::diagonal")) +{ + DIAGONAL_SUBCASE( case11, a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case11, a_a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case11, a_f, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case11, a_h, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case11, a_d, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case12)" * doctest::test_suite("array::diagonal")) +{ + DIAGONAL_SUBCASE( case12, a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case12, a_a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case12, a_f, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case12, a_h, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case12, a_d, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case13)" * doctest::test_suite("array::diagonal")) +{ + DIAGONAL_SUBCASE( case13, a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case13, a_a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case13, a_f, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case13, a_h, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case13, a_d, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case14)" * doctest::test_suite("array::diagonal")) +{ + DIAGONAL_SUBCASE( case14, a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case14, a_a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case14, a_f, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case14, a_h, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case14, a_d, offset, axis1, axis2 ); +} \ No newline at end of file diff --git a/tests/index/CMakeLists.txt b/tests/index/CMakeLists.txt index 48a126c12..ef378fd99 100644 --- a/tests/index/CMakeLists.txt +++ b/tests/index/CMakeLists.txt @@ -54,6 +54,7 @@ if (NMTOOLS_INDEX_TEST_ALL) src/compute_strides.cpp src/concatenate.cpp src/convnd.cpp + src/diagonal.cpp src/expand_dims.cpp src/expand.cpp src/eye.cpp diff --git a/tests/index/src/diagonal.cpp b/tests/index/src/diagonal.cpp index 43a1a1808..f994bed14 100644 --- a/tests/index/src/diagonal.cpp +++ b/tests/index/src/diagonal.cpp @@ -11,6 +11,15 @@ SUBCASE(#case_name) \ NMTOOLS_ASSERT_EQUAL( result, expect::result ); \ } +#define INDEX_DIAGONAL_SUBCASE(case_name, ...) \ +SUBCASE(#case_name) \ +{ \ + NMTOOLS_TESTING_USE_CASE(index,diagonal,case_name); \ + using namespace args; \ + auto result = nmtools::index::diagonal(__VA_ARGS__); \ + NMTOOLS_ASSERT_EQUAL( result, expect::result ); \ +} + TEST_CASE("shape_diagonal(case1a)" * doctest::test_suite("index::shape_diagonal")) { SHAPE_DIAGONAL_SUBCASE( case1a, src_shape, offset, axis1, axis2 ); @@ -121,6 +130,28 @@ TEST_CASE("shape_diagonal(case2f)" * doctest::test_suite("index::shape_diagonal" SHAPE_DIAGONAL_SUBCASE( case2f, src_shape_ct, offset_ct, axis1_ct, axis2_ct ); } +TEST_CASE("shape_diagonal(case2g)" * doctest::test_suite("index::shape_diagonal")) +{ + SHAPE_DIAGONAL_SUBCASE( case2g, src_shape, offset, axis1, axis2 ); + SHAPE_DIAGONAL_SUBCASE( case2g, src_shape_a, offset, axis1, axis2 ); + SHAPE_DIAGONAL_SUBCASE( case2g, src_shape_f, offset, axis1, axis2 ); + SHAPE_DIAGONAL_SUBCASE( case2g, src_shape_h, offset, axis1, axis2 ); + SHAPE_DIAGONAL_SUBCASE( case2g, src_shape_v, offset, axis1, axis2 ); + + SHAPE_DIAGONAL_SUBCASE( case2g, src_shape_ct, offset_ct, axis1_ct, axis2_ct ); +} + +TEST_CASE("shape_diagonal(case2h)" * doctest::test_suite("index::shape_diagonal")) +{ + SHAPE_DIAGONAL_SUBCASE( case2h, src_shape, offset, axis1, axis2 ); + SHAPE_DIAGONAL_SUBCASE( case2h, src_shape_a, offset, axis1, axis2 ); + SHAPE_DIAGONAL_SUBCASE( case2h, src_shape_f, offset, axis1, axis2 ); + SHAPE_DIAGONAL_SUBCASE( case2h, src_shape_h, offset, axis1, axis2 ); + SHAPE_DIAGONAL_SUBCASE( case2h, src_shape_v, offset, axis1, axis2 ); + + SHAPE_DIAGONAL_SUBCASE( case2h, src_shape_ct, offset_ct, axis1_ct, axis2_ct ); +} + TEST_CASE("shape_diagonal(case3a)" * doctest::test_suite("index::shape_diagonal")) { SHAPE_DIAGONAL_SUBCASE( case3a, src_shape, offset, axis1, axis2 ); @@ -141,4 +172,228 @@ TEST_CASE("shape_diagonal(case3b)" * doctest::test_suite("index::shape_diagonal" SHAPE_DIAGONAL_SUBCASE( case3b, src_shape_v, offset, axis1, axis2 ); SHAPE_DIAGONAL_SUBCASE( case3b, src_shape_ct, offset_ct, axis1_ct, axis2_ct ); +} + +TEST_CASE("shape_diagonal(case3c)" * doctest::test_suite("index::shape_diagonal")) +{ + SHAPE_DIAGONAL_SUBCASE( case3c, src_shape, offset, axis1, axis2 ); + SHAPE_DIAGONAL_SUBCASE( case3c, src_shape_a, offset, axis1, axis2 ); + SHAPE_DIAGONAL_SUBCASE( case3c, src_shape_f, offset, axis1, axis2 ); + SHAPE_DIAGONAL_SUBCASE( case3c, src_shape_h, offset, axis1, axis2 ); + SHAPE_DIAGONAL_SUBCASE( case3c, src_shape_v, offset, axis1, axis2 ); + + SHAPE_DIAGONAL_SUBCASE( case3c, src_shape_ct, offset_ct, axis1_ct, axis2_ct ); +} + +TEST_CASE("shape_diagonal(case3d)" * doctest::test_suite("index::shape_diagonal")) +{ + SHAPE_DIAGONAL_SUBCASE( case3d, src_shape, offset, axis1, axis2 ); + SHAPE_DIAGONAL_SUBCASE( case3d, src_shape_a, offset, axis1, axis2 ); + SHAPE_DIAGONAL_SUBCASE( case3d, src_shape_f, offset, axis1, axis2 ); + SHAPE_DIAGONAL_SUBCASE( case3d, src_shape_h, offset, axis1, axis2 ); + SHAPE_DIAGONAL_SUBCASE( case3d, src_shape_v, offset, axis1, axis2 ); + + SHAPE_DIAGONAL_SUBCASE( case3d, src_shape_ct, offset_ct, axis1_ct, axis2_ct ); +} + +TEST_CASE("shape_diagonal(case3e)" * doctest::test_suite("index::shape_diagonal")) +{ + SHAPE_DIAGONAL_SUBCASE( case3e, src_shape, offset, axis1, axis2 ); + SHAPE_DIAGONAL_SUBCASE( case3e, src_shape_a, offset, axis1, axis2 ); + SHAPE_DIAGONAL_SUBCASE( case3e, src_shape_f, offset, axis1, axis2 ); + SHAPE_DIAGONAL_SUBCASE( case3e, src_shape_h, offset, axis1, axis2 ); + SHAPE_DIAGONAL_SUBCASE( case3e, src_shape_v, offset, axis1, axis2 ); + + SHAPE_DIAGONAL_SUBCASE( case3e, src_shape_ct, offset_ct, axis1_ct, axis2_ct ); +} + +TEST_CASE("shape_diagonal(case3f)" * doctest::test_suite("index::shape_diagonal")) +{ + SHAPE_DIAGONAL_SUBCASE( case3f, src_shape, offset, axis1, axis2 ); + SHAPE_DIAGONAL_SUBCASE( case3f, src_shape_a, offset, axis1, axis2 ); + SHAPE_DIAGONAL_SUBCASE( case3f, src_shape_f, offset, axis1, axis2 ); + SHAPE_DIAGONAL_SUBCASE( case3f, src_shape_h, offset, axis1, axis2 ); + SHAPE_DIAGONAL_SUBCASE( case3f, src_shape_v, offset, axis1, axis2 ); + + SHAPE_DIAGONAL_SUBCASE( case3f, src_shape_ct, offset_ct, axis1_ct, axis2_ct ); +} + +TEST_CASE("diagonal(case1a)" * doctest::test_suite("index::diagonal")) +{ + INDEX_DIAGONAL_SUBCASE( case1a, src_shape, indices, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case1a, src_shape_a, indices_a, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case1a, src_shape_f, indices_f, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case1a, src_shape_h, indices_h, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case1a, src_shape_v, indices_v, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case1b)" * doctest::test_suite("index::diagonal")) +{ + INDEX_DIAGONAL_SUBCASE( case1b, src_shape, indices, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case1b, src_shape_a, indices_a, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case1b, src_shape_f, indices_f, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case1b, src_shape_h, indices_h, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case1b, src_shape_v, indices_v, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case2a)" * doctest::test_suite("index::diagonal")) +{ + INDEX_DIAGONAL_SUBCASE( case2a, src_shape, indices, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case2a, src_shape_a, indices_a, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case2a, src_shape_f, indices_f, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case2a, src_shape_h, indices_h, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case2a, src_shape_v, indices_v, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case3a)" * doctest::test_suite("index::diagonal")) +{ + INDEX_DIAGONAL_SUBCASE( case3a, src_shape, indices, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case3a, src_shape_a, indices_a, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case3a, src_shape_f, indices_f, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case3a, src_shape_h, indices_h, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case3a, src_shape_v, indices_v, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case3b)" * doctest::test_suite("index::diagonal")) +{ + INDEX_DIAGONAL_SUBCASE( case3b, src_shape, indices, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case3b, src_shape_a, indices_a, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case3b, src_shape_f, indices_f, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case3b, src_shape_h, indices_h, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case3b, src_shape_v, indices_v, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case3c)" * doctest::test_suite("index::diagonal")) +{ + INDEX_DIAGONAL_SUBCASE( case3c, src_shape, indices, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case3c, src_shape_a, indices_a, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case3c, src_shape_f, indices_f, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case3c, src_shape_h, indices_h, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case3c, src_shape_v, indices_v, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case3d)" * doctest::test_suite("index::diagonal")) +{ + INDEX_DIAGONAL_SUBCASE( case3d, src_shape, indices, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case3d, src_shape_a, indices_a, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case3d, src_shape_f, indices_f, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case3d, src_shape_h, indices_h, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case3d, src_shape_v, indices_v, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case4a)" * doctest::test_suite("index::diagonal")) +{ + INDEX_DIAGONAL_SUBCASE( case4a, src_shape, indices, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case4a, src_shape_a, indices_a, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case4a, src_shape_f, indices_f, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case4a, src_shape_h, indices_h, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case4a, src_shape_v, indices_v, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case4b)" * doctest::test_suite("index::diagonal")) +{ + INDEX_DIAGONAL_SUBCASE( case4b, src_shape, indices, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case4b, src_shape_a, indices_a, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case4b, src_shape_f, indices_f, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case4b, src_shape_h, indices_h, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case4b, src_shape_v, indices_v, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case4c)" * doctest::test_suite("index::diagonal")) +{ + INDEX_DIAGONAL_SUBCASE( case4c, src_shape, indices, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case4c, src_shape_a, indices_a, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case4c, src_shape_f, indices_f, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case4c, src_shape_h, indices_h, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case4c, src_shape_v, indices_v, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case4d)" * doctest::test_suite("index::diagonal")) +{ + INDEX_DIAGONAL_SUBCASE( case4d, src_shape, indices, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case4d, src_shape_a, indices_a, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case4d, src_shape_f, indices_f, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case4d, src_shape_h, indices_h, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case4d, src_shape_v, indices_v, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case5a)" * doctest::test_suite("index::diagonal")) +{ + INDEX_DIAGONAL_SUBCASE( case5a, src_shape, indices, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case5a, src_shape_a, indices_a, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case5a, src_shape_f, indices_f, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case5a, src_shape_h, indices_h, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case5a, src_shape_v, indices_v, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case5b)" * doctest::test_suite("index::diagonal")) +{ + INDEX_DIAGONAL_SUBCASE( case5b, src_shape, indices, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case5b, src_shape_a, indices_a, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case5b, src_shape_f, indices_f, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case5b, src_shape_h, indices_h, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case5b, src_shape_v, indices_v, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case5c)" * doctest::test_suite("index::diagonal")) +{ + INDEX_DIAGONAL_SUBCASE( case5c, src_shape, indices, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case5c, src_shape_a, indices_a, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case5c, src_shape_f, indices_f, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case5c, src_shape_h, indices_h, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case5c, src_shape_v, indices_v, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case5d)" * doctest::test_suite("index::diagonal")) +{ + INDEX_DIAGONAL_SUBCASE( case5d, src_shape, indices, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case5d, src_shape_a, indices_a, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case5d, src_shape_f, indices_f, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case5d, src_shape_h, indices_h, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case5d, src_shape_v, indices_v, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case5e)" * doctest::test_suite("index::diagonal")) +{ + INDEX_DIAGONAL_SUBCASE( case5e, src_shape, indices, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case5e, src_shape_a, indices_a, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case5e, src_shape_f, indices_f, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case5e, src_shape_h, indices_h, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case5e, src_shape_v, indices_v, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case5f)" * doctest::test_suite("index::diagonal")) +{ + INDEX_DIAGONAL_SUBCASE( case5f, src_shape, indices, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case5f, src_shape_a, indices_a, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case5f, src_shape_f, indices_f, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case5f, src_shape_h, indices_h, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case5f, src_shape_v, indices_v, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case7a)" * doctest::test_suite("index::diagonal")) +{ + INDEX_DIAGONAL_SUBCASE( case7a, src_shape, indices, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case7a, src_shape_a, indices_a, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case7a, src_shape_f, indices_f, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case7a, src_shape_h, indices_h, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case7a, src_shape_v, indices_v, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case7b)" * doctest::test_suite("index::diagonal")) +{ + INDEX_DIAGONAL_SUBCASE( case7b, src_shape, indices, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case7b, src_shape_a, indices_a, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case7b, src_shape_f, indices_f, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case7b, src_shape_h, indices_h, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case7b, src_shape_v, indices_v, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case7c)" * doctest::test_suite("index::diagonal")) +{ + INDEX_DIAGONAL_SUBCASE( case7c, src_shape, indices, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case7c, src_shape_a, indices_a, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case7c, src_shape_f, indices_f, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case7c, src_shape_h, indices_h, offset, axis1, axis2 ); + INDEX_DIAGONAL_SUBCASE( case7c, src_shape_v, indices_v, offset, axis1, axis2 ); } \ No newline at end of file diff --git a/tests/view/CMakeLists.txt b/tests/view/CMakeLists.txt index f31a561ed..7cbab3533 100644 --- a/tests/view/CMakeLists.txt +++ b/tests/view/CMakeLists.txt @@ -65,6 +65,7 @@ set(ARRAY_VIEW_1_TEST_SOURCES src/concatenate.cpp src/compress.cpp src/diagflat.cpp + src/diagonal.cpp src/expand_dims.cpp src/expand.cpp src/eye.cpp diff --git a/tests/view/src/diagonal.cpp b/tests/view/src/diagonal.cpp new file mode 100644 index 000000000..9bf12d74f --- /dev/null +++ b/tests/view/src/diagonal.cpp @@ -0,0 +1,158 @@ +#if defined(NMTOOLS_TESTING_GENERIC_NDARRAY) +#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_fs_fb); \ +inline auto name##_fs_hb = nmtools::cast(name, nmtools::array::kind::ndarray_fs_hb); \ +inline auto name##_fs_db = nmtools::cast(name, nmtools::array::kind::ndarray_fs_db); \ +inline auto name##_hs_fb = nmtools::cast(name, nmtools::array::kind::ndarray_hs_fb); \ +inline auto name##_hs_hb = nmtools::cast(name, nmtools::array::kind::ndarray_hs_hb); \ +inline auto name##_hs_db = nmtools::cast(name, nmtools::array::kind::ndarray_hs_db); \ +inline auto name##_ds_fb = nmtools::cast(name, nmtools::array::kind::ndarray_ds_fb); \ +inline auto name##_ds_hb = nmtools::cast(name, nmtools::array::kind::ndarray_ds_hb); \ +inline auto name##_ds_db = nmtools::cast(name, nmtools::array::kind::ndarray_ds_db); \ +inline auto name##_ls_fb = nmtools::cast(name, nmtools::array::kind::ndarray_ls_fb); \ +inline auto name##_ls_hb = nmtools::cast(name, nmtools::array::kind::ndarray_ls_hb); \ +inline auto name##_ls_db = nmtools::cast(name, nmtools::array::kind::ndarray_ls_db); +#endif + +#include "nmtools/array/view/diagonal.hpp" +#include "nmtools/testing/data/array/diagonal.hpp" +#include "nmtools/testing/doctest.hpp" + +#define DIAGONAL_SUBCASE(case_name, ...) \ +SUBCASE(#case_name) \ +{ \ + NMTOOLS_TESTING_USE_CASE( array, diagonal, case_name ); \ + using namespace args; \ + auto result = nmtools::view::diagonal(__VA_ARGS__); \ + NMTOOLS_ASSERT_EQUAL( nmtools::shape(result), nmtools::shape(expect::result) ); \ + NMTOOLS_ASSERT_CLOSE( result, expect::result ); \ +} + +TEST_CASE("diagonal(case1)" * doctest::test_suite("view::diagonal")) +{ + DIAGONAL_SUBCASE( case1, a ); + DIAGONAL_SUBCASE( case1, a_a ); + DIAGONAL_SUBCASE( case1, a_f ); + DIAGONAL_SUBCASE( case1, a_h ); + DIAGONAL_SUBCASE( case1, a_d ); +} + +TEST_CASE("diagonal(case2)" * doctest::test_suite("view::diagonal")) +{ + // DIAGONAL_SUBCASE( case2, a, offset ); + DIAGONAL_SUBCASE( case2, a_a, offset ); + DIAGONAL_SUBCASE( case2, a_f, offset ); + DIAGONAL_SUBCASE( case2, a_h, offset ); + DIAGONAL_SUBCASE( case2, a_d, offset ); +} + +TEST_CASE("diagonal(case3)" * doctest::test_suite("view::diagonal")) +{ + DIAGONAL_SUBCASE( case3, a, offset ); + DIAGONAL_SUBCASE( case3, a_a, offset ); + DIAGONAL_SUBCASE( case3, a_f, offset ); + DIAGONAL_SUBCASE( case3, a_h, offset ); + DIAGONAL_SUBCASE( case3, a_d, offset ); +} + +TEST_CASE("diagonal(case4)" * doctest::test_suite("view::diagonal")) +{ + DIAGONAL_SUBCASE( case4, a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case4, a_a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case4, a_f, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case4, a_h, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case4, a_d, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case5)" * doctest::test_suite("view::diagonal")) +{ + DIAGONAL_SUBCASE( case5, a, offset, axis1,axis2 ); + DIAGONAL_SUBCASE( case5, a_a, offset, axis1,axis2 ); + DIAGONAL_SUBCASE( case5, a_f, offset, axis1,axis2 ); + DIAGONAL_SUBCASE( case5, a_h, offset, axis1,axis2 ); + DIAGONAL_SUBCASE( case5, a_d, offset, axis1,axis2 ); +} + +TEST_CASE("diagonal(case6)" * doctest::test_suite("view::diagonal")) +{ + DIAGONAL_SUBCASE( case6, a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case6, a_a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case6, a_f, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case6, a_h, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case6, a_d, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case7)" * doctest::test_suite("view::diagonal")) +{ + DIAGONAL_SUBCASE( case7, a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case7, a_a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case7, a_f, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case7, a_h, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case7, a_d, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case8)" * doctest::test_suite("view::diagonal")) +{ + DIAGONAL_SUBCASE( case8, a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case8, a_a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case8, a_f, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case8, a_h, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case8, a_d, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case9)" * doctest::test_suite("view::diagonal")) +{ + DIAGONAL_SUBCASE( case9, a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case9, a_a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case9, a_f, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case9, a_h, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case9, a_d, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case10)" * doctest::test_suite("view::diagonal")) +{ + DIAGONAL_SUBCASE( case10, a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case10, a_a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case10, a_f, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case10, a_h, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case10, a_d, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case11)" * doctest::test_suite("view::diagonal")) +{ + DIAGONAL_SUBCASE( case11, a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case11, a_a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case11, a_f, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case11, a_h, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case11, a_d, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case12)" * doctest::test_suite("view::diagonal")) +{ + DIAGONAL_SUBCASE( case12, a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case12, a_a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case12, a_f, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case12, a_h, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case12, a_d, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case13)" * doctest::test_suite("view::diagonal")) +{ + DIAGONAL_SUBCASE( case13, a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case13, a_a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case13, a_f, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case13, a_h, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case13, a_d, offset, axis1, axis2 ); +} + +TEST_CASE("diagonal(case14)" * doctest::test_suite("view::diagonal")) +{ + DIAGONAL_SUBCASE( case14, a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case14, a_a, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case14, a_f, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case14, a_h, offset, axis1, axis2 ); + DIAGONAL_SUBCASE( case14, a_d, offset, axis1, axis2 ); +} \ No newline at end of file