load help;


@[name]
dao.type.array
@[name]

@[title]
Multi-dimensional Numeric Array
@[title]

@[text]
Multi-dimentional numeric array is supported by Dao as @[green]array@[green] type.


@[subsection]Definition@[subsection]
@[code(syntax)]
# Elements Enumeration:
VectorEnumeration  ::= '[' ExpressionList ']'
MatrixEnumeration  ::= '[' ExpressionList { ';' ExpressionList } ']'
VectorEnumeration2 ::= 'array' '{' ExpressionList '}'
MatrixEnumeration2 ::= 'array' '{' ExpressionList { ';' ExpressionList } '}'

# Elements of Arithmetic Progression sequence: count ~ start [ ~ step ]
ArrayByArithProg  ::= '[' Expression ':' [ Expression ':' ] Expression ']'
ArrayByArithProg2 ::= 'array' '{' Expression ':' [ Expression ':' ] Expression '}'

Array ::= VectorEnumeration | MatrixEnumeration | ArrayByArithProg
          | VectorEnumeration2 | MatrixEnumeration2 | ArrayByArithProg2
@[code(syntax)]
Please note that @[green]VectorEnumeration@[green] or @[green]VectorEnumeration2@[green]
can still create a matrix or a multi-dimensional array, 
if the @[green]ExpressionList@[green] produces a list of arrays.


Four numeric types are supported by the @[green]array@[green] type:
@[green]int@[green], @[green]float@[green], @[green]double@[green]
and @[green]complex@[green]. When an array is created by enumeration without 
explicit type declaration, its numeric type is inferred from the first expression 
of the expression list, if the enumeration is not empty; otherwise, 
@[green]float@[green] will be used as the numeric type.


Dao supports a number of built-in operations for array. For arithmetic operations, 
they are always supported element-wise operations. 


@[subsection]Examples@[subsection]
@[code]
vec1 = [1, 2, 3]  # array<int> vector, or 1x3 matrix;
vec2 = [1.0; 2; 3]  # array<float> 3x1 matrix, or transposed vector;
mat1 = [1D, 2; 3, 4]  # array<double> 2x2 matrix;
mat2 = [ [1, 2], [3, 4] ]  # 2x2 matrix
mat3 = [ [1, 2, 3] : 5 ]   # 5x3 matrix;
mat4 = array{ 1, 2; 3, 4 }  # 2x2 matrix
@[code]

@[text]


@[name]
dao.type.array.method
@[name]

@[title]
Array methods
@[title]

@[text]

@[code]
dim( self :array, i : int )=>int
dim( self :array )=>array<int>
index( self :array, i : int )=>array<int>
size( self :array )=>int
resize( self :array, dims :array<int> )
reshape( self :array, dims :array<int> )

permute( self :array, dims :array<int> )
transpose( self :array )
max( self :array<@ITEM> )=>tuple<@ITEM,int>
min( self :array<@ITEM> )=>tuple<@ITEM,int>
sum( self :array<@ITEM> )=>@ITEM
varn( self :array )=>double
reverse( self :array<@ITEM> )=>array<@ITEM>
rank( self :array<any>, order :enum<ascend,descend>=$ascend, k=0 )=>array<int>
sort( self :array<@T>, order :enum<ascend,descend>=$ascend, k=0 )=>array<@T>

fft( self :array<complex>, direction :enum<forward, backward> )

map( self :array<@T> )[item:@T,I:int,J:int,K:int,L:int,M:int=>@T2]=>array<@T2>
reduce( self :array<@T> )[item:@T,res:@T,I:int,J:int,K:int,L:int,M:int=>@T]=>@T
reduce( self :array<@T>, init :@V )[item:@T,res:@V,I:int,J:int,K:int,L:int,M:int=>@V]=>@V
select( self :array<@T> )[item:@T,I:int,J:int,K:int,L:int,M:int=>int]=>list<@T>
index( self :array<@T> )[item:@T,I:int,J:int,K:int,L:int,M:int=>int]=>list<array<int>>
count( self :array<@T> )[item:@T,I:int,J:int,K:int,L:int,M:int=>int]=>int
iterate( self :array<@T> )[item:@T,I:int,J:int,K:int,L:int,M:int]
apply( self :array<@T> )[item:@T,I:int,J:int,K:int,L:int,M:int=>@T]=>array<@T>
@[code]

@[text]




@[name]
dao.type.array.method.dim
@[name]

@[title]
Array method dim()
@[title]

@[name]
dao.type.array.method.index
@[name]

@[title]
Array method index()
@[title]
