Пример #1
0
        public void WriteBadMatrixThrowsArgumentException()
        {
            var matrix = new LinearAlgebra.Single.DenseMatrix(1, 1);
            var writer = new MatlabMatrixWriter("somefile1");

            Assert.Throws <ArgumentException>(() => writer.WriteMatrix(matrix, string.Empty));
            Assert.Throws <ArgumentException>(() => writer.WriteMatrix(matrix, null));
            writer.Dispose();
        }
Пример #2
0
        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));
            }
        }
Пример #3
0
        public void WriteNullMatricesThrowsArgumentNullException()
        {
            var writer = new MatlabMatrixWriter("somefile4");

            Assert.Throws <ArgumentNullException>(() => writer.WriteMatrices(new LinearAlgebra.Single.Matrix[] { null }, new[] { "matrix" }));
            var matrix = new LinearAlgebra.Single.DenseMatrix(1, 1);

            Assert.Throws <ArgumentNullException>(() => writer.WriteMatrices(new LinearAlgebra.Single.Matrix[] { matrix }, null));
            writer.Dispose();
        }
Пример #4
0
        public void WriteBadMatricesThrowsArgumentException()
        {
            var matrix = new LinearAlgebra.Single.DenseMatrix(1, 1);
            var writer = new MatlabMatrixWriter("somefile3");

            Assert.Throws <ArgumentException>(() => writer.WriteMatrices(new[] { matrix }, new[] { string.Empty }));
            Assert.Throws <ArgumentException>(() => writer.WriteMatrices(new[] { matrix }, new string[] { null }));
            Assert.Throws <ArgumentException>(() => writer.WriteMatrices(new[] { matrix, matrix }, new[] { "matrix" }));
            Assert.Throws <ArgumentException>(() => writer.WriteMatrices(new[] { matrix }, new[] { "some matrix" }));
            writer.Dispose();
        }
 public void WriteNullMatricesThrowsArgumentNullException()
 {
     var writer = new MatlabMatrixWriter("somefile4");
     Assert.Throws<ArgumentNullException>(() => writer.WriteMatrices(new LinearAlgebra.Single.Matrix[] { null }, new[] { "matrix" }));
     var matrix = new LinearAlgebra.Single.DenseMatrix(1, 1);
     Assert.Throws<ArgumentNullException>(() => writer.WriteMatrices(new LinearAlgebra.Single.Matrix[] { matrix }, null));
     writer.Dispose();
 }
 public void WriteBadMatrixThrowsArgumentException()
 {
     var matrix = new LinearAlgebra.Single.DenseMatrix(1, 1);
     var writer = new MatlabMatrixWriter("somefile1");
     Assert.Throws<ArgumentException>(() => writer.WriteMatrix(matrix, string.Empty));
     Assert.Throws<ArgumentException>(() => writer.WriteMatrix(matrix, null));
     writer.Dispose();
 }
 public void WriteBadMatricesThrowsArgumentException()
 {
     var matrix = new LinearAlgebra.Single.DenseMatrix(1, 1);
     var writer = new MatlabMatrixWriter("somefile3");
     Assert.Throws<ArgumentException>(() => writer.WriteMatrices(new[] { matrix }, new[] { string.Empty }));
     Assert.Throws<ArgumentException>(() => writer.WriteMatrices(new[] { matrix }, new string[] { null }));
     Assert.Throws<ArgumentException>(() => writer.WriteMatrices(new[] { matrix, matrix }, new[] { "matrix" }));
     Assert.Throws<ArgumentException>(() => writer.WriteMatrices(new[] { matrix }, new[] { "some matrix" }));
     writer.Dispose();
 }
        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));
            }
        }