Stratax
Scientific computing containers and operations
Loading...
Searching...
No Matches
Arithmetic.hpp File Reference

Go to the source code of this file.

Functions

template<Array A>
void require_same_arithmetic_shape (const A &lhs, const A &rhs)
 Verifies that two arrays have the same shape before arithmetic.
template<Array A>
operator+ (const A &lhs, const A &rhs)
 Adds two arrays element by element.
template<Array A>
operator- (const A &lhs, const A &rhs)
 Subtracts two arrays element by element.
template<Array A>
operator* (const A &lhs, const A &rhs)
 Multiplies two arrays element by element.
template<Array A>
operator/ (const A &lhs, const A &rhs)
 Divides two arrays element by element.
template<Array A, Numeric Scalar>
operator+ (const A &lhs, const Scalar &rhs)
 Adds a scalar to every element of an array.
template<Array A, Numeric Scalar>
operator- (const A &lhs, const Scalar &rhs)
 Subtracts a scalar from every element of an array.
template<Array A, Numeric Scalar>
operator* (const A &lhs, const Scalar &rhs)
 Multiplies every element of an array by a scalar.
template<Array A, Numeric Scalar>
operator/ (const A &lhs, const Scalar &rhs)
 Divides every element of an array by a scalar.
template<Numeric Scalar, Array A>
operator+ (const Scalar &lhs, const A &rhs)
 Adds an array to a scalar.
template<Numeric Scalar, Array A>
operator- (const Scalar &lhs, const A &rhs)
 Subtracts each array element from a scalar.
template<Numeric Scalar, Array A>
operator* (const Scalar &lhs, const A &rhs)
 Multiplies an array by a scalar.
template<Numeric Scalar, Array A>
operator/ (const Scalar &lhs, const A &rhs)
 Divides a scalar by each array element.
template<Array A>
A & operator+= (A &lhs, const A &rhs)
 Adds an array to itself in place.
template<Array A>
A & operator-= (A &lhs, const A &rhs)
 Subtracts an array from itself in place.
template<Array A>
A & operator*= (A &lhs, const A &rhs)
 Multiplies an array by another array in place.
template<Array A>
A & operator/= (A &lhs, const A &rhs)
 Divides an array by another array in place.
template<Array A, Numeric Scalar>
A & operator+= (A &lhs, const Scalar &rhs)
 Adds a scalar to an array in place.
template<Array A, Numeric Scalar>
A & operator-= (A &lhs, const Scalar &rhs)
 Subtracts a scalar from an array in place.
template<Array A, Numeric Scalar>
A & operator*= (A &lhs, const Scalar &rhs)
 Multiplies an array by a scalar in place.
template<Array A, Numeric Scalar>
A & operator/= (A &lhs, const Scalar &rhs)
 Divides an array by a scalar in place.
template<Array A>
operator- (const A &arr)
 Negates every element of an array.
template<Array A>
operator+ (const A &arr)
 Returns an array unchanged.

Function Documentation

◆ operator*() [1/3]

template<Array A>
A operator* ( const A & lhs,
const A & rhs )

Multiplies two arrays element by element.

Parameters
lhsLeft-hand operand.
rhsRight-hand operand.
Returns
Array containing the element-wise product.
Exceptions
Exceptions::ShapeErrorIf the operands do not match in shape.

Definition at line 93 of file Arithmetic.hpp.

References require_same_arithmetic_shape().

◆ operator*() [2/3]

template<Array A, Numeric Scalar>
A operator* ( const A & lhs,
const Scalar & rhs )

Multiplies every element of an array by a scalar.

Parameters
lhsArray operand.
rhsScalar operand.
Returns
Array containing the element-wise product.

Definition at line 201 of file Arithmetic.hpp.

◆ operator*() [3/3]

template<Numeric Scalar, Array A>
A operator* ( const Scalar & lhs,
const A & rhs )

Multiplies an array by a scalar.

Parameters
lhsScalar operand.
rhsArray operand.
Returns
Array containing the element-wise product.

Definition at line 291 of file Arithmetic.hpp.

◆ operator*=() [1/2]

template<Array A>
A & operator*= ( A & lhs,
const A & rhs )

Multiplies an array by another array in place.

Parameters
lhsLeft-hand operand to modify.
rhsRight-hand operand.
Returns
Reference to the updated array.
Exceptions
Exceptions::ShapeErrorIf the operands do not match in shape.

Definition at line 367 of file Arithmetic.hpp.

◆ operator*=() [2/2]

template<Array A, Numeric Scalar>
A & operator*= ( A & lhs,
const Scalar & rhs )

Multiplies an array by a scalar in place.

Parameters
lhsArray to modify.
rhsScalar operand.
Returns
Reference to the updated array.

Definition at line 429 of file Arithmetic.hpp.

◆ operator+() [1/4]

template<Array A>
A operator+ ( const A & arr)

Returns an array unchanged.

Parameters
arrArray operand.
Returns
Copy of the input array.

Definition at line 472 of file Arithmetic.hpp.

◆ operator+() [2/4]

template<Array A>
A operator+ ( const A & lhs,
const A & rhs )

Adds two arrays element by element.

Parameters
lhsLeft-hand operand.
rhsRight-hand operand.
Returns
Array containing the element-wise sum.
Exceptions
Exceptions::ShapeErrorIf the operands do not match in shape.

Definition at line 35 of file Arithmetic.hpp.

References require_same_arithmetic_shape().

◆ operator+() [3/4]

template<Array A, Numeric Scalar>
A operator+ ( const A & lhs,
const Scalar & rhs )

Adds a scalar to every element of an array.

Parameters
lhsArray operand.
rhsScalar operand.
Returns
Array containing the element-wise sum.

Definition at line 155 of file Arithmetic.hpp.

◆ operator+() [4/4]

template<Numeric Scalar, Array A>
A operator+ ( const Scalar & lhs,
const A & rhs )

Adds an array to a scalar.

Parameters
lhsScalar operand.
rhsArray operand.
Returns
Array containing the element-wise sum.

Definition at line 254 of file Arithmetic.hpp.

◆ operator+=() [1/2]

template<Array A>
A & operator+= ( A & lhs,
const A & rhs )

Adds an array to itself in place.

Parameters
lhsLeft-hand operand to modify.
rhsRight-hand operand.
Returns
Reference to the updated array.
Exceptions
Exceptions::ShapeErrorIf the operands do not match in shape.

Definition at line 335 of file Arithmetic.hpp.

◆ operator+=() [2/2]

template<Array A, Numeric Scalar>
A & operator+= ( A & lhs,
const Scalar & rhs )

Adds a scalar to an array in place.

Parameters
lhsArray to modify.
rhsScalar operand.
Returns
Reference to the updated array.

Definition at line 399 of file Arithmetic.hpp.

◆ operator-() [1/4]

template<Array A>
A operator- ( const A & arr)

Negates every element of an array.

Parameters
arrArray operand.
Returns
Array containing the negated values.

Definition at line 459 of file Arithmetic.hpp.

◆ operator-() [2/4]

template<Array A>
A operator- ( const A & lhs,
const A & rhs )

Subtracts two arrays element by element.

Parameters
lhsLeft-hand operand.
rhsRight-hand operand.
Returns
Array containing the element-wise difference.
Exceptions
Exceptions::ShapeErrorIf the operands do not match in shape.

Definition at line 64 of file Arithmetic.hpp.

References require_same_arithmetic_shape().

◆ operator-() [3/4]

template<Array A, Numeric Scalar>
A operator- ( const A & lhs,
const Scalar & rhs )

Subtracts a scalar from every element of an array.

Parameters
lhsArray operand.
rhsScalar operand.
Returns
Array containing the element-wise difference.

Definition at line 178 of file Arithmetic.hpp.

◆ operator-() [4/4]

template<Numeric Scalar, Array A>
A operator- ( const Scalar & lhs,
const A & rhs )

Subtracts each array element from a scalar.

Parameters
lhsScalar operand.
rhsArray operand.
Returns
Array containing the element-wise difference.

Definition at line 268 of file Arithmetic.hpp.

◆ operator-=() [1/2]

template<Array A>
A & operator-= ( A & lhs,
const A & rhs )

Subtracts an array from itself in place.

Parameters
lhsLeft-hand operand to modify.
rhsRight-hand operand.
Returns
Reference to the updated array.
Exceptions
Exceptions::ShapeErrorIf the operands do not match in shape.

Definition at line 351 of file Arithmetic.hpp.

◆ operator-=() [2/2]

template<Array A, Numeric Scalar>
A & operator-= ( A & lhs,
const Scalar & rhs )

Subtracts a scalar from an array in place.

Parameters
lhsArray to modify.
rhsScalar operand.
Returns
Reference to the updated array.

Definition at line 414 of file Arithmetic.hpp.

◆ operator/() [1/3]

template<Array A>
A operator/ ( const A & lhs,
const A & rhs )

Divides two arrays element by element.

Parameters
lhsLeft-hand operand.
rhsRight-hand operand.
Returns
Array containing the element-wise quotient.
Exceptions
Exceptions::ShapeErrorIf the operands do not match in shape.
Exceptions::ZeroDivisionErrorIf any divisor element is zero.

Definition at line 123 of file Arithmetic.hpp.

References require_same_arithmetic_shape().

◆ operator/() [2/3]

template<Array A, Numeric Scalar>
A operator/ ( const A & lhs,
const Scalar & rhs )

Divides every element of an array by a scalar.

Parameters
lhsArray operand.
rhsScalar operand.
Returns
Array containing the element-wise quotient.
Exceptions
Exceptions::ZeroDivisionErrorIf the scalar is zero.

Definition at line 226 of file Arithmetic.hpp.

◆ operator/() [3/3]

template<Numeric Scalar, Array A>
A operator/ ( const Scalar & lhs,
const A & rhs )

Divides a scalar by each array element.

Parameters
lhsScalar operand.
rhsArray operand.
Returns
Array containing the element-wise quotient.
Exceptions
Exceptions::ZeroDivisionErrorIf any array element is zero.

Definition at line 307 of file Arithmetic.hpp.

◆ operator/=() [1/2]

template<Array A>
A & operator/= ( A & lhs,
const A & rhs )

Divides an array by another array in place.

Parameters
lhsLeft-hand operand to modify.
rhsRight-hand operand.
Returns
Reference to the updated array.
Exceptions
Exceptions::ShapeErrorIf the operands do not match in shape.
Exceptions::ZeroDivisionErrorIf any divisor element is zero.

Definition at line 384 of file Arithmetic.hpp.

◆ operator/=() [2/2]

template<Array A, Numeric Scalar>
A & operator/= ( A & lhs,
const Scalar & rhs )

Divides an array by a scalar in place.

Parameters
lhsArray to modify.
rhsScalar operand.
Returns
Reference to the updated array.
Exceptions
Exceptions::ZeroDivisionErrorIf the scalar is zero.

Definition at line 445 of file Arithmetic.hpp.

◆ require_same_arithmetic_shape()

template<Array A>
void require_same_arithmetic_shape ( const A & lhs,
const A & rhs )

Verifies that two arrays have the same shape before arithmetic.

Parameters
lhsLeft-hand operand.
rhsRight-hand operand.
Exceptions
Exceptions::ShapeErrorIf the operands do not match in size or shape.

Definition at line 16 of file Arithmetic.hpp.

References stratax::core::validation::require_same_shape().

Referenced by operator*(), operator+(), operator-(), and operator/().