Click or drag to resize

DoubleMatrixDense Method (Int32, Int32, Double, StorageOrder)

Creates a dense DoubleMatrix instance having the specified size, and assigns data to entries applying the given storage order.

Namespace:  Novacta.Analytics
Assembly:  Novacta.Analytics (in Novacta.Analytics.dll) Version: 2.0.0
Syntax
public static DoubleMatrix Dense(
	int numberOfRows,
	int numberOfColumns,
	double[] data,
	StorageOrder storageOrder
)

Parameters

numberOfRows
Type: SystemInt32
The number of matrix rows.
numberOfColumns
Type: SystemInt32
The number of matrix columns.
data
Type: SystemDouble
The data assigned to matrix entries.
storageOrder
Type: Novacta.AnalyticsStorageOrder
The linear ordering of matrix entries assumed when assigning data.

Return Value

Type: DoubleMatrix
The matrix having the specified size and data.
Exceptions
ExceptionCondition
ArgumentExceptionstorageOrder is not a field of StorageOrder.
-or-
data has Length not equal to the multiplication of numberOfRows by numberOfColumns.
ArgumentOutOfRangeExceptionnumberOfRows is not positive.
-or-
numberOfColumns is not positive.
ArgumentNullExceptiondata is null.
Remarks

DoubleMatrix dense instances allocate storage for each matrix entry. Sparse DoubleMatrix instances can be created by calling method Sparse(Int32, Int32, Int32).

Parameter data is unidimensional, while matrix entries are bi-dimensional, since are defined by their row and column indexes. As a consequence, entries must be linearly ordered to define a correspondence between data and matrix entries. Supported linear orderings can be specified through parameter storageOrder. If constant ColumnMajor is passed, then the order is assumed by columns: matrix entries are ordered by their column index first, and entries laying on a given column are in turn ordered by their row index. This implies that the first numberOfRows entries in data will be assumed to contain the first column of the returned matrix, and so on. If constant RowMajor is passed, then the order is assumed by rows: matrix entries are ordered by their row index first, and entries laying on a given row are in turn ordered by their column index. This implies that the first numberOfColumns entries in data will be assumed to contain the first row of the returned matrix, and so on.

Examples

In the following example, a dense matrix is created by passing both RowMajor and ColMajor ordered data.

Creation of a dense matrix with RowMajor or ColMajor ordered data
using System;

namespace Novacta.Analytics.CodeExamples
{
    public class DenseExample0  
    {
        public void Main()
        {
            // Set matrix dimensions.
            int numberOfRows = 3;
            int numberOfColumns = 2;

            // Create the data.
            var data = new double[6] {
               1,  2,  3,  4,  5,  6
            };

            // Assume the data as RowMajor ordered.
            StorageOrder storageOrder = StorageOrder.RowMajor;

            // Create the matrix.
            var matrix = DoubleMatrix.Dense(
                numberOfRows, numberOfColumns, data, storageOrder);
            Console.WriteLine("Assuming RowMajor ordered data.");
            Console.WriteLine("The data matrix:");
            Console.WriteLine(matrix);

            // Assume the data as ColMajor ordered.
            storageOrder = StorageOrder.ColumnMajor;

            // Create the matrix.
            matrix = DoubleMatrix.Dense(
                numberOfRows, numberOfColumns, data, storageOrder);
            Console.WriteLine("Assuming ColMajor ordered data.");
            Console.WriteLine("The data matrix:");
            Console.WriteLine(matrix);
        }
    }
}

// Executing method Main() produces the following output:
// 
// Assuming RowMajor ordered data.
// The data matrix:
// 1                2                
// 3                4                
// 5                6                
// 
// 
// Assuming ColMajor ordered data.
// The data matrix:
// 1                4                
// 2                5                
// 3                6                
// 

See Also