Esempio n. 1
0
        public void CanWriteComplexMatrices()
        {
            var mat1 = new LinearAlgebra.Complex.DenseMatrix(5, 3);

            for (var i = 0; i < mat1.ColumnCount; i++)
            {
                mat1[i, i] = new Complex(i + .1, i + .1);
            }

            var mat2 = new LinearAlgebra.Complex.DenseMatrix(4, 5);

            for (var i = 0; i < mat2.RowCount; i++)
            {
                mat2[i, i] = new Complex(i + .1, i + .1);
            }

            var mat3 = new LinearAlgebra.Complex.SparseMatrix(5, 4);

            mat3[0, 0] = new Complex(1.1, 1.1);
            mat3[0, 2] = new Complex(2.2, 2.2);
            mat3[4, 3] = new Complex(3.3, 3.3);

            var mat4 = new LinearAlgebra.Complex.SparseMatrix(3, 5);

            mat4[0, 0] = new Complex(1.1, 1.1);
            mat4[0, 2] = new Complex(2.2, 2.2);
            mat4[2, 4] = new Complex(3.3, 3.3);

            var write = new LinearAlgebra.Complex.Matrix[] { mat1, mat2, mat3, mat4 };

            var names = new[] { "mat1", "dense_matrix_2", "s1", "sparse2" };

            if (File.Exists("testz.mat"))
            {
                File.Delete("testz.mat");
            }

            var writer = new MatlabMatrixWriter("testz.mat");

            writer.WriteMatrices(write, names);
            writer.Dispose();

            var reader = new MatlabMatrixReader <Complex>("testz.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 CanWriteComplexMatrices()
        {
            var mat1 = new LinearAlgebra.Complex.DenseMatrix(5, 3);
            for (var i = 0; i < mat1.ColumnCount; i++)
            {
                mat1[i, i] = new Complex(i + .1, i + .1);
            }

            var mat2 = new LinearAlgebra.Complex.DenseMatrix(4, 5);
            for (var i = 0; i < mat2.RowCount; i++)
            {
                mat2[i, i] = new Complex(i + .1, i + .1);
            }

            var mat3 = new LinearAlgebra.Complex.SparseMatrix(5, 4);
            mat3[0, 0] = new Complex(1.1, 1.1);
            mat3[0, 2] = new Complex(2.2, 2.2);
            mat3[4, 3] = new Complex(3.3, 3.3);

            var mat4 = new LinearAlgebra.Complex.SparseMatrix(3, 5);
            mat4[0, 0] = new Complex(1.1, 1.1);
            mat4[0, 2] = new Complex(2.2, 2.2);
            mat4[2, 4] = new Complex(3.3, 3.3);

            var write = new LinearAlgebra.Complex.Matrix[] { mat1, mat2, mat3, mat4 };

            var names = new[] { "mat1", "dense_matrix_2", "s1", "sparse2" };
            if (File.Exists("testz.mat"))
            {
                File.Delete("testz.mat");
            }

            var writer = new MatlabMatrixWriter("testz.mat");
            writer.WriteMatrices(write, names);
            writer.Dispose();

            var reader = new MatlabMatrixReader<Complex>("testz.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));
            }
        }