public void MultiplyMatrix() { float[] values = new float[] { 12, 23, 45, 56, 67, 89, 90, 12, 43, 65, 87, 43, 34, -12, 84, 44 }; MatrixF m = new MatrixF(4, 4, values, MatrixOrder.RowMajor); Assert.AreEqual(new MatrixF(4, 4), MatrixF.Multiply(m, new MatrixF(4, 4))); Assert.AreEqual(new MatrixF(4, 4), MatrixF.Multiply(new MatrixF(4, 4), m)); Assert.AreEqual(m, MatrixF.Multiply(m, MatrixF.CreateIdentity(4, 4))); Assert.AreEqual(m, MatrixF.Multiply(MatrixF.CreateIdentity(4, 4), m)); Assert.IsTrue(MatrixF.AreNumericallyEqual(MatrixF.CreateIdentity(4, 4), MatrixF.Multiply(m, m.Inverse))); Assert.IsTrue(MatrixF.AreNumericallyEqual(MatrixF.CreateIdentity(4, 4), MatrixF.Multiply(m.Inverse, m))); MatrixF m1 = new MatrixF(3, 4, rowMajor, MatrixOrder.RowMajor); MatrixF m2 = new MatrixF(4, 4, values, MatrixOrder.RowMajor); MatrixF result = MatrixF.Multiply(m1, m2); Assert.AreEqual(3, result.NumberOfRows); Assert.AreEqual(4, result.NumberOfColumns); for (int column = 0; column < 4; column++) for (int row = 0; row < 3; row++) Assert.AreEqual(VectorF.Dot(m1.GetRow(row), m2.GetColumn(column)), result[row, column]); }
public void GetColumn() { MatrixF m = new MatrixF(3, 4, rowMajor, MatrixOrder.RowMajor); Assert.AreEqual(new VectorF(new float[] { 1.0f, 5.0f, 9.0f }), m.GetColumn(0)); Assert.AreEqual(new VectorF(new float[] { 2.0f, 6.0f, 10.0f }), m.GetColumn(1)); Assert.AreEqual(new VectorF(new float[] { 3.0f, 7.0f, 11.0f }), m.GetColumn(2)); Assert.AreEqual(new VectorF(new float[] { 4.0f, 8.0f, 12.0f }), m.GetColumn(3)); }
public void GetColumnException2() { MatrixF m = new MatrixF(3, 4, rowMajor, MatrixOrder.RowMajor); m.GetColumn(4); }
public void SetColumn() { MatrixF m = new MatrixF(3, 4, rowMajor, MatrixOrder.RowMajor); m.SetColumn(0, new VectorF(new float[]{ 0.1f, 0.2f, 0.3f })); Assert.AreEqual(new VectorF(new float[]{ 0.1f, 0.2f, 0.3f }), m.GetColumn(0)); Assert.AreEqual(new VectorF(new float[]{ 2.0f, 6.0f, 10.0f }), m.GetColumn(1)); Assert.AreEqual(new VectorF(new float[]{ 3.0f, 7.0f, 11.0f }), m.GetColumn(2)); Assert.AreEqual(new VectorF(new float[]{ 4.0f, 8.0f, 12.0f }), m.GetColumn(3)); m.SetColumn(1, new VectorF(new float[] { 0.4f, 0.5f, 0.6f })); Assert.AreEqual(new VectorF(new float[] { 0.1f, 0.2f, 0.3f }), m.GetColumn(0)); Assert.AreEqual(new VectorF(new float[] { 0.4f, 0.5f, 0.6f }), m.GetColumn(1)); Assert.AreEqual(new VectorF(new float[] { 3.0f, 7.0f, 11.0f }), m.GetColumn(2)); Assert.AreEqual(new VectorF(new float[] { 4.0f, 8.0f, 12.0f }), m.GetColumn(3)); m.SetColumn(2, new VectorF(new float[] { 0.7f, 0.8f, 0.9f })); Assert.AreEqual(new VectorF(new float[] { 0.1f, 0.2f, 0.3f }), m.GetColumn(0)); Assert.AreEqual(new VectorF(new float[] { 0.4f, 0.5f, 0.6f }), m.GetColumn(1)); Assert.AreEqual(new VectorF(new float[] { 0.7f, 0.8f, 0.9f }), m.GetColumn(2)); Assert.AreEqual(new VectorF(new float[] { 4.0f, 8.0f, 12.0f }), m.GetColumn(3)); m.SetColumn(3, new VectorF(new float[] { 1.1f, 1.8f, 1.9f })); Assert.AreEqual(new VectorF(new float[] { 0.1f, 0.2f, 0.3f }), m.GetColumn(0)); Assert.AreEqual(new VectorF(new float[] { 0.4f, 0.5f, 0.6f }), m.GetColumn(1)); Assert.AreEqual(new VectorF(new float[] { 0.7f, 0.8f, 0.9f }), m.GetColumn(2)); Assert.AreEqual(new VectorF(new float[] { 1.1f, 1.8f, 1.9f }), m.GetColumn(3)); }