Crate slicemath

Source
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 and src2 element-wise and stores the results in dst. All slices must have the same length.
add_inplace
Adds all values in src1_dst and src2 element-wise and stores the results in src1_dst. All slices must have the same length.
add_scalar
Adds a scalar value to each element in src, storing the results in dst. All slices must have the same length.
add_scalar_inplace
Adds a scalar value to each element in src_dst, storing the results in src_dst.
apply_binary
Apply the closure f to each corresponding pair of elements of src1 and src2 and store the result in dst. All slices must have the same length.
apply_binary_inplace
Apply the closure f to each corresponding pair of elements of src1_dst and src2 and store the result in src1_dst. Both slices must have the same length.
apply_indexed_unary
Apply the closure f to each element of dst along with its index, and store the result in dst.
apply_ternary
Apply the closure f to each corresponding pair of elements of src1, src2, and src3, and store the result in dst. All slices must have the same length.
apply_ternary_inplace
Apply the closure f to each corresponding triple of elements of src1_dst, src2, and src3, and store the result in src1_dst. All slices must have the same length.
apply_unary
Apply the closure f to each element of src and store the result in dst. Both slices must have the same length.
apply_unary_inplace
Apply the closure F to each element in src_dst and store the result in src_dst.
copy
Copies each value in src to the corresponding position in dst. Both slices must have the same length.
div
Divides all values in src1 by src2 element-wise and stores the results in dst. All slices must have the same length.
div_inplace
Divides all values in src1_dst and src2 element-wise and stores the results in src1_dst. All slices must have the same length.
div_scalar
Divides each element in src by a scalar value, storing the results in dst. All slices must have the same length.
div_scalar_inplace
Divides each element in src_dst by a scalar value, storing the results in src_dst.
exclusive_scan
Apply the closure f to each neighbouring pair of elements in src, storing the result in dst. The first call of f is performed with the additional previous value prev, 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 of dst.
exclusive_scan_inplace
Apply the closure f to each neighbouring pair of elements in src_dst, storing the result in src_dst. The first call of f is performed with the additional previous value prev, 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 of src_dst.
fill
Copies value to every position of dst
inclusive_scan
Apply the closure f to each neighbouring pair of elements in src, storing the result in dst. The first element is copied as-is, and the first result of calling f on the first two elements of src in stored in the second position of dst.
inclusive_scan_inplace
Apply the closure f to each neighbouring pair of elements in src_dst, storing the result in src_dst. The first element is not modified, and the first result of calling f on the first two elements of src_dst in stored in the second position of src_dst.
linspace
Computes a linear sequence of uniformly spaced values, starting with first_value and ending either at or just before last_value, depending on endpoint. Results are written to dst, whose length is used to determine the step size between values.
mul
Multiplies all values src1 and src2 element-wise and stores the results in dst. All slices must have the same length.
mul_inplace
Multiplies all values in src1_dst and src2 element-wise and stores the results in src1_dst. All slices must have the same length.
mul_scalar
Multiplies a scalar value by each element in src, storing the results in dst. All slices must have the same length.
mul_scalar_inplace
Multiplies a scalar value by each element in src_dst, storing the results in src_dst.
negate
Negates each value in src and stores the results in dst. Both slices must have the same length.
negate_inplace
Negates each value in src_dst and stores the results in src_dst.
rdiv_scalar
Divides a scalar value by each element in src, storing the results in dst. All slices must have the same length.
rdiv_scalar_inplace
Divides a scalar value by each element in src_dst, storing the results in src_dst.
rsub_scalar
Subtracts each element in src from a scalar value, storing the results in dst. All slices must have the same length.
rsub_scalar_inplace
Subtracts each element in src_dst from a scalar value, storing the results in src_dst.
sub
Subtracts all values in src2 from src1 element-wise and stores the results in dst. All slices must have the same length.
sub_inplace
Subtracts all values in src2 from src1_dst element-wise and stores the results in src1_dst. All slices must have the same length.
sub_scalar
Subtracts a scalar value from each element in src, storing the results in dst. All slices must have the same length.
sub_scalar_inplace
Subtracts a scalar value from each element in src_dst, storing the results in src_dst.