ArrayΒΆ

Class and companion object for managing one dimensional arrays on the CPU.

Note that this type shadows the unstaged Scala Array. In the case where an unstaged Array type is required, use the full scala.Array name.


Constructor

The following syntax is available for constructing Arrays from indexed functions:

(0::32){i => func(i) }

This returns an Array of size 32 with elements defined by func(i). More general Range forms can also be used, including strided (e.g. 0::2::8) and offset (e.g. 32::64). The iterator i will iterate over all values in the supplied range.


Static methods

object Array
def tabulate[T:Type](size: Index)(func: Index => T): Array[T]
Returns an immutable Array with the given size and elements defined by func.
def **

def fill[T:Type](size: Index)(func: => T): Array[T] = this.tabulate(size){ _
Returns an immutable Array with the given size and elements defined by func.
Note that while func does not depend on the index, it is still executed size times.
def empty[T:Type](size: Index): Array[T]
Returns an empty, mutable Array with the given size.
def apply[T:Type](elements: T*): Array[T]
Returns an immutable Array with the given elements.

Infix methods

class Array[T]
def length: Index
Returns the size of this Array.
def apply(i: Index): T
Returns the element at index i.
def update[A](i: Index, data: A)(implicit lift: Lift[A,T]): Unit
Updates the element at index i to data.
def foreach(func: T => Unit): Unit
Applies the function func on each element in the Array.
def map[R:Type](func: T => R): Array[R]
Returns a new Array created using the mapping func over each element in this Array.
def zip[S:Type,R:Type](that: Array[S])(func: (T,S) => R): Array[R]
Returns a new Array created using the pairwise mapping func over each element in this Array
and the corresponding element in that.
def reduce(rfunc: (T,T) => T): T
Reduces the elements in this Array into a single element using associative function rfunc.
def fold(init: T)(rfunc: (T,T) => T): T
Reduces the elements in this Array and the given initial value into a single element
using associative function rfunc.
def filter(cond: T => MBoolean): Array[T]
Returns a new Array with all elements in this Array which satisfy the given predicate cond.
def flatMap[R:Type](func: T => Array[R]): Array[R]
Returns a new Array created by concatenating the results of func applied to all elements in this Array.
def groupByReduce[K:Type,V:Type](key: A => K)(value: A => V)(reduce: (V,V) => V): HashMap[K,V]
Partitions this Array using the key function, then maps each element using value, and
finally combines values in each bin using the associative reduce function.
def mkString(delimeter: String)
Creates a string representation of this Array using the given delimeter.
def mkString(start: String, delimeter: String, stop: String): String
Creates a string representation of this Array using the given delimeter, bracketed by start and stop.
def reshape(rows: Index, cols: Index): Matrix[T]
Returns an immutable view of the data in this Array as a Matrix with given rows and cols.
def reshape(dim0: Index, dim1: Index, dim2: Index): Tensor3[T]
Returns an immutable view of the data in this Array as a Tensor3 with given dimensions.
def reshape(dim0: Index, dim1: Index, dim2: Index, dim3: Index): Tensor4[T]
Returns an immutable view of the data in this Array as a Tensor4 with given dimensions.
def reshape(dim0: Index, dim1: Index, dim2: Index, dim3: Index, dim4: Index): Tensor5[T]
Returns an immutable view of the data in this Array as a Tensor5 with given dimensions.
def !=(that: Array[T]): MBoolean = this.zip(that){(x,y) => x =!
Returns true if this Array and that differ by at least one element, false otherwise.
def ==(that: Array[T]): MBoolean = this.zip(that){(x,y) => x ==
Returns true if this Array and that contain the same elements, false otherwise.