Procs
proc fold[U, T](arg: Tensor[U]; start_val: T; f: (T, U) -> T): T {.effectsOf: f.}
-
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: .. code:: nim 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](arg: Tensor[U]; start_val: Tensor[T]; f: (Tensor[T], Tensor[U]) -> Tensor[T]; axis: int): Tensor[T] {. effectsOf: f.}
-
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](arg: Tensor[T]; f: (T, T) -> T): T {.effectsOf: f.}
-
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: .. code:: nim a.reduce(max) ## This returns the maximum value in the Tensor.
Source Edit proc reduce[T](arg: Tensor[T]; f: (Tensor[T], Tensor[T]) -> Tensor[T]; axis: int): Tensor[ T] {.noinit, effectsOf: f.}
-
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 fold_axis_inline[T](arg: Tensor[T]; accumType: typedesc; fold_axis: int; op_initial, op_middle, op_final: untyped): untyped
- Source Edit
template fold_inline[T](arg: Tensor[T]; op_initial, op_middle, op_final: untyped): untyped
- Source Edit
template reduce_axis_inline[T](arg: Tensor[T]; reduction_axis: int; op: untyped): untyped
- Source Edit
template reduce_inline[T](arg: Tensor[T]; op: untyped): untyped
- Source Edit