Go to the source code of this file.
|
template<typename NewType > |
CastXpr< NewType >::Type | cast () const |
|
ConjugateReturnType | conjugate () const |
|
template<bool Cond> |
std::conditional_t< Cond, ConjugateReturnType, const Derived & > | conjugateIf () const |
|
const ImagReturnType | imag () const |
|
const NegativeReturnType | operator- () const |
|
RealReturnType | real () const |
|
template<typename CustomUnaryOp > |
const CwiseUnaryOp< CustomUnaryOp, const Derived > | unaryExpr (const CustomUnaryOp &func=CustomUnaryOp()) const |
| Apply a unary operator coefficient-wise. More...
|
|
template<typename CustomViewOp > |
const CwiseUnaryView< CustomViewOp, const Derived > | unaryViewExpr (const CustomViewOp &func=CustomViewOp()) const |
|
◆ cast()
template<typename NewType >
CastXpr<NewType>::Type cast |
( |
| ) |
const |
- Returns
- an expression of
*this
with the Scalar type casted to NewScalar.
The template parameter NewScalar is the type we are casting the scalars to.
- See also
- class CwiseUnaryOp
Definition at line 62 of file CommonCwiseUnaryOps.h.
internal::cast_return_type< Derived, const CwiseUnaryOp< internal::core_cast_op< Scalar, NewType >, const Derived > >::type Type
◆ conjugate()
ConjugateReturnType conjugate |
( |
| ) |
const |
|
inline |
- Returns
- an expression of the complex conjugate of
*this
.
- See also
- Math functions, MatrixBase::adjoint()
Definition at line 74 of file CommonCwiseUnaryOps.h.
76 return ConjugateReturnType(derived());
◆ conjugateIf()
template<bool Cond>
std::conditional_t<Cond,ConjugateReturnType,const Derived&> conjugateIf |
( |
| ) |
const |
|
inline |
- Returns
- an expression of the complex conjugate of
*this
if Cond==true, returns derived() otherwise.
- See also
- conjugate()
Definition at line 87 of file CommonCwiseUnaryOps.h.
89 typedef std::conditional_t<Cond,ConjugateReturnType,const Derived&> ReturnType;
90 return ReturnType(derived());
◆ imag()
NonConstImagReturnType imag |
( |
| ) |
const |
|
inline |
- Returns
- an read-only expression of the imaginary part of
*this
.
- See also
- real()
- Returns
- a non const expression of the imaginary part of
*this
.
- See also
- real()
Definition at line 109 of file CommonCwiseUnaryOps.h.
109 {
return ImagReturnType(derived()); }
◆ operator-()
const NegativeReturnType operator- |
( |
| ) |
const |
|
inline |
- Returns
- an expression of the opposite of
*this
Definition at line 45 of file CommonCwiseUnaryOps.h.
45 {
return NegativeReturnType(derived()); }
◆ real()
NonConstRealReturnType real |
( |
| ) |
const |
|
inline |
- Returns
- a read-only expression of the real part of
*this
.
- See also
- imag()
- Returns
- a non const expression of the real part of
*this
.
- See also
- imag()
Definition at line 100 of file CommonCwiseUnaryOps.h.
100 {
return RealReturnType(derived()); }
◆ unaryExpr()
template<typename CustomUnaryOp >
const CwiseUnaryOp<CustomUnaryOp, const Derived> unaryExpr |
( |
const CustomUnaryOp & |
func = CustomUnaryOp() | ) |
const |
|
inline |
Apply a unary operator coefficient-wise.
- Parameters
-
[in] | func | Functor implementing the unary operator |
- Template Parameters
-
CustomUnaryOp | Type of func |
- Returns
- An expression of a custom coefficient-wise unary operator func of *this
The function ptr_fun()
from the C++ standard library can be used to make functors out of normal functions.
Example:
#include <iostream>
{
else
return 0;
}
{
std::cout <<
m1 << std::endl <<
"becomes: " << std::endl <<
m1.unaryExpr(std::ptr_fun(
ramp)) << std::endl;
return 0;
}
static const RandomReturnType Random()
The matrix class, also used for vectors and row-vectors.
Output:
0.68 0.823 -0.444 -0.27
-0.211 -0.605 0.108 0.0268
0.566 -0.33 -0.0452 0.904
0.597 0.536 0.258 0.832
becomes:
0.68 0.823 0 0
0 0 0.108 0.0268
0.566 0 0 0.904
0.597 0.536 0.258 0.832
Genuine functors allow for more possibilities, for instance it may contain a state.
Example:
#include <iostream>
template<typename Scalar>
struct CwiseClampOp {
CwiseClampOp(const Scalar& inf, const Scalar& sup) : m_inf(inf), m_sup(sup) {}
const Scalar
operator()(
const Scalar&
x)
const {
return x<m_inf ? m_inf : (
x>m_sup ? m_sup :
x); }
Scalar m_inf, m_sup;
};
{
std::cout <<
m1 << std::endl <<
"becomes: " << std::endl <<
m1.unaryExpr(CwiseClampOp<double>(-0.5,0.5)) << std::endl;
return 0;
}
IndexedView_or_Block operator()(const RowIndices &rowIndices, const ColIndices &colIndices)
Output:
0.68 0.823 -0.444 -0.27
-0.211 -0.605 0.108 0.0268
0.566 -0.33 -0.0452 0.904
0.597 0.536 0.258 0.832
becomes:
0.5 0.5 -0.444 -0.27
-0.211 -0.5 0.108 0.0268
0.5 -0.33 -0.0452 0.5
0.5 0.5 0.258 0.5
- See also
- unaryViewExpr, binaryExpr, class CwiseUnaryOp
Definition at line 135 of file CommonCwiseUnaryOps.h.
137 return CwiseUnaryOp<CustomUnaryOp, const Derived>(derived(), func);
◆ unaryViewExpr()
template<typename CustomViewOp >
const CwiseUnaryView<CustomViewOp, const Derived> unaryViewExpr |
( |
const CustomViewOp & |
func = CustomViewOp() | ) |
const |
|
inline |
- Returns
- an expression of a custom coefficient-wise unary operator func of *this
The template parameter CustomUnaryOp is the type of the functor of the custom unary operator.
Example:
#include <iostream>
template<typename Scalar>
struct CwiseClampOp {
CwiseClampOp(const Scalar& inf, const Scalar& sup) : m_inf(inf), m_sup(sup) {}
const Scalar
operator()(
const Scalar&
x)
const {
return x<m_inf ? m_inf : (
x>m_sup ? m_sup :
x); }
Scalar m_inf, m_sup;
};
{
std::cout <<
m1 << std::endl <<
"becomes: " << std::endl <<
m1.unaryExpr(CwiseClampOp<double>(-0.5,0.5)) << std::endl;
return 0;
}
Output:
0.68 0.823 -0.444 -0.27
-0.211 -0.605 0.108 0.0268
0.566 -0.33 -0.0452 0.904
0.597 0.536 0.258 0.832
becomes:
0.5 0.5 -0.444 -0.27
-0.211 -0.5 0.108 0.0268
0.5 -0.33 -0.0452 0.5
0.5 0.5 0.258 0.5
- See also
- unaryExpr, binaryExpr class CwiseUnaryOp
Definition at line 156 of file CommonCwiseUnaryOps.h.
158 return CwiseUnaryView<CustomViewOp, const Derived>(derived(), func);