35 #ifndef _BLAZE_MATH_EXPRESSIONS_SVECSVECOUTEREXPR_H_ 36 #define _BLAZE_MATH_EXPRESSIONS_SVECSVECOUTEREXPR_H_ 85 template<
typename VT1
87 class SVecSVecOuterExpr
88 :
public VecTVecMultExpr< SparseMatrix< SVecSVecOuterExpr<VT1,VT2>, false > >
108 static constexpr
bool returnExpr = ( !IsTemporary_v<RN1> && !IsTemporary_v<RN2> );
183 if( i >=
lhs_.size() ) {
186 if( j >=
rhs_.size() ) {
198 inline size_t rows() const noexcept {
219 return lhs_.nonZeros() *
rhs_.nonZeros();
260 template<
typename T >
261 inline bool canAlias(
const T* alias )
const noexcept {
262 return (
lhs_.canAlias( alias ) ||
rhs_.canAlias( alias ) );
272 template<
typename T >
273 inline bool isAliased(
const T* alias )
const noexcept {
274 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
296 template<
typename MT >
312 const auto lend( x.end() );
313 const auto rend( y.end() );
315 for(
auto lelem=x.begin(); lelem!=lend; ++lelem ) {
317 for(
auto relem=y.begin(); relem!=rend; ++relem ) {
318 (~lhs)(lelem->index(),relem->index()) = lelem->value() * relem->value();
339 template<
typename MT >
357 const auto lend( x.end() );
358 const auto rend( y.end() );
360 for(
auto relem=y.begin(); relem!=rend; ++relem ) {
362 for(
auto lelem=x.begin(); lelem!=lend; ++lelem ) {
363 (~lhs)(lelem->index(),relem->index()) = lelem->value() * relem->value();
383 template<
typename MT >
384 friend inline void assign( SparseMatrix<MT,false>& lhs,
const SVecSVecOuterExpr& rhs )
401 (~lhs).reserve( x.nonZeros() * y.nonZeros() );
404 const auto lend( x.end() );
405 const auto rend( y.end() );
408 for(
auto lelem=x.begin(); lelem!=lend; ++lelem ) {
410 for( ; index < lelem->index(); ++index ) {
411 (~lhs).finalize( index );
413 for(
auto relem=y.begin(); relem!=rend; ++relem ) {
414 (~lhs).append( lelem->index(), relem->index(), lelem->value() * relem->value() );
416 (~lhs).finalize( index++ );
420 for( ; index < x.size(); ++index ) {
421 (~lhs).finalize( index );
440 template<
typename MT >
441 friend inline void assign( SparseMatrix<MT,true>& lhs,
const SVecSVecOuterExpr& rhs )
459 const auto lend( x.end() );
460 const auto rend( y.end() );
463 for(
auto relem=y.begin(); relem!=rend; ++relem ) {
465 for( ; index < relem->index(); ++index ) {
466 (~lhs).finalize( index );
468 for(
auto lelem=x.begin(); lelem!=lend; ++lelem ) {
469 (~lhs).append( lelem->index(), relem->index(), lelem->value() * relem->value() );
471 (~lhs).finalize( index++ );
475 for( ; index < y.size(); ++index ) {
476 (~lhs).finalize( index );
495 template<
typename MT >
496 friend inline void addAssign( DenseMatrix<MT,false>& lhs,
const SVecSVecOuterExpr& rhs )
511 const auto lend( x.end() );
512 const auto rend( y.end() );
514 for(
auto lelem=x.begin(); lelem!=lend; ++lelem ) {
516 for(
auto relem=y.begin(); relem!=rend; ++relem ) {
517 (~lhs)(lelem->index(),relem->index()) += lelem->value() * relem->value();
538 template<
typename MT >
539 friend inline void addAssign( DenseMatrix<MT,true>& lhs,
const SVecSVecOuterExpr& rhs )
556 const auto lend( x.end() );
557 const auto rend( y.end() );
559 for(
auto relem=y.begin(); relem!=rend; ++relem ) {
561 for(
auto lelem=x.begin(); lelem!=lend; ++lelem ) {
562 (~lhs)(lelem->index(),relem->index()) += lelem->value() * relem->value();
587 template<
typename MT >
588 friend inline void subAssign( DenseMatrix<MT,false>& lhs,
const SVecSVecOuterExpr& rhs )
603 const auto lend( x.end() );
604 const auto rend( y.end() );
606 for(
auto lelem=x.begin(); lelem!=lend; ++lelem ) {
608 for(
auto relem=y.begin(); relem!=rend; ++relem ) {
609 (~lhs)(lelem->index(),relem->index()) -= lelem->value() * relem->value();
630 template<
typename MT >
631 friend inline void subAssign( DenseMatrix<MT,true>& lhs,
const SVecSVecOuterExpr& rhs )
648 const auto lend( x.end() );
649 const auto rend( y.end() );
651 for(
auto relem=y.begin(); relem!=rend; ++relem ) {
653 for(
auto lelem=x.begin(); lelem!=lend; ++lelem ) {
654 (~lhs)(lelem->index(),relem->index()) -= lelem->value() * relem->value();
679 template<
typename MT >
680 friend inline void schurAssign( DenseMatrix<MT,false>& lhs,
const SVecSVecOuterExpr& rhs )
695 const auto lend( x.end() );
696 const auto rend( y.end() );
700 for(
auto lelem=x.begin(); lelem!=lend; ++lelem )
702 if(
isDefault( lelem->value() ) )
continue;
704 for( ; i<lelem->index(); ++i ) {
705 for(
size_t j=0UL; j<y.size(); ++j )
706 reset( (~lhs)(i,j) );
711 for(
auto relem=y.begin(); relem!=rend; ++relem, ++j ) {
712 for( ; j<relem->index(); ++j )
713 reset( (~lhs)(i,j) );
714 (~lhs)(lelem->index(),relem->index()) *= lelem->value() * relem->value();
717 for( ; j<y.size(); ++j ) {
718 reset( (~lhs)(i,j) );
724 for( ; i<x.size(); ++i ) {
725 for(
size_t j=0UL; j<y.size(); ++j )
726 reset( (~lhs)(i,j) );
745 template<
typename MT >
746 friend inline void schurAssign( DenseMatrix<MT,true>& lhs,
const SVecSVecOuterExpr& rhs )
763 const auto lend( x.end() );
764 const auto rend( y.end() );
768 for(
auto relem=y.begin(); relem!=rend; ++relem )
770 if(
isDefault( relem->value() ) )
continue;
772 for( ; j<relem->index(); ++j ) {
773 for(
size_t i=0UL; i<x.size(); ++i )
774 reset( (~lhs)(i,j) );
779 for(
auto lelem=x.begin(); lelem!=lend; ++lelem, ++i ) {
780 for( ; i<lelem->index(); ++i )
781 reset( (~lhs)(i,j) );
782 (~lhs)(lelem->index(),relem->index()) *= lelem->value() * relem->value();
785 for( ; i<x.size(); ++i ) {
786 reset( (~lhs)(i,j) );
792 for( ; j<y.size(); ++j ) {
793 for(
size_t i=0UL; i<x.size(); ++i )
794 reset( (~lhs)(i,j) );
848 template<
typename VT1
850 , DisableIf_t< IsZero_v<VT1> || IsZero_v<VT2> >* =
nullptr >
851 inline const SVecSVecOuterExpr<VT1,VT2>
852 svecsvecouter(
const SparseVector<VT1,false>& lhs,
const SparseVector<VT2,true>& rhs )
856 return SVecSVecOuterExpr<VT1,VT2>( ~lhs, ~rhs );
875 template<
typename VT1
877 , EnableIf_t< IsZero_v<VT1> || IsZero_v<VT2> >* =
nullptr >
878 inline decltype(
auto)
879 svecsvecouter( const SparseVector<VT1,false>& lhs, const SparseVector<VT2,true>& rhs )
883 using ReturnType =
const MultTrait_t< ResultType_t<VT1>, ResultType_t<VT2> >;
888 return ReturnType( (~lhs).
size(), (~rhs).
size() );
921 template<
typename VT1
923 inline decltype(
auto)
928 return svecsvecouter( ~lhs, ~rhs );
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse vector operand.
Definition: SVecSVecOuterExpr.h:239
Header file for auxiliary alias declarations.
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: SVecSVecOuterExpr.h:166
size_t capacity(const Matrix< MT, SO > &matrix) noexcept
Returns the maximum capacity of the matrix.
Definition: Matrix.h:546
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: SVecSVecOuterExpr.h:144
Header file for basic type definitions.
Expression object for sparse vector-sparse vector outer products.The SVecSVecOuterExpr class represen...
Definition: Forward.h:163
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
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.The ResultType_t alias declaration provides ...
Definition: Aliases.h:390
#define BLAZE_CONSTRAINT_MUST_BE_COLUMN_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a column dense or sparse vector type...
Definition: ColumnVector.h:61
Header file for the serial shim.
static constexpr bool returnExpr
Compilation switch for the selection of the subscript operator return type.
Definition: SVecSVecOuterExpr.h:108
If_t< IsComputation_v< VT2 >, const RT2, CT2 > RT
Type for the assignment of the right-hand side sparse vector operand.
Definition: SVecSVecOuterExpr.h:139
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:595
CompositeType_t< VT2 > CT2
Composite type of the right-hand side sparse vector expression.
Definition: SVecSVecOuterExpr.h:98
Constraint on the data type.
If_t< IsExpression_v< VT2 >, const VT2, const VT2 & > RightOperand
Composite type of the right-hand side sparse vector expression.
Definition: SVecSVecOuterExpr.h:133
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: SVecSVecOuterExpr.h:198
Header file for the Computation base class.
ResultType_t< VT2 > RT2
Result type of the right-hand side sparse vector expression.
Definition: SVecSVecOuterExpr.h:94
RightOperand rightOperand() const noexcept
Returns the right-hand side sparse vector operand.
Definition: SVecSVecOuterExpr.h:249
typename T::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.The ReturnType_t alias declaration provides ...
Definition: Aliases.h:410
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes....
Definition: DenseMatrix.h:81
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
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row.
Definition: SVecSVecOuterExpr.h:229
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: SVecSVecOuterExpr.h:218
Header file for the SparseMatrix base class.
Constraint on the transpose flag of vector types.
RightOperand rhs_
Right-hand side sparse vector of the multiplication expression.
Definition: SVecSVecOuterExpr.h:281
Constraint on the data type.
Header file for the IsTemporary type trait class.
Header file for the multiplication trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the If class template.
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: SVecSVecOuterExpr.h:121
#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
CompositeType_t< VT1 > CT1
Composite type of the left-hand side sparse vector expression.
Definition: SVecSVecOuterExpr.h:97
#define BLAZE_CONSTRAINT_MUST_FORM_VALID_VECTVECMULTEXPR(T1, T2)
Constraint on the data type.In case the given data types T1 and T2 do not form a valid vector/vector ...
Definition: VecTVecMultExpr.h:103
#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
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a sparse, N-dimensional vector type,...
Definition: SparseVector.h:61
SVecSVecOuterExpr(const VT1 &lhs, const VT2 &rhs) noexcept
Constructor for the SVecSVecOuterExpr class.
Definition: SVecSVecOuterExpr.h:153
Header file for the exception macros of the math module.
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: SVecSVecOuterExpr.h:120
Constraint on the data type.
Header file for the VecTVecMultExpr base class.
typename MultTrait< T1, T2 >::Type MultTrait_t
Auxiliary alias declaration for the MultTrait class template.The MultTrait_t alias declaration provid...
Definition: MultTrait.h:240
typename T::OppositeType OppositeType_t
Alias declaration for nested OppositeType type definitions.The OppositeType_t alias declaration provi...
Definition: Aliases.h:270
ReturnType_t< VT1 > RN1
Return type of the left-hand side sparse vector expression.
Definition: SVecSVecOuterExpr.h:95
#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,...
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
typename T::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.The TransposeType_t alias declaration pro...
Definition: Aliases.h:470
OppositeType_t< ResultType > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: SVecSVecOuterExpr.h:119
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
ResultType_t< VT1 > RT1
Result type of the left-hand side sparse vector expression.
Definition: SVecSVecOuterExpr.h:93
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
Header file for all forward declarations for expression class templates.
Header file for the isDefault shim.
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:530
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
Constraint on the data type.
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: SVecSVecOuterExpr.h:208
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: SVecSVecOuterExpr.h:182
ReturnType_t< VT2 > RN2
Return type of the right-hand side sparse vector expression.
Definition: SVecSVecOuterExpr.h:96
const ResultType CompositeType
Data type for composite expression templates.
Definition: SVecSVecOuterExpr.h:127
If_t< IsComputation_v< VT1 >, const RT1, CT1 > LT
Type for the assignment of the left-hand side sparse vector operand.
Definition: SVecSVecOuterExpr.h:136
Header file for the IsComputation type trait class.
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SVecSVecOuterExpr.h:261
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:146
const If_t< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: SVecSVecOuterExpr.h:124
#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
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:635
MultTrait_t< RT1, RT2 > ResultType
Result type for expression template evaluations.
Definition: SVecSVecOuterExpr.h:118
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SVecSVecOuterExpr.h:273
If_t< IsExpression_v< VT1 >, const VT1, const VT1 & > LeftOperand
Composite type of the left-hand side sparse vector expression.
Definition: SVecSVecOuterExpr.h:130
#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
Size type of the Blaze library.
#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
Constraint on the transpose flag of vector types.
Header file for the IsExpression type trait class.
Header file for the function trace functionality.
decltype(std::declval< RN1 >() *std::declval< RN2 >()) ExprReturnType
Expression return type for the subscript operator.
Definition: SVecSVecOuterExpr.h:111
LeftOperand lhs_
Left-hand side sparse vector of the multiplication expression.
Definition: SVecSVecOuterExpr.h:280