Fixed bug in ScalarDoubleTensor for "inverse" function and added an explicit case for this in the inverse tests
@@ -5,6 +5,7 @@ import static org.junit.Assert.assertEquals;
import org.junit.Test;
import io.improbable.keanu.tensor.dbl.DoubleTensor;
+import io.improbable.keanu.tensor.dbl.ScalarDoubleTensor;
import io.improbable.keanu.vertices.dbl.DoubleVertex;
import io.improbable.keanu.vertices.dbl.nonprobabilistic.ConstantDoubleVertex;
import io.improbable.keanu.vertices.dbl.probabilistic.UniformVertex;
@@ -86,4 +87,15 @@ public class MatrixInverseVertexTest {
}
}
+ @Test
+ public void scalarTensorsInvertCorrectly() {
+ DoubleTensor oneByOneMatrix = new ScalarDoubleTensor(2.0);
+ DoubleVertex input = new ConstantDoubleVertex(oneByOneMatrix);
+ DoubleVertex inverse = input.matrixInverse();
+
+ inverse.lazyEval();
+
+ assertEquals(0.5, inverse.getValue().scalar(), 1e-6);
+ }
+
}
