codac 2.0.0
Loading...
Searching...
No Matches
codac2_matrices.h File Reference
#include <type_traits>
#include "codac2_Interval.h"
#include "codac2_Interval_operations.h"
#include "codac2_assert.h"
#include <Eigen/Core>
#include <Eigen/Dense>
Include dependency graph for codac2_matrices.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<typename OtherDerived>
auto codac2::abs (const Eigen::MatrixBase< OtherDerived > &x)
 Compute the element-wise absolute value of a matrix.
 
template<typename OtherDerived>
requires (!Eigen::IsIntervalDomain<typename OtherDerived::Scalar>)
auto codac2::floor (const Eigen::MatrixBase< OtherDerived > &x)
 Compute the element-wise floor of a matrix.
 
template<typename OtherDerived>
requires (!Eigen::IsIntervalDomain<typename OtherDerived::Scalar>)
auto codac2::ceil (const Eigen::MatrixBase< OtherDerived > &x)
 Compute the element-wise ceiling of a matrix.
 
template<typename OtherDerived>
requires (!Eigen::IsIntervalDomain<typename OtherDerived::Scalar>)
auto codac2::round (const Eigen::MatrixBase< OtherDerived > &x)
 Compute the element-wise rounding of a matrix.
 
Eigen::IOFormat codac2::codac_row_fmt ()
 Provides an Eigen IOFormat for formatting row vectors.
 
Eigen::IOFormat codac2::codac_vector_fmt ()
 Provides an Eigen IOFormat for formatting column vectors.
 
Eigen::IOFormat codac2::codac_matrix_fmt ()
 Provides an Eigen IOFormat for formatting matrices.
 

Detailed Description

This file is included in the declaration of Eigen::MatrixBase, thanks to the preprocessor token EIGEN_MATRIXBASE_PLUGIN. See: https://eigen.tuxfamily.org/dox/TopicCustomizing_Plugins.html

This file is included in the declaration of Eigen::MatrixBase, thanks to the preprocessor token EIGEN_MATRIXBASE_PLUGIN. See: https://eigen.tuxfamily.org/dox/TopicCustomizing_Plugins.html and the file codac2_matrices.h


Date
2024
Author
Simon Rohou
License: GNU Lesser General Public License (LGPL)

Function Documentation

◆ abs()

template<typename OtherDerived>
auto codac2::abs ( const Eigen::MatrixBase< OtherDerived > & x)
inline

Compute the element-wise absolute value of a matrix.

This function takes an Eigen matrix expression and returns a matrix where each element is replaced by its absolute value.

For scalar type double, the standard library fabs() is used. For other scalar types, it uses the generic abs() function.

Parameters
xInput matrix expression.
Returns
A new Eigen matrix with the absolute values of the elements of x.
127 {
128 using M = Eigen::MatrixBase<OtherDerived>;
129 Eigen::Matrix<typename M::Scalar,M::RowsAtCompileTime,M::ColsAtCompileTime> a(x.rows(),x.cols());
130
131 for(Index i = 0 ; i < x.rows() ; i++)
132 for(Index j = 0 ; j < x.cols() ; j++)
133 {
134 if constexpr(std::is_same_v<typename M::Scalar,double>)
135 a(i,j) = fabs(x(i,j));
136 else
137 a(i,j) = abs(x(i,j));
138 }
139
140 return a;
141 }
Interval abs(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:264

◆ floor()

template<typename OtherDerived>
requires (!Eigen::IsIntervalDomain<typename OtherDerived::Scalar>)
auto codac2::floor ( const Eigen::MatrixBase< OtherDerived > & x)
inline

Compute the element-wise floor of a matrix.

This function returns a matrix where each element is replaced by the largest integer not greater than that element.

Disabled for interval matrices.

Parameters
xInput matrix expression.
Returns
A new Eigen matrix with floored elements.
157 {
158 return x.array().floor().matrix();
159 }

◆ ceil()

template<typename OtherDerived>
requires (!Eigen::IsIntervalDomain<typename OtherDerived::Scalar>)
auto codac2::ceil ( const Eigen::MatrixBase< OtherDerived > & x)
inline

Compute the element-wise ceiling of a matrix.

This function returns a matrix where each element is replaced by the smallest integer not less than that element.

Disabled for interval matrices.

Parameters
xInput matrix expression.
Returns
A new Eigen matrix with ceiled elements.
175 {
176 return x.array().ceil().matrix();
177 }

◆ round()

template<typename OtherDerived>
requires (!Eigen::IsIntervalDomain<typename OtherDerived::Scalar>)
auto codac2::round ( const Eigen::MatrixBase< OtherDerived > & x)
inline

Compute the element-wise rounding of a matrix.

This function returns a matrix where each element is replaced by the nearest integer to that element.

Disabled for interval matrices.

Parameters
xInput matrix expression.
Returns
A new Eigen matrix with rounded elements.
193 {
194 return x.array().round().matrix();
195 }

◆ codac_row_fmt()

Eigen::IOFormat codac2::codac_row_fmt ( )
inline

Provides an Eigen IOFormat for formatting row vectors.

This format prints elements separated by spaces, with brackets around the entire row vector.

Returns
An Eigen::IOFormat configured for row vector formatting.
206 {
207 return Eigen::IOFormat(Eigen::StreamPrecision, Eigen::DontAlignCols, " ", "", "", "", "[ ", " ]");
208 }

◆ codac_vector_fmt()

Eigen::IOFormat codac2::codac_vector_fmt ( )
inline

Provides an Eigen IOFormat for formatting column vectors.

This format prints elements separated by semicolons, with brackets around the entire vector.

Returns
An Eigen::IOFormat configured for column vector formatting.
219 {
220 return Eigen::IOFormat(Eigen::StreamPrecision, Eigen::DontAlignCols, "", " ; ", "", "", "[ ", " ]");
221 }

◆ codac_matrix_fmt()

Eigen::IOFormat codac2::codac_matrix_fmt ( )
inline

Provides an Eigen IOFormat for formatting matrices.

This format prints elements separated by commas, rows separated by new lines, and brackets around the entire matrix.

Returns
An Eigen::IOFormat configured for matrix formatting.
233 {
234 return Eigen::IOFormat(Eigen::StreamPrecision, 0, " , ", "\n", "[ ", " ]", "[", "]");
235 }