From 3c7cd2397c15601794ce3ddd0cdd4dcd32258ccc Mon Sep 17 00:00:00 2001 From: shugeo Date: Thu, 15 Aug 2019 15:28:19 +0300 Subject: [PATCH] Eliminated memory leaks and dropped waste prints with tests. (#117) --- .../generic/datatypes/to_double.cpp | 2 +- .../generic/datatypes/to_float16.cpp | 2 +- .../generic/datatypes/to_float32.cpp | 2 +- .../declarable/generic/datatypes/to_int32.cpp | 2 +- .../declarable/generic/datatypes/to_int64.cpp | 2 +- .../generic/datatypes/to_uint32.cpp | 2 +- .../generic/datatypes/to_uint64.cpp | 2 +- .../generic/transforms/merge_max_idx.cpp | 2 +- .../layers_tests/DeclarableOpsTests6.cpp | 28 +++++++++---------- .../layers_tests/ListOperationsTests.cpp | 1 + libnd4j/tests_cpu/layers_tests/RNGTests.cpp | 4 +-- 11 files changed, 25 insertions(+), 24 deletions(-) diff --git a/libnd4j/include/ops/declarable/generic/datatypes/to_double.cpp b/libnd4j/include/ops/declarable/generic/datatypes/to_double.cpp index 2cee857fa..9d3e5aaed 100644 --- a/libnd4j/include/ops/declarable/generic/datatypes/to_double.cpp +++ b/libnd4j/include/ops/declarable/generic/datatypes/to_double.cpp @@ -45,7 +45,7 @@ namespace nd4j { DECLARE_SHAPE_FN(to_double) { auto outShape = ShapeBuilders::copyShapeInfoAndType(inputShape->at(0), DataType::DOUBLE, true, block.workspace()); - return SHAPELIST(outShape); + return SHAPELIST(CONSTANT(outShape)); } } diff --git a/libnd4j/include/ops/declarable/generic/datatypes/to_float16.cpp b/libnd4j/include/ops/declarable/generic/datatypes/to_float16.cpp index d3e2f3cd0..d6818bec4 100644 --- a/libnd4j/include/ops/declarable/generic/datatypes/to_float16.cpp +++ b/libnd4j/include/ops/declarable/generic/datatypes/to_float16.cpp @@ -45,7 +45,7 @@ namespace nd4j { DECLARE_SHAPE_FN(to_float16) { auto outShape = ShapeBuilders::copyShapeInfoAndType(inputShape->at(0), DataType::HALF, true, block.workspace()); - return SHAPELIST(outShape); + return SHAPELIST(CONSTANT(outShape)); } } diff --git a/libnd4j/include/ops/declarable/generic/datatypes/to_float32.cpp b/libnd4j/include/ops/declarable/generic/datatypes/to_float32.cpp index c558f4d78..4ca46bb82 100644 --- a/libnd4j/include/ops/declarable/generic/datatypes/to_float32.cpp +++ b/libnd4j/include/ops/declarable/generic/datatypes/to_float32.cpp @@ -45,7 +45,7 @@ namespace nd4j { DECLARE_SHAPE_FN(to_float32) { auto outShape = ShapeBuilders::copyShapeInfoAndType(inputShape->at(0), DataType::FLOAT32, true, block.workspace()); - return SHAPELIST(outShape); + return SHAPELIST(CONSTANT(outShape)); } } diff --git a/libnd4j/include/ops/declarable/generic/datatypes/to_int32.cpp b/libnd4j/include/ops/declarable/generic/datatypes/to_int32.cpp index 960aab483..897868be5 100644 --- a/libnd4j/include/ops/declarable/generic/datatypes/to_int32.cpp +++ b/libnd4j/include/ops/declarable/generic/datatypes/to_int32.cpp @@ -44,7 +44,7 @@ namespace nd4j { } DECLARE_SHAPE_FN(to_int32) { auto outShape = ShapeBuilders::copyShapeInfoAndType(inputShape->at(0), DataType::INT32, true, block.workspace()); - return SHAPELIST(outShape); + return SHAPELIST(CONSTANT(outShape)); } } diff --git a/libnd4j/include/ops/declarable/generic/datatypes/to_int64.cpp b/libnd4j/include/ops/declarable/generic/datatypes/to_int64.cpp index d5721b266..6fa728254 100644 --- a/libnd4j/include/ops/declarable/generic/datatypes/to_int64.cpp +++ b/libnd4j/include/ops/declarable/generic/datatypes/to_int64.cpp @@ -44,7 +44,7 @@ namespace nd4j { } DECLARE_SHAPE_FN(to_int64) { auto outShape = ShapeBuilders::copyShapeInfoAndType(inputShape->at(0), DataType::INT64, true, block.workspace()); - return SHAPELIST(outShape); + return SHAPELIST(CONSTANT(outShape)); } } diff --git a/libnd4j/include/ops/declarable/generic/datatypes/to_uint32.cpp b/libnd4j/include/ops/declarable/generic/datatypes/to_uint32.cpp index b0833dd25..6805855f1 100644 --- a/libnd4j/include/ops/declarable/generic/datatypes/to_uint32.cpp +++ b/libnd4j/include/ops/declarable/generic/datatypes/to_uint32.cpp @@ -44,7 +44,7 @@ namespace nd4j { } DECLARE_SHAPE_FN(to_uint32) { auto outShape = ShapeBuilders::copyShapeInfoAndType(inputShape->at(0), DataType::UINT32, true, block.workspace()); - return SHAPELIST(outShape); + return SHAPELIST(CONSTANT(outShape)); } } diff --git a/libnd4j/include/ops/declarable/generic/datatypes/to_uint64.cpp b/libnd4j/include/ops/declarable/generic/datatypes/to_uint64.cpp index 64633d34b..fe61821a5 100644 --- a/libnd4j/include/ops/declarable/generic/datatypes/to_uint64.cpp +++ b/libnd4j/include/ops/declarable/generic/datatypes/to_uint64.cpp @@ -44,7 +44,7 @@ namespace nd4j { } DECLARE_SHAPE_FN(to_uint64) { auto outShape = ShapeBuilders::copyShapeInfoAndType(inputShape->at(0), DataType::UINT64, true, block.workspace()); - return SHAPELIST(outShape); + return SHAPELIST(CONSTANT(outShape)); } } } diff --git a/libnd4j/include/ops/declarable/generic/transforms/merge_max_idx.cpp b/libnd4j/include/ops/declarable/generic/transforms/merge_max_idx.cpp index f6aeeebcf..e48761f8f 100644 --- a/libnd4j/include/ops/declarable/generic/transforms/merge_max_idx.cpp +++ b/libnd4j/include/ops/declarable/generic/transforms/merge_max_idx.cpp @@ -56,7 +56,7 @@ DECLARE_SHAPE_FN(mergemaxindex) { dtype = (DataType)INT_ARG(0); auto resShape = ShapeBuilders::copyShapeInfoAndType(in, dtype, block.workspace()); - return SHAPELIST(resShape); + return SHAPELIST(CONSTANT(resShape)); } } diff --git a/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests6.cpp b/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests6.cpp index 81086594d..5568e5119 100644 --- a/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests6.cpp +++ b/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests6.cpp @@ -1570,8 +1570,8 @@ TEST_F(DeclarableOpsTests6, LogDet_1) { ASSERT_EQ(ND4J_STATUS_OK, result->status()); auto z = result->at(0); - z->printIndexedBuffer("LogDet Output1 "); - exp.printIndexedBuffer("LogDet Expected1 "); +// z->printIndexedBuffer("LogDet Output1 "); +// exp.printIndexedBuffer("LogDet Expected1 "); ASSERT_TRUE(exp.isSameShape(z)); ASSERT_TRUE(exp.equalsTo(z)); @@ -1592,9 +1592,9 @@ TEST_F(DeclarableOpsTests6, LogDet_2) { ASSERT_EQ(ND4J_STATUS_OK, result->status()); auto z = result->at(0); - z->printIndexedBuffer("LogDet Output2 "); +// z->printIndexedBuffer("LogDet Output2 "); // z->printShapeInfo("Shape"); - exp.printIndexedBuffer("LogDet Expected2 "); +// exp.printIndexedBuffer("LogDet Expected2 "); ASSERT_TRUE(exp.isSameShape(z)); ASSERT_TRUE(exp.equalsTo(z)); @@ -1615,9 +1615,9 @@ TEST_F(DeclarableOpsTests6, LogDet_3) { ASSERT_EQ(ND4J_STATUS_OK, result->status()); auto z = result->at(0); - z->printIndexedBuffer("LogDet Output3 "); +// z->printIndexedBuffer("LogDet Output3 "); // z->printShapeInfo("Shape"); - exp.printIndexedBuffer("LogDet Expected3 "); +// exp.printIndexedBuffer("LogDet Expected3 "); ASSERT_TRUE(exp.isSameShape(z)); ASSERT_TRUE(exp.equalsTo(z)); @@ -1662,8 +1662,8 @@ TEST_F(DeclarableOpsTests6, MatrixInverse_1) { ASSERT_EQ(ND4J_STATUS_OK, result->status()); auto z = result->at(0); - z->printIndexedBuffer("Output "); - exp.printIndexedBuffer("Expected "); +// z->printIndexedBuffer("Output "); +// exp.printIndexedBuffer("Expected "); ASSERT_TRUE(exp.isSameShape(z)); ASSERT_TRUE(exp.equalsTo(z)); @@ -1698,8 +1698,8 @@ TEST_F(DeclarableOpsTests6, MatrixInverse_01) { ASSERT_EQ(ND4J_STATUS_OK, result->status()); auto z = result->at(0); - z->printIndexedBuffer("Output "); - exp.printIndexedBuffer("Expected "); +// z->printIndexedBuffer("Output "); +// exp.printIndexedBuffer("Expected "); ASSERT_TRUE(exp.isSameShape(z)); ASSERT_TRUE(exp.equalsTo(z)); @@ -1732,8 +1732,8 @@ TEST_F(DeclarableOpsTests6, MatrixInverse_02) { ASSERT_EQ(ND4J_STATUS_OK, result->status()); auto z = result->at(0); - z->printIndexedBuffer("Output "); - exp.printIndexedBuffer("Expected "); +// z->printIndexedBuffer("Output "); +// exp.printIndexedBuffer("Expected "); ASSERT_TRUE(exp.isSameShape(z)); ASSERT_TRUE(exp.equalsTo(z)); @@ -1812,8 +1812,8 @@ TEST_F(DeclarableOpsTests6, MatrixInverse_03) { ASSERT_EQ(ND4J_STATUS_OK, result->status()); auto z = result->at(0); - z->printIndexedBuffer("Output "); - exp.printIndexedBuffer("Expected "); +// z->printIndexedBuffer("Output "); +// exp.printIndexedBuffer("Expected "); ASSERT_TRUE(exp.isSameShape(z)); ASSERT_TRUE(exp.equalsTo(z)); diff --git a/libnd4j/tests_cpu/layers_tests/ListOperationsTests.cpp b/libnd4j/tests_cpu/layers_tests/ListOperationsTests.cpp index 2890c9012..e506839df 100644 --- a/libnd4j/tests_cpu/layers_tests/ListOperationsTests.cpp +++ b/libnd4j/tests_cpu/layers_tests/ListOperationsTests.cpp @@ -105,6 +105,7 @@ TEST_F(ListOperationsTests, BasicTest_UnStackList_1) { auto row = list.read(e); ASSERT_TRUE(row->equalsTo(tads->at(e))); //list.write(e, row); + delete row; } delete result; diff --git a/libnd4j/tests_cpu/layers_tests/RNGTests.cpp b/libnd4j/tests_cpu/layers_tests/RNGTests.cpp index 314a83aad..e1a23ee3f 100644 --- a/libnd4j/tests_cpu/layers_tests/RNGTests.cpp +++ b/libnd4j/tests_cpu/layers_tests/RNGTests.cpp @@ -248,8 +248,8 @@ TEST_F(RNGTests, Test_Gaussian_21) { RandomLauncher::fillGaussian(LaunchContext::defaultContext(), _rngA, &x0, 0.0f, 1.0f); RandomLauncher::fillGaussian(LaunchContext::defaultContext(), _rngB, &x1, 0.0f, 1.0f); - x0.printIndexedBuffer("x0"); - x1.printIndexedBuffer("x1"); +// x0.printIndexedBuffer("x0"); +// x1.printIndexedBuffer("x1"); ASSERT_TRUE(x0.equalsTo(&x1)); ASSERT_FALSE(x0.equalsTo(nexp0));