From c86300373e9118d54a4a43def98536b7b3600e25 Mon Sep 17 00:00:00 2001 From: AbdelRauf Date: Tue, 23 Feb 2021 21:17:56 +0100 Subject: [PATCH 1/4] sparseUtil test: fix memory leak in the test code implemented by user/contributor Signed-off-by: AbdelRauf --- libnd4j/tests_cpu/layers_tests/SparseUtilsTest.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libnd4j/tests_cpu/layers_tests/SparseUtilsTest.cpp b/libnd4j/tests_cpu/layers_tests/SparseUtilsTest.cpp index f83e61eb3..8afef3701 100644 --- a/libnd4j/tests_cpu/layers_tests/SparseUtilsTest.cpp +++ b/libnd4j/tests_cpu/layers_tests/SparseUtilsTest.cpp @@ -227,6 +227,7 @@ TEST_F(SparseUtilsTest, RavelIndices_Test) { } shape[2] = 30; + delete[] shapeInfoBuffer; shapeInfoBuffer = shape::shapeBuffer(rank, sd::DataType::INT64, shape); try { From 426e28640a3d3e88130645abb5a54138f8fe1bdb Mon Sep 17 00:00:00 2001 From: AbdelRauf Date: Tue, 23 Feb 2021 21:16:07 +0100 Subject: [PATCH 2/4] fusedbatchnorm: fix type mismatching error Signed-off-by: AbdelRauf --- .../include/ops/declarable/generic/nn/fusedBatchNorm.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libnd4j/include/ops/declarable/generic/nn/fusedBatchNorm.cpp b/libnd4j/include/ops/declarable/generic/nn/fusedBatchNorm.cpp index ccdf60f40..d9e48d1c1 100644 --- a/libnd4j/include/ops/declarable/generic/nn/fusedBatchNorm.cpp +++ b/libnd4j/include/ops/declarable/generic/nn/fusedBatchNorm.cpp @@ -89,8 +89,8 @@ namespace sd { else { //REQUIRE_TRUE(block.width() == 3, 0, "CUSTOM_OP fused_batch_norm: when isTraining=true then number of input arrays must be equal to 3, but got %i instead !", block.width()); std::vector shape = {iD}; - mean = NDArrayFactory::create_(scale->ordering(), shape, sd::DataType::FLOAT32, block.launchContext()); - variance = NDArrayFactory::create_(scale->ordering(), shape, sd::DataType::FLOAT32, block.launchContext()); + mean = NDArrayFactory::create_(scale->ordering(), shape, scale->dataType(), block.launchContext()); + variance = NDArrayFactory::create_(scale->ordering(), shape, scale->dataType(), block.launchContext()); } @@ -104,7 +104,7 @@ namespace sd { const int restSize = x->lengthOf() / iD; - auto xAffected = NDArrayFactory::create(x->ordering(), {restSize, iD}, sd::DataType::FLOAT32, block.launchContext()); + auto xAffected = NDArrayFactory::create(x->ordering(), {restSize, iD}, mean->dataType(), block.launchContext()); xAffected.assign(xCast); const int restSizeMinusOne = (restSize > 1) ? (restSize - 1) : 1; From 375efff2e490fa42dba4d75503242db2c5e828eb Mon Sep 17 00:00:00 2001 From: AbdelRauf Date: Tue, 23 Feb 2021 21:12:16 +0100 Subject: [PATCH 3/4] uniform: change description. -2 (or values below -1 ) means unknown number of arguments or no arguments at all. Signed-off-by: AbdelRauf --- libnd4j/include/ops/declarable/generic/random/uniform.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libnd4j/include/ops/declarable/generic/random/uniform.cpp b/libnd4j/include/ops/declarable/generic/random/uniform.cpp index cb7f146da..7743255d1 100644 --- a/libnd4j/include/ops/declarable/generic/random/uniform.cpp +++ b/libnd4j/include/ops/declarable/generic/random/uniform.cpp @@ -40,7 +40,7 @@ namespace sd { * TArgs[0] - min for rng * TArgs[1] - max for rng */ - CUSTOM_OP_IMPL(randomuniform, -1, 1, true, 0, -1) { + CUSTOM_OP_IMPL(randomuniform, -1, 1, true, 0, -2) { // uniform distribution auto rng = block.randomGenerator(); auto dtype = DataType::FLOAT32; From 1550cebcd514befa819093196e790c1d814c6581 Mon Sep 17 00:00:00 2001 From: AbdelRauf Date: Tue, 23 Feb 2021 21:11:30 +0100 Subject: [PATCH 4/4] reshape: fix optional order case that failed tests Signed-off-by: AbdelRauf --- .../ops/declarable/generic/shape/reshape.cpp | 39 ++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/libnd4j/include/ops/declarable/generic/shape/reshape.cpp b/libnd4j/include/ops/declarable/generic/shape/reshape.cpp index bca23c1cc..2932bc455 100644 --- a/libnd4j/include/ops/declarable/generic/shape/reshape.cpp +++ b/libnd4j/include/ops/declarable/generic/shape/reshape.cpp @@ -61,6 +61,29 @@ DECLARE_TYPES(reshape) { ->setSameMode(true); } + +bool handleOptionalOrder(std::vector &reshapeArgs, char &ordering){ + if(reshapeArgs.size()>0){ + //check if any optional negative ordering value is passed + auto optional = reshapeArgs[0]; + if(optional < 0){ + optional = abs(optional); + //check if passed option is allowed. (-1 -> dynamic shape) + // in that case we will return back + if(optional == 1 ) return true; + //in this case it should obey allowed orderings + if (optional != 'c' && optional != 'f' ) return false; + reshapeArgs.erase( reshapeArgs.begin()); + //ordering was passed and ok. let's assign + ordering = optional; + } + + } + //skipped + return true; +} + + DECLARE_SHAPE_FN(reshape) { const auto x = INPUT_VARIABLE(0); @@ -78,26 +101,14 @@ DECLARE_SHAPE_FN(reshape) { */ if (block.width() == 1) { reshapeArgs = *block.getIArguments(); - if (!reshapeArgs.empty()) { - char potentialOrdering = (char)-reshapeArgs[0]; - orderNew = potentialOrdering; - if (potentialOrdering != 'c' && potentialOrdering != 'f') { + if(!handleOptionalOrder(reshapeArgs, orderNew)){ throw std::runtime_error( "reshape:: Value passed in must be -99 or -102 for the ordering if " "an int array is present. -99 represents c ordering and -102 " "represents f ordering. This number is negative for the long array " "case to flag the difference between an ordering and a dimension " "being specified."); - } - - nd4j_debug("Reshape Ordering is %c int ordering is %d\n", orderNew, - -reshapeArgs[0]); - - if (orderNew == 'c' || orderNew == 'f') - reshapeArgs.erase( - reshapeArgs - .begin()); // remove first element being order in this case - } + }; } else { reshapeArgs = INPUT_VARIABLE(1)->getBufferAsVector(); if (block.numI() > 0) {