diff --git a/libnd4j/include/ops/declarable/platform/mkldnn/mkldnnUtils.h b/libnd4j/include/ops/declarable/platform/mkldnn/mkldnnUtils.h index e0e1b83c2..5f8fa2755 100644 --- a/libnd4j/include/ops/declarable/platform/mkldnn/mkldnnUtils.h +++ b/libnd4j/include/ops/declarable/platform/mkldnn/mkldnnUtils.h @@ -14,14 +14,15 @@ * SPDX-License-Identifier: Apache-2.0 ******************************************************************************/ -// -// @author saudet -// @author Yurii Shyrma (iuriish@yahoo.com) -// + // + // @author saudet + // @author Yurii Shyrma (iuriish@yahoo.com) + // #ifndef DEV_TESTS_MKLDNNUTILS_H #define DEV_TESTS_MKLDNNUTILS_H + #include #include #include @@ -33,7 +34,7 @@ using namespace samediff; -namespace sd{ +namespace sd { namespace ops { namespace platforms { /** @@ -86,64 +87,67 @@ namespace sd{ DECLARE_PLATFORM(depthwise_conv2d_bp, ENGINE_CPU); DECLARE_PLATFORM(matmul, ENGINE_CPU); + + DECLARE_PLATFORM(softmax, ENGINE_CPU); + } } namespace mkldnnUtils { - void poolingMKLDNN(const NDArray *input, NDArray *output, const int kD, const int kH, const int kW, const int sD, const int sH, const int sW, const int pD, const int pH, const int pW, const int isNCHW, const dnnl::algorithm mode); + void poolingMKLDNN(const NDArray* input, NDArray* output, const int kD, const int kH, const int kW, const int sD, const int sH, const int sW, const int pD, const int pH, const int pW, const int isNCHW, const dnnl::algorithm mode); - void poolingBpMKLDNN(const NDArray *input, const NDArray *gradO, NDArray *gradI, const int kD, const int kH, const int kW, const int sD, const int sH, const int sW, const int pD, const int pH, const int pW, const int isNCHW, const dnnl::algorithm mode); + void poolingBpMKLDNN(const NDArray* input, const NDArray* gradO, NDArray* gradI, const int kD, const int kH, const int kW, const int sD, const int sH, const int sW, const int pD, const int pH, const int pW, const int isNCHW, const dnnl::algorithm mode); void getMKLDNNMemoryDescLrn(const NDArray* src, const NDArray* diff_src, const NDArray* dst, - dnnl::memory::desc* lrn_src_md, dnnl::memory::desc* lrn_diff_src_md, dnnl::memory::desc* lrn_dst_md, - dnnl::memory::desc* user_src_md, dnnl::memory::desc* user_diff_src_md, dnnl::memory::desc* user_dst_md, int axis); + dnnl::memory::desc* lrn_src_md, dnnl::memory::desc* lrn_diff_src_md, dnnl::memory::desc* lrn_dst_md, + dnnl::memory::desc* user_src_md, dnnl::memory::desc* user_diff_src_md, dnnl::memory::desc* user_dst_md, int axis); - dnnl::engine& getEngine(void *ptr); + dnnl::engine& getEngine(void* ptr); /** * Utility methods for MKLDNN */ -/* void getMKLDNNMemoryDescConv2d( - int kH, int kW, int sH, int sW, int pH, int pW, int dH, int dW, const int paddingMode, bool isNCHW, - int bS, int iC, int iH, int iW, int oC, int oH, int oW, const NDArray* src, const NDArray* diff_src, - const NDArray* weights, const NDArray* diff_weights, const NDArray* bias, const NDArray* dst, - dnnl::memory::desc* conv_src_md, dnnl::memory::desc* conv_diff_src_md, dnnl::memory::desc* conv_weights_md, - dnnl::memory::desc* conv_diff_weights_md, dnnl::memory::desc* conv_bias_md, dnnl::memory::desc* conv_dst_md, - dnnl::memory::desc* user_src_md, dnnl::memory::desc* user_diff_src_md, dnnl::memory::desc* user_weights_md, - dnnl::memory::desc* user_diff_weights_md, dnnl::memory::desc* user_bias_md, dnnl::memory::desc* user_dst_md, - dnnl::memory::dims& conv_strides, dnnl::memory::dims& conv_padding, dnnl::memory::dims& conv_padding_r, dnnl::memory::dims& conv_dilation); + /* void getMKLDNNMemoryDescConv2d( + int kH, int kW, int sH, int sW, int pH, int pW, int dH, int dW, const int paddingMode, bool isNCHW, + int bS, int iC, int iH, int iW, int oC, int oH, int oW, const NDArray* src, const NDArray* diff_src, + const NDArray* weights, const NDArray* diff_weights, const NDArray* bias, const NDArray* dst, + dnnl::memory::desc* conv_src_md, dnnl::memory::desc* conv_diff_src_md, dnnl::memory::desc* conv_weights_md, + dnnl::memory::desc* conv_diff_weights_md, dnnl::memory::desc* conv_bias_md, dnnl::memory::desc* conv_dst_md, + dnnl::memory::desc* user_src_md, dnnl::memory::desc* user_diff_src_md, dnnl::memory::desc* user_weights_md, + dnnl::memory::desc* user_diff_weights_md, dnnl::memory::desc* user_bias_md, dnnl::memory::desc* user_dst_md, + dnnl::memory::dims& conv_strides, dnnl::memory::dims& conv_padding, dnnl::memory::dims& conv_padding_r, dnnl::memory::dims& conv_dilation); - void getMKLDNNMemoryDescConv3d( - int kD, int kH, int kW, int sD, int sH, int sW, int pD, int pH, int pW, int dD, int dH, int dW, bool isSameMode, bool isNCDHW, - int bS, int iC, int iD, int iH, int iW, int oC, int oD, int oH, int oW, const NDArray* src, const NDArray* diff_src, - const NDArray* weights, const NDArray* diff_weights, const NDArray* bias, const NDArray* dst, - dnnl::memory::desc* conv_src_md, dnnl::memory::desc* conv_diff_src_md, dnnl::memory::desc* conv_weights_md, - dnnl::memory::desc* conv_diff_weights_md, dnnl::memory::desc* conv_bias_md, dnnl::memory::desc* conv_dst_md, - dnnl::memory::desc* user_src_md, dnnl::memory::desc* user_diff_src_md, dnnl::memory::desc* user_weights_md, - dnnl::memory::desc* user_diff_weights_md, dnnl::memory::desc* user_bias_md, dnnl::memory::desc* user_dst_md, - dnnl::memory::dims& conv_strides, dnnl::memory::dims& conv_padding, dnnl::memory::dims& conv_padding_r, dnnl::memory::dims& conv_dilation); + void getMKLDNNMemoryDescConv3d( + int kD, int kH, int kW, int sD, int sH, int sW, int pD, int pH, int pW, int dD, int dH, int dW, bool isSameMode, bool isNCDHW, + int bS, int iC, int iD, int iH, int iW, int oC, int oD, int oH, int oW, const NDArray* src, const NDArray* diff_src, + const NDArray* weights, const NDArray* diff_weights, const NDArray* bias, const NDArray* dst, + dnnl::memory::desc* conv_src_md, dnnl::memory::desc* conv_diff_src_md, dnnl::memory::desc* conv_weights_md, + dnnl::memory::desc* conv_diff_weights_md, dnnl::memory::desc* conv_bias_md, dnnl::memory::desc* conv_dst_md, + dnnl::memory::desc* user_src_md, dnnl::memory::desc* user_diff_src_md, dnnl::memory::desc* user_weights_md, + dnnl::memory::desc* user_diff_weights_md, dnnl::memory::desc* user_bias_md, dnnl::memory::desc* user_dst_md, + dnnl::memory::dims& conv_strides, dnnl::memory::dims& conv_padding, dnnl::memory::dims& conv_padding_r, dnnl::memory::dims& conv_dilation); - void getMKLDNNMemoryDescPool2d( - int kH, int kW, int sH, int sW, int pH, int pW, int dH, int dW, int poolingMode, int extraParam0, bool isNCHW, - int bS, int iC, int iH, int iW, int oC, int oH, int oW, - const NDArray* src, const NDArray* diff_src, const NDArray* dst, dnnl::algorithm& algorithm, - dnnl::memory::desc* pool_src_md, dnnl::memory::desc* pool_diff_src_md, dnnl::memory::desc* pool_dst_md, - dnnl::memory::desc* user_src_md, dnnl::memory::desc* user_diff_src_md, dnnl::memory::desc* user_dst_md, - dnnl::memory::dims& pool_strides, dnnl::memory::dims& pool_kernel, dnnl::memory::dims& pool_padding, dnnl::memory::dims& pool_padding_r); + void getMKLDNNMemoryDescPool2d( + int kH, int kW, int sH, int sW, int pH, int pW, int dH, int dW, int poolingMode, int extraParam0, bool isNCHW, + int bS, int iC, int iH, int iW, int oC, int oH, int oW, + const NDArray* src, const NDArray* diff_src, const NDArray* dst, dnnl::algorithm& algorithm, + dnnl::memory::desc* pool_src_md, dnnl::memory::desc* pool_diff_src_md, dnnl::memory::desc* pool_dst_md, + dnnl::memory::desc* user_src_md, dnnl::memory::desc* user_diff_src_md, dnnl::memory::desc* user_dst_md, + dnnl::memory::dims& pool_strides, dnnl::memory::dims& pool_kernel, dnnl::memory::dims& pool_padding, dnnl::memory::dims& pool_padding_r); - void getMKLDNNMemoryDescPool3d( - int kD, int kH, int kW, int sD, int sH, int sW, int pD, int pH, int pW, int dD, int dH, int dW, int poolingMode, int extraParam0, bool isNCDHW, - int bS, int iC, int iD, int iH, int iW, int oC, int oD, int oH, int oW, - const NDArray* src, const NDArray* diff_src, const NDArray* dst, dnnl::algorithm& algorithm, - dnnl::memory::desc* pool_src_md, dnnl::memory::desc* pool_diff_src_md, dnnl::memory::desc* pool_dst_md, - dnnl::memory::desc* user_src_md, dnnl::memory::desc* user_diff_src_md, dnnl::memory::desc* user_dst_md, - dnnl::memory::dims& pool_strides, dnnl::memory::dims& pool_kernel, dnnl::memory::dims& pool_padding, dnnl::memory::dims& pool_padding_r); + void getMKLDNNMemoryDescPool3d( + int kD, int kH, int kW, int sD, int sH, int sW, int pD, int pH, int pW, int dD, int dH, int dW, int poolingMode, int extraParam0, bool isNCDHW, + int bS, int iC, int iD, int iH, int iW, int oC, int oD, int oH, int oW, + const NDArray* src, const NDArray* diff_src, const NDArray* dst, dnnl::algorithm& algorithm, + dnnl::memory::desc* pool_src_md, dnnl::memory::desc* pool_diff_src_md, dnnl::memory::desc* pool_dst_md, + dnnl::memory::desc* user_src_md, dnnl::memory::desc* user_diff_src_md, dnnl::memory::desc* user_dst_md, + dnnl::memory::dims& pool_strides, dnnl::memory::dims& pool_kernel, dnnl::memory::dims& pool_padding, dnnl::memory::dims& pool_padding_r); - void getMKLDNNMemoryDescBatchNorm(const NDArray* src, const NDArray* diff_src, const NDArray* dst, - dnnl::memory::desc* batchnorm_src_md, dnnl::memory::desc* batchnorm_diff_src_md, dnnl::memory::desc* batchnorm_dst_md, - dnnl::memory::desc* user_src_md, dnnl::memory::desc* user_diff_src_md, dnnl::memory::desc* user_dst_md, int axis); -*/ + void getMKLDNNMemoryDescBatchNorm(const NDArray* src, const NDArray* diff_src, const NDArray* dst, + dnnl::memory::desc* batchnorm_src_md, dnnl::memory::desc* batchnorm_diff_src_md, dnnl::memory::desc* batchnorm_dst_md, + dnnl::memory::desc* user_src_md, dnnl::memory::desc* user_diff_src_md, dnnl::memory::desc* user_dst_md, int axis); + */ } } diff --git a/libnd4j/include/ops/declarable/platform/mkldnn/softmax.cpp b/libnd4j/include/ops/declarable/platform/mkldnn/softmax.cpp new file mode 100644 index 000000000..9d1541efb --- /dev/null +++ b/libnd4j/include/ops/declarable/platform/mkldnn/softmax.cpp @@ -0,0 +1,183 @@ +/******************************************************************************* + * Copyright (c) 2019-2020 Konduit K.K. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ******************************************************************************/ + + // + // @author Oleg Semeniv + // + // + +#include +#include +#include +#include +#include "mkldnnUtils.h" + +using namespace dnnl; + +namespace sd { + namespace ops { + namespace platforms { + + ////////////////////////////////////////////////////////////////////// + static void softmaxMKLDNN(const NDArray* x, NDArray* z, const int axis) { + + const auto xRank = x->rankOf(); + const auto zRank = z->rankOf(); + + std::vector dimsX(xRank), dimsZ(zRank); + for (auto i = 0; i < xRank; i++) { + dimsX[i] = x->sizeAt(i); + dimsZ[i] = z->sizeAt(i); + } + + dnnl::memory::dims xShape = dnnl::memory::dims(dimsX); + dnnl::memory::dims zShape = dnnl::memory::dims(dimsZ); + + dnnl::memory::format_tag format = dnnl::memory::format_tag::a; // 1 == xRank + if (2 == xRank && 1 == axis) { + format = dnnl::memory::format_tag::ab; + } + else if (2 == xRank && 0 == axis) { + format = dnnl::memory::format_tag::ba; + } + else if (3 == xRank) { + format = dnnl::memory::format_tag::abc; + } + else if (4 == xRank && 3 == axis) { + format = dnnl::memory::format_tag::abcd; + } + else if (4 == xRank && 1 == axis && dimsX[2] * dimsX[3] > 1) { + format = dnnl::memory::format_tag::acdb; + } + else if (4 == xRank) { + format = dnnl::memory::format_tag::abcd; + } + else if (5 == xRank) { + format = dnnl::memory::format_tag::abcde; + } + else if (6 == xRank) { + format = dnnl::memory::format_tag::abcdef; + } + + dnnl::memory::data_type xType = dnnl::memory::data_type::f32; + dnnl::memory::data_type zType = dnnl::memory::data_type::f32; + + dnnl::memory::desc x_mkl_md = dnnl::memory::desc(xShape, xType, format); + dnnl::memory::desc x_user_md = dnnl::memory::desc(xShape, xType, format); + + if (x->ews() != 1 || x->ordering() != 'c') { + x_user_md.data.format_kind = dnnl_blocked; // overrides format + for (auto i = 0; i < xRank; ++i) { + x_user_md.data.format_desc.blocking.strides[i] = x->strideAt(i); + } + } + + // z + dnnl::memory::desc z_mkl_md = dnnl::memory::desc(zShape, zType, dnnl::memory::format_tag::any); + dnnl::memory::desc z_user_md = dnnl::memory::desc(zShape, zType, format); + if (z->ews() != 1 || z->ordering() != 'c') { + z_user_md.data.format_kind = dnnl_blocked; // overrides format + for (auto i = 0; i < xRank; ++i) { + z_user_md.data.format_desc.blocking.strides[i] = z->strideAt(i); + } + } + + auto engine = mkldnnUtils::getEngine(LaunchContext::defaultContext()->engine()); + + // Create attributes (to handle alpha and beta if necessary) + dnnl::primitive_attr attr; // it is empty since we have usual values for alpha (=1) and beta (=0) + + // operation primitive description + // todo check this + dnnl::softmax_forward::desc op_desc(dnnl::prop_kind::forward_inference, x_mkl_md, axis); + + dnnl::softmax_forward::primitive_desc op_prim_desc(op_desc, attr, engine); + + // arguments (memory buffers) necessary for calculations + std::unordered_map args; + + dnnl::stream stream(engine); + + // provide memory buffers and check whether reorder is required + + // input + auto x_user_mem = dnnl::memory(x_user_md, engine, x->getBuffer()); + const bool xReorder = op_prim_desc.src_desc() != x_user_mem.get_desc(); + auto x_mkl_mem = xReorder ? dnnl::memory(op_prim_desc.src_desc(), engine) : x_user_mem; + if (xReorder) + dnnl::reorder(x_user_mem, x_mkl_mem).execute(stream, x_user_mem, x_mkl_mem); + args[DNNL_ARG_SRC] = x_mkl_mem; + + // z + auto z_user_mem = dnnl::memory(z_user_md, engine, z->getBuffer()); + const bool zReorder = op_prim_desc.dst_desc() != z_user_mem.get_desc(); + auto z_mkl_mem = zReorder ? dnnl::memory(op_prim_desc.dst_desc(), engine) : z_user_mem; + args[DNNL_ARG_DST] = z_mkl_mem; + + // run calculations + dnnl::softmax_forward(op_prim_desc).execute(stream, args); + + // reorder outputs if necessary + if (zReorder) + dnnl::reorder(z_mkl_mem, z_user_mem).execute(stream, z_mkl_mem, z_user_mem); + + stream.wait(); + } + + + PLATFORM_IMPL(softmax, ENGINE_CPU) { + + auto input = INPUT_VARIABLE(0); + auto output = OUTPUT_VARIABLE(0); + + const int rank = input->rankOf(); + int dim = block.getIArguments()->size() > 0 ? INT_ARG(0) : rank - 1; + + if (dim < 0) { + dim += rank; + } + + REQUIRE_TRUE(dim < rank && dim >= 0, 0, "SOFTMAX_MKLDNN OP: the value of input integer parameter (dimension) must be less than input array rank %i, but got dimension = %i instead !", rank, dim); + + REQUIRE_TRUE(rank <= 6, 0, "SOFTMAX_MKLDNN OP: the rank of input must be less or qual 4, but got rank = %i instead !", rank); + + // mkldnnSoftMax + softmaxMKLDNN(input, output, dim); + + return Status::OK(); + } + + PLATFORM_CHECK(softmax, ENGINE_CPU) { + + auto x = INPUT_VARIABLE(0); + auto z = OUTPUT_VARIABLE(0); + + const DataType xType = x->dataType(); + const DataType zType = z->dataType(); + + const int xRank = x->rankOf(); + bool bSupportedRanks = (xRank > 2 && xRank < 7); + /* + Source Destination + f32 f32 + */ + return block.isUseMKLDNN() && bSupportedRanks && (xType == DataType::FLOAT32 && zType == DataType::FLOAT32); + + } + + } + } +} diff --git a/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests1.cpp b/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests1.cpp index 90623420e..60076f7d6 100644 --- a/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests1.cpp +++ b/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests1.cpp @@ -14,9 +14,9 @@ * SPDX-License-Identifier: Apache-2.0 ******************************************************************************/ -// -// @author raver119@gmail.com -// + // + // @author raver119@gmail.com + // #include "testlayers.h" #include @@ -51,8 +51,8 @@ public: const int pW = 0; // padding width const int dH = 2; // dilation height const int dW = 2; // dilation width - const int oH = (iH - kH - (kH-1)*(dH-1) + 2*pH)/sH + 1; // output height - const int oW = (iW - kW - (kW-1)*(dW-1) + 2*pW)/sW + 1; // output width + const int oH = (iH - kH - (kH - 1) * (dH - 1) + 2 * pH) / sH + 1; // output height + const int oW = (iW - kW - (kW - 1) * (dW - 1) + 2 * pW) / sW + 1; // output width DeclarableOpsTests1() { sd::memory::MemoryTracker::getInstance()->reset(); @@ -80,8 +80,8 @@ public: const int pW = 0; // padding width const int dH = 2; // dilation height const int dW = 2; // dilation width - const int oH = (iH - kH - (kH-1)*(dH-1) + 2*pH)/sH + 1; // output height - const int oW = (iW - kW - (kW-1)*(dW-1) + 2*pW)/sW + 1; // output width + const int oH = (iH - kH - (kH - 1) * (dH - 1) + 2 * pH) / sH + 1; // output height + const int oW = (iW - kW - (kW - 1) * (dW - 1) + 2 * pW) / sW + 1; // output width TypedDeclarableOpsTests1() { printf("\n"); @@ -97,11 +97,11 @@ TEST_F(DeclarableOpsTests1, BasicInitialization1) { std::string expName("concat"); ASSERT_EQ(expName, *(concat->getOpName())); - auto x0 = NDArrayFactory::create_('c', {1, 5}); - auto x1 = NDArrayFactory::create_('c', {1, 5}); - auto x2 = NDArrayFactory::create_('c', {1, 5}); - auto x3 = NDArrayFactory::create_('c', {1, 5}); - auto x4 = NDArrayFactory::create_('c', {1, 5}); + auto x0 = NDArrayFactory::create_('c', { 1, 5 }); + auto x1 = NDArrayFactory::create_('c', { 1, 5 }); + auto x2 = NDArrayFactory::create_('c', { 1, 5 }); + auto x3 = NDArrayFactory::create_('c', { 1, 5 }); + auto x4 = NDArrayFactory::create_('c', { 1, 5 }); x0->assign(1.0f); x1->assign(1.0f); @@ -123,7 +123,7 @@ TEST_F(DeclarableOpsTests1, BasicInitialization1) { Context block(1, variableSpace); block.getIArguments()->push_back(1); - block.fillInputs({-1, -2, -3, -4, -5}); + block.fillInputs({ -1, -2, -3, -4, -5 }); ASSERT_FALSE(nodeVar->hasNDArray()); @@ -156,12 +156,12 @@ TEST_F(DeclarableOpsTests1, BasicInitialization2) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, ApplyGradientDescent_1) { - auto x = NDArrayFactory::create('c', {3,4}, {1,2,3,4,5,6,7,8,9,10,11,12}); - auto y = NDArrayFactory::create('c', {3,4}, {0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2}); - auto exp = NDArrayFactory::create('c', {3,4}); + auto x = NDArrayFactory::create('c', { 3,4 }, { 1,2,3,4,5,6,7,8,9,10,11,12 }); + auto y = NDArrayFactory::create('c', { 3,4 }, { 0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2 }); + auto exp = NDArrayFactory::create('c', { 3,4 }); exp.linspace(0.9, 0.9); sd::ops::apply_sgd op; - auto result = op.evaluate({&x, &y}, {1.}, {}); + auto result = op.evaluate({ &x, &y }, { 1. }, {}); ASSERT_EQ(result->status(), ND4J_STATUS_OK); auto z = result->at(0); @@ -171,11 +171,11 @@ TEST_F(DeclarableOpsTests1, ApplyGradientDescent_1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, AssignBroadcastTest_1) { - auto x = NDArrayFactory::create('c', {3,4}, {1,2,3,4,5,6,7,8,9,10,11,12}); - auto y = NDArrayFactory::create('c', {1,4}, {0.1,0.2,0.3,0.4}); - auto exp = NDArrayFactory::create('c', {3,4}, {0.1, 0.2, 0.3, 0.4, 0.1, 0.2, 0.3, 0.4, 0.1, 0.2, 0.3, 0.4}); + auto x = NDArrayFactory::create('c', { 3,4 }, { 1,2,3,4,5,6,7,8,9,10,11,12 }); + auto y = NDArrayFactory::create('c', { 1,4 }, { 0.1,0.2,0.3,0.4 }); + auto exp = NDArrayFactory::create('c', { 3,4 }, { 0.1, 0.2, 0.3, 0.4, 0.1, 0.2, 0.3, 0.4, 0.1, 0.2, 0.3, 0.4 }); sd::ops::assign op; - auto result = op.evaluate({&x, &y}); + auto result = op.evaluate({ &x, &y }); ASSERT_EQ(result->status(), ND4J_STATUS_OK); auto z = result->at(0); @@ -185,13 +185,13 @@ TEST_F(DeclarableOpsTests1, AssignBroadcastTest_1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, AssignBroadcastTest_2) { - auto x = NDArrayFactory::create('c', {3,4}, {1,2,3,4,5,6,7,8,9,10,11,12}); - auto y = NDArrayFactory::create('c', {1,4}, {0.1,0.2,0.3,0.4}); - auto eps = NDArrayFactory::create('c', {3,4}, {1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}); - auto exp1 = NDArrayFactory::create('c', {3,4}); // zero - auto exp2 = NDArrayFactory::create('c', {1,4}, {3, 6, 9, 12}); + auto x = NDArrayFactory::create('c', { 3,4 }, { 1,2,3,4,5,6,7,8,9,10,11,12 }); + auto y = NDArrayFactory::create('c', { 1,4 }, { 0.1,0.2,0.3,0.4 }); + auto eps = NDArrayFactory::create('c', { 3,4 }, { 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4 }); + auto exp1 = NDArrayFactory::create('c', { 3,4 }); // zero + auto exp2 = NDArrayFactory::create('c', { 1,4 }, { 3, 6, 9, 12 }); sd::ops::assign_bp op; - auto result = op.evaluate({&x, &y, &eps}); + auto result = op.evaluate({ &x, &y, &eps }); ASSERT_EQ(result->status(), ND4J_STATUS_OK); auto z1 = result->at(0); auto z2 = result->at(1); @@ -203,12 +203,12 @@ TEST_F(DeclarableOpsTests1, AssignBroadcastTest_2) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, AXpY_Test_1) { - auto x = NDArrayFactory::create('c', {3,4}, {1,2,3,4,5,6,7,8,9,10,11,12}); - auto y = NDArrayFactory::create('c', {3,4}, {1,2,3,4,5,6,7,8,9,10,11,12}); - auto exp = NDArrayFactory::create('c', {3,4}); + auto x = NDArrayFactory::create('c', { 3,4 }, { 1,2,3,4,5,6,7,8,9,10,11,12 }); + auto y = NDArrayFactory::create('c', { 3,4 }, { 1,2,3,4,5,6,7,8,9,10,11,12 }); + auto exp = NDArrayFactory::create('c', { 3,4 }); exp.linspace(3, 3); sd::ops::axpy op; - auto result = op.evaluate({&x, &y}, {2.}); + auto result = op.evaluate({ &x, &y }, { 2. }); ASSERT_EQ(result->status(), ND4J_STATUS_OK); auto z = result->at(0); @@ -240,20 +240,20 @@ TEST_F(DeclarableOpsTests1, SynonymInitialization2) { TEST_F(DeclarableOpsTests1, TestTensorMmul1) { - NDArray x('c', {2, 3, 4}, sd::DataType::FLOAT32); - NDArray y('c', {2, 3, 4}, sd::DataType::FLOAT32); + NDArray x('c', { 2, 3, 4 }, sd::DataType::FLOAT32); + NDArray y('c', { 2, 3, 4 }, sd::DataType::FLOAT32); x.linspace(1); y.linspace(1); - NDArray exp('c', {2, 2}, {650.0, 1586.0, 1586.0, 4250.0}, sd::DataType::FLOAT32); + NDArray exp('c', { 2, 2 }, { 650.0, 1586.0, 1586.0, 4250.0 }, sd::DataType::FLOAT32); sd::ops::tensormmul op; - auto results = op.evaluate({&x, &y}, {}, {2,1,2,2,1,2}); + auto results = op.evaluate({ &x, &y }, {}, { 2,1,2,2,1,2 }); ASSERT_EQ(ND4J_STATUS_OK, results->status()); - auto *out = results->at(0); + auto* out = results->at(0); ASSERT_TRUE(exp.isSameShape(out)); ASSERT_TRUE(exp.equalsTo(out)); @@ -263,17 +263,17 @@ TEST_F(DeclarableOpsTests1, TestTensorMmul1) { TEST_F(DeclarableOpsTests1, TestTensorDot2) { - NDArray x('f', {2, 3, 4}, {1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24.}, sd::DataType::FLOAT32); - NDArray y('f', {2, 3, 4}, {1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24.}, sd::DataType::FLOAT32); + NDArray x('f', { 2, 3, 4 }, { 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24. }, sd::DataType::FLOAT32); + NDArray y('f', { 2, 3, 4 }, { 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24. }, sd::DataType::FLOAT32); - NDArray exp('c', {2, 2}, {2300.0, 2444.0, 2444.0, 2600.0}, sd::DataType::FLOAT32); + NDArray exp('c', { 2, 2 }, { 2300.0, 2444.0, 2444.0, 2600.0 }, sd::DataType::FLOAT32); sd::ops::tensormmul op; - auto results = op.evaluate({&x, &y}, {}, {2,1,2,2,1,2}); + auto results = op.evaluate({ &x, &y }, {}, { 2,1,2,2,1,2 }); ASSERT_EQ(ND4J_STATUS_OK, results->status()); - auto *out = results->at(0); + auto* out = results->at(0); ASSERT_TRUE(exp.isSameShape(out)); ASSERT_TRUE(exp.equalsTo(out)); @@ -283,17 +283,17 @@ TEST_F(DeclarableOpsTests1, TestTensorDot2) { TEST_F(DeclarableOpsTests1, TestTensorDot3) { - NDArray x('c', {2, 3, 4}, {1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24.}, sd::DataType::FLOAT32); - NDArray y('f', {2, 3, 4}, {1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24.}, sd::DataType::FLOAT32); + NDArray x('c', { 2, 3, 4 }, { 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24. }, sd::DataType::FLOAT32); + NDArray y('f', { 2, 3, 4 }, { 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24. }, sd::DataType::FLOAT32); - NDArray exp('f', {2, 2}, {1090.0, 2818.0, 1168.0, 3040.0}, sd::DataType::FLOAT32); + NDArray exp('f', { 2, 2 }, { 1090.0, 2818.0, 1168.0, 3040.0 }, sd::DataType::FLOAT32); sd::ops::tensormmul op; - auto results = op.evaluate({&x, &y}, {}, {2,1,2,2,1,2}); + auto results = op.evaluate({ &x, &y }, {}, { 2,1,2,2,1,2 }); ASSERT_EQ(ND4J_STATUS_OK, results->status()); - auto *out = results->at(0); + auto* out = results->at(0); ASSERT_TRUE(exp.isSameShape(out)); ASSERT_TRUE(exp.equalsTo(out)); @@ -303,17 +303,17 @@ TEST_F(DeclarableOpsTests1, TestTensorDot3) { TEST_F(DeclarableOpsTests1, TestTensorDot4) { - NDArray x('f', {2, 3, 4}, {1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24.}, sd::DataType::FLOAT32); - NDArray y('c', {2, 3, 4}, {1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24.}, sd::DataType::FLOAT32); + NDArray x('f', { 2, 3, 4 }, { 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24. }, sd::DataType::FLOAT32); + NDArray y('c', { 2, 3, 4 }, { 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24. }, sd::DataType::FLOAT32); - NDArray exp('f', {2, 2}, {1090.0, 1168.0, 2818.0, 3040.0}, sd::DataType::FLOAT32); + NDArray exp('f', { 2, 2 }, { 1090.0, 1168.0, 2818.0, 3040.0 }, sd::DataType::FLOAT32); sd::ops::tensormmul op; - auto results = op.evaluate({&x, &y}, {}, {2,1,2,2,1,2}); + auto results = op.evaluate({ &x, &y }, {}, { 2,1,2,2,1,2 }); ASSERT_EQ(ND4J_STATUS_OK, results->status()); - auto *out = results->at(0); + auto* out = results->at(0); ASSERT_TRUE(exp.isSameShape(out)); ASSERT_TRUE(exp.equalsTo(out)); @@ -324,16 +324,16 @@ TEST_F(DeclarableOpsTests1, TestTensorDot4) { //////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, TestTensorDot5) { - auto x = NDArrayFactory::create('c', {2,3,4}, {1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15}); - auto y = NDArrayFactory::create('c', {2,4,3}, {2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16}); - auto expected = NDArrayFactory::create('c', {2,4,2,4}, {44,110,160, 66,132, 38, 88,154, 68,170,224,102,204, 82,136,238, 92,230,288,138,276,126,184,322, 116,290,352,174,348,170,232,406, 76,190,160,114,228,182,152,266, 100,250,224,150,300,226,200,350, 124,310,288,186,372,270,248,434, 148,370,352,222,444,314,296,518}); + auto x = NDArrayFactory::create('c', { 2,3,4 }, { 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15 }); + auto y = NDArrayFactory::create('c', { 2,4,3 }, { 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16 }); + auto expected = NDArrayFactory::create('c', { 2,4,2,4 }, { 44,110,160, 66,132, 38, 88,154, 68,170,224,102,204, 82,136,238, 92,230,288,138,276,126,184,322, 116,290,352,174,348,170,232,406, 76,190,160,114,228,182,152,266, 100,250,224,150,300,226,200,350, 124,310,288,186,372,270,248,434, 148,370,352,222,444,314,296,518 }); sd::ops::tensormmul op; - auto results = op.evaluate({&x, &y}, {}, {1,1,1,2}); + auto results = op.evaluate({ &x, &y }, {}, { 1,1,1,2 }); ASSERT_EQ(ND4J_STATUS_OK, results->status()); - auto *result = results->at(0); + auto* result = results->at(0); ASSERT_TRUE(expected.isSameShape(result)); ASSERT_TRUE(expected.equalsTo(result)); @@ -346,16 +346,16 @@ TEST_F(DeclarableOpsTests1, TestTensorDot5) { //////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, TestTensorDot6) { - auto x = NDArrayFactory::create('c', {2,3,4}, {1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15}); - auto y = NDArrayFactory::create('f', {2,4,3}, {2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16}); - auto expected = NDArrayFactory::create('c', {2,4,2,4}, {22, 66,110,154, 44, 88,132,176, 34,102,170,238, 68,136,204,272, 46,138,230,322, 92,184,276,368, 58,174,290,406,116,232,348,464, 38,114,190,266, 76,152,228,304, 50,150,250,350,100,200,300,400, 62,186,310,434,124,248,372,496, 74,222,370,518,148,296,444,592}); + auto x = NDArrayFactory::create('c', { 2,3,4 }, { 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15 }); + auto y = NDArrayFactory::create('f', { 2,4,3 }, { 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16 }); + auto expected = NDArrayFactory::create('c', { 2,4,2,4 }, { 22, 66,110,154, 44, 88,132,176, 34,102,170,238, 68,136,204,272, 46,138,230,322, 92,184,276,368, 58,174,290,406,116,232,348,464, 38,114,190,266, 76,152,228,304, 50,150,250,350,100,200,300,400, 62,186,310,434,124,248,372,496, 74,222,370,518,148,296,444,592 }); sd::ops::tensormmul op; - auto results = op.evaluate({&x, &y}, {}, {1,1,1,2}); + auto results = op.evaluate({ &x, &y }, {}, { 1,1,1,2 }); ASSERT_EQ(ND4J_STATUS_OK, results->status()); - auto *result = results->at(0); + auto* result = results->at(0); ASSERT_TRUE(expected.isSameShape(result)); ASSERT_TRUE(expected.equalsTo(result)); @@ -367,16 +367,16 @@ TEST_F(DeclarableOpsTests1, TestTensorDot6) { //////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, TestTensorDot7) { - auto x = NDArrayFactory::create('f', {2,3,4}, {1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15}); - auto y = NDArrayFactory::create('c', {2,4,3}, {2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16}); - auto expected = NDArrayFactory::create('c', {2,4,2,4}, {76,166,112,106,196, 62,136,226, 60,174,208, 98,212,230,136,250, 76,214,336,122,260,174,168,306, 124,286,240,178,340,150,232,394, 100,226,176,142,268,106,184,310, 84,234,272,134,284,274,184,334, 100,274,400,158,332,218,216,390, 148,346,304,214,412,194,280,478}); + auto x = NDArrayFactory::create('f', { 2,3,4 }, { 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15 }); + auto y = NDArrayFactory::create('c', { 2,4,3 }, { 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16 }); + auto expected = NDArrayFactory::create('c', { 2,4,2,4 }, { 76,166,112,106,196, 62,136,226, 60,174,208, 98,212,230,136,250, 76,214,336,122,260,174,168,306, 124,286,240,178,340,150,232,394, 100,226,176,142,268,106,184,310, 84,234,272,134,284,274,184,334, 100,274,400,158,332,218,216,390, 148,346,304,214,412,194,280,478 }); sd::ops::tensormmul op; - auto results = op.evaluate({&x, &y}, {}, {1,1,1,2}); + auto results = op.evaluate({ &x, &y }, {}, { 1,1,1,2 }); ASSERT_EQ(ND4J_STATUS_OK, results->status()); - auto *result = results->at(0); + auto* result = results->at(0); ASSERT_TRUE(expected.isSameShape(result)); ASSERT_TRUE(expected.equalsTo(result)); @@ -388,16 +388,16 @@ TEST_F(DeclarableOpsTests1, TestTensorDot7) { //////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, TestTensorDot8) { - auto x = NDArrayFactory::create('f', {2,3,4}, {1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15}); - auto y = NDArrayFactory::create('f', {2,4,3}, {2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16}); - auto expected = NDArrayFactory::create('c', {2,4,2,4}, {30, 90,150,210, 60,120,180,240, 38,114,190,266, 76,152,228,304, 46,138,230,322, 92,184,276,368, 54,162,270,378,108,216,324,432, 42,126,210,294, 84,168,252,336, 50,150,250,350,100,200,300,400, 58,174,290,406,116,232,348,464, 66,198,330,462,132,264,396,528}); + auto x = NDArrayFactory::create('f', { 2,3,4 }, { 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15 }); + auto y = NDArrayFactory::create('f', { 2,4,3 }, { 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16 }); + auto expected = NDArrayFactory::create('c', { 2,4,2,4 }, { 30, 90,150,210, 60,120,180,240, 38,114,190,266, 76,152,228,304, 46,138,230,322, 92,184,276,368, 54,162,270,378,108,216,324,432, 42,126,210,294, 84,168,252,336, 50,150,250,350,100,200,300,400, 58,174,290,406,116,232,348,464, 66,198,330,462,132,264,396,528 }); sd::ops::tensormmul op; - auto results = op.evaluate({&x, &y}, {}, {1,1,1,2}); + auto results = op.evaluate({ &x, &y }, {}, { 1,1,1,2 }); ASSERT_EQ(ND4J_STATUS_OK, results->status()); - auto *result = results->at(0); + auto* result = results->at(0); ASSERT_TRUE(expected.isSameShape(result)); ASSERT_TRUE(expected.equalsTo(result)); @@ -417,16 +417,16 @@ TEST_F(DeclarableOpsTests1, TestTensorDot9) { // z.printShapeInfo(); // z.printIndexedBuffer(); - auto x = NDArrayFactory::create('f', {2,3,4}, {1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15}); - auto y = NDArrayFactory::create('f', {2,4,3}, {2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16}); - auto expected = NDArrayFactory::create('c', {3,4,4,3}, {14, 14, 14, 30, 30, 30, 46, 46, 46, 62, 62, 62, 86, 86, 86,198,198,198,310,310,310,422,422,422, 62, 62, 62,142,142,142,222,222,222,302,302,302, 38, 38, 38, 86, 86, 86,134,134,134,182,182,182, 38, 38, 38, 86, 86, 86,134,134,134,182,182,182, 14, 14, 14, 30, 30, 30, 46, 46, 46, 62, 62, 62, 86, 86, 86,198,198,198,310,310,310,422,422,422, 62, 62, 62,142,142,142,222,222,222,302,302,302, 62, 62, 62,142,142,142,222,222,222,302,302,302, 38, 38, 38, 86, 86, 86,134,134,134,182,182,182, 14, 14, 14, 30, 30, 30, 46, 46, 46, 62, 62, 62, 86, 86, 86,198,198,198,310,310,310,422,422,422}); + auto x = NDArrayFactory::create('f', { 2,3,4 }, { 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15 }); + auto y = NDArrayFactory::create('f', { 2,4,3 }, { 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16 }); + auto expected = NDArrayFactory::create('c', { 3,4,4,3 }, { 14, 14, 14, 30, 30, 30, 46, 46, 46, 62, 62, 62, 86, 86, 86,198,198,198,310,310,310,422,422,422, 62, 62, 62,142,142,142,222,222,222,302,302,302, 38, 38, 38, 86, 86, 86,134,134,134,182,182,182, 38, 38, 38, 86, 86, 86,134,134,134,182,182,182, 14, 14, 14, 30, 30, 30, 46, 46, 46, 62, 62, 62, 86, 86, 86,198,198,198,310,310,310,422,422,422, 62, 62, 62,142,142,142,222,222,222,302,302,302, 62, 62, 62,142,142,142,222,222,222,302,302,302, 38, 38, 38, 86, 86, 86,134,134,134,182,182,182, 14, 14, 14, 30, 30, 30, 46, 46, 46, 62, 62, 62, 86, 86, 86,198,198,198,310,310,310,422,422,422 }); sd::ops::tensormmul op; - auto results = op.evaluate({&x, &y}, {}, {1,0,1,0}); + auto results = op.evaluate({ &x, &y }, {}, { 1,0,1,0 }); ASSERT_EQ(ND4J_STATUS_OK, results->status()); - auto *result = results->at(0); + auto* result = results->at(0); ASSERT_TRUE(expected.isSameShape(result)); ASSERT_TRUE(expected.equalsTo(result)); @@ -438,16 +438,16 @@ TEST_F(DeclarableOpsTests1, TestTensorDot9) { //////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, TestTensorDot10) { - auto x = NDArrayFactory::create('f', {2,3,4}, {1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15}); - auto y = NDArrayFactory::create('f', {2,4,3}, {2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16}); - auto expected = NDArrayFactory::create('c', {4,4}, {114,258,402,546, 138,314,490,666, 162,370,578,786, 186,426,666,906}); + auto x = NDArrayFactory::create('f', { 2,3,4 }, { 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15 }); + auto y = NDArrayFactory::create('f', { 2,4,3 }, { 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16 }); + auto expected = NDArrayFactory::create('c', { 4,4 }, { 114,258,402,546, 138,314,490,666, 162,370,578,786, 186,426,666,906 }); sd::ops::tensormmul op; - auto results = op.evaluate({&x, &y}, {}, {2,0,1, 2,0,2}); + auto results = op.evaluate({ &x, &y }, {}, { 2,0,1, 2,0,2 }); ASSERT_EQ(ND4J_STATUS_OK, results->status()); - auto *result = results->at(0); + auto* result = results->at(0); ASSERT_TRUE(expected.isSameShape(result)); ASSERT_TRUE(expected.equalsTo(result)); @@ -460,16 +460,16 @@ TEST_F(DeclarableOpsTests1, TestTensorDot10) { //////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, TestTensorDot11) { - auto x = NDArrayFactory::create('c', {2,3,4}, {1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15}); - auto y = NDArrayFactory::create('f', {2,4,3}, {2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16}); - auto expected = NDArrayFactory::create('c', {4,4}, {98,218,338,458, 134,302,470,638, 170,386,602,818, 206,470,734,998}); + auto x = NDArrayFactory::create('c', { 2,3,4 }, { 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15 }); + auto y = NDArrayFactory::create('f', { 2,4,3 }, { 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16 }); + auto expected = NDArrayFactory::create('c', { 4,4 }, { 98,218,338,458, 134,302,470,638, 170,386,602,818, 206,470,734,998 }); sd::ops::tensormmul op; - auto results = op.evaluate({&x, &y}, {}, {2,0,1, 2,0,2}); + auto results = op.evaluate({ &x, &y }, {}, { 2,0,1, 2,0,2 }); ASSERT_EQ(ND4J_STATUS_OK, results->status()); - auto *result = results->at(0); + auto* result = results->at(0); ASSERT_TRUE(expected.isSameShape(result)); ASSERT_TRUE(expected.equalsTo(result)); @@ -481,16 +481,16 @@ TEST_F(DeclarableOpsTests1, TestTensorDot11) { //////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, TestTensorDot12) { - auto x = NDArrayFactory::create('c', {2,3,4}, {1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15}); - auto y = NDArrayFactory::create('c', {2,4,3}, {2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16}); - auto expected = NDArrayFactory::create('c', {4,4}, {272,292,312,332, 368,396,424,452, 464,500,536,572, 560,604,648,692}); + auto x = NDArrayFactory::create('c', { 2,3,4 }, { 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15 }); + auto y = NDArrayFactory::create('c', { 2,4,3 }, { 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16 }); + auto expected = NDArrayFactory::create('c', { 4,4 }, { 272,292,312,332, 368,396,424,452, 464,500,536,572, 560,604,648,692 }); sd::ops::tensormmul op; - auto results = op.evaluate({&x, &y}, {}, {2,0,1, 2,0,2}); + auto results = op.evaluate({ &x, &y }, {}, { 2,0,1, 2,0,2 }); ASSERT_EQ(ND4J_STATUS_OK, results->status()); - auto *result = results->at(0); + auto* result = results->at(0); ASSERT_TRUE(expected.isSameShape(result)); ASSERT_TRUE(expected.equalsTo(result)); @@ -502,16 +502,16 @@ TEST_F(DeclarableOpsTests1, TestTensorDot12) { //////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, TestTensorDot13) { - auto x = NDArrayFactory::create('c', {2,3,4}, {1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15}); - auto y = NDArrayFactory::create('c', {4,2,3}, {2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16}); - auto expected = NDArrayFactory::create('c', {3,3}, {640,560,640, 576,624,576, 640,560,640}); + auto x = NDArrayFactory::create('c', { 2,3,4 }, { 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15 }); + auto y = NDArrayFactory::create('c', { 4,2,3 }, { 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16 }); + auto expected = NDArrayFactory::create('c', { 3,3 }, { 640,560,640, 576,624,576, 640,560,640 }); sd::ops::tensormmul op; - auto results = op.evaluate({&x, &y}, {}, {2,0,2, 2,1,0}); + auto results = op.evaluate({ &x, &y }, {}, { 2,0,2, 2,1,0 }); ASSERT_EQ(ND4J_STATUS_OK, results->status()); - auto *result = results->at(0); + auto* result = results->at(0); ASSERT_TRUE(expected.isSameShape(result)); ASSERT_TRUE(expected.equalsTo(result)); @@ -523,16 +523,16 @@ TEST_F(DeclarableOpsTests1, TestTensorDot13) { //////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, TestTensorDot14) { - auto x = NDArrayFactory::create('f', {2,3,4}, {1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15}); - auto y = NDArrayFactory::create('c', {4,2,3}, {2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16}); - auto expected = NDArrayFactory::create('c', {3,3}, {648,600,520, 648,536,648, 520,600,648}); + auto x = NDArrayFactory::create('f', { 2,3,4 }, { 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15 }); + auto y = NDArrayFactory::create('c', { 4,2,3 }, { 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16 }); + auto expected = NDArrayFactory::create('c', { 3,3 }, { 648,600,520, 648,536,648, 520,600,648 }); sd::ops::tensormmul op; - auto results = op.evaluate({&x, &y}, {}, {2,0,2, 2,1,0}); + auto results = op.evaluate({ &x, &y }, {}, { 2,0,2, 2,1,0 }); ASSERT_EQ(ND4J_STATUS_OK, results->status()); - auto *result = results->at(0); + auto* result = results->at(0); ASSERT_TRUE(expected.isSameShape(result)); ASSERT_TRUE(expected.equalsTo(result)); @@ -544,16 +544,16 @@ TEST_F(DeclarableOpsTests1, TestTensorDot14) { //////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, TestTensorDot15) { - auto x = NDArrayFactory::create('f', {2,3,4}, {1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15}); - auto y = NDArrayFactory::create('f', {4,2,3}, {2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16}); - auto expected = NDArrayFactory::create('c', {3,3}, {624,624,624, 656,656,656, 624,624,624}); + auto x = NDArrayFactory::create('f', { 2,3,4 }, { 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15, 1,3,5,7,9,11,13,15 }); + auto y = NDArrayFactory::create('f', { 4,2,3 }, { 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16, 2,4,6,8,10,12,14,16 }); + auto expected = NDArrayFactory::create('c', { 3,3 }, { 624,624,624, 656,656,656, 624,624,624 }); sd::ops::tensormmul op; - auto results = op.evaluate({&x, &y}, {}, {2,0,2, 2,1,0}); + auto results = op.evaluate({ &x, &y }, {}, { 2,0,2, 2,1,0 }); ASSERT_EQ(ND4J_STATUS_OK, results->status()); - auto *result = results->at(0); + auto* result = results->at(0); ASSERT_TRUE(expected.isSameShape(result)); ASSERT_TRUE(expected.equalsTo(result)); @@ -565,16 +565,16 @@ TEST_F(DeclarableOpsTests1, TestTensorDot15) { //////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, TestTensorDot16) { - NDArray x('c', {1}, std::vector{2}, sd::DataType::FLOAT32); - NDArray y('c', {2,1,2}, {1,2,3,4}, sd::DataType::FLOAT32); - NDArray exp('c', {2,2}, {2,4,6,8}, sd::DataType::FLOAT32); + NDArray x('c', { 1 }, std::vector{2}, sd::DataType::FLOAT32); + NDArray y('c', { 2,1,2 }, { 1,2,3,4 }, sd::DataType::FLOAT32); + NDArray exp('c', { 2,2 }, { 2,4,6,8 }, sd::DataType::FLOAT32); sd::ops::tensormmul op; - auto results = op.evaluate({&x, &y}, {}, {1,0, 1,1}); + auto results = op.evaluate({ &x, &y }, {}, { 1,0, 1,1 }); ASSERT_EQ(ND4J_STATUS_OK, results->status()); - auto *result = results->at(0); + auto* result = results->at(0); ASSERT_TRUE(exp.isSameShape(result)); ASSERT_TRUE(exp.equalsTo(result)); @@ -585,12 +585,12 @@ TEST_F(DeclarableOpsTests1, TestTensorDot16) { //////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, TestTensorDot17) { - NDArray x('f', {16,16}, sd::DataType::FLOAT32); - NDArray y('f', {1000,16}, sd::DataType::FLOAT32); - NDArray z('c', {16,1000}, sd::DataType::FLOAT32); + NDArray x('f', { 16,16 }, sd::DataType::FLOAT32); + NDArray y('f', { 1000,16 }, sd::DataType::FLOAT32); + NDArray z('c', { 16,1000 }, sd::DataType::FLOAT32); sd::ops::tensormmul op; - auto status = op.execute({&x, &y}, {&z}, {}, {1,1, 1,1}, {}); + auto status = op.execute({ &x, &y }, { &z }, {}, { 1,1, 1,1 }, {}); ASSERT_EQ(ND4J_STATUS_OK, status); } @@ -609,9 +609,9 @@ TEST_F(DeclarableOpsTests1, DivergentCheck1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, AddMatrices1) { - auto x = NDArrayFactory::create_ ('c', {5, 3}); - auto y = NDArrayFactory::create_ ('c', {5, 3}); - auto exp = NDArrayFactory::create_('c', {5, 3}); + auto x = NDArrayFactory::create_('c', { 5, 3 }); + auto y = NDArrayFactory::create_('c', { 5, 3 }); + auto exp = NDArrayFactory::create_('c', { 5, 3 }); x->assign(2); y->assign(1); exp->assign(3); @@ -620,7 +620,7 @@ TEST_F(DeclarableOpsTests1, AddMatrices1) { variableSpace->putVariable(-1, x); variableSpace->putVariable(-2, y); auto block = new Context(1, variableSpace, true); - block->fillInputs({-1, -2}); + block->fillInputs({ -1, -2 }); sd::ops::add addOp; @@ -637,9 +637,9 @@ TEST_F(DeclarableOpsTests1, AddMatrices1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, AddVectorVector1) { - auto x = NDArrayFactory::create_ ('c', {1, 15}); - auto y = NDArrayFactory::create_ ('c', {1, 15}); - auto exp = NDArrayFactory::create_('c', {1, 15}); + auto x = NDArrayFactory::create_('c', { 1, 15 }); + auto y = NDArrayFactory::create_('c', { 1, 15 }); + auto exp = NDArrayFactory::create_('c', { 1, 15 }); x->assign(2); y->assign(1); exp->assign(3); @@ -648,7 +648,7 @@ TEST_F(DeclarableOpsTests1, AddVectorVector1) { variableSpace->putVariable(-1, x); variableSpace->putVariable(-2, y); auto block = new Context(1, variableSpace, true); - block->fillInputs({-1, -2}); + block->fillInputs({ -1, -2 }); sd::ops::add addOp; @@ -664,9 +664,9 @@ TEST_F(DeclarableOpsTests1, AddVectorVector1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, AddMatrixScalar1) { - auto x = NDArrayFactory::create_('c', {5, 3}); - auto y = NDArrayFactory::create_('c', {1, 1}); - auto exp = NDArrayFactory::create('c', {5, 3}); + auto x = NDArrayFactory::create_('c', { 5, 3 }); + auto y = NDArrayFactory::create_('c', { 1, 1 }); + auto exp = NDArrayFactory::create('c', { 5, 3 }); x->assign(2); y->assign(1); exp.assign(3); @@ -675,7 +675,7 @@ TEST_F(DeclarableOpsTests1, AddMatrixScalar1) { variableSpace->putVariable(-1, x); variableSpace->putVariable(-2, y); auto block = new Context(1, variableSpace, true); - block->fillInputs({-1, -2}); + block->fillInputs({ -1, -2 }); sd::ops::add addOp; @@ -690,9 +690,9 @@ TEST_F(DeclarableOpsTests1, AddMatrixScalar1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, AddScalarScalar1) { - auto x = NDArrayFactory::create_('c', {1, 1}); - auto y = NDArrayFactory::create_('c', {1, 1}); - auto exp = NDArrayFactory::create('c', {1, 1}); + auto x = NDArrayFactory::create_('c', { 1, 1 }); + auto y = NDArrayFactory::create_('c', { 1, 1 }); + auto exp = NDArrayFactory::create('c', { 1, 1 }); x->assign(2); y->assign(1); exp.assign(3); @@ -701,7 +701,7 @@ TEST_F(DeclarableOpsTests1, AddScalarScalar1) { variableSpace->putVariable(-1, x); variableSpace->putVariable(-2, y); auto block = new Context(1, variableSpace, true); - block->fillInputs({-1, -2}); + block->fillInputs({ -1, -2 }); sd::ops::add addOp; @@ -716,9 +716,9 @@ TEST_F(DeclarableOpsTests1, AddScalarScalar1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, SubtractMatrices1) { - auto x = NDArrayFactory::create_('c', {5, 3}); - auto y = NDArrayFactory::create_('c', {5, 3}); - auto exp = NDArrayFactory::create('c', {5, 3}); + auto x = NDArrayFactory::create_('c', { 5, 3 }); + auto y = NDArrayFactory::create_('c', { 5, 3 }); + auto exp = NDArrayFactory::create('c', { 5, 3 }); x->assign(3); y->assign(1); exp.assign(2); @@ -727,7 +727,7 @@ TEST_F(DeclarableOpsTests1, SubtractMatrices1) { variableSpace->putVariable(-1, x); variableSpace->putVariable(-2, y); auto block = new Context(1, variableSpace, true); - block->fillInputs({-1, -2}); + block->fillInputs({ -1, -2 }); sd::ops::subtract subOp; @@ -743,9 +743,9 @@ TEST_F(DeclarableOpsTests1, SubtractMatrices1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, SubtractTest_1) { - auto x = NDArrayFactory::create_('c', {1, 6}); - auto y = NDArrayFactory::create_('c', {1, 6}); - auto exp = NDArrayFactory::create('c', {1, 6}); + auto x = NDArrayFactory::create_('c', { 1, 6 }); + auto y = NDArrayFactory::create_('c', { 1, 6 }); + auto exp = NDArrayFactory::create('c', { 1, 6 }); x->assign(3); y->assign(1); exp.assign(2); @@ -754,7 +754,7 @@ TEST_F(DeclarableOpsTests1, SubtractTest_1) { variableSpace->putVariable(-1, x); variableSpace->putVariable(-2, y); auto block = new Context(1, variableSpace, true); - block->fillInputs({-1, -2}); + block->fillInputs({ -1, -2 }); sd::ops::subtract subOp; @@ -769,10 +769,10 @@ TEST_F(DeclarableOpsTests1, SubtractTest_1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, SubtractTest_2) { - auto x = NDArrayFactory::create('c', {3, 4, 5, 1}); - auto y = NDArrayFactory::create('c', {1, 6}); -// auto y({6}, {1,1,1,1,1,1}); - auto exp = NDArrayFactory::create('c', {3, 4, 5, 6}); + auto x = NDArrayFactory::create('c', { 3, 4, 5, 1 }); + auto y = NDArrayFactory::create('c', { 1, 6 }); + // auto y({6}, {1,1,1,1,1,1}); + auto exp = NDArrayFactory::create('c', { 3, 4, 5, 6 }); x.assign(3); y.assign(1); exp.assign(2); @@ -780,7 +780,7 @@ TEST_F(DeclarableOpsTests1, SubtractTest_2) { sd::ops::subtract subOp; - auto res = subOp.evaluate({&x, &y}); + auto res = subOp.evaluate({ &x, &y }); ASSERT_TRUE(res->status() == ND4J_STATUS_OK); @@ -790,46 +790,46 @@ TEST_F(DeclarableOpsTests1, SubtractTest_2) { } TEST_F(DeclarableOpsTests1, TestRng1) { -/* - Nd4jLong *buffer = new Nd4jLong[100000]; + /* + Nd4jLong *buffer = new Nd4jLong[100000]; - sd::random::RandomBuffer *rng = (sd::random::RandomBuffer *) initRandom(nullptr, 123, 100000, (Nd4jPointer) buffer); + sd::random::RandomBuffer *rng = (sd::random::RandomBuffer *) initRandom(nullptr, 123, 100000, (Nd4jPointer) buffer); - if (rng == nullptr) - throw std::runtime_error("RNG initialization failed"); + if (rng == nullptr) + throw std::runtime_error("RNG initialization failed"); - auto x = NDArrayFactory::create_('c', {5, 3}); - auto variableSpace = new VariableSpace(); - variableSpace->putVariable(-1, x); - auto block = new Context(1, variableSpace, true); - block->fillInputs({-1}); - block->setRNG(rng); - block->getTArguments()->push_back(0.0f); - block->getTArguments()->push_back(1.0f); + auto x = NDArrayFactory::create_('c', {5, 3}); + auto variableSpace = new VariableSpace(); + variableSpace->putVariable(-1, x); + auto block = new Context(1, variableSpace, true); + block->fillInputs({-1}); + block->setRNG(rng); + block->getTArguments()->push_back(0.0f); + block->getTArguments()->push_back(1.0f); - sd::ops::randomuniform uniform; + sd::ops::randomuniform uniform; - Nd4jStatus status = uniform.execute(block); + Nd4jStatus status = uniform.execute(block); - ASSERT_EQ(ND4J_STATUS_OK, status); + ASSERT_EQ(ND4J_STATUS_OK, status); - ASSERT_TRUE(x->sumNumber() > 0.0); + ASSERT_TRUE(x->sumNumber() > 0.0); - destroyRandom((Nd4jPointer) rng); - delete[] buffer; + destroyRandom((Nd4jPointer) rng); + delete[] buffer; - delete variableSpace; - delete block; - */ + delete variableSpace; + delete block; + */ } ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, MergeSumTest1) { - auto x = NDArrayFactory::create_('c', {5, 5}); - auto y = NDArrayFactory::create_('c', {5, 5}); - auto z = NDArrayFactory::create_('c', {5, 5}); - auto exp = NDArrayFactory::create('c', {5, 5}); + auto x = NDArrayFactory::create_('c', { 5, 5 }); + auto y = NDArrayFactory::create_('c', { 5, 5 }); + auto z = NDArrayFactory::create_('c', { 5, 5 }); + auto exp = NDArrayFactory::create('c', { 5, 5 }); x->assign(3); y->assign(1); z->assign(2); @@ -839,9 +839,9 @@ TEST_F(DeclarableOpsTests1, MergeSumTest1) { variableSpace->putVariable(-1, x); variableSpace->putVariable(-2, y); variableSpace->putVariable(-3, z); - variableSpace->putVariable(1, new Variable(NDArrayFactory::create_('c', {5, 5}))); + variableSpace->putVariable(1, new Variable(NDArrayFactory::create_('c', { 5, 5 }))); auto block = new Context(1, variableSpace, false); - block->fillInputs({-1, -2, -3}); + block->fillInputs({ -1, -2, -3 }); sd::ops::mergeadd merge; @@ -859,8 +859,8 @@ TEST_F(DeclarableOpsTests1, MergeSumTest1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, ClipByValue1) { - auto x = NDArrayFactory::create_('c', {5, 5}); - auto exp = NDArrayFactory::create('c', {5, 5}); + auto x = NDArrayFactory::create_('c', { 5, 5 }); + auto exp = NDArrayFactory::create('c', { 5, 5 }); x->assign(4); x->p(0, -1); x->p(1, 2); @@ -874,7 +874,7 @@ TEST_F(DeclarableOpsTests1, ClipByValue1) { auto block = new Context(1, variableSpace, true); block->getTArguments()->push_back(0.0f); block->getTArguments()->push_back(3.0f); - block->fillInputs({-1}); + block->fillInputs({ -1 }); sd::ops::clipbyvalue clip; @@ -890,24 +890,24 @@ TEST_F(DeclarableOpsTests1, ClipByValue1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, MergeAvgTest1) { - auto x = NDArrayFactory::create_('c', {5, 5}); - auto y = NDArrayFactory::create_('c', {5, 5}); - auto z = NDArrayFactory::create_('c', {5, 5}); - auto exp = NDArrayFactory::create('c', {5, 5}); + auto x = NDArrayFactory::create_('c', { 5, 5 }); + auto y = NDArrayFactory::create_('c', { 5, 5 }); + auto z = NDArrayFactory::create_('c', { 5, 5 }); + auto exp = NDArrayFactory::create('c', { 5, 5 }); x->assign(3); y->assign(1); z->assign(2); exp.assign(2); - auto zu = NDArrayFactory::create('c', {5, 5}); + auto zu = NDArrayFactory::create('c', { 5, 5 }); auto variableSpace = new VariableSpace(); variableSpace->putVariable(-1, x); variableSpace->putVariable(-2, y); variableSpace->putVariable(-3, z); - variableSpace->putVariable(1, new Variable(NDArrayFactory::create_('c', {5, 5}))); + variableSpace->putVariable(1, new Variable(NDArrayFactory::create_('c', { 5, 5 }))); auto block = new Context(1, variableSpace, false); - block->fillInputs({-1, -2, -3}); + block->fillInputs({ -1, -2, -3 }); sd::ops::mergeavg merge; @@ -925,9 +925,9 @@ TEST_F(DeclarableOpsTests1, MergeAvgTest1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, SubtractVectorVector1) { - auto x = NDArrayFactory::create_('c', {1, 15}); - auto y = NDArrayFactory::create_('c', {1, 15}); - auto exp = NDArrayFactory::create('c', {1, 15}); + auto x = NDArrayFactory::create_('c', { 1, 15 }); + auto y = NDArrayFactory::create_('c', { 1, 15 }); + auto exp = NDArrayFactory::create('c', { 1, 15 }); x->assign(3); y->assign(1); exp.assign(2); @@ -936,7 +936,7 @@ TEST_F(DeclarableOpsTests1, SubtractVectorVector1) { variableSpace->putVariable(-1, x); variableSpace->putVariable(-2, y); auto block = new Context(1, variableSpace, true); - block->fillInputs({-1, -2}); + block->fillInputs({ -1, -2 }); sd::ops::subtract subOp; @@ -953,9 +953,9 @@ TEST_F(DeclarableOpsTests1, SubtractVectorVector1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, SubtractMatrixScalar1) { - auto x = NDArrayFactory::create_('c', {5, 3}); - auto y = NDArrayFactory::create_('c', {1, 1}); - auto exp = NDArrayFactory::create('c', {5, 3}); + auto x = NDArrayFactory::create_('c', { 5, 3 }); + auto y = NDArrayFactory::create_('c', { 1, 1 }); + auto exp = NDArrayFactory::create('c', { 5, 3 }); x->assign(3); y->assign(1); exp.assign(2); @@ -964,7 +964,7 @@ TEST_F(DeclarableOpsTests1, SubtractMatrixScalar1) { variableSpace->putVariable(-1, x); variableSpace->putVariable(-2, y); auto block = new Context(1, variableSpace, true); - block->fillInputs({-1, -2}); + block->fillInputs({ -1, -2 }); sd::ops::subtract subOp; @@ -980,9 +980,9 @@ TEST_F(DeclarableOpsTests1, SubtractMatrixScalar1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, SubtractScalarScalar1) { - auto x = NDArrayFactory::create_('c', {1, 1}); - auto y = NDArrayFactory::create_('c', {1, 1}); - auto exp = NDArrayFactory::create('c', {1, 1}); + auto x = NDArrayFactory::create_('c', { 1, 1 }); + auto y = NDArrayFactory::create_('c', { 1, 1 }); + auto exp = NDArrayFactory::create('c', { 1, 1 }); x->assign(3); y->assign(1); exp.assign(2); @@ -991,7 +991,7 @@ TEST_F(DeclarableOpsTests1, SubtractScalarScalar1) { variableSpace->putVariable(-1, x); variableSpace->putVariable(-2, y); auto block = new Context(1, variableSpace, true); - block->fillInputs({-1, -2}); + block->fillInputs({ -1, -2 }); sd::ops::subtract subOp; @@ -1006,9 +1006,9 @@ TEST_F(DeclarableOpsTests1, SubtractScalarScalar1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, ReverseSubtractMatrices1) { - auto x = NDArrayFactory::create_('c', {5, 3}); - auto y = NDArrayFactory::create_('c', {5, 3}); - auto exp = NDArrayFactory::create('c', {5, 3}); + auto x = NDArrayFactory::create_('c', { 5, 3 }); + auto y = NDArrayFactory::create_('c', { 5, 3 }); + auto exp = NDArrayFactory::create('c', { 5, 3 }); x->assign(3.f); y->assign(1.f); exp.assign(-2.f); @@ -1017,7 +1017,7 @@ TEST_F(DeclarableOpsTests1, ReverseSubtractMatrices1) { variableSpace->putVariable(-1, x); variableSpace->putVariable(-2, y); auto block = new Context(1, variableSpace, true); - block->fillInputs({-1, -2}); + block->fillInputs({ -1, -2 }); sd::ops::reversesubtract subOp; @@ -1032,16 +1032,16 @@ TEST_F(DeclarableOpsTests1, ReverseSubtractMatrices1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, ReverseSubtractTest_1) { - auto x = NDArrayFactory::create('c', {1, 6}); - auto y = NDArrayFactory::create('c', {1, 6}); - auto exp = NDArrayFactory::create('c', {1, 6}); + auto x = NDArrayFactory::create('c', { 1, 6 }); + auto y = NDArrayFactory::create('c', { 1, 6 }); + auto exp = NDArrayFactory::create('c', { 1, 6 }); x.assign(3.f); y.assign(1.f); exp.assign(-2.f); sd::ops::reversesubtract subOp; - auto res = subOp.evaluate({&x, &y}); + auto res = subOp.evaluate({ &x, &y }); ASSERT_TRUE(res->status() == ND4J_STATUS_OK); ASSERT_TRUE(res->at(0)->equalsTo(&exp)); @@ -1052,10 +1052,10 @@ TEST_F(DeclarableOpsTests1, ReverseSubtractTest_1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, ReverseSubtractTest_2) { -// auto x('c', {1, 6}); - auto x = NDArrayFactory::create('c', {1, 6}); - auto y = NDArrayFactory::create('c', {3, 4, 5, 1}); - auto exp = NDArrayFactory::create('c', {3, 4, 5, 6}); + // auto x('c', {1, 6}); + auto x = NDArrayFactory::create('c', { 1, 6 }); + auto y = NDArrayFactory::create('c', { 3, 4, 5, 1 }); + auto exp = NDArrayFactory::create('c', { 3, 4, 5, 6 }); auto z(exp); x.assign(3.f); y.assign(1.f); @@ -1066,7 +1066,7 @@ TEST_F(DeclarableOpsTests1, ReverseSubtractTest_2) { sd::ops::reversesubtract subOp; - auto res = subOp.evaluate({&x, &y}); + auto res = subOp.evaluate({ &x, &y }); ASSERT_TRUE(res->status() == ND4J_STATUS_OK); ASSERT_TRUE(res->at(0)->equalsTo(&exp)); @@ -1077,10 +1077,10 @@ TEST_F(DeclarableOpsTests1, ReverseSubtractTest_2) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, ReverseSubtractTest_3) { -// auto x('c', {1, 6}); - auto x = NDArrayFactory::create('c', {6}); - auto y = NDArrayFactory::create('c', {3, 4, 5, 1}); - auto exp = NDArrayFactory::create('c', {3, 4, 5, 6}); + // auto x('c', {1, 6}); + auto x = NDArrayFactory::create('c', { 6 }); + auto y = NDArrayFactory::create('c', { 3, 4, 5, 1 }); + auto exp = NDArrayFactory::create('c', { 3, 4, 5, 6 }); auto z(exp); x.assign(1); y.assign(3); @@ -1089,7 +1089,7 @@ TEST_F(DeclarableOpsTests1, ReverseSubtractTest_3) { ASSERT_TRUE(z.equalsTo(&exp)); sd::ops::reversesubtract subOp; - auto res = subOp.evaluate({&x, &y}); + auto res = subOp.evaluate({ &x, &y }); ASSERT_TRUE(res->status() == ND4J_STATUS_OK); ASSERT_TRUE(res->at(0)->equalsTo(&exp)); @@ -1099,10 +1099,10 @@ TEST_F(DeclarableOpsTests1, ReverseSubtractTest_3) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, ReverseModTest_1) { -// auto x('c', {1, 6}); - auto x = NDArrayFactory::create('c', {6}); - auto y = NDArrayFactory::create('c', {3, 4, 5, 1}); - auto exp = NDArrayFactory::create('c', {3, 4, 5, 6}); + // auto x('c', {1, 6}); + auto x = NDArrayFactory::create('c', { 6 }); + auto y = NDArrayFactory::create('c', { 3, 4, 5, 1 }); + auto exp = NDArrayFactory::create('c', { 3, 4, 5, 6 }); auto z(exp); x.assign(2.); y.assign(9.f); @@ -1115,7 +1115,7 @@ TEST_F(DeclarableOpsTests1, ReverseModTest_1) { sd::ops::reversemod subOp; - auto res = subOp.evaluate({&x, &y}); + auto res = subOp.evaluate({ &x, &y }); ASSERT_TRUE(res->status() == ND4J_STATUS_OK); ASSERT_TRUE(res->at(0)->equalsTo(&exp)); @@ -1127,10 +1127,10 @@ TEST_F(DeclarableOpsTests1, ReverseModTest_1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, ReverseModTest_2) { -// auto x('c', {1, 6}); - auto x = NDArrayFactory::create('c', {3, 4, 5}); - auto y = NDArrayFactory::create('c', {3, 4, 5}); - auto exp = NDArrayFactory::create('c', {3, 4, 5}); + // auto x('c', {1, 6}); + auto x = NDArrayFactory::create('c', { 3, 4, 5 }); + auto y = NDArrayFactory::create('c', { 3, 4, 5 }); + auto exp = NDArrayFactory::create('c', { 3, 4, 5 }); auto z(exp); x.assign(2.f); y.assign(9.f); @@ -1142,7 +1142,7 @@ TEST_F(DeclarableOpsTests1, ReverseModTest_2) { sd::ops::reversemod subOp; - auto res = subOp.evaluate({&x, &y}); + auto res = subOp.evaluate({ &x, &y }); ASSERT_TRUE(res->status() == ND4J_STATUS_OK); ASSERT_TRUE(res->at(0)->equalsTo(&exp)); @@ -1153,9 +1153,9 @@ TEST_F(DeclarableOpsTests1, ReverseModTest_2) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, ReverseSubtractVectorVector1) { - auto x = NDArrayFactory::create_ ('c', {1, 15}); - auto y = NDArrayFactory::create_ ('c', {1, 15}); - auto exp = NDArrayFactory::create_ ('c', {1, 15}); + auto x = NDArrayFactory::create_('c', { 1, 15 }); + auto y = NDArrayFactory::create_('c', { 1, 15 }); + auto exp = NDArrayFactory::create_('c', { 1, 15 }); x->assign(3); y->assign(1); exp->assign(-2); @@ -1164,7 +1164,7 @@ TEST_F(DeclarableOpsTests1, ReverseSubtractVectorVector1) { variableSpace->putVariable(-1, x); variableSpace->putVariable(-2, y); auto block = new Context(1, variableSpace, true); - block->fillInputs({-1, -2}); + block->fillInputs({ -1, -2 }); sd::ops::reversesubtract subOp; @@ -1181,9 +1181,9 @@ TEST_F(DeclarableOpsTests1, ReverseSubtractVectorVector1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, ReverseSubtractMatrixScalar1) { - auto x = NDArrayFactory::create_ ('c', {5, 3}); - auto y = NDArrayFactory::create_ ('c', {1, 1}); - auto exp = NDArrayFactory::create_('c', {5, 3}); + auto x = NDArrayFactory::create_('c', { 5, 3 }); + auto y = NDArrayFactory::create_('c', { 1, 1 }); + auto exp = NDArrayFactory::create_('c', { 5, 3 }); x->assign(3); y->assign(1); exp->assign(-2); @@ -1192,7 +1192,7 @@ TEST_F(DeclarableOpsTests1, ReverseSubtractMatrixScalar1) { variableSpace->putVariable(-1, x); variableSpace->putVariable(-2, y); auto block = new Context(1, variableSpace, true); - block->fillInputs({-1, -2}); + block->fillInputs({ -1, -2 }); sd::ops::reversesubtract subOp; @@ -1209,9 +1209,9 @@ TEST_F(DeclarableOpsTests1, ReverseSubtractMatrixScalar1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, ReverseSubtractScalarScalar1) { - auto x = NDArrayFactory::create_ ('c', {1, 1}); - auto y = NDArrayFactory::create_ ('c', {1, 1}); - auto exp = NDArrayFactory::create_('c', {1, 1}); + auto x = NDArrayFactory::create_('c', { 1, 1 }); + auto y = NDArrayFactory::create_('c', { 1, 1 }); + auto exp = NDArrayFactory::create_('c', { 1, 1 }); x->assign(3); y->assign(1); exp->assign(-2); @@ -1220,7 +1220,7 @@ TEST_F(DeclarableOpsTests1, ReverseSubtractScalarScalar1) { variableSpace->putVariable(-1, x); variableSpace->putVariable(-2, y); auto block = new Context(1, variableSpace, true); - block->fillInputs({-1, -2}); + block->fillInputs({ -1, -2 }); sd::ops::reversesubtract subOp; @@ -1236,9 +1236,9 @@ TEST_F(DeclarableOpsTests1, ReverseSubtractScalarScalar1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, MultiplyMatrices1) { - auto x = NDArrayFactory::create_ ('c', {5, 3}); - auto y = NDArrayFactory::create_ ('c', {5, 3}); - auto exp = NDArrayFactory::create_('c', {5, 3}); + auto x = NDArrayFactory::create_('c', { 5, 3 }); + auto y = NDArrayFactory::create_('c', { 5, 3 }); + auto exp = NDArrayFactory::create_('c', { 5, 3 }); x->assign(2); y->assign(3); exp->assign(6); @@ -1247,7 +1247,7 @@ TEST_F(DeclarableOpsTests1, MultiplyMatrices1) { variableSpace->putVariable(-1, x); variableSpace->putVariable(-2, y); auto block = new Context(1, variableSpace, true); - block->fillInputs({-1, -2}); + block->fillInputs({ -1, -2 }); sd::ops::multiply mul; @@ -1263,9 +1263,9 @@ TEST_F(DeclarableOpsTests1, MultiplyMatrices1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, MultiplyVectorVector1) { - auto x = NDArrayFactory::create_ ('c', {1, 15}); - auto y = NDArrayFactory::create_ ('c', {1, 15}); - auto exp = NDArrayFactory::create_('c', {1, 15}); + auto x = NDArrayFactory::create_('c', { 1, 15 }); + auto y = NDArrayFactory::create_('c', { 1, 15 }); + auto exp = NDArrayFactory::create_('c', { 1, 15 }); x->assign(2); y->assign(3); exp->assign(6); @@ -1274,7 +1274,7 @@ TEST_F(DeclarableOpsTests1, MultiplyVectorVector1) { variableSpace->putVariable(-1, x); variableSpace->putVariable(-2, y); auto block = new Context(1, variableSpace, true); - block->fillInputs({-1, -2}); + block->fillInputs({ -1, -2 }); sd::ops::multiply mul; @@ -1290,9 +1290,9 @@ TEST_F(DeclarableOpsTests1, MultiplyVectorVector1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, MultiplyMatrixScalar) { - auto x = NDArrayFactory::create_ ('c', {5, 3}); - auto y = NDArrayFactory::create_ ('c', {1, 1}); - auto exp = NDArrayFactory::create_('c', {5, 3}); + auto x = NDArrayFactory::create_('c', { 5, 3 }); + auto y = NDArrayFactory::create_('c', { 1, 1 }); + auto exp = NDArrayFactory::create_('c', { 5, 3 }); x->assign(2); y->assign(3); exp->assign(6); @@ -1301,7 +1301,7 @@ TEST_F(DeclarableOpsTests1, MultiplyMatrixScalar) { variableSpace->putVariable(-1, x); variableSpace->putVariable(-2, y); auto block = new Context(1, variableSpace, true); - block->fillInputs({-1, -2}); + block->fillInputs({ -1, -2 }); sd::ops::multiply mul; @@ -1317,9 +1317,9 @@ TEST_F(DeclarableOpsTests1, MultiplyMatrixScalar) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, MultiplyScalarScalar1) { - auto x = NDArrayFactory::create_ ('c', {1, 1}); - auto y = NDArrayFactory::create_ ('c', {1, 1}); - auto exp = NDArrayFactory::create_('c', {1, 1}); + auto x = NDArrayFactory::create_('c', { 1, 1 }); + auto y = NDArrayFactory::create_('c', { 1, 1 }); + auto exp = NDArrayFactory::create_('c', { 1, 1 }); x->assign(2); y->assign(3); exp->assign(6); @@ -1328,7 +1328,7 @@ TEST_F(DeclarableOpsTests1, MultiplyScalarScalar1) { variableSpace->putVariable(-1, x); variableSpace->putVariable(-2, y); auto block = new Context(1, variableSpace, true); - block->fillInputs({-1, -2}); + block->fillInputs({ -1, -2 }); sd::ops::multiply mul; @@ -1344,20 +1344,20 @@ TEST_F(DeclarableOpsTests1, MultiplyScalarScalar1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, TestSoftMax_bp_1) { - auto input = NDArrayFactory::create_('c', {2, 2}); + auto input = NDArrayFactory::create_('c', { 2, 2 }); for (int e = 0; e < input->lengthOf(); e++) - input->p(e, e+1); + input->p(e, e + 1); - auto epsilon = NDArrayFactory::create_('c', {2, 2}); + auto epsilon = NDArrayFactory::create_('c', { 2, 2 }); epsilon->p(0, 0.1f); epsilon->p(1, 0.2f); epsilon->p(2, 0.3f); epsilon->p(3, 0.4f); - auto output = NDArrayFactory::create_('c', {2, 2}); + auto output = NDArrayFactory::create_('c', { 2, 2 }); output->assign(1.0f); - auto exp = NDArrayFactory::create_('c', {2, 2}); + auto exp = NDArrayFactory::create_('c', { 2, 2 }); exp->p(0, -0.019661194f); exp->p(1, 0.019661194f); exp->p(2, -0.019661194f); @@ -1370,7 +1370,7 @@ TEST_F(DeclarableOpsTests1, TestSoftMax_bp_1) { //variableSpace->putVariable(42, exp); auto block = new Context(1, variableSpace, false); - block->fillInputs({-1, -2}); + block->fillInputs({ -1, -2 }); sd::ops::softmax_bp op; @@ -1388,16 +1388,16 @@ TEST_F(DeclarableOpsTests1, TestSoftMax_bp_1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, BroadcastDivideTest_1) { - auto x = NDArrayFactory::create('c', {3, 4, 5, 1}); - auto y = NDArrayFactory::create('c', {1, 6}); - auto exp = NDArrayFactory::create('c', {3, 4, 5, 6}); + auto x = NDArrayFactory::create('c', { 3, 4, 5, 1 }); + auto y = NDArrayFactory::create('c', { 1, 6 }); + auto exp = NDArrayFactory::create('c', { 3, 4, 5, 6 }); x.assign(6); y.assign(2); exp.assign(3); sd::ops::divide div; - auto res = div.evaluate({&x, &y}); + auto res = div.evaluate({ &x, &y }); ASSERT_EQ(res->status(), ND4J_STATUS_OK); ASSERT_TRUE(res->at(0)->equalsTo(exp)); @@ -1408,15 +1408,15 @@ TEST_F(DeclarableOpsTests1, BroadcastDivideTest_1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, BroadcastDivideTest_2) { - auto x = NDArrayFactory::create('c', {3, 4, 5, 1}); - auto y = NDArrayFactory::create('c', {1, 6}); - auto exp = NDArrayFactory::create('c', {3, 4, 5, 6}); + auto x = NDArrayFactory::create('c', { 3, 4, 5, 1 }); + auto y = NDArrayFactory::create('c', { 1, 6 }); + auto exp = NDArrayFactory::create('c', { 3, 4, 5, 6 }); x.assign(6); y.assign(2); exp.assign(3); sd::ops::divide_no_nan div; - auto res = div.evaluate({&x, &y}); + auto res = div.evaluate({ &x, &y }); ASSERT_EQ(res->status(), ND4J_STATUS_OK); ASSERT_TRUE(res->at(0)->equalsTo(exp)); @@ -1427,12 +1427,12 @@ TEST_F(DeclarableOpsTests1, BroadcastDivideTest_2) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, BroadcastDivideTest_3) { - auto x = NDArrayFactory::create({6,6,6,6,6}); - auto y = NDArrayFactory::create({3,3,0,3,3}); - auto exp = NDArrayFactory::create({2, 2, 0, 2, 2}); + auto x = NDArrayFactory::create({ 6,6,6,6,6 }); + auto y = NDArrayFactory::create({ 3,3,0,3,3 }); + auto exp = NDArrayFactory::create({ 2, 2, 0, 2, 2 }); sd::ops::divide_no_nan div; - auto res = div.evaluate({&x, &y}); + auto res = div.evaluate({ &x, &y }); ASSERT_EQ(res->status(), ND4J_STATUS_OK); ASSERT_TRUE(res->at(0)->equalsTo(exp)); @@ -1443,16 +1443,16 @@ TEST_F(DeclarableOpsTests1, BroadcastDivideTest_3) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, BroadcastReverseDivideTest_1) { - auto x = NDArrayFactory::create('c', {3, 4, 5, 1}); - auto y = NDArrayFactory::create('c', {1, 6}); - auto exp = NDArrayFactory::create('c', {3, 4, 5, 6}); + auto x = NDArrayFactory::create('c', { 3, 4, 5, 1 }); + auto y = NDArrayFactory::create('c', { 1, 6 }); + auto exp = NDArrayFactory::create('c', { 3, 4, 5, 6 }); x.assign(3.f); y.assign(6.f); exp.assign(2.f); sd::ops::reversedivide div; - auto res = div.evaluate({&x, &y}); + auto res = div.evaluate({ &x, &y }); ASSERT_EQ(res->status(), ND4J_STATUS_OK); @@ -1469,9 +1469,9 @@ TEST_F(DeclarableOpsTests1, BroadcastReverseDivideTest_1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, DivideMatrices1) { - auto x = NDArrayFactory::create_ ('c', {5, 3}); - auto y = NDArrayFactory::create_ ('c', {5, 3}); - auto exp = NDArrayFactory::create_('c', {5, 3}); + auto x = NDArrayFactory::create_('c', { 5, 3 }); + auto y = NDArrayFactory::create_('c', { 5, 3 }); + auto exp = NDArrayFactory::create_('c', { 5, 3 }); x->assign(6); y->assign(2); exp->assign(3); @@ -1480,7 +1480,7 @@ TEST_F(DeclarableOpsTests1, DivideMatrices1) { variableSpace->putVariable(-1, x); variableSpace->putVariable(-2, y); auto block = new Context(1, variableSpace, true); - block->fillInputs({-1, -2}); + block->fillInputs({ -1, -2 }); sd::ops::divide div; @@ -1496,9 +1496,9 @@ TEST_F(DeclarableOpsTests1, DivideMatrices1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, DivideVectorVector1) { - auto x = NDArrayFactory::create_('c', {1, 15}); - auto y = NDArrayFactory::create_('c', {1, 15}); - auto exp = NDArrayFactory::create('c', {1, 15}); + auto x = NDArrayFactory::create_('c', { 1, 15 }); + auto y = NDArrayFactory::create_('c', { 1, 15 }); + auto exp = NDArrayFactory::create('c', { 1, 15 }); x->assign(6); y->assign(2); exp.assign(3); @@ -1507,7 +1507,7 @@ TEST_F(DeclarableOpsTests1, DivideVectorVector1) { variableSpace->putVariable(-1, x); variableSpace->putVariable(-2, y); auto block = new Context(1, variableSpace, true); - block->fillInputs({-1, -2}); + block->fillInputs({ -1, -2 }); sd::ops::divide div; @@ -1522,9 +1522,9 @@ TEST_F(DeclarableOpsTests1, DivideVectorVector1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, DivideMatrixScalar1) { - auto x = NDArrayFactory::create_('c', {5, 3}); - auto y = NDArrayFactory::create_('c', {1, 1}); - auto exp = NDArrayFactory::create('c', {5, 3}); + auto x = NDArrayFactory::create_('c', { 5, 3 }); + auto y = NDArrayFactory::create_('c', { 1, 1 }); + auto exp = NDArrayFactory::create('c', { 5, 3 }); x->assign(6); y->assign(2); exp.assign(3); @@ -1533,7 +1533,7 @@ TEST_F(DeclarableOpsTests1, DivideMatrixScalar1) { variableSpace->putVariable(-1, x); variableSpace->putVariable(-2, y); auto block = new Context(1, variableSpace, true); - block->fillInputs({-1, -2}); + block->fillInputs({ -1, -2 }); sd::ops::divide div; @@ -1549,9 +1549,9 @@ TEST_F(DeclarableOpsTests1, DivideMatrixScalar1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, DivideScalarScalar1) { - auto x = NDArrayFactory::create_('c', {5, 1}); - auto y = NDArrayFactory::create_('c', {5, 1}); - auto exp = NDArrayFactory::create('c', {5, 1}); + auto x = NDArrayFactory::create_('c', { 5, 1 }); + auto y = NDArrayFactory::create_('c', { 5, 1 }); + auto exp = NDArrayFactory::create('c', { 5, 1 }); x->assign(6); y->assign(2); exp.assign(3); @@ -1560,7 +1560,7 @@ TEST_F(DeclarableOpsTests1, DivideScalarScalar1) { variableSpace->putVariable(-1, x); variableSpace->putVariable(-2, y); auto block = new Context(1, variableSpace, true); - block->fillInputs({-1, -2}); + block->fillInputs({ -1, -2 }); sd::ops::divide div; @@ -1575,9 +1575,9 @@ TEST_F(DeclarableOpsTests1, DivideScalarScalar1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, ReverseDivideMatrices1) { - auto x = NDArrayFactory::create_('c', {5, 3}); - auto y = NDArrayFactory::create_('c', {5, 3}); - auto exp = NDArrayFactory::create('c', {5, 3}); + auto x = NDArrayFactory::create_('c', { 5, 3 }); + auto y = NDArrayFactory::create_('c', { 5, 3 }); + auto exp = NDArrayFactory::create('c', { 5, 3 }); x->assign(2); y->assign(6); exp.assign(3); @@ -1586,7 +1586,7 @@ TEST_F(DeclarableOpsTests1, ReverseDivideMatrices1) { variableSpace->putVariable(-1, x); variableSpace->putVariable(-2, y); auto block = new Context(1, variableSpace, true); - block->fillInputs({-1, -2}); + block->fillInputs({ -1, -2 }); sd::ops::reversedivide div; @@ -1601,9 +1601,9 @@ TEST_F(DeclarableOpsTests1, ReverseDivideMatrices1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, ReverseDivideVectorVector1) { - auto x = NDArrayFactory::create_('c', {1, 15}); - auto y = NDArrayFactory::create_('c', {1, 15}); - auto exp = NDArrayFactory::create('c', {1, 15}); + auto x = NDArrayFactory::create_('c', { 1, 15 }); + auto y = NDArrayFactory::create_('c', { 1, 15 }); + auto exp = NDArrayFactory::create('c', { 1, 15 }); x->assign(2); y->assign(6); exp.assign(3); @@ -1612,7 +1612,7 @@ TEST_F(DeclarableOpsTests1, ReverseDivideVectorVector1) { variableSpace->putVariable(-1, x); variableSpace->putVariable(-2, y); auto block = new Context(1, variableSpace, true); - block->fillInputs({-1, -2}); + block->fillInputs({ -1, -2 }); sd::ops::reversedivide div; @@ -1627,9 +1627,9 @@ TEST_F(DeclarableOpsTests1, ReverseDivideVectorVector1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, ReverseDivideMatrixScalar1) { - auto x = NDArrayFactory::create_('c', {5, 3}); - auto y = NDArrayFactory::create_('c', {1, 1}); - auto exp = NDArrayFactory::create('c', {5, 3}); + auto x = NDArrayFactory::create_('c', { 5, 3 }); + auto y = NDArrayFactory::create_('c', { 1, 1 }); + auto exp = NDArrayFactory::create('c', { 5, 3 }); x->assign(2); y->assign(6); exp.assign(3); @@ -1638,7 +1638,7 @@ TEST_F(DeclarableOpsTests1, ReverseDivideMatrixScalar1) { variableSpace->putVariable(-1, x); variableSpace->putVariable(-2, y); auto block = new Context(1, variableSpace, true); - block->fillInputs({-1, -2}); + block->fillInputs({ -1, -2 }); sd::ops::reversedivide div; @@ -1653,9 +1653,9 @@ TEST_F(DeclarableOpsTests1, ReverseDivideMatrixScalar1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, ReverseDivideScalarScalar1) { - auto x = NDArrayFactory::create_('c', {1, 1}); - auto y = NDArrayFactory::create_('c', {1, 1}); - auto exp = NDArrayFactory::create('c', {1, 1}); + auto x = NDArrayFactory::create_('c', { 1, 1 }); + auto y = NDArrayFactory::create_('c', { 1, 1 }); + auto exp = NDArrayFactory::create('c', { 1, 1 }); x->assign(2); y->assign(6); exp.assign(3); @@ -1664,7 +1664,7 @@ TEST_F(DeclarableOpsTests1, ReverseDivideScalarScalar1) { variableSpace->putVariable(-1, x); variableSpace->putVariable(-2, y); auto block = new Context(1, variableSpace, true); - block->fillInputs({-1, -2}); + block->fillInputs({ -1, -2 }); sd::ops::reversedivide div; @@ -1678,8 +1678,8 @@ TEST_F(DeclarableOpsTests1, ReverseDivideScalarScalar1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, Reshapeas1) { - const std::vector xShape = {5,4,3}; - const std::vector yShape = {3,5,4}; + const std::vector xShape = { 5,4,3 }; + const std::vector yShape = { 3,5,4 }; auto x = NDArrayFactory::create_('f', xShape); auto y = NDArrayFactory::create_('f', yShape); @@ -1689,7 +1689,7 @@ TEST_F(DeclarableOpsTests1, Reshapeas1) { variableSpace->putVariable(-1, x); variableSpace->putVariable(-2, y); auto block = new Context(1, variableSpace, true); - block->fillInputs({-1, -2}); + block->fillInputs({ -1, -2 }); sd::ops::reshapeas reshape; @@ -1703,13 +1703,13 @@ TEST_F(DeclarableOpsTests1, Reshapeas1) { TEST_F(DeclarableOpsTests1, Test_Cast_1) { // TODO: right now there's no real cast implementation, but genera idea should be the same: arrays equality to be expected - auto x = NDArrayFactory::create('c', {5, 5}); - auto yExp = NDArrayFactory::create('c', {5, 5}); + auto x = NDArrayFactory::create('c', { 5, 5 }); + auto yExp = NDArrayFactory::create('c', { 5, 5 }); x.linspace(1); yExp.linspace(1); sd::ops::cast op; - auto result = op.evaluate({&x}, {}, {3}); + auto result = op.evaluate({ &x }, {}, { 3 }); ASSERT_EQ(ND4J_STATUS_OK, result->status()); auto z = result->at(0); @@ -1850,8 +1850,8 @@ TEST_F(DeclarableOpsTests1, TestGemv1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, Reshape2) { - const std::vector xShape = {5,4,3}; - const std::vector yShape = {3,5,4}; + const std::vector xShape = { 5,4,3 }; + const std::vector yShape = { 3,5,4 }; auto x = NDArrayFactory::create_('c', xShape); auto y = NDArrayFactory::create_('c', yShape); @@ -1861,7 +1861,7 @@ TEST_F(DeclarableOpsTests1, Reshape2) { variableSpace->putVariable(1, new Variable()); auto block = new Context(1, variableSpace, false); - block->fillInputs({-1}); + block->fillInputs({ -1 }); std::vector* arguments = block->getIArguments(); arguments->push_back(-y->ordering()); arguments->push_back(3); @@ -1882,10 +1882,10 @@ TEST_F(DeclarableOpsTests1, Reshape2) { } TEST_F(DeclarableOpsTests1, Reshape3) { - auto x = NDArrayFactory::create('c', {3, 4, 5}); + auto x = NDArrayFactory::create('c', { 3, 4, 5 }); sd::ops::reshape op; - auto result = op.evaluate({&x}, {}, {-99, 3, 4, 5}); + auto result = op.evaluate({ &x }, {}, { -99, 3, 4, 5 }); ASSERT_EQ(ND4J_STATUS_OK, result->status()); @@ -1897,10 +1897,10 @@ TEST_F(DeclarableOpsTests1, Reshape3) { } TEST_F(DeclarableOpsTests1, Reshape4) { - auto x = NDArrayFactory::create('c', {3, 4, 5}); + auto x = NDArrayFactory::create('c', { 3, 4, 5 }); sd::ops::reshape op; - auto result = op.evaluate({&x}, {}, {3, 4, 5}); + auto result = op.evaluate({ &x }, {}, { 3, 4, 5 }); ASSERT_EQ(ND4J_STATUS_OK, result->status()); @@ -1912,22 +1912,22 @@ TEST_F(DeclarableOpsTests1, Reshape4) { } TEST_F(DeclarableOpsTests1, Reshape5) { - auto x = NDArrayFactory::create('c', {3, 4, 5}); + auto x = NDArrayFactory::create('c', { 3, 4, 5 }); sd::ops::reshape op; - auto result = op.evaluate({&x}, {}, {5, 4, 3}); + auto result = op.evaluate({ &x }, {}, { 5, 4, 3 }); ASSERT_EQ(ND4J_STATUS_OK, result->status()); delete result; } -TEST_F(DeclarableOpsTests1, Reshape6){ - auto x = NDArrayFactory::create('c', {3, 4, 5}); - auto exp = NDArrayFactory::create('c', {4, 15}); +TEST_F(DeclarableOpsTests1, Reshape6) { + auto x = NDArrayFactory::create('c', { 3, 4, 5 }); + auto exp = NDArrayFactory::create('c', { 4, 15 }); sd::ops::reshape op; - auto result = op.evaluate({&x}, {}, {4, -1}); + auto result = op.evaluate({ &x }, {}, { 4, -1 }); ASSERT_EQ(ND4J_STATUS_OK, result->status()); @@ -1939,12 +1939,12 @@ TEST_F(DeclarableOpsTests1, Reshape6){ } -TEST_F(DeclarableOpsTests1, Reshape7){ - auto x = NDArrayFactory::create('c', {3, 4, 5}); - auto exp = NDArrayFactory::create('c', {60}); +TEST_F(DeclarableOpsTests1, Reshape7) { + auto x = NDArrayFactory::create('c', { 3, 4, 5 }); + auto exp = NDArrayFactory::create('c', { 60 }); sd::ops::reshape op; - auto result = op.evaluate({&x}, {}, {-1}); + auto result = op.evaluate({ &x }, {}, { -1 }); ASSERT_EQ(ND4J_STATUS_OK, result->status()); @@ -1958,15 +1958,15 @@ TEST_F(DeclarableOpsTests1, Reshape7){ ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, Transpose1) { - auto x = NDArrayFactory::create_('c', {3,5,2}); - auto exp = NDArrayFactory::create_('c', {2,5,3}); + auto x = NDArrayFactory::create_('c', { 3,5,2 }); + auto exp = NDArrayFactory::create_('c', { 2,5,3 }); auto variableSpace = new VariableSpace(); variableSpace->putVariable(-1, x); variableSpace->putVariable(1, new Variable()); auto block = new Context(1, variableSpace, false); // not-in-place - block->fillInputs({-1}); + block->fillInputs({ -1 }); sd::ops::transpose transpose; Nd4jStatus status = transpose.execute(block); @@ -1988,9 +1988,9 @@ TEST_F(DeclarableOpsTests1, Transpose1) { // not-in-place TEST_F(DeclarableOpsTests1, Permute1) { - Nd4jLong shapeX[] = {3, 5,10,15, 150,15,1, 0,1,99}; - Nd4jLong shapeExp[] = {3, 15,5,10, 50,10,1, 0,1,99}; - const std::vector perm = {2, 0, 1}; + Nd4jLong shapeX[] = { 3, 5,10,15, 150,15,1, 0,1,99 }; + Nd4jLong shapeExp[] = { 3, 15,5,10, 50,10,1, 0,1,99 }; + const std::vector perm = { 2, 0, 1 }; ArrayOptions::setDataType(shapeX, sd::DataType::FLOAT32); ArrayOptions::setDataType(shapeExp, sd::DataType::FLOAT32); @@ -2003,7 +2003,7 @@ TEST_F(DeclarableOpsTests1, Permute1) { variableSpace->putVariable(1, new Variable()); auto block = new Context(1, variableSpace, false); // not-in-place - block->fillInputs({-1}); + block->fillInputs({ -1 }); auto arguments = block->getIArguments(); *arguments = perm; // set dimensions to be permuted @@ -2021,13 +2021,13 @@ TEST_F(DeclarableOpsTests1, Permute1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, TestArgumentsValidation1) { - Nd4jLong shapeX[] = {3, 5, 10, 15, 150, 15, 1, 0, 1, 99}; - Nd4jLong shapeExp[] = {3, 15, 5, 10, 1, 150, 15, 0, -1, 99}; + Nd4jLong shapeX[] = { 3, 5, 10, 15, 150, 15, 1, 0, 1, 99 }; + Nd4jLong shapeExp[] = { 3, 15, 5, 10, 1, 150, 15, 0, -1, 99 }; ArrayOptions::setDataType(shapeX, sd::DataType::FLOAT32); ArrayOptions::setDataType(shapeExp, sd::DataType::FLOAT32); - const std::vector perm = {2, 0, 1}; + const std::vector perm = { 2, 0, 1 }; auto x = new NDArray(shapeX); auto exp = new NDArray(shapeExp); @@ -2036,7 +2036,7 @@ TEST_F(DeclarableOpsTests1, TestArgumentsValidation1) { variableSpace->putVariable(1, new Variable()); auto block = new Context(1, variableSpace, false); // not-in-place - block->fillInputs({-1}); + block->fillInputs({ -1 }); sd::ops::im2col permute; Nd4jStatus status = permute.execute(block); @@ -2050,13 +2050,13 @@ TEST_F(DeclarableOpsTests1, TestArgumentsValidation1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, TestReductionShape1) { - auto input = NDArrayFactory::create_('c', {4, 5, 5, 10, 10}); + auto input = NDArrayFactory::create_('c', { 4, 5, 5, 10, 10 }); auto variableSpace = new VariableSpace(); variableSpace->putVariable(-1, input); auto block = new Context(1, variableSpace, false); // not-in-place - block->fillInputs({-1}); + block->fillInputs({ -1 }); // kernel params block->getIArguments()->push_back(MAX_INT); @@ -2070,10 +2070,10 @@ TEST_F(DeclarableOpsTests1, TestReductionShape1) { auto shapes = testop.calculateOutputShape(inshape, *block); - ASSERT_EQ(1,shapes->size()); - ASSERT_EQ(0,shapes->at(0)[0]); // scalar shape has rank 0 - ASSERT_EQ(8192,shapes->at(0)[1]); - ASSERT_EQ(1,shapes->at(0)[2]); + ASSERT_EQ(1, shapes->size()); + ASSERT_EQ(0, shapes->at(0)[0]); // scalar shape has rank 0 + ASSERT_EQ(8192, shapes->at(0)[1]); + ASSERT_EQ(1, shapes->at(0)[2]); delete[] inP; delete variableSpace; @@ -2085,13 +2085,13 @@ TEST_F(DeclarableOpsTests1, TestReductionShape1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, TestReductionShape2) { - auto input = NDArrayFactory::create_('c', {4, 5, 5, 10, 10}); + auto input = NDArrayFactory::create_('c', { 4, 5, 5, 10, 10 }); auto variableSpace = new VariableSpace(); variableSpace->putVariable(-1, input); auto block = new Context(1, variableSpace, false); // not-in-place - block->fillInputs({-1}); + block->fillInputs({ -1 }); // kernel params //block->getIArguments()->push_back(4); @@ -2104,10 +2104,10 @@ TEST_F(DeclarableOpsTests1, TestReductionShape2) { auto inshapes = new ShapeList(input->getShapeInfo()); auto shapes = testop.calculateOutputShape(inshapes, *block); - ASSERT_EQ(1,shapes->size()); - ASSERT_EQ(1,shapes->at(0)[0]); - ASSERT_EQ(4,shapes->at(0)[1]); - ASSERT_EQ(1,shapes->at(0)[2]); + ASSERT_EQ(1, shapes->size()); + ASSERT_EQ(1, shapes->at(0)[0]); + ASSERT_EQ(4, shapes->at(0)[1]); + ASSERT_EQ(1, shapes->at(0)[2]); delete variableSpace; delete block; @@ -2117,13 +2117,13 @@ TEST_F(DeclarableOpsTests1, TestReductionShape2) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, TestCustomShape1) { - auto input = NDArrayFactory::create_('c', {2, 3, 4}); + auto input = NDArrayFactory::create_('c', { 2, 3, 4 }); auto variableSpace = new VariableSpace(); variableSpace->putVariable(-1, input); auto block = new Context(1, variableSpace, false); // not-in-place - block->fillInputs({-1}); + block->fillInputs({ -1 }); sd::ops::testcustom test; @@ -2131,7 +2131,7 @@ TEST_F(DeclarableOpsTests1, TestCustomShape1) { auto shapes = test.calculateOutputShape(inshapes, *block); - ASSERT_EQ(input->getShapeInfo()[0] , shapes->at(0)[0]); + ASSERT_EQ(input->getShapeInfo()[0], shapes->at(0)[0]); ASSERT_EQ(input->getShapeInfo()[1] * 2, shapes->at(0)[1]); ASSERT_EQ(input->getShapeInfo()[2] * 2, shapes->at(0)[2]); ASSERT_EQ(input->getShapeInfo()[3] * 2, shapes->at(0)[3]); @@ -2183,8 +2183,8 @@ TEST_F(DeclarableOpsTests1, Sum1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, Pnormpool2d1) { - auto x = NDArrayFactory::create_('c', {bS,iD,iH,iW}); - auto exp = NDArrayFactory::create('c',{bS,iD,oH,oW}); + auto x = NDArrayFactory::create_('c', { bS,iD,iH,iW }); + auto exp = NDArrayFactory::create('c', { bS,iD,oH,oW }); // auto z('c',{bS,iD,oH,oW}); auto variableSpace = new VariableSpace(); @@ -2192,9 +2192,9 @@ TEST_F(DeclarableOpsTests1, Pnormpool2d1) { // variableSpace->putVariable(1, &z); auto block = new Context(1, variableSpace, false); - block->fillInputs({-1}); + block->fillInputs({ -1 }); std::vector* argI = block->getIArguments(); - *argI = {kH,kW, sH,sW, pH,pW, dW,dH, 0, 1, 0}; // 0,1 - kernel Height/Width; 2,3 - stride Height/Width; 4,5 - pad Height/Width; 6,7 - dilation Height/Width; 8 - same mode; 9 - extraParam0 for pnorm case; + *argI = { kH,kW, sH,sW, pH,pW, dW,dH, 0, 1, 0 }; // 0,1 - kernel Height/Width; 2,3 - stride Height/Width; 4,5 - pad Height/Width; 6,7 - dilation Height/Width; 8 - same mode; 9 - extraParam0 for pnorm case; sd::ops::pnormpool2d pooling; Nd4jStatus status = pooling.execute(block); @@ -2242,16 +2242,16 @@ TEST_F(DeclarableOpsTests1, IsMax1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, IsMax1) { - NDArray x('c', {3, 3}, sd::DataType::FLOAT32); -// NDArray exp('c', {3, 3}, sd::DataType::BOOL); - NDArray exp('c', {3, 3}, sd::DataType::FLOAT32); + NDArray x('c', { 3, 3 }, sd::DataType::FLOAT32); + // NDArray exp('c', {3, 3}, sd::DataType::BOOL); + NDArray exp('c', { 3, 3 }, sd::DataType::FLOAT32); x.linspace(1); exp.p(0, 2, true); exp.p(1, 2, true); exp.p(2, 2, true); sd::ops::ismax ismaxOp; - auto result = ismaxOp.evaluate({&x}, {}, {1}); + auto result = ismaxOp.evaluate({ &x }, {}, { 1 }); ASSERT_EQ(ND4J_STATUS_OK, result->status()); @@ -2264,16 +2264,16 @@ TEST_F(DeclarableOpsTests1, IsMax1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, IsMax2) { - NDArray x('c', {3, 3}, sd::DataType::FLOAT32); -// NDArray exp('c', {3, 3}, sd::DataType::BOOL); - NDArray exp('c', {3, 3}, sd::DataType::FLOAT32); + NDArray x('c', { 3, 3 }, sd::DataType::FLOAT32); + // NDArray exp('c', {3, 3}, sd::DataType::BOOL); + NDArray exp('c', { 3, 3 }, sd::DataType::FLOAT32); x.linspace(1); //exp.p(0, 2, true); //exp.p(1, 2, true); exp.p(2, 2, true); sd::ops::ismax ismaxOp; - auto result = ismaxOp.evaluate({&x}, {}, {0, 1}); + auto result = ismaxOp.evaluate({ &x }, {}, { 0, 1 }); ASSERT_EQ(ND4J_STATUS_OK, result->status()); @@ -2295,7 +2295,7 @@ TEST_F(DeclarableOpsTests1, IsMax3) { //exp.p(2, 2, true); sd::ops::ismax ismaxOp; - auto result = ismaxOp.evaluate({&x}, {}, {0}); + auto result = ismaxOp.evaluate({ &x }, {}, { 0 }); ASSERT_EQ(ND4J_STATUS_OK, result->status()); @@ -2308,12 +2308,12 @@ TEST_F(DeclarableOpsTests1, IsMax3) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, IsMax4) { - auto x = NDArrayFactory::create('c', {6}, {0, 0, 0, 2, 2, 0}); - auto z = NDArrayFactory::create('c', {6}); - auto e = NDArrayFactory::create('c', {6}, {false, false, false, true, false, false}); + auto x = NDArrayFactory::create('c', { 6 }, { 0, 0, 0, 2, 2, 0 }); + auto z = NDArrayFactory::create('c', { 6 }); + auto e = NDArrayFactory::create('c', { 6 }, { false, false, false, true, false, false }); sd::ops::ismax op; - auto result = op.execute({&x}, {&z}); + auto result = op.execute({ &x }, { &z }); ASSERT_EQ(Status::OK(), result); ASSERT_EQ(e, z); @@ -2362,26 +2362,26 @@ TEST_F(DeclarableOpsTests1, sru_test1) { const int K = 3; const int N = 4; - NDArray input('c', {bS,K,N}, sd::DataType::DOUBLE); - NDArray weights('c', {3*K,K}, sd::DataType::DOUBLE); - NDArray bias('c', {2*K}, sd::DataType::DOUBLE); - NDArray init('c', {bS,K}, sd::DataType::DOUBLE); - NDArray mask('c', {bS,K}, sd::DataType::DOUBLE); - NDArray expState('c', {bS,K,N}, {1.090533, 1.174509, 1.252403, 1.324656, 1.090533, 1.174509, 1.252403, 1.324656, 1.090533, 1.174509, 1.252403, 1.324656, 1.090533, 1.174509, 1.252403, 1.324656, 1.090533, 1.174509, 1.252403, 1.324656, 1.090533, 1.174509, 1.252403, 1.324656}, sd::DataType::DOUBLE); - NDArray expOut('c', {bS,K,N}, {0.847983, 0.874549, 0.896109, 0.913715, 0.847983, 0.874549, 0.896109, 0.913715, 0.847983, 0.874549, 0.896109, 0.913715, 0.847983, 0.874549, 0.896109, 0.913715, 0.847983, 0.874549, 0.896109, 0.913715, 0.847983, 0.874549, 0.896109, 0.913715}, sd::DataType::DOUBLE); + NDArray input('c', { bS,K,N }, sd::DataType::DOUBLE); + NDArray weights('c', { 3 * K,K }, sd::DataType::DOUBLE); + NDArray bias('c', { 2 * K }, sd::DataType::DOUBLE); + NDArray init('c', { bS,K }, sd::DataType::DOUBLE); + NDArray mask('c', { bS,K }, sd::DataType::DOUBLE); + NDArray expState('c', { bS,K,N }, { 1.090533, 1.174509, 1.252403, 1.324656, 1.090533, 1.174509, 1.252403, 1.324656, 1.090533, 1.174509, 1.252403, 1.324656, 1.090533, 1.174509, 1.252403, 1.324656, 1.090533, 1.174509, 1.252403, 1.324656, 1.090533, 1.174509, 1.252403, 1.324656 }, sd::DataType::DOUBLE); + NDArray expOut('c', { bS,K,N }, { 0.847983, 0.874549, 0.896109, 0.913715, 0.847983, 0.874549, 0.896109, 0.913715, 0.847983, 0.874549, 0.896109, 0.913715, 0.847983, 0.874549, 0.896109, 0.913715, 0.847983, 0.874549, 0.896109, 0.913715, 0.847983, 0.874549, 0.896109, 0.913715 }, sd::DataType::DOUBLE); input.assign(1.5); weights.assign(0.5); - bias.assign(0.3) ; + bias.assign(0.3); init.assign(1.); mask.assign(1.); sd::ops::sru op; - auto results = op.evaluate({&input, &weights, &bias, &init, &mask}); + auto results = op.evaluate({ &input, &weights, &bias, &init, &mask }); ASSERT_TRUE(results->size() == 2); auto output = results->at(0); - auto state = results->at(1); + auto state = results->at(1); ASSERT_TRUE(expState.equalsTo(state)); ASSERT_TRUE(expOut.equalsTo(output)); @@ -2395,45 +2395,45 @@ TEST_F(DeclarableOpsTests1, sru_bp) { const int bS = 2; const int K = 3; const int N = 4; - std::vector expGradXBuff = {-0.0259303, -0.03869125, -0.0302272, -0.02299165, -0.0259303, -0.03869125, -0.0302272, -0.02299165, -0.0259303, -0.03869125, -0.0302272, -0.02299165, -0.0259303, -0.03869125, -0.0302272, -0.02299165, -0.0259303, -0.03869125, -0.0302272, -0.02299165, -0.0259303, -0.03869125, -0.0302272, -0.02299165}; - std::vector expGradWBuff = {0.42526005,0.42526005,0.42526005, 0.42526005,0.42526005,0.42526005, 0.42526005,0.42526005,0.42526005, -0.5282811 , -0.5282811 , -0.5282811 , -0.5282811 , -0.5282811 , -0.5282811 , -0.5282811 , -0.5282811 , -0.5282811 , -0.15967215, -0.15967215, -0.15967215, -0.15967215, -0.15967215, -0.15967215, -0.15967215, -0.15967215, -0.15967215, 0.42526005,0.42526005,0.42526005, 0.42526005,0.42526005,0.42526005, 0.42526005,0.42526005,0.42526005, -0.5282811 , -0.5282811 , -0.5282811 , -0.5282811 , -0.5282811 , -0.5282811 , -0.5282811 , -0.5282811 , -0.5282811 , -0.15967215, -0.15967215, -0.15967215, -0.15967215, -0.15967215, -0.15967215, -0.15967215, -0.15967215, -0.15967215}; - std::vector expGradBBuff = {-0.7043748, -0.7043748, -0.7043748, -0.2128962, -0.2128962, -0.2128962}; - std::vector expGradInitBuff = {1.1421, 1.1421, 1.1421, 1.1421, 1.1421, 1.1421}; - std::vector stateBuff = {0.847983, 0.874549, 0.896109, 0.913715, 0.847983, 0.874549, 0.896109, 0.913715, 0.847983, 0.874549, 0.896109, 0.913715, 0.847983, 0.874549, 0.896109, 0.913715, 0.847983, 0.874549, 0.896109, 0.913715, 0.847983, 0.874549, 0.896109, 0.913715}; + std::vector expGradXBuff = { -0.0259303, -0.03869125, -0.0302272, -0.02299165, -0.0259303, -0.03869125, -0.0302272, -0.02299165, -0.0259303, -0.03869125, -0.0302272, -0.02299165, -0.0259303, -0.03869125, -0.0302272, -0.02299165, -0.0259303, -0.03869125, -0.0302272, -0.02299165, -0.0259303, -0.03869125, -0.0302272, -0.02299165 }; + std::vector expGradWBuff = { 0.42526005,0.42526005,0.42526005, 0.42526005,0.42526005,0.42526005, 0.42526005,0.42526005,0.42526005, -0.5282811 , -0.5282811 , -0.5282811 , -0.5282811 , -0.5282811 , -0.5282811 , -0.5282811 , -0.5282811 , -0.5282811 , -0.15967215, -0.15967215, -0.15967215, -0.15967215, -0.15967215, -0.15967215, -0.15967215, -0.15967215, -0.15967215, 0.42526005,0.42526005,0.42526005, 0.42526005,0.42526005,0.42526005, 0.42526005,0.42526005,0.42526005, -0.5282811 , -0.5282811 , -0.5282811 , -0.5282811 , -0.5282811 , -0.5282811 , -0.5282811 , -0.5282811 , -0.5282811 , -0.15967215, -0.15967215, -0.15967215, -0.15967215, -0.15967215, -0.15967215, -0.15967215, -0.15967215, -0.15967215 }; + std::vector expGradBBuff = { -0.7043748, -0.7043748, -0.7043748, -0.2128962, -0.2128962, -0.2128962 }; + std::vector expGradInitBuff = { 1.1421, 1.1421, 1.1421, 1.1421, 1.1421, 1.1421 }; + std::vector stateBuff = { 0.847983, 0.874549, 0.896109, 0.913715, 0.847983, 0.874549, 0.896109, 0.913715, 0.847983, 0.874549, 0.896109, 0.913715, 0.847983, 0.874549, 0.896109, 0.913715, 0.847983, 0.874549, 0.896109, 0.913715, 0.847983, 0.874549, 0.896109, 0.913715 }; - auto input = NDArrayFactory::create('c', {bS,K,N}); - auto weights = NDArrayFactory::create('c', {3*K,K}); - auto bias = NDArrayFactory::create('c', {1,2*K}); - auto init = NDArrayFactory::create('c', {bS,K}); - auto mask = NDArrayFactory::create('c', {bS,K}); - auto state = NDArrayFactory::create('c', {bS,K,N}, stateBuff); - auto inGradCt = NDArrayFactory::create('c', {bS,K}); - auto inGradH = NDArrayFactory::create('c', {bS,K,N}); + auto input = NDArrayFactory::create('c', { bS,K,N }); + auto weights = NDArrayFactory::create('c', { 3 * K,K }); + auto bias = NDArrayFactory::create('c', { 1,2 * K }); + auto init = NDArrayFactory::create('c', { bS,K }); + auto mask = NDArrayFactory::create('c', { bS,K }); + auto state = NDArrayFactory::create('c', { bS,K,N }, stateBuff); + auto inGradCt = NDArrayFactory::create('c', { bS,K }); + auto inGradH = NDArrayFactory::create('c', { bS,K,N }); - auto expGradX = NDArrayFactory::create('c', {bS,K,N}, expGradXBuff); - auto expGradW = NDArrayFactory::create('c', {bS,3*K,K}, expGradWBuff); - auto expGradB = NDArrayFactory::create('c', {1,2*K}, expGradBBuff); - auto expGradInit = NDArrayFactory::create('c', {bS,K}, expGradInitBuff); + auto expGradX = NDArrayFactory::create('c', { bS,K,N }, expGradXBuff); + auto expGradW = NDArrayFactory::create('c', { bS,3 * K,K }, expGradWBuff); + auto expGradB = NDArrayFactory::create('c', { 1,2 * K }, expGradBBuff); + auto expGradInit = NDArrayFactory::create('c', { bS,K }, expGradInitBuff); input.assign(1.5); weights.assign(0.5); - bias.assign(0.3) ; + bias.assign(0.3); mask.assign(1.); init.assign(1.); inGradCt.assign(0.5); inGradH.assign(0.5); sd::ops::sru_bp bp; - auto resultsBP = bp.evaluate({&input, &weights, &bias, &init, &state, &inGradCt, &inGradH, &mask}, {}, {}); + auto resultsBP = bp.evaluate({ &input, &weights, &bias, &init, &state, &inGradCt, &inGradH, &mask }, {}, {}); ASSERT_TRUE(resultsBP->size() == 4); - auto gradX = resultsBP->at(0); - auto gradW = resultsBP->at(1); - auto gradB = resultsBP->at(2); + auto gradX = resultsBP->at(0); + auto gradW = resultsBP->at(1); + auto gradB = resultsBP->at(2); auto gradInit = resultsBP->at(3); // expGradX.printBuffer("Exp GRAD"); // gradX->printBuffer("Res GRAD"); - ASSERT_TRUE(expGradX.equalsTo(gradX,1e-4)); + ASSERT_TRUE(expGradX.equalsTo(gradX, 1e-4)); ASSERT_TRUE(expGradW.equalsTo(gradW)); ASSERT_TRUE(expGradB.equalsTo(gradB)); ASSERT_TRUE(expGradInit.equalsTo(gradInit)); @@ -2448,22 +2448,22 @@ TEST_F(DeclarableOpsTests1, sru_bi_1) { const int K = 3; const int N = 4; - NDArray input('c', {N,bS,2*K}, sd::DataType::DOUBLE); - NDArray weights('c', {2*K,6*K}, sd::DataType::DOUBLE); - NDArray bias('c', {4*K}, sd::DataType::DOUBLE); - NDArray init('c', {bS,2*K}, sd::DataType::DOUBLE); - NDArray mask('c', {bS,2*K}, sd::DataType::DOUBLE); - NDArray expState('c', {N,bS,2*K}, {1.02857, 1.02857, 1.02857, 1.11288, 1.11288, 1.11288, 1.02857, 1.02857, 1.02857, 1.11288, 1.11288, 1.11288, 1.0569, 1.0569, 1.0569, 1.08501, 1.08501, 1.08501, 1.0569, 1.0569, 1.0569, 1.08501, 1.08501, 1.08501, 1.08501, 1.08501, 1.08501, 1.0569, 1.0569, 1.0569, 1.08501, 1.08501, 1.08501, 1.0569, 1.0569, 1.0569, 1.11288, 1.11288, 1.11288, 1.02857, 1.02857, 1.02857, 1.11288, 1.11288, 1.11288, 1.02857, 1.02857, 1.02857}); - NDArray expOut('c', {N,bS,2*K}, {0.779265, 0.779265, 0.779265, 0.810752, 0.810752, 0.810752, 0.779265, 0.779265, 0.779265, 0.810752, 0.810752, 0.810752, 0.790317, 0.790317, 0.790317, 0.800804, 0.800804, 0.800804, 0.790317, 0.790317, 0.790317, 0.800804, 0.800804, 0.800804, 0.800804, 0.800804, 0.800804, 0.790317, 0.790317, 0.790317, 0.800804, 0.800804, 0.800804, 0.790317, 0.790317, 0.790317, 0.810752, 0.810752, 0.810752, 0.779265, 0.779265, 0.779265, 0.810752, 0.810752, 0.810752, 0.779265, 0.779265, 0.779265}); + NDArray input('c', { N,bS,2 * K }, sd::DataType::DOUBLE); + NDArray weights('c', { 2 * K,6 * K }, sd::DataType::DOUBLE); + NDArray bias('c', { 4 * K }, sd::DataType::DOUBLE); + NDArray init('c', { bS,2 * K }, sd::DataType::DOUBLE); + NDArray mask('c', { bS,2 * K }, sd::DataType::DOUBLE); + NDArray expState('c', { N,bS,2 * K }, { 1.02857, 1.02857, 1.02857, 1.11288, 1.11288, 1.11288, 1.02857, 1.02857, 1.02857, 1.11288, 1.11288, 1.11288, 1.0569, 1.0569, 1.0569, 1.08501, 1.08501, 1.08501, 1.0569, 1.0569, 1.0569, 1.08501, 1.08501, 1.08501, 1.08501, 1.08501, 1.08501, 1.0569, 1.0569, 1.0569, 1.08501, 1.08501, 1.08501, 1.0569, 1.0569, 1.0569, 1.11288, 1.11288, 1.11288, 1.02857, 1.02857, 1.02857, 1.11288, 1.11288, 1.11288, 1.02857, 1.02857, 1.02857 }); + NDArray expOut('c', { N,bS,2 * K }, { 0.779265, 0.779265, 0.779265, 0.810752, 0.810752, 0.810752, 0.779265, 0.779265, 0.779265, 0.810752, 0.810752, 0.810752, 0.790317, 0.790317, 0.790317, 0.800804, 0.800804, 0.800804, 0.790317, 0.790317, 0.790317, 0.800804, 0.800804, 0.800804, 0.800804, 0.800804, 0.800804, 0.790317, 0.790317, 0.790317, 0.800804, 0.800804, 0.800804, 0.790317, 0.790317, 0.790317, 0.810752, 0.810752, 0.810752, 0.779265, 0.779265, 0.779265, 0.810752, 0.810752, 0.810752, 0.779265, 0.779265, 0.779265 }); input.assign(1.5); weights.assign(0.5); - bias.assign(0.3) ; + bias.assign(0.3); init.assign(1.); mask.assign(1.); sd::ops::sru_bi op; - auto results = op.evaluate({&input, &weights, &bias, &init, &mask}, {}, {}); + auto results = op.evaluate({ &input, &weights, &bias, &init, &mask }, {}, {}); ASSERT_TRUE(results->size() == 2); auto output = results->at(0); @@ -2482,44 +2482,44 @@ TEST_F(DeclarableOpsTests1, sru_bi_bp_1) { const int bS = 2; const int K = 3; const int N = 3; - std::vector expGradXBuff = {0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129}; - std::vector expGradInitBuff = {1.05121, 1.05121, 1.05121, 1.02676, 1.02676, 1.02676, 1.05121, 1.05121, 1.05121, 1.02676, 1.02676, 1.02676}; - std::vector expGradWBuff = {0.02595354,-0.090096 ,-0.00882456,0.02595354,-0.090096 ,-0.0088245, 0.02595354,-0.090096 ,-0.00882456,0.01651665,-0.0559437,-0.0084390, 0.01651665,-0.0559437,-0.00843906,0.01651665,-0.0559437,-0.00843906, 0.02595354,-0.090096 ,-0.00882456,0.02595354,-0.090096 ,-0.0088245, 0.02595354,-0.090096 ,-0.00882456,0.01651665,-0.0559437,-0.0084390, 0.01651665,-0.0559437,-0.00843906,0.01651665,-0.0559437,-0.00843906, 0.02595354,-0.090096 ,-0.00882456,0.02595354,-0.090096 ,-0.0088245, 0.02595354,-0.090096 ,-0.00882456,0.01651665,-0.0559437,-0.0084390, 0.01651665,-0.0559437,-0.00843906,0.01651665,-0.0559437,-0.00843906, 0.02595354,-0.090096 ,-0.00882456,0.02595354,-0.090096 ,-0.0088245, 0.02595354,-0.090096 ,-0.00882456,0.01651665,-0.0559437,-0.0084390, 0.01651665,-0.0559437,-0.00843906,0.01651665,-0.0559437,-0.00843906, 0.02595354,-0.090096 ,-0.00882456,0.02595354,-0.090096 ,-0.0088245, 0.02595354,-0.090096 ,-0.00882456,0.01651665,-0.0559437,-0.0084390, 0.01651665,-0.0559437,-0.00843906,0.01651665,-0.0559437,-0.00843906, 0.02595354,-0.090096 ,-0.00882456,0.02595354,-0.090096 ,-0.0088245, 0.02595354,-0.090096 ,-0.00882456,0.01651665,-0.0559437,-0.0084390, 0.01651665,-0.0559437,-0.00843906,0.01651665,-0.0559437,-0.00843906, 0.02124567,-0.0731508,-0.00868926,0.02124567,-0.0731508,-0.0086892, 0.02124567,-0.0731508,-0.00868926,0.02084955,-0.0712011,-0.0085608, 0.02084955,-0.0712011,-0.00856086,0.02084955,-0.0712011,-0.00856086, 0.02124567,-0.0731508,-0.00868926,0.02124567,-0.0731508,-0.0086892, 0.02124567,-0.0731508,-0.00868926,0.02084955,-0.0712011,-0.0085608, 0.02084955,-0.0712011,-0.00856086,0.02084955,-0.0712011,-0.00856086, 0.02124567,-0.0731508,-0.00868926,0.02124567,-0.0731508,-0.0086892, 0.02124567,-0.0731508,-0.00868926,0.02084955,-0.0712011,-0.0085608, 0.02084955,-0.0712011,-0.00856086,0.02084955,-0.0712011,-0.00856086, 0.02124567,-0.0731508,-0.00868926,0.02124567,-0.0731508,-0.0086892, 0.02124567,-0.0731508,-0.00868926,0.02084955,-0.0712011,-0.0085608, 0.02084955,-0.0712011,-0.00856086,0.02084955,-0.0712011,-0.00856086, 0.02124567,-0.0731508,-0.00868926,0.02124567,-0.0731508,-0.0086892, 0.02124567,-0.0731508,-0.00868926,0.02084955,-0.0712011,-0.0085608, 0.02084955,-0.0712011,-0.00856086,0.02084955,-0.0712011,-0.00856086, 0.02124567,-0.0731508,-0.00868926,0.02124567,-0.0731508,-0.0086892, 0.02124567,-0.0731508,-0.00868926,0.02084955,-0.0712011,-0.0085608, 0.02084955,-0.0712011,-0.00856086,0.02084955,-0.0712011,-0.00856086, 0.01671156,-0.0570699,-0.00856086,0.01671156,-0.0570699,-0.0085608, 0.01671156,-0.0570699,-0.00856086,0.02534988,-0.0880002,-0.0086892, 0.02534988,-0.0880002,-0.00868926,0.02534988,-0.0880002,-0.00868926, 0.01671156,-0.0570699,-0.00856086,0.01671156,-0.0570699,-0.0085608, 0.01671156,-0.0570699,-0.00856086,0.02534988,-0.0880002,-0.0086892, 0.02534988,-0.0880002,-0.00868926,0.02534988,-0.0880002,-0.00868926, 0.01671156,-0.0570699,-0.00856086,0.01671156,-0.0570699,-0.0085608, 0.01671156,-0.0570699,-0.00856086,0.02534988,-0.0880002,-0.0086892, 0.02534988,-0.0880002,-0.00868926,0.02534988,-0.0880002,-0.00868926, 0.01671156,-0.0570699,-0.00856086,0.01671156,-0.0570699,-0.0085608, 0.01671156,-0.0570699,-0.00856086,0.02534988,-0.0880002,-0.0086892, 0.02534988,-0.0880002,-0.00868926,0.02534988,-0.0880002,-0.00868926, 0.01671156,-0.0570699,-0.00856086,0.01671156,-0.0570699,-0.0085608, 0.01671156,-0.0570699,-0.00856086,0.02534988,-0.0880002,-0.0086892, 0.02534988,-0.0880002,-0.00868926,0.02534988,-0.0880002,-0.00868926, 0.01671156,-0.0570699,-0.00856086,0.01671156,-0.0570699,-0.0085608, 0.01671156,-0.0570699,-0.00856086,0.02534988,-0.0880002,-0.0086892, 0.02534988,-0.0880002,-0.00868926,0.02534988,-0.0880002,-0.00868926}; - std::vector expGradBBuff = {-0.0734389, -0.0734389, -0.0734389, -0.0717151, -0.0717151, -0.0717151, -0.0734389, -0.0734389, -0.0734389, -0.0717151, -0.0717151, -0.0717151, -0.00869156, -0.00869156, -0.00869156, -0.00856306, -0.00856306, -0.00856306, -0.00869156, -0.00869156, -0.00869156, -0.00856306, -0.00856306, -0.00856306}; - std::vector stateBuff = {1.028569, 1.028569, 1.028569, 1.112884, 1.112884, 1.112884, 1.028569, 1.028569, 1.028569, 1.112884,1.112884, 1.112884, 1.056905, 1.056905, 1.056905, 1.085009, 1.085009, 1.085009, 1.056905, 1.056905,1.056905, 1.085009, 1.085009, 1.085009, 1.085009, 1.085009, 1.085009, 1.056905, 1.056905, 1.056905,1.085009, 1.085009, 1.085009, 1.056905, 1.056905, 1.056905}; + std::vector expGradXBuff = { 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129, 0.00408129 }; + std::vector expGradInitBuff = { 1.05121, 1.05121, 1.05121, 1.02676, 1.02676, 1.02676, 1.05121, 1.05121, 1.05121, 1.02676, 1.02676, 1.02676 }; + std::vector expGradWBuff = { 0.02595354,-0.090096 ,-0.00882456,0.02595354,-0.090096 ,-0.0088245, 0.02595354,-0.090096 ,-0.00882456,0.01651665,-0.0559437,-0.0084390, 0.01651665,-0.0559437,-0.00843906,0.01651665,-0.0559437,-0.00843906, 0.02595354,-0.090096 ,-0.00882456,0.02595354,-0.090096 ,-0.0088245, 0.02595354,-0.090096 ,-0.00882456,0.01651665,-0.0559437,-0.0084390, 0.01651665,-0.0559437,-0.00843906,0.01651665,-0.0559437,-0.00843906, 0.02595354,-0.090096 ,-0.00882456,0.02595354,-0.090096 ,-0.0088245, 0.02595354,-0.090096 ,-0.00882456,0.01651665,-0.0559437,-0.0084390, 0.01651665,-0.0559437,-0.00843906,0.01651665,-0.0559437,-0.00843906, 0.02595354,-0.090096 ,-0.00882456,0.02595354,-0.090096 ,-0.0088245, 0.02595354,-0.090096 ,-0.00882456,0.01651665,-0.0559437,-0.0084390, 0.01651665,-0.0559437,-0.00843906,0.01651665,-0.0559437,-0.00843906, 0.02595354,-0.090096 ,-0.00882456,0.02595354,-0.090096 ,-0.0088245, 0.02595354,-0.090096 ,-0.00882456,0.01651665,-0.0559437,-0.0084390, 0.01651665,-0.0559437,-0.00843906,0.01651665,-0.0559437,-0.00843906, 0.02595354,-0.090096 ,-0.00882456,0.02595354,-0.090096 ,-0.0088245, 0.02595354,-0.090096 ,-0.00882456,0.01651665,-0.0559437,-0.0084390, 0.01651665,-0.0559437,-0.00843906,0.01651665,-0.0559437,-0.00843906, 0.02124567,-0.0731508,-0.00868926,0.02124567,-0.0731508,-0.0086892, 0.02124567,-0.0731508,-0.00868926,0.02084955,-0.0712011,-0.0085608, 0.02084955,-0.0712011,-0.00856086,0.02084955,-0.0712011,-0.00856086, 0.02124567,-0.0731508,-0.00868926,0.02124567,-0.0731508,-0.0086892, 0.02124567,-0.0731508,-0.00868926,0.02084955,-0.0712011,-0.0085608, 0.02084955,-0.0712011,-0.00856086,0.02084955,-0.0712011,-0.00856086, 0.02124567,-0.0731508,-0.00868926,0.02124567,-0.0731508,-0.0086892, 0.02124567,-0.0731508,-0.00868926,0.02084955,-0.0712011,-0.0085608, 0.02084955,-0.0712011,-0.00856086,0.02084955,-0.0712011,-0.00856086, 0.02124567,-0.0731508,-0.00868926,0.02124567,-0.0731508,-0.0086892, 0.02124567,-0.0731508,-0.00868926,0.02084955,-0.0712011,-0.0085608, 0.02084955,-0.0712011,-0.00856086,0.02084955,-0.0712011,-0.00856086, 0.02124567,-0.0731508,-0.00868926,0.02124567,-0.0731508,-0.0086892, 0.02124567,-0.0731508,-0.00868926,0.02084955,-0.0712011,-0.0085608, 0.02084955,-0.0712011,-0.00856086,0.02084955,-0.0712011,-0.00856086, 0.02124567,-0.0731508,-0.00868926,0.02124567,-0.0731508,-0.0086892, 0.02124567,-0.0731508,-0.00868926,0.02084955,-0.0712011,-0.0085608, 0.02084955,-0.0712011,-0.00856086,0.02084955,-0.0712011,-0.00856086, 0.01671156,-0.0570699,-0.00856086,0.01671156,-0.0570699,-0.0085608, 0.01671156,-0.0570699,-0.00856086,0.02534988,-0.0880002,-0.0086892, 0.02534988,-0.0880002,-0.00868926,0.02534988,-0.0880002,-0.00868926, 0.01671156,-0.0570699,-0.00856086,0.01671156,-0.0570699,-0.0085608, 0.01671156,-0.0570699,-0.00856086,0.02534988,-0.0880002,-0.0086892, 0.02534988,-0.0880002,-0.00868926,0.02534988,-0.0880002,-0.00868926, 0.01671156,-0.0570699,-0.00856086,0.01671156,-0.0570699,-0.0085608, 0.01671156,-0.0570699,-0.00856086,0.02534988,-0.0880002,-0.0086892, 0.02534988,-0.0880002,-0.00868926,0.02534988,-0.0880002,-0.00868926, 0.01671156,-0.0570699,-0.00856086,0.01671156,-0.0570699,-0.0085608, 0.01671156,-0.0570699,-0.00856086,0.02534988,-0.0880002,-0.0086892, 0.02534988,-0.0880002,-0.00868926,0.02534988,-0.0880002,-0.00868926, 0.01671156,-0.0570699,-0.00856086,0.01671156,-0.0570699,-0.0085608, 0.01671156,-0.0570699,-0.00856086,0.02534988,-0.0880002,-0.0086892, 0.02534988,-0.0880002,-0.00868926,0.02534988,-0.0880002,-0.00868926, 0.01671156,-0.0570699,-0.00856086,0.01671156,-0.0570699,-0.0085608, 0.01671156,-0.0570699,-0.00856086,0.02534988,-0.0880002,-0.0086892, 0.02534988,-0.0880002,-0.00868926,0.02534988,-0.0880002,-0.00868926 }; + std::vector expGradBBuff = { -0.0734389, -0.0734389, -0.0734389, -0.0717151, -0.0717151, -0.0717151, -0.0734389, -0.0734389, -0.0734389, -0.0717151, -0.0717151, -0.0717151, -0.00869156, -0.00869156, -0.00869156, -0.00856306, -0.00856306, -0.00856306, -0.00869156, -0.00869156, -0.00869156, -0.00856306, -0.00856306, -0.00856306 }; + std::vector stateBuff = { 1.028569, 1.028569, 1.028569, 1.112884, 1.112884, 1.112884, 1.028569, 1.028569, 1.028569, 1.112884,1.112884, 1.112884, 1.056905, 1.056905, 1.056905, 1.085009, 1.085009, 1.085009, 1.056905, 1.056905,1.056905, 1.085009, 1.085009, 1.085009, 1.085009, 1.085009, 1.085009, 1.056905, 1.056905, 1.056905,1.085009, 1.085009, 1.085009, 1.056905, 1.056905, 1.056905 }; - auto input = NDArrayFactory::create('c', {N,bS,2*K}); - auto weights = NDArrayFactory::create('c', {2*K,6*K}); - auto bias = NDArrayFactory::create('c', {4*K}); - auto init = NDArrayFactory::create('c', {bS,2*K}); - auto mask = NDArrayFactory::create('c', {bS,2*K}); - NDArray state('c', {N,bS,2*K}, stateBuff); - auto inGradCt = NDArrayFactory::create('c', {bS,2*K}); - auto inGradH = NDArrayFactory::create('c', {N,bS,2*K}); + auto input = NDArrayFactory::create('c', { N,bS,2 * K }); + auto weights = NDArrayFactory::create('c', { 2 * K,6 * K }); + auto bias = NDArrayFactory::create('c', { 4 * K }); + auto init = NDArrayFactory::create('c', { bS,2 * K }); + auto mask = NDArrayFactory::create('c', { bS,2 * K }); + NDArray state('c', { N,bS,2 * K }, stateBuff); + auto inGradCt = NDArrayFactory::create('c', { bS,2 * K }); + auto inGradH = NDArrayFactory::create('c', { N,bS,2 * K }); - NDArray gradBias('c', {bS,4*K}, expGradBBuff); + NDArray gradBias('c', { bS,4 * K }, expGradBBuff); - NDArray expGradX('c', {N,bS,2*K}, expGradXBuff); - NDArray expGradW('c', {N,2*K,6*K}, expGradWBuff); - auto expGradB = NDArrayFactory::create('c', {4*K}); - gradBias.reduceAlongDimension(reduce::Sum, expGradB, {0}); // [bS, 4K] -> [4K] - NDArray expGradInit('c', {bS,2*K}, expGradInitBuff); + NDArray expGradX('c', { N,bS,2 * K }, expGradXBuff); + NDArray expGradW('c', { N,2 * K,6 * K }, expGradWBuff); + auto expGradB = NDArrayFactory::create('c', { 4 * K }); + gradBias.reduceAlongDimension(reduce::Sum, expGradB, { 0 }); // [bS, 4K] -> [4K] + NDArray expGradInit('c', { bS,2 * K }, expGradInitBuff); input.assign(1.5); weights.assign(0.5); - bias.assign(0.3) ; + bias.assign(0.3); mask.assign(1.); init.assign(1.); inGradCt.assign(0.5); inGradH.assign(0.5); sd::ops::sru_bi_bp bp; - auto resultsBP = bp.evaluate({&input, &weights, &bias, &init, &state, &inGradCt, &inGradH, &mask}, {}, {}); + auto resultsBP = bp.evaluate({ &input, &weights, &bias, &init, &state, &inGradCt, &inGradH, &mask }, {}, {}); ASSERT_TRUE(resultsBP->size() == 4); - auto gradX = resultsBP->at(0); - auto gradW = resultsBP->at(1); - auto gradB = resultsBP->at(2); + auto gradX = resultsBP->at(0); + auto gradW = resultsBP->at(1); + auto gradB = resultsBP->at(2); auto gradInit = resultsBP->at(3); ASSERT_TRUE(expGradX.equalsTo(gradX)); @@ -2531,14 +2531,14 @@ TEST_F(DeclarableOpsTests1, sru_bi_bp_1) { } TEST_F(DeclarableOpsTests1, ArgMax1) { - auto x = NDArrayFactory::create('c', {3, 5}); + auto x = NDArrayFactory::create('c', { 3, 5 }); x.linspace(1); - auto exp = NDArrayFactory::create('c', {3}); + auto exp = NDArrayFactory::create('c', { 3 }); exp.assign(4); sd::ops::argmax op; - auto result = op.evaluate({&x}, {}, {1}); + auto result = op.evaluate({ &x }, {}, { 1 }); ASSERT_EQ(ND4J_STATUS_OK, result->status()); @@ -2552,14 +2552,14 @@ TEST_F(DeclarableOpsTests1, ArgMax1) { TEST_F(DeclarableOpsTests1, ArgMax2) { - auto x = NDArrayFactory::create('c', {3, 5}); + auto x = NDArrayFactory::create('c', { 3, 5 }); x.linspace(1); - auto exp = NDArrayFactory::create('c', {5}); + auto exp = NDArrayFactory::create('c', { 5 }); exp.assign(2); sd::ops::argmax op; - auto result = op.evaluate({&x}, {}, {0}); + auto result = op.evaluate({ &x }, {}, { 0 }); ASSERT_EQ(ND4J_STATUS_OK, result->status()); @@ -2573,15 +2573,15 @@ TEST_F(DeclarableOpsTests1, ArgMax2) { TEST_F(DeclarableOpsTests1, ArgMax3) { - auto x = NDArrayFactory::create('c', {3, 5}); - auto dim = NDArrayFactory::create('c', {1, 1}, {0.}); + auto x = NDArrayFactory::create('c', { 3, 5 }); + auto dim = NDArrayFactory::create('c', { 1, 1 }, { 0. }); x.linspace(1); - auto exp = NDArrayFactory::create('c', {5}); + auto exp = NDArrayFactory::create('c', { 5 }); exp.assign(2); sd::ops::argmax op; - auto result = op.evaluate({&x, &dim}, {}, {}); + auto result = op.evaluate({ &x, &dim }, {}, {}); ASSERT_EQ(ND4J_STATUS_OK, result->status()); @@ -2594,15 +2594,15 @@ TEST_F(DeclarableOpsTests1, ArgMax3) { } TEST_F(DeclarableOpsTests1, ArgMax4) { - auto x = NDArrayFactory::create('c', {3, 5}); - auto dim = NDArrayFactory::create('c', {1, 1}, {1}); + auto x = NDArrayFactory::create('c', { 3, 5 }); + auto dim = NDArrayFactory::create('c', { 1, 1 }, { 1 }); x.linspace(1); - auto exp = NDArrayFactory::create('c', {3}); + auto exp = NDArrayFactory::create('c', { 3 }); exp.assign(4); sd::ops::argmax op; - auto result = op.evaluate({&x, &dim}, {}, {}); + auto result = op.evaluate({ &x, &dim }, {}, {}); ASSERT_EQ(ND4J_STATUS_OK, result->status()); @@ -2616,15 +2616,15 @@ TEST_F(DeclarableOpsTests1, ArgMax4) { TEST_F(DeclarableOpsTests1, ArgMax5) { - auto x = NDArrayFactory::create('c', {3, 5}); - auto dim = NDArrayFactory::create('c', {1, 2}, {0, 1}); + auto x = NDArrayFactory::create('c', { 3, 5 }); + auto dim = NDArrayFactory::create('c', { 1, 2 }, { 0, 1 }); x.linspace(1); auto exp = NDArrayFactory::create(14); sd::ops::argmax op; - auto result = op.evaluate({&x, &dim}, {}, {}); + auto result = op.evaluate({ &x, &dim }, {}, {}); ASSERT_EQ(ND4J_STATUS_OK, result->status()); @@ -2637,19 +2637,19 @@ TEST_F(DeclarableOpsTests1, ArgMax5) { } TEST_F(DeclarableOpsTests1, ArgMax6) { - auto x = NDArrayFactory::create('c', {3, 4, 5}); + auto x = NDArrayFactory::create('c', { 3, 4, 5 }); auto dim = NDArrayFactory::create(-1.f); x.linspace(1); sd::ops::argmax op; - auto expected = op.evaluate({&x}, {}, {2}); + auto expected = op.evaluate({ &x }, {}, { 2 }); ASSERT_EQ(Status::OK(), expected->status()); auto exp = expected->at(0); - auto result = op.evaluate({&x, &dim}, {}, {}); + auto result = op.evaluate({ &x, &dim }, {}, {}); ASSERT_EQ(Status::OK(), result->status()); auto z = result->at(0); @@ -2662,15 +2662,15 @@ TEST_F(DeclarableOpsTests1, ArgMax6) { TEST_F(DeclarableOpsTests1, ArgMin1) { - auto x = NDArrayFactory::create('c', {3, 5}); + auto x = NDArrayFactory::create('c', { 3, 5 }); x.linspace(1); -// auto exp('c', {3, 1}); - auto exp = NDArrayFactory::create('c', {3}); + // auto exp('c', {3, 1}); + auto exp = NDArrayFactory::create('c', { 3 }); exp.assign(0.0f); sd::ops::argmin op; - auto result = op.evaluate({&x}, {}, {1}); + auto result = op.evaluate({ &x }, {}, { 1 }); ASSERT_EQ(ND4J_STATUS_OK, result->status()); @@ -2684,16 +2684,16 @@ TEST_F(DeclarableOpsTests1, ArgMin1) { TEST_F(DeclarableOpsTests1, SquareTests1) { - auto x = NDArrayFactory::create('c', {3, 5}); + auto x = NDArrayFactory::create('c', { 3, 5 }); x.linspace(1); - auto exp = NDArrayFactory::create('c', {3, 5}); + auto exp = NDArrayFactory::create('c', { 3, 5 }); exp.linspace(1); exp *= exp; sd::ops::square op; - auto result = op.evaluate({&x}, {}, {}); + auto result = op.evaluate({ &x }, {}, {}); ASSERT_EQ(ND4J_STATUS_OK, result->status()); auto z = result->at(0); @@ -2705,13 +2705,13 @@ TEST_F(DeclarableOpsTests1, SquareTests1) { TEST_F(DeclarableOpsTests1, OneHotTests_1) { - auto indices = NDArrayFactory::create('c', {1, 4}, {0.0f, 2.0f, -1.0f, 1.0f}); + auto indices = NDArrayFactory::create('c', { 1, 4 }, { 0.0f, 2.0f, -1.0f, 1.0f }); - auto exp = NDArrayFactory::create('c', {1, 4, 3}, {1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f}); + auto exp = NDArrayFactory::create('c', { 1, 4, 3 }, { 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f }); sd::ops::onehot op; - auto result = op.evaluate({&indices}, {1.0f, 0.0f}, {-1, 3}); + auto result = op.evaluate({ &indices }, { 1.0f, 0.0f }, { -1, 3 }); ASSERT_EQ(ND4J_STATUS_OK, result->status()); auto z = result->at(0); @@ -2724,12 +2724,12 @@ TEST_F(DeclarableOpsTests1, OneHotTests_1) { } TEST_F(DeclarableOpsTests1, OneHotTests_2) { - auto indices = NDArrayFactory::create('c', {2, 2}, {0.f, 2.f, 1.f, -1.f}); + auto indices = NDArrayFactory::create('c', { 2, 2 }, { 0.f, 2.f, 1.f, -1.f }); - auto exp = NDArrayFactory::create('c', {2, 2, 3}, {1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f}); + auto exp = NDArrayFactory::create('c', { 2, 2, 3 }, { 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f }); sd::ops::onehot op; - auto result = op.evaluate({&indices}, {1.0f, 0.0f}, {-1, 3}); + auto result = op.evaluate({ &indices }, { 1.0f, 0.0f }, { -1, 3 }); ASSERT_EQ(ND4J_STATUS_OK, result->status()); @@ -2743,13 +2743,13 @@ TEST_F(DeclarableOpsTests1, OneHotTests_2) { } TEST_F(DeclarableOpsTests1, OneHotTests_3) { - auto indices = NDArrayFactory::create('c', {4}, {0.0f, 2.0f, -1.0f, 1.0f}); + auto indices = NDArrayFactory::create('c', { 4 }, { 0.0f, 2.0f, -1.0f, 1.0f }); - auto exp = NDArrayFactory::create('c', {4, 3}, {1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f}); + auto exp = NDArrayFactory::create('c', { 4, 3 }, { 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f }); sd::ops::onehot op; - auto result = op.evaluate({&indices}, {1.0f, 0.0f}, {-1, 3}); + auto result = op.evaluate({ &indices }, { 1.0f, 0.0f }, { -1, 3 }); ASSERT_EQ(ND4J_STATUS_OK, result->status()); auto z = result->at(0); @@ -2763,14 +2763,14 @@ TEST_F(DeclarableOpsTests1, OneHotTests_3) { } TEST_F(DeclarableOpsTests1, OneHotTests_4) { - auto indices = NDArrayFactory::create('c', {4}, {0.0f, 2.0f, -1.0f, 1.0f}); + auto indices = NDArrayFactory::create('c', { 4 }, { 0.0f, 2.0f, -1.0f, 1.0f }); auto depth = NDArrayFactory::create(3.0f); - auto exp = NDArrayFactory::create('c', {4, 3}, {1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f}); + auto exp = NDArrayFactory::create('c', { 4, 3 }, { 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f }); sd::ops::onehot op; - auto result = op.evaluate({&indices, &depth}, {1.0f, 0.0f}, {}); + auto result = op.evaluate({ &indices, &depth }, { 1.0f, 0.0f }, {}); ASSERT_EQ(ND4J_STATUS_OK, result->status()); auto z = result->at(0); @@ -2782,16 +2782,16 @@ TEST_F(DeclarableOpsTests1, OneHotTests_4) { } TEST_F(DeclarableOpsTests1, OneHotTests_5) { - auto indices = NDArrayFactory::create('c', {4}, {0.0f, 2.0f, -1.0f, 1.0f}); + auto indices = NDArrayFactory::create('c', { 4 }, { 0.0f, 2.0f, -1.0f, 1.0f }); auto depth = NDArrayFactory::create(3.0f); auto on = NDArrayFactory::create(1.0f); auto off = NDArrayFactory::create(0.0f); - auto exp = NDArrayFactory::create('c', {4, 3}, {1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f}); + auto exp = NDArrayFactory::create('c', { 4, 3 }, { 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f }); sd::ops::onehot op; - auto result = op.evaluate({&indices, &depth, &on, &off}, {}, {}); + auto result = op.evaluate({ &indices, &depth, &on, &off }, {}, {}); ASSERT_EQ(ND4J_STATUS_OK, result->status()); auto z = result->at(0); @@ -2803,11 +2803,11 @@ TEST_F(DeclarableOpsTests1, OneHotTests_5) { } TEST_F(DeclarableOpsTests1, OneHotTests_6) { - auto indices = NDArrayFactory::create('c', {3}, {0.f, 1.f, 2.f}); - auto e = NDArrayFactory::create('c', {3, 3}, {1.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 1.f}); + auto indices = NDArrayFactory::create('c', { 3 }, { 0.f, 1.f, 2.f }); + auto e = NDArrayFactory::create('c', { 3, 3 }, { 1.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 1.f }); sd::ops::onehot op; - auto result = op.evaluate({&indices}, {1.0, 0.0}, {0, 3}); + auto result = op.evaluate({ &indices }, { 1.0, 0.0 }, { 0, 3 }); auto z = result->at(0); ASSERT_EQ(e, *z); @@ -2816,11 +2816,11 @@ TEST_F(DeclarableOpsTests1, OneHotTests_6) { } TEST_F(DeclarableOpsTests1, OneHotTests_7) { - auto indices = NDArrayFactory::create('c', {3}, {0, 1, 2}); - auto e = NDArrayFactory::create('c', {3, 3}, {1., 0., 0., 0., 1., 0., 0., 0., 1.}); + auto indices = NDArrayFactory::create('c', { 3 }, { 0, 1, 2 }); + auto e = NDArrayFactory::create('c', { 3, 3 }, { 1., 0., 0., 0., 1., 0., 0., 0., 1. }); sd::ops::onehot op; - auto result = op.evaluate({&indices}, {1.0, 0.0}, {0, 3}, {}, {sd::DataType::HALF}, false); + auto result = op.evaluate({ &indices }, { 1.0, 0.0 }, { 0, 3 }, {}, { sd::DataType::HALF }, false); auto z = result->at(0); ASSERT_EQ(e, *z); @@ -2829,13 +2829,13 @@ TEST_F(DeclarableOpsTests1, OneHotTests_7) { } TEST_F(DeclarableOpsTests1, FillAs_1) { - auto x = NDArrayFactory::create('c', {2, 2}); + auto x = NDArrayFactory::create('c', { 2, 2 }); x.assign(117); float scalar = 119.f; sd::ops::fill_as op; - auto result = op.evaluate({&x}, {scalar}, {}); + auto result = op.evaluate({ &x }, { scalar }, {}); ASSERT_EQ(ND4J_STATUS_OK, result->status()); @@ -2854,12 +2854,12 @@ TEST_F(DeclarableOpsTests1, LRN1) { } TEST_F(DeclarableOpsTests1, Test_Range_Integer_1) { - auto exp = NDArrayFactory::create('c', {4}); + auto exp = NDArrayFactory::create('c', { 4 }); exp.linspace(1); sd::ops::range op; - auto result = op.evaluate({}, {}, {1, 5, 1}); + auto result = op.evaluate({}, {}, { 1, 5, 1 }); ASSERT_EQ(ND4J_STATUS_OK, result->status()); ASSERT_EQ(1, result->size()); @@ -2874,19 +2874,19 @@ TEST_F(DeclarableOpsTests1, Test_Range_Integer_1) { TEST_F(DeclarableOpsTests1, Test_Range_Integer_2) { - auto exp = NDArrayFactory::create('c', {4}); + auto exp = NDArrayFactory::create('c', { 4 }); exp.linspace(1); - auto start = NDArrayFactory::create('c', {1, 1}); - auto stop = NDArrayFactory::create('c', {1, 1}); - auto step = NDArrayFactory::create('c', {1, 1}); + auto start = NDArrayFactory::create('c', { 1, 1 }); + auto stop = NDArrayFactory::create('c', { 1, 1 }); + auto step = NDArrayFactory::create('c', { 1, 1 }); start.p(0, 1.f); stop.p(0, 5.f); step.p(0, 1.f); sd::ops::range op; - auto result = op.evaluate({&start, &stop, &step}, {}, {}); + auto result = op.evaluate({ &start, &stop, &step }, {}, {}); ASSERT_EQ(ND4J_STATUS_OK, result->status()); ASSERT_EQ(1, result->size()); @@ -2901,12 +2901,12 @@ TEST_F(DeclarableOpsTests1, Test_Range_Integer_2) { TEST_F(DeclarableOpsTests1, Test_Range_Integer_3) { - auto exp = NDArrayFactory::create('c', {4}); + auto exp = NDArrayFactory::create('c', { 4 }); exp.linspace(1); sd::ops::range op; - auto result = op.evaluate({}, {1.f, 5.f, 1.f}, {}); + auto result = op.evaluate({}, { 1.f, 5.f, 1.f }, {}); ASSERT_EQ(ND4J_STATUS_OK, result->status()); ASSERT_EQ(1, result->size()); @@ -2921,11 +2921,13 @@ TEST_F(DeclarableOpsTests1, Test_Range_Integer_3) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, softmax_test1) { - auto input = NDArrayFactory::create('c', {3, 3}, {-1, 1, -2, 2, -3, 3, -4, 4, 5}); - auto expOutput = NDArrayFactory::create('c', {3, 3}, {1.14195199e-01, 8.43794734e-01, 4.20100661e-02, 2.68454951e-01, 1.80883523e-03, 7.29736214e-01, 9.02116571e-05, 2.68917160e-01, 7.30992629e-01}); + + NDArray input('c', { 3, 3 }, { -1.f, 1.f, -2.f, 2.f, -3.f, 3.f, -4.f, 4.f, 5.f }, sd::DataType::FLOAT32); + + NDArray expOutput('c', { 3, 3 }, { 1.14195199e-01, 8.43794734e-01, 4.20100661e-02, 2.68454951e-01, 1.80883523e-03, 7.29736214e-01, 9.02116571e-05, 2.68917160e-01, 7.30992629e-01 }, sd::DataType::FLOAT32); sd::ops::softmax op; - auto results = op.evaluate({&input}, {}, {}, {}); + auto results = op.evaluate({ &input }, {}, {}, {}); auto z = results->at(0); ASSERT_EQ(Status::OK(), results->status()); @@ -2937,11 +2939,11 @@ TEST_F(DeclarableOpsTests1, softmax_test1) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, softmax_test2) { - auto input = NDArrayFactory::create('c', {3, 3, 3}, {-1, 1, -2, 2, -3, 3, -4, 4, -5,5 ,-6,6, -7,7, -8,8, -9,9, -10,10, -11,11, -12,12, -13,13, 14}); - auto expOutput = NDArrayFactory::create('c', {3, 3, 3}, {4.73142e-02,4.73847e-02,6.69062e-03, 9.50330e-01,8.67881e-04,9.92976e-01, 2.35563e-03,9.51747e-01,3.33106e-04, 4.74259e-02,2.26032e-06,4.74259e-02, 2.91395e-07,9.99998e-01,3.94360e-08, 9.52574e-01,1.12535e-07,9.52574e-01, 7.58256e-10,4.74259e-02,1.22325e-11, 1.00000e+00,1.32293e-11,1.19203e-01, 3.77513e-11,9.52574e-01,8.80797e-01}); + NDArray input('c', { 3, 3, 3 }, { -1, 1, -2, 2, -3, 3, -4, 4, -5,5 ,-6,6, -7,7, -8,8, -9,9, -10,10, -11,11, -12,12, -13,13, 14 }, sd::DataType::FLOAT32); + NDArray expOutput('c', { 3, 3, 3 }, { 4.73142e-02,4.73847e-02,6.69062e-03, 9.50330e-01,8.67881e-04,9.92976e-01, 2.35563e-03,9.51747e-01,3.33106e-04, 4.74259e-02,2.26032e-06,4.74259e-02, 2.91395e-07,9.99998e-01,3.94360e-08, 9.52574e-01,1.12535e-07,9.52574e-01, 7.58256e-10,4.74259e-02,1.22325e-11, 1.00000e+00,1.32293e-11,1.19203e-01, 3.77513e-11,9.52574e-01,8.80797e-01 }, sd::DataType::FLOAT32); sd::ops::softmax op; - auto results = op.evaluate({&input}, {}, {1}, {}); + auto results = op.evaluate({ &input }, {}, { 1 }, {}); auto z = results->at(0); ASSERT_EQ(Status::OK(), results->status()); @@ -2953,11 +2955,11 @@ TEST_F(DeclarableOpsTests1, softmax_test2) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, softmax_test3) { - auto input = NDArrayFactory::create('c', {3, 3, 3}, {-1, 1, -2, 2, -3, 3, -4, 4, -5,5 ,-6,6, -7,7, -8,8, -9,9, -10,10, -11,11, -12,12, -13,13, 14}); - auto expOutput = NDArrayFactory::create('c', {3, 3, 3}, {2.47262e-03,1.23395e-04,3.35350e-04, 1.23395e-04,4.53979e-05,1.23395e-04, 6.14417e-06,1.23395e-04,5.56530e-09, 9.97527e-01,1.12521e-07,9.99665e-01, 1.52281e-08,9.99955e-01,2.06090e-09, 9.99994e-01,2.78912e-10,6.69285e-03, 3.05146e-07,9.99876e-01,4.13855e-08, 9.99877e-01,5.60254e-09,9.99877e-01, 7.58251e-10,9.99877e-01,9.93307e-01}); + NDArray input('c', { 3, 3, 3 }, { -1, 1, -2, 2, -3, 3, -4, 4, -5,5 ,-6,6, -7,7, -8,8, -9,9, -10,10, -11,11, -12,12, -13,13, 14 }, sd::DataType::FLOAT32); + NDArray expOutput('c', { 3, 3, 3 }, { 2.47262e-03,1.23395e-04,3.35350e-04, 1.23395e-04,4.53979e-05,1.23395e-04, 6.14417e-06,1.23395e-04,5.56530e-09, 9.97527e-01,1.12521e-07,9.99665e-01, 1.52281e-08,9.99955e-01,2.06090e-09, 9.99994e-01,2.78912e-10,6.69285e-03, 3.05146e-07,9.99876e-01,4.13855e-08, 9.99877e-01,5.60254e-09,9.99877e-01, 7.58251e-10,9.99877e-01,9.93307e-01 }, sd::DataType::FLOAT32); sd::ops::softmax op; - auto results = op.evaluate({&input}, {}, {0}, {}); + auto results = op.evaluate({ &input }, {}, { 0 }, {}); auto z = results->at(0); ASSERT_EQ(Status::OK(), results->status()); @@ -2969,11 +2971,11 @@ TEST_F(DeclarableOpsTests1, softmax_test3) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, softmax_test4) { - auto input = NDArrayFactory::create('c', {1, 5}, {-1, 1, -2, 2, 3}); - auto expOutput = NDArrayFactory::create('c', {1, 5}, {0.01198,0.08855,0.00441,0.24072,0.65434}); + NDArray input('c', { 1, 5 }, { -1, 1, -2, 2, 3 }, sd::DataType::FLOAT32); + NDArray expOutput('c', { 1, 5 }, { 0.01198,0.08855,0.00441,0.24072,0.65434 }, sd::DataType::FLOAT32); sd::ops::softmax op; - auto results = op.evaluate({&input}, {}, {1}, {}); + auto results = op.evaluate({ &input }, {}, { 1 }, {}); auto z = results->at(0); ASSERT_EQ(Status::OK(), results->status()); @@ -2985,11 +2987,11 @@ TEST_F(DeclarableOpsTests1, softmax_test4) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, softmax_test5) { - auto input = NDArrayFactory::create('c', {1, 5}, {-1, 1, -2, 2, 3}); - auto expOutput = NDArrayFactory::create('c', {1, 5}, {1,1,1,1,1}); + NDArray input('c', { 1, 5 }, { -1, 1, -2, 2, 3 }, sd::DataType::FLOAT32); + NDArray expOutput('c', { 1, 5 }, { 1,1,1,1,1 }, sd::DataType::FLOAT32); sd::ops::softmax op; - auto results = op.evaluate({&input}, {}, {0}); + auto results = op.evaluate({ &input }, {}, { 0 }); auto z = results->at(0); ASSERT_EQ(Status::OK(), results->status()); @@ -3001,11 +3003,11 @@ TEST_F(DeclarableOpsTests1, softmax_test5) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, softmax_test6) { - auto input = NDArrayFactory::create('c', {5, 1}, {-1, 1, -2, 2, 3}); - auto expOutput = NDArrayFactory::create('c', {5, 1}, {0.01198,0.08855,0.00441,0.24072,0.65434}); + NDArray input('c', { 5, 1 }, { -1, 1, -2, 2, 3 }, sd::DataType::FLOAT32); + NDArray expOutput('c', { 5, 1 }, { 0.01198,0.08855,0.00441,0.24072,0.65434 }, sd::DataType::FLOAT32); sd::ops::softmax op; - auto results = op.evaluate({&input}, {}, {0}, {}); + auto results = op.evaluate({ &input }, {}, { 0 }, {}); auto z = results->at(0); ASSERT_EQ(Status::OK(), results->status()); @@ -3017,11 +3019,11 @@ TEST_F(DeclarableOpsTests1, softmax_test6) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, softmax_test7) { - auto input = NDArrayFactory::create('c', {5, 1}, {-1, 1, -2, 2, 3}); - auto expOutput = NDArrayFactory::create('c', {5, 1}, {1,1,1,1,1}); + NDArray input('c', { 5, 1 }, { -1, 1, -2, 2, 3 }, sd::DataType::FLOAT32); + NDArray expOutput('c', { 5, 1 }, { 1,1,1,1,1 }, sd::DataType::FLOAT32); sd::ops::softmax op; - auto results = op.evaluate({&input}, {}, {1}, {}); + auto results = op.evaluate({ &input }, {}, { 1 }, {}); auto z = results->at(0); ASSERT_EQ(Status::OK(), results->status()); @@ -3033,11 +3035,11 @@ TEST_F(DeclarableOpsTests1, softmax_test7) { ////////////////////////////////////////////////////////////////////// TEST_F(DeclarableOpsTests1, softmax_test8) { - auto input = NDArrayFactory::create('c', {5}, {-1, 1, -2, 2, 3}); - auto expOutput = NDArrayFactory::create('c', {5}, {0.01198,0.08855,0.00441,0.24072,0.65434}); + NDArray input('c', { 5 }, { -1, 1, -2, 2, 3 }, sd::DataType::FLOAT32); + NDArray expOutput('c', { 5 }, { 0.01198,0.08855,0.00441,0.24072,0.65434 }, sd::DataType::FLOAT32); sd::ops::softmax op; - auto results = op.evaluate({&input}, {}, {}, {}); + auto results = op.evaluate({ &input }, {}, {}, {}); auto z = results->at(0); ASSERT_EQ(Status::OK(), results->status()); @@ -3048,11 +3050,75 @@ TEST_F(DeclarableOpsTests1, softmax_test8) { } ////////////////////////////////////////////////////////////////////// -TEST_F(DeclarableOpsTests1, Reverse_1 ) { +TEST_F(DeclarableOpsTests1, softmax_test9) { + NDArray input('c', { 2, 2, 2, 2 }, { -1, 1, -2, 2, -3, 3, -4, 4, -5,5 ,-6,6, -7,7, -8,8 }, sd::DataType::FLOAT32); + NDArray expOutput('c', { 2, 2, 2, 2 }, { 0.731059, 0.268941, 0.268941, 0.731059, 0.731059, 0.268941, 0.268941, 0.731059, 0.731059, 0.268941, 0.268941, 0.731059, 0.731059, 0.268941, 0.268941, 0.731059 }, sd::DataType::FLOAT32); - float inBuff[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24}; - float expBuff[] = {24., 23., 22., 21., 20., 19., 18., 17., 16., 15., 14., 13., 12., 11., 10., 9., 8., 7., 6., 5., 4., 3., 2., 1.}; - Nd4jLong shapeInfo[] = {3, 2, 3, 4, 12, 4, 1, 0, 1, 99}; + sd::ops::softmax op; + auto results = op.evaluate({ &input }, {}, { 2 }, {}); + auto z = results->at(0); + + ASSERT_EQ(Status::OK(), results->status()); + ASSERT_TRUE(expOutput.isSameShape(z)); + ASSERT_TRUE(expOutput.equalsTo(z)); + + delete results; +} +////////////////////////////////////////////////////////////////////// +TEST_F(DeclarableOpsTests1, softmax_test10) { + NDArray input('c', { 2, 2, 2, 2, 2 }, { -1, 1, -2, 2, -3, 3, -4, 4, -5,5 ,-6,6, -7,7, -8,8, -9,9, -10,10, -11,11, -12,12, -13,13, 14, -14, 15, -15, 16,-16 }, sd::DataType::FLOAT32); + NDArray expOutput('c', { 2, 2, 2, 2, 2 }, { 0.119203, 0.880797, 0.017986, 0.982014, 0.002473, 0.997527, 0.000335, 0.999665, 0.000045, 0.999955, 0.000006, 0.999994, 0.000001, 0.999999, 0.000000, 1.000000, 0.000000, 1.000000, 0.000000, 1.000000, 0.000000, 1.000000, 0.000000, 1.000000, 0.000000, 1.000000, 1.000000, 0.000000, 1.000000, 0.000000, 1.000000, 0.00000 }, sd::DataType::FLOAT32); + + sd::ops::softmax op; + auto results = op.evaluate({ &input }, {}, { 4 }, {}); + auto z = results->at(0); + + ASSERT_EQ(Status::OK(), results->status()); + ASSERT_TRUE(expOutput.isSameShape(z)); + ASSERT_TRUE(expOutput.equalsTo(z)); + + delete results; +} +////////////////////////////////////////////////////////////////////// +TEST_F(DeclarableOpsTests1, softmax_test11) { + NDArray input('c', { 2, 2, 2, 2, 2, 2 }, { -1, 1, -2, 2, -3, 3, -4, 4, -5,5 ,-6,6, -7,7, -8,8, -9,9, -10,10, -11,11, -12,12, -13,13, 14, -14, 15, -15, 16,-16, -2.1, 2.1, -2.2, 2.2, -2.3, 2.3, -2.4, 2.4, -2.5,2.5 ,-2.6,2.6, -2.7,2.7, -2.8,2.8, -2.9,2.9, -3.0,3.0, -3.1,3.1, -3.2,3.2, -3.3,3.3, 3.4, -3.4, 3.5, -3.5, 3.6,-3.6 }, sd::DataType::FLOAT32); + NDArray expOutput('c', { 2, 2, 2, 2, 2, 2 }, { 0.731059, 0.268941, 0.268941, 0.731059, 0.731059, 0.268941, 0.268941, 0.731059, 0.731059, 0.268941, 0.268941, 0.731059, 0.731059, 0.268941, 0.268941, 0.731059, 0.731059, 0.268941, 0.268941, 0.731059, 0.731059, 0.268941, 0.268941, 0.731059, 0.000000, 1.000000, 1.000000, 0.000000, 0.268941, 0.731059, 0.731059, 0.268941, 0.524979, 0.475021, 0.475021, 0.524979, 0.524979, 0.475021, 0.475021, 0.524979, 0.524979, 0.475021, 0.475021, 0.524979, 0.524979, 0.475021, 0.475021, 0.524979, 0.524979, 0.475021, 0.475021, 0.524979, 0.524979, 0.475021, 0.475021, 0.524979, 0.001229, 0.998771, 0.998771, 0.001229, 0.475021, 0.524979, 0.524979, 0.475021 }, sd::DataType::FLOAT32); + + sd::ops::softmax op; + auto results = op.evaluate({ &input }, {}, { 4 }, {}); + auto z = results->at(0); + + ASSERT_EQ(Status::OK(), results->status()); + ASSERT_TRUE(expOutput.isSameShape(z)); + ASSERT_TRUE(expOutput.equalsTo(z)); + + delete results; +} + +////////////////////////////////////////////////////////////////////// +TEST_F(DeclarableOpsTests1, softmax_test12) { + NDArray input('f', { 2, 2, 2, 2, 2, 2 }, { -1, 1, -2, 2, -3, 3, -4, 4, -5,5 ,-6,6, -7,7, -8,8, -9,9, -10,10, -11,11, -12,12, -13,13, 14, -14, 15, -15, 16,-16, -2.1, 2.1, -2.2, 2.2, -2.3, 2.3, -2.4, 2.4, -2.5,2.5 ,-2.6,2.6, -2.7,2.7, -2.8,2.8, -2.9,2.9, -3.0,3.0, -3.1,3.1, -3.2,3.2, -3.3,3.3, 3.4, -3.4, 3.5, -3.5, 3.6,-3.6 }, sd::DataType::FLOAT32); + NDArray exp('c', { 2, 2, 2, 2, 2, 2 }, { 0.982014, 0.598688, 0.982014, 0.598688, 0.017986, 0.401312, 0.017986, 0.401312, 0.982014, 0.598688, 0.000000, 0.001359, 0.017986, 0.401312, 1.000000, 0.998641, 0.982014, 0.598688, 0.000000, 0.001659, 0.017986, 0.401312, 1.000000, 0.998341, 0.982014, 0.598688, 0.000000, 0.001113, 0.017986, 0.401312, 1.000000, 0.998887, 0.017986, 0.401312, 0.017986, 0.401312, 0.982014, 0.598688, 0.982014, 0.598688, 0.017986, 0.401312, 1.000000, 0.998641, 0.982014, 0.598688, 0.000000, 0.001359, 0.017986, 0.401312, 1.000000, 0.998341, 0.982014, 0.598688, 0.000000, 0.001659, 0.017986, 0.401312, 1.000000, 0.998887, 0.982014, 0.598688, 0.000000, 0.001113 }, sd::DataType::FLOAT32); + + auto expOutput = NDArray('f', { 2, 2, 2, 2, 2, 2 }, sd::DataType::FLOAT32); + expOutput.assign(exp); + + sd::ops::softmax op; + auto results = op.evaluate({ &input }, {}, { 3 }, {}); + auto z = results->at(0); + + ASSERT_EQ(Status::OK(), results->status()); + ASSERT_TRUE(expOutput.isSameShape(z)); + ASSERT_TRUE(expOutput.equalsTo(z)); + + delete results; +} +////////////////////////////////////////////////////////////////////// +TEST_F(DeclarableOpsTests1, Reverse_1) { + + float inBuff[] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24 }; + float expBuff[] = { 24., 23., 22., 21., 20., 19., 18., 17., 16., 15., 14., 13., 12., 11., 10., 9., 8., 7., 6., 5., 4., 3., 2., 1. }; + Nd4jLong shapeInfo[] = { 3, 2, 3, 4, 12, 4, 1, 0, 1, 99 }; ArrayOptions::setDataType(shapeInfo, sd::DataType::FLOAT32); NDArray input(inBuff, shapeInfo); @@ -3060,7 +3126,7 @@ TEST_F(DeclarableOpsTests1, Reverse_1 ) { NDArray output(shapeInfo); sd::ops::reverse op; - auto results = op.evaluate({&input}, {}, {0,1,2}); + auto results = op.evaluate({ &input }, {}, { 0,1,2 }); ASSERT_EQ(ND4J_STATUS_OK, results->status()); @@ -3073,11 +3139,11 @@ TEST_F(DeclarableOpsTests1, Reverse_1 ) { } ////////////////////////////////////////////////////////////////////// -TEST_F(DeclarableOpsTests1, Reverse_2 ) { +TEST_F(DeclarableOpsTests1, Reverse_2) { - float inBuff[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24}; - float expBuff[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24}; - Nd4jLong shapeInfo[] = {3, 2, 3, 4, 12, 4, 1, 0, 1, 99}; + float inBuff[] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24 }; + float expBuff[] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24 }; + Nd4jLong shapeInfo[] = { 3, 2, 3, 4, 12, 4, 1, 0, 1, 99 }; ArrayOptions::setDataType(shapeInfo, sd::DataType::FLOAT32); NDArray input(inBuff, shapeInfo); @@ -3085,7 +3151,7 @@ TEST_F(DeclarableOpsTests1, Reverse_2 ) { NDArray output(shapeInfo); sd::ops::reverse op; - auto results = op.evaluate({&input}, {}, {}, {}, {}, true); + auto results = op.evaluate({ &input }, {}, {}, {}, {}, true); ASSERT_EQ(ND4J_STATUS_OK, results->status()); @@ -3098,11 +3164,11 @@ TEST_F(DeclarableOpsTests1, Reverse_2 ) { } ////////////////////////////////////////////////////////////////////// -TEST_F(DeclarableOpsTests1, Reverse_3 ) { +TEST_F(DeclarableOpsTests1, Reverse_3) { - float inBuff[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24}; - float expBuff[] = {12., 11., 10., 9., 8., 7., 6., 5., 4., 3., 2., 1., 24., 23., 22., 21., 20., 19., 18., 17., 16., 15., 14., 13.}; - Nd4jLong shapeInfo[] = {3, 2, 3, 4, 12, 4, 1, 0, 1, 99}; + float inBuff[] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24 }; + float expBuff[] = { 12., 11., 10., 9., 8., 7., 6., 5., 4., 3., 2., 1., 24., 23., 22., 21., 20., 19., 18., 17., 16., 15., 14., 13. }; + Nd4jLong shapeInfo[] = { 3, 2, 3, 4, 12, 4, 1, 0, 1, 99 }; ArrayOptions::setDataType(shapeInfo, sd::DataType::FLOAT32); NDArray input(inBuff, shapeInfo); @@ -3110,7 +3176,7 @@ TEST_F(DeclarableOpsTests1, Reverse_3 ) { NDArray output(shapeInfo); sd::ops::reverse op; - auto results = op.evaluate({&input}, {}, {1,2}); + auto results = op.evaluate({ &input }, {}, { 1,2 }); ASSERT_EQ(ND4J_STATUS_OK, results->status()); @@ -3124,11 +3190,11 @@ TEST_F(DeclarableOpsTests1, Reverse_3 ) { } ////////////////////////////////////////////////////////////////////// -TEST_F(DeclarableOpsTests1, Reverse_4 ) { +TEST_F(DeclarableOpsTests1, Reverse_4) { - float inBuff[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24}; - float expBuff[] = {16,15,14,13,20,19,18,17,24,23,22,21,4,3,2,1,8,7,6,5,12,11,10,9,}; - Nd4jLong shapeInfo[] = {3, 2, 3, 4, 12, 4, 1, 0, 1, 99}; + float inBuff[] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24 }; + float expBuff[] = { 16,15,14,13,20,19,18,17,24,23,22,21,4,3,2,1,8,7,6,5,12,11,10,9, }; + Nd4jLong shapeInfo[] = { 3, 2, 3, 4, 12, 4, 1, 0, 1, 99 }; ArrayOptions::setDataType(shapeInfo, sd::DataType::FLOAT32); NDArray input(inBuff, shapeInfo); @@ -3136,7 +3202,7 @@ TEST_F(DeclarableOpsTests1, Reverse_4 ) { NDArray output(shapeInfo); sd::ops::reverse op; - auto results = op.evaluate({&input}, {}, {0,2}); + auto results = op.evaluate({ &input }, {}, { 0,2 }); ASSERT_EQ(ND4J_STATUS_OK, results->status()); @@ -3150,11 +3216,11 @@ TEST_F(DeclarableOpsTests1, Reverse_4 ) { } ////////////////////////////////////////////////////////////////////// -TEST_F(DeclarableOpsTests1, Reverse_5 ) { +TEST_F(DeclarableOpsTests1, Reverse_5) { - float inBuff[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24}; - float expBuff[] = {21., 22., 23., 24., 17., 18., 19., 20., 13., 14., 15., 16., 9., 10., 11., 12., 5., 6., 7., 8., 1., 2., 3., 4.}; - Nd4jLong shapeInfo[] = {3, 2, 3, 4, 12, 4, 1, 0, 1, 99}; + float inBuff[] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24 }; + float expBuff[] = { 21., 22., 23., 24., 17., 18., 19., 20., 13., 14., 15., 16., 9., 10., 11., 12., 5., 6., 7., 8., 1., 2., 3., 4. }; + Nd4jLong shapeInfo[] = { 3, 2, 3, 4, 12, 4, 1, 0, 1, 99 }; ArrayOptions::setDataType(shapeInfo, sd::DataType::FLOAT32); NDArray input(inBuff, shapeInfo); @@ -3162,7 +3228,7 @@ TEST_F(DeclarableOpsTests1, Reverse_5 ) { NDArray output(shapeInfo); sd::ops::reverse op; - auto results = op.evaluate({&input}, {}, {0,1}); + auto results = op.evaluate({ &input }, {}, { 0,1 }); ASSERT_EQ(ND4J_STATUS_OK, results->status()); @@ -3175,11 +3241,11 @@ TEST_F(DeclarableOpsTests1, Reverse_5 ) { } //////////////////////////////////////////////////////////////////// -TEST_F(DeclarableOpsTests1, Reverse_6 ) { +TEST_F(DeclarableOpsTests1, Reverse_6) { - float inBuff[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24}; - float expBuff[] = {4., 3., 2., 1., 8., 7., 6., 5., 12., 11., 10., 9., 16., 15., 14., 13., 20., 19., 18., 17., 24., 23., 22., 21.}; - Nd4jLong shapeInfo[] = {3, 2, 3, 4, 12, 4, 1, 0, 1, 99}; + float inBuff[] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24 }; + float expBuff[] = { 4., 3., 2., 1., 8., 7., 6., 5., 12., 11., 10., 9., 16., 15., 14., 13., 20., 19., 18., 17., 24., 23., 22., 21. }; + Nd4jLong shapeInfo[] = { 3, 2, 3, 4, 12, 4, 1, 0, 1, 99 }; ArrayOptions::setDataType(shapeInfo, sd::DataType::FLOAT32); NDArray input(inBuff, shapeInfo); @@ -3187,7 +3253,7 @@ TEST_F(DeclarableOpsTests1, Reverse_6 ) { NDArray output(shapeInfo); sd::ops::reverse op; - auto results = op.evaluate({&input}, {}, {2}, {}, {}, true); + auto results = op.evaluate({ &input }, {}, { 2 }, {}, {}, true); ASSERT_EQ(ND4J_STATUS_OK, results->status()); @@ -3202,11 +3268,11 @@ TEST_F(DeclarableOpsTests1, Reverse_6 ) { //////////////////////////////////////////////////////////////////// -TEST_F(DeclarableOpsTests1, Reverse_7 ) { +TEST_F(DeclarableOpsTests1, Reverse_7) { - float inBuff[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24}; - float expBuff[] = {9., 10., 11., 12., 5., 6., 7., 8., 1., 2., 3., 4., 21., 22., 23., 24., 17., 18., 19., 20., 13., 14., 15., 16.}; - Nd4jLong shapeInfo[] = {3, 2, 3, 4, 12, 4, 1, 0, 1, 99}; + float inBuff[] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24 }; + float expBuff[] = { 9., 10., 11., 12., 5., 6., 7., 8., 1., 2., 3., 4., 21., 22., 23., 24., 17., 18., 19., 20., 13., 14., 15., 16. }; + Nd4jLong shapeInfo[] = { 3, 2, 3, 4, 12, 4, 1, 0, 1, 99 }; ArrayOptions::setDataType(shapeInfo, sd::DataType::FLOAT32); NDArray input(inBuff, shapeInfo); @@ -3214,7 +3280,7 @@ TEST_F(DeclarableOpsTests1, Reverse_7 ) { NDArray output(shapeInfo); sd::ops::reverse op; - auto results = op.evaluate({&input}, {}, {1}); + auto results = op.evaluate({ &input }, {}, { 1 }); ASSERT_EQ(ND4J_STATUS_OK, results->status()); @@ -3231,11 +3297,11 @@ TEST_F(DeclarableOpsTests1, Reverse_7 ) { ////////////////////////////////////////////////////////////////////// -TEST_F(DeclarableOpsTests1, Reverse_8 ) { +TEST_F(DeclarableOpsTests1, Reverse_8) { - float inBuff[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24}; - float expBuff[] = {12., 11., 10., 9., 8., 7., 6., 5., 4., 3., 2., 1., 24., 23., 22., 21., 20., 19., 18., 17., 16., 15., 14., 13.}; - Nd4jLong shapeInfo[] = {3, 2, 3, 4, 12, 4, 1, 0, 1, 99}; + float inBuff[] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24 }; + float expBuff[] = { 12., 11., 10., 9., 8., 7., 6., 5., 4., 3., 2., 1., 24., 23., 22., 21., 20., 19., 18., 17., 16., 15., 14., 13. }; + Nd4jLong shapeInfo[] = { 3, 2, 3, 4, 12, 4, 1, 0, 1, 99 }; ArrayOptions::setDataType(shapeInfo, sd::DataType::FLOAT32); NDArray input(inBuff, shapeInfo); @@ -3243,7 +3309,7 @@ TEST_F(DeclarableOpsTests1, Reverse_8 ) { NDArray output(shapeInfo); sd::ops::reverse op; - auto results = op.evaluate({&input}, {}, {2,1}); + auto results = op.evaluate({ &input }, {}, { 2,1 }); ASSERT_EQ(ND4J_STATUS_OK, results->status()); @@ -3257,11 +3323,11 @@ TEST_F(DeclarableOpsTests1, Reverse_8 ) { } //////////////////////////////////////////////////////////////////// -TEST_F(DeclarableOpsTests1, Reverse_9 ) { +TEST_F(DeclarableOpsTests1, Reverse_9) { - float inBuff[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24}; - float expBuff[] = {13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.}; - Nd4jLong shapeInfo[] = {3, 2, 3, 4, 12, 4, 1, 0, 1, 99}; + float inBuff[] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24 }; + float expBuff[] = { 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12. }; + Nd4jLong shapeInfo[] = { 3, 2, 3, 4, 12, 4, 1, 0, 1, 99 }; ArrayOptions::setDataType(shapeInfo, sd::DataType::FLOAT32); NDArray input(inBuff, shapeInfo); @@ -3269,7 +3335,7 @@ TEST_F(DeclarableOpsTests1, Reverse_9 ) { NDArray output(shapeInfo); sd::ops::reverse op; - auto results = op.evaluate({&input}, {}, {0}); + auto results = op.evaluate({ &input }, {}, { 0 }); ASSERT_EQ(ND4J_STATUS_OK, results->status()); @@ -3281,13 +3347,13 @@ TEST_F(DeclarableOpsTests1, Reverse_9 ) { delete results; } -TEST_F(DeclarableOpsTests1, Reverse_10 ) { - auto x = NDArrayFactory::create('c', {4, 3}, {1.5375735, 0.1592365, 0.09966054, 0.677872, 1.144433, -1.0355669, 0.48456487, -0.67863184, 0.85020787, 0.13950661, 0.20998026, -1.1660044}); - auto i = NDArrayFactory::create('c', {1}, {-1}); - auto e = NDArrayFactory::create('c', {4, 3}, {0.09966054, 0.1592365, 1.5375735, -1.0355669, 1.144433, 0.677872,0.85020787, -0.67863184, 0.48456487, -1.1660044, 0.20998026, 0.13950661}); +TEST_F(DeclarableOpsTests1, Reverse_10) { + auto x = NDArrayFactory::create('c', { 4, 3 }, { 1.5375735, 0.1592365, 0.09966054, 0.677872, 1.144433, -1.0355669, 0.48456487, -0.67863184, 0.85020787, 0.13950661, 0.20998026, -1.1660044 }); + auto i = NDArrayFactory::create('c', { 1 }, { -1 }); + auto e = NDArrayFactory::create('c', { 4, 3 }, { 0.09966054, 0.1592365, 1.5375735, -1.0355669, 1.144433, 0.677872,0.85020787, -0.67863184, 0.48456487, -1.1660044, 0.20998026, 0.13950661 }); sd::ops::reverse op; - auto result = op.evaluate({&x, &i}, {}, {}, {}); + auto result = op.evaluate({ &x, &i }, {}, {}, {}); auto z = result->at(0); @@ -3298,17 +3364,17 @@ TEST_F(DeclarableOpsTests1, Reverse_10 ) { } ////////////////////////////////////////////////////////////////////// -TEST_F(DeclarableOpsTests1, Reverse_11 ) { +TEST_F(DeclarableOpsTests1, Reverse_11) { - auto input = NDArrayFactory::create('c', {2,3,4}); - auto expected = NDArrayFactory::create('c', {2,3,4}, {24.f, 23.f, 22.f, 21.f, 20.f, 19.f, 18.f, 17.f, 16.f, + auto input = NDArrayFactory::create('c', { 2,3,4 }); + auto expected = NDArrayFactory::create('c', { 2,3,4 }, { 24.f, 23.f, 22.f, 21.f, 20.f, 19.f, 18.f, 17.f, 16.f, 15.f, 14.f, 13.f, 12.f, 11.f, 10.f, 9.f, 8.f, 7.f, - 6.f, 5.f, 4.f, 3.f, 2.f, 1.f}); + 6.f, 5.f, 4.f, 3.f, 2.f, 1.f }); input.linspace(1); sd::ops::reverse op; - auto results = op.evaluate({&input}, {}, {0, 1, 2}); + auto results = op.evaluate({ &input }, {}, { 0, 1, 2 }); ASSERT_EQ(ND4J_STATUS_OK, results->status()); @@ -3321,15 +3387,15 @@ TEST_F(DeclarableOpsTests1, Reverse_11 ) { } ////////////////////////////////////////////////////////////////////// -TEST_F(DeclarableOpsTests1, Reverse_12 ) { +TEST_F(DeclarableOpsTests1, Reverse_12) { - auto input = NDArrayFactory::create({0.f, 1.f, 2.f, 3.f, 4.f}); - auto expected = NDArrayFactory::create({4.f, 3.f, 2.f, 1.f, 0.f}); + auto input = NDArrayFactory::create({ 0.f, 1.f, 2.f, 3.f, 4.f }); + auto expected = NDArrayFactory::create({ 4.f, 3.f, 2.f, 1.f, 0.f }); //input.linspace(1); sd::ops::reverse op; - auto results = op.evaluate({&input}, {}, {0}); + auto results = op.evaluate({ &input }, {}, { 0 }); ASSERT_EQ(ND4J_STATUS_OK, results->status()); @@ -3343,15 +3409,15 @@ TEST_F(DeclarableOpsTests1, Reverse_12 ) { } ////////////////////////////////////////////////////////////////////// -TEST_F(DeclarableOpsTests1, Reverse_13 ) { +TEST_F(DeclarableOpsTests1, Reverse_13) { - auto input = NDArrayFactory::create({0.f, 1.f, 2.f, 3.f, 4.f}); - auto expected = NDArrayFactory::create({4.f, 3.f, 2.f, 1.f, 0.f}); + auto input = NDArrayFactory::create({ 0.f, 1.f, 2.f, 3.f, 4.f }); + auto expected = NDArrayFactory::create({ 4.f, 3.f, 2.f, 1.f, 0.f }); //input.linspace(1); sd::ops::reverse op; - auto results = op.evaluate({&input}, {}, {-1}); + auto results = op.evaluate({ &input }, {}, { -1 }); ASSERT_EQ(ND4J_STATUS_OK, results->status()); @@ -3364,15 +3430,15 @@ TEST_F(DeclarableOpsTests1, Reverse_13 ) { } ////////////////////////////////////////////////////////////////////// -TEST_F(DeclarableOpsTests1, Reverse_14 ) { +TEST_F(DeclarableOpsTests1, Reverse_14) { - auto input = NDArrayFactory::create({0.f, 1.f, 2.f, 3.f, 4.f}); - auto expected = NDArrayFactory::create({0.f, 1.f, 2.f, 3.f, 4.f}); + auto input = NDArrayFactory::create({ 0.f, 1.f, 2.f, 3.f, 4.f }); + auto expected = NDArrayFactory::create({ 0.f, 1.f, 2.f, 3.f, 4.f }); //input.linspace(1); sd::ops::reverse op; - auto results = op.evaluate({&input}, {}, {}, {}); + auto results = op.evaluate({ &input }, {}, {}, {}); ASSERT_EQ(ND4J_STATUS_OK, results->status()); @@ -3385,12 +3451,12 @@ TEST_F(DeclarableOpsTests1, Reverse_14 ) { } TEST_F(DeclarableOpsTests1, Test_Expose_1) { - auto input0 = NDArrayFactory::create('c', {2, 3}, {1, 2, 3, 6, 5, 4}); - auto input1 = NDArrayFactory::create('c', {2, 3}, {3, 2, 1, 4, 5, 6}); + auto input0 = NDArrayFactory::create('c', { 2, 3 }, { 1, 2, 3, 6, 5, 4 }); + auto input1 = NDArrayFactory::create('c', { 2, 3 }, { 3, 2, 1, 4, 5, 6 }); sd::ops::expose op; - auto result = op.evaluate({&input0, &input1}); + auto result = op.evaluate({ &input0, &input1 }); ASSERT_EQ(ND4J_STATUS_OK, result->status()); @@ -3433,7 +3499,6 @@ TEST_F(DeclarableOpsTests1, Test_Expose_2) { } TEST_F(DeclarableOpsTests1, Test_Release) { - auto x = NDArrayFactory::create('c', {8, 8}); + auto x = NDArrayFactory::create('c', { 8, 8 }); // x.printShapeInfo("x shape"); } - diff --git a/libnd4j/tests_cpu/layers_tests/MklDnnTests.cpp b/libnd4j/tests_cpu/layers_tests/MklDnnTests.cpp index a9b0d92e6..e7efb3cb5 100644 --- a/libnd4j/tests_cpu/layers_tests/MklDnnTests.cpp +++ b/libnd4j/tests_cpu/layers_tests/MklDnnTests.cpp @@ -69,6 +69,8 @@ TEST_F(MklDnnTests, helpers_includer) { sd::ops::platforms::PLATFORM_matmul_ENGINE_CPU matmul; - printer({&conv2d, &conv2d_bp, &conv3d, &conv3d_bp, &avgpool2d, &avgpool2d_bp, &maxpool2d, &maxpool2d_bp, &avgpool3d, &avgpool3d_bp, &maxpool3d, &maxpool3d_bp, &lrn, &batchnorm, &matmul}); + sd::ops::platforms::PLATFORM_softmax_ENGINE_CPU softmax; + + printer({&conv2d, &conv2d_bp, &conv3d, &conv3d_bp, &avgpool2d, &avgpool2d_bp, &maxpool2d, &maxpool2d_bp, &avgpool3d, &avgpool3d_bp, &maxpool3d, &maxpool3d_bp, &lrn, &batchnorm, &matmul, &softmax }); #endif } \ No newline at end of file