MostlyHarmless 0.0.1
 
Loading...
Searching...
No Matches
marvin::math::vecops Namespace Reference

Collection of basic arithmetic operations on vectors, SIMD accelerated where possible. More...

Functions

template<FloatType T>
void add (T *lhs, const T *rhs, size_t size) noexcept
 
template<FloatType T>
void add (T *arr, T scalar, size_t size) noexcept
 
template<FloatArrayLike T>
void add (T &lhs, T &rhs) noexcept
 
template<FloatArrayLike T>
void add (T &arr, typename T::value_type scalar) noexcept
 
template<FloatType T>
void subtract (T *lhs, const T *rhs, size_t size) noexcept
 
template<FloatType T>
void subtract (T *arr, T scalar, size_t size) noexcept
 
template<FloatArrayLike T>
requires std::is_floating_point_v<typename T::value_type>
void subtract (T &lhs, const T &rhs) noexcept
 
template<FloatArrayLike T>
void subtract (T &arr, typename T::value_type scalar) noexcept
 
template<FloatType T>
void multiply (T *lhs, const T *rhs, size_t size) noexcept
 
template<FloatType T>
void multiply (T *arr, T scalar, size_t size) noexcept
 
template<FloatArrayLike T>
void multiply (T &lhs, const T &rhs) noexcept
 
template<FloatArrayLike T>
void multiply (T &arr, typename T::value_type scalar) noexcept
 
template<FloatType T>
void divide (T *lhs, const T *rhs, size_t size) noexcept
 
template<FloatType T>
void divide (T *arr, T scalar, size_t size) noexcept
 
template<FloatArrayLike T>
void divide (T &lhs, const T &rhs) noexcept
 
template<FloatArrayLike T>
void divide (T &arr, typename T::value_type scalar) noexcept
 
template<NumericType T>
void copy (T *lhs, const T *rhs, size_t size) noexcept
 
template<ArrayLike T>
void copy (T &lhs, const T &rhs) noexcept
 

Detailed Description

Collection of basic arithmetic operations on vectors, SIMD accelerated where possible.

On macOS this will use Accelerate's vDSP library for SIMD intrinsics. On Windows, Marvin has an optional dependency on Intel's IPP library. If it's found by CMake, these functions will use the IPP implementations of these functions. If it's not found, it will use the fallback implementations, which are simple for loops.
If you're struggling to get IPP installed, Sudara has a great blog post detailing the hoops you need to jump through to get it up and running.

Note that even when using SIMD, it's not guaranteed to be faster than what the compiler might generate with a for loop - I'd recommend benchmarking on the platform you're targeting with the kind of data you'll be using, and choosing whether to use these functions accordingly.

Function Documentation

◆ add() [1/4]

template<FloatArrayLike T>
void marvin::math::vecops::add ( T & arr,
typename T::value_type scalar )
noexcept

Adds the value of scalar to the values of lhs, and stores the result in lhs.

Parameters
arrThe destination array-like.
scalarThe value to add to each element of arr.

◆ add() [2/4]

template<FloatArrayLike T>
void marvin::math::vecops::add ( T & lhs,
T & rhs )
noexcept

Adds the values of rhs to the values of lhs, and stores the result in lhs. lhs.size() must == rhs.size().

Parameters
lhsThe destination array-like.
rhsThe source array-like.

◆ add() [3/4]

template<FloatType T>
void marvin::math::vecops::add ( T * arr,
T scalar,
size_t size )
noexcept

Adds the value of scalar to the values of lhs, and stores the result in lhs.

Parameters
arrA raw pointer to the dest array-like.
scalarThe value to add to each element of arr.
sizeThe number of elements in arr.

◆ add() [4/4]

template<FloatType T>
void marvin::math::vecops::add ( T * lhs,
const T * rhs,
size_t size )
noexcept

Adds the values of rhs to the values of lhs, and stores the result in lhs.

Parameters
lhsA raw pointer to the dest array-like.
rhsA raw pointer to the source array-like.
sizeThe number of elements in lhs and rhs.

◆ copy() [1/2]

template<ArrayLike T>
void marvin::math::vecops::copy ( T & lhs,
const T & rhs )
noexcept

Copies the contents of rhs into lhs. lhs.size() must == rhs.size().

Parameters
lhsThe destination array-like.
rhsThe source array-like.

◆ copy() [2/2]

template<NumericType T>
void marvin::math::vecops::copy ( T * lhs,
const T * rhs,
size_t size )
noexcept

Copies the contents of rhs into lhs.

Parameters
lhsA raw pointer to the destination array-like.
rhsA raw pointer to the source array-like.
sizeThe number of elements to copy.

◆ divide() [1/4]

template<FloatArrayLike T>
void marvin::math::vecops::divide ( T & arr,
typename T::value_type scalar )
noexcept

Divides the values of lhs by the value of scalar, and stores the result in lhs.

Parameters
arrThe destination array-like.
scalarThe value to divide each element in arr by.

◆ divide() [2/4]

template<FloatArrayLike T>
void marvin::math::vecops::divide ( T & lhs,
const T & rhs )
noexcept

Divides the values of lhs by the values of rhs, and stores the result in lhs. lhs.size() must == rhs.size().

Parameters
lhsThe destination array-like.
rhsThe source array-like.

◆ divide() [3/4]

template<FloatType T>
void marvin::math::vecops::divide ( T * arr,
T scalar,
size_t size )
noexcept

Divides the values of lhs by the value of scalar, and stores the result in lhs.

Parameters
arrA raw pointer to the dest array-like.
scalarThe value to divide each element in arr by.
sizeThe number of elements in lhs and rhs.

◆ divide() [4/4]

template<FloatType T>
void marvin::math::vecops::divide ( T * lhs,
const T * rhs,
size_t size )
noexcept

Divides the values of lhs by the values of rhs, and stores the result in lhs.

Parameters
lhsA raw pointer to the dest array-like.
rhsA raw pointer to the source array-like.
sizeThe number of elements in lhs and rhs.

◆ multiply() [1/4]

template<FloatArrayLike T>
void marvin::math::vecops::multiply ( T & arr,
typename T::value_type scalar )
noexcept

Multiplies the values of lhs by the value of scalar, and stores the result in lhs.

Parameters
arrThe destination array-like.
scalarThe value to multiply each element in arr by.

◆ multiply() [2/4]

template<FloatArrayLike T>
void marvin::math::vecops::multiply ( T & lhs,
const T & rhs )
noexcept

Multiplies the values of lhs by the values of rhs, and stores the result in lhs. lhs.size() must == rhs.size().

Parameters
lhsThe destination array-like.
rhsThe source array-like.

◆ multiply() [3/4]

template<FloatType T>
void marvin::math::vecops::multiply ( T * arr,
T scalar,
size_t size )
noexcept

Multiplies the values of lhs by value of scalar, and stores the result in lhs.

Parameters
arrA raw pointer to the dest array-like.
scalarThe value to multiply each element in arr by.
sizeThe number of elements in lhs and rhs.

◆ multiply() [4/4]

template<FloatType T>
void marvin::math::vecops::multiply ( T * lhs,
const T * rhs,
size_t size )
noexcept

Multiplies the values of lhs by the values of rhs, and stores the result in lhs.

Parameters
lhsA raw pointer to the dest array-like.
rhsA raw pointer to the source array-like.
sizeThe number of elements in lhs and rhs.

◆ subtract() [1/4]

template<FloatArrayLike T>
void marvin::math::vecops::subtract ( T & arr,
typename T::value_type scalar )
noexcept

Subtracts the value of scalar from the values of lhs, and stores the result in lhs.

Parameters
arrThe destination array-like.
scalarThe value to subtract from each element in arr.

◆ subtract() [2/4]

template<FloatArrayLike T>
requires std::is_floating_point_v<typename T::value_type>
void marvin::math::vecops::subtract ( T & lhs,
const T & rhs )
noexcept

Subtracts the values of rhs from the values of lhs, and stores the result in lhs. lhs.size() must == rhs.size().

Parameters
lhsThe destination array-like.
rhsThe source array-like.

◆ subtract() [3/4]

template<FloatType T>
void marvin::math::vecops::subtract ( T * arr,
T scalar,
size_t size )
noexcept

Subtracts the value of scalar from the values of lhs, and stores the result in lhs.

Parameters
arrA raw pointer to the dest array-like.
scalarThe value to subtract from each element in arr.
sizeThe number of elements in lhs and rhs.

◆ subtract() [4/4]

template<FloatType T>
void marvin::math::vecops::subtract ( T * lhs,
const T * rhs,
size_t size )
noexcept

Subtracts the values of rhs from the values of lhs, and stores the result in lhs.

Parameters
lhsA raw pointer to the dest array-like.
rhsA raw pointer to the source array-like.
sizeThe number of elements in lhs and rhs.