Fork me on GitHub

src/arraymancer/tensor/accessors

Search:
Group by:
  Source Edit

Procs

proc atAxisIndex[T](t: Tensor[T]; axis, idx: int; length = 1): Tensor[T] {.
    noinit, inline.}
Returns a sliced tensor in the given axis index   Source Edit
proc atContiguousIndex[T](t: Tensor[T]; idx: int): T {.noSideEffect, inline.}
Return value of tensor at contiguous index i.e. as treat the tensor as flattened   Source Edit
proc atContiguousIndex[T](t: var Tensor[T]; idx: int): var T {.noSideEffect,
    inline.}
Return value of tensor at contiguous index (mutable) i.e. as treat the tensor as flattened   Source Edit

Iterators

iterator axis[T](t: Tensor[T]; axis, offset, size: int): Tensor[T] {.inline.}
  Source Edit
iterator axis[T](t: Tensor[T]; axis: int): Tensor[T] {.inline.}

Inline iterator over an axis.

Returns:

  • A slice along the given axis at each iteration.

Note: The slice dimension is not collapsed by default. You can use squeeze to collapse it.

Usage: .. code:: nim for subtensor in t.axis(1): # do stuff

  Source Edit
iterator enumerate[T](t: Tensor[T]): (int, T) {.inline.}
Enumerate Tensor values   Source Edit
iterator enumerate[T](t: Tensor[T]; offset, size: int): (int, T) {.inline,
    noSideEffect.}
Enumerate Tensor values (with offset)   Source Edit
iterator enumerateAxis[T](t: Tensor[T]; axis, offset, size: int): (int,
    Tensor[T]) {.inline.}
  Source Edit
iterator enumerateAxis[T](t: Tensor[T]; axis: int): (int, Tensor[T]) {.inline.}

Inline iterator over an axis.

Returns a tuple:

  • The index along the axis
  • A slice along the given axis at each iteration.

Note: The slice dimension is not collapsed by default. You can use squeeze to collapse it.

Usage: .. code:: nim for subtensor in t.axis(1): # do stuff

  Source Edit
iterator enumerateZip[T, U, V](t1: Tensor[T]; t2: Tensor[U]; t3: Tensor[V]): (
    int, T, U, V) {.inline, noSideEffect.}
Enumerate simultaneously on two tensors returning their elements in a tuple. Note: only tensors of the same shape will be zipped together.   Source Edit
iterator enumerateZip[T, U, V](t1: Tensor[T]; t2: Tensor[U]; t3: Tensor[V];
                               offset, size: int): (int, T, U, V) {.inline,
    noSideEffect.}
Enumerate simultaneously on two tensors returning their elements in a tuple. (with offset) Note: only tensors of the same shape will be zipped together.   Source Edit
iterator enumerateZip[T, U](t1: Tensor[T]; t2: Tensor[U]): (int, T, U) {.inline,
    noSideEffect.}
Enumerate simultaneously on two tensors returning their elements in a tuple. Note: only tensors of the same shape will be zipped together.   Source Edit
iterator enumerateZip[T, U](t1: Tensor[T]; t2: Tensor[U]; offset, size: int): (
    int, T, U) {.inline, noSideEffect.}
Enumerate simultaneously on two tensors returning their elements in a tuple. (with offset) Note: only tensors of the same shape will be zipped together.   Source Edit
iterator items[T](t: Tensor[T]): T {.inline, noSideEffect.}

Inline iterator on Tensor values

The iterator will iterate in C order regardingless of the tensor properties (Fortran layout, non-contiguous, slice ...). So 0, 0, 0 then 0, 0, 1 then ... then 0, 1, 0 ...

Usage: .. code:: nim for val in t: # items is implicitly called val += 42

  Source Edit
iterator items[T](t: Tensor[T]; offset, size: int): T {.inline, noSideEffect.}
Inline iterator on Tensor values (with offset)   Source Edit
iterator mitems[T](t: var Tensor[T]): var T {.inline, noSideEffect.}

Inline iterator on Tensor values (mutable, with offset)

Note: due to C++ restrictions and Nim current codegen on mutable iterator, it is not possible to use this iterator with the C++ backend or at the same time as Cuda (that uses C++)

  Source Edit
iterator mitems[T](t: var Tensor[T]; offset, size: int): var T {.inline,
    noSideEffect.}

Inline iterator on Tensor values (mutable, with offset)

Note: due to C++ restrictions and Nim current codegen on mutable iterator, it is not possible to use this iterator with the C++ backend or at the same time as Cuda (that uses C++)

  Source Edit
iterator mpairs[T](t: var Tensor[T]): (seq[int], var T) {.inline, noSideEffect.}

Inline iterator on Tensor (coordinates, values) (mutable)

Note: due to C++ restrictions and Nim current codegen on mutable iterator, it is not possible to use this iterator with the C++ backend or at the same time as Cuda (that uses C++)

  Source Edit
iterator mzip[T, U, V](t1: var Tensor[T]; t2: Tensor[U]; t3: Tensor[V]): (var T,
    U, V) {.inline, noSideEffect.}

Iterates simultaneously on two tensors returning their elements in a tuple. (mutable) Note: only tensors of the same shape will be zipped together.

Note: due to C++ restrictions and Nim current codegen on mutable iterator, it is not possible to use this iterator with the C++ backend or at the same time as Cuda (that uses C++)

  Source Edit
iterator mzip[T, U, V](t1: var Tensor[T]; t2: Tensor[U]; t3: Tensor[V];
                       offset, size: int): (var T, U, V) {.inline, noSideEffect.}

Iterates simultaneously on two tensors returning their elements in a tuple. (mutable, with offset) Note: only tensors of the same shape will be zipped together.

Note: due to C++ restrictions and Nim current codegen on mutable iterator, it is not possible to use this iterator with the C++ backend or at the same time as Cuda (that uses C++)

  Source Edit
iterator mzip[T, U](t1: var Tensor[T]; t2: Tensor[U]): (var T, U) {.inline,
    noSideEffect.}

Iterates simultaneously on two tensors returning their elements in a tuple. (mutable) Note: only tensors of the same shape will be zipped together.

Note: due to C++ restrictions and Nim current codegen on mutable iterator, it is not possible to use this iterator with the C++ backend or at the same time as Cuda (that uses C++)

  Source Edit
iterator mzip[T, U](t1: var Tensor[T]; t2: Tensor[U]; offset, size: int): (
    var T, U) {.inline, noSideEffect.}

Iterates simultaneously on two tensors returning their elements in a tuple. (mutable, with offset) Note: only tensors of the same shape will be zipped together.

Note: due to C++ restrictions and Nim current codegen on mutable iterator, it is not possible to use this iterator with the C++ backend or at the same time as Cuda (that uses C++)

  Source Edit
iterator pairs[T](t: Tensor[T]): (seq[int], T) {.inline, noSideEffect.}

Inline iterator on Tensor (coordinates, values)

The iterator will iterate in C order regardingless of the tensor properties (Fortran layout, non-contiguous, slice ...). So 0, 0, 0 then 0, 0, 1 then ... then 0, 1, 0 ...

It returns a tuple of (coordinates, value) like (@1,0,1, 1337)

Usage: .. code:: nim for coord, val in t: echo coord echo val .. code:: nim for coordval in t: echo coordval0 echo coordval1

  Source Edit
iterator zip[T, U, V](t1: Tensor[T]; t2: Tensor[U]; t3: Tensor[V]): (T, U, V) {.
    inline, noSideEffect.}
Iterates simultaneously on two tensors returning their elements in a tuple. Note: only tensors of the same shape will be zipped together.   Source Edit
iterator zip[T, U, V](t1: Tensor[T]; t2: Tensor[U]; t3: Tensor[V];
                      offset, size: int): (T, U, V) {.inline, noSideEffect.}
Iterates simultaneously on two tensors returning their elements in a tuple. (with offset) Note: only tensors of the same shape will be zipped together.   Source Edit
iterator zip[T, U](t1: Tensor[T]; t2: Tensor[U]): (T, U) {.inline, noSideEffect.}
Iterates simultaneously on two tensors returning their elements in a tuple. Note: only tensors of the same shape will be zipped together.   Source Edit
iterator zip[T, U](t1: Tensor[T]; t2: Tensor[U]; offset, size: int): (T, U) {.
    inline, noSideEffect.}
Iterates simultaneously on two tensors returning their elements in a tuple. (with offset) Note: only tensors of the same shape will be zipped together.   Source Edit
iterator zipAxis[T, U](a: Tensor[T]; b: Tensor[U]; axis: int): tuple[
    a: Tensor[T], b: Tensor[U]] {.inline.}

Inline iterator over 2 tensors over an axis.

Returns:

  • 2 slices along the given axis at each iteration.

Note: The slice dimension is not collapsed by default. You can use squeeze to collapse it.

Usage: .. code:: nim for subtensor in zipAxis(a, b, 1): # do stuff

  Source Edit
Arraymancer Technical reference Tutorial Spellbook (How-To's) Under the hood