Click or drag to resize

IndexPartitionCreateT Method (IndexCollection, FuncInt32, T)

Creates a partition of the elements in an IndexCollection instance by aggregating those elements corresponding to a same part.

Namespace:  Novacta.Analytics
Assembly:  Novacta.Analytics (in Novacta.Analytics.dll) Version: 2.0.0
Syntax
public static IndexPartition<T> Create<T>(
	IndexCollection elements,
	Func<int, T> partitioner
)
where T : Object, IComparable<T>

Parameters

elements
Type: Novacta.AnalyticsIndexCollection
The collection of indexes to be partitioned.
partitioner
Type: SystemFuncInt32, T
A method which returns the part identifier corresponding to a given element in elements.

Type Parameters

T
The type of the parts in the partition.

Return Value

Type: IndexPartitionT
The partition of the indexes in the specified collection induced by the partitioner.
Exceptions
ExceptionCondition
ArgumentNullExceptionelements is null.
-or-
partitioner is null.
Examples

In the following example, the linear indexes of the main diagonal of a matrix are partitioned by checking if their corresponding entries are less than 3 in absolute value. Two parts are created, one for diagonal entries less than 3 in absolute value, the other for entries not satisfying that condition.

Partitioning the main diagonal entries of a matrix by their absolute value satisfying a certain condition
using System;

namespace Novacta.Analytics.CodeExamples
{
    public class IndexPartitionExample5  
    {
        public void Main()
        {
            // Create a matrix.
            var data = new double[16] {
               -3,  3,  3, -1,
                0,  2, -2,  2,
                2,  1, -4, -5,  
               -8,  2,  7, -1
            };
            var matrix = DoubleMatrix.Dense(4, 4, data, StorageOrder.RowMajor);

            // Create the collection of linear indexes corresponding
            // to entries on the matrix main diagonal.
            var diagonalIndexes = 
                IndexCollection.Sequence(0, 1 + matrix.NumberOfRows, matrix.Count);

            // Create a partitioner which returns true if
            // the absolute value in a entry having the specified linear
            // index is less than 3, otherwise false.
            bool partitioner(int linearIndex)
            {
                return Math.Abs(matrix[linearIndex]) < 3.0;
            }

            // Partition the diagonal linear indexes through the
            // specified partitioner.
            var partition = IndexPartition.Create(diagonalIndexes, partitioner);

            // Two parts are created, one for diagonal
            // entries less than 3 in absolute value, the other for 
            // entries not satisfying that condition.
            Console.WriteLine();
            foreach (var identifier in partition.Identifiers) {
                Console.WriteLine("Part identifier: {0}", identifier);
                Console.WriteLine("     indexes: {0}", partition[identifier]);
                Console.WriteLine();
            }
        }
    }
}

// Executing method Main() produces the following output:
// 
// 
// Part identifier: False
//      indexes: 0, 10
// 
// Part identifier: True
//      indexes: 5, 15

See Also