35#ifndef _BLAZE_MATH_EXPRESSIONS_SMATDMATSCHUREXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_SMATDMATSCHUREXPR_H_
101 :
public SchurExpr< SparseMatrix< SMatDMatSchurExpr<MT1,MT2>, false > >
121 static constexpr bool returnExpr = ( !IsTemporary_v<RN1> && !IsTemporary_v<RN2> );
135 static constexpr bool useAssign = ( RequiresEvaluation_v<MT1> || RequiresEvaluation_v<MT2> );
139 template<
typename MT >
140 static constexpr bool UseAssign_v =
useAssign;
258 return left_->index();
347 if( i >=
lhs_.rows() ) {
350 if( j >=
lhs_.columns() ) {
384 inline size_t rows() const noexcept {
395 return lhs_.columns();
405 return lhs_.nonZeros();
416 return lhs_.nonZeros(i);
485 template<
typename T >
486 inline bool canAlias(
const T* alias )
const noexcept {
487 return (
lhs_.canAlias( alias ) ||
rhs_.isAliased( alias ) );
497 template<
typename T >
498 inline bool isAliased(
const T* alias )
const noexcept {
499 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
521 template<
typename MT
541 for(
size_t i=0UL; i<(*lhs).rows(); ++i ) {
542 for(
auto element=A.begin(i); element!=A.end(i); ++element )
543 (*lhs)(i,element->index()) = element->value() * B(i,element->index());
561 template<
typename MT >
581 (*lhs).reserve( A.nonZeros() );
584 for(
size_t i=0UL; i<(*lhs).rows(); ++i ) {
585 for(
auto element=A.begin(i); element!=A.end(i); ++element )
586 (*lhs).append( i, element->index(), element->value() * B(i,element->index()) );
587 (*lhs).finalize( i );
606 template<
typename MT >
607 friend inline auto assign( SparseMatrix<MT,true>& lhs,
const SMatDMatSchurExpr& rhs )
608 -> EnableIf_t< UseAssign_v<MT> >
625 const size_t m( rhs.rows() );
626 const size_t n( rhs.columns() );
629 std::vector<size_t> nonzeros( n, 0UL );
630 for(
size_t i=0UL; i<m; ++i ) {
631 const auto lend( A.end(i) );
632 for(
auto l=A.begin(i); l!=lend; ++l ) {
633 ++nonzeros[l->index()];
638 for(
size_t j=0UL; j<n; ++j ) {
639 (*lhs).reserve( j, nonzeros[j] );
643 for(
size_t i=0UL; i<m; ++i ) {
644 for(
auto element=A.begin(i); element!=A.end(i); ++element )
645 (*lhs).append( i, element->index(), element->value() * B(i,element->index()) );
663 template<
typename MT
665 friend inline auto addAssign( DenseMatrix<MT,SO2>& lhs,
const SMatDMatSchurExpr& rhs )
666 -> EnableIf_t< UseAssign_v<MT> >
683 for(
size_t i=0UL; i<(*lhs).rows(); ++i ) {
684 for(
auto element=A.begin(i); element!=A.end(i); ++element )
685 (*lhs)(i,element->index()) += element->value() * B(i,element->index());
707 template<
typename MT
709 friend inline auto subAssign( DenseMatrix<MT,SO2>& lhs,
const SMatDMatSchurExpr& rhs )
710 -> EnableIf_t< UseAssign_v<MT> >
727 for(
size_t i=0UL; i<(*lhs).rows(); ++i ) {
728 for(
auto element=A.begin(i); element!=A.end(i); ++element )
729 (*lhs)(i,element->index()) -= element->value() * B(i,element->index());
752 template<
typename MT
754 friend inline void schurAssign( DenseMatrix<MT,SO2>& lhs,
const SMatDMatSchurExpr& rhs )
771 for(
size_t i=0UL; i<(*lhs).rows(); ++i )
773 const auto end( A.end(i) );
774 auto begin( A.begin(i) );
779 for( ; j<index; ++j )
780 reset( (*lhs)(i,j) );
781 (*lhs)(i,index) *=
begin->
value() * B(i,index);
785 for( ; j<(*lhs).columns(); ++j )
786 reset( (*lhs)(i,j) );
841 template<
typename MT
902template<
typename MT1
904 ,
DisableIf_t< ( IsUniLower_v<MT1> && IsUniUpper_v<MT2> ) ||
905 ( IsUniUpper_v<MT1> && IsUniLower_v<MT2> ) ||
906 ( IsStrictlyLower_v<MT1> && IsUpper_v<MT2> ) ||
907 ( IsStrictlyUpper_v<MT1> && IsLower_v<MT2> ) ||
908 ( IsLower_v<MT1> && IsStrictlyUpper_v<MT2> ) ||
909 ( IsUpper_v<MT1> && IsStrictlyLower_v<MT2> ) ||
910 IsZero_v<MT1> >* =
nullptr >
911inline const SMatDMatSchurExpr<MT1,MT2>
912 smatdmatschur(
const SparseMatrix<MT1,false>& lhs,
const DenseMatrix<MT2,false>& rhs )
919 return SMatDMatSchurExpr<MT1,MT2>( *lhs, *rhs );
939template<
typename MT1
941 ,
EnableIf_t< ( IsUniLower_v<MT1> && IsUniUpper_v<MT2> ) ||
942 ( IsUniUpper_v<MT1> && IsUniLower_v<MT2> ) >* =
nullptr >
944 smatdmatschur(
const SparseMatrix<MT1,false>& lhs,
const DenseMatrix<MT2,false>& rhs )
953 using ReturnType =
const SchurTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
958 return ReturnType( (*lhs).rows() );
978template<
typename MT1
980 ,
EnableIf_t< ( IsStrictlyLower_v<MT1> && IsUpper_v<MT2> ) ||
981 ( IsStrictlyUpper_v<MT1> && IsLower_v<MT2> ) ||
982 ( IsLower_v<MT1> && IsStrictlyUpper_v<MT2> ) ||
983 ( IsUpper_v<MT1> && IsStrictlyLower_v<MT2> ) ||
984 IsZero_v<MT1> >* =
nullptr >
986 smatdmatschur(
const SparseMatrix<MT1,false>& lhs,
const DenseMatrix<MT2,false>& rhs )
995 using ReturnType =
const SchurTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
1000 return ReturnType( (*lhs).rows(), (*lhs).columns() );
1035template<
typename MT1
1037inline decltype(
auto)
1042 if( (*lhs).rows() != (*rhs).rows() || (*lhs).columns() != (*rhs).columns() ) {
1046 return smatdmatschur( *lhs, *rhs );
1064template<
typename MT1
1066 ,
DisableIf_t< ( IsUniLower_v<MT1> && IsUniUpper_v<MT2> ) ||
1067 ( IsUniUpper_v<MT1> && IsUniLower_v<MT2> ) ||
1068 ( IsStrictlyLower_v<MT1> && IsUpper_v<MT2> ) ||
1069 ( IsStrictlyUpper_v<MT1> && IsLower_v<MT2> ) ||
1070 ( IsLower_v<MT1> && IsStrictlyUpper_v<MT2> ) ||
1071 ( IsUpper_v<MT1> && IsStrictlyLower_v<MT2> ) ||
1072 IsZero_v<MT1> >* =
nullptr >
1073inline const SMatDMatSchurExpr<MT1,MT2>
1074 smattdmatschur(
const SparseMatrix<MT1,false>& lhs,
const DenseMatrix<MT2,true>& rhs )
1081 return SMatDMatSchurExpr<MT1,MT2>( *lhs, *rhs );
1101template<
typename MT1
1103 ,
EnableIf_t< ( IsUniLower_v<MT1> && IsUniUpper_v<MT2> ) ||
1104 ( IsUniUpper_v<MT1> && IsUniLower_v<MT2> ) >* =
nullptr >
1105inline decltype(
auto)
1106 smattdmatschur(
const SparseMatrix<MT1,false>& lhs,
const DenseMatrix<MT2,true>& rhs )
1115 using ReturnType =
const SchurTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
1120 return ReturnType( (*lhs).rows() );
1140template<
typename MT1
1142 ,
EnableIf_t< ( IsStrictlyLower_v<MT1> && IsUpper_v<MT2> ) ||
1143 ( IsStrictlyUpper_v<MT1> && IsLower_v<MT2> ) ||
1144 ( IsLower_v<MT1> && IsStrictlyUpper_v<MT2> ) ||
1145 ( IsUpper_v<MT1> && IsStrictlyLower_v<MT2> ) ||
1146 IsZero_v<MT1> >* =
nullptr >
1147inline decltype(
auto)
1148 smattdmatschur(
const SparseMatrix<MT1,false>& lhs,
const DenseMatrix<MT2,true>& rhs )
1157 using ReturnType =
const SchurTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
1162 return ReturnType( (*lhs).rows(), (*lhs).columns() );
1198template<
typename MT1
1200inline decltype(
auto)
1205 if( (*lhs).rows() != (*rhs).rows() || (*lhs).columns() != (*rhs).columns() ) {
1209 return smattdmatschur( *lhs, *rhs );
1224template<
typename MT1,
typename MT2 >
1225struct Size< SMatDMatSchurExpr<MT1,MT2>, 0UL >
1226 :
public Max_t< Size<MT1,0UL>, Size<MT2,0UL> >
1229template<
typename MT1,
typename MT2 >
1230struct Size< SMatDMatSchurExpr<MT1,MT2>, 1UL >
1231 :
public Max_t< Size<MT1,1UL>, Size<MT2,1UL> >
Header file for auxiliary alias declarations.
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.
Definition: Aliases.h:110
typename T::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.
Definition: Aliases.h:470
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::ConstIterator ConstIterator_t
Alias declaration for nested ConstIterator type definitions.
Definition: Aliases.h:130
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 EnableIf class template.
Header file for the function trace functionality.
Constraint on the data type.
Header file for the If class template.
Header file for the IntegralConstant class template.
Header file for the IsExpression type trait class.
Header file for the IsLower type trait.
Header file for the IsStrictlyLower type trait.
Header file for the IsStrictlyUpper type trait.
Header file for the IsTemporary type trait class.
Header file for the IsUniLower type trait.
Header file for the IsUniUpper type trait.
Header file for the IsUpper type trait.
Header file for the MAYBE_UNUSED function template.
Header file for the RemoveReference type trait.
Constraints on the storage order of matrix types.
Header file for the Schur product trait.
Header file for the ValueIndexPair class.
Constraint on the data type.
Base class for dense matrices.
Definition: DenseMatrix.h:82
Iterator over the elements of the sparse matrix/dense matrix Schur product expression.
Definition: SMatDMatSchurExpr.h:174
bool operator!=(const ConstIterator &rhs) const
Inequality comparison between two ConstIterator objects.
Definition: SMatDMatSchurExpr.h:279
bool operator==(const ConstIterator &rhs) const
Equality comparison between two ConstIterator objects.
Definition: SMatDMatSchurExpr.h:268
ValueType & ReferenceType
Reference return type.
Definition: SMatDMatSchurExpr.h:186
ConstIterator & operator++()
Pre-increment operator.
Definition: SMatDMatSchurExpr.h:216
std::forward_iterator_tag IteratorCategory
The iterator category.
Definition: SMatDMatSchurExpr.h:183
ConstIterator_t< RemoveReference_t< LeftOperand > > LeftIterator
Iterator type of the sparse matrix expression.
Definition: SMatDMatSchurExpr.h:181
RightOperand right_
Right-hand side dense matrix expression.
Definition: SMatDMatSchurExpr.h:298
Element ValueType
Type of the underlying pointers.
Definition: SMatDMatSchurExpr.h:184
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: SMatDMatSchurExpr.h:187
ReturnType value() const
Access to the current value of the sparse element.
Definition: SMatDMatSchurExpr.h:247
ValueIndexPair< ElementType > Element
Element type of the sparse matrix expression.
Definition: SMatDMatSchurExpr.h:178
DifferenceType difference_type
Difference between two iterators.
Definition: SMatDMatSchurExpr.h:194
ConstIterator(LeftIterator left, RightOperand right, size_t row)
Constructor for the ConstIterator class.
Definition: SMatDMatSchurExpr.h:204
const ConstIterator * operator->() const
Direct access to the sparse matrix element at the current iterator position.
Definition: SMatDMatSchurExpr.h:237
const Element operator*() const
Direct access to the sparse matrix element at the current iterator position.
Definition: SMatDMatSchurExpr.h:227
LeftIterator left_
Iterator over the elements of the left-hand side sparse matrix expression.
Definition: SMatDMatSchurExpr.h:297
size_t row_
The row index of the iterator.
Definition: SMatDMatSchurExpr.h:299
IteratorCategory iterator_category
The iterator category.
Definition: SMatDMatSchurExpr.h:190
DifferenceType operator-(const ConstIterator &rhs) const
Calculating the number of elements between two expression iterators.
Definition: SMatDMatSchurExpr.h:290
size_t index() const
Access to the current index of the sparse element.
Definition: SMatDMatSchurExpr.h:257
ValueType * PointerType
Pointer return type.
Definition: SMatDMatSchurExpr.h:185
Expression object for sparse matrix-dense matrix Schur product.
Definition: SMatDMatSchurExpr.h:103
RightOperand rhs_
Right-hand side dense matrix of the Schur product expression.
Definition: SMatDMatSchurExpr.h:506
ConstIterator upperBound(size_t i, size_t j) const
Returns an iterator to the first index greater then the given index.
Definition: SMatDMatSchurExpr.h:453
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: SMatDMatSchurExpr.h:306
If_t< useAssign, const ResultType, const SMatDMatSchurExpr & > CompositeType
Data type for composite expression templates.
Definition: SMatDMatSchurExpr.h:161
ReturnType_t< MT2 > RN2
Return type of the right-hand side dense matrix expression.
Definition: SMatDMatSchurExpr.h:109
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SMatDMatSchurExpr.h:486
LeftOperand lhs_
Left-hand side sparse matrix of the Schur product expression.
Definition: SMatDMatSchurExpr.h:505
ConstIterator end(size_t i) const
Returns an iterator just past the last non-zero element of row i.
Definition: SMatDMatSchurExpr.h:374
static constexpr bool useAssign
Compilation switch for the evaluation strategy of the Schur product expression.
Definition: SMatDMatSchurExpr.h:135
ConstIterator find(size_t i, size_t j) const
Searches for a specific matrix element.
Definition: SMatDMatSchurExpr.h:427
decltype(std::declval< RN1 >() *std::declval< RN2 >()) ExprReturnType
Expression return type for the subscript operator.
Definition: SMatDMatSchurExpr.h:124
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: SMatDMatSchurExpr.h:394
SMatDMatSchurExpr(const MT1 &lhs, const MT2 &rhs) noexcept
Constructor for the SMatDMatSchurExpr class.
Definition: SMatDMatSchurExpr.h:315
SchurTrait_t< RT1, RT2 > ResultType
Result type for expression template evaluations.
Definition: SMatDMatSchurExpr.h:152
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: SMatDMatSchurExpr.h:154
CompositeType_t< MT1 > CT1
Composite type of the left-hand side sparse matrix expression.
Definition: SMatDMatSchurExpr.h:110
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse matrix operand.
Definition: SMatDMatSchurExpr.h:464
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: SMatDMatSchurExpr.h:384
CompositeType_t< MT2 > CT2
Composite type of the right-hand side dense matrix expression.
Definition: SMatDMatSchurExpr.h:111
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row.
Definition: SMatDMatSchurExpr.h:415
OppositeType_t< ResultType > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: SMatDMatSchurExpr.h:153
If_t< IsExpression_v< MT2 >, const MT2, const MT2 & > RightOperand
Composite type of the right-hand side dense matrix expression.
Definition: SMatDMatSchurExpr.h:167
const If_t< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: SMatDMatSchurExpr.h:158
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SMatDMatSchurExpr.h:498
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: SMatDMatSchurExpr.h:346
ConstIterator lowerBound(size_t i, size_t j) const
Returns an iterator to the first index not less then the given index.
Definition: SMatDMatSchurExpr.h:440
ConstIterator begin(size_t i) const
Returns an iterator to the first non-zero element of row i.
Definition: SMatDMatSchurExpr.h:363
RightOperand rightOperand() const noexcept
Returns the right-hand side dense matrix operand.
Definition: SMatDMatSchurExpr.h:474
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: SMatDMatSchurExpr.h:155
ResultType_t< MT2 > RT2
Result type of the right-hand side dense matrix expression.
Definition: SMatDMatSchurExpr.h:107
If_t< IsExpression_v< MT1 >, const MT1, const MT1 & > LeftOperand
Composite type of the left-hand side sparse matrix expression.
Definition: SMatDMatSchurExpr.h:164
ResultType_t< MT1 > RT1
Result type of the left-hand side sparse matrix expression.
Definition: SMatDMatSchurExpr.h:106
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: SMatDMatSchurExpr.h:331
ReturnType_t< MT1 > RN1
Return type of the left-hand side sparse matrix expression.
Definition: SMatDMatSchurExpr.h:108
static constexpr bool returnExpr
Compilation switch for the selection of the subscript operator return type.
Definition: SMatDMatSchurExpr.h:121
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: SMatDMatSchurExpr.h:404
Base class for sparse matrices.
Definition: SparseMatrix.h:77
Index-value-pair for sparse vectors and matrices.
Definition: ValueIndexPair.h:75
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Header file for the Computation base class.
Header file for the SchurExpr base class.
Header file for the SparseMatrix base class.
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:812
#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_NOT_BE_ZERO_TYPE(T)
Constraint on the data type.
Definition: Zero.h:81
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: DenseMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: SparseMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_BE_IDENTITY_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Identity.h:60
#define BLAZE_CONSTRAINT_MUST_FORM_VALID_SCHUREXPR(T1, T2)
Constraint on the data type.
Definition: SchurExpr.h:103
#define BLAZE_CONSTRAINT_MUST_BE_ZERO_TYPE(T)
Constraint on the data type.
Definition: Zero.h:61
typename SchurTrait< T1, T2 >::Type SchurTrait_t
Auxiliary alias declaration for the SchurTrait class template.
Definition: SchurTrait.h:137
constexpr void reset(Matrix< MT, SO > &matrix)
Resetting the given matrix.
Definition: Matrix.h:806
If_t< Less_t< T1, T2 >::value, T2, T1 > Max_t
Compile time value evaluation.
Definition: Max.h:73
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
auto smpSchurAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP Schur product assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:194
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
typename EnableIf<!Condition, T >::Type DisableIf_t
Auxiliary type for the EnableIf class template.
Definition: EnableIf.h:175
#define BLAZE_FUNCTION_TRACE
Function trace macro.
Definition: FunctionTrace.h:94
Header file for the exception macros of the math module.
Header file for all forward declarations for expression class templates.
Header file for all forward declarations for sparse vectors and matrices.
Header file for the Size type trait.
Header file for the serial shim.
Base class for all compute expression templates.
Definition: Computation.h:68
Base class for all Schur product expression templates.
Definition: SchurExpr.h:68
Header file for the IsZero type trait.
Header file for basic type definitions.
Header file for the Max_t alias template.