diff --git a/libnd4j/include/ops/declarable/generic/boolean/is_non_decreasing.cpp b/libnd4j/include/ops/declarable/generic/boolean/is_non_decreasing.cpp index 563965147..37fa1350a 100644 --- a/libnd4j/include/ops/declarable/generic/boolean/is_non_decreasing.cpp +++ b/libnd4j/include/ops/declarable/generic/boolean/is_non_decreasing.cpp @@ -27,9 +27,12 @@ namespace nd4j { namespace ops { BOOLEAN_OP_IMPL(is_non_decreasing, 1, true) { - auto input = INPUT_VARIABLE(0); + // in case of empty input there's nothing to do + if (input->isEmpty()) + return ND4J_STATUS_TRUE; + bool isNonDecreasing = true; nd4j::ops::helpers::compare_elem(block.launchContext(), input, false, isNonDecreasing); diff --git a/libnd4j/include/ops/declarable/generic/boolean/is_strictly_increasing.cpp b/libnd4j/include/ops/declarable/generic/boolean/is_strictly_increasing.cpp index a238eedac..a41852394 100644 --- a/libnd4j/include/ops/declarable/generic/boolean/is_strictly_increasing.cpp +++ b/libnd4j/include/ops/declarable/generic/boolean/is_strictly_increasing.cpp @@ -27,9 +27,12 @@ namespace nd4j { namespace ops { BOOLEAN_OP_IMPL(is_strictly_increasing, 1, true) { - auto input = INPUT_VARIABLE(0); + // in case of empty input there's nothing to do + if (input->isEmpty()) + return ND4J_STATUS_TRUE; + bool isStrictlyIncreasing = true; nd4j::ops::helpers::compare_elem(block.launchContext(), input, true, isStrictlyIncreasing); diff --git a/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests15.cpp b/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests15.cpp index 97e7d2d91..ff554f837 100644 --- a/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests15.cpp +++ b/libnd4j/tests_cpu/layers_tests/DeclarableOpsTests15.cpp @@ -551,4 +551,34 @@ TEST_F(DeclarableOpsTests15, test_lstmBlock_3) { auto temp1 = ft.reshape('f', {bS, nIn}); auto temp2 = temp1 * cLast; } +} + +TEST_F(DeclarableOpsTests15, test_empty_increasing_1) { + auto x = NDArrayFactory::create('c', {1, 0, 3}); + auto z = NDArrayFactory::create(false); + + Context ctx(1); + ctx.setInputArray(0, &x); + ctx.setOutputArray(0, &z); + + nd4j::ops::is_strictly_increasing op; + auto status = op.execute(&ctx); + ASSERT_EQ(Status::OK(), status); + + ASSERT_EQ(true, z.e(0)); +} + +TEST_F(DeclarableOpsTests15, test_empty_decreasing_1) { + auto x = NDArrayFactory::create('c', {1, 0, 3}); + auto z = NDArrayFactory::create(false); + + Context ctx(1); + ctx.setInputArray(0, &x); + ctx.setOutputArray(0, &z); + + nd4j::ops::is_non_decreasing op; + auto status = op.execute(&ctx); + ASSERT_EQ(Status::OK(), status); + + ASSERT_EQ(true, z.e(0)); } \ No newline at end of file