Note
In the current version of the Novacta.Analytics
assembly, this method stores non-zero entries using the compressed sparse row scheme.
public static DoubleMatrix Sparse(
int numberOfRows,
int numberOfColumns,
int capacity
)
Public Shared Function Sparse (
numberOfRows As Integer,
numberOfColumns As Integer,
capacity As Integer
) As DoubleMatrix
public:
static DoubleMatrix^ Sparse(
int numberOfRows,
int numberOfColumns,
int capacity
)
static member Sparse :
numberOfRows : int *
numberOfColumns : int *
capacity : int -> DoubleMatrix
DoubleMatrix 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 DoubleMatrix 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.
In the following example, a sparse matrix is created.
using System;
namespace Novacta.Analytics.CodeExamples
{
public class SparseExample0
{
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 = DoubleMatrix.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] = 1.0;
matrix[2, 1] = -2.0;
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
//
//
//
// Updated data matrix:
// 1 0
// 0 0
// 0 -2
//
//
ArgumentOutOfRangeException | numberOfRows is not positive. -or- numberOfColumns is not positive. -or- capacity is negative. |