35 #ifndef _BLAZE_MATH_EXPRESSIONS_SMATSMATSCHUREXPR_H_ 36 #define _BLAZE_MATH_EXPRESSIONS_SMATSMATSCHUREXPR_H_ 98 template<
typename MT1
100 class SMatSMatSchurExpr
101 :
public SchurExpr< SparseMatrix< SMatSMatSchurExpr<MT1,MT2>, false > >
102 ,
private Computation
121 static constexpr
bool returnExpr = ( !IsTemporary_v<RN1> && !IsTemporary_v<RN2> );
134 template<
typename T1,
typename T2,
typename T3 >
135 static constexpr
bool UseSymmetricKernel_v =
136 ( IsColumnMajorMatrix_v<T1> && IsSymmetric_v<T2> && IsSymmetric_v<T3> );
205 if( i >=
lhs_.rows() ) {
208 if( j >=
lhs_.columns() ) {
220 inline size_t rows() const noexcept {
231 return lhs_.columns();
282 template<
typename T >
283 inline bool canAlias(
const T* alias )
const noexcept {
284 return (
lhs_.canAlias( alias ) ||
rhs_.canAlias( alias ) );
294 template<
typename T >
295 inline bool isAliased(
const T* alias )
const noexcept {
296 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
318 template<
typename MT
338 for(
size_t i=0UL; i<(~lhs).
rows(); ++i )
340 const auto lend( A.end(i) );
341 const auto rend( B.end(i) );
343 auto l( A.begin(i) );
344 auto r( B.begin(i) );
346 for( ; l!=lend; ++l ) {
347 while( r!=rend && r->index() < l->index() ) ++r;
349 if( l->index() == r->index() ) {
350 (~lhs)(i,l->index()) = l->value() * r->value();
371 template<
typename MT >
390 (~lhs).reserve(
min( A.nonZeros(), B.nonZeros() ) );
393 for(
size_t i=0UL; i<(~lhs).
rows(); ++i )
395 const auto lend( A.end(i) );
396 const auto rend( B.end(i) );
398 auto l( A.begin(i) );
399 auto r( B.begin(i) );
401 for( ; l!=lend; ++l ) {
402 while( r!=rend && r->index() < l->index() ) ++r;
404 if( l->index() == r->index() ) {
405 (~lhs).append( i, l->index(), l->value() * r->value() );
410 (~lhs).finalize( i );
429 template<
typename MT >
430 friend inline auto assign( SparseMatrix<MT,true>& lhs,
const SMatSMatSchurExpr& rhs )
431 -> DisableIf_t< UseSymmetricKernel_v<MT,MT1,MT2> >
450 const size_t m( rhs.rows() );
451 const size_t n( rhs.columns() );
454 std::vector<size_t> nonzeros( n, 0UL );
455 for(
size_t i=0UL; i<m; ++i )
457 const auto lend( A.end(i) );
458 const auto rend( B.end(i) );
460 auto l( A.begin(i) );
461 auto r( B.begin(i) );
463 for( ; l!=lend; ++l ) {
464 while( r!=rend && r->index() < l->index() ) ++r;
466 if( l->index() == r->index() ) {
467 ++nonzeros[l->index()];
474 for(
size_t j=0UL; j<n; ++j ) {
475 (~lhs).reserve( j, nonzeros[j] );
479 for(
size_t i=0UL; i<m; ++i )
481 const auto lend( A.end(i) );
482 const auto rend( B.end(i) );
484 auto l( A.begin(i) );
485 auto r( B.begin(i) );
487 for( ; l!=lend; ++l ) {
488 while( r!=rend && r->index() < l->index() ) ++r;
490 if( l->index() == r->index() ) {
491 (~lhs).append( i, l->index(), l->value() * r->value() );
513 template<
typename MT >
515 -> EnableIf_t< UseSymmetricKernel_v<MT,MT1,MT2> >
524 assign( ~lhs,
trans( rhs.lhs_ ) %
trans( rhs.rhs_ ) );
541 template<
typename MT
543 friend inline auto addAssign( DenseMatrix<MT,SO>& lhs,
const SMatSMatSchurExpr& rhs )
544 -> DisableIf_t< UseSymmetricKernel_v<MT,MT1,MT2> >
561 for(
size_t i=0UL; i<(~lhs).
rows(); ++i )
563 const auto lend( A.end(i) );
564 const auto rend( B.end(i) );
566 auto l( A.begin(i) );
567 auto r( B.begin(i) );
569 for( ; l!=lend; ++l ) {
570 while( r!=rend && r->index() < l->index() ) ++r;
572 if( l->index() == r->index() ) {
573 (~lhs)(i,l->index()) += l->value() * r->value();
595 template<
typename MT >
596 friend inline auto addAssign( Matrix<MT,true>& lhs,
const SMatSMatSchurExpr& rhs )
597 -> EnableIf_t< UseSymmetricKernel_v<MT,MT1,MT2> >
606 addAssign( ~lhs,
trans( rhs.lhs_ ) %
trans( rhs.rhs_ ) );
628 template<
typename MT
630 friend inline auto subAssign( DenseMatrix<MT,SO>& lhs,
const SMatSMatSchurExpr& rhs )
631 -> DisableIf_t< UseSymmetricKernel_v<MT,MT1,MT2> >
648 for(
size_t i=0UL; i<(~lhs).
rows(); ++i )
650 const auto lend( A.end(i) );
651 const auto rend( B.end(i) );
653 auto l( A.begin(i) );
654 auto r( B.begin(i) );
656 for( ; l!=lend; ++l ) {
657 while( r!=rend && r->index() < l->index() ) ++r;
659 if( l->index() == r->index() ) {
660 (~lhs)(i,l->index()) -= l->value() * r->value();
682 template<
typename MT >
683 friend inline auto subAssign( Matrix<MT,true>& lhs,
const SMatSMatSchurExpr& rhs )
684 -> EnableIf_t< UseSymmetricKernel_v<MT,MT1,MT2> >
693 subAssign( ~lhs,
trans( rhs.lhs_ ) %
trans( rhs.rhs_ ) );
715 template<
typename MT
717 friend inline auto schurAssign( DenseMatrix<MT,SO>& lhs,
const SMatSMatSchurExpr& rhs )
718 -> DisableIf_t< UseSymmetricKernel_v<MT,MT1,MT2> >
735 for(
size_t i=0UL; i<(~lhs).
rows(); ++i )
737 const auto lend( A.end(i) );
738 const auto rend( B.end(i) );
740 auto l( A.begin(i) );
741 auto r( B.begin(i) );
745 for( ; l!=lend; ++l ) {
746 while( r!=rend && r->index() < l->index() ) ++r;
748 if( l->index() == r->index() ) {
749 for( ; j<l->index(); ++j )
750 reset( (~lhs)(i,j) );
751 (~lhs)(i,l->index()) *= l->value() * r->value();
757 for( ; j<(~lhs).
columns(); ++j )
758 reset( (~lhs)(i,j) );
777 template<
typename MT >
778 friend inline auto schurAssign( Matrix<MT,true>& lhs,
const SMatSMatSchurExpr& rhs )
779 -> EnableIf_t< UseSymmetricKernel_v<MT,MT1,MT2> >
788 schurAssign( ~lhs,
trans( rhs.lhs_ ) %
trans( rhs.rhs_ ) );
842 template<
typename MT
905 template<
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> || IsZero_v<MT2> ) >* =
nullptr >
914 inline const SMatSMatSchurExpr<MT1,MT2>
915 smatsmatschur(
const SparseMatrix<MT1,false>& lhs,
const SparseMatrix<MT2,false>& rhs )
922 return SMatSMatSchurExpr<MT1,MT2>( ~lhs, ~rhs );
941 template<
typename MT1
943 , EnableIf_t< ( IsUniLower_v<MT1> && IsUniUpper_v<MT2> ) ||
944 ( IsUniUpper_v<MT1> && IsUniLower_v<MT2> ) >* =
nullptr >
945 inline decltype(
auto)
946 smatsmatschur( const SparseMatrix<MT1,false>& lhs, const SparseMatrix<MT2,false>& rhs )
955 using ReturnType =
const SchurTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
979 template<
typename MT1
981 , EnableIf_t< ( IsStrictlyLower_v<MT1> && IsUpper_v<MT2> ) ||
982 ( IsStrictlyUpper_v<MT1> && IsLower_v<MT2> ) ||
983 ( IsLower_v<MT1> && IsStrictlyUpper_v<MT2> ) ||
984 ( IsUpper_v<MT1> && IsStrictlyLower_v<MT2> ) ||
985 ( IsZero_v<MT1> || IsZero_v<MT2> ) >* =
nullptr >
986 inline decltype(
auto)
987 smatsmatschur(
const SparseMatrix<MT1,false>& lhs,
const SparseMatrix<MT2,false>& rhs )
996 using ReturnType =
const SchurTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
1033 template<
typename MT1
1035 inline decltype(
auto)
1044 return smatsmatschur( ~lhs, ~rhs );
Constraint on the data type.
#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
Header file for auxiliary alias declarations.
Headerfile for the generic min algorithm.
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SMatSMatSchurExpr.h:295
#define BLAZE_CONSTRAINT_MUST_BE_IDENTITY_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not an identity matrix type...
Definition: Identity.h:60
Header file for the Schur product trait.
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row.
Definition: SMatSMatSchurExpr.h:251
Header file for the UNUSED_PARAMETER function template.
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: SMatSMatSchurExpr.h:189
Header file for the IsUniUpper type trait.
Header file for basic type definitions.
SchurTrait_t< RT1, RT2 > ResultType
Result type for expression template evaluations.
Definition: SMatSMatSchurExpr.h:144
typename If< Condition, T1, T2 >::Type If_t
Auxiliary alias declaration for the If class template.The If_t alias declaration provides a convenien...
Definition: If.h:109
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.
OppositeType_t< ResultType > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: SMatSMatSchurExpr.h:145
ReturnType_t< MT1 > RN1
ReturnType type of the left-hand side sparse matrix expression.
Definition: SMatSMatSchurExpr.h:108
Header file for the IsColumnMajorMatrix type trait.
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:591
CompositeType_t< MT2 > CT2
Composite type of the right-hand side sparse matrix expression.
Definition: SMatSMatSchurExpr.h:111
Constraint on the data type.
Header file for the Computation base class.
Constraints on the storage order of matrix types.
constexpr void UNUSED_PARAMETER(const Args &...)
Suppression of unused parameter warnings.
Definition: Unused.h:81
const ResultType CompositeType
Data type for composite expression templates.
Definition: SMatSMatSchurExpr.h:153
typename T::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.The ReturnType_t alias declaration provides ...
Definition: Aliases.h:410
Header file for the IsUniLower type trait.
RightOperand rhs_
Right-hand side sparse matrix of the Schur product expression.
Definition: SMatSMatSchurExpr.h:303
#define BLAZE_CONSTRAINT_MUST_FORM_VALID_SCHUREXPR(T1, T2)
Constraint on the data type.In case the given data types T1 and T2 do not form a valid matrix/matrix ...
Definition: SchurExpr.h:103
constexpr size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:514
ReturnType_t< MT2 > RN2
ReturnType type of the right-hand side sparse matrix expression.
Definition: SMatSMatSchurExpr.h:109
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes...
Definition: DenseMatrix.h:80
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:137
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.The ElementType_t alias declaration provide...
Definition: Aliases.h:170
Header file for all forward declarations for sparse vectors and matrices.
ResultType_t< MT2 > RT2
Result type of the right-hand side sparse matrix expression.
Definition: SMatSMatSchurExpr.h:107
Header file for the SparseMatrix base class.
Constraint on the data type.
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: SMatSMatSchurExpr.h:164
Headerfile for the generic max algorithm.
Header file for the DisableIf class template.
Header file for the IsTemporary type trait class.
Header file for the IsStrictlyUpper type trait.
Header file for the IsSymmetric type trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the If class template.
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse matrix operand.
Definition: SMatSMatSchurExpr.h:261
If_t< IsExpression_v< MT2 >, const MT2, const MT2 &> RightOperand
Composite type of the right-hand side sparse matrix expression.
Definition: SMatSMatSchurExpr.h:159
#define BLAZE_CONSTRAINT_MUST_BE_ZERO_TYPE(T)
Constraint on the data type.In case the given data type T is not a zero vector or matrix type...
Definition: Zero.h:61
decltype(auto) min(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise minimum of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1147
#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: SMatSMatSchurExpr.h:146
Header file for the IsLower type trait.
ResultType_t< MT1 > RT1
Result type of the left-hand side sparse matrix expression.
Definition: SMatSMatSchurExpr.h:106
static constexpr bool returnExpr
Compilation switch for the selection of the subscript operator return type.
Definition: SMatSMatSchurExpr.h:121
Header file for the exception macros of the math module.
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: SMatSMatSchurExpr.h:230
Header file for all forward declarations for expression class templates.
SMatSMatSchurExpr(const MT1 &lhs, const MT2 &rhs) noexcept
Constructor for the SMatSMatSchurExpr class.
Definition: SMatSMatSchurExpr.h:173
Header file for the EnableIf class template.
Header file for the IsStrictlyLower type trait.
Expression object for sparse matrix-sparse matrix Schur product.The SMatSMatSchurExpr class represent...
Definition: Forward.h:126
typename T::OppositeType OppositeType_t
Alias declaration for nested OppositeType type definitions.The OppositeType_t alias declaration provi...
Definition: Aliases.h:270
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a symmetric matrix type, a compilation error is created.
Definition: Symmetric.h:79
#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
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: SMatSMatSchurExpr.h:240
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.
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.The CompositeType_t alias declaration pro...
Definition: Aliases.h:90
LeftOperand lhs_
Left-hand side sparse matrix of the Schur product expression.
Definition: SMatSMatSchurExpr.h:302
Header file for the SchurExpr base class.
typename SchurTrait< T1, T2 >::Type SchurTrait_t
Auxiliary alias declaration for the SchurTrait class template.The SchurTrait_t alias declaration prov...
Definition: SchurTrait.h:164
CompositeType_t< MT1 > CT1
Composite type of the left-hand side sparse matrix expression.
Definition: SMatSMatSchurExpr.h:110
Header file for the IsZero type trait.
#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
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: SMatSMatSchurExpr.h:204
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SMatSMatSchurExpr.h:283
const If_t< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: SMatSMatSchurExpr.h:150
Constraint on the data type.
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:808
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
constexpr size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:498
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: SMatSMatSchurExpr.h:147
If_t< IsExpression_v< MT1 >, const MT1, const MT1 &> LeftOperand
Composite type of the left-hand side sparse matrix expression.
Definition: SMatSMatSchurExpr.h:156
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:3081
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:765
Header file for the IsComputation type trait class.
Header file for the IntegralConstant class template.
decltype(std::declval< RN1 >() *std::declval< RN2 >()) ExprReturnType
Expression return type for the subscript operator.
Definition: SMatSMatSchurExpr.h:124
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: SMatSMatSchurExpr.h:220
Header file for the IsUpper type trait.
typename DisableIf< Condition, T >::Type DisableIf_t
Auxiliary type for the DisableIf class template.The DisableIf_t alias declaration provides a convenie...
Definition: DisableIf.h:138
RightOperand rightOperand() const noexcept
Returns the right-hand side sparse matrix operand.
Definition: SMatSMatSchurExpr.h:271
#define BLAZE_CONSTRAINT_MUST_NOT_BE_ZERO_TYPE(T)
Constraint on the data type.In case the given data type T is a zero vector or matrix type...
Definition: Zero.h:81
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101
#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 IsExpression type trait class.
Header file for the function trace functionality.
Constraint on the data type.