[Bug] Fix unchanged work in Apply template
authorDonghyeon Jeong <dhyeon.jeong@samsung.com>
Thu, 3 Aug 2023 04:52:03 +0000 (13:52 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Mon, 21 Aug 2023 06:29:23 +0000 (15:29 +0900)
FP16 is seperated from FP32 in apply function.

Signed-off-by: Donghyeon Jeong <dhyeon.jeong@samsung.com>
test/nntrainer_test_util.cpp
test/unittest/unittest_nntrainer_tensor_fp16.cpp

index 4996303..fd7eaec 100644 (file)
@@ -188,13 +188,13 @@ nntrainer::Tensor ranged(unsigned int batch, unsigned int channel,
                          nntrainer::Tformat fm, nntrainer::Tdatatype d_type) {
   nntrainer::TensorDim::TensorType t_type(fm, d_type);
   nntrainer::Tensor t(batch, channel, height, width, t_type);
-  // if (t_type.data_type == nntrainer::Tdatatype::FP32) {
+  if (t_type.data_type == nntrainer::Tdatatype::FP32) {
     float i = 0;
     t = t.apply((std::function<float(float)>)[&](float in) { return i++; });
-  // } else if (t_type.data_type == nntrainer::Tdatatype::FP16) {
-  //   _FP16 i = 0;
-  //   t = t.apply((std::function<_FP16(_FP16)>)[&](_FP16 in) { return i++; });
-  // }
+  } else if (t_type.data_type == nntrainer::Tdatatype::FP16) {
+    _FP16 i = 0;
+    t = t.apply((std::function<_FP16(_FP16)>)[&](_FP16 in) { return i++; });
+  }
 
   return t;
 }
@@ -203,7 +203,7 @@ nntrainer::Tensor randUniform(unsigned int batch, unsigned int channel,
                               unsigned int height, unsigned int width,
                               float min, float max, nntrainer::Tformat fm,
                               nntrainer::Tdatatype d_type) {
-  nntrainer::TensorDim::TensorType t_type(fm, d_type);                              
+  nntrainer::TensorDim::TensorType t_type(fm, d_type);
   nntrainer::Tensor t(batch, channel, height, width, t_type);
   t.setRandUniform(min, max);
   return t;
index bc28612..43e8789 100644 (file)
@@ -3752,7 +3752,9 @@ TEST(nntrainer_Tensor, average_axis_p) {
   nntrainer::Tensor t = constant(1.0, 2, 2, 2, 2, nntrainer::Tformat::NCHW,
                                  nntrainer::Tdatatype::FP16);
   int idx = 0;
-  std::function<float(float)> f = [&](float in) { return idx++ % 2; };
+  std::function<_FP16(_FP16)> f = [&](_FP16 in) {
+    return static_cast<_FP16>(idx++ % 2);
+  };
   t = t.apply(f);
 
   nntrainer::Tensor actual, expected;