From 4e9fafbe35e16d5645415d4f7155d4a34bc869f8 Mon Sep 17 00:00:00 2001 From: Donghyeon Jeong Date: Tue, 30 Jan 2024 10:12:42 +0900 Subject: [PATCH] Replace manual static cast with a helper struct used with std::transform() This commit replaces a manual static_cast operation with a helper struct that can be used with std::transform(). This change improves readability and maintainability by encapsulating the casting logic in a separate struct. suggessted by @DonghakPark Co-authored-by: Donghak Park Signed-off-by: Donghyeon Jeong --- test/include/nntrainer_test_util.h | 29 + .../unittest_nntrainer_tensor_v2_fp16.cpp | 696 ++++-------------- 2 files changed, 155 insertions(+), 570 deletions(-) diff --git a/test/include/nntrainer_test_util.h b/test/include/nntrainer_test_util.h index 64e56fdc43..7845b63647 100644 --- a/test/include/nntrainer_test_util.h +++ b/test/include/nntrainer_test_util.h @@ -333,5 +333,34 @@ float mse(Ta *A, Tb *B, uint32_t size) { return mse; } +/** + * @brief A helper struct for performing static_cast operations on types. + * + * This struct provides a templated function that can be used to perform a + * static_cast operation between two types. It is intended to be used with the + * std::transform() function from the STL. + * + * @tparam T The target type to which the value will be converted. + */ +template // T models Any +struct static_cast_func { + /** + * @brief Performs a static_cast operation on a given value. + * + * This function takes a constant reference to a value of type T1, where T1 is + * a type that is statically convertible to T. It performs a static_cast + * operation on the value and returns the result as a value of type T. + * + * @tparam T1 The source type of the value being converted. + * @param[in] x The input value to convert. + * @return result of the static_cast operation as a value of type + * T. + */ + template // T1 models type statically convertible to T + T operator()(const T1 &x) const { + return static_cast(x); + } +}; + #endif /* __cplusplus */ #endif /* __NNTRAINER_TEST_UTIL_H__ */ diff --git a/test/unittest/unittest_nntrainer_tensor_v2_fp16.cpp b/test/unittest/unittest_nntrainer_tensor_v2_fp16.cpp index de9ed444bd..adb848dd47 100644 --- a/test/unittest/unittest_nntrainer_tensor_v2_fp16.cpp +++ b/test/unittest/unittest_nntrainer_tensor_v2_fp16.cpp @@ -472,6 +472,8 @@ TEST(nntrainer_Tensor, multiply_i_03_fp16_n) { } TEST(nntrainer_Tensor, multiply_i_broadcast_01_fp16_p) { + unsigned int N = 120; + _FP16 *answer_data = new _FP16[N]; { nntrainer::TensorDim ref_dim(3, 2, 4, 5, nntrainer::Tformat::NCHW, nntrainer::Tdatatype::FP16); @@ -479,66 +481,22 @@ TEST(nntrainer_Tensor, multiply_i_broadcast_01_fp16_p) { nntrainer::Tdatatype::FP16); nntrainer::TensorV2 m = rangedV2(1, 2, 4, 5, nntrainer::Tformat::NCHW, nntrainer::Tdatatype::FP16); - _FP16 answer_data[] = {static_cast<_FP16>(0), static_cast<_FP16>(1), - static_cast<_FP16>(4), static_cast<_FP16>(9), - static_cast<_FP16>(16), static_cast<_FP16>(25), - static_cast<_FP16>(36), static_cast<_FP16>(49), - static_cast<_FP16>(64), static_cast<_FP16>(81), - static_cast<_FP16>(100), static_cast<_FP16>(121), - static_cast<_FP16>(144), static_cast<_FP16>(169), - static_cast<_FP16>(196), static_cast<_FP16>(225), - static_cast<_FP16>(256), static_cast<_FP16>(289), - static_cast<_FP16>(324), static_cast<_FP16>(361), - static_cast<_FP16>(400), static_cast<_FP16>(441), - static_cast<_FP16>(484), static_cast<_FP16>(529), - static_cast<_FP16>(576), static_cast<_FP16>(625), - static_cast<_FP16>(676), static_cast<_FP16>(729), - static_cast<_FP16>(784), static_cast<_FP16>(841), - static_cast<_FP16>(900), static_cast<_FP16>(961), - static_cast<_FP16>(1024), static_cast<_FP16>(1089), - static_cast<_FP16>(1156), static_cast<_FP16>(1225), - static_cast<_FP16>(1296), static_cast<_FP16>(1369), - static_cast<_FP16>(1444), static_cast<_FP16>(1521), - static_cast<_FP16>(0), static_cast<_FP16>(41), - static_cast<_FP16>(84), static_cast<_FP16>(129), - static_cast<_FP16>(176), static_cast<_FP16>(225), - static_cast<_FP16>(276), static_cast<_FP16>(329), - static_cast<_FP16>(384), static_cast<_FP16>(441), - static_cast<_FP16>(500), static_cast<_FP16>(561), - static_cast<_FP16>(624), static_cast<_FP16>(689), - static_cast<_FP16>(756), static_cast<_FP16>(825), - static_cast<_FP16>(896), static_cast<_FP16>(969), - static_cast<_FP16>(1044), static_cast<_FP16>(1121), - static_cast<_FP16>(1200), static_cast<_FP16>(1281), - static_cast<_FP16>(1364), static_cast<_FP16>(1449), - static_cast<_FP16>(1536), static_cast<_FP16>(1625), - static_cast<_FP16>(1716), static_cast<_FP16>(1809), - static_cast<_FP16>(1904), static_cast<_FP16>(2001), - static_cast<_FP16>(2100), static_cast<_FP16>(2201), - static_cast<_FP16>(2304), static_cast<_FP16>(2409), - static_cast<_FP16>(2516), static_cast<_FP16>(2625), - static_cast<_FP16>(2736), static_cast<_FP16>(2849), - static_cast<_FP16>(2964), static_cast<_FP16>(3081), - static_cast<_FP16>(0), static_cast<_FP16>(81), - static_cast<_FP16>(164), static_cast<_FP16>(249), - static_cast<_FP16>(336), static_cast<_FP16>(425), - static_cast<_FP16>(516), static_cast<_FP16>(609), - static_cast<_FP16>(704), static_cast<_FP16>(801), - static_cast<_FP16>(900), static_cast<_FP16>(1001), - static_cast<_FP16>(1104), static_cast<_FP16>(1209), - static_cast<_FP16>(1316), static_cast<_FP16>(1425), - static_cast<_FP16>(1536), static_cast<_FP16>(1649), - static_cast<_FP16>(1764), static_cast<_FP16>(1881), - static_cast<_FP16>(2000), static_cast<_FP16>(2121), - static_cast<_FP16>(2244), static_cast<_FP16>(2369), - static_cast<_FP16>(2496), static_cast<_FP16>(2625), - static_cast<_FP16>(2756), static_cast<_FP16>(2889), - static_cast<_FP16>(3024), static_cast<_FP16>(3161), - static_cast<_FP16>(3300), static_cast<_FP16>(3441), - static_cast<_FP16>(3584), static_cast<_FP16>(3729), - static_cast<_FP16>(3876), static_cast<_FP16>(4025), - static_cast<_FP16>(4176), static_cast<_FP16>(4329), - static_cast<_FP16>(4484), static_cast<_FP16>(4641)}; + + float float_data[] = { + 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, + 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, + 576, 625, 676, 729, 784, 841, 900, 961, 1024, 1089, 1156, 1225, + 1296, 1369, 1444, 1521, 0, 41, 84, 129, 176, 225, 276, 329, + 384, 441, 500, 561, 624, 689, 756, 825, 896, 969, 1044, 1121, + 1200, 1281, 1364, 1449, 1536, 1625, 1716, 1809, 1904, 2001, 2100, 2201, + 2304, 2409, 2516, 2625, 2736, 2849, 2964, 3081, 0, 81, 164, 249, + 336, 425, 516, 609, 704, 801, 900, 1001, 1104, 1209, 1316, 1425, + 1536, 1649, 1764, 1881, 2000, 2121, 2244, 2369, 2496, 2625, 2756, 2889, + 3024, 3161, 3300, 3441, 3584, 3729, 3876, 4025, 4176, 4329, 4484, 4641}; + + std::transform(float_data, float_data + N, answer_data, + static_cast_func<_FP16>()); + nntrainer::TensorV2 answer(ref_dim, answer_data); int status = t.multiply_i(m); EXPECT_EQ(status, ML_ERROR_NONE); @@ -551,66 +509,19 @@ TEST(nntrainer_Tensor, multiply_i_broadcast_01_fp16_p) { nntrainer::Tdatatype::FP16); nntrainer::TensorV2 m = rangedV2(3, 1, 4, 5, nntrainer::Tformat::NCHW, nntrainer::Tdatatype::FP16); - _FP16 answer_data[] = {static_cast<_FP16>(0), static_cast<_FP16>(1), - static_cast<_FP16>(4), static_cast<_FP16>(9), - static_cast<_FP16>(16), static_cast<_FP16>(25), - static_cast<_FP16>(36), static_cast<_FP16>(49), - static_cast<_FP16>(64), static_cast<_FP16>(81), - static_cast<_FP16>(100), static_cast<_FP16>(121), - static_cast<_FP16>(144), static_cast<_FP16>(169), - static_cast<_FP16>(196), static_cast<_FP16>(225), - static_cast<_FP16>(256), static_cast<_FP16>(289), - static_cast<_FP16>(324), static_cast<_FP16>(361), - static_cast<_FP16>(0), static_cast<_FP16>(21), - static_cast<_FP16>(44), static_cast<_FP16>(69), - static_cast<_FP16>(96), static_cast<_FP16>(125), - static_cast<_FP16>(156), static_cast<_FP16>(189), - static_cast<_FP16>(224), static_cast<_FP16>(261), - static_cast<_FP16>(300), static_cast<_FP16>(341), - static_cast<_FP16>(384), static_cast<_FP16>(429), - static_cast<_FP16>(476), static_cast<_FP16>(525), - static_cast<_FP16>(576), static_cast<_FP16>(629), - static_cast<_FP16>(684), static_cast<_FP16>(741), - static_cast<_FP16>(800), static_cast<_FP16>(861), - static_cast<_FP16>(924), static_cast<_FP16>(989), - static_cast<_FP16>(1056), static_cast<_FP16>(1125), - static_cast<_FP16>(1196), static_cast<_FP16>(1269), - static_cast<_FP16>(1344), static_cast<_FP16>(1421), - static_cast<_FP16>(1500), static_cast<_FP16>(1581), - static_cast<_FP16>(1664), static_cast<_FP16>(1749), - static_cast<_FP16>(1836), static_cast<_FP16>(1925), - static_cast<_FP16>(2016), static_cast<_FP16>(2109), - static_cast<_FP16>(2204), static_cast<_FP16>(2301), - static_cast<_FP16>(1200), static_cast<_FP16>(1281), - static_cast<_FP16>(1364), static_cast<_FP16>(1449), - static_cast<_FP16>(1536), static_cast<_FP16>(1625), - static_cast<_FP16>(1716), static_cast<_FP16>(1809), - static_cast<_FP16>(1904), static_cast<_FP16>(2001), - static_cast<_FP16>(2100), static_cast<_FP16>(2201), - static_cast<_FP16>(2304), static_cast<_FP16>(2409), - static_cast<_FP16>(2516), static_cast<_FP16>(2625), - static_cast<_FP16>(2736), static_cast<_FP16>(2849), - static_cast<_FP16>(2964), static_cast<_FP16>(3081), - static_cast<_FP16>(3200), static_cast<_FP16>(3321), - static_cast<_FP16>(3444), static_cast<_FP16>(3569), - static_cast<_FP16>(3696), static_cast<_FP16>(3825), - static_cast<_FP16>(3956), static_cast<_FP16>(4089), - static_cast<_FP16>(4224), static_cast<_FP16>(4361), - static_cast<_FP16>(4500), static_cast<_FP16>(4641), - static_cast<_FP16>(4784), static_cast<_FP16>(4929), - static_cast<_FP16>(5076), static_cast<_FP16>(5225), - static_cast<_FP16>(5376), static_cast<_FP16>(5529), - static_cast<_FP16>(5684), static_cast<_FP16>(5841), - static_cast<_FP16>(4000), static_cast<_FP16>(4141), - static_cast<_FP16>(4284), static_cast<_FP16>(4429), - static_cast<_FP16>(4576), static_cast<_FP16>(4725), - static_cast<_FP16>(4876), static_cast<_FP16>(5029), - static_cast<_FP16>(5184), static_cast<_FP16>(5341), - static_cast<_FP16>(5500), static_cast<_FP16>(5661), - static_cast<_FP16>(5824), static_cast<_FP16>(5989), - static_cast<_FP16>(6156), static_cast<_FP16>(6325), - static_cast<_FP16>(6496), static_cast<_FP16>(6669), - static_cast<_FP16>(6844), static_cast<_FP16>(7021)}; + float float_data[] = { + 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, + 144, 169, 196, 225, 256, 289, 324, 361, 0, 21, 44, 69, + 96, 125, 156, 189, 224, 261, 300, 341, 384, 429, 476, 525, + 576, 629, 684, 741, 800, 861, 924, 989, 1056, 1125, 1196, 1269, + 1344, 1421, 1500, 1581, 1664, 1749, 1836, 1925, 2016, 2109, 2204, 2301, + 1200, 1281, 1364, 1449, 1536, 1625, 1716, 1809, 1904, 2001, 2100, 2201, + 2304, 2409, 2516, 2625, 2736, 2849, 2964, 3081, 3200, 3321, 3444, 3569, + 3696, 3825, 3956, 4089, 4224, 4361, 4500, 4641, 4784, 4929, 5076, 5225, + 5376, 5529, 5684, 5841, 4000, 4141, 4284, 4429, 4576, 4725, 4876, 5029, + 5184, 5341, 5500, 5661, 5824, 5989, 6156, 6325, 6496, 6669, 6844, 7021}; + std::transform(float_data, float_data + N, answer_data, + static_cast_func<_FP16>()); nntrainer::TensorV2 answer(ref_dim, answer_data); int status = t.multiply_i(m); EXPECT_EQ(status, ML_ERROR_NONE); @@ -623,66 +534,19 @@ TEST(nntrainer_Tensor, multiply_i_broadcast_01_fp16_p) { nntrainer::Tdatatype::FP16); nntrainer::TensorV2 m = rangedV2(3, 2, 4, 1, nntrainer::Tformat::NCHW, nntrainer::Tdatatype::FP16); - _FP16 answer_data[] = {static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(5), - static_cast<_FP16>(6), static_cast<_FP16>(7), - static_cast<_FP16>(8), static_cast<_FP16>(9), - static_cast<_FP16>(20), static_cast<_FP16>(22), - static_cast<_FP16>(24), static_cast<_FP16>(26), - static_cast<_FP16>(28), static_cast<_FP16>(45), - static_cast<_FP16>(48), static_cast<_FP16>(51), - static_cast<_FP16>(54), static_cast<_FP16>(57), - static_cast<_FP16>(80), static_cast<_FP16>(84), - static_cast<_FP16>(88), static_cast<_FP16>(92), - static_cast<_FP16>(96), static_cast<_FP16>(125), - static_cast<_FP16>(130), static_cast<_FP16>(135), - static_cast<_FP16>(140), static_cast<_FP16>(145), - static_cast<_FP16>(180), static_cast<_FP16>(186), - static_cast<_FP16>(192), static_cast<_FP16>(198), - static_cast<_FP16>(204), static_cast<_FP16>(245), - static_cast<_FP16>(252), static_cast<_FP16>(259), - static_cast<_FP16>(266), static_cast<_FP16>(273), - static_cast<_FP16>(320), static_cast<_FP16>(328), - static_cast<_FP16>(336), static_cast<_FP16>(344), - static_cast<_FP16>(352), static_cast<_FP16>(405), - static_cast<_FP16>(414), static_cast<_FP16>(423), - static_cast<_FP16>(432), static_cast<_FP16>(441), - static_cast<_FP16>(500), static_cast<_FP16>(510), - static_cast<_FP16>(520), static_cast<_FP16>(530), - static_cast<_FP16>(540), static_cast<_FP16>(605), - static_cast<_FP16>(616), static_cast<_FP16>(627), - static_cast<_FP16>(638), static_cast<_FP16>(649), - static_cast<_FP16>(720), static_cast<_FP16>(732), - static_cast<_FP16>(744), static_cast<_FP16>(756), - static_cast<_FP16>(768), static_cast<_FP16>(845), - static_cast<_FP16>(858), static_cast<_FP16>(871), - static_cast<_FP16>(884), static_cast<_FP16>(897), - static_cast<_FP16>(980), static_cast<_FP16>(994), - static_cast<_FP16>(1008), static_cast<_FP16>(1022), - static_cast<_FP16>(1036), static_cast<_FP16>(1125), - static_cast<_FP16>(1140), static_cast<_FP16>(1155), - static_cast<_FP16>(1170), static_cast<_FP16>(1185), - static_cast<_FP16>(1280), static_cast<_FP16>(1296), - static_cast<_FP16>(1312), static_cast<_FP16>(1328), - static_cast<_FP16>(1344), static_cast<_FP16>(1445), - static_cast<_FP16>(1462), static_cast<_FP16>(1479), - static_cast<_FP16>(1496), static_cast<_FP16>(1513), - static_cast<_FP16>(1620), static_cast<_FP16>(1638), - static_cast<_FP16>(1656), static_cast<_FP16>(1674), - static_cast<_FP16>(1692), static_cast<_FP16>(1805), - static_cast<_FP16>(1824), static_cast<_FP16>(1843), - static_cast<_FP16>(1862), static_cast<_FP16>(1881), - static_cast<_FP16>(2000), static_cast<_FP16>(2020), - static_cast<_FP16>(2040), static_cast<_FP16>(2060), - static_cast<_FP16>(2080), static_cast<_FP16>(2205), - static_cast<_FP16>(2226), static_cast<_FP16>(2247), - static_cast<_FP16>(2268), static_cast<_FP16>(2289), - static_cast<_FP16>(2420), static_cast<_FP16>(2442), - static_cast<_FP16>(2464), static_cast<_FP16>(2486), - static_cast<_FP16>(2508), static_cast<_FP16>(2645), - static_cast<_FP16>(2668), static_cast<_FP16>(2691), - static_cast<_FP16>(2714), static_cast<_FP16>(2737)}; + float float_data[] = { + 0, 0, 0, 0, 0, 5, 6, 7, 8, 9, 20, 22, + 24, 26, 28, 45, 48, 51, 54, 57, 80, 84, 88, 92, + 96, 125, 130, 135, 140, 145, 180, 186, 192, 198, 204, 245, + 252, 259, 266, 273, 320, 328, 336, 344, 352, 405, 414, 423, + 432, 441, 500, 510, 520, 530, 540, 605, 616, 627, 638, 649, + 720, 732, 744, 756, 768, 845, 858, 871, 884, 897, 980, 994, + 1008, 1022, 1036, 1125, 1140, 1155, 1170, 1185, 1280, 1296, 1312, 1328, + 1344, 1445, 1462, 1479, 1496, 1513, 1620, 1638, 1656, 1674, 1692, 1805, + 1824, 1843, 1862, 1881, 2000, 2020, 2040, 2060, 2080, 2205, 2226, 2247, + 2268, 2289, 2420, 2442, 2464, 2486, 2508, 2645, 2668, 2691, 2714, 2737}; + std::transform(float_data, float_data + N, answer_data, + static_cast_func<_FP16>()); nntrainer::TensorV2 answer(ref_dim, answer_data); int status = t.multiply_i(m); EXPECT_EQ(status, ML_ERROR_NONE); @@ -695,66 +559,19 @@ TEST(nntrainer_Tensor, multiply_i_broadcast_01_fp16_p) { nntrainer::Tdatatype::FP16); nntrainer::TensorV2 m = rangedV2(3, 1, 1, 5, nntrainer::Tformat::NCHW, nntrainer::Tdatatype::FP16); - _FP16 answer_data[] = {static_cast<_FP16>(0), static_cast<_FP16>(1), - static_cast<_FP16>(4), static_cast<_FP16>(9), - static_cast<_FP16>(16), static_cast<_FP16>(0), - static_cast<_FP16>(6), static_cast<_FP16>(14), - static_cast<_FP16>(24), static_cast<_FP16>(36), - static_cast<_FP16>(0), static_cast<_FP16>(11), - static_cast<_FP16>(24), static_cast<_FP16>(39), - static_cast<_FP16>(56), static_cast<_FP16>(0), - static_cast<_FP16>(16), static_cast<_FP16>(34), - static_cast<_FP16>(54), static_cast<_FP16>(76), - static_cast<_FP16>(0), static_cast<_FP16>(21), - static_cast<_FP16>(44), static_cast<_FP16>(69), - static_cast<_FP16>(96), static_cast<_FP16>(0), - static_cast<_FP16>(26), static_cast<_FP16>(54), - static_cast<_FP16>(84), static_cast<_FP16>(116), - static_cast<_FP16>(0), static_cast<_FP16>(31), - static_cast<_FP16>(64), static_cast<_FP16>(99), - static_cast<_FP16>(136), static_cast<_FP16>(0), - static_cast<_FP16>(36), static_cast<_FP16>(74), - static_cast<_FP16>(114), static_cast<_FP16>(156), - static_cast<_FP16>(200), static_cast<_FP16>(246), - static_cast<_FP16>(294), static_cast<_FP16>(344), - static_cast<_FP16>(396), static_cast<_FP16>(225), - static_cast<_FP16>(276), static_cast<_FP16>(329), - static_cast<_FP16>(384), static_cast<_FP16>(441), - static_cast<_FP16>(250), static_cast<_FP16>(306), - static_cast<_FP16>(364), static_cast<_FP16>(424), - static_cast<_FP16>(486), static_cast<_FP16>(275), - static_cast<_FP16>(336), static_cast<_FP16>(399), - static_cast<_FP16>(464), static_cast<_FP16>(531), - static_cast<_FP16>(300), static_cast<_FP16>(366), - static_cast<_FP16>(434), static_cast<_FP16>(504), - static_cast<_FP16>(576), static_cast<_FP16>(325), - static_cast<_FP16>(396), static_cast<_FP16>(469), - static_cast<_FP16>(544), static_cast<_FP16>(621), - static_cast<_FP16>(350), static_cast<_FP16>(426), - static_cast<_FP16>(504), static_cast<_FP16>(584), - static_cast<_FP16>(666), static_cast<_FP16>(375), - static_cast<_FP16>(456), static_cast<_FP16>(539), - static_cast<_FP16>(624), static_cast<_FP16>(711), - static_cast<_FP16>(800), static_cast<_FP16>(891), - static_cast<_FP16>(984), static_cast<_FP16>(1079), - static_cast<_FP16>(1176), static_cast<_FP16>(850), - static_cast<_FP16>(946), static_cast<_FP16>(1044), - static_cast<_FP16>(1144), static_cast<_FP16>(1246), - static_cast<_FP16>(900), static_cast<_FP16>(1001), - static_cast<_FP16>(1104), static_cast<_FP16>(1209), - static_cast<_FP16>(1316), static_cast<_FP16>(950), - static_cast<_FP16>(1056), static_cast<_FP16>(1164), - static_cast<_FP16>(1274), static_cast<_FP16>(1386), - static_cast<_FP16>(1000), static_cast<_FP16>(1111), - static_cast<_FP16>(1224), static_cast<_FP16>(1339), - static_cast<_FP16>(1456), static_cast<_FP16>(1050), - static_cast<_FP16>(1166), static_cast<_FP16>(1284), - static_cast<_FP16>(1404), static_cast<_FP16>(1526), - static_cast<_FP16>(1100), static_cast<_FP16>(1221), - static_cast<_FP16>(1344), static_cast<_FP16>(1469), - static_cast<_FP16>(1596), static_cast<_FP16>(1150), - static_cast<_FP16>(1276), static_cast<_FP16>(1404), - static_cast<_FP16>(1534), static_cast<_FP16>(1666)}; + float float_data[] = { + 0, 1, 4, 9, 16, 0, 6, 14, 24, 36, 0, 11, + 24, 39, 56, 0, 16, 34, 54, 76, 0, 21, 44, 69, + 96, 0, 26, 54, 84, 116, 0, 31, 64, 99, 136, 0, + 36, 74, 114, 156, 200, 246, 294, 344, 396, 225, 276, 329, + 384, 441, 250, 306, 364, 424, 486, 275, 336, 399, 464, 531, + 300, 366, 434, 504, 576, 325, 396, 469, 544, 621, 350, 426, + 504, 584, 666, 375, 456, 539, 624, 711, 800, 891, 984, 1079, + 1176, 850, 946, 1044, 1144, 1246, 900, 1001, 1104, 1209, 1316, 950, + 1056, 1164, 1274, 1386, 1000, 1111, 1224, 1339, 1456, 1050, 1166, 1284, + 1404, 1526, 1100, 1221, 1344, 1469, 1596, 1150, 1276, 1404, 1534, 1666}; + std::transform(float_data, float_data + N, answer_data, + static_cast_func<_FP16>()); nntrainer::TensorV2 answer(ref_dim, answer_data); int status = t.multiply_i(m); EXPECT_EQ(status, ML_ERROR_NONE); @@ -767,66 +584,18 @@ TEST(nntrainer_Tensor, multiply_i_broadcast_01_fp16_p) { nntrainer::Tdatatype::FP16); nntrainer::TensorV2 m = rangedV2(1, 2, 1, 5, nntrainer::Tformat::NCHW, nntrainer::Tdatatype::FP16); - _FP16 answer_data[] = {static_cast<_FP16>(0), static_cast<_FP16>(1), - static_cast<_FP16>(4), static_cast<_FP16>(9), - static_cast<_FP16>(16), static_cast<_FP16>(0), - static_cast<_FP16>(6), static_cast<_FP16>(14), - static_cast<_FP16>(24), static_cast<_FP16>(36), - static_cast<_FP16>(0), static_cast<_FP16>(11), - static_cast<_FP16>(24), static_cast<_FP16>(39), - static_cast<_FP16>(56), static_cast<_FP16>(0), - static_cast<_FP16>(16), static_cast<_FP16>(34), - static_cast<_FP16>(54), static_cast<_FP16>(76), - static_cast<_FP16>(100), static_cast<_FP16>(126), - static_cast<_FP16>(154), static_cast<_FP16>(184), - static_cast<_FP16>(216), static_cast<_FP16>(125), - static_cast<_FP16>(156), static_cast<_FP16>(189), - static_cast<_FP16>(224), static_cast<_FP16>(261), - static_cast<_FP16>(150), static_cast<_FP16>(186), - static_cast<_FP16>(224), static_cast<_FP16>(264), - static_cast<_FP16>(306), static_cast<_FP16>(175), - static_cast<_FP16>(216), static_cast<_FP16>(259), - static_cast<_FP16>(304), static_cast<_FP16>(351), - static_cast<_FP16>(0), static_cast<_FP16>(41), - static_cast<_FP16>(84), static_cast<_FP16>(129), - static_cast<_FP16>(176), static_cast<_FP16>(0), - static_cast<_FP16>(46), static_cast<_FP16>(94), - static_cast<_FP16>(144), static_cast<_FP16>(196), - static_cast<_FP16>(0), static_cast<_FP16>(51), - static_cast<_FP16>(104), static_cast<_FP16>(159), - static_cast<_FP16>(216), static_cast<_FP16>(0), - static_cast<_FP16>(56), static_cast<_FP16>(114), - static_cast<_FP16>(174), static_cast<_FP16>(236), - static_cast<_FP16>(300), static_cast<_FP16>(366), - static_cast<_FP16>(434), static_cast<_FP16>(504), - static_cast<_FP16>(576), static_cast<_FP16>(325), - static_cast<_FP16>(396), static_cast<_FP16>(469), - static_cast<_FP16>(544), static_cast<_FP16>(621), - static_cast<_FP16>(350), static_cast<_FP16>(426), - static_cast<_FP16>(504), static_cast<_FP16>(584), - static_cast<_FP16>(666), static_cast<_FP16>(375), - static_cast<_FP16>(456), static_cast<_FP16>(539), - static_cast<_FP16>(624), static_cast<_FP16>(711), - static_cast<_FP16>(0), static_cast<_FP16>(81), - static_cast<_FP16>(164), static_cast<_FP16>(249), - static_cast<_FP16>(336), static_cast<_FP16>(0), - static_cast<_FP16>(86), static_cast<_FP16>(174), - static_cast<_FP16>(264), static_cast<_FP16>(356), - static_cast<_FP16>(0), static_cast<_FP16>(91), - static_cast<_FP16>(184), static_cast<_FP16>(279), - static_cast<_FP16>(376), static_cast<_FP16>(0), - static_cast<_FP16>(96), static_cast<_FP16>(194), - static_cast<_FP16>(294), static_cast<_FP16>(396), - static_cast<_FP16>(500), static_cast<_FP16>(606), - static_cast<_FP16>(714), static_cast<_FP16>(824), - static_cast<_FP16>(936), static_cast<_FP16>(525), - static_cast<_FP16>(636), static_cast<_FP16>(749), - static_cast<_FP16>(864), static_cast<_FP16>(981), - static_cast<_FP16>(550), static_cast<_FP16>(666), - static_cast<_FP16>(784), static_cast<_FP16>(904), - static_cast<_FP16>(1026), static_cast<_FP16>(575), - static_cast<_FP16>(696), static_cast<_FP16>(819), - static_cast<_FP16>(944), static_cast<_FP16>(1071)}; + float float_data[] = { + 0, 1, 4, 9, 16, 0, 6, 14, 24, 36, 0, 11, 24, 39, + 56, 0, 16, 34, 54, 76, 100, 126, 154, 184, 216, 125, 156, 189, + 224, 261, 150, 186, 224, 264, 306, 175, 216, 259, 304, 351, 0, 41, + 84, 129, 176, 0, 46, 94, 144, 196, 0, 51, 104, 159, 216, 0, + 56, 114, 174, 236, 300, 366, 434, 504, 576, 325, 396, 469, 544, 621, + 350, 426, 504, 584, 666, 375, 456, 539, 624, 711, 0, 81, 164, 249, + 336, 0, 86, 174, 264, 356, 0, 91, 184, 279, 376, 0, 96, 194, + 294, 396, 500, 606, 714, 824, 936, 525, 636, 749, 864, 981, 550, 666, + 784, 904, 1026, 575, 696, 819, 944, 1071}; + std::transform(float_data, float_data + N, answer_data, + static_cast_func<_FP16>()); nntrainer::TensorV2 answer(ref_dim, answer_data); int status = t.multiply_i(m); EXPECT_EQ(status, ML_ERROR_NONE); @@ -839,66 +608,19 @@ TEST(nntrainer_Tensor, multiply_i_broadcast_01_fp16_p) { nntrainer::Tdatatype::FP16); nntrainer::TensorV2 m = rangedV2(3, 1, 4, 1, nntrainer::Tformat::NCHW, nntrainer::Tdatatype::FP16); - _FP16 answer_data[] = {static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(5), - static_cast<_FP16>(6), static_cast<_FP16>(7), - static_cast<_FP16>(8), static_cast<_FP16>(9), - static_cast<_FP16>(20), static_cast<_FP16>(22), - static_cast<_FP16>(24), static_cast<_FP16>(26), - static_cast<_FP16>(28), static_cast<_FP16>(45), - static_cast<_FP16>(48), static_cast<_FP16>(51), - static_cast<_FP16>(54), static_cast<_FP16>(57), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(25), - static_cast<_FP16>(26), static_cast<_FP16>(27), - static_cast<_FP16>(28), static_cast<_FP16>(29), - static_cast<_FP16>(60), static_cast<_FP16>(62), - static_cast<_FP16>(64), static_cast<_FP16>(66), - static_cast<_FP16>(68), static_cast<_FP16>(105), - static_cast<_FP16>(108), static_cast<_FP16>(111), - static_cast<_FP16>(114), static_cast<_FP16>(117), - static_cast<_FP16>(160), static_cast<_FP16>(164), - static_cast<_FP16>(168), static_cast<_FP16>(172), - static_cast<_FP16>(176), static_cast<_FP16>(225), - static_cast<_FP16>(230), static_cast<_FP16>(235), - static_cast<_FP16>(240), static_cast<_FP16>(245), - static_cast<_FP16>(300), static_cast<_FP16>(306), - static_cast<_FP16>(312), static_cast<_FP16>(318), - static_cast<_FP16>(324), static_cast<_FP16>(385), - static_cast<_FP16>(392), static_cast<_FP16>(399), - static_cast<_FP16>(406), static_cast<_FP16>(413), - static_cast<_FP16>(240), static_cast<_FP16>(244), - static_cast<_FP16>(248), static_cast<_FP16>(252), - static_cast<_FP16>(256), static_cast<_FP16>(325), - static_cast<_FP16>(330), static_cast<_FP16>(335), - static_cast<_FP16>(340), static_cast<_FP16>(345), - static_cast<_FP16>(420), static_cast<_FP16>(426), - static_cast<_FP16>(432), static_cast<_FP16>(438), - static_cast<_FP16>(444), static_cast<_FP16>(525), - static_cast<_FP16>(532), static_cast<_FP16>(539), - static_cast<_FP16>(546), static_cast<_FP16>(553), - static_cast<_FP16>(640), static_cast<_FP16>(648), - static_cast<_FP16>(656), static_cast<_FP16>(664), - static_cast<_FP16>(672), static_cast<_FP16>(765), - static_cast<_FP16>(774), static_cast<_FP16>(783), - static_cast<_FP16>(792), static_cast<_FP16>(801), - static_cast<_FP16>(900), static_cast<_FP16>(910), - static_cast<_FP16>(920), static_cast<_FP16>(930), - static_cast<_FP16>(940), static_cast<_FP16>(1045), - static_cast<_FP16>(1056), static_cast<_FP16>(1067), - static_cast<_FP16>(1078), static_cast<_FP16>(1089), - static_cast<_FP16>(800), static_cast<_FP16>(808), - static_cast<_FP16>(816), static_cast<_FP16>(824), - static_cast<_FP16>(832), static_cast<_FP16>(945), - static_cast<_FP16>(954), static_cast<_FP16>(963), - static_cast<_FP16>(972), static_cast<_FP16>(981), - static_cast<_FP16>(1100), static_cast<_FP16>(1110), - static_cast<_FP16>(1120), static_cast<_FP16>(1130), - static_cast<_FP16>(1140), static_cast<_FP16>(1265), - static_cast<_FP16>(1276), static_cast<_FP16>(1287), - static_cast<_FP16>(1298), static_cast<_FP16>(1309)}; + float float_data[] = { + 0, 0, 0, 0, 0, 5, 6, 7, 8, 9, 20, 22, + 24, 26, 28, 45, 48, 51, 54, 57, 0, 0, 0, 0, + 0, 25, 26, 27, 28, 29, 60, 62, 64, 66, 68, 105, + 108, 111, 114, 117, 160, 164, 168, 172, 176, 225, 230, 235, + 240, 245, 300, 306, 312, 318, 324, 385, 392, 399, 406, 413, + 240, 244, 248, 252, 256, 325, 330, 335, 340, 345, 420, 426, + 432, 438, 444, 525, 532, 539, 546, 553, 640, 648, 656, 664, + 672, 765, 774, 783, 792, 801, 900, 910, 920, 930, 940, 1045, + 1056, 1067, 1078, 1089, 800, 808, 816, 824, 832, 945, 954, 963, + 972, 981, 1100, 1110, 1120, 1130, 1140, 1265, 1276, 1287, 1298, 1309}; + std::transform(float_data, float_data + N, answer_data, + static_cast_func<_FP16>()); nntrainer::TensorV2 answer(ref_dim, answer_data); int status = t.multiply_i(m); EXPECT_EQ(status, ML_ERROR_NONE); @@ -911,66 +633,17 @@ TEST(nntrainer_Tensor, multiply_i_broadcast_01_fp16_p) { nntrainer::Tdatatype::FP16); nntrainer::TensorV2 m = rangedV2(1, 1, 1, 5, nntrainer::Tformat::NCHW, nntrainer::Tdatatype::FP16); - _FP16 answer_data[] = {static_cast<_FP16>(0), static_cast<_FP16>(1), - static_cast<_FP16>(4), static_cast<_FP16>(9), - static_cast<_FP16>(16), static_cast<_FP16>(0), - static_cast<_FP16>(6), static_cast<_FP16>(14), - static_cast<_FP16>(24), static_cast<_FP16>(36), - static_cast<_FP16>(0), static_cast<_FP16>(11), - static_cast<_FP16>(24), static_cast<_FP16>(39), - static_cast<_FP16>(56), static_cast<_FP16>(0), - static_cast<_FP16>(16), static_cast<_FP16>(34), - static_cast<_FP16>(54), static_cast<_FP16>(76), - static_cast<_FP16>(0), static_cast<_FP16>(21), - static_cast<_FP16>(44), static_cast<_FP16>(69), - static_cast<_FP16>(96), static_cast<_FP16>(0), - static_cast<_FP16>(26), static_cast<_FP16>(54), - static_cast<_FP16>(84), static_cast<_FP16>(116), - static_cast<_FP16>(0), static_cast<_FP16>(31), - static_cast<_FP16>(64), static_cast<_FP16>(99), - static_cast<_FP16>(136), static_cast<_FP16>(0), - static_cast<_FP16>(36), static_cast<_FP16>(74), - static_cast<_FP16>(114), static_cast<_FP16>(156), - static_cast<_FP16>(0), static_cast<_FP16>(41), - static_cast<_FP16>(84), static_cast<_FP16>(129), - static_cast<_FP16>(176), static_cast<_FP16>(0), - static_cast<_FP16>(46), static_cast<_FP16>(94), - static_cast<_FP16>(144), static_cast<_FP16>(196), - static_cast<_FP16>(0), static_cast<_FP16>(51), - static_cast<_FP16>(104), static_cast<_FP16>(159), - static_cast<_FP16>(216), static_cast<_FP16>(0), - static_cast<_FP16>(56), static_cast<_FP16>(114), - static_cast<_FP16>(174), static_cast<_FP16>(236), - static_cast<_FP16>(0), static_cast<_FP16>(61), - static_cast<_FP16>(124), static_cast<_FP16>(189), - static_cast<_FP16>(256), static_cast<_FP16>(0), - static_cast<_FP16>(66), static_cast<_FP16>(134), - static_cast<_FP16>(204), static_cast<_FP16>(276), - static_cast<_FP16>(0), static_cast<_FP16>(71), - static_cast<_FP16>(144), static_cast<_FP16>(219), - static_cast<_FP16>(296), static_cast<_FP16>(0), - static_cast<_FP16>(76), static_cast<_FP16>(154), - static_cast<_FP16>(234), static_cast<_FP16>(316), - static_cast<_FP16>(0), static_cast<_FP16>(81), - static_cast<_FP16>(164), static_cast<_FP16>(249), - static_cast<_FP16>(336), static_cast<_FP16>(0), - static_cast<_FP16>(86), static_cast<_FP16>(174), - static_cast<_FP16>(264), static_cast<_FP16>(356), - static_cast<_FP16>(0), static_cast<_FP16>(91), - static_cast<_FP16>(184), static_cast<_FP16>(279), - static_cast<_FP16>(376), static_cast<_FP16>(0), - static_cast<_FP16>(96), static_cast<_FP16>(194), - static_cast<_FP16>(294), static_cast<_FP16>(396), - static_cast<_FP16>(0), static_cast<_FP16>(101), - static_cast<_FP16>(204), static_cast<_FP16>(309), - static_cast<_FP16>(416), static_cast<_FP16>(0), - static_cast<_FP16>(106), static_cast<_FP16>(214), - static_cast<_FP16>(324), static_cast<_FP16>(436), - static_cast<_FP16>(0), static_cast<_FP16>(111), - static_cast<_FP16>(224), static_cast<_FP16>(339), - static_cast<_FP16>(456), static_cast<_FP16>(0), - static_cast<_FP16>(116), static_cast<_FP16>(234), - static_cast<_FP16>(354), static_cast<_FP16>(476)}; + float float_data[] = { + 0, 1, 4, 9, 16, 0, 6, 14, 24, 36, 0, 11, 24, 39, 56, + 0, 16, 34, 54, 76, 0, 21, 44, 69, 96, 0, 26, 54, 84, 116, + 0, 31, 64, 99, 136, 0, 36, 74, 114, 156, 0, 41, 84, 129, 176, + 0, 46, 94, 144, 196, 0, 51, 104, 159, 216, 0, 56, 114, 174, 236, + 0, 61, 124, 189, 256, 0, 66, 134, 204, 276, 0, 71, 144, 219, 296, + 0, 76, 154, 234, 316, 0, 81, 164, 249, 336, 0, 86, 174, 264, 356, + 0, 91, 184, 279, 376, 0, 96, 194, 294, 396, 0, 101, 204, 309, 416, + 0, 106, 214, 324, 436, 0, 111, 224, 339, 456, 0, 116, 234, 354, 476}; + std::transform(float_data, float_data + N, answer_data, + static_cast_func<_FP16>()); nntrainer::TensorV2 answer(ref_dim, answer_data); int status = t.multiply_i(m); EXPECT_EQ(status, ML_ERROR_NONE); @@ -983,66 +656,18 @@ TEST(nntrainer_Tensor, multiply_i_broadcast_01_fp16_p) { nntrainer::Tdatatype::FP16); nntrainer::TensorV2 m = rangedV2(1, 2, 1, 1, nntrainer::Tformat::NCHW, nntrainer::Tdatatype::FP16); - _FP16 answer_data[] = {static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(20), static_cast<_FP16>(21), - static_cast<_FP16>(22), static_cast<_FP16>(23), - static_cast<_FP16>(24), static_cast<_FP16>(25), - static_cast<_FP16>(26), static_cast<_FP16>(27), - static_cast<_FP16>(28), static_cast<_FP16>(29), - static_cast<_FP16>(30), static_cast<_FP16>(31), - static_cast<_FP16>(32), static_cast<_FP16>(33), - static_cast<_FP16>(34), static_cast<_FP16>(35), - static_cast<_FP16>(36), static_cast<_FP16>(37), - static_cast<_FP16>(38), static_cast<_FP16>(39), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(60), static_cast<_FP16>(61), - static_cast<_FP16>(62), static_cast<_FP16>(63), - static_cast<_FP16>(64), static_cast<_FP16>(65), - static_cast<_FP16>(66), static_cast<_FP16>(67), - static_cast<_FP16>(68), static_cast<_FP16>(69), - static_cast<_FP16>(70), static_cast<_FP16>(71), - static_cast<_FP16>(72), static_cast<_FP16>(73), - static_cast<_FP16>(74), static_cast<_FP16>(75), - static_cast<_FP16>(76), static_cast<_FP16>(77), - static_cast<_FP16>(78), static_cast<_FP16>(79), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(100), static_cast<_FP16>(101), - static_cast<_FP16>(102), static_cast<_FP16>(103), - static_cast<_FP16>(104), static_cast<_FP16>(105), - static_cast<_FP16>(106), static_cast<_FP16>(107), - static_cast<_FP16>(108), static_cast<_FP16>(109), - static_cast<_FP16>(110), static_cast<_FP16>(111), - static_cast<_FP16>(112), static_cast<_FP16>(113), - static_cast<_FP16>(114), static_cast<_FP16>(115), - static_cast<_FP16>(116), static_cast<_FP16>(117), - static_cast<_FP16>(118), static_cast<_FP16>(119)}; + float float_data[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, + 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, + 112, 113, 114, 115, 116, 117, 118, 119}; + std::transform(float_data, float_data + N, answer_data, + static_cast_func<_FP16>()); nntrainer::TensorV2 answer(ref_dim, answer_data); int status = t.multiply_i(m); EXPECT_EQ(status, ML_ERROR_NONE); @@ -1055,66 +680,18 @@ TEST(nntrainer_Tensor, multiply_i_broadcast_01_fp16_p) { nntrainer::Tdatatype::FP16); nntrainer::TensorV2 m = rangedV2(3, 1, 1, 1, nntrainer::Tformat::NCHW, nntrainer::Tdatatype::FP16); - _FP16 answer_data[] = {static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(0), static_cast<_FP16>(0), - static_cast<_FP16>(40), static_cast<_FP16>(41), - static_cast<_FP16>(42), static_cast<_FP16>(43), - static_cast<_FP16>(44), static_cast<_FP16>(45), - static_cast<_FP16>(46), static_cast<_FP16>(47), - static_cast<_FP16>(48), static_cast<_FP16>(49), - static_cast<_FP16>(50), static_cast<_FP16>(51), - static_cast<_FP16>(52), static_cast<_FP16>(53), - static_cast<_FP16>(54), static_cast<_FP16>(55), - static_cast<_FP16>(56), static_cast<_FP16>(57), - static_cast<_FP16>(58), static_cast<_FP16>(59), - static_cast<_FP16>(60), static_cast<_FP16>(61), - static_cast<_FP16>(62), static_cast<_FP16>(63), - static_cast<_FP16>(64), static_cast<_FP16>(65), - static_cast<_FP16>(66), static_cast<_FP16>(67), - static_cast<_FP16>(68), static_cast<_FP16>(69), - static_cast<_FP16>(70), static_cast<_FP16>(71), - static_cast<_FP16>(72), static_cast<_FP16>(73), - static_cast<_FP16>(74), static_cast<_FP16>(75), - static_cast<_FP16>(76), static_cast<_FP16>(77), - static_cast<_FP16>(78), static_cast<_FP16>(79), - static_cast<_FP16>(160), static_cast<_FP16>(162), - static_cast<_FP16>(164), static_cast<_FP16>(166), - static_cast<_FP16>(168), static_cast<_FP16>(170), - static_cast<_FP16>(172), static_cast<_FP16>(174), - static_cast<_FP16>(176), static_cast<_FP16>(178), - static_cast<_FP16>(180), static_cast<_FP16>(182), - static_cast<_FP16>(184), static_cast<_FP16>(186), - static_cast<_FP16>(188), static_cast<_FP16>(190), - static_cast<_FP16>(192), static_cast<_FP16>(194), - static_cast<_FP16>(196), static_cast<_FP16>(198), - static_cast<_FP16>(200), static_cast<_FP16>(202), - static_cast<_FP16>(204), static_cast<_FP16>(206), - static_cast<_FP16>(208), static_cast<_FP16>(210), - static_cast<_FP16>(212), static_cast<_FP16>(214), - static_cast<_FP16>(216), static_cast<_FP16>(218), - static_cast<_FP16>(220), static_cast<_FP16>(222), - static_cast<_FP16>(224), static_cast<_FP16>(226), - static_cast<_FP16>(228), static_cast<_FP16>(230), - static_cast<_FP16>(232), static_cast<_FP16>(234), - static_cast<_FP16>(236), static_cast<_FP16>(238)}; + float float_data[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 40, 41, + 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, + 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 160, 162, 164, 166, + 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 188, 190, 192, 194, + 196, 198, 200, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 222, + 224, 226, 228, 230, 232, 234, 236, 238}; + std::transform(float_data, float_data + N, answer_data, + static_cast_func<_FP16>()); nntrainer::TensorV2 answer(ref_dim, answer_data); int status = t.multiply_i(m); EXPECT_EQ(status, ML_ERROR_NONE); @@ -1127,41 +704,20 @@ TEST(nntrainer_Tensor, multiply_i_broadcast_01_fp16_p) { nntrainer::Tdatatype::FP16); nntrainer::TensorV2 m = rangedV2(3, 1, 1, 4, nntrainer::Tformat::NCHW, nntrainer::Tdatatype::FP16); - _FP16 answer_data[] = {static_cast<_FP16>(0), static_cast<_FP16>(1), - static_cast<_FP16>(4), static_cast<_FP16>(9), - static_cast<_FP16>(0), static_cast<_FP16>(5), - static_cast<_FP16>(12), static_cast<_FP16>(21), - static_cast<_FP16>(0), static_cast<_FP16>(9), - static_cast<_FP16>(20), static_cast<_FP16>(33), - static_cast<_FP16>(0), static_cast<_FP16>(13), - static_cast<_FP16>(28), static_cast<_FP16>(45), - static_cast<_FP16>(0), static_cast<_FP16>(17), - static_cast<_FP16>(36), static_cast<_FP16>(57), - static_cast<_FP16>(80), static_cast<_FP16>(105), - static_cast<_FP16>(132), static_cast<_FP16>(161), - static_cast<_FP16>(96), static_cast<_FP16>(125), - static_cast<_FP16>(156), static_cast<_FP16>(189), - static_cast<_FP16>(112), static_cast<_FP16>(145), - static_cast<_FP16>(180), static_cast<_FP16>(217), - static_cast<_FP16>(128), static_cast<_FP16>(165), - static_cast<_FP16>(204), static_cast<_FP16>(245), - static_cast<_FP16>(144), static_cast<_FP16>(185), - static_cast<_FP16>(228), static_cast<_FP16>(273), - static_cast<_FP16>(320), static_cast<_FP16>(369), - static_cast<_FP16>(420), static_cast<_FP16>(473), - static_cast<_FP16>(352), static_cast<_FP16>(405), - static_cast<_FP16>(460), static_cast<_FP16>(517), - static_cast<_FP16>(384), static_cast<_FP16>(441), - static_cast<_FP16>(500), static_cast<_FP16>(561), - static_cast<_FP16>(416), static_cast<_FP16>(477), - static_cast<_FP16>(540), static_cast<_FP16>(605), - static_cast<_FP16>(448), static_cast<_FP16>(513), - static_cast<_FP16>(580), static_cast<_FP16>(649)}; + float float_data[] = {0, 1, 4, 9, 0, 5, 12, 21, 0, 9, + 20, 33, 0, 13, 28, 45, 0, 17, 36, 57, + 80, 105, 132, 161, 96, 125, 156, 189, 112, 145, + 180, 217, 128, 165, 204, 245, 144, 185, 228, 273, + 320, 369, 420, 473, 352, 405, 460, 517, 384, 441, + 500, 561, 416, 477, 540, 605, 448, 513, 580, 649}; + std::transform(float_data, float_data + 60, answer_data, + static_cast_func<_FP16>()); nntrainer::TensorV2 answer(ref_dim, answer_data); int status = t.multiply_i(m); EXPECT_EQ(status, ML_ERROR_NONE); EXPECT_EQ(t, answer); } + delete[] answer_data; } TEST(nntrainer_Tensor, multiply_i_broadcast_not_supported_01_n) {