35#ifndef _BLAZE_MATH_EXPRESSIONS_TSMATDMATSCHUREXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_TSMATDMATSCHUREXPR_H_
101 :
public SchurExpr< SparseMatrix< TSMatDMatSchurExpr<MT1,MT2>, true > >
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(j);
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 j=0UL; j<(*lhs).columns(); ++j ) {
542 for(
auto element=A.begin(j); element!=A.end(j); ++element )
543 (*lhs)(element->index(),j) = element->value() * B(element->index(),j);
562 template<
typename MT >
581 const size_t m( rhs.rows() );
582 const size_t n( rhs.columns() );
585 std::vector<size_t> nonzeros( m, 0UL );
586 for(
size_t j=0UL; j<n; ++j ) {
587 const auto lend( A.end(j) );
588 for(
auto l=A.begin(j); l!=lend; ++l ) {
589 ++nonzeros[l->index()];
594 for(
size_t i=0UL; i<m; ++i ) {
595 (*lhs).reserve( i, nonzeros[i] );
599 for(
size_t j=0UL; j<(*lhs).columns(); ++j ) {
600 for(
auto element=A.begin(j); element!=A.end(j); ++element )
601 (*lhs).append( element->index(), j, element->value() * B(element->index(),j) );
620 template<
typename MT >
621 friend inline auto assign( SparseMatrix<MT,true>& lhs,
const TSMatDMatSchurExpr& rhs )
622 -> EnableIf_t< UseAssign_v<MT> >
640 (*lhs).reserve( A.nonZeros() );
643 for(
size_t j=0UL; j<(*lhs).columns(); ++j ) {
644 for(
auto element=A.begin(j); element!=A.end(j); ++element )
645 (*lhs).append( element->index(), j, element->value() * B(element->index(),j) );
646 (*lhs).finalize( j );
665 template<
typename MT
667 friend inline auto addAssign( DenseMatrix<MT,SO2>& lhs,
const TSMatDMatSchurExpr& rhs )
668 -> EnableIf_t< UseAssign_v<MT> >
685 for(
size_t j=0UL; j<(*lhs).columns(); ++j ) {
686 for(
auto element=A.begin(j); element!=A.end(j); ++element )
687 (*lhs)(element->index(),j) += element->value() * B(element->index(),j);
710 template<
typename MT
712 friend inline auto subAssign( DenseMatrix<MT,SO2>& lhs,
const TSMatDMatSchurExpr& rhs )
713 -> EnableIf_t< UseAssign_v<MT> >
730 for(
size_t j=0UL; j<(*lhs).columns(); ++j ) {
731 for(
auto element=A.begin(j); element!=A.end(j); ++element )
732 (*lhs)(element->index(),j) -= element->value() * B(element->index(),j);
755 template<
typename MT
757 friend inline void schurAssign( DenseMatrix<MT,SO2>& lhs,
const TSMatDMatSchurExpr& rhs )
774 for(
size_t j=0UL; j<(*lhs).columns(); ++j )
776 const auto end( A.end(j) );
777 auto begin( A.begin(j) );
782 for( ; i<index; ++i )
783 reset( (*lhs)(i,j) );
784 (*lhs)(index,j) *=
begin->
value() * B(index,j);
788 for( ; i<(*lhs).rows(); ++i )
789 reset( (*lhs)(i,j) );
844 template<
typename MT
905template<
typename MT1
907 ,
DisableIf_t< ( IsUniLower_v<MT1> && IsUniUpper_v<MT2> ) ||
908 ( IsUniUpper_v<MT1> && IsUniLower_v<MT2> ) ||
909 ( IsStrictlyLower_v<MT1> && IsUpper_v<MT2> ) ||
910 ( IsStrictlyUpper_v<MT1> && IsLower_v<MT2> ) ||
911 ( IsLower_v<MT1> && IsStrictlyUpper_v<MT2> ) ||
912 ( IsUpper_v<MT1> && IsStrictlyLower_v<MT2> ) ||
913 IsZero_v<MT1> >* =
nullptr >
914inline const TSMatDMatSchurExpr<MT1,MT2>
915 tsmatdmatschur(
const SparseMatrix<MT1,true>& lhs,
const DenseMatrix<MT2,false>& rhs )
922 return TSMatDMatSchurExpr<MT1,MT2>( *lhs, *rhs );
942template<
typename MT1
944 ,
EnableIf_t< ( IsUniLower_v<MT1> && IsUniUpper_v<MT2> ) ||
945 ( IsUniUpper_v<MT1> && IsUniLower_v<MT2> ) >* =
nullptr >
947 tsmatdmatschur(
const SparseMatrix<MT1,true>& lhs,
const DenseMatrix<MT2,false>& rhs )
956 using ReturnType =
const SchurTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
961 return ReturnType( (*lhs).rows() );
981template<
typename MT1
983 ,
EnableIf_t< ( IsStrictlyLower_v<MT1> && IsUpper_v<MT2> ) ||
984 ( IsStrictlyUpper_v<MT1> && IsLower_v<MT2> ) ||
985 ( IsLower_v<MT1> && IsStrictlyUpper_v<MT2> ) ||
986 ( IsUpper_v<MT1> && IsStrictlyLower_v<MT2> ) ||
987 IsZero_v<MT1> >* =
nullptr >
989 tsmatdmatschur(
const SparseMatrix<MT1,true>& lhs,
const DenseMatrix<MT2,false>& rhs )
998 using ReturnType =
const SchurTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
1003 return ReturnType( (*lhs).rows(), (*lhs).columns() );
1039template<
typename MT1
1041inline decltype(
auto)
1046 if( (*lhs).rows() != (*rhs).rows() || (*lhs).columns() != (*rhs).columns() ) {
1050 return tsmatdmatschur( *lhs, *rhs );
1068template<
typename MT1
1070 ,
DisableIf_t< ( IsUniLower_v<MT1> && IsUniUpper_v<MT2> ) ||
1071 ( IsUniUpper_v<MT1> && IsUniLower_v<MT2> ) ||
1072 ( IsStrictlyLower_v<MT1> && IsUpper_v<MT2> ) ||
1073 ( IsStrictlyUpper_v<MT1> && IsLower_v<MT2> ) ||
1074 ( IsLower_v<MT1> && IsStrictlyUpper_v<MT2> ) ||
1075 ( IsUpper_v<MT1> && IsStrictlyLower_v<MT2> ) ||
1076 IsZero_v<MT1> >* =
nullptr >
1077inline const TSMatDMatSchurExpr<MT1,MT2>
1078 tsmattdmatschur(
const SparseMatrix<MT1,true>& lhs,
const DenseMatrix<MT2,true>& rhs )
1085 return TSMatDMatSchurExpr<MT1,MT2>( *lhs, *rhs );
1105template<
typename MT1
1107 ,
EnableIf_t< ( IsUniLower_v<MT1> && IsUniUpper_v<MT2> ) ||
1108 ( IsUniUpper_v<MT1> && IsUniLower_v<MT2> ) >* =
nullptr >
1109inline decltype(
auto)
1110 tsmattdmatschur(
const SparseMatrix<MT1,true>& lhs,
const DenseMatrix<MT2,true>& rhs )
1119 using ReturnType =
const SchurTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
1124 return ReturnType( (*lhs).rows() );
1144template<
typename MT1
1146 ,
EnableIf_t< ( IsStrictlyLower_v<MT1> && IsUpper_v<MT2> ) ||
1147 ( IsStrictlyUpper_v<MT1> && IsLower_v<MT2> ) ||
1148 ( IsLower_v<MT1> && IsStrictlyUpper_v<MT2> ) ||
1149 ( IsUpper_v<MT1> && IsStrictlyLower_v<MT2> ) ||
1150 IsZero_v<MT1> >* =
nullptr >
1151inline decltype(
auto)
1152 tsmattdmatschur(
const SparseMatrix<MT1,true>& lhs,
const DenseMatrix<MT2,true>& rhs )
1161 using ReturnType =
const SchurTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
1166 return ReturnType( (*lhs).rows(), (*lhs).columns() );
1201template<
typename MT1
1203inline decltype(
auto)
1208 if( (*lhs).rows() != (*rhs).rows() || (*lhs).columns() != (*rhs).columns() ) {
1212 return tsmattdmatschur( *lhs, *rhs );
1227template<
typename MT1,
typename MT2 >
1228struct Size< TSMatDMatSchurExpr<MT1,MT2>, 0UL >
1229 :
public Max_t< Size<MT1,0UL>, Size<MT2,0UL> >
1232template<
typename MT1,
typename MT2 >
1233struct Size< TSMatDMatSchurExpr<MT1,MT2>, 1UL >
1234 :
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.
Constraints on the storage order of matrix types.
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.
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
Base class for sparse matrices.
Definition: SparseMatrix.h:77
Iterator over the elements of the sparse matrix/dense matrix Schur product expression.
Definition: TSMatDMatSchurExpr.h:174
ValueType * PointerType
Pointer return type.
Definition: TSMatDMatSchurExpr.h:185
IteratorCategory iterator_category
The iterator category.
Definition: TSMatDMatSchurExpr.h:190
bool operator!=(const ConstIterator &rhs) const
Inequality comparison between two ConstIterator objects.
Definition: TSMatDMatSchurExpr.h:279
DifferenceType operator-(const ConstIterator &rhs) const
Calculating the number of elements between two expression iterators.
Definition: TSMatDMatSchurExpr.h:290
ReturnType value() const
Access to the current value of the sparse element.
Definition: TSMatDMatSchurExpr.h:247
RightOperand right_
Right-hand side dense matrix expression.
Definition: TSMatDMatSchurExpr.h:298
ValueIndexPair< ElementType > Element
Element type of the sparse matrix expression.
Definition: TSMatDMatSchurExpr.h:178
Element ValueType
Type of the underlying pointers.
Definition: TSMatDMatSchurExpr.h:184
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: TSMatDMatSchurExpr.h:187
ConstIterator(LeftIterator left, RightOperand right, size_t column)
Constructor for the ConstIterator class.
Definition: TSMatDMatSchurExpr.h:204
DifferenceType difference_type
Difference between two iterators.
Definition: TSMatDMatSchurExpr.h:194
const ConstIterator * operator->() const
Direct access to the sparse matrix element at the current iterator position.
Definition: TSMatDMatSchurExpr.h:237
const Element operator*() const
Direct access to the sparse matrix element at the current iterator position.
Definition: TSMatDMatSchurExpr.h:227
ConstIterator & operator++()
Pre-increment operator.
Definition: TSMatDMatSchurExpr.h:216
ValueType & ReferenceType
Reference return type.
Definition: TSMatDMatSchurExpr.h:186
std::forward_iterator_tag IteratorCategory
The iterator category.
Definition: TSMatDMatSchurExpr.h:183
size_t col_
The column index of the iterator.
Definition: TSMatDMatSchurExpr.h:299
size_t index() const
Access to the current index of the sparse element.
Definition: TSMatDMatSchurExpr.h:257
ConstIterator_t< RemoveReference_t< LeftOperand > > LeftIterator
Iterator type of the sparse matrix expression.
Definition: TSMatDMatSchurExpr.h:181
bool operator==(const ConstIterator &rhs) const
Equality comparison between two ConstIterator objects.
Definition: TSMatDMatSchurExpr.h:268
LeftIterator left_
Iterator over the elements of the left-hand side sparse matrix expression.
Definition: TSMatDMatSchurExpr.h:297
Expression object for transpose sparse matrix-dense matrix Schur product.
Definition: TSMatDMatSchurExpr.h:103
CompositeType_t< MT1 > CT1
Composite type of the left-hand side sparse matrix expression.
Definition: TSMatDMatSchurExpr.h:110
size_t nonZeros(size_t j) const
Returns the number of non-zero elements in the specified column.
Definition: TSMatDMatSchurExpr.h:415
CompositeType_t< MT2 > CT2
Composite type of the right-hand side dense matrix expression.
Definition: TSMatDMatSchurExpr.h:111
OppositeType_t< ResultType > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: TSMatDMatSchurExpr.h:153
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: TSMatDMatSchurExpr.h:498
const If_t< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: TSMatDMatSchurExpr.h:158
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: TSMatDMatSchurExpr.h:486
ReturnType_t< MT2 > RN2
Return type of the right-hand side dense matrix expression.
Definition: TSMatDMatSchurExpr.h:109
ConstIterator lowerBound(size_t i, size_t j) const
Returns an iterator to the first index not less then the given index.
Definition: TSMatDMatSchurExpr.h:440
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: TSMatDMatSchurExpr.h:306
RightOperand rightOperand() const noexcept
Returns the right-hand side dense matrix operand.
Definition: TSMatDMatSchurExpr.h:474
ConstIterator begin(size_t j) const
Returns an iterator to the first non-zero element of column j.
Definition: TSMatDMatSchurExpr.h:363
ConstIterator end(size_t j) const
Returns an iterator just past the last non-zero element of column j.
Definition: TSMatDMatSchurExpr.h:374
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: TSMatDMatSchurExpr.h:384
ConstIterator find(size_t i, size_t j) const
Searches for a specific matrix element.
Definition: TSMatDMatSchurExpr.h:427
LeftOperand lhs_
Left-hand side sparse matrix of the Schur product expression.
Definition: TSMatDMatSchurExpr.h:505
SchurTrait_t< RT1, RT2 > ResultType
Result type for expression template evaluations.
Definition: TSMatDMatSchurExpr.h:152
ResultType_t< MT1 > RT1
Result type of the left-hand side sparse matrix expression.
Definition: TSMatDMatSchurExpr.h:106
If_t< IsExpression_v< MT2 >, const MT2, const MT2 & > RightOperand
Composite type of the right-hand side dense matrix expression.
Definition: TSMatDMatSchurExpr.h:167
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: TSMatDMatSchurExpr.h:155
ReturnType_t< MT1 > RN1
Return type of the left-hand side sparse matrix expression.
Definition: TSMatDMatSchurExpr.h:108
TSMatDMatSchurExpr(const MT1 &lhs, const MT2 &rhs) noexcept
Constructor for the TSMatDMatSchurExpr class.
Definition: TSMatDMatSchurExpr.h:315
decltype(std::declval< RN1 >() *std::declval< RN2 >()) ExprReturnType
Expression return type for the subscript operator.
Definition: TSMatDMatSchurExpr.h:124
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: TSMatDMatSchurExpr.h:154
If_t< useAssign, const ResultType, const TSMatDMatSchurExpr & > CompositeType
Data type for composite expression templates.
Definition: TSMatDMatSchurExpr.h:161
static constexpr bool useAssign
Compilation switch for the evaluation strategy of the Schur product expression.
Definition: TSMatDMatSchurExpr.h:135
LeftOperand leftOperand() const noexcept
Returns the left-hand side transpose sparse matrix operand.
Definition: TSMatDMatSchurExpr.h:464
If_t< IsExpression_v< MT1 >, const MT1, const MT1 & > LeftOperand
Composite type of the left-hand side sparse matrix expression.
Definition: TSMatDMatSchurExpr.h:164
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: TSMatDMatSchurExpr.h:346
static constexpr bool returnExpr
Compilation switch for the selection of the subscript operator return type.
Definition: TSMatDMatSchurExpr.h:121
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: TSMatDMatSchurExpr.h:394
ResultType_t< MT2 > RT2
Result type of the right-hand side dense matrix expression.
Definition: TSMatDMatSchurExpr.h:107
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: TSMatDMatSchurExpr.h:331
ConstIterator upperBound(size_t i, size_t j) const
Returns an iterator to the first index greater then the given index.
Definition: TSMatDMatSchurExpr.h:453
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: TSMatDMatSchurExpr.h:404
RightOperand rhs_
Right-hand side dense matrix of the Schur product expression.
Definition: TSMatDMatSchurExpr.h:506
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) column(Matrix< MT, SO > &matrix, RCAs... args)
Creating a view on a specific column of the given matrix.
Definition: Column.h:137
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_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_COLUMN_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.
Definition: ColumnMajorMatrix.h:61
#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
#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.