Matrix Views

Matrix View 1D

template<typename Mat, internal::TypeLayout Dir>
class MatrixView1D : public mocca::MatrixBase<MatrixView1D<Mat, Dir>>

The MatrixView1D class represents an individual row or column of a Matrix. A instance of this class is returned when calling the row() or the col() methods, and usually, this is the only way it is used.

Template Parameters:

  • Mat - Matrix datatype (must be a variant of a Matrix)

  • Dir - The direction of the view (either kRowMajor or kColMajor)

Public Functions

MatrixView1D(Mat &mat, index_t i)

Creates a new MatrixView1D from the row/column i of the matrix mat. Complexity: Constant

Parameters:
  • mat[in] matrix to use as data source

  • i[in] index of the row/column of the matrix

virtual ~MatrixView1D() = default

Default Destructor.

MatrixView1D &operator=(const MatrixView1D &other)

Copy Assignment Operator. Replaces content of the MatrixView1D with the contents of an other.

Complexity: Linear in other.size()

Parameters:

other[in] another block to use as data source

Throws:

std::length_error – if `other.size() != this->size()`

Returns:

*this

template<typename OtherMat, internal::TypeLayout L>
MatrixView1D &operator=(const MatrixView1D<OtherMat, L> &other)

Copy Assignment Operator. Replaces content of the MatrixView1D with the contents of an other.

Complexity: Linear in other.size()

Parameters:

other[in] another block to use as data source

Throws:

std::length_error – if `other.size() != this->size()`

Returns:

*this

template<typename E>
MatrixView1D &operator=(const MatrixBase<E> &expr)

Evaluates an expression and assign the result to the MatrixView1D.

Complexity: Linear in other.size()

Parameters:

expr[in] matrix expression

Throws:

std::length_error – if `other.size() != this->size()`

Returns:

*this

constexpr index_t cols() const

Complexity: Constant

Returns:

the number of columns in the MatrixView1D.

constexpr index_t rows() const

Complexity: Constant

Returns:

the number of rows in the MatrixView1D.

constexpr index_t size() const

Complexity: Constant

Returns:

the size of the MatrixView1D.

Mat &expr()

Complexity: Constant

Returns:

a reference to the underlying matrix.

const Mat &expr() const

Complexity: Constant

Returns:

a reference to the underlying matrix.

index_t index() const

Complexity: Constant

Returns:

the index of the column/row of the underlying matrix.

reference operator[](index_t idx)

Accesses the element at (idx) position.

Complexity: Constant

Parameters:

idx[in] position of the element to return

Returns:

reference to the requested element

value_type operator[](index_t idx) const

Accesses element at (idx) position.

Complexity: Constant

Parameters:

idx[in] position of the element to return

Returns:

the requested element

reference operator()(index_t idx)

Accesses the element at (idx) position.

Complexity: Constant

Parameters:
  • row[in] row of the requested element

  • col[in] column of the requested element

Returns:

reference to requested element

value_type operator()(index_t idx) const

Accesses the element at (idx) position.

Complexity: Constant

Parameters:
  • row[in] row of the requested element

  • col[in] column of the requested element

Returns:

the requested element

pointer data() const

Complexity: Constant

Note

If MatrixView1D do not share the same layout as underlying matrix (e.g., selecting a column in a RowMajor matrix), the data is not stored contiguous in memory.

Returns:

a raw pointer to the beginning of the MatrixView1D

iterator begin() noexcept

Complexity: Constant

Returns:

iterator to the beginning of the MatrixView1D

iterator end() noexcept

Complexity: Constant

Returns:

iterator to past-the-end element of the MatrixView1D

const_iterator cbegin() const noexcept

Complexity: Constant

Returns:

a const_iterator to the beginning of the MatrixView1D

const_iterator cend() const noexcept

Complexity: Constant

Returns:

a const_iterator to past-the-end element of the MatrixView1D

CSRow

template<typename Mat>
class CSRow : public mocca::MatrixBase<CSRow<Mat>>

The CSRow class represents an individual row of a CSRMatrix. A instance of this class is returned when calling the row() method, and usually, this is the only way it is used.

Template Parameters:

Public Functions

inline CSRow(Mat &mat, index_t i)

Creates a new CSRow from the row i of the matrix mat. Complexity: Constant

Parameters:
  • mat[in] matrix to use as data source

  • i[in] index of the row of the matrix

CSRow &operator=(const CSRow &other) = delete

No object can be assigned to the CSRow due to the sparse layout.

virtual ~CSRow() = default

Default destructor.

inline reference operator[](index_t idx)

Accesses the nonzero element at (idx). In this case, the indexing only includes the non zeros elements.

Complexity: Constant

Parameters:

idx[in] index of the nonzero element to return

Returns:

Reference to requested element

inline value_type operator[](index_t idx) const

Accesses the nonzero element at (idx). In this case, the indexing only includes the non zeros elements.

Complexity: Constant

Parameters:

idx[in] position of the nonzero element to return

Returns:

Reference to requested element

inline CSRowNonzero<value_type> nonzero_at(index_t idx) const

Accesses the nonzero element at (idx). In this case, the indexing only includes the non zeros elements.

Complexity: Constant

Parameters:

idx[in] position of the nonzero element to return

Returns:

a CSRowNonzero object containing the column and the value of the nonzero element.

inline index_t index_at(index_t pos) const

Accesses the index of the nonzero element at (pos) position. In this case, the indexing only includes nonzeros elements.

Complexity: Constant

Returns:

the index of requested element

inline constexpr index_t cols() const

Complexity: Constant

Returns:

the number of columns in the CSRow

inline constexpr index_t rows() const

Complexity: Constant

Returns:

the number of rows in the CSRow (always 1)

inline constexpr index_t size() const

Complexity: Constant

Returns:

the number of non zeros entries in the CSRow

inline index_t index()

Complexity:

Returns:

the index of the row in the underlying matrix.

inline Mat &expr()

Complexity: Constant

Returns:

a reference to the underlying matrix.

inline const Mat &expr() const

Complexity: Constant

Returns:

a reference to the underlying matrix.

inline constexpr pointer nonzeros_ptr()

Complexity: Constant

Returns:

a raw pointer to the nonzeros buffer of the CSRow

inline constexpr pointer nonzeros_ptr() const

Complexity: Constant

Returns:

a raw pointer to the nonzeros buffer of the CSRow

inline constexpr index_t *columns_ptr()

Complexity: Constant

Returns:

a raw pointer to the column buffer of the CSRow

inline constexpr index_t *columns_ptr() const

Complexity: Constant

Returns:

a raw pointer to the column buffer of the CSRow

inline iterator begin() noexcept

Complexity: Constant

Returns:

iterator to the first nonzero element in the CSRow

inline iterator end() noexcept

Complexity: Constant

Returns:

iterator to past-the-end element of the CSRow

inline const_iterator cbegin() const noexcept

Complexity: Constant

Returns:

const_iterator to the first nonzero element in the CSRow

inline const_iterator cend() const noexcept

Complexity: Constant

Returns:

const_iterator to past-the-end element of the CSRow