MatrixBase#

template<typename Derived>
class MatrixBase#

Base class inherited by all matrices, vectors and related expressions.

If you want to write a function that accepts any matrix, vector or expression, just use this class as the argument type. For example, the following function calculates the mean value of all elements in a given matrix, vector or expression x,

   template<typename Derived>
auto mean(mocca::MatrixBase<Derived> &x)
{
    return sum(x) / x.size();
}

Template Parameters:

  • Derived - Derived class, either a matrix, vector or an expression

Public Types

using traits = typename internal::type_traits<Derived>#

Type traits of the MatrixBase.

using value_type = typename traits::value_type#

Type of the elements in the expression, vector or matrix.

Public Functions

MatrixBase() = default#

Default Constructor.

Complexity: Constant

virtual ~MatrixBase() = default#

Default Destructor.

Complexity: Constant

constexpr index_t size() const noexcept#

Complexity: Constant

Returns:

the number of entries in the container. In sparse objects, this routines returns the number of non-zeros elements.

constexpr index_t rows() const noexcept#

Complexity: Constant

Returns:

the number of rows in the container

constexpr index_t cols() const noexcept#

Complexity: Constant

Returns:

the number of columns in the container

Derived &derived()#

Complexity: Constant

Returns:

reference to the derived object in order to access its methods

const Derived &derived() const#

Complexity: Constant

Returns:

const reference to the derived object in order to access its methods

auto transpose() const#

Complexity: Constant

Warning

If you want to replace the matrix by its transpose, do not use:

mat = mat.transpose(); 
Instead, do
mat.tranpose_inplace() 
to correctly transpose the matrix and allows MOCCA to optimize the operation.

Returns:

an abstract expression representing the transpose of the matrix, vector or expression

auto T() const#

Alias for transpose()

template<typename E>
Derived &operator+=(const MatrixBase<E> &expr)#

Compound Operator (Addition). Evaluates the sum between *this and the expression expr, then assign the results to *this.

Complexity: Linear in this->size() (Typical)

Parameters:

expr[in] a matrix, vector or expression

Throws:

std::length_error – if ``*this`` and ``expr`` have mismatch dimensions

Returns:

a reference to *this

template<typename E>
Derived &operator-=(const MatrixBase<E> &expr)#

Compound Operator (Subtraction). Evaluates the subtraction between *this and the expression expr, then assign the results to *this.

Complexity: Linear in this->size() (Typical)

Parameters:

expr[in] a matrix, vector or expression

Throws:

std::length_error – if ``*this`` and ``expr`` have mismatch dimensions

Returns:

a reference to *this

template<typename E>
Derived &operator*=(const MatrixBase<E> &expr)#

Compound Operator (Multiplication). Evaluates the element-wise multiplication between *this and the expression expr, then assign the results to *this.

Complexity: Linear in this->size() (Typical)

Parameters:

expr[in] a matrix, vector or expression

Throws:

std::length_error – if ``*this`` and ``expr`` have mismatch dimensions

Returns:

a reference to *this

template<typename E>
Derived &operator/=(const MatrixBase<E> &expr)#

Compound Operator (Division). Evaluates the element-wise division between *this and the expression expr, then assign the results to *this.

Complexity: Linear in this->size() (Typical)

Parameters:

expr[in] a matrix, vector or expression

Throws:

std::length_error – if ``*this`` and ``expr`` have mismatch dimensions

Returns:

a reference to *this

template<typename S, internal::require_numeric_type<S> = true>
Derived &operator+=(S scalar)#

Compound Operator (Addition). Sum a scalar to all elements in the container.

Complexity: Linear in this->size()

Parameters:

scalar[in] scalar value to multiply all elements with

Returns:

a reference to *this

template<typename S, internal::require_numeric_type<S> = true>
Derived &operator-=(S scalar)#

Compound Operator (Subtraction). Subtract a scalar from each element in the container.

Complexity: Linear in this->size()

Parameters:

scalar[in] scalar value to divide all elements with

Returns:

a reference to *this

template<typename S, internal::require_numeric_type<S> = true>
Derived &operator*=(S scalar)#

Compound Operator (Multiplication). Multiplies each element in the container by a scalar.

Complexity: Linear in this->size()

Parameters:

scalar[in] scalar value to multiply all elements with

Returns:

a reference to *this

template<typename S, internal::require_numeric_type<S> = true>
Derived &operator/=(S scalar)#

Compound Operator (Division). Divides each element in the container by a scalar.

Complexity: Linear in this->size()

Parameters:

scalar[in] scalar value to divide all elements with

Returns:

a reference to *this