Expand description
A library for element-wise mathematical operations on single or multiple slices. In general, methods in this library will check array sizes only once to confirm that all sizes match, and then perform unchecked array accesses for performance. If multiple arrays with mismatched sizes are passed, the methods will panic.
Methods for common mathematical operations are provided in many combinations of flavours, such as in-place and out-of-place as well as binary operations on mixtures of arrays and scalars. Representative examples of the nomenclature used here include
add
to perform element-wise addition of two arrays, storing result in a third output array.add_inplace
to perform element-wise addition of two arrays, storing the result in one of the input arrays.sub_scalar
to subtract a common scalar value from each element in an array, storing the result in a separate output array.rdiv_scalar_inplace
to divide a scalar by each element in an array and store the result in place
More general methods are provided as well which take simple closures
to be applied to each element, which allow you to perform other
operations not included here, such as apply_unary
, apply_binary_inplace
,
apply_ternary
, exclusive_scan_inplace
, etc.
Enums§
- EndPoint
- Whether or not to include the endpoint in a range of values
Functions§
- add
- Adds all values in
src1
andsrc2
element-wise and stores the results indst
. All slices must have the same length. - add_
inplace - Adds all values in
src1_dst
andsrc2
element-wise and stores the results insrc1_dst
. All slices must have the same length. - add_
scalar - Adds a scalar value to each element in
src
, storing the results indst
. All slices must have the same length. - add_
scalar_ inplace - Adds a scalar value to each element in
src_dst
, storing the results insrc_dst
. - apply_
binary - Apply the closure
f
to each corresponding pair of elements ofsrc1
andsrc2
and store the result indst
. All slices must have the same length. - apply_
binary_ inplace - Apply the closure
f
to each corresponding pair of elements ofsrc1_dst
andsrc2
and store the result insrc1_dst
. Both slices must have the same length. - apply_
indexed_ unary - Apply the closure
f
to each element ofdst
along with its index, and store the result indst
. - apply_
ternary - Apply the closure
f
to each corresponding pair of elements ofsrc1
,src2
, andsrc3
, and store the result indst
. All slices must have the same length. - apply_
ternary_ inplace - Apply the closure
f
to each corresponding triple of elements ofsrc1_dst
,src2
, andsrc3
, and store the result insrc1_dst
. All slices must have the same length. - apply_
unary - Apply the closure
f
to each element ofsrc
and store the result indst
. Both slices must have the same length. - apply_
unary_ inplace - Apply the closure
F
to each element insrc_dst
and store the result insrc_dst
. - copy
- Copies each value in
src
to the corresponding position indst
. Both slices must have the same length. - div
- Divides all values in
src1
bysrc2
element-wise and stores the results indst
. All slices must have the same length. - div_
inplace - Divides all values in
src1_dst
andsrc2
element-wise and stores the results insrc1_dst
. All slices must have the same length. - div_
scalar - Divides each element in
src
by a scalar value, storing the results indst
. All slices must have the same length. - div_
scalar_ inplace - Divides each element in
src_dst
by a scalar value, storing the results insrc_dst
. - exclusive_
scan - Apply the closure
f
to each neighbouring pair of elements insrc
, storing the result indst
. The first call off
is performed with the additional previous valueprev
, which may be thought of as appearing one position before the beginning of the input array, and the result of this call is stored in the first position ofdst
. - exclusive_
scan_ inplace - Apply the closure
f
to each neighbouring pair of elements insrc_dst
, storing the result insrc_dst
. The first call off
is performed with the additional previous valueprev
, which may be thought of as appearing one position before the beginning of the input array, and the result of this call is stored in the first position ofsrc_dst
. - fill
- Copies
value
to every position ofdst
- inclusive_
scan - Apply the closure
f
to each neighbouring pair of elements insrc
, storing the result indst
. The first element is copied as-is, and the first result of callingf
on the first two elements ofsrc
in stored in the second position ofdst
. - inclusive_
scan_ inplace - Apply the closure
f
to each neighbouring pair of elements insrc_dst
, storing the result insrc_dst
. The first element is not modified, and the first result of callingf
on the first two elements ofsrc_dst
in stored in the second position ofsrc_dst
. - linspace
- Computes a linear sequence of uniformly spaced values, starting with
first_value
and ending either at or just beforelast_value
, depending onendpoint
. Results are written todst
, whose length is used to determine the step size between values. - mul
- Multiplies all values
src1
andsrc2
element-wise and stores the results indst
. All slices must have the same length. - mul_
inplace - Multiplies all values in
src1_dst
andsrc2
element-wise and stores the results insrc1_dst
. All slices must have the same length. - mul_
scalar - Multiplies a scalar value by each element in
src
, storing the results indst
. All slices must have the same length. - mul_
scalar_ inplace - Multiplies a scalar value by each element in
src_dst
, storing the results insrc_dst
. - negate
- Negates each value in
src
and stores the results indst
. Both slices must have the same length. - negate_
inplace - Negates each value in
src_dst
and stores the results insrc_dst
. - rdiv_
scalar - Divides a scalar value by each element in
src
, storing the results indst
. All slices must have the same length. - rdiv_
scalar_ inplace - Divides a scalar value by each element in
src_dst
, storing the results insrc_dst
. - rsub_
scalar - Subtracts each element in
src
from a scalar value, storing the results indst
. All slices must have the same length. - rsub_
scalar_ inplace - Subtracts each element in
src_dst
from a scalar value, storing the results insrc_dst
. - sub
- Subtracts all values in
src2
fromsrc1
element-wise and stores the results indst
. All slices must have the same length. - sub_
inplace - Subtracts all values in
src2
fromsrc1_dst
element-wise and stores the results insrc1_dst
. All slices must have the same length. - sub_
scalar - Subtracts a scalar value from each element in
src
, storing the results indst
. All slices must have the same length. - sub_
scalar_ inplace - Subtracts a scalar value from each element in
src_dst
, storing the results insrc_dst
.