public void Copy() { double[][] data = { new[] {1.0, 2.0}, new[] {3.0, 4.0} }; var source = new Matrix(data); var target = new Matrix(2, 2); MatrixMath.Copy(source, target); Assert.IsTrue(source.Equals(target)); }
public void Boolean() { bool[][] matrixDataBoolean = { new[] {true, false}, new[] {false, true} }; double[][] matrixDataDouble = { new[] {1.0, -1.0}, new[] {-1.0, 1.0}, }; var matrixBoolean = new Matrix(matrixDataBoolean); var matrixDouble = new Matrix(matrixDataDouble); Assert.IsTrue(matrixBoolean.Equals(matrixDouble)); }
public void Bipolar2Double() { // test a 1x4 bool[] boolData1 = { true, false, true, false }; double[] checkData1 = { 1, -1, 1, -1 }; Matrix matrix1 = Matrix.CreateRowMatrix(BiPolarUtil.Bipolar2double(boolData1)); Matrix checkMatrix1 = Matrix.CreateRowMatrix(checkData1); Assert.IsTrue(matrix1.Equals(checkMatrix1)); // test a 2x2 bool[][] boolData2 = { new[]{ true, false }, new[]{ false, true } }; double[][] checkData2 = { new[] { 1.0, -1.0 }, new[] { -1.0, 1.0 } }; var matrix2 = new Matrix(BiPolarUtil.Bipolar2double(boolData2)); var checkMatrix2 = new Matrix(checkData2); Assert.IsTrue(matrix2.Equals(checkMatrix2)); }
public void DeleteRow() { double[][] origData = { new[] {1.0, 2.0}, new[] {3.0, 4.0} }; double[][] checkData = {new[] {3.0, 4.0}}; var orig = new Matrix(origData); Matrix matrix = MatrixMath.DeleteRow(orig, 0); var check = new Matrix(checkData); Assert.IsTrue(check.Equals(matrix)); try { MatrixMath.DeleteRow(orig, 10); Assert.IsTrue(false); } catch (MatrixError) { } }
public void Identity() { try { MatrixMath.Identity(0); Assert.IsTrue(false); } catch (MatrixError) { } double[][] checkData = { new[] {1.0, 0.0}, new[] {0.0, 1.0} }; var check = new Matrix(checkData); Matrix matrix = MatrixMath.Identity(2); Assert.IsTrue(check.Equals(matrix)); }
public void PackedArray() { double[][] matrixData = { new[] {1.0, 2.0}, new[] {3.0, 4.0} }; var matrix = new Matrix(matrixData); double[] matrixData2 = matrix.ToPackedArray(); Assert.AreEqual(4, matrixData2.Length); Assert.AreEqual(1.0, matrix[0, 0]); Assert.AreEqual(2.0, matrix[0, 1]); Assert.AreEqual(3.0, matrix[1, 0]); Assert.AreEqual(4.0, matrix[1, 1]); var matrix2 = new Matrix(2, 2); matrix2.FromPackedArray(matrixData2, 0); Assert.IsTrue(matrix.Equals(matrix2)); }
public void MatrixEquals() { double[][] m1 = { new[] {1.0, 2.0}, new[] {3.0, 4.0} }; double[][] m2 = { new[] {0.0, 2.0}, new[] {3.0, 4.0} }; var matrix1 = new Matrix(m1); var matrix2 = new Matrix(m1); Assert.IsTrue(matrix1.Equals(matrix2)); matrix2 = new Matrix(m2); Assert.IsFalse(matrix1.Equals(matrix2)); }