35#ifndef _BLAZE_MATH_EXPRESSIONS_SMATVAREXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_SMATVAREXPR_H_
112template<
typename MT >
114 :
public MatReduceExpr< DenseVector< SMatVarExpr<MT,columnwise>, true >, columnwise >
144 static constexpr bool simdEnabled =
false;
147 static constexpr bool smpAssignable =
false;
180 if( index >= sm_.columns() ) {
183 return (*
this)[index];
192 inline size_t size() const noexcept {
193 return sm_.columns();
213 template<
typename T >
214 inline bool canAlias(
const T* alias )
const noexcept {
215 return ( sm_.isAliased( alias ) );
225 template<
typename T >
226 inline bool isAliased(
const T* alias )
const noexcept {
227 return ( sm_.isAliased( alias ) );
258 template<
typename VT1 >
270 assign( *lhs, var<columnwise>( tmp ) );
288 template<
typename VT1 >
299 const ResultType tmp(
serial( rhs ) );
318 template<
typename VT1 >
319 friend inline void addAssign( DenseVector<VT1,true>& lhs,
const SMatVarExpr& rhs )
329 const OT tmp(
serial( rhs.sm_ ) );
330 addAssign( *lhs, var<columnwise>( tmp ) );
348 template<
typename VT1 >
349 friend inline void addAssign( SparseVector<VT1,true>& lhs,
const SMatVarExpr& rhs )
359 const ResultType tmp(
serial( rhs ) );
360 addAssign( *lhs, tmp );
378 template<
typename VT1 >
379 friend inline void subAssign( DenseVector<VT1,true>& lhs,
const SMatVarExpr& rhs )
389 const OT tmp(
serial( rhs.sm_ ) );
390 subAssign( *lhs, var<columnwise>( tmp ) );
408 template<
typename VT1 >
409 friend inline void subAssign( SparseVector<VT1,true>& lhs,
const SMatVarExpr& rhs )
419 const ResultType tmp(
serial( rhs ) );
420 subAssign( *lhs, tmp );
438 template<
typename VT1 >
439 friend inline void multAssign( DenseVector<VT1,true>& lhs,
const SMatVarExpr& rhs )
449 const OT tmp(
serial( rhs.sm_ ) );
450 multAssign( *lhs, var<columnwise>( tmp ) );
468 template<
typename VT1 >
469 friend inline void multAssign( SparseVector<VT1,true>& lhs,
const SMatVarExpr& rhs )
479 const ResultType tmp(
serial( rhs ) );
480 multAssign( *lhs, tmp );
498 template<
typename VT1 >
499 friend inline void divAssign( DenseVector<VT1,true>& lhs,
const SMatVarExpr& rhs )
509 const OT tmp(
serial( rhs.sm_ ) );
510 divAssign( *lhs, var<columnwise>( tmp ) );
528 template<
typename VT1 >
529 friend inline void divAssign( SparseVector<VT1,true>& lhs,
const SMatVarExpr& rhs )
539 const ResultType tmp(
serial( rhs ) );
540 divAssign( *lhs, tmp );
570template<
typename MT >
572 :
public MatReduceExpr< DenseVector< SMatVarExpr<MT,rowwise>, false >, rowwise >
588 static constexpr bool useAssign = RequiresEvaluation_v<MT>;
592 template<
typename VT >
593 static constexpr bool UseAssign_v = useAssign;
691 return ConstIterator( index_++ );
712 return ConstIterator( index_-- );
733 return index_ == rhs.index_;
744 return index_ != rhs.index_;
754 inline bool operator<(
const ConstIterator& rhs )
const {
755 return index_ < rhs.index_;
765 inline bool operator>(
const ConstIterator& rhs )
const {
766 return index_ > rhs.index_;
777 return index_ <= rhs.index_;
788 return index_ >= rhs.index_;
799 return index_ - rhs.index_;
810 friend inline const ConstIterator
operator+(
const ConstIterator& it,
size_t inc ) {
811 return ConstIterator( it.index_ + inc );
822 friend inline const ConstIterator
operator+(
size_t inc,
const ConstIterator& it ) {
823 return ConstIterator( it.index_ + inc );
834 friend inline const ConstIterator
operator-(
const ConstIterator& it,
size_t dec ) {
835 return ConstIterator( it.index_ - dec );
849 static constexpr bool simdEnabled =
false;
852 static constexpr bool smpAssignable =
false;
885 if( index >= sm_.rows() ) {
888 return (*
this)[index];
897 inline ConstIterator
begin()
const {
898 return ConstIterator( sm_, 0UL );
907 inline ConstIterator
end()
const {
908 return ConstIterator( sm_,
size() );
917 inline size_t size() const noexcept {
938 template<
typename T >
939 inline bool canAlias(
const T* alias )
const noexcept {
940 return ( sm_.isAliased( alias ) );
950 template<
typename T >
951 inline bool isAliased(
const T* alias )
const noexcept {
952 return ( sm_.isAliased( alias ) );
985 template<
typename VT1 >
994 assign( *lhs, var<rowwise>( tmp ) );
1013 template<
typename VT1 >
1021 const RT tmp(
serial( rhs.sm_ ) );
1022 addAssign( *lhs, var<rowwise>( tmp ) );
1042 template<
typename VT1 >
1043 friend inline auto subAssign( Vector<VT1,false>& lhs,
const SMatVarExpr& rhs )
1044 -> EnableIf_t< UseAssign_v<VT1> >
1050 const RT tmp(
serial( rhs.sm_ ) );
1051 subAssign( *lhs, var<rowwise>( tmp ) );
1071 template<
typename VT1 >
1072 friend inline auto multAssign( Vector<VT1,false>& lhs,
const SMatVarExpr& rhs )
1073 -> EnableIf_t< UseAssign_v<VT1> >
1079 const RT tmp(
serial( rhs.sm_ ) );
1080 multAssign( *lhs, var<rowwise>( tmp ) );
1099 template<
typename VT1 >
1100 friend inline auto divAssign( Vector<VT1,false>& lhs,
const SMatVarExpr& rhs )
1101 -> EnableIf_t< UseAssign_v<VT1> >
1107 const RT tmp(
serial( rhs.sm_ ) );
1108 divAssign( *lhs, var<rowwise>( tmp ) );
1139template<
typename MT
1141inline decltype(
auto) var_backend(
const SparseMatrix<MT,SO>& sm,
FalseType )
1143 using BT = UnderlyingBuiltin_t<MT>;
1145 const size_t n (
size( *sm ) );
1146 const size_t nz(
nonZeros( *sm ) );
1151 const auto meanValue(
mean( *sm ) );
1152 auto variance( ( n - nz ) *
pow2( meanValue ) );
1154 const size_t iend( SO ? (*sm).columns() : (*sm).rows() );
1155 for(
size_t i=0UL; i<iend; ++i ) {
1156 const auto end( (*sm).end(i) );
1157 for(
auto element=(*sm).begin(i); element!=
end; ++element ) {
1158 variance +=
pow2( element->value() - meanValue );
1162 return variance *
inv( BT( n-1UL ) );
1176template<
typename MT
1178inline decltype(
auto) var_backend(
const SparseMatrix<MT,SO>& sm,
TrueType )
1184 return ElementType_t<MT>();
1214template<
typename MT
1220 if(
size( *sm ) < 2UL ) {
1237template< ReductionFlag RF
1239inline const SMatVarExpr<MT,RF> var_backend(
const SparseMatrix<MT,false>& sm )
1241 using ReturnType =
const SMatVarExpr<MT,RF>;
1242 return ReturnType( *sm );
1258inline decltype(
auto) var_backend(
const SparseMatrix<MT,true>& sm )
1260 constexpr ReductionFlag RF2( RF == rowwise ? columnwise : rowwise );
1312 return var_backend<RF>( *sm );
Header file for auxiliary alias declarations.
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.
Definition: Aliases.h:110
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.
Definition: Aliases.h:450
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.
Definition: Aliases.h:190
typename T::OppositeType OppositeType_t
Alias declaration for nested OppositeType type definitions.
Definition: Aliases.h:310
typename T::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.
Definition: Aliases.h:550
Header file for run time assertion macros.
Header file for the blaze::checked and blaze::unchecked instances.
Header file for the EnableIf class template.
Header file for the function trace functionality.
Header file for the If class template.
Header file for the IntegralConstant class template.
Header file for the InvAdd functor.
Header file for the invert shim.
Header file for the IsExpression type trait class.
Deactivation of problematic macros.
Header file for the MAYBE_UNUSED function template.
Header file for the reduce trait.
Header file for the reduction flags.
constexpr ReductionFlag columnwise
Reduction flag for column-wise reduction operations.
Definition: ReductionFlag.h:97
constexpr ReductionFlag rowwise
Reduction flag for row-wise reduction operations.
Definition: ReductionFlag.h:77
size_t ReductionFlag
Type of the reduction flags.
Definition: ReductionFlag.h:57
Constraints on the storage order of matrix types.
Header file for the UnderlyingBuiltin type trait.
Base class for N-dimensional dense vectors.
Definition: DenseVector.h:77
Expression object for the column-wise variance function on row-major sparse matrices.
Definition: SMatVarExpr.h:116
SMatVarExpr(const MT &sm) noexcept
Constructor for the SMatVarExpr class.
Definition: SMatVarExpr.h:155
const ResultType CompositeType
Data type for composite expression templates.
Definition: SMatVarExpr.h:136
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SMatVarExpr.h:214
Operand operand() const noexcept
Returns the sparse matrix operand.
Definition: SMatVarExpr.h:202
Operand sm_
Sparse matrix of the variance expression.
Definition: SMatVarExpr.h:243
ReduceTrait_t< RT, InvAdd, columnwise > ResultType
Result type for expression template evaluations.
Definition: SMatVarExpr.h:132
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: SMatVarExpr.h:133
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SMatVarExpr.h:226
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: SMatVarExpr.h:179
OppositeType_t< MT > OT
Opposite type of the sparse matrix expression.
Definition: SMatVarExpr.h:120
If_t< IsExpression_v< MT >, const MT, const MT & > Operand
Composite type of the left-hand side sparse matrix expression.
Definition: SMatVarExpr.h:139
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SMatVarExpr.h:166
bool isAligned() const noexcept
Returns whether the operands of the expression are properly aligned in memory.
Definition: SMatVarExpr.h:236
ResultType_t< MT > RT
Result type of the sparse matrix expression.
Definition: SMatVarExpr.h:119
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: SMatVarExpr.h:192
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: SMatVarExpr.h:134
const ElementType ReturnType
Return type for expression template evaluations.
Definition: SMatVarExpr.h:135
CompositeType_t< MT > CT
Composite type of the sparse matrix expression.
Definition: SMatVarExpr.h:121
const ConstIterator operator--(int)
Post-decrement operator.
Definition: SMatVarExpr.h:711
IteratorCategory iterator_category
The iterator category.
Definition: SMatVarExpr.h:631
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: SMatVarExpr.h:628
ConstIterator(Operand sm, size_t index)
Constructor for the ConstIterator class.
Definition: SMatVarExpr.h:644
ConstIterator & operator-=(size_t dec)
Subtraction assignment operator.
Definition: SMatVarExpr.h:668
Operand sm_
Sparse matrix of the variance expression.
Definition: SMatVarExpr.h:841
ValueType value_type
Type of the underlying elements.
Definition: SMatVarExpr.h:632
bool operator>=(const ConstIterator &rhs) const
Greater-than comparison between two ConstIterator objects.
Definition: SMatVarExpr.h:787
ElementType ValueType
Type of the underlying elements.
Definition: SMatVarExpr.h:625
size_t index_
Index to the current matrix row.
Definition: SMatVarExpr.h:842
bool operator<=(const ConstIterator &rhs) const
Less-than comparison between two ConstIterator objects.
Definition: SMatVarExpr.h:776
bool operator==(const ConstIterator &rhs) const
Equality comparison between two ConstIterator objects.
Definition: SMatVarExpr.h:732
const ConstIterator operator++(int)
Post-increment operator.
Definition: SMatVarExpr.h:690
ConstIterator & operator--()
Pre-decrement operator.
Definition: SMatVarExpr.h:700
DifferenceType difference_type
Difference between two iterators.
Definition: SMatVarExpr.h:635
bool operator<(const ConstIterator &rhs) const
Less-than comparison between two ConstIterator objects.
Definition: SMatVarExpr.h:754
ElementType & ReferenceType
Reference return type.
Definition: SMatVarExpr.h:627
friend const ConstIterator operator+(const ConstIterator &it, size_t inc)
Addition between a ConstIterator and an integral value.
Definition: SMatVarExpr.h:810
std::random_access_iterator_tag IteratorCategory
The iterator category.
Definition: SMatVarExpr.h:624
ReferenceType reference
Reference return type.
Definition: SMatVarExpr.h:634
bool operator!=(const ConstIterator &rhs) const
Inequality comparison between two ConstIterator objects.
Definition: SMatVarExpr.h:743
ConstIterator & operator++()
Pre-increment operator.
Definition: SMatVarExpr.h:679
friend const ConstIterator operator-(const ConstIterator &it, size_t dec)
Subtraction between a ConstIterator and an integral value.
Definition: SMatVarExpr.h:834
ReturnType operator*() const
Direct access to the element at the current iterator position.
Definition: SMatVarExpr.h:721
friend const ConstIterator operator+(size_t inc, const ConstIterator &it)
Addition between an integral value and a ConstIterator.
Definition: SMatVarExpr.h:822
DifferenceType operator-(const ConstIterator &rhs) const
Calculating the number of elements between two iterators.
Definition: SMatVarExpr.h:798
ElementType * PointerType
Pointer return type.
Definition: SMatVarExpr.h:626
PointerType pointer
Pointer return type.
Definition: SMatVarExpr.h:633
bool operator>(const ConstIterator &rhs) const
Greater-than comparison between two ConstIterator objects.
Definition: SMatVarExpr.h:765
ConstIterator & operator+=(size_t inc)
Addition assignment operator.
Definition: SMatVarExpr.h:656
Expression object for the row-wise variance function on row-major sparse matrices.
Definition: SMatVarExpr.h:574
ReduceTrait_t< RT, InvAdd, rowwise > ResultType
Result type for expression template evaluations.
Definition: SMatVarExpr.h:605
ConstIterator end() const
Returns an iterator just past the last non-zero element of the dense vector.
Definition: SMatVarExpr.h:907
Operand sm_
Sparse matrix of the variance expression.
Definition: SMatVarExpr.h:968
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: SMatVarExpr.h:606
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SMatVarExpr.h:939
If_t< useAssign, const ResultType, const SMatVarExpr & > CompositeType
Data type for composite expression templates.
Definition: SMatVarExpr.h:611
ConstIterator begin() const
Returns an iterator to the first non-zero element of the dense vector.
Definition: SMatVarExpr.h:897
Operand operand() const noexcept
Returns the sparse matrix operand.
Definition: SMatVarExpr.h:927
SMatVarExpr(const MT &sm) noexcept
Constructor for the SMatVarExpr class.
Definition: SMatVarExpr.h:860
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: SMatVarExpr.h:917
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SMatVarExpr.h:951
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: SMatVarExpr.h:884
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SMatVarExpr.h:871
bool isAligned() const noexcept
Returns whether the operands of the expression are properly aligned in memory.
Definition: SMatVarExpr.h:961
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: SMatVarExpr.h:607
If_t< IsExpression_v< MT >, const MT, const MT & > Operand
Composite type of the left-hand side sparse matrix expression.
Definition: SMatVarExpr.h:614
const ElementType ReturnType
Return type for expression template evaluations.
Definition: SMatVarExpr.h:608
ResultType_t< MT > RT
Result type of the sparse matrix expression.
Definition: SMatVarExpr.h:577
Base template for the row-/column-wise variance computations on row-major sparse matrices.
Definition: SMatVarExpr.h:93
Base class for sparse matrices.
Definition: SparseMatrix.h:77
Base class for sparse vectors.
Definition: SparseVector.h:72
Base class for N-dimensional vectors.
Definition: Vector.h:82
Constraint on the data type.
Header file for the Computation base class.
Header file for the DenseVector base class.
Header file for the MatReduceExpr base class.
Header file for the SparseMatrix base class.
decltype(auto) column(Matrix< MT, SO > &matrix, RCAs... args)
Creating a view on a specific column of the given matrix.
Definition: Column.h:137
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:766
decltype(auto) mean(const DenseMatrix< MT, SO > &dm)
Computes the (arithmetic) mean for the given dense matrix.
Definition: DMatMeanExpr.h:134
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:812
decltype(auto) inv(const DenseMatrix< MT, SO > &dm)
Calculation of the inverse of the given dense matrix.
Definition: DMatInvExpr.h:405
decltype(auto) var(const DenseMatrix< MT, SO > &dm)
Computes the variance for the given dense matrix.
Definition: DMatVarExpr.h:138
#define BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.
Definition: RowMajorMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.
Definition: RequiresEvaluation.h:81
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: SparseMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE(T)
Constraint on the data type.
Definition: DenseVector.h:61
#define BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE(T)
Constraint on the data type.
Definition: RowVector.h:61
#define BLAZE_CONSTRAINT_MUST_BE_COLUMN_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.
Definition: ColumnMajorMatrix.h:61
typename ReduceTrait< T, OP, RF... >::Type ReduceTrait_t
Auxiliary alias declaration for the ReduceTrait class template.
Definition: ReduceTrait.h:150
size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:730
decltype(auto) pow2(const Matrix< MT, SO > &m)
Computes the square for each single element of the matrix m.
Definition: Matrix.h:686
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:584
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:676
decltype(auto) row(Matrix< MT, SO > &, RRAs...)
Creating a view on a specific row of the given matrix.
Definition: Row.h:137
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.
Definition: Assert.h:101
#define BLAZE_STATIC_ASSERT_MSG(expr, msg)
Compile time assertion macro.
Definition: StaticAssert.h:123
BoolConstant< true > TrueType
Type traits base class.
Definition: IntegralConstant.h:132
BoolConstant< false > FalseType
Type/value traits base class.
Definition: IntegralConstant.h:121
typename EnableIf< Condition, T >::Type EnableIf_t
Auxiliary type for the EnableIf class template.
Definition: EnableIf.h:138
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition: MaybeUnused.h:81
typename If< Condition >::template Type< T1, T2 > If_t
Auxiliary alias template for the If class template.
Definition: If.h:108
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.
Definition: Exception.h:331
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.
Definition: Exception.h:235
#define BLAZE_FUNCTION_TRACE
Function trace macro.
Definition: FunctionTrace.h:94
constexpr Unchecked unchecked
Global Unchecked instance.
Definition: Check.h:146
Header file for the exception macros of the math module.
Header file for all forward declarations for expression class templates.
Header file for the pow2 shim.
Header file for the serial shim.
Base class for all compute expression templates.
Definition: Computation.h:68
Compile time check for zero vectors or matrices.
Definition: IsZero.h:109
Base class for all matrix reduction expression templates.
Definition: MatReduceExpr.h:70
Header file for the IsZero type trait.
Header file for the RequiresEvaluation type trait.
Header file for basic type definitions.