public void TestOfIndexed(int rows, int columns) { var denseData = MatrixHelper.LoadDense(rows, columns); var denseA = denseData.A; var denseB = DenseMatrix.OfIndexed(rows, columns, denseA.EnumerateIndexed()); Assert.IsTrue(denseA.Equals(denseB)); }
public void TestOfColumnMajor(int rows, int columns) { var denseData = MatrixHelper.LoadDense(rows, columns); var denseA = denseData.A; var denseB = DenseMatrix.OfColumnMajor(rows, columns, denseA.Values); Assert.IsTrue(denseA.Equals(denseB)); }
public void TestMatrixSum(int rows, int columns) { var data = MatrixHelper.LoadDense(rows, columns); var A = data.A; var B = data.B; var actual = A.Add(B); CollectionAssert.AreEqual(data.ApB.Values, actual.Values); }
public void TestMatrixTranspose(int rows, int columns) { var data = MatrixHelper.LoadDense(rows, columns); var A = data.A; var B = data.B; var actualA = A.Transpose(); var actualB = B.Transpose(); CollectionAssert.AreEqual(data.AT.Values, actualA.Values); CollectionAssert.AreEqual(data.BT.Values, actualB.Values); }
public void TestMatrixVectorTransposeMultiplyUpdate(int rows, int columns) { var data = MatrixHelper.LoadDense(rows, columns); var A = data.A; var y = data.y; var actual = Vector.Create(A.ColumnCount, 1.0); A.TransposeMultiply(1.0, y, 0.0, actual); CollectionAssert.AreEqual(data.ATy, actual); }
public void TestMatrixVectorMultiplyUpdate(int rows, int columns) { var data = MatrixHelper.LoadDense(rows, columns); var A = data.A; var x = data.x; var actual = Vector.Create(A.RowCount, 1.0); A.Multiply(1.0, x, 0.0, actual); CollectionAssert.AreEqual(data.Ax, actual); }
public void TestOfMatrix(int rows, int columns) { var sparseData = MatrixHelper.LoadSparse(rows, columns); var sparseA = sparseData.A; var sparseB = SparseMatrix.OfMatrix(sparseA); Assert.IsTrue(sparseA.Equals(sparseB)); var denseData = MatrixHelper.LoadDense(rows, columns); sparseB = SparseMatrix.OfMatrix(denseData.A); Assert.IsTrue(sparseA.Equals(sparseB)); }
public void TestGetColumn(int rows, int columns) { var data = MatrixHelper.LoadDense(rows, columns); var A = data.A; for (int j = 0; j < columns; j++) { var y = A.Column(j); for (int i = 0; i < rows; i++) { Assert.AreEqual(A.At(i, j), y[i]); } } }
public void TestFrobeniusNorm() { var A = DenseMatrix.CreateDiagonal(9, 2.0); var actual = A.FrobeniusNorm(); var expected = 6.0; Assert.AreEqual(expected, actual); var data = MatrixHelper.LoadDense(2, 2); actual = data.A.FrobeniusNorm(); expected = 5.477225575; Assert.AreEqual(expected, actual); }
public void TestInfinityNorm() { var A = DenseMatrix.CreateDiagonal(9, 2.0); var actual = A.InfinityNorm(); var expected = 2.0; Assert.AreEqual(expected, actual); var data = MatrixHelper.LoadDense(2, 2); actual = data.A.InfinityNorm(); expected = 7.0; Assert.AreEqual(expected, actual); }
public void TestMatrixMultiply(int rows, int columns) { var data = MatrixHelper.LoadDense(rows, columns); var A = data.A; var B = data.B; var AT = data.AT; var BT = data.BT; var actual = AT.Multiply(B); CollectionAssert.AreEqual(data.ATmB.Values, actual.Values, ComplexNumberComparer.Default); actual = A.Multiply(BT); CollectionAssert.AreEqual(data.AmBT.Values, actual.Values, ComplexNumberComparer.Default); }
public void TestSetColumn(int rows, int columns) { var data = MatrixHelper.LoadDense(rows, columns); var x = new Complex(-1.1, 0); var A = data.A.Clone(); var z = Vector.Create(rows, x); for (int j = 0; j < columns; j++) { A.SetColumn(j, z); for (int i = 0; i < rows; i++) { Assert.AreEqual(x, A.At(i, j)); } } }