ILNumerics Ultimate VS

InArrayT  Conversion (Array to InArrayT)

ILNumerics Ultimate VS Documentation
ILNumerics - Technical Application Development
Implicitly convert n-dimensional System.Array to ILNumerics array.

[ILNumerics Core Module]

Namespace:  ILNumerics
Assembly:  ILNumerics.Core (in ILNumerics.Core.dll) Version: 5.4.0.0 (5.4.7431.3055)
Syntax

public static implicit operator InArray<T> (
	Array A
)

Parameters

A
Type: SystemArray
System.Array of arbitrary size

Return Value

Type: InArrayT
If A is null: empty array. Otherwise a new ILNumerics array of the same size as A.
Exceptions

ExceptionCondition
InvalidCastExceptionIf the type of the elements in A cannot get converted to T.
InvalidOperationExceptionIf the type of the elements in A is not supported.
Remarks

Elements of A will be copied to elements of the output array (shallow copy). The following element types are supported for A and T: double, float, int, uint, long, ulong, short, ushort, sbyte, byte.

Alternatively, A may consists out of scalar Arrays (or RetArray, InArray, OutArray) of one of the above element types.

The resulting Array will reflect all dimensions of A. Due to the fact that .NET System.Arrays are stored in row major order and ILNumerics stores array in column major (for compatibility with e.g. Matlab and Fortran) the resulting Array will have its dimensions reverted! For matrices this corresponds to a matrix transpose.

System.Convert is used for the conversion of elements in A to destination elements. This includes widening and narrowing conversions. When, for example, array elements of type double are provided and T is Int32 the conversion will round the source elements. See the examples below.

[ILNumerics Core Module]

Examples

VB Code Example
'' Elements of System.Value types:
Dim A1 As Array(Of Double) = { 1, 2, 3 }  ' provide int elements
Dim A2 As Array(Of Double) = { 1.0, 2.9, 3.4, 5.12 }  ' provide double elements
Dim A As Double = 5
Dim B As Double = 6
Dim C As Double = 7

Dim A3 As Array(Of Double) = { A, B, C } ' provide double variables

Dim A4 As Array(Of Double) = { ILMath.cos(A), ILMath.tan(B) * C, C, 3 } ' provide mixed element types, including scalar Array
C# Code Example
Array<double> A1 = new[] { 1, ILMath.cos(2.0), 3, 4 };
double B = -1, C = 10;
Array<double> A2 = new[] { ILMath.cos(A1[1]), ILMath.tan(B) * C, C, 3 };
// create from multidimensional System.Array 
Array<int> A3 = new[,] { { 11, 12, 13 }, { 21, 22, 23 } };
// narrowing conversion: from double to int (note the rounding rules!)
Array<int> A4 = new[,] { { 11.9, 12.1, 13 }, { 21.5, 22.5, 23 } };
//<Int32> [3,2]
//    12         22 
//    12         22 
//    13         23
See Also

Reference