Repository: deeplearning4j/deeplearning4j
Issue: INDArray.match(Number, Condition) not returning expected results. 

**Expected behavior:**
`array.match(n, Conditions.equals())` should return a mask such that each entry `mask.get(i)` is `array[i] == n`

**Encountered behavior:**

the mask contains incorrect booleans for anything but `n=0`. 

#### Version Information

Please indicate relevant versions, including, if relevant:

* nd4j version beta 7. 
* Platform information (OS, etc): Windows 10 Enterprise

#### To reproduce: 

The following code will reproduce the error for `i > 0`:

        int[] assignments = {0,0,0,1,0,2,2};
        int[] indexes     = {0,1,2,3,4,5,7};

        INDArray asarray = Nd4j.createFromArray(assignments);
        INDArray idxarray = Nd4j.createFromArray(indexes);

        int i = 1; 
        INDArray mask = asarray.match(i, Conditions.equals());

- `i=1` results in the mask ` [ false, false, false, true, false, true, true]`
- `i=2` results in the mask ` [ false, false, false, false, false, false, false]`

There seem to be similar problems with `notEquals()` and `notEquals(someNumber)`. Everything is inverted or totally incorrect. 



#### Contributing

I would love to contribute, but might need guidance. 


Changed files:
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/indexing/conditions/ConditionEquals.java
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/BaseNDArray.java
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/indexing/conditions/EqualsCondition.java
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/indexing/conditions/Not.java
nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/ops/NativeOpExecutioner.java
nd4j/nd4j-backends/nd4j-tests/src/test/java/org/nd4j/linalg/custom/CustomOpsTests.java
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/indexing/conditions/BaseCondition.java
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ops/impl/transforms/bool/MatchConditionTransform.java
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/indexing/conditions/Or.java
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/indexing/conditions/Condition.java
nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/nativeblas/Nd4jCpu.java

diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/BaseNDArray.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/BaseNDArray.java
index c3594696d5..98bf9d16e5 100644
--- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/BaseNDArray.java
+++ b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/BaseNDArray.java
@@ -1889,7 +1889,9 @@ public abstract class BaseNDArray implements INDArray, Iterable {
 
     @Override
     public INDArray match(Number comp, Condition condition) {
-        return Nd4j.getExecutioner().exec(new MatchConditionTransform(this,comp.doubleValue(), condition));
+        //override the value so the value gets parsed properly
+        condition.setValue(comp);
+        return Nd4j.getExecutioner().exec(new MatchConditionTransform(this, EPS_THRESHOLD, condition));
     }
 
     @Override
diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ops/impl/transforms/bool/MatchConditionTransform.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ops/impl/transforms/bool/MatchConditionTransform.java
index 2ae0e0c0f5..7a94c3fd22 100644
--- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ops/impl/transforms/bool/MatchConditionTransform.java
+++ b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ops/impl/transforms/bool/MatchConditionTransform.java
@@ -45,7 +45,7 @@ public class MatchConditionTransform extends BaseTransformBoolOp {
         this.compare = condition.getValue();
         this.mode = condition.condtionNum();
         this.eps = Nd4j.EPS_THRESHOLD;
-        this.extraArgs = new Object[] {compare, eps, (double) mode};
+        this.extraArgs = new Object[] {compare,1.0, eps,  mode};
     }
 
     public MatchConditionTransform() {}
@@ -70,7 +70,7 @@ public class MatchConditionTransform extends BaseTransformBoolOp {
         this.mode = condition.condtionNum();
         this.eps = eps;
 
-        this.extraArgs = new Object[] {compare, eps, (double) mode};
+        this.extraArgs = new Object[] {compare, eps, mode};
     }
 
     public MatchConditionTransform(INDArray x, double eps, @NonNull Condition condition) {
diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/indexing/conditions/BaseCondition.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/indexing/conditions/BaseCondition.java
index 0b5b619a67..207cfc9d3f 100644
--- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/indexing/conditions/BaseCondition.java
+++ b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/indexing/conditions/BaseCondition.java
@@ -29,6 +29,11 @@ public abstract class BaseCondition implements Condition {
         this.value = value;
     }
 
+    @Override
+    public void setValue(Number value) {
+        this.value = value;
+    }
+
     @Override
     public double epsThreshold() {
         return Nd4j.EPS_THRESHOLD;
diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/indexing/conditions/Condition.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/indexing/conditions/Condition.java
index 7f92450f38..acfc47b9d6 100644
--- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/indexing/conditions/Condition.java
+++ b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/indexing/conditions/Condition.java
@@ -21,9 +21,47 @@
 package org.nd4j.linalg.indexing.conditions;
 
 import org.nd4j.common.function.Function;
-
+/**
+ *
+ * Sets a condition in correspondence with the MatchConditionalBool op
+ * (op num 5 in the legacy operations)
+ *
+ * Condition number is affected by the ops internals, see here for the comprehensive overview:
+ * https://github.com/eclipse/deeplearning4j/blob/master/libnd4j/include/ops/ops.h#L2253
+ *
+ * As of this writing (July 27,2021), the following operations are relevant:
+ * 0: equals
+ * 1: not equals
+ * 2: less than
+ * 3: greater than
+ * 4: less than or equal
+ * 5: greater than or equal
+ * 6: absolute difference less than
+ * 7: absolute difference greater than
+ * 8: is infinite
+ * 9: is nan
+ * 10: absolute equals
+ * 11: not equals
+ * 12: absolute difference greater or equal to
+ * 13: absolute difference less than or equal to
+ * 14: is finite
+ * 15: is infinite
+ *
+ * @return
+ */
 public interface Condition extends Function<Number, Boolean> {
 
+    /**
+     * Allows overriding of the value.
+     *
+     * @param value
+     */
+    default void setValue(Number value) {
+        //no-op for aggregate conditions. Mainly used for providing an api to end users such as:
+        //INDArray.match(input,Conditions.equals())
+        //See: https://github.com/eclipse/deeplearning4j/issues/9393
+    }
+
     /**
      * Returns condition ID for native side
      *
diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/indexing/conditions/ConditionEquals.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/indexing/conditions/ConditionEquals.java
index cd8e78b873..edbc1368a4 100644
--- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/indexing/conditions/ConditionEquals.java
+++ b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/indexing/conditions/ConditionEquals.java
@@ -28,6 +28,7 @@ public class ConditionEquals implements Condition {
         this.conditions = conditions;
     }
 
+
     /**
      * Returns condition ID for native side
      *
diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/indexing/conditions/EqualsCondition.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/indexing/conditions/EqualsCondition.java
index a535f807ea..bceb885beb 100644
--- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/indexing/conditions/EqualsCondition.java
+++ b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/indexing/conditions/EqualsCondition.java
@@ -38,12 +38,14 @@ public class EqualsCondition extends BaseCondition {
 
     /**
      * Returns condition ID for native side
+     * Condition number is affected by:
+     * https://github.com/eclipse/deeplearning4j/blob/0ba0f933a95d2dceeff3651bc540d03b5f3b1631/libnd4j/include/ops/ops.h#L2253
      *
      * @return
      */
     @Override
     public int condtionNum() {
-        return 10;
+        return 0;
     }
 
     @Override
diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/indexing/conditions/Not.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/indexing/conditions/Not.java
index db6cfd6a70..9e911c0e03 100644
--- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/indexing/conditions/Not.java
+++ b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/indexing/conditions/Not.java
@@ -24,6 +24,7 @@ public class Not implements Condition {
 
     private Condition opposite;
 
+
     /**
      * Returns condition ID for native side
      *
diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/indexing/conditions/Or.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/indexing/conditions/Or.java
index 6c1f6adeed..65ae169ae2 100644
--- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/indexing/conditions/Or.java
+++ b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/indexing/conditions/Or.java
@@ -28,6 +28,7 @@ public class Or implements Condition {
         this.conditions = conditions;
     }
 
+
     /**
      * Returns condition ID for native side
      *
diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/ops/NativeOpExecutioner.java b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/ops/NativeOpExecutioner.java
index bec01aa6ee..7c204de133 100644
--- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/ops/NativeOpExecutioner.java
+++ b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/ops/NativeOpExecutioner.java
@@ -819,6 +819,8 @@ public class NativeOpExecutioner extends DefaultOpExecutioner {
                 case TRANSFORM_FLOAT: {
                     val xtraz = getPointerForExtraArgs(op, z.dataType());
 
+
+
                     loop.execTransformFloat(dummy, op.opNum(),
                             xb, (LongPointer) x.shapeInfoDataBuffer().addressPointer(), null,
                             zb, (LongPointer) z.shapeInfoDataBuffer().addressPointer(),
diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/nativeblas/Nd4jCpu.java b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/nativeblas/Nd4jCpu.java
index 4b6cd2b079..750c024a98 100644
--- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/nativeblas/Nd4jCpu.java
+++ b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/nativeblas/Nd4jCpu.java
@@ -3392,9 +3392,6 @@ public native int getRandomGeneratorRelativeInt(OpaqueRandomGenerator ptr, @Cast
 public native @Cast("Nd4jLong") long getRandomGeneratorRelativeLong(OpaqueRandomGenerator ptr, @Cast("Nd4jLong") long index);
 public native void deleteRandomGenerator(OpaqueRandomGenerator ptr);
 
-public native @Cast("char*") String runLightBenchmarkSuit(@Cast("bool") boolean printOut);
-public native @Cast("char*") String runFullBenchmarkSuit(@Cast("bool") boolean printOut);
-
 public native OpaqueLaunchContext defaultLaunchContext();
 public native @Cast("Nd4jPointer") Pointer lcScalarPointer(OpaqueLaunchContext lc);
 public native @Cast("Nd4jPointer") Pointer lcReductionPointer(OpaqueLaunchContext lc);
diff --git a/nd4j/nd4j-backends/nd4j-tests/src/test/java/org/nd4j/linalg/custom/CustomOpsTests.java b/nd4j/nd4j-backends/nd4j-tests/src/test/java/org/nd4j/linalg/custom/CustomOpsTests.java
index 4bc2de4b21..35a6bc66d3 100644
--- a/nd4j/nd4j-backends/nd4j-tests/src/test/java/org/nd4j/linalg/custom/CustomOpsTests.java
+++ b/nd4j/nd4j-backends/nd4j-tests/src/test/java/org/nd4j/linalg/custom/CustomOpsTests.java
@@ -1497,6 +1497,30 @@ public class CustomOpsTests extends BaseNd4jTestWithBackends {
         assertEquals(exp, z);
     }
 
+    @ParameterizedTest
+    @MethodSource("org.nd4j.linalg.BaseNd4jTestWithBackends#configs")
+    public void testMatch_2(Nd4jBackend backend) {
+        int[] assignments = {0,0,0,1,0,2,2};
+        int[] indexes     = {0,1,2,3,4,5,7};
+
+        INDArray asarray = Nd4j.createFromArray(assignments);
+        INDArray idxarray = Nd4j.createFromArray(indexes);
+
+        int[] testIndicesForMask = new int[] {1,2};
+        INDArray[] assertions = {
+                Nd4j.createFromArray(false,false,false,true,false,false,false),
+                Nd4j.createFromArray(false,false,false,false,false,true,true)
+        };
+
+        for(int j = 0; j < testIndicesForMask.length; j++) {
+            INDArray mask = asarray.match(testIndicesForMask[j], Conditions.equals());
+            assertEquals(assertions[j],mask);
+
+        }
+
+    }
+
+
 
     @ParameterizedTest
     @MethodSource("org.nd4j.linalg.BaseNd4jTestWithBackends#configs")