Click or drag to resize

CsvComplexMatrixSerializerDeserialize Method (TextReader)

Deserializes as ComplexMatrix the CSV document contained by the specified TextReader.

Namespace:  Novacta.Analytics
Assembly:  Novacta.Analytics (in Novacta.Analytics.dll) Version: 2.0.0
Syntax
public static ComplexMatrix Deserialize(
	TextReader reader
)

Parameters

reader
Type: System.IOTextReader
The TextReader that contains the CSV document to deserialize.

Return Value

Type: ComplexMatrix
The ComplexMatrix being deserialized.
Exceptions
ExceptionCondition
ArgumentNullExceptionreader is null.
InvalidOperationException An error occurred during deserialization. The original exception is available using the InnerException property.
Remarks

This method reads CSV files created by method Serialize(TextWriter, ComplexMatrix) or one of its overloaded versions.

Examples

In the following example, the content of a well formatted CSV document is deserialized to create a matrix instance.

Deserializing a CSV document to create a matrix
using System;
using System.IO;

namespace Novacta.Analytics.CodeExamples
{
    public class CsvSerializeExample0  
    {
        public void Main()
        {
            // Create the CSV representation of a dense matrix.
            string[] data = new string[5] {
                "Dense|Complex,3,2,MatrixName",
                ",column0,column1",
                "row0,(1.0 -2.0),(NaN NaN)",
                "row1,(2.0 -3.0),(4.0 -1.0)",
                "row2,(0 0),(5.0 7.0)"
            };

            // Show the matrix CSV representation.
            Console.WriteLine("CSV representation of the matrix:");
            for (int i = 0; i < data.Length; i++) {
                Console.WriteLine(data[i]);
            }
            Console.WriteLine();

            // Create a stream containing the CSV content.
            MemoryStream stream = new();
            StreamWriter writer = new(stream);
            for (int i = 0; i < data.Length; i++) {
                writer.WriteLine(data[i].ToCharArray());
                writer.Flush();
            }
            stream.Position = 0;

            // Create a reader for the stream.
            StreamReader reader = new(stream);

            // Deserialize the CSV document contained in the stream.
            ComplexMatrix matrix = 
                CsvComplexMatrixSerializer.Deserialize(reader);

            // Show the matrix.
            Console.WriteLine("Deserialized matrix:");
            Console.WriteLine(matrix);
        }
    }
}

// Executing method Main() produces the following output:
// 
// CSV representation of the matrix:
// Dense|Complex,3,2,MatrixName
// ,column0,column1
// row0,(1.0 -2.0),(NaN NaN)
// row1,(2.0 -3.0),(4.0 -1.0)
// row2,(0 0),(5.0 7.0)
// 
// Deserialized matrix:
//                  [column0]                             [column1]                             
// [row0]           (                1,               -2) (              NaN,              NaN) 
// [row1]           (                2,               -3) (                4,               -1) 
// [row2]           (                0,                0) (                5,                7) 
// 

See Also