Integer Array |
Shared implementation of the integer array. This class implements interfaces SharedDataT<Int32>, ICloneable, IFormattable, IList<Int32>, IList
This topic contains the following sections:
Constructor | Description | Performance |
---|---|---|
set size | Creates new instance of IntegerArray. | |
default size | Creates new instance of IntegerArray with default zero size. | |
set size and buffer capasity | Creates new instance of IntegerArray. | |
copy from array | Creates IntegerArray with elements from specified array. |
There are also static methods for quick creation of IntegerArray.
Method | Description | Performance |
---|---|---|
random permute | Creates the IntegerArray of given size which is random permute of numbers from 0 to size - 1. | |
sample of a distribution | Creates the IntegerArray of given size with elements that are sampled from the specified distribution. |
An IntegerArray instance has a set of properties:
Property | Description | Performance |
---|---|---|
length | Number of elements in the collection. | |
a certain element | Returns certain element of the array by its index. | |
is fixed size | Returns true if and only if collection has fixed size. | |
is read only | Returns true if and only if collection is read only. |
Method | Description | Performance |
---|---|---|
resize | Resize container to specified size. New Length and internal capacity will be set to specified value. Missing values will be filled with zeros. | |
sort | Sort elements of the collection. | |
add | Adds new element to IntegerArray. Adds new element to IntegerArray and returns the index in which the element is placed. | |
insert | Insert element on position. All elements starting from index to collection size will be shifted to the right. Insert element on position. All elements starting from index to collection size will be shifted to the right. | |
remove | Remove element with smallest index equal to specified. All element with indices greater than removed will be shifted left. Remove element stored on position. All element with indices greater than removed will be shifted left. | |
clear | Drop all elements from IntegerArray. | |
contains | Returns true if and only if there is element equal to value in IntegerArray. | |
index of | Returns smallest index of specified element in IntegerArray. If there is no such element in IntegerArray returns -1. | |
get enumerator | Returns an enumerator that iterates through a collection. |
Method | Description | Performance |
---|---|---|
copy to array | Copy data from integer array to native c# array. Copy starting at a particular array index: | |
clone | Supports cloning, which creates a new instance of a class with the same value as an existing instance. | |
to string | Formats the value of the current instance using the specified format. |
Method | Description | Performance |
---|---|---|
save | Saves IntegerArray to CSV file at the specified path. | |
load | Loads IntegerArray from CSV file at the specified path. |
The following example demonstrates the Integer Array usage:
1using System; 2using FinMath.DataStructures; 3using FinMath.LinearAlgebra; 4 5namespace FinMath.Samples 6{ 7 class IntegerArraySample 8 { 9 static void Main() 10 { 11 // Input parameters. 12 const Int32 rowsCount = 7; 13 const Int32 columnsCount = 5; 14 15 // Generating input. 16 Matrix matrix = Matrix.Random(rowsCount, columnsCount); 17 Console.WriteLine("Input matrix:"); 18 Console.WriteLine(matrix.ToString("0.000")); 19 // Generating random permutation of numbers from 0 to rowsCount - 1. 20 IntegerArray rowsPermutation = IntegerArray.Random(rowsCount); 21 Console.WriteLine("Rows permutation:"); 22 Console.WriteLine(rowsPermutation); 23 // Generating random permutation of numbers from 0 to columnsCount - 1. 24 IntegerArray columnsPermutationTemp = IntegerArray.Random(columnsCount); 25 IntegerArray columnsPermutation = new IntegerArray(); 26 27 // IntegerArray can be used just like C# List<Int32> collection. 28 // You can store elements into it using Add(Int32) method, and it will expand itself 29 // if there is no enough memory to complete operation. 30 for (Int32 i = 0; i < columnsCount; ++i) 31 columnsPermutation.Add(columnsPermutationTemp[i]); 32 33 Console.WriteLine("Columns permutation:"); 34 Console.WriteLine(columnsPermutation); 35 36 // Apply permutations: 37 matrix.PermuteRows(rowsPermutation); 38 matrix.PermuteColumns(columnsPermutation); 39 40 // Output results: 41 Console.WriteLine(); 42 Console.WriteLine("Matrix after permutations:"); 43 Console.WriteLine(matrix.ToString("0.000")); 44 } 45 } 46}