Scalar version of youCanCheckForZeros
package io.improbable.keanu.tensor.dbl;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertEquals;
+
import org.junit.Test;
-import static org.junit.Assert.assertEquals;
+import io.improbable.keanu.tensor.bool.BooleanTensor;
public class ScalarDoubleTensorTest {
@@ -29,4 +33,13 @@ public class ScalarDoubleTensorTest {
double expected = 0.0;
assertEquals(expected, clampedA.scalar(), 0.0);
}
+
+ @Test
+ public void youCanCheckForZeros() {
+ DoubleTensor zero = DoubleTensor.scalar(0.);
+ DoubleTensor nonZero = DoubleTensor.scalar(1e-8);
+ TensorValidator validator = new TensorValidator(0.);
+ assertThat(validator.check(zero), equalTo(BooleanTensor.scalar(true)));
+ assertThat(validator.check(nonZero), equalTo(BooleanTensor.scalar(false)));
+ }
}
