*/
#include <algorithm>
-#include <limits.h>
+#include <map>
+#include <limits>
#include <unistd.h>
#include <nnstreamer_plugin_api.h>
#define __ACTIVATION_LAYER_H__
#ifdef __cplusplus
-#include <fstream>
-#include <iostream>
#include <layer.h>
-#include <optimizer.h>
#include <tensor.h>
-#include <vector>
namespace nntrainer {
void copy(std::shared_ptr<Layer> l);
/**
- * @brief setActivation by preset actiType
+ * @brief setActivation by preset ActiType
*
- * @param[in] ActiType actiType actiType to be set
+ * @param[in] ActiType ActiType ActiType to be set
*/
void setActivation(ActiType acti_type);
#define __ADDITION_LAYER_H__
#ifdef __cplusplus
-#include <fstream>
-#include <iostream>
#include <layer.h>
#include <tensor.h>
-#include <vector>
namespace nntrainer {
#define __BLAS_INTERFACE_H_
#ifdef __cplusplus
-#include <assert.h>
-#include <iostream>
-#include <math.h>
-#include <stdio.h>
-
#ifdef USE_BLAS
extern "C" {
#include <cblas.h>
#ifdef __cplusplus
#include <array>
-#include <fstream>
#include <functional>
-#include <iostream>
#include <vector>
#include <layer.h>
-#include <optimizer.h>
#include <tensor.h>
namespace nntrainer {
#define __CONV2D_LAYER_H_
#ifdef __cplusplus
-#include <fstream>
-#include <iostream>
#include <layer.h>
-#include <optimizer.h>
#include <tensor.h>
-#include <vector>
-
-#define CONV2D_DIM 2
namespace nntrainer {
+constexpr const unsigned int CONV2D_DIM = 2;
+
/**
* @class Convolution 2D Layer
* @brief Convolution 2D Layer
#include <iostream>
#include <memory>
#include <random>
-#include <tensor_dim.h>
#include <thread>
-#include <util_func.h>
#include <vector>
-/**
- * @brief Number of Data Set
- */
-#define NBUFTYPE 4
-
-typedef std::vector<std::vector<std::vector<std::vector<float>>>> vec_4d;
+#include <tensor_dim.h>
#define SET_VALIDATION(val) \
do { \
} \
} while (0)
+/**
+ * @brief Number of Data Set
+ */
+constexpr const unsigned int NBUFTYPE = 4;
+
+typedef std::vector<std::vector<std::vector<std::vector<float>>>> vec_4d;
+
typedef enum {
DATA_NOT_READY = 0,
DATA_READY = 1,
* @brief Create Buffer
* @retval DataBuffer
*/
- DataBuffer(DataBufferType type) :
- train_running(),
- val_running(),
- test_running(),
- train_thread(),
- val_thread(),
- test_thread(),
- data_buffer_type(type),
- user_data(nullptr) {
- SET_VALIDATION(false);
- class_num = 0;
- cur_train_bufsize = 0;
- cur_val_bufsize = 0;
- cur_test_bufsize = 0;
- train_bufsize = 0;
- val_bufsize = 0;
- test_bufsize = 0;
- max_train = 0;
- max_val = 0;
- max_test = 0;
- rest_train = 0;
- rest_val = 0;
- rest_test = 0;
- batch_size = 0;
- train_running = false;
- val_running = false;
- test_running = false;
- trainReadyFlag = DATA_NOT_READY;
- valReadyFlag = DATA_NOT_READY;
- testReadyFlag = DATA_NOT_READY;
- rng.seed(getSeed());
- };
+ DataBuffer(DataBufferType type);
/**
* @brief Destructor
#ifdef __cplusplus
#include <atomic>
-#include <databuffer.h>
#include <fstream>
#include <functional>
#include <iostream>
#include <thread>
#include <vector>
+#include <databuffer.h>
+
namespace nntrainer {
/**
#ifdef __cplusplus
#include <atomic>
-#include <databuffer.h>
#include <fstream>
#include <functional>
#include <iostream>
#include <memory>
-#include <nntrainer-api-common.h>
#include <thread>
#include <vector>
+#include <databuffer.h>
+#include <nntrainer-api-common.h>
+
namespace nntrainer {
/**
#define __FC_LAYER_H__
#ifdef __cplusplus
-#include <fstream>
-#include <iostream>
#include <layer.h>
-#include <optimizer.h>
#include <tensor.h>
-#include <vector>
namespace nntrainer {
#define __FLATTEN_LAYER_H__
#ifdef __cplusplus
-#include <fstream>
-#include <iostream>
#include <layer.h>
#include <tensor.h>
-#include <vector>
namespace nntrainer {
#define __INPUT_LAYER_H__
#ifdef __cplusplus
-#include <fstream>
-#include <iostream>
#include <layer.h>
-#include <optimizer.h>
#include <tensor.h>
-#include <vector>
namespace nntrainer {
#define __LAYERS_H__
#ifdef __cplusplus
-#include <fstream>
-#include <iostream>
#include <memory>
-#include <optimizer.h>
#include <set>
+#include <vector>
+
+#include <optimizer.h>
#include <tensor.h>
#include <tensor_dim.h>
-#include <vector>
namespace nntrainer {
/**
- * @brief Enumeration of loss function type
- * 0. MSE ( Mean Squared Error )
- * 1. ENTROPY ( Cross Entropy )
- * 2. ENTROPY_SIGMOID (Cross Entropy amalgamated with sigmoid for
- * stability)
- * 3. ENTROPY_SOFTMAX (Cross Entropy amalgamated with softmax for
- * stability)
- * 4. Unknown
- */
-enum class LossType {
- LOSS_MSE,
- LOSS_ENTROPY,
- LOSS_ENTROPY_SIGMOID,
- LOSS_ENTROPY_SOFTMAX,
- LOSS_UNKNOWN
-};
-
-/**
* @brief Enumeration of activation function type
* 0. tanh
* 1. sigmoid
void setWeightInit(WeightInitializer wini) { weight_initializer = wini; }
/**
- * @brief initialize Weight
- * @param[in] w_dim TensorDim
- * @param[in] initializer Weight Initializer
- * @param[out] status Status
- * @retval Tensor Initialized Tensor
- */
- Tensor initializeWeight(const TensorDim &w_dim, WeightInitializer initializer,
- int &status);
-
- /**
* @brief Set the input dimension
* @param[in] d dimension to be set
*/
return out;
}
+/**
+ * @brief initialize Weight
+ * @param[in] w_dim TensorDim
+ * @param[in] initializer Weight Initializer
+ * @param[out] status Status
+ * @retval Tensor Initialized Tensor
+ */
+// TODO: move out
+Tensor getInitializedTensor(const TensorDim &w_dim,
+ WeightInitializer initializer);
+
} // namespace nntrainer
#endif /* __cplusplus */
#define __LAZY_TENSOR_H__
#ifdef __cplusplus
-#include <nntrainer_error.h>
#include <tensor.h>
#include <vector>
-#define FWD(...) std::forward<decltype(__VA_ARGS__)>(__VA_ARGS__)
-
-#define _LIFT(X) \
- [](nntrainer::Tensor & t, \
- auto &&... args) noexcept(noexcept(t.X(FWD(args)...))) \
- ->decltype(t.X(FWD(args)...)) { \
- return t.X(FWD(args)...); \
- }
-
namespace nntrainer {
/**
LazyTensor &average();
/**
- * @brief apply A tensor function when predicate is true
- * @param[in] bool predicate predicate to check to determine application
- * @param[in] _Callable&& fn function to be applied
- * (Must be wrapped with _LIFT(X) macro to resolve overload set)
- * @param[in] _Args&&... args args for fn
- * @retval LazyTensor *this
- */
- template <typename _Callable, typename... _Args>
- LazyTensor &applyIf(bool predicate, _Callable &&fn, _Args &&... args) {
- if (predicate) {
- auto f = [&](Tensor &t) mutable -> int {
- try {
- return fn(t, std::forward<_Args>(args)...);
- } catch (std::runtime_error &e) {
- return ML_ERROR_INVALID_PARAMETER;
- }
- };
- call_chain.push_back(f);
- }
-
- return *this;
- }
-
- /**
* @brief execute the call_chain to get the tensor
* @retval calculated tensor
*/
#define __LOSS_LAYER_H__
#ifdef __cplusplus
-#include <fstream>
-#include <iostream>
#include <layer.h>
-#include <optimizer.h>
#include <tensor.h>
-#include <vector>
namespace nntrainer {
/**
+ * @brief Enumeration of loss function type
+ */
+enum class LossType {
+ LOSS_MSE, /** Mean Squared Error */
+ LOSS_ENTROPY, /** Cross Entropy */
+ LOSS_ENTROPY_SIGMOID, /** Cross Entropy amalgamated with sigmoid for stability
+ */
+ LOSS_ENTROPY_SOFTMAX, /** Cross Entropy amalgamated with softmax for stability
+ */
+ LOSS_UNKNOWN /** Unknown */
+};
+
+/**
* @class LossLayer
* @brief loss layer
*/
#define __NEURALNET_H__
#ifdef __cplusplus
+#include <vector>
+
#include <activation_layer.h>
#include <bn_layer.h>
#include <conv2d_layer.h>
#include <databuffer.h>
#include <fc_layer.h>
#include <flatten_layer.h>
-#include <fstream>
#include <input_layer.h>
-#include <iostream>
#include <layer.h>
#include <loss_layer.h>
#include <ml-api-common.h>
#include <optimizer.h>
#include <pooling2d_layer.h>
#include <tensor.h>
-#include <vector>
namespace nntrainer {
#define ML_ERROR_BAD_ADDRESS TIZEN_ERROR_BAD_ADDRESS
#define ML_ERROR_RESULT_OUT_OF_RANGE TIZEN_ERROR_RESULT_OUT_OF_RANGE
#else
-#include <errno.h>
+#include <cerrno>
#define ML_ERROR_BAD_ADDRESS (-EFAULT)
#define ML_ERROR_RESULT_OUT_OF_RANGE (-ERANGE)
#endif
#ifdef __cplusplus
#include <fstream>
-#include <iostream>
#include <mutex>
#include <string>
-#include <vector>
/**
* @brief Log Level of NNtrainer
#define __OPTIMIZER_H__
#ifdef __cplusplus
-#include <iostream>
#include <memory>
#include <tensor.h>
/**
* @brief UpdatableParam that could be updated thorugh optimizer
*/
+// TODO: move this out from here
struct UpdatableParam {
Tensor weight; /**< weight to be updated and used */
Tensor grad; /**< gradient for the weight */
#define __POOLING2D_LAYER_H__
#ifdef __cplusplus
-#include <fstream>
-#include <iostream>
#include <layer.h>
#include <tensor.h>
#include <vector>
#ifdef __cplusplus
#include <array>
-#include <cmath>
-#include <fstream>
-#include <iostream>
+#include <functional>
#include <memory>
-#include <regex>
+#include <vector>
+
#include <tensor_dim.h>
#define MAKE_SHARED_TENSOR(x) std::make_shared<nntrainer::Tensor>(x)
return strides;
}
- /**
- * @brief compute Loop info for broadcasting and vectorization
- *
- * @param m target tensor to be calculated against.
- * @return BroadcastInfo Loopinfo needed to run external loop
- */
- BroadcastInfo computeBroadcastInfo(const Tensor &m);
-
private:
/**
* @brief Get linear index given the n-d index
Tensor const &m,
std::function<void(const BroadcastInfo &e, float *, const float *)> v_func);
+ /**
+ * @brief compute Loop info for broadcasting and vectorization
+ *
+ * @param m target tensor to be calculated against.
+ * @return BroadcastInfo Loopinfo needed to run external loop
+ */
+ BroadcastInfo computeBroadcastInfo(const Tensor &m);
+
/**< handle the data as a std::shared_ptr<float> type */
TensorDim dim;
std::array<unsigned int, MAXDIM> strides;
bool is_contiguous;
std::shared_ptr<float> data;
- static constexpr float min_limits = std::numeric_limits<float>::min();
- static constexpr float max_limits = std::numeric_limits<float>::max();
template <typename T> void setDist(T dist);
static constexpr float epsilon = 1e-5;
};
#include <array>
#include <iostream>
-#include <memory>
-#include <regex>
-#include <vector>
namespace nntrainer {
-#define MAXDIM 4
+constexpr const size_t MAXDIM = 4;
class TensorDim {
public:
TensorDim() {
- for (int i = 0; i < MAXDIM; ++i) {
+ for (size_t i = 0; i < MAXDIM; ++i) {
dim[i] = 0;
}
len = 0;
#define __UTIL_FUNC_H__
#ifdef __cplusplus
-#include <layer.h>
#include <tensor.h>
namespace nntrainer {
*
*/
+#include <algorithm>
+#include <cmath>
#include <fstream>
#include <functional>
#include <iostream>
}
/**
- * @brief setActivation by preset actiType
+ * @brief setActivation by preset ActiType
*
- * @param[in] ActiType actiType actiType to be set
+ * @param[in] ActiType ActiType ActiType to be set
*/
void ActivationLayer::setActivation(ActiType acti_type) {
switch (acti_type) {
return PI;
}
-float ActivationLayer::sigmoid(float x) { return 1.0f / (1.0f + exp(-x)); }
+float ActivationLayer::sigmoid(float x) { return 1.0f / (1.0f + exp_util(-x)); }
float ActivationLayer::sigmoidPrime(float x) {
float sprime = sigmoid(x);
*/
#include <blas_interface.h>
+#include <nntrainer_error.h>
+
+#include <cmath>
#define sgemv_loop(ci, cj, cM, cN) \
do { \
}
Tensor mu =
- initializeWeight(dim, initializers[static_cast<int>(BNParams::mu)], status);
- Tensor var = initializeWeight(
- dim, initializers[static_cast<int>(BNParams::var)], status);
- NN_RETURN_STATUS();
-
- Tensor gamma = initializeWeight(
- dim, initializers[static_cast<int>(BNParams::gamma)], status);
- NN_RETURN_STATUS();
-
- Tensor beta = initializeWeight(
- dim, initializers[static_cast<int>(BNParams::beta)], status);
- NN_RETURN_STATUS();
+ getInitializedTensor(dim, initializers[static_cast<int>(BNParams::mu)]);
+ Tensor var =
+ getInitializedTensor(dim, initializers[static_cast<int>(BNParams::var)]);
+
+ Tensor gamma =
+ getInitializedTensor(dim, initializers[static_cast<int>(BNParams::gamma)]);
+ Tensor beta =
+ getInitializedTensor(dim, initializers[static_cast<int>(BNParams::beta)]);
setParamSize(4);
paramsAt(0) = {std::move(mu), Tensor(), "BN:moving_mean", false};
* @brief This is Convolution Layer Class for Neural Network
*
*/
+#include <cstring>
+#include <string>
#include <blas_interface.h>
#include <conv2d_layer.h>
#include <nntrainer_error.h>
#include <nntrainer_log.h>
#include <parse_util.h>
-#include <string>
#include <util_func.h>
namespace nntrainer {
setParamSize(filter_size * 2);
for (unsigned int i = 0; i < filter_size; ++i) {
- Tensor Knl = initializeWeight(dim, weight_initializer, status);
+ Tensor Knl = getInitializedTensor(dim, weight_initializer);
NN_RETURN_STATUS();
- Tensor bias = initializeWeight(bias_dim, bias_initializer, status);
+ Tensor bias = getInitializedTensor(bias_dim, bias_initializer);
NN_RETURN_STATUS();
Tensor delK(dim);
Tensor &delK = paramsAt(i).grad;
Tensor &filters = paramsAt(i).weight;
- delK = delK.chain()
- .applyIf(this->isWeightRegularizerL2Norm(), _LIFT(add_i),
- filters, weight_regularizer.constant)
- .run();
+ if (isWeightRegularizerL2Norm()) {
+ status = delK.add_i(filters, weight_regularizer.constant);
+ if (status != ML_ERROR_NONE)
+ throw std::runtime_error("Weight regularization failed");
+ }
}
opt.apply_gradients(params, param_size, iteration);
int status = ML_ERROR_NONE;
switch (type) {
case PropertyType::kernel_size:
- for (int i = 0; i < CONV2D_DIM; ++i) {
+ for (unsigned int i = 0; i < CONV2D_DIM; ++i) {
kernel_size[i] = size[i];
}
break;
case PropertyType::stride:
- for (int i = 0; i < CONV2D_DIM; ++i) {
+ for (unsigned int i = 0; i < CONV2D_DIM; ++i) {
stride[i] = size[i];
}
break;
case PropertyType::padding:
- for (int i = 0; i < CONV2D_DIM; ++i) {
+ for (unsigned int i = 0; i < CONV2D_DIM; ++i) {
padding[i] = size[i];
}
break;
#include <stdio.h>
#include <stdlib.h>
#include <thread>
+#include <util_func.h>
std::exception_ptr globalExceptionPtr = nullptr;
std::condition_variable cv_val;
std::condition_variable cv_test;
+DataBuffer::DataBuffer(DataBufferType type) :
+ train_running(),
+ val_running(),
+ test_running(),
+ train_thread(),
+ val_thread(),
+ test_thread(),
+ data_buffer_type(type),
+ user_data(nullptr) {
+ SET_VALIDATION(false);
+ class_num = 0;
+ cur_train_bufsize = 0;
+ cur_val_bufsize = 0;
+ cur_test_bufsize = 0;
+ train_bufsize = 0;
+ val_bufsize = 0;
+ test_bufsize = 0;
+ max_train = 0;
+ max_val = 0;
+ max_test = 0;
+ rest_train = 0;
+ rest_val = 0;
+ rest_test = 0;
+ batch_size = 0;
+ train_running = false;
+ val_running = false;
+ test_running = false;
+ trainReadyFlag = DATA_NOT_READY;
+ valReadyFlag = DATA_NOT_READY;
+ testReadyFlag = DATA_NOT_READY;
+ rng.seed(getSeed());
+};
+
int DataBuffer::rangeRandom(int min, int max) {
std::uniform_int_distribution<int> dist(min, max);
return dist(rng);
TensorDim dim = output_dim;
dim.height(input_dim.width());
dim.batch(1);
- Tensor weight = initializeWeight(dim, weight_initializer, status);
- NN_RETURN_STATUS();
- Tensor bias = initializeWeight(bias_dim, bias_initializer, status);
- NN_RETURN_STATUS();
+ Tensor weight = getInitializedTensor(dim, weight_initializer);
+ Tensor bias = getInitializedTensor(bias_dim, bias_initializer);
setParamSize(2);
paramsAt(0) = {std::move(weight), Tensor(weight.getDim()), "FC:weight"};
}
}
-Tensor Layer::initializeWeight(const TensorDim &w_dim,
- WeightInitializer initializer, int &status) {
-
+Tensor getInitializedTensor(const TensorDim &w_dim,
+ WeightInitializer initializer) {
Tensor w = Tensor(w_dim);
if (initializer == WEIGHT_UNKNOWN) {
w.setValue(1.0f);
break;
case WEIGHT_LECUN_NORMAL:
- w.setRandNormal(0.0f, sqrt(1.0f / w_dim.height()));
+ w.setRandNormal(0.0f, sqrtFloat(1.0f / w_dim.height()));
break;
case WEIGHT_XAVIER_NORMAL:
- w.setRandNormal(0.0f, sqrt(2.0f / (w_dim.width() + w_dim.height())));
+ w.setRandNormal(0.0f, sqrtFloat(2.0f / (w_dim.width() + w_dim.height())));
break;
case WEIGHT_HE_NORMAL:
- w.setRandNormal(0.0f, sqrt(2.0f / (w_dim.height())));
+ w.setRandNormal(0.0f, sqrtFloat(2.0f / (w_dim.height())));
break;
case WEIGHT_LECUN_UNIFORM:
- w.setRandUniform(-1.0f * sqrt(1.0f / w_dim.height()),
- sqrt(1.0f / w_dim.height()));
+ w.setRandUniform(-1.0f * sqrtFloat(1.0f / w_dim.height()),
+ sqrtFloat(1.0f / w_dim.height()));
break;
case WEIGHT_XAVIER_UNIFORM:
- w.setRandUniform(-1.0f * sqrt(6.0f / (w_dim.height() + w_dim.width())),
- sqrt(6.0 / (w_dim.height() + w_dim.width())));
+ w.setRandUniform(-1.0f * sqrtFloat(6.0f / (w_dim.height() + w_dim.width())),
+ sqrtFloat(6.0 / (w_dim.height() + w_dim.width())));
break;
case WEIGHT_HE_UNIFORM:
- w.setRandUniform(-1.0f * sqrt(6.0f / (w_dim.height())),
- sqrt(6.0 / (w_dim.height())));
+ w.setRandUniform(-1.0f * sqrtFloat(6.0f / (w_dim.height())),
+ sqrtFloat(6.0 / (w_dim.height())));
break;
default:
break;
}
+
return w;
}
*/
#include <lazy_tensor.h>
-#include <tensor.h>
+#include <nntrainer_error.h>
namespace nntrainer {
*/
#include <activation_layer.h>
+#include <cmath>
#include <layer.h>
#include <lazy_tensor.h>
#include <loss_layer.h>
#include <cstring>
#include <ctime>
#include <iomanip>
+#include <mutex>
#include <nntrainer_logger.h>
#include <sstream>
#include <stdarg.h>
*
*/
+#include <cmath>
+#include <fstream>
#include <iostream>
+
#include <lazy_tensor.h>
#include <nntrainer_error.h>
#include <nntrainer_log.h>
*
*/
+#include <cstring>
+#include <limits>
+
#include <layer.h>
#include <lazy_tensor.h>
#include <nntrainer_error.h>
*/
#include <assert.h>
-#include <blas_interface.h>
+#include <cmath>
#include <cstring>
+#include <fstream>
#include <iomanip>
#include <iterator>
-#include <math.h>
-#include <nntrainer_error.h>
-#include <nntrainer_log.h>
-#include <parse_util.h>
#include <random>
+#include <regex>
#include <sstream>
#include <stdio.h>
-#include <tensor.h>
-#include <util_func.h>
+#include <blas_interface.h>
#include <lazy_tensor.h>
+#include <nntrainer_error.h>
+#include <nntrainer_log.h>
+#include <parse_util.h>
+#include <tensor.h>
+#include <util_func.h>
#define transposeloop(cl, ci, cj, ck, sl, si, sj, sk) \
do { \
*
*/
-#include <assert.h>
#include <cstring>
+#include <regex>
#include <sstream>
#include <stdio.h>
"[TensorDim] Trying to assign value <=0 to tensor dim");
if (len == 0) {
- for (int i = 0; i < MAXDIM; ++i) {
+ for (size_t i = 0; i < MAXDIM; ++i) {
dim[i] = 1;
}
}
std::sregex_iterator(input_shape.begin(), input_shape.end(), words_regex);
auto words_end = std::sregex_iterator();
int cur_dim = std::distance(words_begin, words_end);
- if (cur_dim <= 0 || cur_dim > MAXDIM) {
+ if (cur_dim <= 0 || (size_t)cur_dim > MAXDIM) {
ml_loge("Tensor Dimension should be between 1 and 4");
return ML_ERROR_INVALID_PARAMETER;
}
}
bool TensorDim::operator==(const TensorDim &rhs) const {
- for (int i = 0; i < MAXDIM; ++i) {
+ for (size_t i = 0; i < MAXDIM; ++i) {
if (this->dim[i] != rhs.dim[i]) {
return false;
}
*
*/
-#include <assert.h>
-#include <math.h>
+#include <cmath>
+#include <fstream>
#include <random>
-#include <tensor.h>
+
#include <util_func.h>
namespace nntrainer {
#include <iostream>
#include <nntrainer_error.h>
#include <random>
+#include <regex>
#include <tensor.h>
#define num_class 10
* @bug No known bugs
*/
#include <fstream>
+#include <regex>
#include <activation_layer.h>
#include <addition_layer.h>
EXPECT_TRUE(target.chain().sum(3).run() == expected);
}
-TEST_F(nntrainer_LazyTensorOpsTest, ApplyIf_01_p) {
-
- EXPECT_TRUE(
- target.chain().applyIf(true, _LIFT(add_i), constant_(4.0), 0.5).run() ==
- original.add(2.0));
-
- EXPECT_TRUE(target.chain().applyIf(true, _LIFT(add_i), 2.0f).run() ==
- original.add(2.0));
-
- EXPECT_TRUE(target.chain().applyIf(true, _LIFT(add_i), 2.0).run() ==
- original.add(2.0));
-}
-
-TEST_F(nntrainer_LazyTensorOpsTest, ApplyIf_01_n) {
- EXPECT_THROW(
- target.chain().applyIf(true, _LIFT(add_i), constant(4.0, 9, 9, 9, 9)).run(),
- std::runtime_error);
-}
-
/**
* @brief Main gtest
*/
EXPECT_EQ(ss.str(), expected.str());
}
-TEST(nntrainer_Tensor, DISABLED_broadcast_info_n) {
- nntrainer::Tensor t = ranged(1, 1, 2, 1);
- nntrainer::Tensor b = ranged(1, 1, 2, 1);
-
- auto vector_func = [](float *buf, int stride, int size) {
- float *cur = buf;
- std::cerr << "[ ";
- for (int i = 0; i < size; ++i) {
- std::cerr << *cur << ' ';
- cur += stride;
- }
- std::cerr << "]\n";
- };
-
- nntrainer::BroadcastInfo e;
- EXPECT_NO_THROW(e = t.computeBroadcastInfo(b));
-
- float *buf = t.getData();
- float *mbuf = b.getData();
-
- auto &t_strides = t.getStrides();
- unsigned int offset;
- unsigned int m_offset;
-
- if (e.buffer_axis == -1) {
- vector_func(buf, t_strides[3], e.buffer_size);
- vector_func(mbuf, e.strides[3], e.buffer_size);
- } else {
- for (unsigned int b = 0; b < t.batch(); ++b) {
- if (e.buffer_axis == 0) {
- offset = b * t_strides[0];
- m_offset = b * e.strides[0];
- std::cerr << "=====================\n";
- vector_func(buf + offset, t_strides[3], e.buffer_size);
- vector_func(mbuf + m_offset, e.strides[3], e.buffer_size);
- continue;
- }
- for (unsigned int c = 0; c < t.channel(); ++c) {
- if (e.buffer_axis == 1) {
- offset = b * t_strides[0] + c * t_strides[1];
- m_offset = b * e.strides[0] + c * e.strides[1];
- std::cerr << "=====================\n";
- vector_func(buf + offset, t_strides[3], e.buffer_size);
- vector_func(mbuf + m_offset, e.strides[3], e.buffer_size);
- continue;
- }
- for (unsigned int h = 0; h < t.height(); ++h) {
- if (e.buffer_axis == 2) {
- offset = b * t_strides[0] + c * t_strides[1] + h * t_strides[2];
- m_offset = b * e.strides[0] + c * e.strides[1] + h * e.strides[2];
- std::cerr << "=====================\n";
- vector_func(buf + offset, t_strides[3], e.buffer_size);
- vector_func(mbuf + m_offset, e.strides[3], e.buffer_size);
- continue;
- }
- for (unsigned int w = 0; w < t.width(); ++w) {
- offset = b * t_strides[0] + c * t_strides[1] + h * t_strides[2] +
- w * t_strides[3];
- m_offset = b * e.strides[0] + c * e.strides[1] + h * e.strides[2] +
- w * e.strides[3];
- std::cerr << "after width: " << offset << std::endl;
- std::cerr << "=====================\n";
- vector_func(buf + offset, t_strides[3], e.buffer_size);
- vector_func(mbuf + m_offset, e.strides[3], e.buffer_size);
- }
- }
- }
- }
- }
- std::cerr << "buffer_axis: " << e.buffer_axis << std::endl;
- std::cerr << "t strides: ";
- for (auto i : t_strides)
- std::cerr << i << ' ';
- std::cerr << std::endl;
- std::cerr << "strides: ";
- for (auto i : e.strides)
- std::cerr << i << ' ';
- std::cerr << std::endl;
- std::cerr << "buffer_size: " << e.buffer_size << std::endl;
-}
-
TEST(nntrainer_Tensor, DISABLED_equation_test_01_p) {
nntrainer::Tensor a, b, c;
nntrainer::Tensor ret1, ret2;