ComplexMatrixSparse Method |
Namespace: Novacta.Analytics
public static ComplexMatrix Sparse( int numberOfRows, int numberOfColumns, int capacity )
Exception | Condition |
---|---|
ArgumentOutOfRangeException | numberOfRows is not positive. -or- numberOfColumns is not positive. -or- capacity is negative. |
ComplexMatrix sparse instances allocate storage only for a number of matrix entries equal to capacity. If an entry is not explicitly set, it is interpreted as zero. If needed, the capacity is automatically updated to store more non-zero entries. Dense ComplexMatrix instances, i.e. instances allocating storage for each of their entries, can be created by calling method Dense(Int32, Int32) or one of its overloaded versions.
Note |
---|
In the current version of the Novacta.Analytics assembly, this method stores non-zero entries using the compressed sparse row scheme. |
In the following example, a sparse matrix is created.
using System; using System.Numerics; namespace Novacta.Analytics.CodeExamples { public class ComplexSparseExample0 { public void Main() { // Set matrix dimensions. int numberOfRows = 3; int numberOfColumns = 2; // Set the initial capacity of the sparse instance. int capacity = 0; // Create the matrix. All entries will be equal to zero. var matrix = ComplexMatrix.Sparse( numberOfRows, numberOfColumns, capacity); Console.WriteLine("Initially, each entry is equal to zero."); Console.WriteLine("The data matrix:"); Console.WriteLine(matrix); Console.WriteLine(); // Set some entries as non-zero values. // If needed, the initial capacity is automatically // incremented. matrix[0, 0] = new Complex(1, -1); matrix[2, 1] = new Complex(2, -2); Console.WriteLine("Updated data matrix:"); Console.WriteLine(matrix); } } } // Executing method Main() produces the following output: // // Initially, each entry is equal to zero. // The data matrix: // ( 0, 0) ( 0, 0) // ( 0, 0) ( 0, 0) // ( 0, 0) ( 0, 0) // // // // Updated data matrix: // ( 1, -1) ( 0, 0) // ( 0, 0) ( 0, 0) // ( 0, 0) ( 2, -2) //