Reorganise and add allTrue/allFalse
@@ -11,6 +11,22 @@ public class AssertVertex extends BoolVertex implements NonProbabilistic<Boolean
private final BooleanTensor expected;
private final String errorMessage;
+ public static AssertVertex allTrue(Vertex<? extends BooleanTensor> predicate) {
+ return new AssertVertex(predicate, BooleanTensor.trues(predicate.getShape()));
+ }
+
+ public static AssertVertex allTrue(Vertex<? extends BooleanTensor> predicate, String errorMessage) {
+ return new AssertVertex(predicate, BooleanTensor.trues(predicate.getShape()), errorMessage);
+ }
+
+ public static AssertVertex allFalse(Vertex<? extends BooleanTensor> predicate) {
+ return new AssertVertex(predicate, BooleanTensor.falses(predicate.getShape()));
+ }
+
+ public static AssertVertex allFalse(Vertex<? extends BooleanTensor> predicate, String errorMessage) {
+ return new AssertVertex(predicate, BooleanTensor.falses(predicate.getShape()), errorMessage);
+ }
+
public AssertVertex(Vertex<? extends BooleanTensor> predicate, BooleanTensor expected,
String errorMessage) {
super(TensorShapeValidation.checkAllShapesMatch(predicate.getShape(), expected.getShape()));
@@ -24,8 +40,11 @@ public class AssertVertex extends BoolVertex implements NonProbabilistic<Boolean
this(predicate, expected, "Failed assertion");
}
- private boolean predicateMatchesExpected() {
- return predicate.getValue().xor(expected).allFalse();
+
+ @Override
+ public BooleanTensor calculate() {
+ assertion();
+ return predicate.getValue();
}
private void assertion() {
@@ -34,14 +53,14 @@ public class AssertVertex extends BoolVertex implements NonProbabilistic<Boolean
}
}
- @Override
- public BooleanTensor calculate() {
- assertion();
- return predicate.getValue();
+ private boolean predicateMatchesExpected() {
+ return predicate.getValue().xor(expected).allFalse();
}
+
@Override
public BooleanTensor sample(KeanuRandom random) {
return predicate.sample();
}
+
}
