35 #ifndef _BLAZE_MATH_EXPRESSIONS_SMATVAREXPR_H_ 36 #define _BLAZE_MATH_EXPRESSIONS_SMATVAREXPR_H_ 111 template<
typename MT >
113 :
public MatReduceExpr< DenseVector< SMatVarExpr<MT,columnwise>, true >, columnwise >
139 static constexpr
bool simdEnabled =
false;
142 static constexpr
bool smpAssignable =
false;
175 if( index >= sm_.columns() ) {
178 return (*
this)[index];
187 inline size_t size() const noexcept {
188 return sm_.columns();
208 template<
typename T >
209 inline bool canAlias(
const T* alias )
const noexcept {
210 return ( sm_.isAliased( alias ) );
220 template<
typename T >
221 inline bool isAliased(
const T* alias )
const noexcept {
222 return ( sm_.isAliased( alias ) );
253 template<
typename VT1 >
265 assign( ~lhs, var<columnwise>( tmp ) );
283 template<
typename VT1 >
294 const ResultType tmp(
serial( rhs ) );
313 template<
typename VT1 >
314 friend inline void addAssign( DenseVector<VT1,true>& lhs,
const SMatVarExpr& rhs )
324 const OT tmp(
serial( rhs.sm_ ) );
325 addAssign( ~lhs, var<columnwise>( tmp ) );
343 template<
typename VT1 >
344 friend inline void addAssign( SparseVector<VT1,true>& lhs,
const SMatVarExpr& rhs )
354 const ResultType tmp(
serial( rhs ) );
355 addAssign( ~lhs, tmp );
373 template<
typename VT1 >
374 friend inline void subAssign( DenseVector<VT1,true>& lhs,
const SMatVarExpr& rhs )
384 const OT tmp(
serial( rhs.sm_ ) );
385 subAssign( ~lhs, var<columnwise>( tmp ) );
403 template<
typename VT1 >
404 friend inline void subAssign( SparseVector<VT1,true>& lhs,
const SMatVarExpr& rhs )
414 const ResultType tmp(
serial( rhs ) );
415 subAssign( ~lhs, tmp );
433 template<
typename VT1 >
434 friend inline void multAssign( DenseVector<VT1,true>& lhs,
const SMatVarExpr& rhs )
444 const OT tmp(
serial( rhs.sm_ ) );
445 multAssign( ~lhs, var<columnwise>( tmp ) );
463 template<
typename VT1 >
464 friend inline void multAssign( SparseVector<VT1,true>& lhs,
const SMatVarExpr& rhs )
474 const ResultType tmp(
serial( rhs ) );
475 multAssign( ~lhs, tmp );
493 template<
typename VT1 >
494 friend inline void divAssign( DenseVector<VT1,true>& lhs,
const SMatVarExpr& rhs )
504 const OT tmp(
serial( rhs.sm_ ) );
505 divAssign( ~lhs, var<columnwise>( tmp ) );
523 template<
typename VT1 >
524 friend inline void divAssign( SparseVector<VT1,true>& lhs,
const SMatVarExpr& rhs )
534 const ResultType tmp(
serial( rhs ) );
535 divAssign( ~lhs, tmp );
565 template<
typename MT >
567 :
public MatReduceExpr< DenseVector< SMatVarExpr<MT,rowwise>, false >, rowwise >
583 static constexpr
bool useAssign = RequiresEvaluation_v<MT>;
586 template<
typename VT >
588 static constexpr
bool UseAssign_v = useAssign;
682 return ConstIterator( index_++ );
703 return ConstIterator( index_-- );
724 return index_ == rhs.index_;
735 return index_ != rhs.index_;
745 inline bool operator<(
const ConstIterator& rhs )
const {
746 return index_ < rhs.index_;
756 inline bool operator>(
const ConstIterator& rhs )
const {
757 return index_ > rhs.index_;
768 return index_ <= rhs.index_;
779 return index_ >= rhs.index_;
790 return index_ - rhs.index_;
801 friend inline const ConstIterator
operator+(
const ConstIterator& it,
size_t inc ) {
802 return ConstIterator( it.index_ + inc );
813 friend inline const ConstIterator
operator+(
size_t inc,
const ConstIterator& it ) {
814 return ConstIterator( it.index_ + inc );
825 friend inline const ConstIterator
operator-(
const ConstIterator& it,
size_t dec ) {
826 return ConstIterator( it.index_ - dec );
840 static constexpr
bool simdEnabled =
false;
843 static constexpr
bool smpAssignable =
false;
876 if( index >= sm_.rows() ) {
879 return (*
this)[index];
888 inline ConstIterator
begin()
const {
889 return ConstIterator( sm_, 0UL );
898 inline ConstIterator
end()
const {
899 return ConstIterator( sm_,
size() );
908 inline size_t size() const noexcept {
929 template<
typename T >
930 inline bool canAlias(
const T* alias )
const noexcept {
931 return ( sm_.isAliased( alias ) );
941 template<
typename T >
942 inline bool isAliased(
const T* alias )
const noexcept {
943 return ( sm_.isAliased( alias ) );
976 template<
typename VT1 >
985 assign( ~lhs, var<rowwise>( tmp ) );
1004 template<
typename VT1 >
1012 const RT tmp(
serial( rhs.sm_ ) );
1013 addAssign( ~lhs, var<rowwise>( tmp ) );
1033 template<
typename VT1 >
1034 friend inline auto subAssign( Vector<VT1,false>& lhs,
const SMatVarExpr& rhs )
1035 -> EnableIf_t< UseAssign_v<VT1> >
1041 const RT tmp(
serial( rhs.sm_ ) );
1042 subAssign( ~lhs, var<rowwise>( tmp ) );
1062 template<
typename VT1 >
1063 friend inline auto multAssign( Vector<VT1,false>& lhs,
const SMatVarExpr& rhs )
1064 -> EnableIf_t< UseAssign_v<VT1> >
1070 const RT tmp(
serial( rhs.sm_ ) );
1071 multAssign( ~lhs, var<rowwise>( tmp ) );
1090 template<
typename VT1 >
1091 friend inline auto divAssign( Vector<VT1,false>& lhs,
const SMatVarExpr& rhs )
1092 -> EnableIf_t< UseAssign_v<VT1> >
1098 const RT tmp(
serial( rhs.sm_ ) );
1099 divAssign( ~lhs, var<rowwise>( tmp ) );
1130 template<
typename MT
1132 inline decltype(
auto) var_backend( const SparseMatrix<MT,SO>& sm,
FalseType )
1134 using BT = UnderlyingBuiltin_t<MT>;
1136 const size_t n (
size( ~sm ) );
1137 const size_t nz(
nonZeros( ~sm ) );
1142 const auto meanValue(
mean( ~sm ) );
1143 auto variance( ( n - nz ) *
pow2( meanValue ) );
1145 const size_t iend( SO ? (~sm).
columns() : (~sm).
rows() );
1146 for(
size_t i=0UL; i<iend; ++i ) {
1147 const auto end( (~sm).
end(i) );
1148 for(
auto element=(~sm).
begin(i); element!=
end; ++element ) {
1149 variance +=
pow2( element->value() - meanValue );
1153 return variance *
inv( BT( n-1UL ) );
1167 template<
typename MT
1169 inline decltype(
auto) var_backend( const SparseMatrix<MT,SO>& sm,
TrueType )
1175 return ElementType_t<MT>();
1205 template<
typename MT
1211 if(
size( ~sm ) < 2UL ) {
1230 inline const SMatVarExpr<MT,RF> var_backend(
const SparseMatrix<MT,false>& sm )
1232 using ReturnType =
const SMatVarExpr<MT,RF>;
1233 return ReturnType( ~sm );
1249 inline decltype(
auto) var_backend( const SparseMatrix<MT,true>& sm )
1302 return var_backend<RF>( ~sm );
BoolConstant< false > FalseType
Type/value traits base class.The FalseType class is used as base class for type traits and value trai...
Definition: IntegralConstant.h:121
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.This macro encapsulates the default way o...
Definition: Exception.h:235
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: SMatVarExpr.h:128
Pointer difference type of the Blaze library.
Header file for auxiliary alias declarations.
decltype(auto) column(Matrix< MT, SO > &matrix, RCAs... args)
Creating a view on a specific column of the given matrix.
Definition: Column.h:133
Header file for the blaze::checked and blaze::unchecked instances.
Header file for basic type definitions.
typename If< Condition, T1, T2 >::Type If_t
Auxiliary alias template for the If class template.The If_t alias template provides a convenient shor...
Definition: If.h:109
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SMatVarExpr.h:209
ConstIterator(Operand sm, size_t index)
Constructor for the ConstIterator class.
Definition: SMatVarExpr.h:635
Header file for the MatReduceExpr base class.
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.The ResultType_t alias declaration provides ...
Definition: Aliases.h:390
Header file for the serial shim.
Base class for all matrix reduction expression templates.The MatReduceExpr class serves as a tag for ...
Definition: MatReduceExpr.h:67
const ElementType ReturnType
Return type for expression template evaluations.
Definition: SMatVarExpr.h:130
MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:372
ConstIterator & operator--()
Pre-decrement operator.
Definition: SMatVarExpr.h:691
bool operator>(const ConstIterator &rhs) const
Greater-than comparison between two ConstIterator objects.
Definition: SMatVarExpr.h:756
CompositeType_t< MT > CT
Composite type of the sparse matrix expression.
Definition: SMatVarExpr.h:120
constexpr Unchecked unchecked
Global Unchecked instance.The blaze::unchecked instance is an optional token for the creation of view...
Definition: Check.h:138
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: SMatVarExpr.h:908
Header file for the DenseVector base class.
const ConstIterator operator--(int)
Post-decrement operator.
Definition: SMatVarExpr.h:702
Header file for the MAYBE_UNUSED function template.
bool isAligned() const noexcept
Returns whether the operands of the expression are properly aligned in memory.
Definition: SMatVarExpr.h:231
Header file for the invert shim.
size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:584
Header file for the Computation base class.
friend const ConstIterator operator+(const ConstIterator &it, size_t inc)
Addition between a ConstIterator and an integral value.
Definition: SMatVarExpr.h:801
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SMatVarExpr.h:221
BoolConstant< true > TrueType
Type traits base class.The TrueType class is used as base class for type traits and value traits that...
Definition: IntegralConstant.h:132
Constraints on the storage order of matrix types.
Header file for the RequiresEvaluation type trait.
DifferenceType operator-(const ConstIterator &rhs) const
Calculating the number of elements between two iterators.
Definition: SMatVarExpr.h:789
#define BLAZE_STATIC_ASSERT_MSG(expr, msg)
Compile time assertion macro.In case of an invalid compile time expression, a compilation error is cr...
Definition: StaticAssert.h:123
Operand sm_
Sparse matrix of the variance expression.
Definition: SMatVarExpr.h:238
Base template for the row-/column-wise variance computations on row-major sparse matrices....
Definition: SMatVarExpr.h:91
Header file for the reduce trait.
constexpr size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:514
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes....
Definition: Forward.h:145
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.The ElementType_t alias declaration provide...
Definition: Aliases.h:170
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: SMatVarExpr.h:129
ConstIterator & operator+=(size_t inc)
Addition assignment operator.
Definition: SMatVarExpr.h:647
const ConstIterator operator++(int)
Post-increment operator.
Definition: SMatVarExpr.h:681
Compile time check for zero vectors or matrices.This type trait tests whether or not the given templa...
Definition: IsZero.h:107
If_t< useAssign, const ResultType, const SMatVarExpr & > CompositeType
Data type for composite expression templates.
Definition: SMatVarExpr.h:602
Header file for the SparseMatrix base class.
ReduceTrait_t< RT, InvAdd, rowwise > ResultType
Result type for expression template evaluations.
Definition: SMatVarExpr.h:596
Constraint on the data type.
typename EnableIf< Condition, T >::Type EnableIf_t
Auxiliary type for the EnableIf class template.The EnableIf_t alias declaration provides a convenient...
Definition: EnableIf.h:138
Operand sm_
Sparse matrix of the variance expression.
Definition: SMatVarExpr.h:832
ElementType & ReferenceType
Reference return type.
Definition: SMatVarExpr.h:618
IteratorCategory iterator_category
The iterator category.
Definition: SMatVarExpr.h:622
bool operator<=(const ConstIterator &rhs) const
Less-than comparison between two ConstIterator objects.
Definition: SMatVarExpr.h:767
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SMatVarExpr.h:862
ConstIterator begin() const
Returns an iterator to the first non-zero element of the dense vector.
Definition: SMatVarExpr.h:888
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SMatVarExpr.h:161
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the If class template.
#define BLAZE_CONSTRAINT_MUST_BE_COLUMN_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a column-major dense or sparse matri...
Definition: ColumnMajorMatrix.h:61
ConstIterator end() const
Returns an iterator just past the last non-zero element of the dense vector.
Definition: SMatVarExpr.h:898
decltype(auto) operator *(const DenseMatrix< MT1, false > &lhs, const DenseMatrix< MT2, false > &rhs)
Multiplication operator for the multiplication of two row-major dense matrices ( ).
Definition: DMatDMatMultExpr.h:9091
Header file for the UnderlyingBuiltin type trait.
ConstIterator & operator++()
Pre-increment operator.
Definition: SMatVarExpr.h:670
ElementType * PointerType
Pointer return type.
Definition: SMatVarExpr.h:617
Expression object for the row-wise variance function on row-major sparse matrices....
Definition: SMatVarExpr.h:566
const ResultType CompositeType
Data type for composite expression templates.
Definition: SMatVarExpr.h:131
bool isAligned() const noexcept
Returns whether the operands of the expression are properly aligned in memory.
Definition: SMatVarExpr.h:952
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.This macro encapsulates the default way of Bl...
Definition: Exception.h:331
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: SMatVarExpr.h:597
friend const ConstIterator operator+(size_t inc, const ConstIterator &it)
Addition between an integral value and a ConstIterator.
Definition: SMatVarExpr.h:813
decltype(auto) inv(const DenseMatrix< MT, SO > &dm)
Calculation of the inverse of the given dense matrix.
Definition: DMatInvExpr.h:423
SMatVarExpr(const MT &sm) noexcept
Constructor for the SMatVarExpr class.
Definition: SMatVarExpr.h:851
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:76
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition: MaybeUnused.h:81
If_t< IsExpression_v< MT >, const MT, const MT & > Operand
Composite type of the left-hand side sparse matrix expression.
Definition: SMatVarExpr.h:134
If_t< IsExpression_v< MT >, const MT, const MT & > Operand
Composite type of the left-hand side sparse matrix expression.
Definition: SMatVarExpr.h:605
Header file for the pow2 shim.
std::random_access_iterator_tag IteratorCategory
The iterator category.
Definition: SMatVarExpr.h:615
Header file for the exception macros of the math module.
OppositeType_t< MT > OT
Opposite type of the sparse matrix expression.
Definition: SMatVarExpr.h:119
MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:438
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: SMatVarExpr.h:875
Header file for the EnableIf class template.
decltype(auto) mean(const DenseMatrix< MT, SO > &dm)
Computes the (arithmetic) mean for the given dense matrix.
Definition: DMatMeanExpr.h:134
typename T::OppositeType OppositeType_t
Alias declaration for nested OppositeType type definitions.The OppositeType_t alias declaration provi...
Definition: Aliases.h:270
size_t index_
Index to the current matrix row.
Definition: SMatVarExpr.h:833
constexpr size_t columnwise
Reduction flag for column-wise reduction operations.
Definition: ReductionFlag.h:90
#define BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a row-major dense or sparse matrix t...
Definition: RowMajorMatrix.h:61
typename ReduceTrait< T, OP, RF... >::Type ReduceTrait_t
Auxiliary alias declaration for the ReduceTrait class template.The ReduceTrait_t alias declaration pr...
Definition: ReduceTrait.h:173
const ElementType ReturnType
Return type for expression template evaluations.
Definition: SMatVarExpr.h:599
typename T::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.The TransposeType_t alias declaration pro...
Definition: Aliases.h:470
Header file for run time assertion macros.
Header file for the InvAdd functor.
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.The CompositeType_t alias declaration pro...
Definition: Aliases.h:90
decltype(auto) var(const DenseMatrix< MT, SO > &dm)
Computes the variance for the given dense matrix.
Definition: DMatVarExpr.h:137
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: SMatVarExpr.h:187
decltype(auto) row(Matrix< MT, SO > &, RRAs...)
Creating a view on a specific row of the given matrix.
Definition: Row.h:133
ReferenceType reference
Reference return type.
Definition: SMatVarExpr.h:625
Header file for the IsZero type trait.
decltype(auto) pow2(const Proxy< PT, RT > &proxy)
Computing the square value of the represented element.
Definition: Proxy.h:1384
Operand operand() const noexcept
Returns the sparse matrix operand.
Definition: SMatVarExpr.h:197
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:94
Header file for all forward declarations for expression class templates.
Operand sm_
Sparse matrix of the variance expression.
Definition: SMatVarExpr.h:959
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:530
bool operator!=(const ConstIterator &rhs) const
Inequality comparison between two ConstIterator objects.
Definition: SMatVarExpr.h:734
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:808
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SMatVarExpr.h:942
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.In case the given data type T requires an intermediate evaluation within ...
Definition: RequiresEvaluation.h:81
bool operator==(const ConstIterator &rhs) const
Equality comparison between two ConstIterator objects.
Definition: SMatVarExpr.h:723
constexpr size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:498
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: SMatVarExpr.h:174
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: SMatVarExpr.h:598
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a dense, N-dimensional vector type,...
Definition: DenseVector.h:61
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:765
bool operator<(const ConstIterator &rhs) const
Less-than comparison between two ConstIterator objects.
Definition: SMatVarExpr.h:745
ResultType_t< MT > RT
Result type of the sparse matrix expression.
Definition: SMatVarExpr.h:572
constexpr size_t rowwise
Reduction flag for row-wise reduction operations.
Definition: ReductionFlag.h:70
SMatVarExpr(const MT &sm) noexcept
Constructor for the SMatVarExpr class.
Definition: SMatVarExpr.h:150
Base class for N-dimensional vectors.The Vector class is a base class for all arbitrarily sized (N-di...
Definition: Forward.h:198
bool operator>=(const ConstIterator &rhs) const
Greater-than comparison between two ConstIterator objects.
Definition: SMatVarExpr.h:778
Base class for all compute expression templates.The Computation class serves as a tag for all computa...
Definition: Computation.h:66
ConstIterator & operator-=(size_t dec)
Subtraction assignment operator.
Definition: SMatVarExpr.h:659
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:146
Expression object for the column-wise variance function on row-major sparse matrices....
Definition: SMatVarExpr.h:112
ResultType_t< MT > RT
Result type of the sparse matrix expression.
Definition: SMatVarExpr.h:118
Header file for the IntegralConstant class template.
friend const ConstIterator operator-(const ConstIterator &it, size_t dec)
Subtraction between a ConstIterator and an integral value.
Definition: SMatVarExpr.h:825
#define BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a row dense or sparse vector type (i...
Definition: RowVector.h:61
ValueType value_type
Type of the underlying elements.
Definition: SMatVarExpr.h:623
ElementType ValueType
Type of the underlying elements.
Definition: SMatVarExpr.h:616
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SMatVarExpr.h:930
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression,...
Definition: Assert.h:101
Operand operand() const noexcept
Returns the sparse matrix operand.
Definition: SMatVarExpr.h:918
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a sparse, N-dimensional matrix type,...
Definition: SparseMatrix.h:61
Header file for the reduction flags.
PointerType pointer
Pointer return type.
Definition: SMatVarExpr.h:624
Header file for the IsExpression type trait class.
Header file for the function trace functionality.
ReduceTrait_t< RT, InvAdd, columnwise > ResultType
Result type for expression template evaluations.
Definition: SMatVarExpr.h:127