Click or drag to resize

ComplexMatrixFindWhile Method

Searches for entries in this instance that matches the conditions defined by the specified predicate, and returns their zero-based linear indexes.

Namespace:  Novacta.Analytics
Assembly:  Novacta.Analytics (in Novacta.Analytics.dll) Version: 2.0.0
Syntax
public IndexCollection FindWhile(
	Predicate<Complex> match
)

Parameters

match
Type: SystemPredicateComplex
The predicate that defines the conditions of the entries to search for.

Return Value

Type: IndexCollection
The collection of zero-based linear indexes of the entries that matches the conditions defined by match, if found; otherwise null.
Exceptions
ExceptionCondition
ArgumentNullExceptionmatch is null.
Remarks

Matrix entries are interpreted as well ordered following a column major ordering. The position of an entry in such well ordering is referred to as the linear position of that entry.

Examples

In the following example, the negative entries of a data matrix are found.

C#
using System;
using System.Numerics;

namespace Novacta.Analytics.CodeExamples
{
    public class ComplexFindWhileExample0  
    {
        public void Main()
        {
            // Create a matrix.
            var data = new Complex[6] {
                new Complex(0,  0), new Complex(5, -5),
                new Complex(2, -2), new Complex(0,  0),
                new Complex(0,  0), new Complex(2, -2)
            };
            var matrix = ComplexMatrix.Dense(3, 2, data, StorageOrder.RowMajor);
            Console.WriteLine("The data matrix:");
            Console.WriteLine(matrix);

            // Match entries having magnitude less than 2.
            static bool match(Complex value) { return value.Magnitude < 2.0; }

            // Find the linear indexes of matched entries in data.
            var indexes = matrix.FindWhile(match);

            Console.WriteLine();
            Console.WriteLine("Linear indexes of matched entries in data:");
            Console.WriteLine(indexes);

            // FindWhile is available for read-only matrices:
            // find matched entries using a read-only wrapper of the data matrix.
            ReadOnlyComplexMatrix readOnlyMatrix = matrix.AsReadOnly();
            indexes = readOnlyMatrix.FindWhile(match);

            Console.WriteLine();
            Console.WriteLine("Using read-only data. Linear indexes of matched entries:");
            Console.WriteLine(indexes);
        }
    }
}

// Executing method Main() produces the following output:
// 
// The data matrix:
// (                0,                0) (                5,               -5) 
// (                2,               -2) (                0,                0) 
// (                0,                0) (                2,               -2) 
// 
// 
// 
// Linear indexes of matched entries in data:
// 0, 2, 4
// 
// Using read-only data. Linear indexes of matched entries:
// 0, 2, 4

See Also