![]() |
OpenMS
|
A 2D matrix class with efficient buffer access for NumPy interoperability. More...
#include <OpenMS/DATASTRUCTURES/Matrix.h>
Public Types | |
Type definitions | |
| using | value_type = Value |
| using | iterator = typename std::vector< Value >::iterator |
| using | const_iterator = typename std::vector< Value >::const_iterator |
Public Member Functions | |
Constructors and assignment | |
| Matrix () | |
| Default constructor creates empty matrix. | |
| Matrix (Size rows, Size cols, Value value=Value()) | |
| Constructor to create a matrix with specified dimensions and fill value. | |
| Matrix (const Matrix &)=default | |
| Copy constructor. | |
| Matrix (Matrix &&) noexcept=default | |
| Move constructor. | |
| Matrix & | operator= (const Matrix &)=default |
| Copy assignment operator. | |
| Matrix & | operator= (Matrix &&) noexcept=default |
| Move assignment operator. | |
| ~Matrix ()=default | |
| Destructor. | |
Dimension accessors | |
| Size | rows () const |
| Number of rows. | |
| Size | cols () const |
| Number of columns. | |
| Size | size () const |
| Total number of elements. | |
| bool | empty () const |
| Check if matrix is empty. | |
Element access | |
| const Value & | getValue (size_t const row, size_t const col) const |
| Get element at (row, col) | |
| Value & | getValue (size_t const row, size_t const col) |
| Get mutable element at (row, col) | |
| void | setValue (size_t const row, size_t const col, const Value &value) |
| Set element at (row, col) | |
| Value & | operator() (size_t row, size_t col) |
| Unchecked element access (row, col) | |
| const Value & | operator() (size_t row, size_t col) const |
| Unchecked const element access (row, col) | |
Modifiers | |
| void | resize (size_t rows, size_t cols) |
| Resize matrix (contents become undefined after resize) | |
| void | fill (Value value) |
| Fill all elements with value. | |
| void | clear () |
| Clear matrix (set to 0x0) | |
| template<typename T , long int ROWS, long int COLS> | |
| void | setMatrix (T const (&array)[ROWS][COLS]) |
| Sets the matrix values using a 2D array. | |
Iterators | |
| iterator | begin () |
| iterator | end () |
| const_iterator | begin () const |
| const_iterator | end () const |
| const_iterator | cbegin () const |
| const_iterator | cend () const |
Reduction operations | |
| Value | maxValue () const |
| Returns the maximum value in the matrix. | |
| Value | minValue () const |
| Returns the minimum value in the matrix. | |
Comparison | |
| bool | operator== (const Matrix &rhs) const |
| Equality operator. Compares two matrices for equality. | |
| bool | operator!= (const Matrix &rhs) const |
Private Attributes | |
| std::vector< Value > | data_ |
| Column-major storage. | |
| Size | rows_ |
| Number of rows. | |
| Size | cols_ |
| Number of columns. | |
Friends | |
| std::ostream & | operator<< (std::ostream &os, const Matrix< Value > &matrix) |
| Friend function to output the matrix to an output stream. | |
Buffer access (for NumPy/Cython interoperability) | |
| Value * | data () |
| Pointer to raw data buffer (column-major storage) | |
| const Value * | data () const |
| Const pointer to raw data buffer. | |
| int | innerStride () const |
| Stride between consecutive elements in same column (always 1 for column-major) | |
| int | outerStride () const |
| Stride between consecutive columns. | |
| static constexpr bool | rowMajor () |
| Returns false (column-major storage, not row-major) | |
A 2D matrix class with efficient buffer access for NumPy interoperability.
Data is stored in column-major order (Fortran style) for compatibility with Eigen and most numerical libraries. Internal OpenMS code can obtain zero-copy Eigen views via the eigenView() function in MatrixEigen.h (internal header).
| Value | The element type (typically double or float) |
| using const_iterator = typename std::vector<Value>::const_iterator |
| using iterator = typename std::vector<Value>::iterator |
| using value_type = Value |
|
inline |
Default constructor creates empty matrix.
Constructor to create a matrix with specified dimensions and fill value.
| rows | Number of rows in the matrix. |
| cols | Number of columns in the matrix. |
| value | Initial value to fill the matrix. |
|
default |
Destructor.
|
inline |
References Matrix< Value >::data_.
|
inline |
References Matrix< Value >::data_.
|
inline |
References Matrix< Value >::data_.
|
inline |
References Matrix< Value >::data_.
|
inline |
Clear matrix (set to 0x0)
References Matrix< Value >::cols_, Matrix< Value >::data_, and Matrix< Value >::rows_.
|
inline |
Number of columns.
References Matrix< Value >::cols_.
Referenced by BilinearInterpolation< Key, Value >::addValue(), MSExperiment::aggregateFromMatrix(), OpenMS::eigenView(), OpenMS::eigenView(), MSExperiment::extractXICsFromMatrix(), Matrix< Value >::resize(), BilinearInterpolation< Key, Value >::supportMax_1(), and BilinearInterpolation< Key, Value >::value().
|
inline |
Pointer to raw data buffer (column-major storage)
References Matrix< Value >::data_.
Referenced by OpenMS::eigenView(), and OpenMS::eigenView().
|
inline |
Const pointer to raw data buffer.
References Matrix< Value >::data_.
|
inline |
Check if matrix is empty.
References Matrix< Value >::data_.
Referenced by BilinearInterpolation< Key, Value >::empty().
|
inline |
References Matrix< Value >::data_.
|
inline |
References Matrix< Value >::data_.
|
inline |
Fill all elements with value.
References Matrix< Value >::data_.
|
inline |
Get mutable element at (row, col)
Note: pyOpenMS can't easily wrap operator() so we provide additional getter.
| [in] | row | Zero-based row index. |
| [in] | col | Zero-based column index. |
References Matrix< Value >::data_, and Matrix< Value >::rows_.
|
inline |
Get element at (row, col)
Note: pyOpenMS can't easily wrap operator() so we provide additional getter.
| [in] | row | Zero-based row index. |
| [in] | col | Zero-based column index. |
References Matrix< Value >::data_, and Matrix< Value >::rows_.
|
inline |
Stride between consecutive elements in same column (always 1 for column-major)
|
inline |
Returns the maximum value in the matrix.
References Matrix< Value >::data_.
|
inline |
Returns the minimum value in the matrix.
References Matrix< Value >::data_.
|
inline |
|
inline |
Unchecked element access (row, col)
References Matrix< Value >::data_, and Matrix< Value >::rows_.
|
inline |
Unchecked const element access (row, col)
References Matrix< Value >::data_, and Matrix< Value >::rows_.
Copy assignment operator.
Move assignment operator.
|
inline |
Equality operator. Compares two matrices for equality.
| [in] | rhs | The matrix to be compared. |
| Exception::Precondition | if matrices have different dimensions (Debug mode only) |
References Matrix< Value >::cols_, Matrix< Value >::data_, OPENMS_PRECONDITION, and Matrix< Value >::rows_.
|
inline |
Stride between consecutive columns.
References Matrix< Value >::rows_.
|
inline |
Resize matrix (contents become undefined after resize)
References Matrix< Value >::cols(), Matrix< Value >::cols_, Matrix< Value >::data_, Matrix< Value >::rows(), and Matrix< Value >::rows_.
Referenced by Matrix< Value >::setMatrix().
|
inlinestaticconstexpr |
Returns false (column-major storage, not row-major)
|
inline |
Number of rows.
References Matrix< Value >::rows_.
Referenced by BilinearInterpolation< Key, Value >::addValue(), MSExperiment::aggregateFromMatrix(), OpenMS::eigenView(), OpenMS::eigenView(), MSExperiment::extractXICsFromMatrix(), Matrix< Value >::resize(), BilinearInterpolation< Key, Value >::supportMax_0(), and BilinearInterpolation< Key, Value >::value().
|
inline |
Sets the matrix values using a 2D array.
This function resizes the matrix to the specified number of rows and columns, and then assigns the values from the 2D array to the corresponding elements in the matrix.
| T | The type of the matrix elements. |
| ROWS | The number of rows in the matrix. |
| COLS | The number of columns in the matrix. |
| [in] | array | The 2D array containing the values to be assigned to the matrix. |
References Matrix< Value >::resize().
|
inline |
Set element at (row, col)
Note: pyOpenMS can't easily wrap operator() so we provide additional setter.
| [in] | row | Zero-based row index. |
| [in] | col | Zero-based column index. |
| [in] | value | Value to set at the given position. |
References Matrix< Value >::data_, and Matrix< Value >::rows_.
|
inline |
Total number of elements.
References Matrix< Value >::data_.
|
friend |
Friend function to output the matrix to an output stream.
| [in,out] | os | Output stream. |
| [in] | matrix | Matrix to be output. |
|
private |
Number of columns.
Referenced by Matrix< Value >::clear(), Matrix< Value >::cols(), Matrix< Value >::operator==(), and Matrix< Value >::resize().
|
private |
Column-major storage.
Referenced by Matrix< Value >::begin(), Matrix< Value >::begin(), Matrix< Value >::cbegin(), Matrix< Value >::cend(), Matrix< Value >::clear(), Matrix< Value >::data(), Matrix< Value >::data(), Matrix< Value >::empty(), Matrix< Value >::end(), Matrix< Value >::end(), Matrix< Value >::fill(), Matrix< Value >::getValue(), Matrix< Value >::getValue(), Matrix< Value >::maxValue(), Matrix< Value >::minValue(), Matrix< Value >::operator()(), Matrix< Value >::operator()(), Matrix< Value >::operator==(), Matrix< Value >::resize(), Matrix< Value >::setValue(), and Matrix< Value >::size().
|
private |
Number of rows.
Referenced by Matrix< Value >::clear(), Matrix< Value >::getValue(), Matrix< Value >::getValue(), Matrix< Value >::operator()(), Matrix< Value >::operator()(), Matrix< Value >::operator==(), Matrix< Value >::outerStride(), Matrix< Value >::resize(), Matrix< Value >::rows(), and Matrix< Value >::setValue().