[Tensor] remove unused code
authorDonghyeon Jeong <dhyeon.jeong@samsung.com>
Thu, 17 Aug 2023 04:40:23 +0000 (13:40 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Mon, 21 Aug 2023 06:29:23 +0000 (15:29 +0900)
- Remove unused code.

Signed-off-by: Donghyeon Jeong <dhyeon.jeong@samsung.com>
nntrainer/tensor/blas_interface.cpp
nntrainer/tensor/tensor.cpp
nntrainer/tensor/tensor.h
nntrainer/tensor/tensor_dim.cpp

index 603bcd9df1ec6c16c36db362470fe93a0bac37b1..059ebd9676db13eceeaf46f4b328baa53502036b 100644 (file)
@@ -12,7 +12,6 @@
  */
 
 #include <blas_interface.h>
-#include <iostream>
 #include <nntrainer_error.h>
 
 #ifdef USE__FP16
index 0444dcbbca1c2bba96369f4f8d2e1fb1a8e864e1..f965029c276442e91245248258feb2faae8b55f8 100644 (file)
@@ -127,8 +127,7 @@ public:
   SrcSharedTensor() : src(nullptr), off(0) {}
 
   SrcSharedTensor(const Tensor *tensor, size_t offset) :
-    src(tensor),
-    off(offset) {}
+    src(tensor), off(offset) {}
 
   /**
    * @brief   Get the allocated src tensor
@@ -2541,57 +2540,6 @@ void Tensor::zoneout_mask(Tensor &opposite, float zoneout) {
   }
 }
 
-// int Tensor::apply_i(std::function<float(float)> f) {
-//   Tensor result = *this;
-//   apply(f, result);
-
-//   return ML_ERROR_NONE;
-// }
-
-// Tensor Tensor::apply(std::function<float(float)> f) const {
-//   Tensor result;
-//   return apply(f, result);
-// }
-
-// Tensor &Tensor::apply(std::function<float(float)> f, Tensor &output) const {
-//   CREATE_IF_EMPTY_DIMS(output, dim);
-
-//   if (dim != output.dim) {
-//     /// @todo add unittest
-//     throw std::invalid_argument(
-//       "[Tensor::apply] output dimension does not match");
-//   }
-
-//   if (contiguous && output.contiguous) {
-//     const float *data = getData();
-//     float *rdata = output.getData();
-//     std::transform(data, data + size(), rdata, f);
-//   } else if (strides[3] == 1 && output.strides[3] == 1) {
-//     /** @todo optimize this with combining these loops where stride is 1 */
-//     for (unsigned int b = 0; b < batch(); ++b) {
-//       for (unsigned int c = 0; c < channel(); ++c) {
-//         for (unsigned int h = 0; h < height(); ++h) {
-//           float *out_data = output.getAddress(b, c, h, 0);
-//           const float *in_data = getAddress(b, c, h, 0);
-//           std::transform(in_data, in_data + width(), out_data, f);
-//         }
-//       }
-//     }
-//   } else {
-//     for (unsigned int b = 0; b < batch(); ++b) {
-//       for (unsigned int c = 0; c < channel(); ++c) {
-//         for (unsigned int h = 0; h < height(); ++h) {
-//           for (unsigned int w = 0; w < width(); ++w) {
-//             output.setValue(b, c, h, w, f(getValue(b, c, h, w)));
-//           }
-//         }
-//       }
-//     }
-//   }
-
-//   return output;
-// }
-
 Tensor Tensor::apply(std::function<Tensor(Tensor)> f) const { return f(*this); }
 
 Tensor &Tensor::apply(std::function<Tensor &(Tensor, Tensor &)> f,
index 1bbe5a2a22f0db8ae2db06bd2ca98b5d02c8f860..559d2a4e6afdb05b7cefe6cef65d74c05ff5ef18 100644 (file)
@@ -1209,72 +1209,6 @@ public:
       }
     }
 
-    // if (dim.getDataType() == Tdatatype::FP32) {
-    //   if (contiguous && output.contiguous) {
-    //     const float *data = (getData<float>());
-    //     float *rdata = (output.getData<float>());
-
-    //     std::transform(data, data + size(), rdata, f);
-    //   } else if (strides[3] == 1 && output.strides[3] == 1) {
-    //     /** @todo optimize this with combining these loops where stride is 1
-    //     */ for (unsigned int b = 0; b < batch(); ++b) {
-    //       for (unsigned int c = 0; c < channel(); ++c) {
-    //         for (unsigned int h = 0; h < height(); ++h) {
-    //           float *out_data = output.getAddress<float>(b, c, h, 0);
-    //           const float *in_data = getAddress<float>(b, c, h, 0);
-    //           std::transform(in_data, in_data + width(), out_data, f);
-    //         }
-    //       }
-    //     }
-    //   } else {
-    //     for (unsigned int b = 0; b < batch(); ++b) {
-    //       for (unsigned int c = 0; c < channel(); ++c) {
-    //         for (unsigned int h = 0; h < height(); ++h) {
-    //           for (unsigned int w = 0; w < width(); ++w) {
-    //             output.setValue(b, c, h, w, f(getValue<float>(b, c, h, w)));
-    //           }
-    //         }
-    //       }
-    //     }
-    //   }
-    // } else if (dim.getDataType() == Tdatatype::FP16) {
-
-    //   auto f_16 = [f](_FP16 x) -> _FP16 {
-    //     return static_cast<_FP16>(f(static_cast<float>(x)));
-    //   };
-
-    //   // std::function<_FP16(_FP16)> f_16 =
-    //   //   static_cast<std::function<_FP16(_FP16)>>(f);
-
-    //   if (contiguous && output.contiguous) {
-    //     const _FP16 *data = (getData<_FP16>());
-    //     _FP16 *rdata = (output.getData<_FP16>());
-
-    //     std::transform(data, data + size(), rdata, f_16);
-    //   } else if (strides[3] == 1 && output.strides[3] == 1) {
-    //     /** @todo optimize this with combining these loops where stride is 1
-    //     */ for (unsigned int b = 0; b < batch(); ++b) {
-    //       for (unsigned int c = 0; c < channel(); ++c) {
-    //         for (unsigned int h = 0; h < height(); ++h) {
-    //           _FP16 *out_data = output.getAddress<_FP16>(b, c, h, 0);
-    //           const _FP16 *in_data = getAddress<_FP16>(b, c, h, 0);
-    //           std::transform(in_data, in_data + width(), out_data, f_16);
-    //         }
-    //       }
-    //     }
-    //   } else {
-    //     for (unsigned int b = 0; b < batch(); ++b) {
-    //       for (unsigned int c = 0; c < channel(); ++c) {
-    //         for (unsigned int h = 0; h < height(); ++h) {
-    //           for (unsigned int w = 0; w < width(); ++w) {
-    //             output.setValue(b, c, h, w, f_16(getValue<_FP16>(b, c, h,
-    //             w)));
-    //           }
-    //         }
-    //       }
-    //     }
-    //   }
-    // }
     return output;
   };
 
@@ -1290,90 +1224,6 @@ public:
     return result;
   };
 
-  // /**
-  //  * @brief Apply instantly to the element
-  //  *
-  //  * @param f function to apply
-  //  * @return int ML_ERROR_NONE if successful
-  //  */
-  // int apply_i(std::function<_FP16(_FP16)> f) {
-  //   Tensor result = *this;
-  //   apply(f, result);
-
-  //   return ML_ERROR_NONE;
-  // };
-
-  // /**
-  //  * @brief     Apply function element by element
-  //  * @param[in] *function function pointer applied
-  //  * @retval    Tensor
-  //  */
-  // Tensor apply(std::function<_FP16(_FP16)> f) const {
-  //   Tensor result;
-  //   return apply(f, result);
-  // };
-
-  // /**
-  //  * @brief     Apply function element by element
-  //  * @param[in] *function function pointer applied
-  //  * @retval    Tensor
-  //  */
-  // Tensor apply(std::function<float(float)> f) const {
-  //   Tensor result;
-  //   return apply(f, result);
-  // };
-
-  // /**
-  //  * @brief     Apply function element by element
-  //  * @param[in] *function function pointer applied
-  //  * @param[out] output output tensor
-  //  * @retval    Tensor
-  //  */
-  // Tensor &apply(std::function<_FP16(_FP16)> f, Tensor &output) const {
-  //   CREATE_IF_EMPTY_DIMS(output, dim, nullptr);
-
-  //   if (dim != output.dim) {
-  //     /// @todo add unittest
-  //     throw std::invalid_argument(
-  //       "[Tensor::apply] output dimension does not match");
-  //   }
-
-  //   #ifdef ENABLE_FP16
-  //     if (contiguous && output.contiguous) {
-  //       const _FP16 *data = (getData<_FP16>());
-  //       _FP16 *rdata = (output.getData<_FP16>());
-
-  //       std::transform(data, data + size(), rdata, f);
-  //     } else if (strides[3] == 1 && output.strides[3] == 1) {
-  //       /** @todo optimize this with combining these loops where stride is 1
-  //       */ for (unsigned int b = 0; b < batch(); ++b) {
-  //         for (unsigned int c = 0; c < channel(); ++c) {
-  //           for (unsigned int h = 0; h < height(); ++h) {
-  //             _FP16 *out_data = (_FP16 *)output.getAddress(b, c, h, 0);
-  //             const _FP16 *in_data = (_FP16 *)getAddress(b, c, h, 0);
-  //             std::transform(in_data, in_data + width(), out_data, f);
-  //           }
-  //         }
-  //       }
-  //     } else {
-  //       for (unsigned int b = 0; b < batch(); ++b) {
-  //         for (unsigned int c = 0; c < channel(); ++c) {
-  //           for (unsigned int h = 0; h < height(); ++h) {
-  //             for (unsigned int w = 0; w < width(); ++w) {
-  //               output.setValue(b, c, h, w,
-  //                               f((_FP16)((_FP16)getValue(b, c, h, w))));
-  //             }
-  //           }
-  //         }
-  //       }
-  //     }
-  //   #else
-  //     throw std::invalid_argument("Error: enable-fp16 is not enabled");
-  //   #endif
-
-  //   return output;
-  // };
-
   /**
    * @brief     Apply function to Tensor
    * @param[in] *function function pointer applied
index 0cf53c8947c2e9f49e792eaf5c1cef6077d7ee1a..b99e18f931c89f973403c325e1253d21233ec140 100644 (file)
@@ -17,7 +17,6 @@
 #include <sstream>
 #include <stdio.h>
 
-#include <iostream>
 #include <nntrainer_error.h>
 #include <nntrainer_log.h>
 #include <tensor_dim.h>
@@ -34,9 +33,7 @@ TensorDim::TensorDim(TensorDim::Format fm, TensorDim::DataType d_type,
 TensorDim::TensorDim(TensorType t_type_,
                      const std::bitset<MAXDIM> &eff_dim_flag_,
                      const std::bitset<MAXDIM> &dyn_dim_flag_) :
-  t_type(t_type_),
-  eff_dim_flag(eff_dim_flag_),
-  dyn_dim_flag(dyn_dim_flag_) {
+  t_type(t_type_), eff_dim_flag(eff_dim_flag_), dyn_dim_flag(dyn_dim_flag_) {
   for (size_t i = 0; i < MAXDIM; ++i) {
     dim[i] = 0;
   }
@@ -181,12 +178,6 @@ int TensorDim::setTensorDim(const std::string &input_shape,
   return status;
 }
 
-// int TensorDim::setTensorDim(const std::string &input_shape,
-//                             TensorDim::Format fm, TensorDim::DataType d_type)
-//                             {
-//   return setTensorDim(input_shape, TensorType{fm, d_type});
-// }
-
 void TensorDim::setEffDimFlag(const std::bitset<MAXDIM> &dim_flag_) {
   eff_dim_flag = dim_flag_;
 }