Fork me on GitHub
Arraymancer Technical reference Tutorial Spellbook (How-To's) Under the hood

Module higher_order_foldreduce

Procs

proc fold[U, T](t: Tensor[U]; start_val: T; f: (T, U) -> T): T
Chain result = f(result, element) over all elements of the Tensor
Input:
  • A tensor to aggregate on
  • The starting value
  • The aggregation function. It is applied this way: new_aggregate = f(old_aggregate, current_value)
Result:
  • An aggregate of the function called on the starting value and all elements of the tensor
Usage:
a.fold(100,max) ## This compare 100 with the first tensor value and returns 100
                ## In the end, we will get the highest value in the Tensor or 100
                ## whichever is bigger.
  Source Edit
proc fold[U, T](t: Tensor[U]; start_val: Tensor[T];
              f: (Tensor[T], Tensor[U]) -> Tensor[T]; axis: int): Tensor[T]
Chain result = f(result, element) over all elements of the Tensor
Input:
  • A tensor to aggregate on
  • The starting value
  • The aggregation function. It is applied this way: new_aggregate = f(old_aggregate, current_value)
  • The axis to aggregate on
Result:
  • An Tensor with the aggregate of the function called on the starting value and all slices along the selected axis
  Source Edit
proc reduce[T](t: Tensor[T]; f: (T, T) -> T): T

Chain result = f(result, element) over all elements of the Tensor.

The starting value is the first element of the Tensor.

Input:
  • A tensor to aggregate on
  • The aggregation function. It is applied this way: new_aggregate = f(old_aggregate, current_value)
Result:
  • An aggregate of the function called all elements of the tensor
Usage:
a.reduce(max) ## This returns the maximum value in the Tensor.
  Source Edit
proc reduce[T](t: Tensor[T]; f: (Tensor[T], Tensor[T]) -> Tensor[T]; axis: int): Tensor[T] {.
noInit
.}

Chain result = f(result, element) over all elements of the Tensor.

The starting value is the first element of the Tensor.

Input:
  • A tensor to aggregate on
  • The aggregation function. It is applied this way: new_aggregate = f(old_aggregate, current_value)
  • An axis to aggregate on
Result:
  • A tensor aggregate of the function called all elements of the tensor
  Source Edit

Templates

template reduce_inline[T](t: Tensor[T]; op: untyped): untyped
  Source Edit
template fold_inline[T](t: Tensor[T]; op_initial, op_middle, op_final: untyped): untyped
  Source Edit
template reduce_axis_inline[T](t: Tensor[T]; reduction_axis: int; op: untyped): untyped
  Source Edit
template fold_axis_inline[T; ](t: Tensor[T]; accumType: typedesc; fold_axis: int;
                             op_initial, op_middle, op_final: untyped): untyped
  Source Edit