diff --git a/.gitignore b/.gitignore index 6a54f8ee2..468c158b0 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,5 @@ pocl *.ll llvm.sh install -amdgpu-* \ No newline at end of file +amdgpu-* +*.dot \ No newline at end of file diff --git a/include/nmtools/testing/data/array/broadcast_to.hpp b/include/nmtools/testing/data/array/broadcast_to.hpp index 04f32a32c..2331ee7a1 100644 --- a/include/nmtools/testing/data/array/broadcast_to.hpp +++ b/include/nmtools/testing/data/array/broadcast_to.hpp @@ -18,10 +18,10 @@ NMTOOLS_TESTING_DECLARE_CASE(index, broadcast_to) inline int bshape[2] = {3,1}; NMTOOLS_CAST_INDEX_ARRAYS(ashape) NMTOOLS_CAST_INDEX_ARRAYS(bshape) - inline auto ashape_ct = tuple{3_ct,1_ct}; - inline auto bshape_ct = tuple{3_ct,1_ct}; - inline auto ashape_cl = tuple{"3:[3]"_ct,"1:[1]"_ct}; - inline auto bshape_cl = tuple{"3:[3]"_ct,"1:[1]"_ct}; + inline auto ashape_ct = nmtools_tuple{3_ct,1_ct}; + inline auto bshape_ct = nmtools_tuple{3_ct,1_ct}; + inline auto ashape_cl = nmtools_tuple{"3:[3]"_ct,"1:[1]"_ct}; + inline auto bshape_cl = nmtools_tuple{"3:[3]"_ct,"1:[1]"_ct}; } NMTOOLS_TESTING_DECLARE_EXPECT(case1) { @@ -37,10 +37,10 @@ NMTOOLS_TESTING_DECLARE_CASE(index, broadcast_to) inline int bshape[2] = {3,3}; NMTOOLS_CAST_INDEX_ARRAYS(ashape) NMTOOLS_CAST_INDEX_ARRAYS(bshape) - inline auto ashape_ct = tuple{3_ct,1_ct}; - inline auto bshape_ct = tuple{3_ct,3_ct}; - inline auto ashape_cl = tuple{"3:[3]"_ct,"1:[1]"_ct}; - inline auto bshape_cl = tuple{"3:[3]"_ct,"3:[3]"_ct}; + inline auto ashape_ct = nmtools_tuple{3_ct,1_ct}; + inline auto bshape_ct = nmtools_tuple{3_ct,3_ct}; + inline auto ashape_cl = nmtools_tuple{"3:[3]"_ct,"1:[1]"_ct}; + inline auto bshape_cl = nmtools_tuple{"3:[3]"_ct,"3:[3]"_ct}; } NMTOOLS_TESTING_DECLARE_EXPECT(case2) { @@ -56,10 +56,10 @@ NMTOOLS_TESTING_DECLARE_CASE(index, broadcast_to) inline int bshape[3] = {3,3,1}; NMTOOLS_CAST_INDEX_ARRAYS(ashape) NMTOOLS_CAST_INDEX_ARRAYS(bshape) - inline auto ashape_ct = tuple{3_ct,1_ct}; - inline auto bshape_ct = tuple{3_ct,3_ct,1_ct}; - inline auto ashape_cl = tuple{"3:[3]"_ct,"1:[1]"_ct}; - inline auto bshape_cl = tuple{"3:[3]"_ct,"3:[3]"_ct,"1:[1]"_ct}; + inline auto ashape_ct = nmtools_tuple{3_ct,1_ct}; + inline auto bshape_ct = nmtools_tuple{3_ct,3_ct,1_ct}; + inline auto ashape_cl = nmtools_tuple{"3:[3]"_ct,"1:[1]"_ct}; + inline auto bshape_cl = nmtools_tuple{"3:[3]"_ct,"3:[3]"_ct,"1:[1]"_ct}; } NMTOOLS_TESTING_DECLARE_EXPECT(case3) { @@ -75,10 +75,10 @@ NMTOOLS_TESTING_DECLARE_CASE(index, broadcast_to) inline int bshape[3] = {3,3,6}; NMTOOLS_CAST_INDEX_ARRAYS(ashape) NMTOOLS_CAST_INDEX_ARRAYS(bshape) - inline auto ashape_ct = tuple{3_ct,1_ct}; - inline auto bshape_ct = tuple{3_ct,3_ct,6_ct}; - inline auto ashape_cl = tuple{"3:[3]"_ct,"1:[1]"_ct}; - inline auto bshape_cl = tuple{"3:[3]"_ct,"3:[3]"_ct,"6:[6]"_ct}; + inline auto ashape_ct = nmtools_tuple{3_ct,1_ct}; + inline auto bshape_ct = nmtools_tuple{3_ct,3_ct,6_ct}; + inline auto ashape_cl = nmtools_tuple{"3:[3]"_ct,"1:[1]"_ct}; + inline auto bshape_cl = nmtools_tuple{"3:[3]"_ct,"3:[3]"_ct,"6:[6]"_ct}; } NMTOOLS_TESTING_DECLARE_EXPECT(case4) { @@ -94,10 +94,10 @@ NMTOOLS_TESTING_DECLARE_CASE(index, broadcast_to) inline int bshape[1] = {3}; NMTOOLS_CAST_INDEX_ARRAYS(ashape) NMTOOLS_CAST_INDEX_ARRAYS(bshape) - inline auto ashape_ct = tuple{3_ct,1_ct}; - inline auto bshape_ct = tuple{3_ct}; - inline auto ashape_cl = tuple{"3:[3]"_ct,"1:[1]"_ct}; - inline auto bshape_cl = tuple{"3:[3]"_ct}; + inline auto ashape_ct = nmtools_tuple{3_ct,1_ct}; + inline auto bshape_ct = nmtools_tuple{3_ct}; + inline auto ashape_cl = nmtools_tuple{"3:[3]"_ct,"1:[1]"_ct}; + inline auto bshape_cl = nmtools_tuple{"3:[3]"_ct}; } NMTOOLS_TESTING_DECLARE_EXPECT(case5) { @@ -113,10 +113,10 @@ NMTOOLS_TESTING_DECLARE_CASE(index, broadcast_to) inline int bshape[3] = {3,6,6}; NMTOOLS_CAST_INDEX_ARRAYS(ashape) NMTOOLS_CAST_INDEX_ARRAYS(bshape) - inline auto ashape_ct = tuple{3_ct,1_ct}; - inline auto bshape_ct = tuple{3_ct,6_ct,6_ct}; - inline auto ashape_cl = tuple{"3:[3]"_ct,"1:[1]"_ct}; - inline auto bshape_cl = tuple{"3:[3]"_ct,"6:[6]"_ct,"6:[6]"_ct}; + inline auto ashape_ct = nmtools_tuple{3_ct,1_ct}; + inline auto bshape_ct = nmtools_tuple{3_ct,6_ct,6_ct}; + inline auto ashape_cl = nmtools_tuple{"3:[3]"_ct,"1:[1]"_ct}; + inline auto bshape_cl = nmtools_tuple{"3:[3]"_ct,"6:[6]"_ct,"6:[6]"_ct}; } NMTOOLS_TESTING_DECLARE_EXPECT(case6) { @@ -132,10 +132,10 @@ NMTOOLS_TESTING_DECLARE_CASE(index, broadcast_to) inline int bshape[4] = {7,3,3,6}; NMTOOLS_CAST_INDEX_ARRAYS(ashape) NMTOOLS_CAST_INDEX_ARRAYS(bshape) - inline auto ashape_ct = tuple{3_ct,1_ct}; - inline auto bshape_ct = tuple{7_ct,3_ct,3_ct,6_ct}; - inline auto ashape_cl = tuple{"3:[3]"_ct,"1:[1]"_ct}; - inline auto bshape_cl = tuple{"7:[7]"_ct,"3:[3]"_ct,"3:[3]"_ct,"6:[6]"_ct}; + inline auto ashape_ct = nmtools_tuple{3_ct,1_ct}; + inline auto bshape_ct = nmtools_tuple{7_ct,3_ct,3_ct,6_ct}; + inline auto ashape_cl = nmtools_tuple{"3:[3]"_ct,"1:[1]"_ct}; + inline auto bshape_cl = nmtools_tuple{"7:[7]"_ct,"3:[3]"_ct,"3:[3]"_ct,"6:[6]"_ct}; } NMTOOLS_TESTING_DECLARE_EXPECT(case7) { diff --git a/include/nmtools/testing/data/index/alias.hpp b/include/nmtools/testing/data/index/alias.hpp new file mode 100644 index 000000000..b6dafe1ef --- /dev/null +++ b/include/nmtools/testing/data/index/alias.hpp @@ -0,0 +1,188 @@ +#ifndef NMTOOLS_TESTING_DATA_INDEX_ALIAS_HPP +#define NMTOOLS_TESTING_DATA_INDEX_ALIAS_HPP + +#include "nmtools/testing/testing.hpp" + +NMTOOLS_TESTING_DECLARE_CASE(index,alias) +{ + using namespace literals; + + NMTOOLS_TESTING_DECLARE_ARGS(case1) + { + inline int operands[1] = {-1}; + inline auto reserved_ids = None; + inline auto operands_ct = nmtools_tuple{meta::ct_v<-1>}; + } + NMTOOLS_TESTING_DECLARE_EXPECT(case1) + { + inline int result[1] = {0}; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case2) + { + inline int operands[1] = {-1}; + inline int reserved_ids[3] = {2,0,1}; + inline auto operands_ct = nmtools_tuple{meta::ct_v<-1>}; + inline auto reserved_ids_ct = nmtools_tuple{2_ct,0_ct,1_ct}; + } + NMTOOLS_TESTING_DECLARE_EXPECT(case2) + { + inline int result[1] = {3}; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case3) + { + inline int operands[3] = {-1,2,-1}; + inline int reserved_ids[2] = {3,1}; + inline auto operands_ct = nmtools_tuple{meta::ct_v<-1>,2_ct,meta::ct_v<-1>}; + inline auto reserved_ids_ct = nmtools_tuple{3_ct,1_ct}; + } + NMTOOLS_TESTING_DECLARE_EXPECT(case3) + { + inline int result[3] = {4,2,5}; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case4) + { + inline int operands[3] = {-1,2,-1}; + inline auto reserved_ids = nmtools_tuple{}; + } + NMTOOLS_TESTING_DECLARE_EXPECT(case4) + { + inline int operands[3] = {3,2,4}; + } +} + +NMTOOLS_TESTING_DECLARE_CASE(index,generate_alias) +{ + using namespace literals; + using meta::ct_v; + + NMTOOLS_TESTING_DECLARE_ARGS(case1) + { + inline int aliases[1] = {0}; + inline int base = 256; + inline int prime = 101; + inline auto aliases_ct = nmtools_tuple{0_ct}; + inline auto base_ct = 256_ct; + inline auto prime_ct = 101_ct; + } + NMTOOLS_TESTING_DECLARE_EXPECT(case1) + { + inline int result = 0; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case2) + { + inline int aliases[2] = {0,-1}; + inline int base = 256; + inline int prime = 101; + inline auto aliases_ct = nmtools_tuple{0_ct,ct_v<-1>}; + inline auto base_ct = 256_ct; + inline auto prime_ct = 101_ct; + } + NMTOOLS_TESTING_DECLARE_EXPECT(case2) + { + inline auto result = 100; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case3) + { + inline int aliases[3] = {100,0,-1}; + inline int base = 256; + inline int prime = 101; + inline auto aliases_ct = nmtools_tuple{100_ct,0_ct,ct_v<-1>}; + inline auto base_ct = 256_ct; + inline auto prime_ct = 101_ct; + } + NMTOOLS_TESTING_DECLARE_EXPECT(case3) + { + inline auto result = 12; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case4) + { + inline int aliases[4] = {12,100,0,-1}; + inline int base = 256; + inline int prime = 101; + inline auto aliases_ct = nmtools_tuple{12_ct,100_ct,0_ct,ct_v<-1>}; + inline auto base_ct = 256_ct; + inline auto prime_ct = 101_ct; + } + NMTOOLS_TESTING_DECLARE_EXPECT(case4) + { + inline auto result = 72; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case5) + { + inline int aliases[5] = {72,12,100,0,-1}; + inline int base = 256; + inline int prime = 101; + inline auto aliases_ct = nmtools_tuple{72,12,100,0,ct_v<-1>}; + inline auto base_ct = 256_ct; + inline auto prime_ct = 101_ct; + } + NMTOOLS_TESTING_DECLARE_EXPECT(case5) + { + inline auto result = 19; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case6) + { + inline int aliases[7] = {3,0,1,2,3,4,-1}; + inline int base = 256; + inline int prime = 503; + inline auto aliases_ct = nmtools_tuple{3_ct,0_ct,1_ct,2_ct,3_ct,4_ct,ct_v<-1>}; + inline auto base_ct = 256_ct; + inline auto prime_ct = 503_ct; + } + NMTOOLS_TESTING_DECLARE_EXPECT(case6) + { + inline auto result = 172; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case7) + { + inline int aliases[7] = {2,0,1,2,3,4,-1}; + inline int base = 256; + inline int prime = 503; + inline auto aliases_ct = nmtools_tuple{2_ct,0_ct,1_ct,2_ct,3_ct,4_ct,ct_v<-1>}; + inline int base_ct = 256_ct; + inline int prime_ct = 503_ct; + } + NMTOOLS_TESTING_DECLARE_EXPECT(case7) + { + inline auto result = 97; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case8) + { + inline int aliases[7] = {1,0,1,2,3,4,-1}; + inline int base = 256; + inline int prime = 503; + inline auto aliases_ct = nmtools_tuple{1_ct,0_ct,1_ct,2_ct,3_ct,4_ct,ct_v<-1>}; + inline auto base_ct = 256_ct; + inline auto prime_ct = 503_ct; + } + NMTOOLS_TESTING_DECLARE_EXPECT(case8) + { + inline auto result = 22; + } + + NMTOOLS_TESTING_DECLARE_ARGS(case9) + { + inline int aliases[7] = {4,0,1,2,3,4,-1}; + inline int base = 256; + inline int prime = 503; + inline auto aliases_ct = nmtools_tuple{4_ct,0_ct,1_ct,2_ct,3_ct,4_ct,ct_v<-1>}; + inline auto base_ct = 256_ct; + inline auto prime_ct = 503_ct; + } + NMTOOLS_TESTING_DECLARE_EXPECT(case9) + { + inline auto result = 247; + } +} + +#endif // NMTOOLS_TESTING_DATA_INDEX_ALIAS_HPP \ No newline at end of file diff --git a/include/nmtools/testing/data/index/gather.hpp b/include/nmtools/testing/data/index/gather.hpp index 260c45ffc..30f1a95e8 100644 --- a/include/nmtools/testing/data/index/gather.hpp +++ b/include/nmtools/testing/data/index/gather.hpp @@ -5,23 +5,12 @@ #include "nmtools/utils/isequal.hpp" #include "nmtools/constants.hpp" #include "nmtools/testing/doctest.hpp" -#include -#include -#include namespace nm = nmtools; namespace na = nm::array; namespace kind = na::kind; using namespace nm::literals; using nmtools::utils::isequal; -#ifndef NMTOOLS_DISABLE_STL -using std::tuple; -using std::vector; -using std::array; -#else -using nmtools_tuple; -using nmtools_array; -#endif NMTOOLS_TESTING_DECLARE_CASE(gather) { @@ -31,10 +20,10 @@ NMTOOLS_TESTING_DECLARE_CASE(gather) inline int32_t indices[3] = {0,1,2}; NMTOOLS_CAST_INDEX_ARRAYS(vec); NMTOOLS_CAST_INDEX_ARRAYS(indices); - inline auto vec_ct = tuple{1_ct,2_ct,3_ct}; - inline auto indices_ct = tuple{0_ct,1_ct,2_ct}; - inline auto vec_cl = tuple{"1:[1]"_ct,"2:[2]"_ct,"3:[3]"_ct}; - inline auto indices_cl = tuple{"0:[1]"_ct,"1:[1]"_ct,"2:[2]"_ct}; + inline auto vec_ct = nmtools_tuple{1_ct,2_ct,3_ct}; + inline auto indices_ct = nmtools_tuple{0_ct,1_ct,2_ct}; + inline auto vec_cl = nmtools_tuple{"1:[1]"_ct,"2:[2]"_ct,"3:[3]"_ct}; + inline auto indices_cl = nmtools_tuple{"0:[1]"_ct,"1:[1]"_ct,"2:[2]"_ct}; } NMTOOLS_TESTING_DECLARE_EXPECT(case1) { @@ -47,10 +36,10 @@ NMTOOLS_TESTING_DECLARE_CASE(gather) inline int indices[3] = {1,0,2}; NMTOOLS_CAST_INDEX_ARRAYS(vec); NMTOOLS_CAST_INDEX_ARRAYS(indices); - inline auto vec_ct = tuple{1_ct,2_ct,3_ct}; - inline auto vec_cl = tuple{"1:[1]"_ct,"2:[2]"_ct,"3:[3]"_ct}; - inline auto indices_ct = tuple{1_ct,0_ct,2_ct}; - inline auto indices_cl = tuple{"1:[1]"_ct,"0:[1]"_ct,"2:[2]"_ct}; + inline auto vec_ct = nmtools_tuple{1_ct,2_ct,3_ct}; + inline auto vec_cl = nmtools_tuple{"1:[1]"_ct,"2:[2]"_ct,"3:[3]"_ct}; + inline auto indices_ct = nmtools_tuple{1_ct,0_ct,2_ct}; + inline auto indices_cl = nmtools_tuple{"1:[1]"_ct,"0:[1]"_ct,"2:[2]"_ct}; } NMTOOLS_TESTING_DECLARE_EXPECT(case2) { @@ -63,10 +52,10 @@ NMTOOLS_TESTING_DECLARE_CASE(gather) inline int indices[3] = {1,2,0}; NMTOOLS_CAST_INDEX_ARRAYS(vec); NMTOOLS_CAST_INDEX_ARRAYS(indices); - inline auto vec_ct = tuple{1_ct,2_ct,3_ct}; - inline auto vec_cl = tuple{"1:[1]"_ct,"2:[2]"_ct,"3:[3]"_ct}; - inline auto indices_ct = tuple{1_ct,2_ct,0_ct}; - inline auto indices_cl = tuple{"1:[1]"_ct,"2:[2]"_ct,"0:[1]"_ct}; + inline auto vec_ct = nmtools_tuple{1_ct,2_ct,3_ct}; + inline auto vec_cl = nmtools_tuple{"1:[1]"_ct,"2:[2]"_ct,"3:[3]"_ct}; + inline auto indices_ct = nmtools_tuple{1_ct,2_ct,0_ct}; + inline auto indices_cl = nmtools_tuple{"1:[1]"_ct,"2:[2]"_ct,"0:[1]"_ct}; } NMTOOLS_TESTING_DECLARE_EXPECT(case3) { @@ -79,10 +68,10 @@ NMTOOLS_TESTING_DECLARE_CASE(gather) inline int indices[3] = {2,0,1}; NMTOOLS_CAST_INDEX_ARRAYS(vec); NMTOOLS_CAST_INDEX_ARRAYS(indices); - inline auto vec_ct = tuple{1_ct,2_ct,3_ct}; - inline auto vec_cl = tuple{"1:[1]"_ct,"2:[2]"_ct,"3:[3]"_ct}; - inline auto indices_ct = tuple{2_ct,0_ct,1_ct}; - inline auto indices_cl = tuple{"2:[2]"_ct,"0:[1]"_ct,"1:[1]"_ct}; + inline auto vec_ct = nmtools_tuple{1_ct,2_ct,3_ct}; + inline auto vec_cl = nmtools_tuple{"1:[1]"_ct,"2:[2]"_ct,"3:[3]"_ct}; + inline auto indices_ct = nmtools_tuple{2_ct,0_ct,1_ct}; + inline auto indices_cl = nmtools_tuple{"2:[2]"_ct,"0:[1]"_ct,"1:[1]"_ct}; } NMTOOLS_TESTING_DECLARE_EXPECT(case4) { @@ -95,10 +84,10 @@ NMTOOLS_TESTING_DECLARE_CASE(gather) inline int indices[3] = {2,1,0}; NMTOOLS_CAST_INDEX_ARRAYS(vec); NMTOOLS_CAST_INDEX_ARRAYS(indices); - inline auto vec_ct = tuple{1_ct,2_ct,3_ct}; - inline auto vec_cl = tuple{"1:[1]"_ct,"2:[2]"_ct,"3:[3]"_ct}; - inline auto indices_ct = tuple{2_ct,1_ct,0_ct}; - inline auto indices_cl = tuple{"2:[2]"_ct,"1:[1]"_ct,"0:[1]"_ct}; + inline auto vec_ct = nmtools_tuple{1_ct,2_ct,3_ct}; + inline auto vec_cl = nmtools_tuple{"1:[1]"_ct,"2:[2]"_ct,"3:[3]"_ct}; + inline auto indices_ct = nmtools_tuple{2_ct,1_ct,0_ct}; + inline auto indices_cl = nmtools_tuple{"2:[2]"_ct,"1:[1]"_ct,"0:[1]"_ct}; } NMTOOLS_TESTING_DECLARE_EXPECT(case5) { @@ -111,10 +100,10 @@ NMTOOLS_TESTING_DECLARE_CASE(gather) inline int indices[3] = {2,1,0}; NMTOOLS_CAST_INDEX_ARRAYS(vec); NMTOOLS_CAST_INDEX_ARRAYS(indices); - inline auto vec_ct = tuple{1_ct,2_ct,3_ct,4_ct,5_ct}; - inline auto vec_cl = tuple{"1:[1]"_ct,"2:[2]"_ct,"3:[3]"_ct,"4:[4]"_ct,"5:[5]"_ct}; - inline auto indices_ct = tuple{2_ct,1_ct,0_ct}; - inline auto indices_cl = tuple{"2:[2]"_ct,"1:[1]"_ct,"0:[1]"_ct}; + inline auto vec_ct = nmtools_tuple{1_ct,2_ct,3_ct,4_ct,5_ct}; + inline auto vec_cl = nmtools_tuple{"1:[1]"_ct,"2:[2]"_ct,"3:[3]"_ct,"4:[4]"_ct,"5:[5]"_ct}; + inline auto indices_ct = nmtools_tuple{2_ct,1_ct,0_ct}; + inline auto indices_cl = nmtools_tuple{"2:[2]"_ct,"1:[1]"_ct,"0:[1]"_ct}; } NMTOOLS_TESTING_DECLARE_EXPECT(case6) { diff --git a/include/nmtools/testing/data/index/slice.hpp b/include/nmtools/testing/data/index/slice.hpp index d9b317a80..08e66dac4 100644 --- a/include/nmtools/testing/data/index/slice.hpp +++ b/include/nmtools/testing/data/index/slice.hpp @@ -18,11 +18,11 @@ NMTOOLS_TESTING_DECLARE_CASE(index, shape_slice) NMTOOLS_TESTING_DECLARE_ARGS(case1) { inline int shape[3] = {2,3,2}; - inline auto slice0 = tuple{None,None}; - inline auto slice1 = tuple{0,1}; - inline auto slice2 = tuple{None,None}; - inline auto shape_ct = tuple{2_ct,3_ct,2_ct}; - inline auto shape_cl = tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; + inline auto slice0 = nmtools_tuple{None,None}; + inline auto slice1 = nmtools_tuple{0,1}; + inline auto slice2 = nmtools_tuple{None,None}; + inline auto shape_ct = nmtools_tuple{2_ct,3_ct,2_ct}; + inline auto shape_cl = nmtools_tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; NMTOOLS_CAST_INDEX_ARRAYS(shape) } NMTOOLS_TESTING_DECLARE_EXPECT(case1) @@ -33,11 +33,11 @@ NMTOOLS_TESTING_DECLARE_CASE(index, shape_slice) NMTOOLS_TESTING_DECLARE_ARGS(case2) { inline int shape[3] = {2,3,2}; - inline auto slice0 = tuple{None,None}; - inline auto slice1 = tuple{None,None}; - inline auto slice2 = tuple{None,None}; - inline auto shape_ct = tuple{2_ct,3_ct,2_ct}; - inline auto shape_cl = tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; + inline auto slice0 = nmtools_tuple{None,None}; + inline auto slice1 = nmtools_tuple{None,None}; + inline auto slice2 = nmtools_tuple{None,None}; + inline auto shape_ct = nmtools_tuple{2_ct,3_ct,2_ct}; + inline auto shape_cl = nmtools_tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; NMTOOLS_CAST_INDEX_ARRAYS(shape) } NMTOOLS_TESTING_DECLARE_EXPECT(case2) @@ -48,11 +48,11 @@ NMTOOLS_TESTING_DECLARE_CASE(index, shape_slice) NMTOOLS_TESTING_DECLARE_ARGS(case3) { inline int shape[3] = {2,3,2}; - inline auto slice0 = tuple{1,2}; - inline auto slice1 = tuple{0,1}; - inline auto slice2 = tuple{None,None}; - inline auto shape_ct = tuple{2_ct,3_ct,2_ct}; - inline auto shape_cl = tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; + inline auto slice0 = nmtools_tuple{1,2}; + inline auto slice1 = nmtools_tuple{0,1}; + inline auto slice2 = nmtools_tuple{None,None}; + inline auto shape_ct = nmtools_tuple{2_ct,3_ct,2_ct}; + inline auto shape_cl = nmtools_tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; NMTOOLS_CAST_INDEX_ARRAYS(shape) } NMTOOLS_TESTING_DECLARE_EXPECT(case3) @@ -63,11 +63,11 @@ NMTOOLS_TESTING_DECLARE_CASE(index, shape_slice) NMTOOLS_TESTING_DECLARE_ARGS(case4) { inline int shape[3] = {2,3,2}; - inline auto slice0 = tuple{1,3}; - inline auto slice1 = tuple{0,1}; - inline auto slice2 = tuple{None,None}; - inline auto shape_ct = tuple{2_ct,3_ct,2_ct}; - inline auto shape_cl = tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; + inline auto slice0 = nmtools_tuple{1,3}; + inline auto slice1 = nmtools_tuple{0,1}; + inline auto slice2 = nmtools_tuple{None,None}; + inline auto shape_ct = nmtools_tuple{2_ct,3_ct,2_ct}; + inline auto shape_cl = nmtools_tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; NMTOOLS_CAST_INDEX_ARRAYS(shape) } NMTOOLS_TESTING_DECLARE_EXPECT(case4) @@ -78,11 +78,11 @@ NMTOOLS_TESTING_DECLARE_CASE(index, shape_slice) NMTOOLS_TESTING_DECLARE_ARGS(case5) { inline int shape[3] = {2,3,2}; - inline auto slice0 = tuple{None,None}; - inline auto slice1 = tuple{0,2}; - inline auto slice2 = tuple{None,-1}; - inline auto shape_ct = tuple{2_ct,3_ct,2_ct}; - inline auto shape_cl = tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; + inline auto slice0 = nmtools_tuple{None,None}; + inline auto slice1 = nmtools_tuple{0,2}; + inline auto slice2 = nmtools_tuple{None,-1}; + inline auto shape_ct = nmtools_tuple{2_ct,3_ct,2_ct}; + inline auto shape_cl = nmtools_tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; NMTOOLS_CAST_INDEX_ARRAYS(shape) } NMTOOLS_TESTING_DECLARE_EXPECT(case5) @@ -93,11 +93,11 @@ NMTOOLS_TESTING_DECLARE_CASE(index, shape_slice) NMTOOLS_TESTING_DECLARE_ARGS(case6) { inline int shape[3] = {2,3,2}; - inline auto slice0 = tuple{None,None}; + inline auto slice0 = nmtools_tuple{None,None}; inline auto slice1 = 0; inline auto slice2 = 0; - inline auto shape_ct = tuple{2_ct,3_ct,2_ct}; - inline auto shape_cl = tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; + inline auto shape_ct = nmtools_tuple{2_ct,3_ct,2_ct}; + inline auto shape_cl = nmtools_tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; NMTOOLS_CAST_INDEX_ARRAYS(shape) } NMTOOLS_TESTING_DECLARE_EXPECT(case6) @@ -108,11 +108,11 @@ NMTOOLS_TESTING_DECLARE_CASE(index, shape_slice) NMTOOLS_TESTING_DECLARE_ARGS(case7) { inline int shape[3] = {2,3,2}; - inline auto slice0 = tuple{None,None}; + inline auto slice0 = nmtools_tuple{None,None}; inline auto slice1 = 0; - inline auto slice2 = tuple{None,-1}; - inline auto shape_ct = tuple{2_ct,3_ct,2_ct}; - inline auto shape_cl = tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; + inline auto slice2 = nmtools_tuple{None,-1}; + inline auto shape_ct = nmtools_tuple{2_ct,3_ct,2_ct}; + inline auto shape_cl = nmtools_tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; NMTOOLS_CAST_INDEX_ARRAYS(shape) } NMTOOLS_TESTING_DECLARE_EXPECT(case7) @@ -123,11 +123,11 @@ NMTOOLS_TESTING_DECLARE_CASE(index, shape_slice) NMTOOLS_TESTING_DECLARE_ARGS(case8) { inline int shape[3] = {2,3,2}; - inline auto slice0 = tuple{None,None,-1}; - inline auto slice1 = tuple{None,None}; - inline auto slice2 = tuple{None,None}; - inline auto shape_ct = tuple{2_ct,3_ct,2_ct}; - inline auto shape_cl = tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; + inline auto slice0 = nmtools_tuple{None,None,-1}; + inline auto slice1 = nmtools_tuple{None,None}; + inline auto slice2 = nmtools_tuple{None,None}; + inline auto shape_ct = nmtools_tuple{2_ct,3_ct,2_ct}; + inline auto shape_cl = nmtools_tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; NMTOOLS_CAST_INDEX_ARRAYS(shape) } NMTOOLS_TESTING_DECLARE_EXPECT(case8) @@ -138,11 +138,11 @@ NMTOOLS_TESTING_DECLARE_CASE(index, shape_slice) NMTOOLS_TESTING_DECLARE_ARGS(case9) { inline int shape[3] = {2,3,2}; - inline auto slice0 = tuple{None,None}; - inline auto slice1 = tuple{None,None,-1}; - inline auto slice2 = tuple{None,None}; - inline auto shape_ct = tuple{2_ct,3_ct,2_ct}; - inline auto shape_cl = tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; + inline auto slice0 = nmtools_tuple{None,None}; + inline auto slice1 = nmtools_tuple{None,None,-1}; + inline auto slice2 = nmtools_tuple{None,None}; + inline auto shape_ct = nmtools_tuple{2_ct,3_ct,2_ct}; + inline auto shape_cl = nmtools_tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; NMTOOLS_CAST_INDEX_ARRAYS(shape) } NMTOOLS_TESTING_DECLARE_EXPECT(case9) @@ -153,11 +153,11 @@ NMTOOLS_TESTING_DECLARE_CASE(index, shape_slice) NMTOOLS_TESTING_DECLARE_ARGS(case10) { inline int shape[3] = {2,3,2}; - inline auto slice0 = tuple{None,None,-1}; - inline auto slice1 = tuple{None,None}; - inline auto slice2 = tuple{None,None,-1}; - inline auto shape_ct = tuple{2_ct,3_ct,2_ct}; - inline auto shape_cl = tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; + inline auto slice0 = nmtools_tuple{None,None,-1}; + inline auto slice1 = nmtools_tuple{None,None}; + inline auto slice2 = nmtools_tuple{None,None,-1}; + inline auto shape_ct = nmtools_tuple{2_ct,3_ct,2_ct}; + inline auto shape_cl = nmtools_tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; NMTOOLS_CAST_INDEX_ARRAYS(shape) } NMTOOLS_TESTING_DECLARE_EXPECT(case10) @@ -168,10 +168,10 @@ NMTOOLS_TESTING_DECLARE_CASE(index, shape_slice) NMTOOLS_TESTING_DECLARE_ARGS(case11) { inline int shape[2] = {4,2}; - inline auto slice0 = tuple{None,None,2}; - inline auto slice1 = tuple{None,None}; - inline auto shape_ct = tuple{4_ct,2_ct}; - inline auto shape_cl = tuple{"4:[4]"_ct,"2:[2]"_ct}; + inline auto slice0 = nmtools_tuple{None,None,2}; + inline auto slice1 = nmtools_tuple{None,None}; + inline auto shape_ct = nmtools_tuple{4_ct,2_ct}; + inline auto shape_cl = nmtools_tuple{"4:[4]"_ct,"2:[2]"_ct}; NMTOOLS_CAST_INDEX_ARRAYS(shape) } NMTOOLS_TESTING_DECLARE_EXPECT(case11) @@ -182,10 +182,10 @@ NMTOOLS_TESTING_DECLARE_CASE(index, shape_slice) NMTOOLS_TESTING_DECLARE_ARGS(case12) { inline int shape[2] = {4,2}; - inline auto slice0 = tuple{None,None,2}; - inline auto slice1 = tuple{None,2}; - inline auto shape_ct = tuple{4_ct,2_ct}; - inline auto shape_cl = tuple{"4:[4]"_ct,"2:[2]"_ct}; + inline auto slice0 = nmtools_tuple{None,None,2}; + inline auto slice1 = nmtools_tuple{None,2}; + inline auto shape_ct = nmtools_tuple{4_ct,2_ct}; + inline auto shape_cl = nmtools_tuple{"4:[4]"_ct,"2:[2]"_ct}; NMTOOLS_CAST_INDEX_ARRAYS(shape) } NMTOOLS_TESTING_DECLARE_EXPECT(case12) @@ -196,10 +196,10 @@ NMTOOLS_TESTING_DECLARE_CASE(index, shape_slice) NMTOOLS_TESTING_DECLARE_ARGS(case13) { inline int shape[2] = {4,2}; - inline auto slice0 = tuple{None,None,2}; - inline auto slice1 = tuple{1,None}; - inline auto shape_ct = tuple{4_ct,2_ct}; - inline auto shape_cl = tuple{"4:[4]"_ct,"2:[2]"_ct}; + inline auto slice0 = nmtools_tuple{None,None,2}; + inline auto slice1 = nmtools_tuple{1,None}; + inline auto shape_ct = nmtools_tuple{4_ct,2_ct}; + inline auto shape_cl = nmtools_tuple{"4:[4]"_ct,"2:[2]"_ct}; NMTOOLS_CAST_INDEX_ARRAYS(shape) } NMTOOLS_TESTING_DECLARE_EXPECT(case13) @@ -210,10 +210,10 @@ NMTOOLS_TESTING_DECLARE_CASE(index, shape_slice) NMTOOLS_TESTING_DECLARE_ARGS(case14) { inline int shape[2] = {4,2}; - inline auto slice0 = tuple{None,None,2}; - inline auto slice1 = tuple{1,None,2}; - inline auto shape_ct = tuple{4_ct,2_ct}; - inline auto shape_cl = tuple{"4:[4]"_ct,"2:[2]"_ct}; + inline auto slice0 = nmtools_tuple{None,None,2}; + inline auto slice1 = nmtools_tuple{1,None,2}; + inline auto shape_ct = nmtools_tuple{4_ct,2_ct}; + inline auto shape_cl = nmtools_tuple{"4:[4]"_ct,"2:[2]"_ct}; NMTOOLS_CAST_INDEX_ARRAYS(shape) } NMTOOLS_TESTING_DECLARE_EXPECT(case14) @@ -224,10 +224,10 @@ NMTOOLS_TESTING_DECLARE_CASE(index, shape_slice) NMTOOLS_TESTING_DECLARE_ARGS(case15) { inline int shape[2] = {4,2}; - inline auto slice0 = tuple{None,None,-2}; - inline auto slice1 = tuple{1,None,-2}; - inline auto shape_ct = tuple{4_ct,2_ct}; - inline auto shape_cl = tuple{"4:[4]"_ct,"2:[2]"_ct}; + inline auto slice0 = nmtools_tuple{None,None,-2}; + inline auto slice1 = nmtools_tuple{1,None,-2}; + inline auto shape_ct = nmtools_tuple{4_ct,2_ct}; + inline auto shape_cl = nmtools_tuple{"4:[4]"_ct,"2:[2]"_ct}; NMTOOLS_CAST_INDEX_ARRAYS(shape) } NMTOOLS_TESTING_DECLARE_EXPECT(case15) @@ -238,10 +238,10 @@ NMTOOLS_TESTING_DECLARE_CASE(index, shape_slice) NMTOOLS_TESTING_DECLARE_ARGS(case16) { inline int shape[2] = {4,2}; - inline auto slice0 = tuple{3,None,-2}; - inline auto slice1 = tuple{1,None,-2}; - inline auto shape_ct = tuple{4_ct,2_ct}; - inline auto shape_cl = tuple{"4:[4]"_ct,"2:[2]"_ct}; + inline auto slice0 = nmtools_tuple{3,None,-2}; + inline auto slice1 = nmtools_tuple{1,None,-2}; + inline auto shape_ct = nmtools_tuple{4_ct,2_ct}; + inline auto shape_cl = nmtools_tuple{"4:[4]"_ct,"2:[2]"_ct}; NMTOOLS_CAST_INDEX_ARRAYS(shape) } NMTOOLS_TESTING_DECLARE_EXPECT(case16) @@ -252,10 +252,10 @@ NMTOOLS_TESTING_DECLARE_CASE(index, shape_slice) NMTOOLS_TESTING_DECLARE_ARGS(case17) { inline int shape[2] = {4,2}; - inline auto slice0 = tuple{3,None,2}; - inline auto slice1 = tuple{1,None,-2}; - inline auto shape_ct = tuple{4_ct,2_ct}; - inline auto shape_cl = tuple{"4:[4]"_ct,"2:[2]"_ct}; + inline auto slice0 = nmtools_tuple{3,None,2}; + inline auto slice1 = nmtools_tuple{1,None,-2}; + inline auto shape_ct = nmtools_tuple{4_ct,2_ct}; + inline auto shape_cl = nmtools_tuple{"4:[4]"_ct,"2:[2]"_ct}; NMTOOLS_CAST_INDEX_ARRAYS(shape) } NMTOOLS_TESTING_DECLARE_EXPECT(case17) @@ -266,10 +266,10 @@ NMTOOLS_TESTING_DECLARE_CASE(index, shape_slice) NMTOOLS_TESTING_DECLARE_ARGS(case18) { inline int shape[2] = {4,2}; - inline auto slice0 = tuple{1,None,-2}; - inline auto slice1 = tuple{1,None,-2}; - inline auto shape_ct = tuple{4_ct,2_ct}; - inline auto shape_cl = tuple{"4:[4]"_ct,"2:[2]"_ct}; + inline auto slice0 = nmtools_tuple{1,None,-2}; + inline auto slice1 = nmtools_tuple{1,None,-2}; + inline auto shape_ct = nmtools_tuple{4_ct,2_ct}; + inline auto shape_cl = nmtools_tuple{"4:[4]"_ct,"2:[2]"_ct}; NMTOOLS_CAST_INDEX_ARRAYS(shape) } NMTOOLS_TESTING_DECLARE_EXPECT(case18) @@ -280,10 +280,10 @@ NMTOOLS_TESTING_DECLARE_CASE(index, shape_slice) NMTOOLS_TESTING_DECLARE_ARGS(case19) { inline int shape[2] = {4,2}; - inline auto slice0 = tuple{2,None,-2}; - inline auto slice1 = tuple{1,None,-2}; - inline auto shape_ct = tuple{4_ct,2_ct}; - inline auto shape_cl = tuple{"4:[4]"_ct,"2:[2]"_ct}; + inline auto slice0 = nmtools_tuple{2,None,-2}; + inline auto slice1 = nmtools_tuple{1,None,-2}; + inline auto shape_ct = nmtools_tuple{4_ct,2_ct}; + inline auto shape_cl = nmtools_tuple{"4:[4]"_ct,"2:[2]"_ct}; NMTOOLS_CAST_INDEX_ARRAYS(shape) } NMTOOLS_TESTING_DECLARE_EXPECT(case19) @@ -294,10 +294,10 @@ NMTOOLS_TESTING_DECLARE_CASE(index, shape_slice) NMTOOLS_TESTING_DECLARE_ARGS(case20) { inline int shape[2] = {4,2}; - inline auto slice0 = tuple{None,None}; - inline auto slice1 = tuple{1,None,4}; - inline auto shape_ct = tuple{4_ct,2_ct}; - inline auto shape_cl = tuple{"4:[4]"_ct,"2:[2]"_ct}; + inline auto slice0 = nmtools_tuple{None,None}; + inline auto slice1 = nmtools_tuple{1,None,4}; + inline auto shape_ct = nmtools_tuple{4_ct,2_ct}; + inline auto shape_cl = nmtools_tuple{"4:[4]"_ct,"2:[2]"_ct}; NMTOOLS_CAST_INDEX_ARRAYS(shape) } NMTOOLS_TESTING_DECLARE_EXPECT(case20) @@ -310,9 +310,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index, shape_slice) { inline int shape[3] = {2,3,2}; inline auto slice0 = Ellipsis; - inline auto slice1 = tuple{None,None}; - inline auto shape_ct = tuple{2_ct,3_ct,2_ct}; - inline auto shape_cl = tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; + inline auto slice1 = nmtools_tuple{None,None}; + inline auto shape_ct = nmtools_tuple{2_ct,3_ct,2_ct}; + inline auto shape_cl = nmtools_tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; NMTOOLS_CAST_INDEX_ARRAYS(shape); } NMTOOLS_TESTING_DECLARE_EXPECT(case21) @@ -324,9 +324,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index, shape_slice) { inline int shape[3] = {2,3,2}; inline auto slice0 = Ellipsis; - inline auto slice1 = tuple{None,Last}; - inline auto shape_ct = tuple{2_ct,3_ct,2_ct}; - inline auto shape_cl = tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; + inline auto slice1 = nmtools_tuple{None,Last}; + inline auto shape_ct = nmtools_tuple{2_ct,3_ct,2_ct}; + inline auto shape_cl = nmtools_tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; NMTOOLS_CAST_INDEX_ARRAYS(shape); } NMTOOLS_TESTING_DECLARE_EXPECT(case22) @@ -339,9 +339,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index, shape_slice) { inline int shape[3] = {2,3,2}; inline auto slice0 = Ellipsis; - inline auto slice1 = tuple{0,Last}; - inline auto shape_ct = tuple{2_ct,3_ct,2_ct}; - inline auto shape_cl = tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; + inline auto slice1 = nmtools_tuple{0,Last}; + inline auto shape_ct = nmtools_tuple{2_ct,3_ct,2_ct}; + inline auto shape_cl = nmtools_tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; NMTOOLS_CAST_INDEX_ARRAYS(shape); } NMTOOLS_TESTING_DECLARE_EXPECT(case23) @@ -352,10 +352,10 @@ NMTOOLS_TESTING_DECLARE_CASE(index, shape_slice) NMTOOLS_TESTING_DECLARE_ARGS(case24) { inline int shape[3] = {2,3,2}; - inline auto slice0 = tuple{0ul,Last}; + inline auto slice0 = nmtools_tuple{0ul,Last}; inline auto slice1 = Ellipsis; - inline auto shape_ct = tuple{2_ct,3_ct,2_ct}; - inline auto shape_cl = tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; + inline auto shape_ct = nmtools_tuple{2_ct,3_ct,2_ct}; + inline auto shape_cl = nmtools_tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; NMTOOLS_CAST_INDEX_ARRAYS(shape); } NMTOOLS_TESTING_DECLARE_EXPECT(case24) @@ -368,8 +368,8 @@ NMTOOLS_TESTING_DECLARE_CASE(index, shape_slice) inline int shape[3] = {2,3,2}; inline auto slice0 = 0; inline auto slice1 = Ellipsis; - inline auto shape_ct = tuple{2_ct,3_ct,2_ct}; - inline auto shape_cl = tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; + inline auto shape_ct = nmtools_tuple{2_ct,3_ct,2_ct}; + inline auto shape_cl = nmtools_tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; NMTOOLS_CAST_INDEX_ARRAYS(shape); } NMTOOLS_TESTING_DECLARE_EXPECT(case25) @@ -382,8 +382,8 @@ NMTOOLS_TESTING_DECLARE_CASE(index, shape_slice) inline int shape[3] = {2,3,2}; inline auto slice0 = Ellipsis; inline auto slice1 = 0; - inline auto shape_ct = tuple{2_ct,3_ct,2_ct}; - inline auto shape_cl = tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; + inline auto shape_ct = nmtools_tuple{2_ct,3_ct,2_ct}; + inline auto shape_cl = nmtools_tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; NMTOOLS_CAST_INDEX_ARRAYS(shape); } NMTOOLS_TESTING_DECLARE_EXPECT(case26) @@ -397,8 +397,8 @@ NMTOOLS_TESTING_DECLARE_CASE(index, shape_slice) inline auto slice0 = 0; inline auto slice1 = Ellipsis; inline auto slice2 = 0; - inline auto shape_ct = tuple{2_ct,3_ct,2_ct}; - inline auto shape_cl = tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; + inline auto shape_ct = nmtools_tuple{2_ct,3_ct,2_ct}; + inline auto shape_cl = nmtools_tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; NMTOOLS_CAST_INDEX_ARRAYS(shape); } NMTOOLS_TESTING_DECLARE_EXPECT(case27) @@ -411,8 +411,8 @@ NMTOOLS_TESTING_DECLARE_CASE(index, shape_slice) inline int shape[4] = {2,1,3,2}; inline auto slice0 = Ellipsis; inline auto slice1 = 1; - inline auto shape_ct = tuple{2_ct,1_ct,3_ct,2_ct}; - inline auto shape_cl = tuple{"2:[2]"_ct,"1:[1]"_ct,"3:[3]"_ct,"2:[2]"_ct}; + inline auto shape_ct = nmtools_tuple{2_ct,1_ct,3_ct,2_ct}; + inline auto shape_cl = nmtools_tuple{"2:[2]"_ct,"1:[1]"_ct,"3:[3]"_ct,"2:[2]"_ct}; NMTOOLS_CAST_INDEX_ARRAYS(shape); } NMTOOLS_TESTING_DECLARE_EXPECT(case28) @@ -426,8 +426,8 @@ NMTOOLS_TESTING_DECLARE_CASE(index, shape_slice) inline auto slice0 = Ellipsis; inline auto slice1 = 1; inline auto slice2 = 0; - inline auto shape_ct = tuple{2_ct,1_ct,3_ct,2_ct}; - inline auto shape_cl = tuple{"2:[2]"_ct,"1:[1]"_ct,"3:[3]"_ct,"2:[2]"_ct}; + inline auto shape_ct = nmtools_tuple{2_ct,1_ct,3_ct,2_ct}; + inline auto shape_cl = nmtools_tuple{"2:[2]"_ct,"1:[1]"_ct,"3:[3]"_ct,"2:[2]"_ct}; NMTOOLS_CAST_INDEX_ARRAYS(shape); } NMTOOLS_TESTING_DECLARE_EXPECT(case29) @@ -441,8 +441,8 @@ NMTOOLS_TESTING_DECLARE_CASE(index, shape_slice) inline auto slice0 = 1; inline auto slice1 = Ellipsis; inline auto slice2 = 0; - inline auto shape_ct = tuple{2_ct,1_ct,3_ct,2_ct}; - inline auto shape_cl = tuple{"2:[2]"_ct,"1:[1]"_ct,"3:[3]"_ct,"2:[2]"_ct}; + inline auto shape_ct = nmtools_tuple{2_ct,1_ct,3_ct,2_ct}; + inline auto shape_cl = nmtools_tuple{"2:[2]"_ct,"1:[1]"_ct,"3:[3]"_ct,"2:[2]"_ct}; NMTOOLS_CAST_INDEX_ARRAYS(shape); } NMTOOLS_TESTING_DECLARE_EXPECT(case30) @@ -456,8 +456,8 @@ NMTOOLS_TESTING_DECLARE_CASE(index, shape_slice) inline auto slice0 = Last; inline auto slice1 = Ellipsis; inline auto slice2 = 0; - inline auto shape_ct = tuple{2_ct,1_ct,3_ct,2_ct}; - inline auto shape_cl = tuple{"2:[2]"_ct,"1:[1]"_ct,"3:[3]"_ct,"2:[2]"_ct}; + inline auto shape_ct = nmtools_tuple{2_ct,1_ct,3_ct,2_ct}; + inline auto shape_cl = nmtools_tuple{"2:[2]"_ct,"1:[1]"_ct,"3:[3]"_ct,"2:[2]"_ct}; NMTOOLS_CAST_INDEX_ARRAYS(shape); } NMTOOLS_TESTING_DECLARE_EXPECT(case31) @@ -470,9 +470,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index, shape_slice) { inline int shape[3] = {2,3,2}; inline auto slice0 = Ellipsis; - inline auto slice1 = tuple{0,Last,-1}; - inline auto shape_ct = tuple{2_ct,3_ct,2_ct}; - inline auto shape_cl = tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; + inline auto slice1 = nmtools_tuple{0,Last,-1}; + inline auto shape_ct = nmtools_tuple{2_ct,3_ct,2_ct}; + inline auto shape_cl = nmtools_tuple{"2:[2]"_ct,"3:[3]"_ct,"2:[2]"_ct}; NMTOOLS_CAST_INDEX_ARRAYS(shape); } NMTOOLS_TESTING_DECLARE_EXPECT(case32) @@ -970,9 +970,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index, slice) { inline int indices[3] = {0,0,1}; inline int shape[3] = {2,3,2}; - inline auto slice0 = tuple{None,None}; - inline auto slice1 = tuple{0,1}; - inline auto slice2 = tuple{None,None}; + inline auto slice0 = nmtools_tuple{None,None}; + inline auto slice1 = nmtools_tuple{0,1}; + inline auto slice2 = nmtools_tuple{None,None}; NMTOOLS_CAST_INDEX_ARRAYS(indices) NMTOOLS_CAST_INDEX_ARRAYS(shape) } @@ -985,9 +985,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index, slice) { inline int indices[3] = {1,2,0}; inline int shape[3] = {2,3,2}; - inline auto slice0 = tuple{None,None}; - inline auto slice1 = tuple{None,None}; - inline auto slice2 = tuple{None,None}; + inline auto slice0 = nmtools_tuple{None,None}; + inline auto slice1 = nmtools_tuple{None,None}; + inline auto slice2 = nmtools_tuple{None,None}; NMTOOLS_CAST_INDEX_ARRAYS(indices) NMTOOLS_CAST_INDEX_ARRAYS(shape) } @@ -1000,9 +1000,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index, slice) { inline int indices[3] = {0,0,1}; inline int shape[3] = {2,3,2}; - inline auto slice0 = tuple{1,2}; - inline auto slice1 = tuple{0,1}; - inline auto slice2 = tuple{None,None}; + inline auto slice0 = nmtools_tuple{1,2}; + inline auto slice1 = nmtools_tuple{0,1}; + inline auto slice2 = nmtools_tuple{None,None}; NMTOOLS_CAST_INDEX_ARRAYS(indices) NMTOOLS_CAST_INDEX_ARRAYS(shape) } @@ -1015,9 +1015,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index, slice) { inline int indices[3] = {0,0,1}; inline int shape[3] = {2,3,2}; - inline auto slice0 = tuple{1,3}; - inline auto slice1 = tuple{0,1}; - inline auto slice2 = tuple{None,None}; + inline auto slice0 = nmtools_tuple{1,3}; + inline auto slice1 = nmtools_tuple{0,1}; + inline auto slice2 = nmtools_tuple{None,None}; NMTOOLS_CAST_INDEX_ARRAYS(indices) NMTOOLS_CAST_INDEX_ARRAYS(shape) } @@ -1030,9 +1030,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index, slice) { inline int indices[3] = {1,1,0}; inline int shape[3] = {2,3,2}; - inline auto slice0 = tuple{None,None}; - inline auto slice1 = tuple{0,2}; - inline auto slice2 = tuple{None,-1}; + inline auto slice0 = nmtools_tuple{None,None}; + inline auto slice1 = nmtools_tuple{0,2}; + inline auto slice2 = nmtools_tuple{None,-1}; NMTOOLS_CAST_INDEX_ARRAYS(indices) NMTOOLS_CAST_INDEX_ARRAYS(shape) } @@ -1045,7 +1045,7 @@ NMTOOLS_TESTING_DECLARE_CASE(index, slice) { inline int indices[1] = {1}; inline int shape[3] = {2,3,2}; - inline auto slice0 = tuple{None,None}; + inline auto slice0 = nmtools_tuple{None,None}; inline auto slice1 = 0; inline auto slice2 = 0; NMTOOLS_CAST_INDEX_ARRAYS(indices) @@ -1060,9 +1060,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index, slice) { inline int indices[2] = {1,0}; inline int shape[3] = {2,3,2}; - inline auto slice0 = tuple{None,None}; + inline auto slice0 = nmtools_tuple{None,None}; inline auto slice1 = 0; - inline auto slice2 = tuple{None,-1}; + inline auto slice2 = nmtools_tuple{None,-1}; NMTOOLS_CAST_INDEX_ARRAYS(indices) NMTOOLS_CAST_INDEX_ARRAYS(shape) } @@ -1075,9 +1075,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index, slice) { inline int indices[3] = {0,0,0}; inline int shape[3] = {2,3,2}; - inline auto slice0 = tuple{None,None,-1}; - inline auto slice1 = tuple{None,None}; - inline auto slice2 = tuple{None,None}; + inline auto slice0 = nmtools_tuple{None,None,-1}; + inline auto slice1 = nmtools_tuple{None,None}; + inline auto slice2 = nmtools_tuple{None,None}; NMTOOLS_CAST_INDEX_ARRAYS(indices) NMTOOLS_CAST_INDEX_ARRAYS(shape) } @@ -1090,9 +1090,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index, slice) { inline int indices[3] = {1,2,1}; inline int shape[3] = {2,3,2}; - inline auto slice0 = tuple{None,None,-1}; - inline auto slice1 = tuple{None,None}; - inline auto slice2 = tuple{None,None}; + inline auto slice0 = nmtools_tuple{None,None,-1}; + inline auto slice1 = nmtools_tuple{None,None}; + inline auto slice2 = nmtools_tuple{None,None}; NMTOOLS_CAST_INDEX_ARRAYS(indices) NMTOOLS_CAST_INDEX_ARRAYS(shape) } @@ -1105,9 +1105,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index, slice) { inline int indices[3] = {0,0,0}; inline int shape[3] = {2,3,2}; - inline auto slice0 = tuple{None,None}; - inline auto slice1 = tuple{None,None,-1}; - inline auto slice2 = tuple{None,None}; + inline auto slice0 = nmtools_tuple{None,None}; + inline auto slice1 = nmtools_tuple{None,None,-1}; + inline auto slice2 = nmtools_tuple{None,None}; NMTOOLS_CAST_INDEX_ARRAYS(indices) NMTOOLS_CAST_INDEX_ARRAYS(shape) } @@ -1120,9 +1120,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index, slice) { inline int indices[3] = {1,2,1}; inline int shape[3] = {2,3,2}; - inline auto slice0 = tuple{None,None}; - inline auto slice1 = tuple{None,None,-1}; - inline auto slice2 = tuple{None,None}; + inline auto slice0 = nmtools_tuple{None,None}; + inline auto slice1 = nmtools_tuple{None,None,-1}; + inline auto slice2 = nmtools_tuple{None,None}; NMTOOLS_CAST_INDEX_ARRAYS(indices) NMTOOLS_CAST_INDEX_ARRAYS(shape) } @@ -1135,9 +1135,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index, slice) { inline int indices[3] = {1,1,1}; inline int shape[3] = {2,3,2}; - inline auto slice0 = tuple{None,None}; - inline auto slice1 = tuple{None,None,-1}; - inline auto slice2 = tuple{None,None}; + inline auto slice0 = nmtools_tuple{None,None}; + inline auto slice1 = nmtools_tuple{None,None,-1}; + inline auto slice2 = nmtools_tuple{None,None}; NMTOOLS_CAST_INDEX_ARRAYS(indices) NMTOOLS_CAST_INDEX_ARRAYS(shape) } @@ -1150,9 +1150,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index, slice) { inline int indices[3] = {0,0,0}; inline int shape[3] = {2,3,2}; - inline auto slice0 = tuple{None,None,-1}; - inline auto slice1 = tuple{None,None}; - inline auto slice2 = tuple{None,None,-1}; + inline auto slice0 = nmtools_tuple{None,None,-1}; + inline auto slice1 = nmtools_tuple{None,None}; + inline auto slice2 = nmtools_tuple{None,None,-1}; NMTOOLS_CAST_INDEX_ARRAYS(indices) NMTOOLS_CAST_INDEX_ARRAYS(shape) } @@ -1165,9 +1165,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index, slice) { inline int indices[3] = {0,0,1}; inline int shape[3] = {2,3,2}; - inline auto slice0 = tuple{None,None,-1}; - inline auto slice1 = tuple{0,1}; - inline auto slice2 = tuple{None,None,-1}; + inline auto slice0 = nmtools_tuple{None,None,-1}; + inline auto slice1 = nmtools_tuple{0,1}; + inline auto slice2 = nmtools_tuple{None,None,-1}; NMTOOLS_CAST_INDEX_ARRAYS(indices) NMTOOLS_CAST_INDEX_ARRAYS(shape) } @@ -1180,9 +1180,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index, slice) { inline int indices[3] = {0,0,1}; inline int shape[3] = {2,3,2}; - inline auto slice0 = tuple{None,None,-1}; - inline auto slice1 = tuple{1,None,-1}; - inline auto slice2 = tuple{None,None,-1}; + inline auto slice0 = nmtools_tuple{None,None,-1}; + inline auto slice1 = nmtools_tuple{1,None,-1}; + inline auto slice2 = nmtools_tuple{None,None,-1}; NMTOOLS_CAST_INDEX_ARRAYS(indices) NMTOOLS_CAST_INDEX_ARRAYS(shape) } @@ -1195,9 +1195,9 @@ NMTOOLS_TESTING_DECLARE_CASE(index, slice) { inline int indices[3] = {0,1,1}; inline int shape[3] = {2,3,2}; - inline auto slice0 = tuple{None,None,-1}; - inline auto slice1 = tuple{1,None,-1}; - inline auto slice2 = tuple{None,None,-1}; + inline auto slice0 = nmtools_tuple{None,None,-1}; + inline auto slice1 = nmtools_tuple{1,None,-1}; + inline auto slice2 = nmtools_tuple{None,None,-1}; NMTOOLS_CAST_INDEX_ARRAYS(indices) NMTOOLS_CAST_INDEX_ARRAYS(shape) } @@ -1210,8 +1210,8 @@ NMTOOLS_TESTING_DECLARE_CASE(index, slice) { inline int indices[2] = {1,1}; inline int shape[2] = {4,2}; - inline auto slice0 = tuple{None,None,2}; - inline auto slice1 = tuple{None,None}; + inline auto slice0 = nmtools_tuple{None,None,2}; + inline auto slice1 = nmtools_tuple{None,None}; NMTOOLS_CAST_INDEX_ARRAYS(indices) NMTOOLS_CAST_INDEX_ARRAYS(shape) } @@ -1224,8 +1224,8 @@ NMTOOLS_TESTING_DECLARE_CASE(index, slice) { inline int indices[2] = {1,1}; inline int shape[2] = {4,2}; - inline auto slice0 = tuple{None,None,-2}; - inline auto slice1 = tuple{None,None}; + inline auto slice0 = nmtools_tuple{None,None,-2}; + inline auto slice1 = nmtools_tuple{None,None}; NMTOOLS_CAST_INDEX_ARRAYS(indices) NMTOOLS_CAST_INDEX_ARRAYS(shape) } @@ -1238,8 +1238,8 @@ NMTOOLS_TESTING_DECLARE_CASE(index, slice) { inline int indices[2] = {0,0}; inline int shape[2] = {4,2}; - inline auto slice0 = tuple{None,None,-2}; - inline auto slice1 = tuple{None,None}; + inline auto slice0 = nmtools_tuple{None,None,-2}; + inline auto slice1 = nmtools_tuple{None,None}; NMTOOLS_CAST_INDEX_ARRAYS(indices) NMTOOLS_CAST_INDEX_ARRAYS(shape) } @@ -1252,8 +1252,8 @@ NMTOOLS_TESTING_DECLARE_CASE(index, slice) { inline int indices[2] = {0,0}; inline int shape[2] = {4,2}; - inline auto slice0 = tuple{None,None,-2}; - inline auto slice1 = tuple{1,None,2}; + inline auto slice0 = nmtools_tuple{None,None,-2}; + inline auto slice1 = nmtools_tuple{1,None,2}; NMTOOLS_CAST_INDEX_ARRAYS(indices) NMTOOLS_CAST_INDEX_ARRAYS(shape) } @@ -1266,8 +1266,8 @@ NMTOOLS_TESTING_DECLARE_CASE(index, slice) { inline int indices[2] = {0,0}; inline int shape[2] = {4,2}; - inline auto slice0 = tuple{None,None,-2}; - inline auto slice1 = tuple{1,None,-2}; + inline auto slice0 = nmtools_tuple{None,None,-2}; + inline auto slice1 = nmtools_tuple{1,None,-2}; NMTOOLS_CAST_INDEX_ARRAYS(indices) NMTOOLS_CAST_INDEX_ARRAYS(shape) } @@ -1280,8 +1280,8 @@ NMTOOLS_TESTING_DECLARE_CASE(index, slice) { inline int indices[2] = {0,0}; inline int shape[2] = {4,2}; - inline auto slice0 = tuple{3,None,-2}; - inline auto slice1 = tuple{1,None,-2}; + inline auto slice0 = nmtools_tuple{3,None,-2}; + inline auto slice1 = nmtools_tuple{1,None,-2}; NMTOOLS_CAST_INDEX_ARRAYS(indices) NMTOOLS_CAST_INDEX_ARRAYS(shape) } @@ -1294,8 +1294,8 @@ NMTOOLS_TESTING_DECLARE_CASE(index, slice) { inline int indices[2] = {0,0}; inline int shape[2] = {4,2}; - inline auto slice0 = tuple{3,None,2}; - inline auto slice1 = tuple{1,None,-2}; + inline auto slice0 = nmtools_tuple{3,None,2}; + inline auto slice1 = nmtools_tuple{1,None,-2}; NMTOOLS_CAST_INDEX_ARRAYS(indices) NMTOOLS_CAST_INDEX_ARRAYS(shape) } @@ -1309,7 +1309,7 @@ NMTOOLS_TESTING_DECLARE_CASE(index, slice) inline int indices[3] = {0,1,0}; inline int shape[3] = {2,3,2}; inline auto slice0 = Ellipsis; - inline auto slice1 = tuple{None,None}; + inline auto slice1 = nmtools_tuple{None,None}; NMTOOLS_CAST_INDEX_ARRAYS(shape); NMTOOLS_CAST_INDEX_ARRAYS(indices); } @@ -1323,7 +1323,7 @@ NMTOOLS_TESTING_DECLARE_CASE(index, slice) inline int indices[3] = {0,1,0}; inline int shape[3] = {2,3,2}; inline auto slice0 = Ellipsis; - inline auto slice1 = tuple{None,Last}; + inline auto slice1 = nmtools_tuple{None,Last}; NMTOOLS_CAST_INDEX_ARRAYS(shape); NMTOOLS_CAST_INDEX_ARRAYS(indices); } @@ -1337,7 +1337,7 @@ NMTOOLS_TESTING_DECLARE_CASE(index, slice) inline int indices[3] = {0,1,0}; inline int shape[3] = {2,3,2}; inline auto slice0 = Ellipsis; - inline auto slice1 = tuple{0,Last}; + inline auto slice1 = nmtools_tuple{0,Last}; NMTOOLS_CAST_INDEX_ARRAYS(shape); NMTOOLS_CAST_INDEX_ARRAYS(indices); } @@ -1350,7 +1350,7 @@ NMTOOLS_TESTING_DECLARE_CASE(index, slice) { inline int indices[3] = {0,1,0}; inline int shape[3] = {2,3,2}; - inline auto slice0 = tuple{0ul,Last}; + inline auto slice0 = nmtools_tuple{0ul,Last}; inline auto slice1 = Ellipsis; NMTOOLS_CAST_INDEX_ARRAYS(shape); NMTOOLS_CAST_INDEX_ARRAYS(indices); @@ -1496,7 +1496,7 @@ NMTOOLS_TESTING_DECLARE_CASE(index, slice) inline int shape[3] = {2,3,2}; inline auto slice0 = Ellipsis; inline auto slice1 = -1; - inline auto slice2 = tuple{None,None,-1}; + inline auto slice2 = nmtools_tuple{None,None,-1}; NMTOOLS_CAST_INDEX_ARRAYS(shape); NMTOOLS_CAST_INDEX_ARRAYS(indices); } @@ -1511,7 +1511,7 @@ NMTOOLS_TESTING_DECLARE_CASE(index, slice) inline int shape[3] = {2,3,2}; inline auto slice0 = Ellipsis; inline auto slice1 = -2; - inline auto slice2 = tuple{None,None,-1}; + inline auto slice2 = nmtools_tuple{None,None,-1}; NMTOOLS_CAST_INDEX_ARRAYS(shape); NMTOOLS_CAST_INDEX_ARRAYS(indices); } @@ -1585,7 +1585,7 @@ NMTOOLS_TESTING_DECLARE_CASE(index, slice) inline int shape[4] = {2,1,3,2}; inline auto slice0 = 1; inline auto slice1 = Ellipsis; - inline auto slice2 = tuple{None,None,-1}; + inline auto slice2 = nmtools_tuple{None,None,-1}; inline auto slice3 = 1; NMTOOLS_CAST_INDEX_ARRAYS(shape); NMTOOLS_CAST_INDEX_ARRAYS(indices); @@ -1601,7 +1601,7 @@ NMTOOLS_TESTING_DECLARE_CASE(index, slice) inline int shape[4] = {2,1,3,2}; inline auto slice0 = 1; inline auto slice1 = Ellipsis; - inline auto slice2 = tuple{None,None,1}; + inline auto slice2 = nmtools_tuple{None,None,1}; inline auto slice3 = 1; NMTOOLS_CAST_INDEX_ARRAYS(shape); NMTOOLS_CAST_INDEX_ARRAYS(indices); @@ -1633,7 +1633,7 @@ NMTOOLS_TESTING_DECLARE_CASE(index, slice) inline int shape[4] = {2,1,3,2}; inline auto slice0 = 1; inline auto slice1 = Ellipsis; - inline auto slice2 = tuple{None,None,-1}; + inline auto slice2 = nmtools_tuple{None,None,-1}; inline auto slice3 = 0; NMTOOLS_CAST_INDEX_ARRAYS(shape); NMTOOLS_CAST_INDEX_ARRAYS(indices); diff --git a/include/nmtools/testing/string.hpp b/include/nmtools/testing/string.hpp index fb6ac62cc..8c3f79081 100644 --- a/include/nmtools/testing/string.hpp +++ b/include/nmtools/testing/string.hpp @@ -63,16 +63,16 @@ namespace nmtools::testing NMTOOLS_STRING ss; constexpr auto n = (sizeof...(args)); #ifdef _NMTOOLS_TESTING_HAS_TYPE_INDEX - auto typenames = meta::make_array_type_t{ + auto typenames = nmtools_array{ {boost::typeindex::type_id().pretty_name()...} }; #elif defined(NMTOOLS_RTTI_ENABLED) - auto typenames = meta::make_array_type_t{ + auto typenames = nmtools_array{ {typeid(decltype(args)).name()...} }; #else // empty - auto typenames = meta::make_array_type_t{}; + auto typenames = nmtools_array{}; #endif ss += func; ss += '('; @@ -91,16 +91,16 @@ namespace nmtools::testing NMTOOLS_STRING ss; constexpr auto n = (sizeof...(args)); #ifdef _NMTOOLS_TESTING_HAS_TYPE_INDEX - auto typenames = meta::make_array_type_t{ + auto typenames = nmtools_array{ {boost::typeindex::type_id().pretty_name()...} }; #elif defined(NMTOOLS_RTTI_ENABLED) - auto typenames = meta::make_array_type_t{ + auto typenames = nmtools_array{ {typeid(decltype(args)).name()...} }; #else // empty - auto typenames = meta::make_array_type_t{}; + auto typenames = nmtools_array{}; #endif ss += func; ss += '('; diff --git a/include/nmtools/utils/isclose.hpp b/include/nmtools/utils/isclose.hpp index 1edeb04d7..9352e1e1a 100644 --- a/include/nmtools/utils/isclose.hpp +++ b/include/nmtools/utils/isclose.hpp @@ -189,8 +189,8 @@ namespace nmtools::utils using ulhs_ptr_t = decltype(get_if(&u)); using trhs_ptr_t = decltype(get_if(&t)); using urhs_ptr_t = decltype(get_if(&u)); - using tuple_lhs_t = meta::make_tuple_type_t; - using tuple_rhs_t = meta::make_tuple_type_t; + using tuple_lhs_t = nmtools_tuple; + using tuple_rhs_t = nmtools_tuple; auto close = false; // under the hood, recursively call isclose to properly handle view type if (const auto [tptr, uptr] = tuple_lhs_t{get_if(&t), get_if(&u)}; tptr && uptr) diff --git a/include/nmtools/utils/isequal.hpp b/include/nmtools/utils/isequal.hpp index 5ac81f0fa..7f2467463 100644 --- a/include/nmtools/utils/isequal.hpp +++ b/include/nmtools/utils/isequal.hpp @@ -237,8 +237,8 @@ namespace nmtools::utils using ulhs_ptr_t = decltype(get_if(&u)); using trhs_ptr_t = decltype(get_if(&t)); using urhs_ptr_t = decltype(get_if(&u)); - using tuple_lhs_t = meta::make_tuple_type_t; - using tuple_rhs_t = meta::make_tuple_type_t; + using tuple_lhs_t = nmtools_tuple; + using tuple_rhs_t = nmtools_tuple; auto same = false; // under the hood, recursively call isequal to properly handle view type if (const auto [tptr, uptr] = tuple_lhs_t{get_if(&t), get_if(&u)}; tptr && uptr) diff --git a/include/nmtools/utils/to_string/common_types.hpp b/include/nmtools/utils/to_string/common_types.hpp index 9a9799098..2f36e4b26 100644 --- a/include/nmtools/utils/to_string/common_types.hpp +++ b/include/nmtools/utils/to_string/common_types.hpp @@ -104,7 +104,7 @@ namespace nmtools::utils::impl return meta::to_value_v; } else if constexpr (meta::is_tuple_v) { constexpr auto N = meta::len_v; - using array_t = meta::make_array_type_t; + using array_t = nmtools_array; auto array = array_t{}; meta::template_for([&](auto i){ at(array,i) = at(shape_,i); diff --git a/include/nmtools/utils/to_string/functor.hpp b/include/nmtools/utils/to_string/functor.hpp index 8ef9788ed..defd5a8c4 100644 --- a/include/nmtools/utils/to_string/functor.hpp +++ b/include/nmtools/utils/to_string/functor.hpp @@ -121,7 +121,7 @@ namespace nmtools::utils::impl auto operator()(const graph_type& graph) const noexcept { auto graphviz = nmtools_string("digraph G"); - graphviz += "{"; + graphviz += "{\n"; { auto out_edges = graph.out_edges(); @@ -144,10 +144,21 @@ namespace nmtools::utils::impl meta::template_for([&](auto index){ auto node_id = nmtools::at(nodes,index); auto node = graph.nodes(node_id); + using node_t = meta::remove_cvref_pointer_t; + constexpr auto is_buffered = + (meta::is_ndarray_v || meta::is_num_v) + && !meta::is_view_v + ; auto node_id_str = to_string(node_id); graphviz += node_id_str; graphviz += "["; + graphviz += "shape=\"box\" "; + if (is_buffered) { + graphviz += "style=\"rounded,filled\" "; + graphviz += "color=\"black\" "; + graphviz += "fillcolor=\"gray93\" "; + } graphviz += "label="; graphviz += "\""; graphviz += "{id: "; diff --git a/tests/array/CMakeLists.txt b/tests/array/CMakeLists.txt index dd0ccfce8..f7d12aeaa 100644 --- a/tests/array/CMakeLists.txt +++ b/tests/array/CMakeLists.txt @@ -145,7 +145,8 @@ set(ARRAY_UFUNCS_TEST_SOURCES array/ufuncs/bitwise_or.cpp array/ufuncs/bitwise_xor.cpp array/ufuncs/ceil.cpp - array/ufuncs/clip.cpp + # TODO: this compiles forever, fix + # array/ufuncs/clip.cpp array/ufuncs/cos.cpp array/ufuncs/cosh.cpp array/ufuncs/divide.cpp diff --git a/tests/array/utility/apply_at.cpp b/tests/array/utility/apply_at.cpp index 753dc622f..2c51864f2 100644 --- a/tests/array/utility/apply_at.cpp +++ b/tests/array/utility/apply_at.cpp @@ -23,37 +23,37 @@ TEST_CASE("apply_at(double[]...)" * doctest::test_suite("utility")) { { double array[1] = {1}; - auto indices = tuple{0}; + auto indices = nmtools_tuple{0}; auto a = nm::apply_at(array, indices); NMTOOLS_ASSERT_CLOSE(a, 1); } { double array[2] = {1, 2}; - auto indices = tuple{1}; + auto indices = nmtools_tuple{1}; auto a = nm::apply_at(array, indices); NMTOOLS_ASSERT_CLOSE(a, 2); } { double array[3] = {1, 3, 2}; - auto indices = tuple{1}; + auto indices = nmtools_tuple{1}; auto a = nm::apply_at(array, indices); NMTOOLS_ASSERT_CLOSE(a, 3); } { double array[1][1][1][1][1] = {{{{{1}}}}}; - auto indices = tuple{0,0,0,0,0}; + auto indices = nmtools_tuple{0,0,0,0,0}; auto a = nm::apply_at(array, indices); NMTOOLS_ASSERT_CLOSE(a, 1); } { double array[1][2][1] = {{{0},{1}}}; { - auto indices = tuple{0,0,0}; + auto indices = nmtools_tuple{0,0,0}; auto a = nm::apply_at(array, indices); NMTOOLS_ASSERT_CLOSE(a, 0); } { - auto indices = tuple{0,1,0}; + auto indices = nmtools_tuple{0,1,0}; auto a = nm::apply_at(array, indices); NMTOOLS_ASSERT_CLOSE(a, 1); } @@ -69,17 +69,17 @@ TEST_CASE("apply_at(std::array<...>)" * doctest::test_suite("utility")) array{3,4}, }; { - auto indices = tuple{0,1}; + auto indices = nmtools_tuple{0,1}; auto res = nm::apply_at(a,indices); NMTOOLS_ASSERT_CLOSE(res, 2); } { - auto indices = tuple{1,0}; + auto indices = nmtools_tuple{1,0}; auto res = nm::apply_at(a,indices); NMTOOLS_ASSERT_CLOSE(res, 3); } { - auto indices = tuple{1,1}; + auto indices = nmtools_tuple{1,1}; auto res = nm::apply_at(a,indices); NMTOOLS_ASSERT_CLOSE(res, 4); } @@ -90,22 +90,22 @@ TEST_CASE("apply_at(std::array<...>)" * doctest::test_suite("utility")) array{ array{5,6}, array{7,8}, }, }; { - auto indices = tuple{0,0,0}; + auto indices = nmtools_tuple{0,0,0}; auto res = nm::apply_at(a,indices); NMTOOLS_ASSERT_CLOSE(res, 1); } { - auto indices = tuple{0,1,0}; + auto indices = nmtools_tuple{0,1,0}; auto res = nm::apply_at(a,indices); NMTOOLS_ASSERT_CLOSE(res, 3); } { - auto indices = tuple{1,0,0}; + auto indices = nmtools_tuple{1,0,0}; auto res = nm::apply_at(a,indices); NMTOOLS_ASSERT_CLOSE(res, 5); } { - auto indices = tuple{1,1,1}; + auto indices = nmtools_tuple{1,1,1}; auto res = nm::apply_at(a,indices); NMTOOLS_ASSERT_CLOSE(res, 8); } @@ -120,17 +120,17 @@ TEST_CASE("apply_at(std::vector<...>)" * doctest::test_suite("utility")) vector{3,4}, }; { - auto indices = tuple{0,1}; + auto indices = nmtools_tuple{0,1}; auto res = nm::apply_at(a,indices); NMTOOLS_ASSERT_CLOSE(res, 2); } { - auto indices = tuple{1,0}; + auto indices = nmtools_tuple{1,0}; auto res = nm::apply_at(a,indices); NMTOOLS_ASSERT_CLOSE(res, 3); } { - auto indices = tuple{1,1}; + auto indices = nmtools_tuple{1,1}; auto res = nm::apply_at(a,indices); NMTOOLS_ASSERT_CLOSE(res, 4); } @@ -141,22 +141,22 @@ TEST_CASE("apply_at(std::vector<...>)" * doctest::test_suite("utility")) vector{ vector{5,6}, vector{7,8}, }, }; { - auto indices = tuple{0,0,0}; + auto indices = nmtools_tuple{0,0,0}; auto res = nm::apply_at(a,indices); NMTOOLS_ASSERT_CLOSE(res, 1); } { - auto indices = tuple{0,1,0}; + auto indices = nmtools_tuple{0,1,0}; auto res = nm::apply_at(a,indices); NMTOOLS_ASSERT_CLOSE(res, 3); } { - auto indices = tuple{1,0,0}; + auto indices = nmtools_tuple{1,0,0}; auto res = nm::apply_at(a,indices); NMTOOLS_ASSERT_CLOSE(res, 5); } { - auto indices = tuple{1,1,1}; + auto indices = nmtools_tuple{1,1,1}; auto res = nm::apply_at(a,indices); NMTOOLS_ASSERT_CLOSE(res, 8); } @@ -169,12 +169,12 @@ TEST_CASE("apply_at(dynamic_ndarray<>)" * doctest::test_suite("utility")) { auto a = dynamic_ndarray{{1,2,3,4,5,6}}; { - auto indices = tuple{1}; + auto indices = nmtools_tuple{1}; auto res = nm::apply_at(a, indices); NMTOOLS_ASSERT_CLOSE(res, 2); } { - auto indices = tuple{2}; + auto indices = nmtools_tuple{2}; auto res = nm::apply_at(a, indices); NMTOOLS_ASSERT_CLOSE(res, 3); } @@ -246,17 +246,17 @@ TEST_CASE("apply_at(fixed_ndarray<>)" * doctest::test_suite("utility")) { {{1},{2}}, {{3},{4}}, {{5},{6}} } }; { - auto indices = tuple{0,1,0}; + auto indices = nmtools_tuple{0,1,0}; auto res = nm::apply_at(a, indices); NMTOOLS_ASSERT_CLOSE(res, 2); } { - auto indices = tuple{1,0,0}; + auto indices = nmtools_tuple{1,0,0}; auto res = nm::apply_at(a, indices); NMTOOLS_ASSERT_CLOSE(res, 3); } { - auto indices = tuple{2,1,0}; + auto indices = nmtools_tuple{2,1,0}; auto res = nm::apply_at(a, indices); NMTOOLS_ASSERT_CLOSE(res, 6); } diff --git a/tests/array/utils/isclose.cpp b/tests/array/utils/isclose.cpp index c029d53c7..6b62b5c1e 100644 --- a/tests/array/utils/isclose.cpp +++ b/tests/array/utils/isclose.cpp @@ -28,13 +28,13 @@ namespace meta = nmtools::meta; TEST_CASE("isclose(tuple,tuple)" * doctest::test_suite("utils")) { { - auto lhs = tuple{1., 2., 3., 4., 5.}; - auto rhs = tuple{1., 2., 3., 4., 5.}; + auto lhs = nmtools_tuple{1., 2., 3., 4., 5.}; + auto rhs = nmtools_tuple{1., 2., 3., 4., 5.}; CHECK( isclose(lhs,rhs) ); } { - auto lhs = tuple{1., 2., 3., 4., 5.}; - auto rhs = tuple{1., 2., 3., 4., 1.}; + auto lhs = nmtools_tuple{1., 2., 3., 4., 5.}; + auto rhs = nmtools_tuple{1., 2., 3., 4., 1.}; CHECK( !isclose(lhs,rhs) ); } } @@ -111,12 +111,12 @@ TEST_CASE("isclose(int[],int[])" * doctest::test_suite("utils")) TEST_CASE("isclose(tuple,array)" * doctest::test_suite("utils")) { { - auto lhs = tuple{1., 2., 3., 4., 5.}; + auto lhs = nmtools_tuple{1., 2., 3., 4., 5.}; auto rhs = array{1., 2., 3., 4., 5.}; CHECK( isclose(lhs,rhs) ); } { - auto lhs = tuple{1., 2., 3., 4., 5.}; + auto lhs = nmtools_tuple{1., 2., 3., 4., 5.}; auto rhs = array{1., 2., 2., 4., 5.}; CHECK( !isclose(lhs,rhs) ); } @@ -130,12 +130,12 @@ TEST_CASE("isclose(array,tuple)" * doctest::test_suite("utils")) { { auto lhs = array{1., 2., 3., 4., 5.}; - auto rhs = tuple{1., 2., 3., 4., 5.}; + auto rhs = nmtools_tuple{1., 2., 3., 4., 5.}; CHECK( isclose(lhs,rhs) ); } { auto lhs = array{1., 2., 3., 4., 5.}; - auto rhs = tuple{1., 2., 2., 4., 5.}; + auto rhs = nmtools_tuple{1., 2., 2., 4., 5.}; CHECK( !isclose(lhs,rhs) ); } } @@ -235,9 +235,9 @@ TEST_CASE("isclose(array[2],tuple[2])" * doctest::test_suite("utils")) array{1., 2., 3.}, array{4., 5., 6.} }; - auto rhs = tuple{ - tuple{1., 2., 3.}, - tuple{4., 5., 6.} + auto rhs = nmtools_tuple{ + nmtools_tuple{1., 2., 3.}, + nmtools_tuple{4., 5., 6.} }; CHECK( isclose(lhs,rhs) ); } @@ -246,9 +246,9 @@ TEST_CASE("isclose(array[2],tuple[2])" * doctest::test_suite("utils")) array{1., 2., 3.}, array{4., 5., 6.} }; - auto rhs = tuple{ - tuple{1., 2., 3.}, - tuple{4., 1., 6.} + auto rhs = nmtools_tuple{ + nmtools_tuple{1., 2., 3.}, + nmtools_tuple{4., 1., 6.} }; CHECK( !isclose(lhs,rhs) ); } @@ -804,9 +804,9 @@ TEST_CASE("isclose(optional)" * doctest::test_suite("isclose")) // array{1., 2., 3.}, // array{4., 5., 6.} // }; -// auto rhs = tuple{ -// tuple{1., 2., 3.}, -// tuple{4, 5, 6, 1} +// auto rhs = nmtools_tuple{ +// nmtools_tuple{1., 2., 3.}, +// nmtools_tuple{4, 5, 6, 1} // }; // CHECK( isclose(lhs,rhs) ); // } @@ -834,12 +834,12 @@ TEST_CASE("isclose(optional)" * doctest::test_suite("isclose")) // { // { // auto lhs = array{1., 2., 3., 4., 5.}; -// auto rhs = tuple{1, 2, 3, 4, 5, 6}; +// auto rhs = nmtools_tuple{1, 2, 3, 4, 5, 6}; // CHECK( isclose(lhs,rhs) ); // } // { // auto lhs = array{1., 2., 3., 4., 5.}; -// auto rhs = tuple{1, 2, 2, 4, 5, 6}; +// auto rhs = nmtools_tuple{1, 2, 2, 4, 5, 6}; // CHECK( !isclose(lhs,rhs) ); // } // } \ No newline at end of file diff --git a/tests/array/utils/isequal.cpp b/tests/array/utils/isequal.cpp index e2a1b7c34..7e4213b01 100644 --- a/tests/array/utils/isequal.cpp +++ b/tests/array/utils/isequal.cpp @@ -24,13 +24,13 @@ namespace meta = nmtools::meta; TEST_CASE("isequal(tuple,tuple)" * doctest::test_suite("utils")) { { - auto lhs = tuple{1, 2, 3, 4, 5}; - auto rhs = tuple{1, 2, 3, 4, 5}; + auto lhs = nmtools_tuple{1, 2, 3, 4, 5}; + auto rhs = nmtools_tuple{1, 2, 3, 4, 5}; CHECK( isequal(lhs,rhs) ); } { - auto lhs = tuple{1, 2, 3, 4, 5}; - auto rhs = tuple{1, 2, 3, 4, 1}; + auto lhs = nmtools_tuple{1, 2, 3, 4, 5}; + auto rhs = nmtools_tuple{1, 2, 3, 4, 1}; CHECK( !isequal(lhs,rhs) ); } } @@ -149,12 +149,12 @@ TEST_CASE("isequal(dynamic_ndarray,dynamic_ndarray)" * doctest::test_suite("util TEST_CASE("isequal(tuple,array)" * doctest::test_suite("utils")) { { - auto lhs = tuple{1, 2, 3, 4, 5}; + auto lhs = nmtools_tuple{1, 2, 3, 4, 5}; auto rhs = array{1, 2, 3, 4, 5}; CHECK( isequal(lhs,rhs) ); } { - auto lhs = tuple{1, 2, 3, 4, 5}; + auto lhs = nmtools_tuple{1, 2, 3, 4, 5}; auto rhs = array{1, 2, 2, 4, 5}; CHECK( !isequal(lhs,rhs) ); } @@ -168,12 +168,12 @@ TEST_CASE("isequal(array,tuple)" * doctest::test_suite("utils")) { { auto lhs = array{1, 2, 3, 4, 5}; - auto rhs = tuple{1, 2, 3, 4, 5}; + auto rhs = nmtools_tuple{1, 2, 3, 4, 5}; CHECK( isequal(lhs,rhs) ); } { auto lhs = array{1, 2, 3, 4, 5}; - auto rhs = tuple{1, 2, 2, 4, 5}; + auto rhs = nmtools_tuple{1, 2, 2, 4, 5}; CHECK( !isequal(lhs,rhs) ); } } @@ -272,9 +272,9 @@ TEST_CASE("isequal(array[2],tuple[2])" * doctest::test_suite("utils")) array{1, 2, 3}, array{4, 5, 6} }; - auto rhs = tuple{ - tuple{1, 2, 3}, - tuple{4, 5, 6} + auto rhs = nmtools_tuple{ + nmtools_tuple{1, 2, 3}, + nmtools_tuple{4, 5, 6} }; CHECK( isequal(lhs,rhs) ); } @@ -283,9 +283,9 @@ TEST_CASE("isequal(array[2],tuple[2])" * doctest::test_suite("utils")) array{1, 2, 3}, array{4, 5, 6} }; - auto rhs = tuple{ - tuple{1, 2, 3}, - tuple{4, 1, 6} + auto rhs = nmtools_tuple{ + nmtools_tuple{1, 2, 3}, + nmtools_tuple{4, 1, 6} }; CHECK( !isequal(lhs,rhs) ); } @@ -1063,9 +1063,9 @@ TEST_CASE("isequal(integral_constant)" * doctest::test_suite("isequal")) // array{1, 2, 3}, // array{4, 5, 6} // }; -// auto rhs = tuple{ -// tuple{1, 2, 3}, -// tuple{4, 5, 6, 1} +// auto rhs = nmtools_tuple{ +// nmtools_tuple{1, 2, 3}, +// nmtools_tuple{4, 5, 6, 1} // }; // CHECK( isequal(lhs,rhs) ); // } @@ -1093,12 +1093,12 @@ TEST_CASE("isequal(integral_constant)" * doctest::test_suite("isequal")) // { // { // auto lhs = array{1, 2, 3, 4, 5}; -// auto rhs = tuple{1, 2, 3, 4, 5, 6}; +// auto rhs = nmtools_tuple{1, 2, 3, 4, 5, 6}; // CHECK( isequal(lhs,rhs) ); // } // { // auto lhs = array{1, 2, 3, 4, 5}; -// auto rhs = tuple{1, 2, 2, 4, 5, 6}; +// auto rhs = nmtools_tuple{1, 2, 2, 4, 5, 6}; // CHECK( !isequal(lhs,rhs) ); // } // } \ No newline at end of file diff --git a/tests/array/utils/to_string.cpp b/tests/array/utils/to_string.cpp index f22218aea..81833fb05 100644 --- a/tests/array/utils/to_string.cpp +++ b/tests/array/utils/to_string.cpp @@ -72,7 +72,7 @@ TEST_CASE("to_string(double[1][1][1][1])" * doctest::test_suite("utils") * docte TEST_CASE("to_string(tuple)" * doctest::test_suite("utils") * doctest::skip(true)) { { - auto arg = tuple{1., 2., 3., 4., 5.}; + auto arg = nmtools_tuple{1., 2., 3., 4., 5.}; auto str = to_string(arg); auto to_print = std::string("\n") + str; MESSAGE( to_print ); @@ -124,9 +124,9 @@ TEST_CASE("to_string(double[5])" * doctest::test_suite("utils") * doctest::skip( TEST_CASE("to_string(tuple[2])" * doctest::test_suite("utils") * doctest::skip(true)) { { - auto arg = tuple{ - tuple{1., 2., 3.}, - tuple{4., 5., 6.} + auto arg = nmtools_tuple{ + nmtools_tuple{1., 2., 3.}, + nmtools_tuple{4., 5., 6.} }; auto str = to_string(arg); auto to_print = std::string("\n") + str; @@ -190,14 +190,14 @@ TEST_CASE("to_string(double[2][3])" * doctest::test_suite("utils") * doctest::sk TEST_CASE("to_string(tuple[3])" * doctest::test_suite("utils") * doctest::skip(true)) { { - auto arg = tuple{ - tuple{ - tuple{1., 2., 3.}, - tuple{4., 5., 6.}, + auto arg = nmtools_tuple{ + nmtools_tuple{ + nmtools_tuple{1., 2., 3.}, + nmtools_tuple{4., 5., 6.}, }, - tuple{ - tuple{ 7., 8., 9.}, - tuple{10., 11., 12.}, + nmtools_tuple{ + nmtools_tuple{ 7., 8., 9.}, + nmtools_tuple{10., 11., 12.}, } }; auto str = to_string(arg); diff --git a/tests/functional/CMakeLists.txt b/tests/functional/CMakeLists.txt index c74b28fe2..6fb5ecea1 100644 --- a/tests/functional/CMakeLists.txt +++ b/tests/functional/CMakeLists.txt @@ -71,7 +71,8 @@ if (NMTOOLS_FUNCTIONAL_TEST_ALL) src/ufuncs/arctan2.cpp src/ufuncs/cbrt.cpp src/ufuncs/ceil.cpp - src/ufuncs/clip.cpp + # TODO: this compiles forever, fix + # src/ufuncs/clip.cpp src/ufuncs/cos.cpp src/ufuncs/cosh.cpp src/ufuncs/exp.cpp @@ -138,17 +139,18 @@ if (NMTOOLS_FUNCTIONAL_TEST_ALL) src/graph/transpose.cpp src/graph/reshape.cpp + src/graph/batch_norm.cpp src/graph/broadcast_to.cpp src/graph/tanh.cpp src/graph/multiply.cpp src/graph/reduce_add_tanh.cpp src/graph/multiply_tanh.cpp src/graph/multiply_add_tanh.cpp - src/graph/multiply_add_tanh_add.cpp - src/graph/reduce_add_divide.cpp + src/graph/mean.cpp src/graph/var.cpp src/graph/stddev.cpp src/graph/softmax.cpp + src/graph/softmin.cpp src/misc/ct_map.cpp src/misc/ct_digraph.cpp diff --git a/tests/functional/src/graph/batch_norm.cpp b/tests/functional/src/graph/batch_norm.cpp new file mode 100644 index 000000000..fb23fcaaf --- /dev/null +++ b/tests/functional/src/graph/batch_norm.cpp @@ -0,0 +1,245 @@ +#include "nmtools/array/array/arange.hpp" +#include "nmtools/array/array/reshape.hpp" +#include "nmtools/array/array/random.hpp" +#include "nmtools/array/array/moveaxis.hpp" +#include "nmtools/array/array/atleast_nd.hpp" +#include "nmtools/array/random_engine.hpp" +#include "nmtools/array/view/batch_norm.hpp" +#include "nmtools/array/functional/batch_norm.hpp" +#include "nmtools/utility/has_value.hpp" +#include "nmtools/testing/doctest.hpp" + +namespace nm = nmtools; +namespace na = nmtools::array; +namespace ix = nmtools::index; +namespace fn = nmtools::functional; +namespace meta = nmtools::meta; +namespace view = nmtools::view; +namespace utils = nmtools::utils; + +using namespace nmtools::literals; +using nm::unwrap; + +TEST_CASE("batch_norm" * doctest::test_suite("functional::get_compute_graph")) +{ + auto input_shape = nmtools_array{1,2,5,5}; + auto mean_shape = nmtools_array{2}; + auto var_shape = nmtools_array{2}; + auto weight_shape = nmtools_array{2}; + auto bias_shape = nmtools_array{2}; + + auto input = na::reshape(na::arange(ix::product(input_shape)),input_shape); + auto mean = na::reshape(na::arange(ix::product(mean_shape)),mean_shape); + auto var = na::reshape(na::arange(ix::product(var_shape)),var_shape); + auto weight = na::reshape(na::arange(ix::product(weight_shape)),weight_shape); + auto bias = na::reshape(na::arange(ix::product(bias_shape)),bias_shape); + + // TODO: support maybe type for batch_norm + auto batch_norm = view::batch_norm(unwrap(input),unwrap(mean),unwrap(var),unwrap(weight),unwrap(bias)); + CHECK( nm::has_value(batch_norm) ); + auto graph = fn::get_compute_graph(unwrap(batch_norm)); + + CHECK_MESSAGE( true, utils::to_string(graph,utils::Graphviz) ); +} + +TEST_CASE("batch_norm(test1)" * doctest::test_suite("functional::get_compute_graph")) +{ + auto input_shape = nmtools_array{1,2,5,5}; + auto mean_shape = nmtools_array{2}; + auto var_shape = nmtools_array{2}; + auto weight_shape = nmtools_array{2}; + auto bias_shape = nmtools_array{2}; + + auto input = na::reshape(na::arange(ix::product(input_shape)),input_shape); + auto mean = na::reshape(na::arange(ix::product(mean_shape)),mean_shape); + auto var = na::reshape(na::arange(ix::product(var_shape)),var_shape); + auto weight = na::reshape(na::arange(ix::product(weight_shape)),weight_shape); + auto bias = na::reshape(na::arange(ix::product(bias_shape)),bias_shape); + + auto src_axis = meta::ct_v<-1>; + auto dst_axis = meta::ct_v<-3>; + + auto aliased = view::aliased(input,mean,var,weight,bias); + [[maybe_unused]] auto a_input = nmtools::get<0>(aliased); + [[maybe_unused]] auto a_mean = nmtools::get<1>(aliased); + [[maybe_unused]] auto a_var = nmtools::get<2>(aliased); + [[maybe_unused]] auto a_weight = nmtools::get<3>(aliased); + [[maybe_unused]] auto a_bias = nmtools::get<4>(aliased); + + auto a = view::atleast_nd(a_weight,3_ct); + auto b = view::moveaxis(a,src_axis,dst_axis); + auto graph = fn::get_compute_graph(unwrap(b)); + + CHECK_MESSAGE( true, utils::to_string(graph,utils::Graphviz) ); +} + +TEST_CASE("batch_norm(test2)" * doctest::test_suite("functional::get_compute_graph")) +{ + auto input_shape = nmtools_array{1,2,5,5}; + auto mean_shape = nmtools_array{2}; + auto var_shape = nmtools_array{2}; + auto weight_shape = nmtools_array{2}; + auto bias_shape = nmtools_array{2}; + + auto input = na::reshape(na::arange(ix::product(input_shape)),input_shape); + auto mean = na::reshape(na::arange(ix::product(mean_shape)),mean_shape); + auto var = na::reshape(na::arange(ix::product(var_shape)),var_shape); + auto weight = na::reshape(na::arange(ix::product(weight_shape)),weight_shape); + auto bias = na::reshape(na::arange(ix::product(bias_shape)),bias_shape); + + auto src_axis = meta::ct_v<-1>; + auto dst_axis = meta::ct_v<-3>; + + auto aliased = view::aliased(input,mean,var,weight,bias); + [[maybe_unused]] auto a_input = nmtools::get<0>(aliased); + [[maybe_unused]] auto a_mean = nmtools::get<1>(aliased); + [[maybe_unused]] auto a_var = nmtools::get<2>(aliased); + [[maybe_unused]] auto a_weight = nmtools::get<3>(aliased); + [[maybe_unused]] auto a_bias = nmtools::get<4>(aliased); + + { + auto a = na::atleast_nd(a_mean,3_ct); + auto aliased = view::aliased(a,a_input); + auto a_a = nmtools::get<0>(aliased); + auto input = nmtools::get<1>(aliased); + auto b = view::moveaxis(a_a,src_axis,dst_axis); + auto c = view::subtract(input,b); + auto graph = fn::get_compute_graph(unwrap(c)); + + CHECK_MESSAGE( true, utils::to_string(graph,utils::Graphviz) ); + } + // TODO: fix, a has the same id as a_input + #if 0 + { + auto a = na::atleast_nd(a_mean,3_ct); + auto b = view::moveaxis(a,src_axis,dst_axis); + auto c = view::subtract(a_input,b); + auto graph = fn::get_compute_graph(unwrap(c)); + + CHECK_MESSAGE( true, utils::to_string(graph,utils::Graphviz) ); + } + #endif +} + +TEST_CASE("batch_norm(test3)" * doctest::test_suite("functional::get_compute_graph")) +{ + auto input_shape = nmtools_array{1,2,5,5}; + auto mean_shape = nmtools_array{2}; + auto var_shape = nmtools_array{2}; + auto weight_shape = nmtools_array{2}; + auto bias_shape = nmtools_array{2}; + + auto input = na::reshape(na::arange(ix::product(input_shape)),input_shape); + auto mean = na::reshape(na::arange(ix::product(mean_shape)),mean_shape); + auto var = na::reshape(na::arange(ix::product(var_shape)),var_shape); + auto weight = na::reshape(na::arange(ix::product(weight_shape)),weight_shape); + auto bias = na::reshape(na::arange(ix::product(bias_shape)),bias_shape); + + auto src_axis = meta::ct_v<-1>; + auto dst_axis = meta::ct_v<-3>; + + auto aliased = view::aliased(input,mean,var,weight,bias); + [[maybe_unused]] auto a_input = nmtools::get<0>(aliased); + [[maybe_unused]] auto a_mean = nmtools::get<1>(aliased); + [[maybe_unused]] auto a_var = nmtools::get<2>(aliased); + [[maybe_unused]] auto a_weight = nmtools::get<3>(aliased); + [[maybe_unused]] auto a_bias = nmtools::get<4>(aliased); + + auto a = view::atleast_nd(a_mean,3_ct); + auto b = view::moveaxis(a,src_axis,dst_axis); + auto c = view::subtract(a_input,b); + auto graph = fn::get_compute_graph(unwrap(c)); + + CHECK_MESSAGE( true, utils::to_string(graph,utils::Graphviz) ); +} + +TEST_CASE("batch_norm(test4)" * doctest::test_suite("functional::get_compute_graph")) +{ + auto input_shape = nmtools_array{1,2,5,5}; + auto mean_shape = nmtools_array{2}; + auto var_shape = nmtools_array{2}; + auto weight_shape = nmtools_array{2}; + auto bias_shape = nmtools_array{2}; + + auto input = na::reshape(na::arange(ix::product(input_shape)),input_shape); + auto mean = na::reshape(na::arange(ix::product(mean_shape)),mean_shape); + auto var = na::reshape(na::arange(ix::product(var_shape)),var_shape); + auto weight = na::reshape(na::arange(ix::product(weight_shape)),weight_shape); + auto bias = na::reshape(na::arange(ix::product(bias_shape)),bias_shape); + + auto aliased = view::aliased(input,mean,var,weight,bias); + [[maybe_unused]] auto a_input = nmtools::get<0>(aliased); + [[maybe_unused]] auto a_mean = nmtools::get<1>(aliased); + [[maybe_unused]] auto a_var = nmtools::get<2>(aliased); + [[maybe_unused]] auto a_weight = nmtools::get<3>(aliased); + [[maybe_unused]] auto a_bias = nmtools::get<4>(aliased); + + auto eps = 0.001f; + + auto src_axis = meta::ct_v<-1>; + auto dst_axis = meta::ct_v<-3>; + + auto a = view::atleast_nd(a_mean,3_ct); + auto b = view::moveaxis(a,src_axis,dst_axis); + auto c = view::subtract(a_input,b); + // var + auto d = view::atleast_nd(a_var,3_ct); + auto e = view::moveaxis(d,src_axis,dst_axis); + // stddev + auto f = view::add(e,eps); + auto g = view::sqrt(f); + // divided + auto h = view::divide(c,g); + + auto graph = fn::get_compute_graph(unwrap(h)); + CHECK_MESSAGE( true, utils::to_string(graph,utils::Graphviz) ); +} + +TEST_CASE("batch_norm(test5)" * doctest::test_suite("functional::get_compute_graph")) +{ + auto input_shape = nmtools_array{1,2,5,5}; + auto mean_shape = nmtools_array{2}; + auto var_shape = nmtools_array{2}; + auto weight_shape = nmtools_array{2}; + auto bias_shape = nmtools_array{2}; + + auto input = na::reshape(na::arange(ix::product(input_shape)),input_shape); + auto mean = na::reshape(na::arange(ix::product(mean_shape)),mean_shape); + auto var = na::reshape(na::arange(ix::product(var_shape)),var_shape); + auto weight = na::reshape(na::arange(ix::product(weight_shape)),weight_shape); + auto bias = na::reshape(na::arange(ix::product(bias_shape)),bias_shape); + + auto aliased = view::aliased(input,mean,var,weight,bias); + [[maybe_unused]] auto a_input = nmtools::get<0>(aliased); + [[maybe_unused]] auto a_mean = nmtools::get<1>(aliased); + [[maybe_unused]] auto a_var = nmtools::get<2>(aliased); + [[maybe_unused]] auto a_weight = nmtools::get<3>(aliased); + [[maybe_unused]] auto a_bias = nmtools::get<4>(aliased); + + auto eps = 0.001f; + + auto src_axis = meta::ct_v<-1>; + auto dst_axis = meta::ct_v<-3>; + + // mean + auto a = view::atleast_nd(a_mean,3_ct); + auto b = view::moveaxis(a,src_axis,dst_axis); + // subtracted + auto c = view::subtract(a_input,b); + // var + auto d = view::atleast_nd(a_var,3_ct); + auto e = view::moveaxis(d,src_axis,dst_axis); + // weight + auto f = view::atleast_nd(a_weight,3_ct); + auto g = view::moveaxis(f,src_axis,dst_axis); + // stddev + auto h = view::add(e,eps); + auto i = view::sqrt(h); + // divided + auto j = view::divide(c,i); + // multiplied + auto k = view::multiply(j,g); + + auto graph = fn::get_compute_graph(unwrap(k)); + CHECK_MESSAGE( true, utils::to_string(graph,utils::Graphviz) ); +} \ No newline at end of file diff --git a/tests/functional/src/graph/broadcast_to.cpp b/tests/functional/src/graph/broadcast_to.cpp index 96621d689..201b6e8d1 100644 --- a/tests/functional/src/graph/broadcast_to.cpp +++ b/tests/functional/src/graph/broadcast_to.cpp @@ -13,6 +13,16 @@ namespace meta = nm::meta; namespace view = nm::view; using namespace nmtools::literals; +using nmtools::unwrap; + +#define get_node_id(a) \ +[&](){ \ + using array_type = decltype(unwrap(a)); \ + using view_type = typename array_type::view_type; \ + constexpr auto view_vtype = meta::as_value_v; \ + constexpr auto node_id = meta::generate_view_id(array_type::operands_ids,view_vtype); \ + return node_id; \ +}() namespace utils = nmtools::utils; @@ -23,14 +33,16 @@ TEST_CASE("broadcast_to" * doctest::test_suite("functional::get_compute_graph") auto a = view::broadcast_to(lhs_array,lhs_shape); + auto a_id = get_node_id(a); + [[maybe_unused]] auto graph = nm::unwrap(fn::get_compute_graph(a)); [[maybe_unused]] auto expect = fn::compute_graph_t<>() .add_node(0_ct,&lhs_array) - .add_node(1_ct,fn::node_t{fn::broadcast_to[lhs_shape],nmtools_tuple{0_ct}}) - .add_edge(0_ct,1_ct) + .add_node(a_id,fn::node_t{fn::broadcast_to[lhs_shape],nmtools_tuple{0_ct}}) + .add_edge(0_ct,a_id) ; // TODO: support comparison of maybe graph @@ -44,14 +56,16 @@ TEST_CASE("broadcast_to" * doctest::test_suite("functional::get_compute_graph")) auto a = view::broadcast_to(lhs_array,lhs_shape); + auto a_id = get_node_id(a); + [[maybe_unused]] auto graph = nm::unwrap(fn::get_compute_graph(a)); [[maybe_unused]] auto expect = fn::compute_graph_t<>() .add_node(0_ct,&lhs_array) - .add_node(1_ct,fn::node_t{fn::indexing[nm::unwrap(a).attributes()],nmtools_tuple{0_ct}}) - .add_edge(0_ct,1_ct) + .add_node(a_id,fn::node_t{fn::indexing[nm::unwrap(a).attributes()],nmtools_tuple{0_ct}}) + .add_edge(0_ct,a_id) ; // TODO: support comparison of maybe graph diff --git a/tests/functional/src/graph/mean.cpp b/tests/functional/src/graph/mean.cpp new file mode 100644 index 000000000..eabeb5406 --- /dev/null +++ b/tests/functional/src/graph/mean.cpp @@ -0,0 +1,84 @@ +#include "nmtools/array/array/ufuncs/multiply.hpp" +#include "nmtools/array/array/ufuncs/divide.hpp" +#include "nmtools/array/array/ufuncs/add.hpp" +#include "nmtools/array/array/arange.hpp" +#include "nmtools/array/functional/functor.hpp" +#include "nmtools/array/functional/ufuncs/multiply.hpp" +#include "nmtools/array/functional/ufuncs/add.hpp" +#include "nmtools/array/functional/ufuncs/divide.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" +#include "nmtools/array/functional/mean.hpp" +#include "nmtools/array/array/mean.hpp" +#include "nmtools/array/array/reshape.hpp" +#include "nmtools/testing/doctest.hpp" +#include "nmtools/testing/data/array/arange.hpp" +#include "nmtools/utility/has_value.hpp" + +namespace nm = nmtools; +namespace na = nmtools::array; +namespace ix = nmtools::index; +namespace fn = nmtools::functional; +namespace meta = nm::meta; +namespace view = nm::view; +namespace utils = nm::utils; + +using namespace nmtools::literals; +using nmtools::unwrap; + +#define get_node_id(a) \ +[&](){ \ + using array_type = decltype(unwrap(a)); \ + using view_type = typename array_type::view_type; \ + constexpr auto view_vtype = meta::as_value_v; \ + constexpr auto node_id = meta::generate_view_id(array_type::operands_ids,view_vtype); \ + return node_id; \ +}() + +TEST_CASE("mean(test1)" * doctest::test_suite("functional::get_compute_graph")) +{ + auto lhs_shape = nmtools_array{3,4}; + auto lhs_buffer = na::arange(12); + auto lhs_array = na::reshape(lhs_buffer,lhs_shape); + + auto divisor = 3; + + auto axis = 0; + auto a = nm::unwrap(view::reduce_add(lhs_array,axis)); + auto b = view::divide(a,divisor); + + auto a_id = get_node_id(a); + auto b_id = get_node_id(b); + + // TODO: use the same function as decorator to get the operand ids + auto divisor_id = meta::ct_v; + + auto graph = nm::unwrap(fn::get_compute_graph(b)); + + auto expect = fn::compute_graph_t<>() + .add_node(0_ct,&lhs_array) + .add_node(a_id,fn::node_t{fn::reduce_add[a.axis][nm::None][a.initial][a.keepdims],nmtools_tuple{0_ct}}) + .add_node(divisor_id,divisor) + .add_node(b_id,fn::node_t{fn::divide,nmtools_tuple{a_id,divisor_id}}) + .add_edge(0_ct,a_id) + .add_edge(a_id,b_id) + .add_edge(divisor_id,b_id) + ; + + // CHECK_MESSAGE( true, utils::to_string(graph, utils::Graphviz) ); + NMTOOLS_ASSERT_GRAPH_EQUAL( graph, expect ); +} + +TEST_CASE("mean" * doctest::test_suite("functional::get_compute_graph")) +{ + auto lhs_shape = nmtools_array{3,4}; + auto lhs_buffer = na::arange(12); + auto lhs_array = na::reshape(lhs_buffer,lhs_shape); + + auto axis = 0_ct; + auto a = view::mean(lhs_array,axis); + + auto graph = fn::get_compute_graph(a); + + // TODO: support maybe type for to_string for graph + CHECK_MESSAGE( nm::has_value(a), utils::to_string(unwrap(graph),utils::Graphviz) ); +} \ No newline at end of file diff --git a/tests/functional/src/graph/multiply.cpp b/tests/functional/src/graph/multiply.cpp index 233d954a7..b0fec6410 100644 --- a/tests/functional/src/graph/multiply.cpp +++ b/tests/functional/src/graph/multiply.cpp @@ -17,6 +17,16 @@ namespace meta = nm::meta; namespace view = nm::view; using namespace nmtools::literals; +using nmtools::unwrap; + +#define get_node_id(a) \ +[&](){ \ + using array_type = decltype(unwrap(a)); \ + using view_type = typename array_type::view_type; \ + constexpr auto view_vtype = meta::as_value_v; \ + constexpr auto node_id = meta::generate_view_id(array_type::operands_ids,view_vtype); \ + return node_id; \ +}() namespace utils = nmtools::utils; @@ -34,14 +44,16 @@ TEST_CASE("multiply" * doctest::test_suite("functional::get_compute_graph")) auto a = view::multiply(lhs_array,rhs_array); + auto node_id = get_node_id(a); + auto graph = unwrap(fn::get_compute_graph(a)); auto expect = fn::compute_graph_t<>() .add_node(0_ct,&lhs_array) .add_node(1_ct,&rhs_array) - .add_node(2_ct,fn::node_t{fn::multiply,nmtools_tuple{0_ct,1_ct}}) - .add_edge(0_ct,2_ct) - .add_edge(1_ct,2_ct) + .add_node(node_id,fn::node_t{fn::multiply,nmtools_tuple{0_ct,1_ct}}) + .add_edge(0_ct,node_id) + .add_edge(1_ct,node_id) ; // TODO: support comparison on maybe type @@ -61,14 +73,16 @@ TEST_CASE("multiply" * doctest::test_suite("functional::get_compute_graph")) auto lhs = view::alias(lhs_array,3_ct); auto a = view::multiply(lhs,rhs_array); + auto node_id = get_node_id(a); + auto graph = unwrap(fn::get_compute_graph(a)); auto expect = fn::compute_graph_t<>() .add_node(3_ct,&lhs_array) - .add_node(1_ct,&rhs_array) - .add_node(5_ct,fn::node_t{fn::multiply,nmtools_tuple{3_ct,1_ct}}) - .add_edge(3_ct,5_ct) - .add_edge(1_ct,5_ct) + .add_node(5_ct,&rhs_array) + .add_node(node_id,fn::node_t{fn::multiply,nmtools_tuple{3_ct,5_ct}}) + .add_edge(3_ct,node_id) + .add_edge(5_ct,node_id) ; // TODO: support comparison on maybe type @@ -88,14 +102,16 @@ TEST_CASE("multiply" * doctest::test_suite("functional::get_compute_graph")) auto rhs = view::alias(rhs_array,3_ct); auto a = view::multiply(lhs_array,rhs); + auto node_id = get_node_id(a); + auto graph = unwrap(fn::get_compute_graph(a)); auto expect = fn::compute_graph_t<>() - .add_node(0_ct,&lhs_array) + .add_node(4_ct,&lhs_array) .add_node(3_ct,&rhs_array) - .add_node(5_ct,fn::node_t{fn::multiply,nmtools_tuple{0_ct,3_ct}}) - .add_edge(0_ct,5_ct) - .add_edge(3_ct,5_ct) + .add_node(node_id,fn::node_t{fn::multiply,nmtools_tuple{4_ct,3_ct}}) + .add_edge(4_ct,node_id) + .add_edge(3_ct,node_id) ; // TODO: support comparison on maybe type @@ -116,14 +132,16 @@ TEST_CASE("multiply" * doctest::test_suite("functional::get_compute_graph")) auto lhs = view::alias(lhs_array,4_ct); auto a = view::multiply(lhs,rhs); + auto node_id = get_node_id(a); + auto graph = unwrap(fn::get_compute_graph(a)); auto expect = fn::compute_graph_t<>() .add_node(4_ct,&lhs_array) .add_node(3_ct,&rhs_array) - .add_node(6_ct,fn::node_t{fn::multiply,nmtools_tuple{4_ct,3_ct}}) - .add_edge(4_ct,6_ct) - .add_edge(3_ct,6_ct) + .add_node(node_id,fn::node_t{fn::multiply,nmtools_tuple{4_ct,3_ct}}) + .add_edge(4_ct,node_id) + .add_edge(3_ct,node_id) ; // TODO: support comparison on maybe type diff --git a/tests/functional/src/graph/multiply_add_tanh.cpp b/tests/functional/src/graph/multiply_add_tanh.cpp index 57aabbc77..08de7e9cc 100644 --- a/tests/functional/src/graph/multiply_add_tanh.cpp +++ b/tests/functional/src/graph/multiply_add_tanh.cpp @@ -19,6 +19,16 @@ namespace view = nm::view; namespace utils = nm::utils; using namespace nmtools::literals; +using nmtools::unwrap; + +#define get_node_id(a) \ +[&](){ \ + using array_type = decltype(unwrap(a)); \ + using view_type = typename array_type::view_type; \ + constexpr auto view_vtype = meta::as_value_v; \ + constexpr auto node_id = meta::generate_view_id(array_type::operands_ids,view_vtype); \ + return node_id; \ +}() TEST_CASE("multiply_add_tanh" * doctest::test_suite("functional::get_compute_graph")) { @@ -34,20 +44,27 @@ TEST_CASE("multiply_add_tanh" * doctest::test_suite("functional::get_compute_gra auto b = view::add(a,rhs_array); auto c = view::tanh(b); + auto a_id = get_node_id(a); + auto b_id = get_node_id(b); + auto c_id = get_node_id(c); + + // TODO: use the same function as decorator to get the operand ids + auto rhs_id = meta::ct_v; + auto graph = nm::unwrap(fn::get_compute_graph(c)); auto expect = fn::compute_graph_t<>() .add_node(0_ct,&lhs_array) .add_node(1_ct,&rhs_array) - .add_node(2_ct,fn::node_t{fn::multiply,nmtools_tuple{0_ct,1_ct}}) - .add_node(3_ct,&rhs_array) - .add_node(4_ct,fn::node_t{fn::add,nmtools_tuple{2_ct,3_ct}}) - .add_node(5_ct,fn::node_t{fn::tanh,nmtools_tuple{4_ct}}) - .add_edge(0_ct,2_ct) - .add_edge(1_ct,2_ct) - .add_edge(2_ct,4_ct) - .add_edge(3_ct,4_ct) - .add_edge(4_ct,5_ct) + .add_node(a_id,fn::node_t{fn::multiply,nmtools_tuple{0_ct,1_ct}}) + .add_node(rhs_id,&rhs_array) + .add_node(b_id,fn::node_t{fn::add,nmtools_tuple{a_id,rhs_id}}) + .add_node(c_id,fn::node_t{fn::tanh,nmtools_tuple{b_id}}) + .add_edge(0_ct,a_id) + .add_edge(1_ct,a_id) + .add_edge(a_id,b_id) + .add_edge(rhs_id,b_id) + .add_edge(b_id,c_id) ; // TODO: support comparison on maybe type @@ -69,19 +86,23 @@ TEST_CASE("multiply_add_tanh" * doctest::test_suite("functional::get_compute_gra auto b = view::add(a,rhs); auto c = view::tanh(b); + auto a_id = get_node_id(a); + auto b_id = get_node_id(b); + auto c_id = get_node_id(c); + auto graph = nm::unwrap(fn::get_compute_graph(c)); auto expect = fn::compute_graph_t<>() - .add_node(0_ct,&lhs_array) + .add_node(2_ct,&lhs_array) .add_node(1_ct,&rhs_array) - .add_node(3_ct,fn::node_t{fn::multiply,nmtools_tuple{0_ct,1_ct}}) - .add_node(5_ct,fn::node_t{fn::add,nmtools_tuple{2_ct,1_ct}}) - .add_node(6_ct,fn::node_t{fn::tanh,nmtools_tuple{5_ct}}) - .add_edge(0_ct,3_ct) - .add_edge(1_ct,3_ct) - .add_edge(1_ct,5_ct) - .add_edge(3_ct,5_ct) - .add_edge(5_ct,6_ct) + .add_node(a_id,fn::node_t{fn::multiply,nmtools_tuple{2_ct,1_ct}}) + .add_node(b_id,fn::node_t{fn::add,nmtools_tuple{a_id,1_ct}}) + .add_node(c_id,fn::node_t{fn::tanh,nmtools_tuple{b_id}}) + .add_edge(2_ct,a_id) + .add_edge(1_ct,a_id) + .add_edge(1_ct,b_id) + .add_edge(a_id,b_id) + .add_edge(b_id,c_id) ; // TODO: support comparison on maybe type @@ -104,19 +125,23 @@ TEST_CASE("multiply_add_tanh" * doctest::test_suite("functional::get_compute_gra auto b = view::add(a,rhs); auto c = view::tanh(b); + auto a_id = get_node_id(a); + auto b_id = get_node_id(b); + auto c_id = get_node_id(c); + auto graph = nm::unwrap(fn::get_compute_graph(c)); auto expect = fn::compute_graph_t<>() .add_node(0_ct,&lhs_array) .add_node(1_ct,&rhs_array) - .add_node(3_ct,fn::node_t{fn::multiply,nmtools_tuple{0_ct,1_ct}}) - .add_node(5_ct,fn::node_t{fn::add,nmtools_tuple{2_ct,1_ct}}) - .add_node(6_ct,fn::node_t{fn::tanh,nmtools_tuple{5_ct}}) - .add_edge(0_ct,3_ct) - .add_edge(1_ct,3_ct) - .add_edge(1_ct,5_ct) - .add_edge(3_ct,5_ct) - .add_edge(5_ct,6_ct) + .add_node(a_id,fn::node_t{fn::multiply,nmtools_tuple{0_ct,1_ct}}) + .add_node(b_id,fn::node_t{fn::add,nmtools_tuple{2_ct,1_ct}}) + .add_node(c_id,fn::node_t{fn::tanh,nmtools_tuple{5_ct}}) + .add_edge(0_ct,a_id) + .add_edge(1_ct,a_id) + .add_edge(1_ct,b_id) + .add_edge(a_id,b_id) + .add_edge(b_id,c_id) ; // TODO: support comparison on maybe type @@ -139,20 +164,24 @@ TEST_CASE("multiply_add_tanh" * doctest::test_suite("functional::get_compute_gra auto b = view::add(a,rhs); auto c = view::tanh(b); + auto a_id = get_node_id(a); + auto b_id = get_node_id(b); + auto c_id = get_node_id(c); + auto graph = nm::unwrap(fn::get_compute_graph(c)); [[maybe_unused]] auto expect = fn::compute_graph_t<>() .add_node(3_ct,&lhs_array) .add_node(1_ct,&rhs_array) - .add_node(5_ct,fn::node_t{fn::multiply,nmtools_tuple{3_ct,1_ct}}) - .add_node(7_ct,fn::node_t{fn::add,nmtools_tuple{2_ct,1_ct}}) - .add_node(8_ct,fn::node_t{fn::tanh,nmtools_tuple{7_ct}}) - .add_edge(3_ct,5_ct) - .add_edge(1_ct,5_ct) - .add_edge(1_ct,7_ct) - .add_edge(5_ct,7_ct) - .add_edge(7_ct,8_ct) + .add_node(a_id,fn::node_t{fn::multiply,nmtools_tuple{3_ct,1_ct}}) + .add_node(b_id,fn::node_t{fn::add,nmtools_tuple{a_id,1_ct}}) + .add_node(c_id,fn::node_t{fn::tanh,nmtools_tuple{b_id}}) + .add_edge(3_ct,a_id) + .add_edge(1_ct,a_id) + .add_edge(1_ct,b_id) + .add_edge(a_id,b_id) + .add_edge(b_id,c_id) ; diff --git a/tests/functional/src/graph/multiply_add_tanh_add.cpp b/tests/functional/src/graph/multiply_add_tanh_add.cpp deleted file mode 100644 index bf9b3b9b7..000000000 --- a/tests/functional/src/graph/multiply_add_tanh_add.cpp +++ /dev/null @@ -1,430 +0,0 @@ -#include "nmtools/array/array/ufuncs/multiply.hpp" -#include "nmtools/array/array/ufuncs/tanh.hpp" -#include "nmtools/array/array/arange.hpp" -#include "nmtools/array/functional/functor.hpp" -#include "nmtools/array/functional/ufuncs/multiply.hpp" -#include "nmtools/array/functional/ufuncs/add.hpp" -#include "nmtools/array/functional/ufuncs/tanh.hpp" -#include "nmtools/array/functional/ufunc/ufunc.hpp" -#include "nmtools/array/array/reshape.hpp" -#include "nmtools/testing/doctest.hpp" -#include "nmtools/testing/data/array/arange.hpp" - -namespace nm = nmtools; -namespace na = nmtools::array; -namespace ix = nmtools::index; -namespace fn = nmtools::functional; -namespace meta = nm::meta; -namespace view = nm::view; -namespace utils = nmtools::utils; - -using namespace nmtools::literals; - -#if 0 -// NOTE: accidentally correct results? -TEST_CASE("multiply_add_tanh_add(case1)" * doctest::test_suite("functional::get_compute_graph")) -{ - auto lhs_shape = nmtools_array{3,4}; - auto lhs_buffer = na::arange(12); - auto lhs_array = na::reshape(lhs_buffer,lhs_shape); - - auto rhs_shape = nmtools_array{4}; - auto rhs_buffer = na::arange(4); - auto rhs_array = na::reshape(rhs_buffer,rhs_shape); - - auto bias_shape = nmtools_array{4}; - auto bias_buffer = na::arange(4); - auto bias_array = na::reshape(bias_buffer,bias_shape); - - auto a = view::multiply(lhs_array,rhs_array); - auto b = view::add(a,bias_array); - auto c = view::tanh(b); - auto d = view::add(lhs_array,c); - - auto graph = nm::unwrap(fn::get_compute_graph(d)); - - CHECK_MESSAGE( true, utils::to_string(graph,utils::Graphviz) ); -} - -TEST_CASE("multiply_add_tanh_add(case2)" * doctest::test_suite("functional::get_compute_graph")) -{ - auto lhs_shape = nmtools_array{3,4}; - auto lhs_buffer = na::arange(12); - auto lhs_array = na::reshape(lhs_buffer,lhs_shape); - - auto rhs_shape = nmtools_array{4}; - auto rhs_buffer = na::arange(4); - auto rhs_array = na::reshape(rhs_buffer,rhs_shape); - - auto bias_shape = nmtools_array{4}; - auto bias_buffer = na::arange(4); - auto bias_array = na::reshape(bias_buffer,bias_shape); - - auto lhs = view::alias(lhs_array,2_ct); - - auto a = view::multiply(lhs,rhs_array); - auto b = view::add(a,bias_array); - auto c = view::tanh(b); - auto d = view::add(lhs,c); - - auto graph = nm::unwrap(fn::get_compute_graph(d)); - - CHECK_MESSAGE( true, utils::to_string(graph,utils::Graphviz) ); -} - -// NOTE: the following is an example of composition that we can't capture correctly for now -TEST_CASE("multiply_add_tanh_add(case3)" * doctest::test_suite("functional::get_compute_graph") * doctest::may_fail()) -{ - auto lhs_shape = nmtools_array{3,4}; - auto lhs_buffer = na::arange(12); - auto lhs_array = na::reshape(lhs_buffer,lhs_shape); - - auto rhs_shape = nmtools_array{4}; - auto rhs_buffer = na::arange(4); - auto rhs_array = na::reshape(rhs_buffer,rhs_shape); - - auto bias_shape = nmtools_array{4}; - auto bias_buffer = na::arange(4); - auto bias_array = na::reshape(bias_buffer,bias_shape); - - auto rhs = view::alias(lhs_array,3_ct); - - auto a = view::multiply(lhs_array,rhs); - auto b = view::add(a,bias_array); - auto c = view::tanh(b); - auto d = view::add(lhs_array,c); - - auto graph = nm::unwrap(fn::get_compute_graph(d)); - - CHECK_MESSAGE( false, utils::to_string(graph,utils::Graphviz) ); -} - -// NOTE: accidental success? -TEST_CASE("multiply_add_tanh_add(case4)" * doctest::test_suite("functional::get_compute_graph")) -{ - auto lhs_shape = nmtools_array{3,4}; - auto lhs_buffer = na::arange(12); - auto lhs_array = na::reshape(lhs_buffer,lhs_shape); - - auto rhs_shape = nmtools_array{4}; - auto rhs_buffer = na::arange(4); - auto rhs_array = na::reshape(rhs_buffer,rhs_shape); - - auto bias_shape = nmtools_array{4}; - auto bias_buffer = na::arange(4); - auto bias_array = na::reshape(bias_buffer,bias_shape); - - auto bias = view::alias(bias_array,4_ct); - - auto a = view::multiply(lhs_array,rhs_array); - auto b = view::add(a,bias); - auto c = view::tanh(b); - auto d = view::add(lhs_array,c); - - auto graph = nm::unwrap(fn::get_compute_graph(d)); - - CHECK_MESSAGE( true, utils::to_string(graph,utils::Graphviz) ); -} - -TEST_CASE("multiply_add_tanh_add(case5)" * doctest::test_suite("functional::get_compute_graph")) -{ - auto lhs_shape = nmtools_array{3,4}; - auto lhs_buffer = na::arange(12); - auto lhs_array = na::reshape(lhs_buffer,lhs_shape); - - auto rhs_shape = nmtools_array{4}; - auto rhs_buffer = na::arange(4); - auto rhs_array = na::reshape(rhs_buffer,rhs_shape); - - auto bias_shape = nmtools_array{4}; - auto bias_buffer = na::arange(4); - auto bias_array = na::reshape(bias_buffer,bias_shape); - - auto lhs = view::alias(lhs_array,0_ct); - auto rhs = view::alias(rhs_array,1_ct); - auto bias = view::alias(bias_array,2_ct); - - auto a = view::multiply(lhs,rhs); - auto b = view::add(a,bias); - auto c = view::tanh(b); - auto d = view::add(lhs,c); - - auto graph = nm::unwrap(fn::get_compute_graph(d)); - - [[maybe_unused]] - auto expect = fn::compute_graph_t<>() - .add_node(0_ct,&lhs_array) - .add_node(1_ct,&rhs_array) - .add_node(2_ct,&bias_array) - .add_node(3_ct,fn::node_t{fn::multiply,nmtools_tuple{0_ct,1_ct}}) - .add_node(5_ct,fn::node_t{fn::add,nmtools_tuple{3_ct,2_ct}}) - .add_node(6_ct,fn::node_t{fn::tanh,nmtools_tuple{5_ct}}) - .add_node(8_ct,fn::node_t{fn::add,nmtools_tuple{6_ct,0_ct}}) - .add_edge(0_ct,3_ct) - .add_edge(0_ct,8_ct) - .add_edge(1_ct,3_ct) - .add_edge(2_ct,5_ct) - .add_edge(3_ct,5_ct) - .add_edge(5_ct,6_ct) - .add_edge(6_ct,8_ct) - ; - - // CHECK_MESSAGE( true, utils::to_string(graph,utils::Graphviz) ); - // TODO: support comparison on maybe type - NMTOOLS_ASSERT_GRAPH_EQUAL( nm::unwrap(graph), expect ); -} - -// NOTE: error maybe because fn::multiply as id 3, but bias also id 3 -// TODO: better error message / handling -#if 0 -TEST_CASE("multiply_add_tanh_add(case6)" * doctest::test_suite("functional::get_compute_graph")) -{ - auto lhs_shape = nmtools_array{3,4}; - auto lhs_buffer = na::arange(12); - auto lhs_array = na::reshape(lhs_buffer,lhs_shape); - - auto rhs_shape = nmtools_array{4}; - auto rhs_buffer = na::arange(4); - auto rhs_array = na::reshape(rhs_buffer,rhs_shape); - - auto bias_shape = nmtools_array{4}; - auto bias_buffer = na::arange(4); - auto bias_array = na::reshape(bias_buffer,bias_shape); - - auto lhs = view::alias(lhs_array,0_ct); - auto rhs = view::alias(rhs_array,1_ct); - auto bias = view::alias(bias_array,3_ct); - - auto a = view::multiply(lhs,rhs); - auto b = view::add(a,bias); - auto c = view::tanh(b); - auto d = view::add(lhs,c); - - auto graph = nm::unwrap(fn::get_compute_graph(d)); - - CHECK_MESSAGE( true, utils::to_string(graph,utils::Graphviz) ); -} -#endif - -TEST_CASE("multiply_add_tanh_add(case7)" * doctest::test_suite("functional::get_compute_graph")) -{ - auto lhs_shape = nmtools_array{3,4}; - auto lhs_buffer = na::arange(12); - auto lhs_array = na::reshape(lhs_buffer,lhs_shape); - - auto rhs_shape = nmtools_array{4}; - auto rhs_buffer = na::arange(4); - auto rhs_array = na::reshape(rhs_buffer,rhs_shape); - - auto bias_shape = nmtools_array{4}; - auto bias_buffer = na::arange(4); - auto bias_array = na::reshape(bias_buffer,bias_shape); - - auto lhs = view::alias(lhs_array,0_ct); - auto rhs = view::alias(rhs_array,1_ct); - auto bias = view::alias(bias_array,4_ct); - - auto a = view::multiply(lhs,rhs); - auto b = view::add(a,bias); - auto c = view::tanh(b); - auto d = view::add(lhs,c); - - auto graph = nm::unwrap(fn::get_compute_graph(d)); - - [[maybe_unused]] - auto expect = fn::compute_graph_t<>() - .add_node(0_ct,&lhs_array) - .add_node(1_ct,&rhs_array) - .add_node(4_ct,&bias_array) - .add_node(3_ct,fn::node_t{fn::multiply,nmtools_tuple{0_ct,1_ct}}) - .add_node(6_ct,fn::node_t{fn::add,nmtools_tuple{3_ct,4_ct}}) - .add_node(7_ct,fn::node_t{fn::tanh,nmtools_tuple{6_ct}}) - .add_node(9_ct,fn::node_t{fn::add,nmtools_tuple{7_ct,0_ct}}) - .add_edge(0_ct,3_ct) - .add_edge(0_ct,9_ct) - .add_edge(1_ct,3_ct) - .add_edge(4_ct,6_ct) - .add_edge(3_ct,6_ct) - .add_edge(6_ct,7_ct) - .add_edge(7_ct,9_ct) - ; - - // CHECK_MESSAGE( true, utils::to_string(graph,utils::Graphviz) ); - // TODO: support comparison on maybe type - NMTOOLS_ASSERT_GRAPH_EQUAL( nm::unwrap(graph), expect ); -} - -TEST_CASE("multiply_add_tanh_add(case8)" * doctest::test_suite("functional::get_compute_graph")) -{ - auto lhs_shape = nmtools_array{3,4}; - auto lhs_buffer = na::arange(12); - auto lhs_array = na::reshape(lhs_buffer,lhs_shape); - - auto rhs_shape = nmtools_array{4}; - auto rhs_buffer = na::arange(4); - auto rhs_array = na::reshape(rhs_buffer,rhs_shape); - - auto bias_shape = nmtools_array{4}; - auto bias_buffer = na::arange(4); - auto bias_array = na::reshape(bias_buffer,bias_shape); - - auto lhs = view::alias(lhs_array,0_ct); - auto rhs = view::alias(rhs_array,1_ct); - auto bias = view::alias(bias_array,5_ct); - - auto a = view::multiply(lhs,rhs); - auto b = view::add(a,bias); - auto c = view::tanh(b); - auto d = view::add(lhs,c); - - auto graph = nm::unwrap(fn::get_compute_graph(d)); - - [[maybe_unused]] - auto expect = fn::compute_graph_t<>() - .add_node(0_ct,&lhs_array) - .add_node(1_ct,&rhs_array) - .add_node(5_ct,&bias_array) - .add_node(3_ct,fn::node_t{fn::multiply,nmtools_tuple{0_ct,1_ct}}) - .add_node(7_ct,fn::node_t{fn::add,nmtools_tuple{3_ct,5_ct}}) - .add_node(8_ct,fn::node_t{fn::tanh,nmtools_tuple{7_ct}}) - .add_node(10_ct,fn::node_t{fn::add,nmtools_tuple{8_ct,0_ct}}) - .add_edge(0_ct,3_ct) - .add_edge(0_ct,10_ct) - .add_edge(1_ct,3_ct) - .add_edge(5_ct,7_ct) - .add_edge(3_ct,7_ct) - .add_edge(7_ct,8_ct) - .add_edge(8_ct,10_ct) - ; - - // CHECK_MESSAGE( true, utils::to_string(graph,utils::Graphviz) ); - // TODO: support comparison on maybe type - NMTOOLS_ASSERT_GRAPH_EQUAL( nm::unwrap(graph), expect ); -} - - -// NOTE: maybe accidentally correct? -TEST_CASE("multiply_add_tanh_add(case9)" * doctest::test_suite("functional::get_compute_graph")) -{ - auto lhs_shape = nmtools_array{3,4}; - auto lhs_buffer = na::arange(12); - auto lhs_array = na::reshape(lhs_buffer,lhs_shape); - - auto rhs_shape = nmtools_array{4}; - auto rhs_buffer = na::arange(4); - auto rhs_array = na::reshape(rhs_buffer,rhs_shape); - - auto bias_shape = nmtools_array{4}; - auto bias_buffer = na::arange(4); - auto bias_array = na::reshape(bias_buffer,bias_shape); - - auto lhs = view::alias(lhs_array,1_ct); - auto rhs = view::alias(rhs_array,2_ct); - auto bias = view::alias(bias_array,3_ct); - - auto a = view::multiply(lhs,rhs); - auto b = view::add(a,bias); - auto c = view::tanh(b); - auto d = view::add(lhs,c); - - auto graph = nm::unwrap(fn::get_compute_graph(d)); - - CHECK_MESSAGE( true, utils::to_string(graph,utils::Graphviz) ); -} - -TEST_CASE("multiply_add_tanh_add(case10)" * doctest::test_suite("functional::get_compute_graph")) -{ - auto lhs_shape = nmtools_array{3,4}; - auto lhs_buffer = na::arange(12); - auto lhs_array = na::reshape(lhs_buffer,lhs_shape); - - auto rhs_shape = nmtools_array{4}; - auto rhs_buffer = na::arange(4); - auto rhs_array = na::reshape(rhs_buffer,rhs_shape); - - auto bias_shape = nmtools_array{4}; - auto bias_buffer = na::arange(4); - auto bias_array = na::reshape(bias_buffer,bias_shape); - - auto lhs = view::alias(lhs_array,2_ct); - auto rhs = view::alias(rhs_array,3_ct); - auto bias = view::alias(bias_array,4_ct); - - auto a = view::multiply(lhs,rhs); - auto b = view::add(a,bias); - auto c = view::tanh(b); - auto d = view::add(lhs,c); - - auto graph = nm::unwrap(fn::get_compute_graph(d)); - - [[maybe_unused]] - auto expect = fn::compute_graph_t<>() - .add_node(2_ct,&lhs_array) - .add_node(3_ct,&rhs_array) - .add_node(4_ct,&bias_array) - .add_node(5_ct,fn::node_t{fn::multiply,nmtools_tuple{2_ct,3_ct}}) - .add_node(7_ct,fn::node_t{fn::add,nmtools_tuple{5_ct,4_ct}}) - .add_node(8_ct,fn::node_t{fn::tanh,nmtools_tuple{7_ct}}) - .add_node(10_ct,fn::node_t{fn::add,nmtools_tuple{8_ct,0_ct}}) - .add_edge(2_ct,5_ct) - .add_edge(2_ct,10_ct) - .add_edge(3_ct,5_ct) - .add_edge(4_ct,7_ct) - .add_edge(5_ct,7_ct) - .add_edge(7_ct,8_ct) - .add_edge(8_ct,10_ct) - ; - - // CHECK_MESSAGE( true, utils::to_string(graph,utils::Graphviz) ); - // TODO: support comparison on maybe type - NMTOOLS_ASSERT_GRAPH_EQUAL( nm::unwrap(graph), expect ); -} - -TEST_CASE("multiply_add_tanh_add(case11)" * doctest::test_suite("functional::get_compute_graph")) -{ - auto lhs_shape = nmtools_array{3,4}; - auto lhs_buffer = na::arange(12); - auto lhs_array = na::reshape(lhs_buffer,lhs_shape); - - auto rhs_shape = nmtools_array{4}; - auto rhs_buffer = na::arange(4); - auto rhs_array = na::reshape(rhs_buffer,rhs_shape); - - auto bias_shape = nmtools_array{4}; - auto bias_buffer = na::arange(4); - auto bias_array = na::reshape(bias_buffer,bias_shape); - - auto lhs = view::alias(lhs_array,3_ct); - auto rhs = view::alias(rhs_array,4_ct); - auto bias = view::alias(bias_array,5_ct); - - auto a = view::multiply(lhs,rhs); - auto b = view::add(a,bias); - auto c = view::tanh(b); - auto d = view::add(lhs,c); - - auto graph = nm::unwrap(fn::get_compute_graph(d)); - - [[maybe_unused]] - auto expect = fn::compute_graph_t<>() - .add_node(3_ct,&lhs_array) - .add_node(4_ct,&rhs_array) - .add_node(5_ct,&bias_array) - .add_node(6_ct,fn::node_t{fn::multiply,nmtools_tuple{3_ct,4_ct}}) - .add_node(8_ct,fn::node_t{fn::add,nmtools_tuple{6_ct,5_ct}}) - .add_node(9_ct,fn::node_t{fn::tanh,nmtools_tuple{8_ct}}) - .add_node(11_ct,fn::node_t{fn::add,nmtools_tuple{9_ct,0_ct}}) - .add_edge(3_ct,6_ct) - .add_edge(3_ct,11_ct) - .add_edge(4_ct,6_ct) - .add_edge(5_ct,8_ct) - .add_edge(6_ct,8_ct) - .add_edge(8_ct,9_ct) - .add_edge(9_ct,11_ct) - ; - - // CHECK_MESSAGE( true, utils::to_string(graph,utils::Graphviz) ); - // TODO: support comparison on maybe type - NMTOOLS_ASSERT_GRAPH_EQUAL( nm::unwrap(graph), expect ); -} -#endif \ No newline at end of file diff --git a/tests/functional/src/graph/multiply_tanh.cpp b/tests/functional/src/graph/multiply_tanh.cpp index 5a8b79a21..15a243370 100644 --- a/tests/functional/src/graph/multiply_tanh.cpp +++ b/tests/functional/src/graph/multiply_tanh.cpp @@ -18,6 +18,16 @@ namespace view = nm::view; namespace utils = nmtools::utils; using namespace nmtools::literals; +using nmtools::unwrap; + +#define get_node_id(a) \ +[&](){ \ + using array_type = decltype(unwrap(a)); \ + using view_type = typename array_type::view_type; \ + constexpr auto view_vtype = meta::as_value_v; \ + constexpr auto node_id = meta::generate_view_id(array_type::operands_ids,view_vtype); \ + return node_id; \ +}() TEST_CASE("multiply_tanh" * doctest::test_suite("functional::get_compute_graph")) { @@ -32,16 +42,19 @@ TEST_CASE("multiply_tanh" * doctest::test_suite("functional::get_compute_graph") auto a = view::multiply(lhs_array,rhs_array); auto b = view::tanh(a); + auto a_id = get_node_id(a); + auto b_id = get_node_id(b); + auto graph = nm::unwrap(fn::get_compute_graph(b)); auto expect = fn::compute_graph_t<>() .add_node(0_ct,&lhs_array) .add_node(1_ct,&rhs_array) - .add_node(2_ct,fn::node_t{fn::multiply,nmtools_tuple{0_ct,1_ct}}) - .add_node(3_ct,fn::node_t{fn::tanh,nmtools_tuple{2_ct}}) - .add_edge(0_ct,2_ct) - .add_edge(1_ct,2_ct) - .add_edge(2_ct,3_ct) + .add_node(a_id,fn::node_t{fn::multiply,nmtools_tuple{0_ct,1_ct}}) + .add_node(b_id,fn::node_t{fn::tanh,nmtools_tuple{a_id}}) + .add_edge(0_ct,a_id) + .add_edge(1_ct,a_id) + .add_edge(a_id,b_id) ; // TODO: support comparison on maybe type @@ -62,16 +75,19 @@ TEST_CASE("multiply_tanh" * doctest::test_suite("functional::get_compute_graph") auto a = view::multiply(lhs,rhs_array); auto b = view::tanh(a); + auto a_id = get_node_id(a); + auto b_id = get_node_id(b); + auto graph = nm::unwrap(fn::get_compute_graph(b)); auto expect = fn::compute_graph_t<>() .add_node(10_ct,&lhs_array) - .add_node(1_ct,&rhs_array) - .add_node(12_ct,fn::node_t{fn::multiply,nmtools_tuple{10_ct,1_ct}}) - .add_node(13_ct,fn::node_t{fn::tanh,nmtools_tuple{12_ct}}) - .add_edge(10_ct,12_ct) - .add_edge(1_ct,12_ct) - .add_edge(12_ct,13_ct) + .add_node(12_ct,&rhs_array) + .add_node(a_id,fn::node_t{fn::multiply,nmtools_tuple{10_ct,11_ct}}) + .add_node(b_id,fn::node_t{fn::tanh,nmtools_tuple{a_id}}) + .add_edge(10_ct,a_id) + .add_edge(12_ct,a_id) + .add_edge(a_id,b_id) ; // TODO: support comparison on maybe type @@ -92,16 +108,19 @@ TEST_CASE("multiply_tanh" * doctest::test_suite("functional::get_compute_graph") auto a = view::multiply(lhs_array,rhs); auto b = view::tanh(a); + auto a_id = get_node_id(a); + auto b_id = get_node_id(b); + auto graph = nm::unwrap(fn::get_compute_graph(b)); auto expect = fn::compute_graph_t<>() - .add_node(0_ct,&lhs_array) + .add_node(11_ct,&lhs_array) .add_node(10_ct,&rhs_array) - .add_node(12_ct,fn::node_t{fn::multiply,nmtools_tuple{0_ct,10_ct}}) - .add_node(13_ct,fn::node_t{fn::tanh,nmtools_tuple{12_ct}}) - .add_edge(10_ct,12_ct) - .add_edge(0_ct,12_ct) - .add_edge(12_ct,13_ct) + .add_node(a_id,fn::node_t{fn::multiply,nmtools_tuple{11_ct,10_ct}}) + .add_node(b_id,fn::node_t{fn::tanh,nmtools_tuple{a_id}}) + .add_edge(10_ct,a_id) + .add_edge(11_ct,a_id) + .add_edge(a_id,b_id) ; // TODO: support comparison on maybe type @@ -123,16 +142,19 @@ TEST_CASE("multiply_tanh" * doctest::test_suite("functional::get_compute_graph") auto a = view::multiply(lhs,rhs); auto b = view::tanh(a); + auto a_id = get_node_id(a); + auto b_id = get_node_id(b); + auto graph = nm::unwrap(fn::get_compute_graph(b)); auto expect = fn::compute_graph_t<>() .add_node(10_ct,&lhs_array) .add_node(5_ct,&rhs_array) - .add_node(12_ct,fn::node_t{fn::multiply,nmtools_tuple{10_ct,5_ct}}) - .add_node(13_ct,fn::node_t{fn::tanh,nmtools_tuple{12_ct}}) - .add_edge(10_ct,12_ct) - .add_edge(5_ct,12_ct) - .add_edge(12_ct,13_ct) + .add_node(a_id,fn::node_t{fn::multiply,nmtools_tuple{10_ct,5_ct}}) + .add_node(b_id,fn::node_t{fn::tanh,nmtools_tuple{a_id}}) + .add_edge(10_ct,a_id) + .add_edge(5_ct,a_id) + .add_edge(a_id,b_id) ; // TODO: support comparison on maybe type diff --git a/tests/functional/src/graph/reduce_add_divide.cpp b/tests/functional/src/graph/reduce_add_divide.cpp deleted file mode 100644 index 93308d05d..000000000 --- a/tests/functional/src/graph/reduce_add_divide.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "nmtools/array/array/ufuncs/multiply.hpp" -#include "nmtools/array/array/ufuncs/divide.hpp" -#include "nmtools/array/array/ufuncs/add.hpp" -#include "nmtools/array/array/arange.hpp" -#include "nmtools/array/functional/functor.hpp" -#include "nmtools/array/functional/ufuncs/multiply.hpp" -#include "nmtools/array/functional/ufuncs/add.hpp" -#include "nmtools/array/functional/ufuncs/divide.hpp" -#include "nmtools/array/functional/ufunc/ufunc.hpp" -#include "nmtools/array/array/reshape.hpp" -#include "nmtools/testing/doctest.hpp" -#include "nmtools/testing/data/array/arange.hpp" - -namespace nm = nmtools; -namespace na = nmtools::array; -namespace ix = nmtools::index; -namespace fn = nmtools::functional; -namespace meta = nm::meta; -namespace view = nm::view; -namespace utils = nm::utils; - -using namespace nmtools::literals; - -TEST_CASE("reduce_add_divide" * doctest::test_suite("functional::get_compute_graph")) -{ - auto lhs_shape = nmtools_array{3,4}; - auto lhs_buffer = na::arange(12); - auto lhs_array = na::reshape(lhs_buffer,lhs_shape); - - auto divisor = 3; - - auto axis = 0; - auto a = nm::unwrap(view::reduce_add(lhs_array,axis)); - auto b = view::divide(a,divisor); - - auto graph = nm::unwrap(fn::get_compute_graph(b)); - - auto expect = fn::compute_graph_t<>() - .add_node(0_ct,&lhs_array) - .add_node(1_ct,fn::node_t{fn::reduce_add[a.axis][nm::None][a.initial][a.keepdims],nmtools_tuple{0_ct}}) - .add_node(2_ct,divisor) - .add_node(3_ct,fn::node_t{fn::divide,nmtools_tuple{1_ct,2_ct}}) - .add_edge(0_ct,1_ct) - .add_edge(1_ct,3_ct) - .add_edge(2_ct,2_ct) - ; - - // CHECK_MESSAGE( true, utils::to_string(graph, utils::Graphviz) ); - NMTOOLS_ASSERT_GRAPH_EQUAL( graph, expect ); -} \ No newline at end of file diff --git a/tests/functional/src/graph/reduce_add_tanh.cpp b/tests/functional/src/graph/reduce_add_tanh.cpp index beb7c9756..99243743f 100644 --- a/tests/functional/src/graph/reduce_add_tanh.cpp +++ b/tests/functional/src/graph/reduce_add_tanh.cpp @@ -18,6 +18,16 @@ namespace meta = nm::meta; namespace view = nm::view; using namespace nmtools::literals; +using nmtools::unwrap; + +#define get_node_id(a) \ +[&](){ \ + using array_type = decltype(unwrap(a)); \ + using view_type = typename array_type::view_type; \ + constexpr auto view_vtype = meta::as_value_v; \ + constexpr auto node_id = meta::generate_view_id(array_type::operands_ids,view_vtype); \ + return node_id; \ +}() #if 1 namespace utils = nmtools::utils; @@ -32,27 +42,30 @@ TEST_CASE("reduce_add_tanh" * doctest::test_suite("functional::get_compute_graph auto a = view::reduce_add(lhs_array,axis); auto b = view::tanh(a); + auto a_id = get_node_id(a); + auto b_id = get_node_id(b); + auto graph = nm::unwrap(fn::get_compute_graph(b)); auto operands = nm::unwrap(fn::get_operands(b)); const auto& operand = nmtools::get<0>(operands); using operand_t = meta::remove_cvref_pointer_t; static_assert( meta::is_view_v ); - static_assert( decltype(nm::unwrap(a))::id_type{} == 1 ); - static_assert( decltype(nm::unwrap(b))::id_type{} == 2 ); + // static_assert( decltype(nm::unwrap(a))::id_type{} == 1 ); + // static_assert( decltype(nm::unwrap(b))::id_type{} == 2 ); static_assert( decltype(nm::unwrap(a))::arity == 1 ); static_assert( decltype(nm::unwrap(b))::arity == 1 ); static_assert( nm::len(decltype(nm::unwrap(b))::operands_ids) == 1 ); - static_assert( nm::at(decltype(nm::unwrap(b))::operands_ids,0) == 1 ); + // static_assert( nm::at(decltype(nm::unwrap(b))::operands_ids,0) == 1 ); auto expect = fn::compute_graph_t<>() .add_node(0_ct,&lhs_array) - .add_node(1_ct,fn::node_t{ + .add_node(a_id,fn::node_t{ fn::reduce_add[nm::unwrap(a).axis][nm::None][nm::unwrap(a).initial][nm::unwrap(a).keepdims] , nmtools_tuple{0_ct}}) - .add_node(2_ct,fn::node_t{fn::tanh,nmtools_tuple{1_ct}}) - .add_edge(0_ct,1_ct) - .add_edge(1_ct,2_ct) + .add_node(b_id,fn::node_t{fn::tanh,nmtools_tuple{a_id}}) + .add_edge(0_ct,a_id) + .add_edge(a_id,b_id) ; // TODO: handle comparison of maybe type @@ -70,16 +83,19 @@ TEST_CASE("reduce_add_tanh" * doctest::test_suite("functional::get_compute_graph auto a = view::reduce_add(array,axis); auto b = view::tanh(a); + auto a_id = get_node_id(a); + auto b_id = get_node_id(b); + auto graph = nm::unwrap(fn::get_compute_graph(b)); auto expect = fn::compute_graph_t<>() .add_node(9_ct,&lhs_array) - .add_node(10_ct,fn::node_t{ + .add_node(a_id,fn::node_t{ fn::reduce_add[nm::unwrap(a).axis][nm::None][nm::unwrap(a).initial][nm::unwrap(a).keepdims] , nmtools_tuple{9_ct}}) - .add_node(11_ct,fn::node_t{fn::tanh,nmtools_tuple{10_ct}}) - .add_edge(9_ct,10_ct) - .add_edge(10_ct,11_ct) + .add_node(b_id,fn::node_t{fn::tanh,nmtools_tuple{a_id}}) + .add_edge(9_ct,a_id) + .add_edge(a_id,b_id) ; // TODO: handle comparison of maybe type diff --git a/tests/functional/src/graph/reshape.cpp b/tests/functional/src/graph/reshape.cpp index 230d368af..894644567 100644 --- a/tests/functional/src/graph/reshape.cpp +++ b/tests/functional/src/graph/reshape.cpp @@ -13,6 +13,16 @@ namespace meta = nm::meta; namespace view = nm::view; using namespace nmtools::literals; +using nmtools::unwrap; + +#define get_node_id(a) \ +[&](){ \ + using array_type = decltype(unwrap(a)); \ + using view_type = typename array_type::view_type; \ + constexpr auto view_vtype = meta::as_value_v; \ + constexpr auto node_id = meta::generate_view_id(array_type::operands_ids,view_vtype); \ + return node_id; \ +}() namespace utils = nmtools::utils; @@ -23,14 +33,16 @@ TEST_CASE("reshape" * doctest::test_suite("functional::get_compute_graph")) auto a = view::reshape(lhs_array,lhs_shape); + auto a_id = get_node_id(a); + [[maybe_unused]] auto graph = nm::unwrap(fn::get_compute_graph(a)); [[maybe_unused]] auto expect = fn::compute_graph_t<>() .add_node(0_ct,&lhs_array) - .add_node(1_ct,fn::node_t{fn::reshape,nmtools_tuple{0_ct}}) - .add_edge(0_ct,1_ct) + .add_node(a_id,fn::node_t{fn::reshape,nmtools_tuple{0_ct}}) + .add_edge(0_ct,a_id) ; // TODO: support comparison of maybe graph diff --git a/tests/functional/src/graph/softmax.cpp b/tests/functional/src/graph/softmax.cpp index 453c9b0c5..dfbd91057 100644 --- a/tests/functional/src/graph/softmax.cpp +++ b/tests/functional/src/graph/softmax.cpp @@ -1,16 +1,8 @@ #include "nmtools/array/array/arange.hpp" #include "nmtools/array/array/reshape.hpp" -#include "nmtools/array/array/ufuncs/maximum.hpp" -#include "nmtools/array/array/ufuncs/subtract.hpp" -#include "nmtools/array/array/ufuncs/exp.hpp" -#include "nmtools/array/array/ufuncs/add.hpp" -#include "nmtools/array/array/ufuncs/divide.hpp" -#include "nmtools/array/functional/ufuncs/maximum.hpp" -#include "nmtools/array/functional/ufuncs/subtract.hpp" -#include "nmtools/array/functional/ufuncs/exp.hpp" -#include "nmtools/array/functional/ufuncs/add.hpp" -#include "nmtools/array/functional/ufuncs/divide.hpp" #include "nmtools/array/functional/ufunc/ufunc.hpp" +#include "nmtools/array/functional/activations/relu.hpp" +#include "nmtools/array/functional/softmax.hpp" #include "nmtools/testing/doctest.hpp" namespace nm = nmtools; @@ -22,8 +14,18 @@ namespace view = nm::view; namespace utils = nm::utils; using namespace nm::literals; +using nmtools::unwrap, nmtools::None, nmtools::True; -TEST_CASE("softmax" * doctest::test_suite("functional::get_compute_graph")) +#define get_node_id(a) \ +[&](){ \ + using array_type = decltype(unwrap(a)); \ + using view_type = typename array_type::view_type; \ + constexpr auto view_vtype = meta::as_value_v; \ + constexpr auto node_id = meta::generate_view_id(array_type::operands_ids,view_vtype); \ + return node_id; \ +}() + +TEST_CASE("softmax(test1)" * doctest::test_suite("functional::get_compute_graph")) { auto lhs_shape = nmtools_array{3,4}; auto lhs_buffer = na::arange(12); @@ -33,30 +35,83 @@ TEST_CASE("softmax" * doctest::test_suite("functional::get_compute_graph")) auto lhs = view::alias(lhs_array,0_ct); - auto a = nm::unwrap(view::reduce_maximum(lhs,axis)); + auto a = nm::unwrap(view::reduce_maximum(lhs,axis,None,None,True)); auto b = view::subtract(a,lhs); auto c = view::exp(b); - auto d = nm::unwrap(view::reduce_add(c,axis)); - auto e = view::divide(d,c); + auto d = nm::unwrap(view::reduce_add(c,axis,None,None,True)); + auto e = view::divide(c,d); auto graph = nm::unwrap(fn::get_compute_graph(e)); + auto a_id = get_node_id(a); + auto b_id = get_node_id(b); + auto c_id = get_node_id(c); + auto d_id = get_node_id(d); + auto e_id = get_node_id(e); + auto expect = fn::compute_graph_t<>() - .add_node(0_ct,&lhs_array) - .add_node(1_ct,fn::node_t{fn::reduce_maximum[a.axis][nm::None][a.initial][a.keepdims],nmtools_tuple{0_ct}}) - .add_node(3_ct,fn::node_t{fn::subtract,nmtools_tuple{1_ct,0_ct}}) - .add_node(4_ct,fn::node_t{fn::exp,nmtools_tuple{3_ct}}) - .add_node(5_ct,fn::node_t{fn::reduce_add[d.axis][nm::None][d.initial][d.keepdims],nmtools_tuple{4_ct}}) - .add_node(7_ct,fn::node_t{fn::divide,nmtools_tuple{5_ct,4_ct}}) - .add_edge(0_ct,1_ct) - .add_edge(0_ct,3_ct) - .add_edge(1_ct,3_ct) - .add_edge(3_ct,4_ct) - .add_edge(4_ct,5_ct) - .add_edge(4_ct,7_ct) - .add_edge(5_ct,7_ct) + .add_node(0_ct,&*lhs_array) + .add_node(a_id,fn::node_t{fn::reduce[unwrap(a).attributes()],nmtools_tuple{0_ct}}) + .add_node(b_id,fn::node_t{fn::broadcast_binary_ufunc[unwrap(b).attributes()],nmtools_tuple{a_id,0_ct}}) + .add_node(c_id,fn::node_t{fn::unary_ufunc[unwrap(c).attributes()],nmtools_tuple{b_id}}) + .add_node(d_id,fn::node_t{fn::reduce[unwrap(d).attributes()],nmtools_tuple{c_id}}) + .add_node(e_id,fn::node_t{fn::broadcast_binary_ufunc[unwrap(e).attributes()],nmtools_tuple{d_id,c_id}}) + .add_edge(0_ct,a_id) + .add_edge(0_ct,b_id) + .add_edge(a_id,b_id) + .add_edge(b_id,c_id) + .add_edge(c_id,d_id) + .add_edge(c_id,e_id) + .add_edge(d_id,e_id) ; // CHECK_MESSAGE( true, utils::to_string(graph,utils::Graphviz) ); NMTOOLS_ASSERT_GRAPH_EQUAL( graph, expect ); +} + +TEST_CASE("softmax" * doctest::test_suite("functional::get_compute_graph")) +{ + auto lhs_shape = nmtools_array{3,4}; + auto lhs_buffer = na::arange(12); + auto lhs_array = na::reshape(lhs_buffer,lhs_shape); + + auto axis = 0; + + // TODO: support maybe type for softmax + auto softmax = view::softmax(unwrap(lhs_array),axis); + auto graph = nm::unwrap(fn::get_compute_graph(softmax)); + + { + auto a_input = view::aliased(lhs_array); + auto a = view::reduce_maximum(a_input,axis,None,None,True); + auto b = view::subtract(a_input,a); + auto c = view::exp(b); + auto d = view::reduce_add(c,axis,None,None,True); + auto e = view::divide(c,d); + + auto a_id = get_node_id(a); + auto b_id = get_node_id(b); + auto c_id = get_node_id(c); + auto d_id = get_node_id(d); + auto e_id = get_node_id(e); + + auto expect = fn::compute_graph_t<>() + .add_node(0_ct,&*lhs_array) + .add_node(a_id,fn::node_t{fn::reduce[unwrap(a).attributes()],nmtools_tuple{0_ct}}) + .add_node(b_id,fn::node_t{fn::broadcast_binary_ufunc[unwrap(b).attributes()],nmtools_tuple{a_id,0_ct}}) + .add_node(c_id,fn::node_t{fn::unary_ufunc[unwrap(c).attributes()],nmtools_tuple{b_id}}) + .add_node(d_id,fn::node_t{fn::reduce[unwrap(d).attributes()],nmtools_tuple{c_id}}) + .add_node(e_id,fn::node_t{fn::broadcast_binary_ufunc[unwrap(e).attributes()],nmtools_tuple{d_id,c_id}}) + .add_edge(0_ct,a_id) + .add_edge(0_ct,b_id) + .add_edge(a_id,b_id) + .add_edge(b_id,c_id) + .add_edge(c_id,d_id) + .add_edge(c_id,e_id) + .add_edge(d_id,e_id) + ; + + // CHECK_MESSAGE( true, utils::to_string(graph,utils::Graphviz) ); + NMTOOLS_ASSERT_GRAPH_EQUAL( graph, expect ); + } } \ No newline at end of file diff --git a/tests/functional/src/graph/softmin.cpp b/tests/functional/src/graph/softmin.cpp new file mode 100644 index 000000000..a1642cc8d --- /dev/null +++ b/tests/functional/src/graph/softmin.cpp @@ -0,0 +1,240 @@ +#include "nmtools/array/array/arange.hpp" +#include "nmtools/array/array/reshape.hpp" +#include "nmtools/array/functional/ufunc/ufunc.hpp" +#include "nmtools/array/functional/softmin.hpp" +#include "nmtools/utility/has_value.hpp" +#include "nmtools/testing/doctest.hpp" + +namespace nm = nmtools; +namespace na = nmtools::array; +namespace fn = nmtools::functional; +namespace meta = nm::meta; +namespace view = nm::view; +namespace utils = nm::utils; + +using namespace nm::literals; +using nm::None, nm::True, nm::unwrap; + +#define get_node_id(a) \ +[&](){ \ + using array_type = decltype(unwrap(a)); \ + using view_type = typename array_type::view_type; \ + constexpr auto view_vtype = meta::as_value_v; \ + constexpr auto node_id = meta::generate_view_id(array_type::operands_ids,view_vtype); \ + return node_id; \ +}() + +TEST_CASE("softmin(test1)" * doctest::test_suite("functional::get_compute_graph")) +{ + auto lhs_shape = nmtools_array{3,4}; + auto lhs_buffer = na::arange(12); + auto lhs_array = unwrap(na::reshape(lhs_buffer,lhs_shape)); + + auto axis = 0; + + auto input = view::aliased(lhs_array); + + auto a = view::negative(input); + auto b = view::reduce_maximum(a,axis,None,None,True); + auto c = view::subtract(a,b); + + auto graph = fn::get_compute_graph(unwrap(c)); + + auto a_id = get_node_id(a); + auto b_id = get_node_id(b); + auto c_id = get_node_id(c); + + auto expect = fn::compute_graph_t<>() + .add_node(0_ct,&lhs_array) + .add_node(a_id,fn::node_t{fn::negative,nmtools_tuple{0_ct}}) + .add_node(b_id,fn::node_t{fn::reduce_maximum[unwrap(b).attributes()],nmtools_tuple{a_id}}) + .add_node(c_id,fn::node_t{fn::subtract,nmtools_tuple{a_id,b_id}}) + .add_edge(0_ct,a_id) + .add_edge(a_id,b_id) + .add_edge(0_ct,b_id) + .add_edge(b_id,c_id) + ; + + CHECK_MESSAGE( nm::has_value(graph), utils::to_string(graph,utils::Graphviz)); + NMTOOLS_ASSERT_GRAPH_EQUAL( graph, expect ); +} + +TEST_CASE("softmin(test2)" * doctest::test_suite("functional::get_compute_graph")) +{ + auto lhs_shape = nmtools_array{3,4}; + auto lhs_buffer = na::arange(12); + auto lhs_array = unwrap(na::reshape(lhs_buffer,lhs_shape)); + + auto axis = 0; + + auto input = view::aliased(lhs_array); + + auto a = view::negative(input); + auto b = view::reduce_maximum(a,axis,None,None,True); + auto c = view::subtract(a,b); + auto d = view::exp(c); + + auto graph = fn::get_compute_graph(unwrap(d)); + + auto a_id = get_node_id(a); + auto b_id = get_node_id(b); + auto c_id = get_node_id(c); + auto d_id = get_node_id(d); + + auto expect = fn::compute_graph_t<>() + .add_node(0_ct,&lhs_array) + .add_node(a_id,fn::node_t{fn::negative,nmtools_tuple{0_ct}}) + .add_node(b_id,fn::node_t{fn::reduce_maximum[unwrap(b).attributes()],nmtools_tuple{a_id}}) + .add_node(c_id,fn::node_t{fn::subtract,nmtools_tuple{a_id,b_id}}) + .add_node(d_id,fn::node_t{fn::exp,nmtools_tuple{c_id}}) + .add_edge(0_ct,a_id) + .add_edge(a_id,b_id) + .add_edge(0_ct,b_id) + .add_edge(b_id,c_id) + .add_edge(c_id,d_id) + ; + + CHECK_MESSAGE( nm::has_value(graph), utils::to_string(graph,utils::Graphviz)); + NMTOOLS_ASSERT_GRAPH_EQUAL( graph, expect ); +} + +TEST_CASE("softmin(test3)" * doctest::test_suite("functional::get_compute_graph")) +{ + auto lhs_shape = nmtools_array{3,4}; + auto lhs_buffer = na::arange(12); + auto lhs_array = unwrap(na::reshape(lhs_buffer,lhs_shape)); + + auto axis = 0; + + auto input = view::aliased(lhs_array); + + auto a = view::negative(input); + auto b = view::reduce_maximum(a,axis,None,None,True); + auto c = view::subtract(a,b); + auto d = view::exp(c); + auto e = view::reduce_add(d,axis,None,None,True); + + auto graph = fn::get_compute_graph(unwrap(e)); + + auto a_id = get_node_id(a); + auto b_id = get_node_id(b); + auto c_id = get_node_id(c); + auto d_id = get_node_id(d); + auto e_id = get_node_id(e); + + auto expect = fn::compute_graph_t<>() + .add_node(0_ct,&lhs_array) + .add_node(a_id,fn::node_t{fn::negative,nmtools_tuple{0_ct}}) + .add_node(b_id,fn::node_t{fn::reduce_maximum[unwrap(b).attributes()],nmtools_tuple{a_id}}) + .add_node(c_id,fn::node_t{fn::subtract,nmtools_tuple{a_id,b_id}}) + .add_node(d_id,fn::node_t{fn::exp,nmtools_tuple{c_id}}) + .add_node(e_id,fn::node_t{fn::reduce_add[unwrap(e).attributes()],nmtools_tuple{d_id}}) + .add_edge(0_ct,a_id) + .add_edge(a_id,b_id) + .add_edge(0_ct,b_id) + .add_edge(b_id,c_id) + .add_edge(c_id,d_id) + .add_edge(d_id,e_id) + ; + + CHECK_MESSAGE( nm::has_value(graph), utils::to_string(graph,utils::Graphviz)); + NMTOOLS_ASSERT_GRAPH_EQUAL( graph, expect ); +} + +TEST_CASE("softmin(test4)" * doctest::test_suite("functional::get_compute_graph")) +{ + auto lhs_shape = nmtools_array{3,4}; + auto lhs_buffer = na::arange(12); + auto lhs_array = unwrap(na::reshape(lhs_buffer,lhs_shape)); + + auto axis = 0; + + auto input = view::aliased(lhs_array); + + auto a = view::negative(input); + auto b = view::reduce_maximum(a,axis,None,None,True); + auto c = view::subtract(a,b); + auto d = view::exp(c); + auto e = view::reduce_add(d,axis,None,None,True); + auto f = view::divide(e,d); + + auto graph = fn::get_compute_graph(unwrap(f)); + + auto a_id = get_node_id(a); + auto b_id = get_node_id(b); + auto c_id = get_node_id(c); + auto d_id = get_node_id(d); + auto e_id = get_node_id(e); + auto f_id = get_node_id(f); + + auto expect = fn::compute_graph_t<>() + .add_node(0_ct,&lhs_array) + .add_node(a_id,fn::node_t{fn::negative,nmtools_tuple{0_ct}}) + .add_node(b_id,fn::node_t{fn::reduce_maximum[unwrap(b).attributes()],nmtools_tuple{a_id}}) + .add_node(c_id,fn::node_t{fn::subtract,nmtools_tuple{a_id,b_id}}) + .add_node(d_id,fn::node_t{fn::exp,nmtools_tuple{c_id}}) + .add_node(e_id,fn::node_t{fn::reduce_add[unwrap(e).attributes()],nmtools_tuple{d_id}}) + .add_node(f_id,fn::node_t{fn::divide,nmtools_tuple{e_id,d_id}}) + .add_edge(0_ct,a_id) + .add_edge(a_id,b_id) + .add_edge(0_ct,b_id) + .add_edge(b_id,c_id) + .add_edge(c_id,d_id) + .add_edge(d_id,e_id) + .add_edge(e_id,f_id) + .add_edge(d_id,f_id) + ; + + CHECK_MESSAGE( nm::has_value(graph), utils::to_string(graph,utils::Graphviz)); + NMTOOLS_ASSERT_GRAPH_EQUAL( graph, expect ); +} + +TEST_CASE("softmin" * doctest::test_suite("functional::get_compute_graph")) +{ + auto lhs_shape = nmtools_array{3,4}; + auto lhs_buffer = na::arange(12); + auto lhs_array = na::reshape(lhs_buffer,lhs_shape); + + auto axis = 0; + + auto softmax = view::softmin(lhs_array,axis); + auto graph = nm::unwrap(fn::get_compute_graph(softmax)); + + { + auto a = view::negative(lhs_array); + auto b = view::reduce_maximum(a,axis,None,None,True); + auto c = view::subtract(a,b); + auto d = view::exp(c); + auto e = view::reduce_add(d,axis,None,None,True); + auto f = view::divide(d,e); + + auto a_id = get_node_id(a); + auto b_id = get_node_id(b); + auto c_id = get_node_id(c); + auto d_id = get_node_id(d); + auto e_id = get_node_id(e); + auto f_id = get_node_id(f); + + // TODO: make unwrap retrun reference avoid &*lhs_array, use &unwrap(lhs_array) + auto expect = fn::compute_graph_t<>() + .add_node(0_ct,&*lhs_array) + .add_node(a_id,fn::node_t{fn::unary_ufunc[unwrap(a).attributes()],nmtools_tuple{0_ct}}) + .add_node(b_id,fn::node_t{fn::reduce[unwrap(b).attributes()],nmtools_tuple{a_id}}) + .add_node(c_id,fn::node_t{fn::broadcast_binary_ufunc[unwrap(c).attributes()],nmtools_tuple{a_id,b_id}}) + .add_node(d_id,fn::node_t{fn::unary_ufunc[unwrap(d).attributes()],nmtools_tuple{c_id}}) + .add_node(e_id,fn::node_t{fn::reduce[unwrap(e).attributes()],nmtools_tuple{d_id}}) + .add_node(f_id,fn::node_t{fn::broadcast_binary_ufunc[unwrap(f).attributes()],nmtools_tuple{e_id,d_id}}) + .add_edge(0_ct,a_id) + .add_edge(a_id,b_id) + .add_edge(b_id,c_id) + .add_edge(a_id,c_id) + .add_edge(c_id,d_id) + .add_edge(d_id,e_id) + .add_edge(e_id,f_id) + .add_edge(d_id,f_id) + ; + + // CHECK_MESSAGE( nm::has_value(graph), utils::to_string(graph,utils::Graphviz)); + NMTOOLS_ASSERT_GRAPH_EQUAL( graph, expect ); + } +} \ No newline at end of file diff --git a/tests/functional/src/graph/stddev.cpp b/tests/functional/src/graph/stddev.cpp index 7dd24826c..3af730ba9 100644 --- a/tests/functional/src/graph/stddev.cpp +++ b/tests/functional/src/graph/stddev.cpp @@ -16,6 +16,7 @@ #include "nmtools/array/functional/ufuncs/divide.hpp" #include "nmtools/array/functional/ufuncs/sqrt.hpp" #include "nmtools/array/functional/ufunc/ufunc.hpp" +#include "nmtools/array/view/stddev.hpp" #include "nmtools/array/array/reshape.hpp" #include "nmtools/testing/doctest.hpp" #include "nmtools/testing/data/array/arange.hpp" @@ -29,6 +30,7 @@ namespace view = nm::view; namespace utils = nm::utils; using namespace nmtools::literals; +using nmtools::unwrap; TEST_CASE("stddev" * doctest::test_suite("functional::get_compute_graph")) { @@ -38,46 +40,8 @@ TEST_CASE("stddev" * doctest::test_suite("functional::get_compute_graph")) auto axis = 0; - auto lhs = view::alias(lhs_array,0_ct); - auto divisor = view::alias(3,11_ct); - auto ddof = view::alias(2,12_ct); - - auto a = nm::unwrap(view::reduce_add(lhs,axis)); - auto b = view::divide(a,divisor); - auto c = view::subtract(b,lhs); - auto d = view::fabs(c); - auto e = view::square(d); - auto f = nm::unwrap(view::sum(e,axis)); - auto g = view::divide(f,ddof); - auto h = view::sqrt(g); - - auto graph = nm::unwrap(fn::get_compute_graph(h)); - - auto expect = fn::compute_graph_t<>() - .add_node(0_ct,&lhs_array) - .add_node(11_ct,3) - .add_node(12_ct,2) - .add_node(1_ct,fn::node_t{fn::reduce_add[a.axis][nm::None][a.initial][a.keepdims],nmtools_tuple{0_ct}}) - .add_node(13_ct,fn::node_t{fn::divide,nmtools_tuple{1_ct,11_ct}}) - .add_node(15_ct,fn::node_t{fn::subtract,nmtools_tuple{13_ct,0_ct}}) - .add_node(16_ct,fn::node_t{fn::fabs,nmtools_tuple{15_ct}}) - .add_node(17_ct,fn::node_t{fn::square,nmtools_tuple{16_ct}}) - .add_node(18_ct,fn::node_t{fn::reduce_add[f.axis][nm::None][f.initial][f.keepdims],nmtools_tuple{17_ct}}) - .add_node(20_ct,fn::node_t{fn::divide,nmtools_tuple{18_ct,12_ct}}) - .add_node(21_ct,fn::node_t{fn::sqrt,nmtools_tuple{21_ct}}) - .add_edge(0_ct,1_ct) - .add_edge(0_ct,15_ct) - .add_edge(1_ct,13_ct) - .add_edge(11_ct,13_ct) - .add_edge(13_ct,15_ct) - .add_edge(15_ct,16_ct) - .add_edge(16_ct,17_ct) - .add_edge(17_ct,18_ct) - .add_edge(18_ct,20_ct) - .add_edge(12_ct,20_ct) - .add_edge(20_ct,21_ct) - ; - - // CHECK_MESSAGE( true, utils::to_string(graph,utils::Graphviz) ); - NMTOOLS_ASSERT_GRAPH_EQUAL( graph, expect ); + // TODO: support maybe type for stddev + auto var = view::stddev(unwrap(lhs_array),axis); + auto graph = fn::get_compute_graph(unwrap(var)); + CHECK_MESSAGE( true, utils::to_string(graph,utils::Graphviz) ); } \ No newline at end of file diff --git a/tests/functional/src/graph/tanh.cpp b/tests/functional/src/graph/tanh.cpp index 72bd79776..a9d2f46b3 100644 --- a/tests/functional/src/graph/tanh.cpp +++ b/tests/functional/src/graph/tanh.cpp @@ -18,6 +18,16 @@ namespace view = nm::view; using namespace nmtools::literals; namespace utils = nmtools::utils; +using nmtools::unwrap; + +#define get_node_id(a) \ +[&](){ \ + using array_type = decltype(unwrap(a)); \ + using view_type = typename array_type::view_type; \ + constexpr auto view_vtype = meta::as_value_v; \ + constexpr auto node_id = meta::generate_view_id(array_type::operands_ids,view_vtype); \ + return node_id; \ +}() TEST_CASE("tanh" * doctest::test_suite("functional::get_compute_graph")) { @@ -26,6 +36,8 @@ TEST_CASE("tanh" * doctest::test_suite("functional::get_compute_graph")) auto lhs_array = na::reshape(lhs_buffer,lhs_shape); auto a = view::tanh(lhs_array); + + auto a_id = get_node_id(a); [[maybe_unused]] auto graph = nm::unwrap(fn::get_compute_graph(a)); @@ -33,8 +45,8 @@ TEST_CASE("tanh" * doctest::test_suite("functional::get_compute_graph")) [[maybe_unused]] auto expect = fn::compute_graph_t<>() .add_node(0_ct,&lhs_array) - .add_node(1_ct,fn::node_t{fn::tanh,nmtools_tuple{0_ct}}) - .add_edge(0_ct,1_ct) + .add_node(a_id,fn::node_t{fn::tanh,nmtools_tuple{0_ct}}) + .add_edge(0_ct,a_id) ; NMTOOLS_ASSERT_GRAPH_EQUAL( graph, expect ); @@ -50,14 +62,16 @@ TEST_CASE("tanh" * doctest::test_suite("functional::get_compute_graph")) auto array = view::alias(lhs_array,5_ct); auto a = view::tanh(array); + auto a_id = get_node_id(a); + [[maybe_unused]] auto graph = nm::unwrap(fn::get_compute_graph(a)); [[maybe_unused]] auto expect = fn::compute_graph_t<>() .add_node(5_ct,&lhs_array) - .add_node(6_ct,fn::node_t{fn::tanh,nmtools_tuple{5_ct}}) - .add_edge(5_ct,6_ct) + .add_node(a_id,fn::node_t{fn::tanh,nmtools_tuple{5_ct}}) + .add_edge(5_ct,a_id) ; auto operands = nm::unwrap(fn::get_operands(a)); diff --git a/tests/functional/src/graph/transpose.cpp b/tests/functional/src/graph/transpose.cpp index 43b424931..a1f6fd381 100644 --- a/tests/functional/src/graph/transpose.cpp +++ b/tests/functional/src/graph/transpose.cpp @@ -15,6 +15,18 @@ namespace view = nm::view; using namespace nmtools::literals; namespace utils = nmtools::utils; +using meta::ct_v; + +using nmtools::unwrap; + +#define get_node_id(a) \ +[&](){ \ + using array_type = decltype(unwrap(a)); \ + using view_type = typename array_type::view_type; \ + constexpr auto view_vtype = meta::as_value_v; \ + constexpr auto node_id = meta::generate_view_id(array_type::operands_ids,view_vtype); \ + return node_id; \ +}() TEST_CASE("transpose" * doctest::test_suite("functional::get_compute_graph")) { @@ -24,14 +36,16 @@ TEST_CASE("transpose" * doctest::test_suite("functional::get_compute_graph")) auto a = view::transpose(lhs_array); + auto a_id = get_node_id(a); + [[maybe_unused]] auto graph = nm::unwrap(fn::get_compute_graph(a)); [[maybe_unused]] auto expect = fn::compute_graph_t<>() .add_node(0_ct,&lhs_array) - .add_node(1_ct,fn::node_t{fn::transpose,nmtools_tuple{0_ct}}) - .add_edge(0_ct,1_ct) + .add_node(a_id,fn::node_t{fn::transpose,nmtools_tuple{0_ct}}) + .add_edge(0_ct,a_id) ; // TODO: support comparison of maybe graph diff --git a/tests/functional/src/graph/var.cpp b/tests/functional/src/graph/var.cpp index e09665e4f..aef3751b2 100644 --- a/tests/functional/src/graph/var.cpp +++ b/tests/functional/src/graph/var.cpp @@ -1,3 +1,6 @@ +// #define NMTOOLS_DEFAULT_TYPE_NAME_MAX_BUFFER_SIZE 4096 +// #define NMTOOLS_ALIAS_DEFAULT_PRIME 1033 + #include "nmtools/array/array/ufuncs/multiply.hpp" #include "nmtools/array/array/ufuncs/divide.hpp" #include "nmtools/array/array/ufuncs/subtract.hpp" @@ -14,6 +17,8 @@ #include "nmtools/array/functional/ufuncs/square.hpp" #include "nmtools/array/functional/ufuncs/divide.hpp" #include "nmtools/array/functional/ufunc/ufunc.hpp" +#include "nmtools/array/view/var.hpp" +#include "nmtools/utility/has_value.hpp" #include "nmtools/array/array/reshape.hpp" #include "nmtools/testing/doctest.hpp" #include "nmtools/testing/data/array/arange.hpp" @@ -27,8 +32,105 @@ namespace view = nm::view; namespace utils = nm::utils; using namespace nmtools::literals; +using nmtools::unwrap; -TEST_CASE("var" * doctest::test_suite("functional::get_compute_graph")) +#define get_node_id(a) \ +[&](){ \ + using array_type = decltype(unwrap(a)); \ + using view_type = typename array_type::view_type; \ + constexpr auto view_vtype = meta::as_value_v; \ + constexpr auto node_id = meta::generate_view_id(array_type::operands_ids,view_vtype); \ + return node_id; \ +}() + +TEST_CASE("var(test1)" * doctest::test_suite("functional::get_compute_graph")) +{ + auto lhs_shape = nmtools_array{3,4}; + auto lhs_buffer = na::arange(12); + auto lhs_array = na::reshape(lhs_buffer,lhs_shape); + + auto axis = 0; + + auto lhs = view::alias(lhs_array,0_ct); + auto divisor = view::alias(3,11_ct); + + auto a = view::reduce_add(lhs,axis); + auto b = view::divide(a,divisor); + auto c = view::subtract(b,lhs); + + auto a_id = get_node_id(a); + auto b_id = get_node_id(b); + auto c_id = get_node_id(c); + + auto graph = unwrap(fn::get_compute_graph(c)); + + // TODO: provide common function to get operands id + auto divisor_id = 11_ct; + + auto expect = fn::compute_graph_t<>() + .add_node(0_ct,&*lhs_array) + .add_node(a_id,fn::node_t{fn::reduce[unwrap(a).attributes()],nmtools_tuple{0_ct}}) + .add_node(divisor_id,divisor) + .add_node(b_id,fn::node_t{fn::broadcast_binary_ufunc[unwrap(b).attributes()],nmtools_tuple{a_id,divisor}}) + .add_node(c_id,fn::node_t{fn::broadcast_binary_ufunc[unwrap(c).attributes()],nmtools_tuple{b_id,0_ct}}) + .add_edge(0_ct,a_id) + .add_edge(a_id,b_id) + .add_edge(divisor_id,b_id) + .add_edge(b_id,c_id) + .add_edge(0_ct,c_id) + ; + + // CHECK_MESSAGE( true, utils::to_string(graph,utils::Graphviz) ); + NMTOOLS_ASSERT_GRAPH_EQUAL( graph, expect ); +} + +TEST_CASE("var(test2)" * doctest::test_suite("functional::get_compute_graph")) +{ + auto lhs_shape = nmtools_array{3,4}; + auto lhs_buffer = na::arange(12); + auto lhs_array = na::reshape(lhs_buffer,lhs_shape); + + auto axis = 0; + + auto lhs = view::alias(lhs_array,0_ct); + auto divisor = view::alias(3,11_ct); + + auto a = view::reduce_add(lhs,axis); + auto b = view::divide(a,divisor); + auto c = view::subtract(b,lhs); + auto d = view::fabs(c); + + auto a_id = get_node_id(a); + auto b_id = get_node_id(b); + auto c_id = get_node_id(c); + auto d_id = get_node_id(d); + + auto graph = unwrap(fn::get_compute_graph(d)); + + // TODO: provide common function to get operands id + auto divisor_id = 11_ct; + + auto expect = fn::compute_graph_t<>() + .add_node(0_ct,&*lhs_array) + .add_node(a_id,fn::node_t{fn::reduce[unwrap(a).attributes()],nmtools_tuple{0_ct}}) + .add_node(divisor_id,divisor) + .add_node(b_id,fn::node_t{fn::broadcast_binary_ufunc[unwrap(b).attributes()],nmtools_tuple{a_id,divisor}}) + .add_node(c_id,fn::node_t{fn::broadcast_binary_ufunc[unwrap(c).attributes()],nmtools_tuple{b_id,0_ct}}) + .add_node(d_id,fn::node_t{fn::unary_ufunc[unwrap(d).attributes()],nmtools_tuple{c_id}}) + .add_edge(0_ct,a_id) + .add_edge(a_id,b_id) + .add_edge(divisor_id,b_id) + .add_edge(b_id,c_id) + .add_edge(0_ct,c_id) + .add_edge(c_id,d_id) + ; + + // CHECK_MESSAGE( true, utils::to_string(graph,utils::Graphviz) ); + NMTOOLS_ASSERT_GRAPH_EQUAL( graph, expect ); +} + + +TEST_CASE("var(test3)" * doctest::test_suite("functional::get_compute_graph")) { auto lhs_shape = nmtools_array{3,4}; auto lhs_buffer = na::arange(12); @@ -38,41 +140,173 @@ TEST_CASE("var" * doctest::test_suite("functional::get_compute_graph")) auto lhs = view::alias(lhs_array,0_ct); auto divisor = view::alias(3,11_ct); - auto ddof = view::alias(2,12_ct); - auto a = nm::unwrap(view::reduce_add(lhs,axis)); + auto a = view::reduce_add(lhs,axis); auto b = view::divide(a,divisor); auto c = view::subtract(b,lhs); auto d = view::fabs(c); auto e = view::square(d); - auto f = nm::unwrap(view::sum(e,axis)); + + auto a_id = get_node_id(a); + auto b_id = get_node_id(b); + auto c_id = get_node_id(c); + auto d_id = get_node_id(d); + auto e_id = get_node_id(e); + + auto graph = unwrap(fn::get_compute_graph(e)); + + // TODO: provide common function to get operands id + auto divisor_id = 11_ct; + + auto expect = fn::compute_graph_t<>() + .add_node(0_ct,&*lhs_array) + .add_node(a_id,fn::node_t{fn::reduce[unwrap(a).attributes()],nmtools_tuple{0_ct}}) + .add_node(divisor_id,divisor) + .add_node(b_id,fn::node_t{fn::broadcast_binary_ufunc[unwrap(b).attributes()],nmtools_tuple{a_id,divisor}}) + .add_node(c_id,fn::node_t{fn::broadcast_binary_ufunc[unwrap(c).attributes()],nmtools_tuple{b_id,0_ct}}) + .add_node(d_id,fn::node_t{fn::unary_ufunc[unwrap(d).attributes()],nmtools_tuple{c_id}}) + .add_node(e_id,fn::node_t{fn::unary_ufunc[unwrap(e).attributes()],nmtools_tuple{d_id}}) + .add_edge(0_ct,a_id) + .add_edge(a_id,b_id) + .add_edge(divisor_id,b_id) + .add_edge(b_id,c_id) + .add_edge(0_ct,c_id) + .add_edge(c_id,d_id) + .add_edge(d_id,e_id) + ; + + // CHECK_MESSAGE( true, utils::to_string(graph,utils::Graphviz) ); + NMTOOLS_ASSERT_GRAPH_EQUAL( graph, expect ); +} + +TEST_CASE("var(test4)" * doctest::test_suite("functional::get_compute_graph")) +{ + auto lhs_shape = nmtools_array{3,4}; + auto lhs_buffer = na::arange(12); + auto lhs_array = na::reshape(lhs_buffer,lhs_shape); + + auto axis = 0; + + auto lhs = view::alias(lhs_array,0_ct); + auto divisor = view::alias(3,11_ct); + + auto a = view::reduce_add(lhs,axis); + auto b = view::divide(a,divisor); + auto c = view::subtract(b,lhs); + auto d = view::fabs(c); + auto e = view::square(d); + auto f = view::sum(e,axis); + + auto a_id = get_node_id(a); + auto b_id = get_node_id(b); + auto c_id = get_node_id(c); + auto d_id = get_node_id(d); + auto e_id = get_node_id(e); + auto f_id = get_node_id(f); + + auto graph = unwrap(fn::get_compute_graph(f)); + + // TODO: provide common function to get operands id + auto divisor_id = 11_ct; + + auto expect = fn::compute_graph_t<>() + .add_node(0_ct,&*lhs_array) + .add_node(a_id,fn::node_t{fn::reduce[unwrap(a).attributes()],nmtools_tuple{0_ct}}) + .add_node(divisor_id,divisor) + .add_node(b_id,fn::node_t{fn::broadcast_binary_ufunc[unwrap(b).attributes()],nmtools_tuple{a_id,divisor}}) + .add_node(c_id,fn::node_t{fn::broadcast_binary_ufunc[unwrap(c).attributes()],nmtools_tuple{b_id,0_ct}}) + .add_node(d_id,fn::node_t{fn::unary_ufunc[unwrap(d).attributes()],nmtools_tuple{c_id}}) + .add_node(e_id,fn::node_t{fn::unary_ufunc[unwrap(e).attributes()],nmtools_tuple{d_id}}) + .add_node(f_id,fn::node_t{fn::reduce[unwrap(f).attributes()],nmtools_tuple{e_id}}) + .add_edge(0_ct,a_id) + .add_edge(a_id,b_id) + .add_edge(divisor_id,b_id) + .add_edge(b_id,c_id) + .add_edge(0_ct,c_id) + .add_edge(c_id,d_id) + .add_edge(d_id,e_id) + .add_edge(e_id,f_id) + ; + + // CHECK_MESSAGE( true, utils::to_string(graph,utils::Graphviz) ); + NMTOOLS_ASSERT_GRAPH_EQUAL( graph, expect ); +} + + +TEST_CASE("var(test5)" * doctest::test_suite("functional::get_compute_graph")) +{ + auto lhs_shape = nmtools_array{3,4}; + auto lhs_buffer = na::arange(12); + auto lhs_array = na::reshape(lhs_buffer,lhs_shape); + + auto axis = 0; + + auto lhs = view::alias(lhs_array,0_ct); + auto divisor = view::alias(3,11_ct); + auto ddof = 2; + + auto a = view::reduce_add(lhs,axis); + auto b = view::divide(a,divisor); + auto c = view::subtract(b,lhs); + auto d = view::fabs(c); + auto e = view::square(d); + auto f = view::sum(e,axis); auto g = view::divide(f,ddof); - auto graph = nm::unwrap(fn::get_compute_graph(g)); + auto a_id = get_node_id(a); + auto b_id = get_node_id(b); + auto c_id = get_node_id(c); + auto d_id = get_node_id(d); + auto e_id = get_node_id(e); + auto f_id = get_node_id(f); + auto g_id = get_node_id(g); + + auto graph = unwrap(fn::get_compute_graph(g)); + + // TODO: provide common function to get operands id + auto divisor_id = 11_ct; + auto ddof_id = meta::ct_v; auto expect = fn::compute_graph_t<>() - .add_node(0_ct,&lhs_array) - .add_node(11_ct,3) - .add_node(12_ct,2) - .add_node(1_ct,fn::node_t{fn::reduce_add[a.axis][nm::None][a.initial][a.keepdims],nmtools_tuple{0_ct}}) - .add_node(13_ct,fn::node_t{fn::divide,nmtools_tuple{1_ct,11_ct}}) - .add_node(15_ct,fn::node_t{fn::subtract,nmtools_tuple{13_ct,0_ct}}) - .add_node(16_ct,fn::node_t{fn::fabs,nmtools_tuple{15_ct}}) - .add_node(17_ct,fn::node_t{fn::square,nmtools_tuple{16_ct}}) - .add_node(18_ct,fn::node_t{fn::reduce_add[f.axis][nm::None][f.initial][f.keepdims],nmtools_tuple{17_ct}}) - .add_node(20_ct,fn::node_t{fn::divide,nmtools_tuple{18_ct,12_ct}}) - .add_edge(0_ct,1_ct) - .add_edge(0_ct,15_ct) - .add_edge(1_ct,13_ct) - .add_edge(11_ct,13_ct) - .add_edge(13_ct,15_ct) - .add_edge(15_ct,16_ct) - .add_edge(16_ct,17_ct) - .add_edge(17_ct,18_ct) - .add_edge(18_ct,20_ct) - .add_edge(12_ct,20_ct) + .add_node(0_ct,&*lhs_array) + .add_node(a_id,fn::node_t{fn::reduce[unwrap(a).attributes()],nmtools_tuple{0_ct}}) + .add_node(divisor_id,divisor) + .add_node(b_id,fn::node_t{fn::broadcast_binary_ufunc[unwrap(b).attributes()],nmtools_tuple{a_id,divisor}}) + .add_node(c_id,fn::node_t{fn::broadcast_binary_ufunc[unwrap(c).attributes()],nmtools_tuple{b_id,0_ct}}) + .add_node(d_id,fn::node_t{fn::unary_ufunc[unwrap(d).attributes()],nmtools_tuple{c_id}}) + .add_node(e_id,fn::node_t{fn::unary_ufunc[unwrap(e).attributes()],nmtools_tuple{d_id}}) + .add_node(f_id,fn::node_t{fn::reduce[unwrap(f).attributes()],nmtools_tuple{e_id}}) + .add_node(ddof_id,ddof) + .add_node(g_id,fn::node_t{fn::broadcast_binary_ufunc[unwrap(g).attributes()],nmtools_tuple{f_id,ddof_id}}) + .add_edge(0_ct,a_id) + .add_edge(a_id,b_id) + .add_edge(divisor_id,b_id) + .add_edge(b_id,c_id) + .add_edge(0_ct,c_id) + .add_edge(c_id,d_id) + .add_edge(d_id,e_id) + .add_edge(e_id,f_id) + .add_edge(f_id,g_id) + .add_edge(ddof_id,g_id) ; // CHECK_MESSAGE( true, utils::to_string(graph,utils::Graphviz) ); NMTOOLS_ASSERT_GRAPH_EQUAL( graph, expect ); +} + +TEST_CASE("var" * doctest::test_suite("functional::get_compute_graph")) +{ + auto lhs_shape = nmtools_array{3,4}; + auto lhs_buffer = na::arange(12); + auto lhs_array = na::reshape(lhs_buffer,lhs_shape); + + CHECK( nm::has_value(lhs_array) ); + + auto axis = 0; + + // TODO: support maybe type for var + auto var = view::var(unwrap(lhs_array),axis); + auto graph = fn::get_compute_graph(nm::unwrap(var)); + + CHECK_MESSAGE( true, utils::to_string(graph,utils::Graphviz) ); } \ No newline at end of file diff --git a/tests/functional/src/misc/ct_digraph.cpp b/tests/functional/src/misc/ct_digraph.cpp index 1ac964a29..e4252d598 100644 --- a/tests/functional/src/misc/ct_digraph.cpp +++ b/tests/functional/src/misc/ct_digraph.cpp @@ -10,6 +10,7 @@ #include "nmtools/array/functional/ufuncs/tanh.hpp" #include "nmtools/array/functional/ufuncs/exp.hpp" #include "nmtools/array/functional/ufuncs/maximum.hpp" +#include "nmtools/array/functional/activations/relu.hpp" #include "nmtools/testing/doctest.hpp" namespace nm = nmtools; @@ -20,6 +21,50 @@ namespace utility = nmtools::utility; using namespace nmtools::literals; +TEST_CASE("ct_digraph(relu)" * doctest::test_suite("ct_digraph")) +{ + auto array = nmtools_array{1,2,3,4}; + + auto graph = utility::ct_digraph() + .add_node(0_ct,&array) + .add_node(1_ct,fn::relu) + .add_edge(0_ct,1_ct) + // .add_edge(0_ct,1_ct) + ; + + NMTOOLS_ASSERT_EQUAL( graph.size(), 2 ); + CHECK( graph.nodes(0_ct) == &array ); + NMTOOLS_ASSERT_EQUAL( graph.nodes(1_ct), fn::relu ); + + auto out_edges = graph.out_edges(0_ct); + CHECK( meta::len_v == 1 ); + + CHECK_MESSAGE( true, utils::to_string(graph,utils::Graphviz) ); +} + +TEST_CASE("ct_digraph(relu)" * doctest::test_suite("ct_digraph")) +{ + auto array = nmtools_array{1,2,3,4}; + + auto graph = utility::ct_digraph() + .add_node(0_ct,&array) + .add_node(1_ct,fn::relu) + .add_edge(0_ct,1_ct) + .add_edge(0_ct,1_ct) + ; + + NMTOOLS_ASSERT_EQUAL( graph.size(), 2 ); + CHECK( graph.nodes(0_ct) == &array ); + NMTOOLS_ASSERT_EQUAL( graph.nodes(1_ct), fn::relu ); + + // make sure edges are not duplicated + auto out_edges = graph.out_edges(0_ct); + CHECK( meta::len_v == 1 ); + NMTOOLS_ASSERT_EQUAL( nmtools::at(out_edges,0_ct), 1_ct ); + + CHECK_MESSAGE( true, utils::to_string(graph,utils::Graphviz) ); +} + TEST_CASE("ct_digraph(reduce_add_divide)" * doctest::test_suite("ct_digraph")) { auto array = nmtools_array{1,2,3,4}; diff --git a/tests/index/CMakeLists.txt b/tests/index/CMakeLists.txt index ad851151a..475c80a3f 100644 --- a/tests/index/CMakeLists.txt +++ b/tests/index/CMakeLists.txt @@ -42,6 +42,7 @@ option(NMTOOLS_INDEX_TEST_ALL "test all index modules" ON) if (NMTOOLS_INDEX_TEST_ALL) set(ARRAY_INDEX_TEST_SOURCES + src/alias.cpp src/argsort.cpp src/array_slice.cpp src/broadcast_shape.cpp diff --git a/tests/index/src/alias.cpp b/tests/index/src/alias.cpp new file mode 100644 index 000000000..9b99f17a0 --- /dev/null +++ b/tests/index/src/alias.cpp @@ -0,0 +1,90 @@ +#include "nmtools/array/index/alias.hpp" +#include "nmtools/testing/data/index/alias.hpp" +#include "nmtools/testing/doctest.hpp" + +#define ALIAS_SUBCASE(case_name, ...) \ +SUBCASE(#case_name) \ +{ \ + NMTOOLS_TESTING_USE_CASE(index, alias, case_name); \ + using namespace args; \ + auto result = nmtools::index::alias(__VA_ARGS__); \ + NMTOOLS_ASSERT_EQUAL( result, expect::result ); \ +} + +#define GENERATE_ALIAS_SUBCASE(case_name, ...) \ +SUBCASE(#case_name) \ +{ \ + NMTOOLS_TESTING_USE_CASE(index, generate_alias, case_name); \ + using namespace args; \ + auto result = nmtools::index::generate_alias(__VA_ARGS__); \ + NMTOOLS_ASSERT_EQUAL( result, expect::result ); \ +} + +TEST_CASE("alias(case1)" * doctest::test_suite("index::alias")) +{ + ALIAS_SUBCASE( case1, operands_ct, reserved_ids ); +} + +TEST_CASE("alias(case2)" * doctest::test_suite("index::alias")) +{ + ALIAS_SUBCASE( case2, operands_ct, reserved_ids_ct ); +} + +TEST_CASE("alias(case3)" * doctest::test_suite("index::alias")) +{ + ALIAS_SUBCASE( case3, operands_ct, reserved_ids_ct ); +} + +TEST_CASE("generate_alias(case1)" * doctest::test_suite("index::alias")) +{ + GENERATE_ALIAS_SUBCASE( case1, aliases_ct, base_ct, prime_ct ); +} + +// 0, -1 sequence doesn't compute nicely for the hash algorithm +TEST_CASE("generate_alias(case2)" * doctest::test_suite("index::alias") * doctest::skip()) +{ + GENERATE_ALIAS_SUBCASE( case2, aliases, base, prime ); + GENERATE_ALIAS_SUBCASE( case2, aliases_ct, base_ct, prime_ct ); +} + +TEST_CASE("generate_alias(case3)" * doctest::test_suite("index::alias")) +{ + GENERATE_ALIAS_SUBCASE( case3, aliases, base, prime ); + GENERATE_ALIAS_SUBCASE( case3, aliases_ct, base_ct, prime_ct ); +} + +TEST_CASE("generate_alias(case4)" * doctest::test_suite("index::alias")) +{ + GENERATE_ALIAS_SUBCASE( case4, aliases, base, prime ); + GENERATE_ALIAS_SUBCASE( case4, aliases_ct, base_ct, prime_ct ); +} + +TEST_CASE("generate_alias(case5)" * doctest::test_suite("index::alias")) +{ + GENERATE_ALIAS_SUBCASE( case5, aliases, base, prime ); + GENERATE_ALIAS_SUBCASE( case5, aliases_ct, base_ct, prime_ct ); +} + +TEST_CASE("generate_alias(case6)" * doctest::test_suite("index::alias")) +{ + GENERATE_ALIAS_SUBCASE( case6, aliases, base, prime ); + GENERATE_ALIAS_SUBCASE( case6, aliases_ct, base_ct, prime_ct ); +} + +TEST_CASE("generate_alias(case7)" * doctest::test_suite("index::alias")) +{ + GENERATE_ALIAS_SUBCASE( case7, aliases, base, prime ); + GENERATE_ALIAS_SUBCASE( case7, aliases_ct, base_ct, prime_ct ); +} + +TEST_CASE("generate_alias(case8)" * doctest::test_suite("index::alias")) +{ + GENERATE_ALIAS_SUBCASE( case8, aliases, base, prime ); + GENERATE_ALIAS_SUBCASE( case8, aliases_ct, base_ct, prime_ct ); +} + +TEST_CASE("generate_alias(case9)" * doctest::test_suite("index::alias")) +{ + GENERATE_ALIAS_SUBCASE( case9, aliases, base, prime ); + GENERATE_ALIAS_SUBCASE( case9, aliases_ct, base_ct, prime_ct ); +} \ No newline at end of file diff --git a/tests/index/src/expand_dims.cpp b/tests/index/src/expand_dims.cpp index ff0f243e7..10e4641d7 100644 --- a/tests/index/src/expand_dims.cpp +++ b/tests/index/src/expand_dims.cpp @@ -3,9 +3,7 @@ #include "nmtools/testing/doctest.hpp" #include "nmtools/testing/array_cast.hpp" -// to allow nmtools_array, vector, tuple identified as array/index -#include "nmtools/meta/stl.hpp" -#include "nmtools/array/impl/stl.hpp" +#include "nmtools/stl.hpp" namespace nm = nmtools; namespace na = nm::array; @@ -348,600 +346,4 @@ TEST_CASE("shape_expand_dims(case9)" * doctest::test_suite("index::shape_expand_ SHAPE_EXPAND_DIMS_SUBCASE( case9, shape_ct, axes_ct ); SHAPE_EXPAND_DIMS_SUBCASE( case9, shape_cl, axes_ct ); SHAPE_EXPAND_DIMS_SUBCASE( case9, shape_cl, axes_cl ); -} - -#if 0 -TEST_CASE("shape_expand_dims(vector)" * doctest::test_suite("index::shape_expand_dims")) -{ - { - auto shape = nmtools_list{1,2,3}; - auto axes = nmtools_array{0}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_list{1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_list{1,2,3}; - auto axes = nmtools_array{1}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_list{1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_list{1,2,3}; - auto axes = nmtools_array{2}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_list{1,2,1,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_list{1,2,3}; - auto axes = nmtools_array{3}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_list{1,2,3,1}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_list{1,2,3}; - auto axes = nmtools_list{0,1}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_list{1,1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_list{1,2,3}; - auto axes = nmtools_list{0,2}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_list{1,1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_list{1,2,3}; - auto axes = nmtools_list{1,2}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - // on numpy 1.18 - // >>> np.shape_expand_dims(np.random.rand(1,2,3),(1,2)).shape - // (1, 1, 1, 2, 3) - auto expected = nmtools_list{1,1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_list{1,2,3}; - auto axes = nmtools_list{2,3}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_list{1,2,1,1,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_list{1,2,3}; - auto axes = nmtools_list{2,3,0}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_list{1,1,1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - - { - auto shape = nmtools_list{1,2,3}; - auto axes = nmtools_array{0}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_list{1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_list{1,2,3}; - auto axes = nmtools_array{1}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_list{1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_list{1,2,3}; - auto axes = nmtools_array{2}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_list{1,2,1,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_list{1,2,3}; - auto axes = nmtools_array{3}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_list{1,2,3,1}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_list{1,2,3}; - auto axes = nmtools_array{0,1}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_list{1,1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_list{1,2,3}; - auto axes = nmtools_array{1,2}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_list{1,1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_list{1,2,3}; - auto axes = nmtools_array{2,3}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_list{1,2,1,1,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_list{1,2,3}; - auto axes = nmtools_array{2,3,0}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_list{1,1,1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - - #if 0 - { - auto shape = nmtools_list{1,2,3}; - auto axes = std::tuple{0}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_list{1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_list{1,2,3}; - auto axes = std::tuple{1}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_list{1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_list{1,2,3}; - auto axes = std::tuple{2}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_list{1,2,1,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_list{1,2,3}; - auto axes = std::tuple{3}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_list{1,2,3,1}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_list{1,2,3}; - auto axes = std::tuple{0,1}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_list{1,1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_list{1,2,3}; - auto axes = std::tuple{1,2}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_list{1,1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_list{1,2,3}; - auto axes = std::tuple{2,3}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_list{1,2,1,1,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_list{1,2,3}; - auto axes = std::tuple{2,3,0}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_list{1,1,1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - #endif - - { - auto shape = nmtools_list{1,2,3}; - auto axes = na::hybrid_ndarray({0}); - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_list{1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_list{1,2,3}; - auto axes = na::hybrid_ndarray({1}); - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_list{1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_list{1,2,3}; - auto axes = na::hybrid_ndarray({2}); - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_list{1,2,1,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_list{1,2,3}; - auto axes = na::hybrid_ndarray({3}); - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_list{1,2,3,1}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_list{1,2,3}; - auto axes = na::hybrid_ndarray({0,1}); - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_list{1,1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_list{1,2,3}; - auto axes = na::hybrid_ndarray({1,2}); - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_list{1,1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_list{1,2,3}; - auto axes = na::hybrid_ndarray({2,3}); - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_list{1,2,1,1,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_list{1,2,3}; - auto axes = na::hybrid_ndarray({2,3,0}); - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_list{1,1,1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } -} - -TEST_CASE("shape_expand_dims(array)" * doctest::test_suite("index::shape_expand_dims")) -{ - { - auto shape = nmtools_array{1,2,3}; - auto axes = nmtools_array{0}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_array{1,2,3}; - auto axes = nmtools_array{1}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_array{1,2,3}; - auto axes = nmtools_array{2}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,2,1,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_array{1,2,3}; - auto axes = nmtools_array{3}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,2,3,1}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_array{1,2,3}; - auto axes = nmtools_array{0,1}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_array{1,2,3}; - auto axes = nmtools_array{1,2}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_array{1,2,3}; - auto axes = nmtools_array{2,3}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,2,1,1,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_array{1,2,3}; - auto axes = nmtools_array{2,3,0}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,1,1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - - { - auto shape = nmtools_array{1,2,3}; - auto axes = nmtools_array{0}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_array{1,2,3}; - auto axes = nmtools_array{1}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_array{1,2,3}; - auto axes = nmtools_array{2}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,2,1,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_array{1,2,3}; - auto axes = nmtools_array{3}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,2,3,1}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_array{1,2,3}; - auto axes = nmtools_list{0,1}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_array{1,2,3}; - auto axes = nmtools_list{1,2}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_array{1,2,3}; - auto axes = nmtools_list{2,3}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,2,1,1,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_array{1,2,3}; - auto axes = nmtools_list{2,3,0}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,1,1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - - #if 0 - { - auto shape = nmtools_array{1,2,3}; - auto axes = std::tuple{0}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_array{1,2,3}; - auto axes = std::tuple{1}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_array{1,2,3}; - auto axes = std::tuple{2}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,2,1,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_array{1,2,3}; - auto axes = std::tuple{3}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,2,3,1}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_array{1,2,3}; - auto axes = std::tuple{0,1}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_array{1,2,3}; - auto axes = std::tuple{1,2}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_array{1,2,3}; - auto axes = std::tuple{2,3}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,2,1,1,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_array{1,2,3}; - auto axes = std::tuple{2,3,0}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,1,1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - #endif - - { - auto shape = nmtools_array{1,2,3}; - auto axes = na::hybrid_ndarray({0}); - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_array{1,2,3}; - auto axes = na::hybrid_ndarray({1}); - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_array{1,2,3}; - auto axes = na::hybrid_ndarray({2}); - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,2,1,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_array{1,2,3}; - auto axes = na::hybrid_ndarray({3}); - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,2,3,1}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_array{1,2,3}; - auto axes = na::hybrid_ndarray({0,1}); - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_array{1,2,3}; - auto axes = na::hybrid_ndarray({1,2}); - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_array{1,2,3}; - auto axes = na::hybrid_ndarray({2,3}); - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,2,1,1,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = nmtools_array{1,2,3}; - auto axes = na::hybrid_ndarray({2,3,0}); - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,1,1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } -} - -#if 0 -TEST_CASE("shape_expand_dims(tuple)" * doctest::test_suite("index::shape_expand_dims")) -{ - { - auto shape = std::tuple{1,2,3}; - auto axes = nmtools_array{0}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = std::tuple{1,2,3}; - auto axes = std::tuple{0}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = std::tuple{1,2,3}; - auto axes = nmtools_array{1}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = std::tuple{1,2,3}; - auto axes = std::tuple{1}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = std::tuple{1,2,3}; - auto axes = nmtools_array{2}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,2,1,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = std::tuple{1,2,3}; - auto axes = std::tuple{2}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,2,1,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = std::tuple{1,2,3}; - auto axes = nmtools_array{3}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,2,3,1}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = std::tuple{1,2,3}; - auto axes = std::tuple{3}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,2,3,1}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = std::tuple{1,2,3}; - auto axes = nmtools_array{0,1}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = std::tuple{1,2,3}; - auto axes = std::tuple{0,1}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = std::tuple{1,2,3}; - auto axes = nmtools_array{1,2}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = std::tuple{1,2,3}; - auto axes = std::tuple{1,2}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = std::tuple{1,2,3}; - auto axes = nmtools_array{2,3}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,2,1,1,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = std::tuple{1,2,3}; - auto axes = std::tuple{2,3}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,2,1,1,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = std::tuple{1,2,3}; - auto axes = nmtools_array{2,3,0}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,1,1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } - { - auto shape = std::tuple{1,2,3}; - auto axes = std::tuple{2,3,0}; - auto newshape = nm::index::shape_expand_dims(shape,axes); - auto expected = nmtools_array{1,1,1,1,2,3}; - NMTOOLS_ASSERT_EQUAL( newshape, expected ); - } -} -#endif -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/tests/index/src/gather.cpp b/tests/index/src/gather.cpp index dfac04f19..c8a0fa2d2 100644 --- a/tests/index/src/gather.cpp +++ b/tests/index/src/gather.cpp @@ -128,21 +128,21 @@ TEST_CASE("gather(constexpr)" * doctest::test_suite("index::gather")) TEST_CASE("gather" * doctest::test_suite("index")) { { - auto indices = tuple{1,2,3}; + auto indices = nmtools_tuple{1,2,3}; auto order = array{0,1,2}; auto gatherd = nm::index::gather(indices, order); auto expected = array{1,2,3}; NMTOOLS_ASSERT_EQUAL( gatherd, expected ); } { - auto indices = tuple{1,2,3}; + auto indices = nmtools_tuple{1,2,3}; auto order = array{1,0,2}; auto gatherd = nm::index::gather(indices, order); auto expected = array{2,1,3}; NMTOOLS_ASSERT_EQUAL( gatherd, expected ); } { - auto indices = tuple{1,2,3}; + auto indices = nmtools_tuple{1,2,3}; auto order = array{1,2,0}; auto gatherd = nm::index::gather(indices, order); auto expected = array{2,3,1}; @@ -150,21 +150,21 @@ TEST_CASE("gather" * doctest::test_suite("index")) } #ifndef NMTOOLS_DISABLE_STL { - auto indices = tuple{1,2,3}; + auto indices = nmtools_tuple{1,2,3}; auto order = vector{0,1,2}; auto gatherd = nm::index::gather(indices, order); auto expected = array{1,2,3}; NMTOOLS_ASSERT_EQUAL( gatherd, expected ); } { - auto indices = tuple{1,2,3}; + auto indices = nmtools_tuple{1,2,3}; auto order = vector{1,0,2}; auto gatherd = nm::index::gather(indices, order); auto expected = array{2,1,3}; NMTOOLS_ASSERT_EQUAL( gatherd, expected ); } { - auto indices = tuple{1,2,3}; + auto indices = nmtools_tuple{1,2,3}; auto order = vector{1,2,0}; auto gatherd = nm::index::gather(indices, order); auto expected = array{2,3,1}; @@ -172,43 +172,43 @@ TEST_CASE("gather" * doctest::test_suite("index")) } #endif // NMTOOLS_DISABLE_STL { - auto indices = tuple{1,2,3}; - auto order = tuple{0,1,2}; + auto indices = nmtools_tuple{1,2,3}; + auto order = nmtools_tuple{0,1,2}; auto gatherd = nm::index::gather(indices, order); auto expected = array{1,2,3}; NMTOOLS_ASSERT_EQUAL( gatherd, expected ); } { - auto indices = tuple{1,2,3}; - auto order = tuple{0_ct,1_ct,2_ct}; + auto indices = nmtools_tuple{1,2,3}; + auto order = nmtools_tuple{0_ct,1_ct,2_ct}; auto gatherd = nm::index::gather(indices, order); auto expected = array{1,2,3}; NMTOOLS_ASSERT_EQUAL( gatherd, expected ); } { - auto indices = tuple{1,2,3}; - auto order = tuple{1,0,2}; + auto indices = nmtools_tuple{1,2,3}; + auto order = nmtools_tuple{1,0,2}; auto gatherd = nm::index::gather(indices, order); auto expected = array{2,1,3}; NMTOOLS_ASSERT_EQUAL( gatherd, expected ); } { - auto indices = tuple{1,2,3}; - auto order = tuple{1_ct,0_ct,2_ct}; + auto indices = nmtools_tuple{1,2,3}; + auto order = nmtools_tuple{1_ct,0_ct,2_ct}; auto gatherd = nm::index::gather(indices, order); auto expected = array{2,1,3}; NMTOOLS_ASSERT_EQUAL( gatherd, expected ); } { - auto indices = tuple{1,2,3}; - auto order = tuple{1,2,0}; + auto indices = nmtools_tuple{1,2,3}; + auto order = nmtools_tuple{1,2,0}; auto gatherd = nm::index::gather(indices, order); auto expected = array{2,3,1}; NMTOOLS_ASSERT_EQUAL( gatherd, expected ); } { - auto indices = tuple{1,2,3}; - auto order = tuple{1_ct,2_ct,0_ct}; + auto indices = nmtools_tuple{1,2,3}; + auto order = nmtools_tuple{1_ct,2_ct,0_ct}; auto gatherd = nm::index::gather(indices, order); auto expected = array{2,3,1}; NMTOOLS_ASSERT_EQUAL( gatherd, expected ); diff --git a/tests/index/src/ndindex.cpp b/tests/index/src/ndindex.cpp index 01e115a6e..ffe500e5a 100644 --- a/tests/index/src/ndindex.cpp +++ b/tests/index/src/ndindex.cpp @@ -18,32 +18,32 @@ using nmtools_tuple; TEST_CASE("ndindex({3,2})" * doctest::test_suite("index")) { - auto shape_ = tuple{3,2}; + auto shape_ = nmtools_tuple{3,2}; auto indices = nm::index::ndindex(shape_); REQUIRE( indices.size() == 6 ); { auto i = indices[0]; - CHECK(( isequal(i,tuple{0,0}) )); + CHECK(( isequal(i,nmtools_tuple{0,0}) )); } { auto i = indices[1]; - CHECK(( isequal(i,tuple{0,1}) )); + CHECK(( isequal(i,nmtools_tuple{0,1}) )); } { auto i = indices[2]; - CHECK(( isequal(i,tuple{1,0}) )); + CHECK(( isequal(i,nmtools_tuple{1,0}) )); } { auto i = indices[3]; - CHECK(( isequal(i,tuple{1,1}) )); + CHECK(( isequal(i,nmtools_tuple{1,1}) )); } { auto i = indices[4]; - CHECK(( isequal(i,tuple{2,0}) )); + CHECK(( isequal(i,nmtools_tuple{2,0}) )); } { auto i = indices[5]; - CHECK(( isequal(i,tuple{2,1}) )); + CHECK(( isequal(i,nmtools_tuple{2,1}) )); } } @@ -84,80 +84,80 @@ TEST_CASE("ndindex(vector{3,2})" * doctest::test_suite("index")) TEST_CASE("ndindex({3,2,3})" * doctest::test_suite("index")) { - auto shape_ = tuple{3,2,3}; + auto shape_ = nmtools_tuple{3,2,3}; auto indices = nm::index::ndindex(shape_); REQUIRE( indices.size() == 18 ); { auto i = indices[0]; - CHECK(( isequal(i,tuple{0,0,0}) )); + CHECK(( isequal(i,nmtools_tuple{0,0,0}) )); } { auto i = indices[1]; - CHECK(( isequal(i,tuple{0,0,1}) )); + CHECK(( isequal(i,nmtools_tuple{0,0,1}) )); } { auto i = indices[2]; - CHECK(( isequal(i,tuple{0,0,2}) )); + CHECK(( isequal(i,nmtools_tuple{0,0,2}) )); } { auto i = indices[3]; - CHECK(( isequal(i,tuple{0,1,0}) )); + CHECK(( isequal(i,nmtools_tuple{0,1,0}) )); } { auto i = indices[4]; - CHECK(( isequal(i,tuple{0,1,1}) )); + CHECK(( isequal(i,nmtools_tuple{0,1,1}) )); } { auto i = indices[5]; - CHECK(( isequal(i,tuple{0,1,2}) )); + CHECK(( isequal(i,nmtools_tuple{0,1,2}) )); } { auto i = indices[6]; - CHECK(( isequal(i,tuple{1,0,0}) )); + CHECK(( isequal(i,nmtools_tuple{1,0,0}) )); } { auto i = indices[7]; - CHECK(( isequal(i,tuple{1,0,1}) )); + CHECK(( isequal(i,nmtools_tuple{1,0,1}) )); } { auto i = indices[8]; - CHECK(( isequal(i,tuple{1,0,2}) )); + CHECK(( isequal(i,nmtools_tuple{1,0,2}) )); } { auto i = indices[9]; - CHECK(( isequal(i,tuple{1,1,0}) )); + CHECK(( isequal(i,nmtools_tuple{1,1,0}) )); } { auto i = indices[10]; - CHECK(( isequal(i,tuple{1,1,1}) )); + CHECK(( isequal(i,nmtools_tuple{1,1,1}) )); } { auto i = indices[11]; - CHECK(( isequal(i,tuple{1,1,2}) )); + CHECK(( isequal(i,nmtools_tuple{1,1,2}) )); } { auto i = indices[12]; - CHECK(( isequal(i,tuple{2,0,0}) )); + CHECK(( isequal(i,nmtools_tuple{2,0,0}) )); } { auto i = indices[13]; - CHECK(( isequal(i,tuple{2,0,1}) )); + CHECK(( isequal(i,nmtools_tuple{2,0,1}) )); } { auto i = indices[14]; - CHECK(( isequal(i,tuple{2,0,2}) )); + CHECK(( isequal(i,nmtools_tuple{2,0,2}) )); } { auto i = indices[15]; - CHECK(( isequal(i,tuple{2,1,0}) )); + CHECK(( isequal(i,nmtools_tuple{2,1,0}) )); } { auto i = indices[16]; - CHECK(( isequal(i,tuple{2,1,1}) )); + CHECK(( isequal(i,nmtools_tuple{2,1,1}) )); } { auto i = indices[17]; - CHECK(( isequal(i,tuple{2,1,2}) )); + CHECK(( isequal(i,nmtools_tuple{2,1,2}) )); } } @@ -244,158 +244,158 @@ TEST_CASE("ndindex({3,2,3})" * doctest::test_suite("index")) TEST_CASE("ndindex({3,2,3,1})" * doctest::test_suite("index")) { - auto shape_ = tuple{3,2,3,1}; + auto shape_ = nmtools_tuple{3,2,3,1}; auto indices = nm::index::ndindex(shape_); REQUIRE( indices.size() == 18 ); { auto i = indices[0]; - CHECK(( isequal(i,tuple{0,0,0,0}) )); + CHECK(( isequal(i,nmtools_tuple{0,0,0,0}) )); } { auto i = indices[1]; - CHECK(( isequal(i,tuple{0,0,1,0}) )); + CHECK(( isequal(i,nmtools_tuple{0,0,1,0}) )); } { auto i = indices[2]; - CHECK(( isequal(i,tuple{0,0,2,0}) )); + CHECK(( isequal(i,nmtools_tuple{0,0,2,0}) )); } { auto i = indices[3]; - CHECK(( isequal(i,tuple{0,1,0,0}) )); + CHECK(( isequal(i,nmtools_tuple{0,1,0,0}) )); } { auto i = indices[4]; - CHECK(( isequal(i,tuple{0,1,1,0}) )); + CHECK(( isequal(i,nmtools_tuple{0,1,1,0}) )); } { auto i = indices[5]; - CHECK(( isequal(i,tuple{0,1,2,0}) )); + CHECK(( isequal(i,nmtools_tuple{0,1,2,0}) )); } { auto i = indices[6]; - CHECK(( isequal(i,tuple{1,0,0,0}) )); + CHECK(( isequal(i,nmtools_tuple{1,0,0,0}) )); } { auto i = indices[7]; - CHECK(( isequal(i,tuple{1,0,1,0}) )); + CHECK(( isequal(i,nmtools_tuple{1,0,1,0}) )); } { auto i = indices[8]; - CHECK(( isequal(i,tuple{1,0,2,0}) )); + CHECK(( isequal(i,nmtools_tuple{1,0,2,0}) )); } { auto i = indices[9]; - CHECK(( isequal(i,tuple{1,1,0,0}) )); + CHECK(( isequal(i,nmtools_tuple{1,1,0,0}) )); } { auto i = indices[10]; - CHECK(( isequal(i,tuple{1,1,1,0}) )); + CHECK(( isequal(i,nmtools_tuple{1,1,1,0}) )); } { auto i = indices[11]; - CHECK(( isequal(i,tuple{1,1,2,0}) )); + CHECK(( isequal(i,nmtools_tuple{1,1,2,0}) )); } { auto i = indices[12]; - CHECK(( isequal(i,tuple{2,0,0,0}) )); + CHECK(( isequal(i,nmtools_tuple{2,0,0,0}) )); } { auto i = indices[13]; - CHECK(( isequal(i,tuple{2,0,1,0}) )); + CHECK(( isequal(i,nmtools_tuple{2,0,1,0}) )); } { auto i = indices[14]; - CHECK(( isequal(i,tuple{2,0,2,0}) )); + CHECK(( isequal(i,nmtools_tuple{2,0,2,0}) )); } { auto i = indices[15]; - CHECK(( isequal(i,tuple{2,1,0,0}) )); + CHECK(( isequal(i,nmtools_tuple{2,1,0,0}) )); } { auto i = indices[16]; - CHECK(( isequal(i,tuple{2,1,1,0}) )); + CHECK(( isequal(i,nmtools_tuple{2,1,1,0}) )); } { auto i = indices[17]; - CHECK(( isequal(i,tuple{2,1,2,0}) )); + CHECK(( isequal(i,nmtools_tuple{2,1,2,0}) )); } } TEST_CASE("ndindex({3,2,3,1})" * doctest::test_suite("index")) { - auto shape_ = tuple{2,3,1,3,1}; + auto shape_ = nmtools_tuple{2,3,1,3,1}; auto indices = nm::index::ndindex(shape_); REQUIRE( indices.size() == 18 ); { auto i = indices[0]; - CHECK(( isequal(i,tuple{0,0,0,0,0}) )); + CHECK(( isequal(i,nmtools_tuple{0,0,0,0,0}) )); } { auto i = indices[1]; - CHECK(( isequal(i,tuple{0,0,0,1,0}) )); + CHECK(( isequal(i,nmtools_tuple{0,0,0,1,0}) )); } { auto i = indices[2]; - CHECK(( isequal(i,tuple{0,0,0,2,0}) )); + CHECK(( isequal(i,nmtools_tuple{0,0,0,2,0}) )); } { auto i = indices[3]; - CHECK(( isequal(i,tuple{0,1,0,0,0}) )); + CHECK(( isequal(i,nmtools_tuple{0,1,0,0,0}) )); } { auto i = indices[4]; - CHECK(( isequal(i,tuple{0,1,0,1,0}) )); + CHECK(( isequal(i,nmtools_tuple{0,1,0,1,0}) )); } { auto i = indices[5]; - CHECK(( isequal(i,tuple{0,1,0,2,0}) )); + CHECK(( isequal(i,nmtools_tuple{0,1,0,2,0}) )); } { auto i = indices[6]; - CHECK(( isequal(i,tuple{0,2,0,0,0}) )); + CHECK(( isequal(i,nmtools_tuple{0,2,0,0,0}) )); } { auto i = indices[7]; - CHECK(( isequal(i,tuple{0,2,0,1,0}) )); + CHECK(( isequal(i,nmtools_tuple{0,2,0,1,0}) )); } { auto i = indices[8]; - CHECK(( isequal(i,tuple{0,2,0,2,0}) )); + CHECK(( isequal(i,nmtools_tuple{0,2,0,2,0}) )); } { auto i = indices[9]; - CHECK(( isequal(i,tuple{1,0,0,0,0}) )); + CHECK(( isequal(i,nmtools_tuple{1,0,0,0,0}) )); } { auto i = indices[10]; - CHECK(( isequal(i,tuple{1,0,0,1,0}) )); + CHECK(( isequal(i,nmtools_tuple{1,0,0,1,0}) )); } { auto i = indices[11]; - CHECK(( isequal(i,tuple{1,0,0,2,0}) )); + CHECK(( isequal(i,nmtools_tuple{1,0,0,2,0}) )); } { auto i = indices[12]; - CHECK(( isequal(i,tuple{1,1,0,0,0}) )); + CHECK(( isequal(i,nmtools_tuple{1,1,0,0,0}) )); } { auto i = indices[13]; - CHECK(( isequal(i,tuple{1,1,0,1,0}) )); + CHECK(( isequal(i,nmtools_tuple{1,1,0,1,0}) )); } { auto i = indices[14]; - CHECK(( isequal(i,tuple{1,1,0,2,0}) )); + CHECK(( isequal(i,nmtools_tuple{1,1,0,2,0}) )); } { auto i = indices[15]; - CHECK(( isequal(i,tuple{1,2,0,0,0}) )); + CHECK(( isequal(i,nmtools_tuple{1,2,0,0,0}) )); } { auto i = indices[16]; - CHECK(( isequal(i,tuple{1,2,0,1,0}) )); + CHECK(( isequal(i,nmtools_tuple{1,2,0,1,0}) )); } { auto i = indices[17]; - CHECK(( isequal(i,tuple{1,2,0,2,0}) )); + CHECK(( isequal(i,nmtools_tuple{1,2,0,2,0}) )); } } \ No newline at end of file diff --git a/tests/index/src/reverse.cpp b/tests/index/src/reverse.cpp index deab68647..aeb9e6280 100644 --- a/tests/index/src/reverse.cpp +++ b/tests/index/src/reverse.cpp @@ -21,19 +21,19 @@ using nmtools_array; TEST_CASE("reverse" * doctest::test_suite("index")) { { - auto indices = tuple{1}; + auto indices = nmtools_tuple{1}; auto reversed = nm::index::reverse(indices); - CHECK( isequal(reversed,tuple{1}) ); + CHECK( isequal(reversed,nmtools_tuple{1}) ); } { - auto indices = tuple{0,1}; + auto indices = nmtools_tuple{0,1}; auto reversed = nm::index::reverse(indices); - CHECK( isequal(reversed,tuple{1,0}) ); + CHECK( isequal(reversed,nmtools_tuple{1,0}) ); } { - auto indices = tuple{2,0,1}; + auto indices = nmtools_tuple{2,0,1}; auto reversed = nm::index::reverse(indices); - CHECK( isequal(reversed,tuple{1,0,2}) ); + CHECK( isequal(reversed,nmtools_tuple{1,0,2}) ); } { auto indices = array{1}; diff --git a/tests/index/src/scatter.cpp b/tests/index/src/scatter.cpp index d26af4a30..fbed8b673 100644 --- a/tests/index/src/scatter.cpp +++ b/tests/index/src/scatter.cpp @@ -21,21 +21,21 @@ using nmtools_array; TEST_CASE("scatter" * doctest::test_suite("index")) { { - auto indices = tuple{1,2,3}; + auto indices = nmtools_tuple{1,2,3}; auto order = array{0,1,2}; auto scattered = nm::index::scatter(indices, order); auto expected = array{1,2,3}; NMTOOLS_ASSERT_EQUAL( scattered, expected ); } { - auto indices = tuple{1,2,3}; + auto indices = nmtools_tuple{1,2,3}; auto order = array{1,0,2}; auto scattered = nm::index::scatter(indices, order); auto expected = array{2,1,3}; NMTOOLS_ASSERT_EQUAL( scattered, expected ); } { - auto indices = tuple{1,2,3}; + auto indices = nmtools_tuple{1,2,3}; auto order = array{1,2,0}; auto scattered = nm::index::scatter(indices, order); auto expected = array{3,1,2}; @@ -43,21 +43,21 @@ TEST_CASE("scatter" * doctest::test_suite("index")) } #ifndef NMTOOLS_DISABLE_STL { - auto indices = tuple{1,2,3}; + auto indices = nmtools_tuple{1,2,3}; auto order = vector{0,1,2}; auto scattered = nm::index::scatter(indices, order); auto expected = array{1,2,3}; NMTOOLS_ASSERT_EQUAL( scattered, expected ); } { - auto indices = tuple{1,2,3}; + auto indices = nmtools_tuple{1,2,3}; auto order = vector{1,0,2}; auto scattered = nm::index::scatter(indices, order); auto expected = array{2,1,3}; NMTOOLS_ASSERT_EQUAL( scattered, expected ); } { - auto indices = tuple{1,2,3}; + auto indices = nmtools_tuple{1,2,3}; auto order = vector{1,2,0}; auto scattered = nm::index::scatter(indices, order); auto expected = array{3,1,2}; @@ -65,22 +65,22 @@ TEST_CASE("scatter" * doctest::test_suite("index")) } #endif // NMTOOLS_DISABLE_STL { - auto indices = tuple{1,2,3}; - auto order = tuple{0,1,2}; + auto indices = nmtools_tuple{1,2,3}; + auto order = nmtools_tuple{0,1,2}; auto scattered = nm::index::scatter(indices, order); auto expected = array{1,2,3}; NMTOOLS_ASSERT_EQUAL( scattered, expected ); } { - auto indices = tuple{1,2,3}; - auto order = tuple{1,0,2}; + auto indices = nmtools_tuple{1,2,3}; + auto order = nmtools_tuple{1,0,2}; auto scattered = nm::index::scatter(indices, order); auto expected = array{2,1,3}; NMTOOLS_ASSERT_EQUAL( scattered, expected ); } { - auto indices = tuple{1,2,3}; - auto order = tuple{1,2,0}; + auto indices = nmtools_tuple{1,2,3}; + auto order = nmtools_tuple{1,2,0}; auto scattered = nm::index::scatter(indices, order); auto expected = array{3,1,2}; NMTOOLS_ASSERT_EQUAL( scattered, expected ); diff --git a/tests/meta/array/index/argsort.cpp b/tests/meta/array/index/argsort.cpp index 97e92dc99..51b5dc37b 100644 --- a/tests/meta/array/index/argsort.cpp +++ b/tests/meta/array/index/argsort.cpp @@ -12,27 +12,27 @@ using nmtools_tuple; TEST_CASE("argsort" * doctest::test_suite("index")) { { - using array_t = decltype(tuple{0_ct,1_ct,2_ct,3_ct}); + using array_t = decltype(nmtools_tuple{0_ct,1_ct,2_ct,3_ct}); using result_t = meta::resolve_optype_t; - using expected_t = decltype(tuple{0_ct,1_ct,2_ct,3_ct}); + using expected_t = decltype(nmtools_tuple{0_ct,1_ct,2_ct,3_ct}); NMTOOLS_STATIC_CHECK_IS_SAME( result_t, expected_t ); } { - using array_t = decltype(tuple{1_ct,2_ct,3_ct,4_ct}); + using array_t = decltype(nmtools_tuple{1_ct,2_ct,3_ct,4_ct}); using result_t = meta::resolve_optype_t; - using expected_t = decltype(tuple{0_ct,1_ct,2_ct,3_ct}); + using expected_t = decltype(nmtools_tuple{0_ct,1_ct,2_ct,3_ct}); NMTOOLS_STATIC_CHECK_IS_SAME( result_t, expected_t ); } { - using array_t = decltype(tuple{2_ct,1_ct,3_ct,4_ct}); + using array_t = decltype(nmtools_tuple{2_ct,1_ct,3_ct,4_ct}); using result_t = meta::resolve_optype_t; - using expected_t = decltype(tuple{1_ct,0_ct,2_ct,3_ct}); + using expected_t = decltype(nmtools_tuple{1_ct,0_ct,2_ct,3_ct}); NMTOOLS_STATIC_CHECK_IS_SAME( result_t, expected_t ); } { - using array_t = decltype(tuple{3_ct,1_ct,2_ct,4_ct}); + using array_t = decltype(nmtools_tuple{3_ct,1_ct,2_ct,4_ct}); using result_t = meta::resolve_optype_t; - using expected_t = decltype(tuple{1_ct,2_ct,0_ct,3_ct}); + using expected_t = decltype(nmtools_tuple{1_ct,2_ct,0_ct,3_ct}); NMTOOLS_STATIC_CHECK_IS_SAME( result_t, expected_t ); } } \ No newline at end of file diff --git a/tests/meta/array/index/broadcast_shape.cpp b/tests/meta/array/index/broadcast_shape.cpp index e6cf26e8f..d8e90c6ab 100644 --- a/tests/meta/array/index/broadcast_shape.cpp +++ b/tests/meta/array/index/broadcast_shape.cpp @@ -133,31 +133,31 @@ using nmtools_tuple; TEST_CASE("broadcast_shape" * doctest::test_suite("index")) { { - using ashape_t = decltype(tuple{5_ct,4_ct}); - using bshape_t = decltype(tuple{1_ct}); + using ashape_t = decltype(nmtools_tuple{5_ct,4_ct}); + using bshape_t = decltype(nmtools_tuple{1_ct}); using result_t = meta::resolve_optype_t; - using expected_t = decltype(tuple{5_ct,4_ct}); + using expected_t = decltype(nmtools_tuple{5_ct,4_ct}); NMTOOLS_STATIC_CHECK_IS_SAME( result_t, expected_t ); } { - using ashape_t = decltype(tuple{5_ct,4_ct}); - using bshape_t = decltype(tuple{1_ct}); + using ashape_t = decltype(nmtools_tuple{5_ct,4_ct}); + using bshape_t = decltype(nmtools_tuple{1_ct}); using result_t = meta::resolve_optype_t; - using expected_t = decltype(tuple{5_ct,4_ct}); + using expected_t = decltype(nmtools_tuple{5_ct,4_ct}); NMTOOLS_STATIC_CHECK_IS_SAME( result_t, expected_t ); } { - using ashape_t = decltype(tuple{5_ct,4_ct}); - using bshape_t = decltype(tuple{4_ct}); + using ashape_t = decltype(nmtools_tuple{5_ct,4_ct}); + using bshape_t = decltype(nmtools_tuple{4_ct}); using result_t = meta::resolve_optype_t; - using expected_t = decltype(tuple{5_ct,4_ct}); + using expected_t = decltype(nmtools_tuple{5_ct,4_ct}); NMTOOLS_STATIC_CHECK_IS_SAME( result_t, expected_t ); } { - using ashape_t = decltype(tuple{8_ct,1_ct,6_ct,1_ct}); - using bshape_t = decltype(tuple{7_ct,1_ct,5_ct}); + using ashape_t = decltype(nmtools_tuple{8_ct,1_ct,6_ct,1_ct}); + using bshape_t = decltype(nmtools_tuple{7_ct,1_ct,5_ct}); using result_t = meta::resolve_optype_t; - using expected_t = decltype(tuple{8_ct,7_ct,6_ct,5_ct}); + using expected_t = decltype(nmtools_tuple{8_ct,7_ct,6_ct,5_ct}); NMTOOLS_STATIC_CHECK_IS_SAME( result_t, expected_t ); } } \ No newline at end of file diff --git a/tests/meta/array/index/compute_strides.cpp b/tests/meta/array/index/compute_strides.cpp index 405a5c3e8..f47153f9e 100644 --- a/tests/meta/array/index/compute_strides.cpp +++ b/tests/meta/array/index/compute_strides.cpp @@ -14,27 +14,27 @@ using nmtools_tuple; TEST_CASE("computes_strides" * doctest::test_suite("index")) { { - using shape_t = decltype(tuple{3_ct}); + using shape_t = decltype(nmtools_tuple{3_ct}); using strides_t = meta::resolve_optype_t; - using expect_t = decltype(tuple{1_ct}); + using expect_t = decltype(nmtools_tuple{1_ct}); NMTOOLS_STATIC_CHECK_IS_SAME( strides_t, expect_t ); } { - using shape_t = decltype(tuple{3_ct,2_ct}); + using shape_t = decltype(nmtools_tuple{3_ct,2_ct}); using strides_t = meta::resolve_optype_t; - using expect_t = decltype(tuple{2_ct,1_ct}); + using expect_t = decltype(nmtools_tuple{2_ct,1_ct}); NMTOOLS_STATIC_CHECK_IS_SAME( strides_t, expect_t ); } { - using shape_t = decltype(tuple{3_ct,2_ct,1_ct}); + using shape_t = decltype(nmtools_tuple{3_ct,2_ct,1_ct}); using strides_t = meta::resolve_optype_t; - using expect_t = decltype(tuple{2_ct,1_ct,1_ct}); + using expect_t = decltype(nmtools_tuple{2_ct,1_ct,1_ct}); NMTOOLS_STATIC_CHECK_IS_SAME( strides_t, expect_t ); } { - using shape_t = decltype(tuple{3_ct,2_ct,3_ct}); + using shape_t = decltype(nmtools_tuple{3_ct,2_ct,3_ct}); using strides_t = meta::resolve_optype_t; - using expect_t = decltype(tuple{6_ct,3_ct,1_ct}); + using expect_t = decltype(nmtools_tuple{6_ct,3_ct,1_ct}); NMTOOLS_STATIC_CHECK_IS_SAME( strides_t, expect_t ); } } \ No newline at end of file diff --git a/tests/meta/array/index/gather.cpp b/tests/meta/array/index/gather.cpp index 7e5053973..fd60e9791 100644 --- a/tests/meta/array/index/gather.cpp +++ b/tests/meta/array/index/gather.cpp @@ -197,45 +197,45 @@ TEST_CASE("gather" * doctest::test_suite("index")) } { - using vector_t = decltype(tuple{1_ct,2_ct,3_ct}); - using indices_t = decltype(tuple{0_ct,1_ct,2_ct}); + using vector_t = decltype(nmtools_tuple{1_ct,2_ct,3_ct}); + using indices_t = decltype(nmtools_tuple{0_ct,1_ct,2_ct}); using result_t = meta::resolve_optype_t; - using expect_t = decltype(tuple{1_ct,2_ct,3_ct}); + using expect_t = decltype(nmtools_tuple{1_ct,2_ct,3_ct}); NMTOOLS_STATIC_CHECK_IS_SAME( result_t, expect_t ); } { - using vector_t = decltype(tuple{1_ct,2_ct,3_ct}); - using indices_t = decltype(tuple{1_ct,0_ct,2_ct}); + using vector_t = decltype(nmtools_tuple{1_ct,2_ct,3_ct}); + using indices_t = decltype(nmtools_tuple{1_ct,0_ct,2_ct}); using result_t = meta::resolve_optype_t; - using expect_t = decltype(tuple{2_ct,1_ct,3_ct}); + using expect_t = decltype(nmtools_tuple{2_ct,1_ct,3_ct}); NMTOOLS_STATIC_CHECK_IS_SAME( result_t, expect_t ); } { - using vector_t = decltype(tuple{1_ct,2_ct,3_ct}); - using indices_t = decltype(tuple{1_ct,2_ct,0_ct}); + using vector_t = decltype(nmtools_tuple{1_ct,2_ct,3_ct}); + using indices_t = decltype(nmtools_tuple{1_ct,2_ct,0_ct}); using result_t = meta::resolve_optype_t; - using expect_t = decltype(tuple{2_ct,3_ct,1_ct}); + using expect_t = decltype(nmtools_tuple{2_ct,3_ct,1_ct}); NMTOOLS_STATIC_CHECK_IS_SAME( result_t, expect_t ); } { - using vector_t = decltype(tuple{1_ct,2_ct,3_ct}); - using indices_t = decltype(tuple{2_ct,0_ct,1_ct}); + using vector_t = decltype(nmtools_tuple{1_ct,2_ct,3_ct}); + using indices_t = decltype(nmtools_tuple{2_ct,0_ct,1_ct}); using result_t = meta::resolve_optype_t; - using expect_t = decltype(tuple{3_ct,1_ct,2_ct}); + using expect_t = decltype(nmtools_tuple{3_ct,1_ct,2_ct}); NMTOOLS_STATIC_CHECK_IS_SAME( result_t, expect_t ); } { - using vector_t = decltype(tuple{1_ct,2_ct,3_ct}); - using indices_t = decltype(tuple{2_ct,1_ct,0_ct}); + using vector_t = decltype(nmtools_tuple{1_ct,2_ct,3_ct}); + using indices_t = decltype(nmtools_tuple{2_ct,1_ct,0_ct}); using result_t = meta::resolve_optype_t; - using expect_t = decltype(tuple{3_ct,2_ct,1_ct}); + using expect_t = decltype(nmtools_tuple{3_ct,2_ct,1_ct}); NMTOOLS_STATIC_CHECK_IS_SAME( result_t, expect_t ); } { - using vector_t = decltype(tuple{1_ct,2_ct,3_ct,4_ct,5_ct}); - using indices_t = decltype(tuple{2_ct,1_ct,0_ct}); + using vector_t = decltype(nmtools_tuple{1_ct,2_ct,3_ct,4_ct,5_ct}); + using indices_t = decltype(nmtools_tuple{2_ct,1_ct,0_ct}); using result_t = meta::resolve_optype_t; - using expect_t = decltype(tuple{3_ct,2_ct,1_ct}); + using expect_t = decltype(nmtools_tuple{3_ct,2_ct,1_ct}); NMTOOLS_STATIC_CHECK_IS_SAME( result_t, expect_t ); } } \ No newline at end of file diff --git a/tests/meta/array/index/logical_not.cpp b/tests/meta/array/index/logical_not.cpp index 237f9c00b..35d5216b9 100644 --- a/tests/meta/array/index/logical_not.cpp +++ b/tests/meta/array/index/logical_not.cpp @@ -17,10 +17,10 @@ using std::tuple, std::false_type, std::true_type; TEST_CASE("logical_not" * doctest::test_suite("index")) { { - using x_t = decltype(tuple{true_type{},false_type{},false_type{},true_type{},false_type{}}); + using x_t = decltype(nmtools_tuple{true_type{},false_type{},false_type{},true_type{},false_type{}}); using res_t = meta::resolve_optype_t; - // using exp_t = decltype(tuple{meta::false_type{},meta::true_type{},meta::true_type{},meta::false_type{},meta::true_type{}}); - using exp_t = decltype(tuple{meta::integral_constant{},meta::integral_constant{},meta::integral_constant{},meta::integral_constant{},meta::integral_constant{}}); + // using exp_t = decltype(nmtools_tuple{meta::false_type{},meta::true_type{},meta::true_type{},meta::false_type{},meta::true_type{}}); + using exp_t = decltype(nmtools_tuple{meta::integral_constant{},meta::integral_constant{},meta::integral_constant{},meta::integral_constant{},meta::integral_constant{}}); NMTOOLS_STATIC_CHECK_IS_SAME( res_t, exp_t ); } } \ No newline at end of file diff --git a/tests/meta/array/index/remove_single_dims.cpp b/tests/meta/array/index/remove_single_dims.cpp index d680d5e87..036778d0e 100644 --- a/tests/meta/array/index/remove_single_dims.cpp +++ b/tests/meta/array/index/remove_single_dims.cpp @@ -19,9 +19,9 @@ using std::tuple; TEST_CASE("remove_single_dims" * doctest::test_suite("index")) { { - using shape_t = decltype(tuple{1_ct,2_ct,3_ct}); + using shape_t = decltype(nmtools_tuple{1_ct,2_ct,3_ct}); using result_t = meta::resolve_optype_t; - using expected_t = decltype(tuple{2_ct,3_ct}); + using expected_t = decltype(nmtools_tuple{2_ct,3_ct}); NMTOOLS_STATIC_CHECK_IS_SAME( result_t, expected_t ); } } \ No newline at end of file diff --git a/tests/meta/array/index/scatter.cpp b/tests/meta/array/index/scatter.cpp index 8272526a7..d9f0cda07 100644 --- a/tests/meta/array/index/scatter.cpp +++ b/tests/meta/array/index/scatter.cpp @@ -15,17 +15,17 @@ using nmtools_tuple; TEST_CASE("scatter" * doctest::test_suite("index")) { { - using indices_t = decltype(tuple{1_ct,2_ct,3_ct}); - using order_t = decltype(tuple{0_ct,1_ct,2_ct}); + using indices_t = decltype(nmtools_tuple{1_ct,2_ct,3_ct}); + using order_t = decltype(nmtools_tuple{0_ct,1_ct,2_ct}); using result_t = meta::resolve_optype_t; - using expect_t = decltype(tuple{1_ct,2_ct,3_ct}); + using expect_t = decltype(nmtools_tuple{1_ct,2_ct,3_ct}); NMTOOLS_STATIC_CHECK_IS_SAME( result_t, expect_t ); } { - using indices_t = decltype(tuple{1_ct,2_ct,3_ct}); - using order_t = decltype(tuple{1_ct,0_ct,2_ct}); + using indices_t = decltype(nmtools_tuple{1_ct,2_ct,3_ct}); + using order_t = decltype(nmtools_tuple{1_ct,0_ct,2_ct}); using result_t = meta::resolve_optype_t; - using expect_t = decltype(tuple{2_ct,1_ct,3_ct}); + using expect_t = decltype(nmtools_tuple{2_ct,1_ct,3_ct}); NMTOOLS_STATIC_CHECK_IS_SAME( result_t, expect_t ); } } \ No newline at end of file diff --git a/tests/meta/array/index/sum.cpp b/tests/meta/array/index/sum.cpp index 8cf7ab815..4bebe4ead 100644 --- a/tests/meta/array/index/sum.cpp +++ b/tests/meta/array/index/sum.cpp @@ -15,7 +15,7 @@ using nmtools_tuple; TEST_CASE("sum" * doctest::test_suite("index")) { { - using array_t = decltype(tuple{1_ct,2_ct,3_ct}); + using array_t = decltype(nmtools_tuple{1_ct,2_ct,3_ct}); using result_t = meta::resolve_optype_t; using expect_t = decltype(6_ct); NMTOOLS_STATIC_CHECK_IS_SAME( result_t, expect_t ); diff --git a/tests/meta/array/view/moveaxis.cpp b/tests/meta/array/view/moveaxis.cpp index 3982dbc35..4bf1d0a15 100644 --- a/tests/meta/array/view/moveaxis.cpp +++ b/tests/meta/array/view/moveaxis.cpp @@ -23,7 +23,7 @@ TEST_CASE("moveaxis(case1)" * doctest::test_suite("meta::moveaxis")) using array_type = na::ndarray_t; using src_type = decltype(0_ct); using dst_type = decltype(1_ct); - using view_type = decltype(view::moveaxis(meta::declval(),meta::declval(),meta::declval())); + using view_type = decltype(nmtools::unwrap(view::moveaxis(meta::declval(),meta::declval(),meta::declval()))); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_shape, view_type ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_dim, view_type ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_size, view_type ); @@ -51,7 +51,7 @@ TEST_CASE("moveaxis(case1)" * doctest::test_suite("meta::moveaxis")) using array_type = na::ndarray_t; using src_type = decltype(0_ct); using dst_type = decltype(1_ct); - using view_type = decltype(view::moveaxis(meta::declval(),meta::declval(),meta::declval())); + using view_type = decltype(nmtools::unwrap(view::moveaxis(meta::declval(),meta::declval(),meta::declval()))); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_shape, view_type ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_dim, view_type ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_size, view_type ); @@ -78,7 +78,7 @@ TEST_CASE("moveaxis(case1)" * doctest::test_suite("meta::moveaxis")) using array_type = na::ndarray_t; using src_type = decltype(0_ct); using dst_type = decltype(1_ct); - using view_type = decltype(view::moveaxis(meta::declval(),meta::declval(),meta::declval())); + using view_type = decltype(nmtools::unwrap(view::moveaxis(meta::declval(),meta::declval(),meta::declval()))); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_shape, view_type ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_dim, view_type ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_size, view_type ); @@ -106,7 +106,7 @@ TEST_CASE("moveaxis(case1)" * doctest::test_suite("meta::moveaxis")) using array_type = na::ndarray_t; using src_type = decltype(0_ct); using dst_type = decltype(1_ct); - using view_type = decltype(view::moveaxis(meta::declval(),meta::declval(),meta::declval())); + using view_type = decltype(nmtools::unwrap(view::moveaxis(meta::declval(),meta::declval(),meta::declval()))); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_shape, view_type ); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_dim, view_type ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_size, view_type ); @@ -133,7 +133,7 @@ TEST_CASE("moveaxis(case1)" * doctest::test_suite("meta::moveaxis")) using array_type = na::ndarray_t; using src_type = decltype(0_ct); using dst_type = decltype(1_ct); - using view_type = decltype(view::moveaxis(meta::declval(),meta::declval(),meta::declval())); + using view_type = decltype(nmtools::unwrap(view::moveaxis(meta::declval(),meta::declval(),meta::declval()))); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_shape, view_type ); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_dim, view_type ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_size, view_type ); @@ -161,7 +161,7 @@ TEST_CASE("moveaxis(case1)" * doctest::test_suite("meta::moveaxis")) using array_type = na::ndarray_t; using src_type = decltype(0_ct); using dst_type = decltype(1_ct); - using view_type = decltype(view::moveaxis(meta::declval(),meta::declval(),meta::declval())); + using view_type = decltype(nmtools::unwrap(view::moveaxis(meta::declval(),meta::declval(),meta::declval()))); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_shape, view_type ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_dim, view_type ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_size, view_type ); @@ -189,7 +189,7 @@ TEST_CASE("moveaxis(case1)" * doctest::test_suite("meta::moveaxis")) using array_type = na::ndarray_t; using src_type = decltype(0_ct); using dst_type = decltype(1_ct); - using view_type = decltype(view::moveaxis(meta::declval(),meta::declval(),meta::declval())); + using view_type = decltype(nmtools::unwrap(view::moveaxis(meta::declval(),meta::declval(),meta::declval()))); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_shape, view_type ); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_dim, view_type ); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_size, view_type ); @@ -216,7 +216,7 @@ TEST_CASE("moveaxis(case1)" * doctest::test_suite("meta::moveaxis")) using array_type = na::ndarray_t; using src_type = decltype(0_ct); using dst_type = decltype(1_ct); - using view_type = decltype(view::moveaxis(meta::declval(),meta::declval(),meta::declval())); + using view_type = decltype(nmtools::unwrap(view::moveaxis(meta::declval(),meta::declval(),meta::declval()))); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_shape, view_type ); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_dim, view_type ); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_size, view_type ); @@ -243,7 +243,7 @@ TEST_CASE("moveaxis(case1)" * doctest::test_suite("meta::moveaxis")) using array_type = na::ndarray_t; using src_type = decltype(0_ct); using dst_type = decltype(1_ct); - using view_type = decltype(view::moveaxis(meta::declval(),meta::declval(),meta::declval())); + using view_type = decltype(nmtools::unwrap(view::moveaxis(meta::declval(),meta::declval(),meta::declval()))); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_shape, view_type ); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_dim, view_type ); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_size, view_type ); @@ -270,7 +270,7 @@ TEST_CASE("moveaxis(case1)" * doctest::test_suite("meta::moveaxis")) using array_type = na::ndarray_t; using src_type = decltype(0_ct); using dst_type = decltype(1_ct); - using view_type = decltype(view::moveaxis(meta::declval(),meta::declval(),meta::declval())); + using view_type = decltype(nmtools::unwrap(view::moveaxis(meta::declval(),meta::declval(),meta::declval()))); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_shape, view_type ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_dim, view_type ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_size, view_type ); @@ -297,7 +297,7 @@ TEST_CASE("moveaxis(case1)" * doctest::test_suite("meta::moveaxis")) using array_type = na::ndarray_t; using src_type = decltype(0_ct); using dst_type = decltype(1_ct); - using view_type = decltype(view::moveaxis(meta::declval(),meta::declval(),meta::declval())); + using view_type = decltype(nmtools::unwrap(view::moveaxis(meta::declval(),meta::declval(),meta::declval()))); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_shape, view_type ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_dim, view_type ); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_size, view_type ); @@ -324,7 +324,7 @@ TEST_CASE("moveaxis(case1)" * doctest::test_suite("meta::moveaxis")) using array_type = na::ndarray_t; using src_type = decltype(0_ct); using dst_type = decltype(1_ct); - using view_type = decltype(view::moveaxis(meta::declval(),meta::declval(),meta::declval())); + using view_type = decltype(nmtools::unwrap(view::moveaxis(meta::declval(),meta::declval(),meta::declval()))); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_shape, view_type ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_dim, view_type ); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_size, view_type ); @@ -351,7 +351,7 @@ TEST_CASE("moveaxis(case1)" * doctest::test_suite("meta::moveaxis")) using array_type = na::ndarray_t; using src_type = decltype(0_ct); using dst_type = decltype(1_ct); - using view_type = decltype(view::moveaxis(meta::declval(),meta::declval(),meta::declval())); + using view_type = decltype(nmtools::unwrap(view::moveaxis(meta::declval(),meta::declval(),meta::declval()))); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_shape, view_type ); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_dim, view_type ); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_size, view_type ); @@ -378,7 +378,7 @@ TEST_CASE("moveaxis(case1)" * doctest::test_suite("meta::moveaxis")) using array_type = na::ndarray_t; using src_type = decltype(0_ct); using dst_type = decltype(1_ct); - using view_type = decltype(view::moveaxis(meta::declval(),meta::declval(),meta::declval())); + using view_type = decltype(nmtools::unwrap(view::moveaxis(meta::declval(),meta::declval(),meta::declval()))); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_shape, view_type ); NMTOOLS_STATIC_CHECK_TRAIT_FALSE( meta::is_fixed_dim, view_type ); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_fixed_size, view_type ); diff --git a/tests/utl/utl/CMakeLists.txt b/tests/utl/utl/CMakeLists.txt index b737e7cf6..a7bce4669 100644 --- a/tests/utl/utl/CMakeLists.txt +++ b/tests/utl/utl/CMakeLists.txt @@ -11,6 +11,7 @@ add_executable(${PROJECT_NAME} tests.cpp src/vector.cpp src/clipped_integer.cpp src/static_vector.cpp + src/tuplev2.cpp ) add_test( NAME ${PROJECT_NAME} diff --git a/tests/utl/utl/src/tuplev2.cpp b/tests/utl/utl/src/tuplev2.cpp new file mode 100644 index 000000000..56f79b8b4 --- /dev/null +++ b/tests/utl/utl/src/tuplev2.cpp @@ -0,0 +1,419 @@ +#include "nmtools/utl/tuplev2.hpp" +#include "nmtools/testing/doctest.hpp" + +namespace nm = nmtools; +namespace utl = nm::utl; + +TEST_CASE("tuplev2(default_constructor)" * doctest::test_suite("utl")) +{ + utl::tuplev2 tp{}; + + utl::tuplev2 tp4{}; + + utl::tuplev2 tp8{}; + + utl::tuplev2 tp16{}; + + NMTOOLS_ASSERT_EQUAL( utl::tuple_size_v, 1 ); + NMTOOLS_ASSERT_EQUAL( utl::tuple_size_v, 4 ); + NMTOOLS_ASSERT_EQUAL( utl::tuple_size_v, 8 ); + NMTOOLS_ASSERT_EQUAL( utl::tuple_size_v, 16 ); + + { + using element_t = utl::tuple_element_t<0,decltype(tp)>; + NMTOOLS_STATIC_CHECK_IS_SAME( element_t, double ); + } + { + using element_t = utl::tuple_element_t<1,decltype(tp4)>; + NMTOOLS_STATIC_CHECK_IS_SAME( element_t, int ); + } + { + using element_t = utl::tuple_element_t<2,decltype(tp4)>; + NMTOOLS_STATIC_CHECK_IS_SAME( element_t, unsigned int ); + } + { + using element_t = utl::tuple_element_t<3,decltype(tp4)>; + NMTOOLS_STATIC_CHECK_IS_SAME( element_t, float ); + } + { + using element_t = utl::tuple_element_t<4,decltype(tp8)>; + NMTOOLS_STATIC_CHECK_IS_SAME( element_t, char ); + } + { + using element_t = utl::tuple_element_t<5,decltype(tp8)>; + NMTOOLS_STATIC_CHECK_IS_SAME( element_t, unsigned char ); + } + { + using element_t = utl::tuple_element_t<6,decltype(tp8)>; + NMTOOLS_STATIC_CHECK_IS_SAME( element_t, short ); + } + { + using element_t = utl::tuple_element_t<7,decltype(tp8)>; + NMTOOLS_STATIC_CHECK_IS_SAME( element_t, unsigned short ); + } + { + using element_t = utl::tuple_element_t<8,decltype(tp16)>; + NMTOOLS_STATIC_CHECK_IS_SAME( element_t, double ); + } + { + using element_t = utl::tuple_element_t<9,decltype(tp16)>; + NMTOOLS_STATIC_CHECK_IS_SAME( element_t, int ); + } + { + using element_t = utl::tuple_element_t<10,decltype(tp16)>; + NMTOOLS_STATIC_CHECK_IS_SAME( element_t, unsigned int ); + } + { + using element_t = utl::tuple_element_t<11,decltype(tp16)>; + NMTOOLS_STATIC_CHECK_IS_SAME( element_t, float ); + } + { + using element_t = utl::tuple_element_t<12,decltype(tp16)>; + NMTOOLS_STATIC_CHECK_IS_SAME( element_t, char ); + } + { + using element_t = utl::tuple_element_t<13,decltype(tp16)>; + NMTOOLS_STATIC_CHECK_IS_SAME( element_t, unsigned char ); + } + { + using element_t = utl::tuple_element_t<14,decltype(tp16)>; + NMTOOLS_STATIC_CHECK_IS_SAME( element_t, short ); + } + { + using element_t = utl::tuple_element_t<15,decltype(tp16)>; + NMTOOLS_STATIC_CHECK_IS_SAME( element_t, unsigned short ); + } +} + +TEST_CASE("tuplev2(get)" * doctest::test_suite("utl")) +{ + utl::tuplev2 tp{}; + + utl::tuplev2 tp4{}; + + utl::tuplev2 tp8{}; + + utl::tuplev2 tp16{}; + + NMTOOLS_ASSERT_CLOSE( utl::get<0>(tp), 0.0 ); + NMTOOLS_ASSERT_EQUAL( utl::get<1>(tp4), 0 ); + NMTOOLS_ASSERT_EQUAL( utl::get<2>(tp4), 0 ); + NMTOOLS_ASSERT_CLOSE( utl::get<3>(tp4), 0.0 ); + NMTOOLS_ASSERT_EQUAL( utl::get<4>(tp8), 0 ); + NMTOOLS_ASSERT_EQUAL( utl::get<5>(tp8), 0 ); + NMTOOLS_ASSERT_EQUAL( utl::get<6>(tp8), 0 ); + NMTOOLS_ASSERT_EQUAL( utl::get<7>(tp8), 0 ); + NMTOOLS_ASSERT_CLOSE( utl::get<8>(tp16), 0 ); + NMTOOLS_ASSERT_EQUAL( utl::get<9>(tp16), 0 ); + NMTOOLS_ASSERT_EQUAL( utl::get<10>(tp16), 0 ); + NMTOOLS_ASSERT_CLOSE( utl::get<11>(tp16), 0.0 ); + NMTOOLS_ASSERT_EQUAL( utl::get<12>(tp16), 0 ); + NMTOOLS_ASSERT_EQUAL( utl::get<13>(tp16), 0 ); + NMTOOLS_ASSERT_EQUAL( utl::get<14>(tp16), 0 ); + NMTOOLS_ASSERT_EQUAL( utl::get<15>(tp16), 0 ); +} + +TEST_CASE("tuplev2(constructor)" * doctest::test_suite("utl")) +{ + using tuple1_t = utl::tuplev2; + tuple1_t tp{1.}; + + using tuple4_t = utl::tuplev2; + tuple4_t tp4{1.,2,3,4.}; + + using tuple8_t = utl::tuplev2; + tuple8_t tp8{1.,2,3,4.,5,6,7,8}; + + using tuple16_t = utl::tuplev2; + tuple16_t tp16{1.,2,3,4.,5,6,7,8,9.,10,11,12.,13,14,15,16}; + + NMTOOLS_ASSERT_EQUAL( utl::tuple_size_v, 1 ); + NMTOOLS_ASSERT_EQUAL( utl::tuple_size_v, 4 ); + NMTOOLS_ASSERT_EQUAL( utl::tuple_size_v, 8 ); + NMTOOLS_ASSERT_EQUAL( utl::tuple_size_v, 16 ); + + NMTOOLS_ASSERT_CLOSE( utl::get<0>(tp), 1.0 ); + NMTOOLS_ASSERT_EQUAL( utl::get<1>(tp4), 2 ); + NMTOOLS_ASSERT_EQUAL( utl::get<2>(tp4), 3 ); + NMTOOLS_ASSERT_CLOSE( utl::get<3>(tp4), 4.0 ); + NMTOOLS_ASSERT_EQUAL( utl::get<4>(tp8), 5 ); + NMTOOLS_ASSERT_EQUAL( utl::get<5>(tp8), 6 ); + NMTOOLS_ASSERT_EQUAL( utl::get<6>(tp8), 7 ); + NMTOOLS_ASSERT_EQUAL( utl::get<7>(tp8), 8 ); + NMTOOLS_ASSERT_CLOSE( utl::get<8>(tp16), 9 ); + NMTOOLS_ASSERT_EQUAL( utl::get<9>(tp16), 10 ); + NMTOOLS_ASSERT_EQUAL( utl::get<10>(tp16), 11 ); + NMTOOLS_ASSERT_CLOSE( utl::get<11>(tp16), 12.0 ); + NMTOOLS_ASSERT_EQUAL( utl::get<12>(tp16), 13 ); + NMTOOLS_ASSERT_EQUAL( utl::get<13>(tp16), 14 ); + NMTOOLS_ASSERT_EQUAL( utl::get<14>(tp16), 15 ); + NMTOOLS_ASSERT_EQUAL( utl::get<15>(tp16), 16 ); +} + +TEST_CASE("tuplev2(copy_constructor)" * doctest::test_suite("utl")) +{ + using tuple1_t = utl::tuplev2; + tuple1_t tp{1.}; + + using tuple4_t = utl::tuplev2; + tuple4_t tp4{1.,2,3,4.}; + + using tuple8_t = utl::tuplev2; + tuple8_t tp8{1.,2,3,4.,5,6,7,8}; + + using tuple16_t = utl::tuplev2; + tuple16_t tp16{1.,2,3,4.,5,6,7,8,9.,10,11,12.,13,14,15,16}; + + tuple1_t c_tp(tp); + tuple4_t c_tp4(tp4); + tuple8_t c_tp8(tp8); + tuple16_t c_tp16(tp16); + + NMTOOLS_ASSERT_CLOSE( utl::get<0>(c_tp), 1.0 ); + NMTOOLS_ASSERT_EQUAL( utl::get<1>(c_tp4), 2 ); + NMTOOLS_ASSERT_EQUAL( utl::get<2>(c_tp4), 3 ); + NMTOOLS_ASSERT_CLOSE( utl::get<3>(c_tp4), 4.0 ); + NMTOOLS_ASSERT_EQUAL( utl::get<4>(c_tp8), 5 ); + NMTOOLS_ASSERT_EQUAL( utl::get<5>(c_tp8), 6 ); + NMTOOLS_ASSERT_EQUAL( utl::get<6>(c_tp8), 7 ); + NMTOOLS_ASSERT_EQUAL( utl::get<7>(c_tp8), 8 ); + NMTOOLS_ASSERT_CLOSE( utl::get<8>(c_tp16), 9 ); + NMTOOLS_ASSERT_EQUAL( utl::get<9>(c_tp16), 10 ); + NMTOOLS_ASSERT_EQUAL( utl::get<10>(c_tp16), 11 ); + NMTOOLS_ASSERT_CLOSE( utl::get<11>(c_tp16), 12.0 ); + NMTOOLS_ASSERT_EQUAL( utl::get<12>(c_tp16), 13 ); + NMTOOLS_ASSERT_EQUAL( utl::get<13>(c_tp16), 14 ); + NMTOOLS_ASSERT_EQUAL( utl::get<14>(c_tp16), 15 ); + NMTOOLS_ASSERT_EQUAL( utl::get<15>(c_tp16), 16 ); +} + +TEST_CASE("tuplev2(copy_assignment)" * doctest::test_suite("utl")) +{ + using tuple1_t = utl::tuplev2; + tuple1_t tp{1.}; + + using tuple4_t = utl::tuplev2; + tuple4_t tp4{1.,2,3,4.}; + + using tuple8_t = utl::tuplev2; + tuple8_t tp8{1.,2,3,4.,5,6,7,8}; + + using tuple16_t = utl::tuplev2; + tuple16_t tp16{1.,2,3,4.,5,6,7,8,9.,10,11,12.,13,14,15,16}; + + tuple1_t c_tp{}; + c_tp = tp; + + tuple4_t c_tp4{}; + c_tp4 = tp4; + + tuple8_t c_tp8{}; + c_tp8 = tp8; + + tuple16_t c_tp16{}; + c_tp16 = tp16; + + NMTOOLS_ASSERT_CLOSE( utl::get<0>(c_tp), 1.0 ); + NMTOOLS_ASSERT_EQUAL( utl::get<1>(c_tp4), 2 ); + NMTOOLS_ASSERT_EQUAL( utl::get<2>(c_tp4), 3 ); + NMTOOLS_ASSERT_CLOSE( utl::get<3>(c_tp4), 4.0 ); + NMTOOLS_ASSERT_EQUAL( utl::get<4>(c_tp8), 5 ); + NMTOOLS_ASSERT_EQUAL( utl::get<5>(c_tp8), 6 ); + NMTOOLS_ASSERT_EQUAL( utl::get<6>(c_tp8), 7 ); + NMTOOLS_ASSERT_EQUAL( utl::get<7>(c_tp8), 8 ); + NMTOOLS_ASSERT_CLOSE( utl::get<8>(c_tp16), 9 ); + NMTOOLS_ASSERT_EQUAL( utl::get<9>(c_tp16), 10 ); + NMTOOLS_ASSERT_EQUAL( utl::get<10>(c_tp16), 11 ); + NMTOOLS_ASSERT_CLOSE( utl::get<11>(c_tp16), 12.0 ); + NMTOOLS_ASSERT_EQUAL( utl::get<12>(c_tp16), 13 ); + NMTOOLS_ASSERT_EQUAL( utl::get<13>(c_tp16), 14 ); + NMTOOLS_ASSERT_EQUAL( utl::get<14>(c_tp16), 15 ); + NMTOOLS_ASSERT_EQUAL( utl::get<15>(c_tp16), 16 ); +} + +TEST_CASE("tuplev2(constructor)" * doctest::test_suite("utl")) +{ + using tuple1_t = utl::tuplev2; + constexpr tuple1_t tp{1.}; + + using tuple4_t = utl::tuplev2; + constexpr tuple4_t tp4{1.,2,3,4.}; + + using tuple8_t = utl::tuplev2; + constexpr tuple8_t tp8{1.,2,3,4.,5,6,7,8}; + + using tuple16_t = utl::tuplev2; + constexpr tuple16_t tp16{1.,2,3,4.,5,6,7,8,9.,10,11,12.,13,14,15,16}; + + NMTOOLS_ASSERT_EQUAL( utl::tuple_size_v, 1 ); + NMTOOLS_ASSERT_EQUAL( utl::tuple_size_v, 4 ); + NMTOOLS_ASSERT_EQUAL( utl::tuple_size_v, 8 ); + NMTOOLS_ASSERT_EQUAL( utl::tuple_size_v, 16 ); + + NMTOOLS_ASSERT_CLOSE( utl::get<0>(tp), 1.0 ); + NMTOOLS_ASSERT_EQUAL( utl::get<1>(tp4), 2 ); + NMTOOLS_ASSERT_EQUAL( utl::get<2>(tp4), 3 ); + NMTOOLS_ASSERT_CLOSE( utl::get<3>(tp4), 4.0 ); + NMTOOLS_ASSERT_EQUAL( utl::get<4>(tp8), 5 ); + NMTOOLS_ASSERT_EQUAL( utl::get<5>(tp8), 6 ); + NMTOOLS_ASSERT_EQUAL( utl::get<6>(tp8), 7 ); + NMTOOLS_ASSERT_EQUAL( utl::get<7>(tp8), 8 ); + NMTOOLS_ASSERT_CLOSE( utl::get<8>(tp16), 9 ); + NMTOOLS_ASSERT_EQUAL( utl::get<9>(tp16), 10 ); + NMTOOLS_ASSERT_EQUAL( utl::get<10>(tp16), 11 ); + NMTOOLS_ASSERT_CLOSE( utl::get<11>(tp16), 12.0 ); + NMTOOLS_ASSERT_EQUAL( utl::get<12>(tp16), 13 ); + NMTOOLS_ASSERT_EQUAL( utl::get<13>(tp16), 14 ); + NMTOOLS_ASSERT_EQUAL( utl::get<14>(tp16), 15 ); + NMTOOLS_ASSERT_EQUAL( utl::get<15>(tp16), 16 ); +} + +TEST_CASE("tuplev2(copy_constructor)" * doctest::test_suite("utl")) +{ + using tuple1_t = utl::tuplev2; + constexpr tuple1_t tp{1.}; + + using tuple4_t = utl::tuplev2; + constexpr tuple4_t tp4{1.,2,3,4.}; + + using tuple8_t = utl::tuplev2; + constexpr tuple8_t tp8{1.,2,3,4.,5,6,7,8}; + + using tuple16_t = utl::tuplev2; + constexpr tuple16_t tp16{1.,2,3,4.,5,6,7,8,9.,10,11,12.,13,14,15,16}; + + constexpr tuple1_t c_tp(tp); + constexpr tuple4_t c_tp4(tp4); + constexpr tuple8_t c_tp8(tp8); + constexpr tuple16_t c_tp16(tp16); + + NMTOOLS_ASSERT_CLOSE( utl::get<0>(c_tp), 1.0 ); + NMTOOLS_ASSERT_EQUAL( utl::get<1>(c_tp4), 2 ); + NMTOOLS_ASSERT_EQUAL( utl::get<2>(c_tp4), 3 ); + NMTOOLS_ASSERT_CLOSE( utl::get<3>(c_tp4), 4.0 ); + NMTOOLS_ASSERT_EQUAL( utl::get<4>(c_tp8), 5 ); + NMTOOLS_ASSERT_EQUAL( utl::get<5>(c_tp8), 6 ); + NMTOOLS_ASSERT_EQUAL( utl::get<6>(c_tp8), 7 ); + NMTOOLS_ASSERT_EQUAL( utl::get<7>(c_tp8), 8 ); + NMTOOLS_ASSERT_CLOSE( utl::get<8>(c_tp16), 9 ); + NMTOOLS_ASSERT_EQUAL( utl::get<9>(c_tp16), 10 ); + NMTOOLS_ASSERT_EQUAL( utl::get<10>(c_tp16), 11 ); + NMTOOLS_ASSERT_CLOSE( utl::get<11>(c_tp16), 12.0 ); + NMTOOLS_ASSERT_EQUAL( utl::get<12>(c_tp16), 13 ); + NMTOOLS_ASSERT_EQUAL( utl::get<13>(c_tp16), 14 ); + NMTOOLS_ASSERT_EQUAL( utl::get<14>(c_tp16), 15 ); + NMTOOLS_ASSERT_EQUAL( utl::get<15>(c_tp16), 16 ); +} + +TEST_CASE("tuplev2(constructor)" * doctest::test_suite("utl")) +{ + auto tp = utl::tuplev2{1.f}; + auto tp4 = utl::tuplev2{1.,2,3,4.}; + auto tp8 = utl::tuplev2{1.,2,3,4.,5,6,7,8}; + auto tp16 = utl::tuplev2{1.,2,3,4.,5,6,7,8,9.,10,11,12.,13,14,15,16}; + + NMTOOLS_ASSERT_CLOSE( utl::get<0>(tp), 1.0 ); + NMTOOLS_ASSERT_EQUAL( utl::get<1>(tp4), 2 ); + NMTOOLS_ASSERT_EQUAL( utl::get<2>(tp4), 3 ); + NMTOOLS_ASSERT_CLOSE( utl::get<3>(tp4), 4.0 ); + NMTOOLS_ASSERT_EQUAL( utl::get<4>(tp8), 5 ); + NMTOOLS_ASSERT_EQUAL( utl::get<5>(tp8), 6 ); + NMTOOLS_ASSERT_EQUAL( utl::get<6>(tp8), 7 ); + NMTOOLS_ASSERT_EQUAL( utl::get<7>(tp8), 8 ); + NMTOOLS_ASSERT_CLOSE( utl::get<8>(tp16), 9 ); + NMTOOLS_ASSERT_EQUAL( utl::get<9>(tp16), 10 ); + NMTOOLS_ASSERT_EQUAL( utl::get<10>(tp16), 11 ); + NMTOOLS_ASSERT_CLOSE( utl::get<11>(tp16), 12.0 ); + NMTOOLS_ASSERT_EQUAL( utl::get<12>(tp16), 13 ); + NMTOOLS_ASSERT_EQUAL( utl::get<13>(tp16), 14 ); + NMTOOLS_ASSERT_EQUAL( utl::get<14>(tp16), 15 ); + NMTOOLS_ASSERT_EQUAL( utl::get<15>(tp16), 16 ); +} + +TEST_CASE("tuplev2(test1)" * doctest::test_suite("utl")) +{ + auto tp = utl::tuplev2{1.f}; + auto tp4 = utl::tuplev2{1.,2,3,4.}; + auto tp8 = utl::tuplev2{1.,2,3,4.,5,6,7,8}; + auto tp16 = utl::tuplev2{1.,2,3,4.,5,6,7,8,9.,10,11,12.,13,14,15,16}; + + utl::get<0>(tp) = 17; + utl::get<1>(tp4) = 18; + utl::get<2>(tp4) = 19; + utl::get<3>(tp4) = 20; + utl::get<4>(tp8) = 21; + utl::get<5>(tp8) = 22; + utl::get<6>(tp8) = 23; + utl::get<7>(tp8) = 24; + utl::get<8>(tp16) = 25; + utl::get<9>(tp16) = 26; + utl::get<10>(tp16) = 27; + utl::get<11>(tp16) = 28; + utl::get<12>(tp16) = 29; + utl::get<13>(tp16) = 30; + utl::get<14>(tp16) = 31; + utl::get<15>(tp16) = 32; + + NMTOOLS_ASSERT_CLOSE( utl::get<0>(tp), 17 ); + NMTOOLS_ASSERT_EQUAL( utl::get<1>(tp4), 18 ); + NMTOOLS_ASSERT_EQUAL( utl::get<2>(tp4), 19 ); + NMTOOLS_ASSERT_CLOSE( utl::get<3>(tp4), 20 ); + NMTOOLS_ASSERT_EQUAL( utl::get<4>(tp8), 21 ); + NMTOOLS_ASSERT_EQUAL( utl::get<5>(tp8), 22 ); + NMTOOLS_ASSERT_EQUAL( utl::get<6>(tp8), 23 ); + NMTOOLS_ASSERT_EQUAL( utl::get<7>(tp8), 24 ); + NMTOOLS_ASSERT_CLOSE( utl::get<8>(tp16), 25 ); + NMTOOLS_ASSERT_EQUAL( utl::get<9>(tp16), 26 ); + NMTOOLS_ASSERT_EQUAL( utl::get<10>(tp16), 27 ); + NMTOOLS_ASSERT_CLOSE( utl::get<11>(tp16), 28 ); + NMTOOLS_ASSERT_EQUAL( utl::get<12>(tp16), 29 ); + NMTOOLS_ASSERT_EQUAL( utl::get<13>(tp16), 30 ); + NMTOOLS_ASSERT_EQUAL( utl::get<14>(tp16), 31 ); + NMTOOLS_ASSERT_EQUAL( utl::get<15>(tp16), 32 ); +} + +TEST_CASE("tuplev2(test2)" * doctest::test_suite("utl")) +{ + // converting constructor + + using tuple1_t = utl::tuplev2; + tuple1_t tp{1.}; + + using tuple4_t = utl::tuplev2; + tuple4_t tp4{1.,2,3,4.}; + + using tuple8_t = utl::tuplev2; + tuple8_t tp8{1.,2,3,4.,5,6,7,8}; + + using tuple16_t = utl::tuplev2; + tuple16_t tp16{1.,2,3,4.,5,6,7,8,9.,10,11,12.,13,14,15,16}; + + using tuple1a_t = utl::tuplev2; + tuple1a_t tp_a{tp}; + + using tuple4a_t = utl::tuplev2; + tuple4a_t tp4_a{tp4}; + + using tuple8a_t = utl::tuplev2; + tuple8a_t tp8_a{tp8}; + + using tuple16a_t = utl::tuplev2; + tuple16a_t tp16_a{tp16}; + + NMTOOLS_ASSERT_CLOSE( utl::get<0>(tp_a), 1.0 ); + NMTOOLS_ASSERT_EQUAL( utl::get<1>(tp4_a), 2 ); + NMTOOLS_ASSERT_EQUAL( utl::get<2>(tp4_a), 3 ); + NMTOOLS_ASSERT_CLOSE( utl::get<3>(tp4_a), 4.0 ); + NMTOOLS_ASSERT_EQUAL( utl::get<4>(tp8_a), 5 ); + NMTOOLS_ASSERT_EQUAL( utl::get<5>(tp8_a), 6 ); + NMTOOLS_ASSERT_EQUAL( utl::get<6>(tp8_a), 7 ); + NMTOOLS_ASSERT_EQUAL( utl::get<7>(tp8_a), 8 ); + NMTOOLS_ASSERT_CLOSE( utl::get<8>(tp16_a), 9 ); + NMTOOLS_ASSERT_EQUAL( utl::get<9>(tp16_a), 10 ); + NMTOOLS_ASSERT_EQUAL( utl::get<10>(tp16_a), 11 ); + NMTOOLS_ASSERT_CLOSE( utl::get<11>(tp16_a), 12.0 ); + NMTOOLS_ASSERT_CLOSE( utl::get<12>(tp16_a), 13 ); + NMTOOLS_ASSERT_CLOSE( utl::get<13>(tp16_a), 14 ); + NMTOOLS_ASSERT_CLOSE( utl::get<14>(tp16_a), 15 ); + NMTOOLS_ASSERT_CLOSE( utl::get<15>(tp16_a), 16 ); +} \ No newline at end of file diff --git a/tests/view/CMakeLists.txt b/tests/view/CMakeLists.txt index b26d714c0..4b2cf881f 100644 --- a/tests/view/CMakeLists.txt +++ b/tests/view/CMakeLists.txt @@ -50,6 +50,7 @@ if (NMTOOLS_VIEW_TEST_ALL) endif (NMTOOLS_VIEW_TEST_ALL) set(ARRAY_VIEW_1_TEST_SOURCES + src/alias.cpp src/arange.cpp src/argsort.cpp ## TODO: fix diff --git a/tests/view/src/alias.cpp b/tests/view/src/alias.cpp new file mode 100644 index 000000000..a69d78832 --- /dev/null +++ b/tests/view/src/alias.cpp @@ -0,0 +1,105 @@ +#include "nmtools/array/view/alias.hpp" +#include "nmtools/array/view/arange.hpp" +#include "nmtools/array/view/atleast_nd.hpp" +#include "nmtools/testing/doctest.hpp" + +namespace view = nmtools::view; +namespace meta = nmtools::meta; + +using nmtools::utils::to_string; + +TEST_CASE("aliased(case1)" * doctest::test_suite("view::aliased")) +{ + int a[3] = {1,2,3}; + int b[2] = {4,5}; + auto aliased = view::aliased(a,b); + auto v_a = nmtools::get<0>(aliased); + auto v_b = nmtools::get<1>(aliased); + static_assert( meta::is_ndarray_v ); + static_assert( meta::is_ndarray_v ); + NMTOOLS_ASSERT_EQUAL( a, v_a ); + NMTOOLS_ASSERT_EQUAL( b, v_b ); + NMTOOLS_ASSERT_EQUAL( view::get_id_v, 0 ); + NMTOOLS_ASSERT_EQUAL( view::get_id_v, 1 ); + + { + constexpr auto type_id = meta::get_type_id_v; + CHECK_MESSAGE(true, to_string(type_id) ); + } + { + constexpr auto type_id = meta::get_type_id_v; + CHECK_MESSAGE(true, to_string(type_id) ); + } + { + constexpr auto type_id = meta::get_type_id_v; + CHECK_MESSAGE(true, to_string(type_id) ); + } + { + constexpr auto type_id = meta::get_type_id_v; + CHECK_MESSAGE(true, to_string(type_id) ); + } +} + +TEST_CASE("aliased(case2)" * doctest::test_suite("view::aliased")) +{ + int a[3] = {1,2,3}; + int b[2] = {4,5}; + int c[1][3] = {{6,7,8}}; + auto aliased = view::aliased(a,b,c); + auto v_a = nmtools::get<0>(aliased); + auto v_b = nmtools::get<1>(aliased); + auto v_c = nmtools::get<2>(aliased); + NMTOOLS_ASSERT_EQUAL( a, v_a ); + NMTOOLS_ASSERT_EQUAL( b, v_b ); + NMTOOLS_ASSERT_EQUAL( c, v_c ); + NMTOOLS_ASSERT_EQUAL( view::get_id_v, 0 ); + NMTOOLS_ASSERT_EQUAL( view::get_id_v, 1 ); + NMTOOLS_ASSERT_EQUAL( view::get_id_v, 2 ); + + static_assert( meta::has_id_type_v ); + static_assert( decltype(v_a)::id_type::value == 0 ); +} + +TEST_CASE("aliased(case2)" * doctest::test_suite("view::aliased")) +{ + int a[3] = {1,2,3}; + int b[2] = {4,5}; + auto c = view::arange(10); + auto aliased = view::aliased(a,b,c); + auto v_a = nmtools::get<0>(aliased); + auto v_b = nmtools::get<1>(aliased); + auto v_c = nmtools::get<2>(aliased); + NMTOOLS_ASSERT_CLOSE( a, v_a ); + NMTOOLS_ASSERT_CLOSE( b, v_b ); + NMTOOLS_ASSERT_CLOSE( c, v_c ); + // c is not aliased together with a & b + constexpr auto c_type_id = meta::get_type_id_v; + NMTOOLS_ASSERT_EQUAL( view::get_id_v, c_type_id ); + // not a simple 1 or 2 because c id is hashed + // NMTOOLS_ASSERT_EQUAL( view::get_id_v, 1 ); + // NMTOOLS_ASSERT_EQUAL( view::get_id_v, 2 ); + NMTOOLS_ASSERT_EQUAL( view::get_id_v, c_type_id ); +} + +TEST_CASE("aliased(case2)" * doctest::test_suite("view::aliased")) +{ + int a[3] = {1,2,3}; + int b[2] = {4,5}; + int a2d[1][3] = {{1,2,3}}; + auto c = view::arange(10); + auto aliased = view::aliased(a,b,c); + auto v_a = nmtools::get<0>(aliased); + auto v_b = nmtools::get<1>(aliased); + auto v_c = nmtools::get<2>(aliased); + auto v_a_2d = view::atleast_2d(v_a); + NMTOOLS_ASSERT_CLOSE( v_a, a ); + NMTOOLS_ASSERT_CLOSE( v_b, b ); + NMTOOLS_ASSERT_CLOSE( v_c, c ); + NMTOOLS_ASSERT_CLOSE( v_a_2d, a2d ); + // not a simple 1 or 2 because c id is hashed + // NMTOOLS_ASSERT_EQUAL( view::get_id_v, 0 ); + // NMTOOLS_ASSERT_EQUAL( view::get_id_v, 1 ); + // NMTOOLS_ASSERT_EQUAL( view::get_id_v, 2 ); + // NMTOOLS_ASSERT_EQUAL( view::get_id_v, 0 ); + // NMTOOLS_ASSERT_EQUAL( view::get_id_v, 2 ); +} \ No newline at end of file diff --git a/tests/view/src/slice.cpp b/tests/view/src/slice.cpp index 559771cd2..742b8469b 100644 --- a/tests/view/src/slice.cpp +++ b/tests/view/src/slice.cpp @@ -1348,7 +1348,7 @@ TEST_CASE("slice" * doctest::test_suite("view::slice")) SUBCASE("fixed_ndarray") { auto array = na::fixed_ndarray{{1,2,3}}; - auto slice = tuple{nm::None,nm::None}; + auto slice = nmtools_tuple{nm::None,nm::None}; auto sliced = view::slice(array,slice); using sliced_t = decltype(sliced); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_ndarray, sliced_t ); @@ -1356,7 +1356,7 @@ TEST_CASE("slice" * doctest::test_suite("view::slice")) SUBCASE("dynamic_ndarray") { auto array = na::dynamic_ndarray({1,2,3}); - auto slice = tuple{nm::None,nm::None}; + auto slice = nmtools_tuple{nm::None,nm::None}; auto sliced = view::slice(array,slice); using sliced_t = decltype(sliced); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_ndarray, sliced_t ); @@ -1364,7 +1364,7 @@ TEST_CASE("slice" * doctest::test_suite("view::slice")) SUBCASE("hybrid_ndarray") { auto array = na::hybrid_ndarray({1,2,3}); - auto slice = tuple{nm::None,nm::None}; + auto slice = nmtools_tuple{nm::None,nm::None}; auto sliced = view::slice(array,slice); using sliced_t = decltype(sliced); NMTOOLS_STATIC_CHECK_TRAIT( meta::is_ndarray, sliced_t ); @@ -1430,7 +1430,7 @@ TEST_CASE("slice" * doctest::test_suite("view::slice")) {1,2,3}, {4,5,6}, }; - auto sliced = view::slice(array, tuple{0,1}, tuple{0,1}); + auto sliced = view::slice(array, nmtools_tuple{0,1}, nmtools_tuple{0,1}); int expected[1][1] = { {1} };