Click or drag to resize

DoubleMatrixSparse Method

Creates a sparse DoubleMatrix instance having the specified size and initial capacity to store entries different from zero.

Namespace:  Novacta.Analytics
Assembly:  Novacta.Analytics (in Novacta.Analytics.dll) Version: 2.0.0
Syntax
public static DoubleMatrix Sparse(
	int numberOfRows,
	int numberOfColumns,
	int capacity
)

Parameters

numberOfRows
Type: SystemInt32
The number of matrix rows.
numberOfColumns
Type: SystemInt32
The number of matrix columns.
capacity
Type: SystemInt32
The initial capacity to store non-zero entries.

Return Value

Type: DoubleMatrix
The matrix having the specified size and initial capacity.
Exceptions
ExceptionCondition
ArgumentOutOfRangeExceptionnumberOfRows is not positive.
-or-
numberOfColumns is not positive.
-or-
capacity is negative.
Remarks

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.

Note Note
In the current version of the Novacta.Analytics assembly, this method stores non-zero entries using the compressed sparse row scheme.

Examples

In the following example, a sparse matrix is created.

Creation of a sparse matrix
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               
// 

See Also