Click or drag to resize

ReadOnlyDoubleMatrixItem Property (Int32)

Gets the entry of this instance corresponding to the specified linear index.

Namespace:  Novacta.Analytics
Assembly:  Novacta.Analytics (in Novacta.Analytics.dll) Version: 2.0.0
Syntax
public double this[
	int linearIndex
] { get; }

Parameters

linearIndex
Type: SystemInt32
The zero-based linear index of the entry to get.

Property Value

Type: Double
The element corresponding to the specified linear index.

Implements

IReadOnlyListTItemInt32
Exceptions
ExceptionCondition
ArgumentOutOfRangeExceptionlinearIndex is less than zero.
-or-
linearIndex is equal to or greater than the Count of this instance.
Remarks

Let LaTeX equation be a matrix, and consider its generic entry

LaTeX equation

where LaTeX equation and LaTeX equation are the number of rows and columns of LaTeX equation, respectively.

A linear index completely identifies an entry, assuming that entries are linearly ordered following the ColumnMajor data order. This means that entry LaTeX equation has linear index equal to LaTeX equation, and matrix entries can be enumerated as follows:

LaTeX equation

where LaTeX equation is the Count of the matrix.

Examples

In the following example, a matrix element is accessed using its linear index.

C#
using System;

namespace Novacta.Analytics.CodeExamples
{
    public class LinearIndexerExample0  
    {
        public void Main()
        {
            // Create a matrix.
            var data = new double[6] {
                10, 20, 30,
                40, 50, 60
            };
            var matrix = DoubleMatrix.Dense(2, 3, data, StorageOrder.RowMajor);
            Console.WriteLine("Initial data matrix:");
            Console.WriteLine(matrix);

            // Specify a linear index.
            int linearIndex = 3;
            Console.WriteLine();
            Console.WriteLine("Linear index: {0}", linearIndex);

            // Set the corresponding entry.
            matrix[linearIndex] = -50.0;

            Console.WriteLine();
            Console.WriteLine("Updated data matrix:");
            Console.WriteLine(matrix);

            // Entries can also be accessed using a read-only wrapper of the matrix.
            ReadOnlyDoubleMatrix readOnlyMatrix = matrix.AsReadOnly();

            Console.WriteLine();
            Console.WriteLine("Updated matrix entry:");
            Console.WriteLine(readOnlyMatrix[linearIndex]);
        }
    }
}

// Executing method Main() produces the following output:
// 
// Initial data matrix:
// 10               20               30               
// 40               50               60               
// 
// 
// 
// Linear index: 3
// 
// Updated data matrix:
// 10               20               30               
// 40               -50              60               
// 
// 
// 
// Updated matrix entry:
// -50

See Also