public void CanWriteFloatMatrices() { var mat1 = new LinearAlgebra.Single.DenseMatrix(5, 3); for (var i = 0; i < mat1.ColumnCount; i++) { mat1[i, i] = i + .1f; } var mat2 = new LinearAlgebra.Single.DenseMatrix(4, 5); for (var i = 0; i < mat2.RowCount; i++) { mat2[i, i] = i + .1f; } var mat3 = new LinearAlgebra.Single.SparseMatrix(5, 4); mat3[0, 0] = 1.1f; mat3[0, 2] = 2.2f; mat3[4, 3] = 3.3f; var mat4 = new LinearAlgebra.Single.SparseMatrix(3, 5); mat4[0, 0] = 1.1f; mat4[0, 2] = 2.2f; mat4[2, 4] = 3.3f; var write = new LinearAlgebra.Single.Matrix[] { mat1, mat2, mat3, mat4 }; var names = new[] { "mat1", "dense_matrix_2", "s1", "sparse2" }; if (File.Exists("tests.mat")) { File.Delete("tests.mat"); } var writer = new MatlabMatrixWriter("tests.mat"); writer.WriteMatrices(write, names); writer.Dispose(); var reader = new MatlabMatrixReader <float>("tests.mat"); var read = reader.ReadMatrices(names); Assert.AreEqual(write.Length, read.Count); for (var i = 0; i < write.Length; i++) { var w = write[i]; var r = read[names[i]]; Assert.AreEqual(w.RowCount, r.RowCount); Assert.AreEqual(w.ColumnCount, r.ColumnCount); Assert.IsTrue(w.Equals(r)); } }
public void CanWriteFloatMatrices() { var mat1 = new LinearAlgebra.Single.DenseMatrix(5, 3); for (var i = 0; i < mat1.ColumnCount; i++) { mat1[i, i] = i + .1f; } var mat2 = new LinearAlgebra.Single.DenseMatrix(4, 5); for (var i = 0; i < mat2.RowCount; i++) { mat2[i, i] = i + .1f; } var mat3 = new LinearAlgebra.Single.SparseMatrix(5, 4); mat3[0, 0] = 1.1f; mat3[0, 2] = 2.2f; mat3[4, 3] = 3.3f; var mat4 = new LinearAlgebra.Single.SparseMatrix(3, 5); mat4[0, 0] = 1.1f; mat4[0, 2] = 2.2f; mat4[2, 4] = 3.3f; var write = new LinearAlgebra.Single.Matrix[] { mat1, mat2, mat3, mat4 }; var names = new[] { "mat1", "dense_matrix_2", "s1", "sparse2" }; if (File.Exists("tests.mat")) { File.Delete("tests.mat"); } var writer = new MatlabMatrixWriter("tests.mat"); writer.WriteMatrices(write, names); writer.Dispose(); var reader = new MatlabMatrixReader<float>("tests.mat"); var read = reader.ReadMatrices(names); Assert.AreEqual(write.Length, read.Count); for (var i = 0; i < write.Length; i++) { var w = write[i]; var r = read[names[i]]; Assert.AreEqual(w.RowCount, r.RowCount); Assert.AreEqual(w.ColumnCount, r.ColumnCount); Assert.IsTrue(w.Equals(r)); } }