void convert_to_binary_row(mxnet::NDArray& array) { CHECK(array.shape().ndim() >= 2); // second dimension is input depth from prev. layer, needed for next line std::cout << "array shape: " << array.shape() << std::endl; //if(array.shape()[1] < BITS_PER_BINARY_WORD) return; CHECK(array.shape()[1] % BITS_PER_BINARY_WORD == 0); // depth from input has to be divisible by 32 (or 64) nnvm::TShape binarized_shape(1); size_t size = array.shape().Size(); binarized_shape[0] = size / BITS_PER_BINARY_WORD; mxnet::NDArray temp(binarized_shape, mxnet::Context::CPU(), false, mxnet::op::xnor_cpu::corresponding_dtype()); mxnet::op::xnor_cpu::get_binary_row((float*) array.data().dptr_, (BINARY_WORD*) temp.data().dptr_, size); array = temp; }
void transpose(mxnet::NDArray& array) { CHECK(array.shape().ndim() == 2); nnvm::TShape tansposed_shape(2); int rows = array.shape()[0]; int cols = array.shape()[1]; tansposed_shape[0] = cols; tansposed_shape[1] = rows; mxnet::NDArray temp(tansposed_shape, mxnet::Context::CPU(), false, array.dtype()); MSHADOW_REAL_TYPE_SWITCH(array.dtype(), DType, { for (int row = 0; row < rows; row++) { for (int col = 0; col < cols; col++) { ((DType*)temp.data().dptr_)[col * rows + row] = ((DType*)array.data().dptr_)[row * cols + col]; } } })