35 #ifndef _BLAZE_MATH_EXPRESSIONS_SVECSVECKRONEXPR_H_ 36 #define _BLAZE_MATH_EXPRESSIONS_SVECSVECKRONEXPR_H_ 85 template<
typename VT1
88 class SVecSVecKronExpr
89 :
public VecVecKronExpr< SparseVector< SVecSVecKronExpr<VT1,VT2,TF>, TF > >
109 static constexpr
bool returnExpr = ( !IsTemporary_v<RN1> && !IsTemporary_v<RN2> );
170 if( index >=
lhs_.size() ) {
173 return (*
this)[index];
182 inline size_t size() const noexcept {
193 return lhs_.nonZeros() *
rhs_.nonZeros();
223 template<
typename T >
224 inline bool canAlias(
const T* alias )
const noexcept {
225 return (
lhs_.canAlias( alias ) ||
rhs_.canAlias( alias ) );
235 template<
typename T >
236 inline bool isAliased(
const T* alias )
const noexcept {
237 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
259 template<
typename VT >
266 if( rhs.size() == 0UL ) {
273 const size_t N( y.size() );
274 const auto xend( x.end() );
275 const auto yend( y.end() );
277 for(
auto xelem=x.begin(); xelem!=xend; ++xelem ) {
278 for(
auto yelem=y.begin(); yelem!=yend; ++yelem ) {
279 (~lhs)[xelem->index()*N+yelem->index()] = xelem->value() * yelem->value();
298 template<
typename VT >
305 if( rhs.size() == 0UL ) {
312 const size_t N( y.size() );
313 const auto xend( x.end() );
314 const auto yend( y.end() );
316 for(
auto xelem=x.begin(); xelem!=xend; ++xelem ) {
317 for(
auto yelem=y.begin(); yelem!=yend; ++yelem ) {
318 (~lhs).append( xelem->index()*N+yelem->index(), xelem->value() * yelem->value(), true );
338 template<
typename VT >
339 friend inline void addAssign( DenseVector<VT,TF>& lhs,
const SVecSVecKronExpr& rhs )
345 if( rhs.size() == 0UL ) {
352 const size_t N( y.size() );
353 const auto xend( x.end() );
354 const auto yend( y.end() );
356 for(
auto xelem=x.begin(); xelem!=xend; ++xelem ) {
357 for(
auto yelem=y.begin(); yelem!=yend; ++yelem ) {
358 (~lhs)[xelem->index()*N+yelem->index()] += xelem->value() * yelem->value();
382 template<
typename VT >
383 friend inline void subAssign( DenseVector<VT,TF>& lhs,
const SVecSVecKronExpr& rhs )
389 if( rhs.size() == 0UL ) {
396 const size_t N( y.size() );
397 const auto xend( x.end() );
398 const auto yend( y.end() );
400 for(
auto xelem=x.begin(); xelem!=xend; ++xelem ) {
401 for(
auto yelem=y.begin(); yelem!=yend; ++yelem ) {
402 (~lhs)[xelem->index()*N+yelem->index()] -= xelem->value() * yelem->value();
426 template<
typename VT >
427 friend inline void multAssign( DenseVector<VT,TF>& lhs,
const SVecSVecKronExpr& rhs )
433 if( rhs.size() == 0UL ) {
440 const size_t N( y.size() );
441 const auto xend( x.end() );
442 const auto yend( y.end() );
445 for(
auto xelem=x.begin(); xelem!=xend; ++xelem ) {
446 for(
auto yelem=y.begin(); yelem!=yend; ++yelem, ++i ) {
447 const size_t index( xelem->index()*N+yelem->index() );
448 for( ; i<index; ++i )
450 (~lhs)[index] *= xelem->value() * yelem->value();
454 for( ; i<(~lhs).
size(); ++i ) {
501 template<
typename VT1
504 ,
DisableIf_t< ( IsZero_v<VT1> || IsZero_v<VT2> ) >* =
nullptr >
505 inline const SVecSVecKronExpr<VT1,VT2,TF>
506 svecsveckron(
const SparseVector<VT1,TF>& lhs,
const SparseVector<VT2,TF>& rhs )
510 return SVecSVecKronExpr<VT1,VT2,TF>( ~lhs, ~rhs );
529 template<
typename VT1
532 , EnableIf_t< IsZero_v<VT1> || IsZero_v<VT2> >* =
nullptr >
533 inline decltype(
auto)
534 svecsveckron( const SparseVector<VT1,TF>& lhs, const SparseVector<VT2,TF>& rhs )
538 using ReturnType =
const KronTrait_t< ResultType_t<VT1>, ResultType_t<VT2> >;
543 return ReturnType( (~lhs).
size()*(~rhs).
size() );
570 template<
typename VT1
573 inline decltype(
auto)
578 return svecsveckron( ~lhs, ~rhs );
const If_t< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: SVecSVecKronExpr.h:124
Header file for auxiliary alias declarations.
SVecSVecKronExpr(const VT1 &lhs, const VT2 &rhs) noexcept
Constructor for the SVecSVecKronExpr class.
Definition: SVecSVecKronExpr.h:144
RightOperand rightOperand() const noexcept
Returns the right-hand side sparse vector operand.
Definition: SVecSVecKronExpr.h:212
Header file for basic type definitions.
Header file for the SparseVector base class.
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
If_t< IsExpression_v< VT1 >, const VT1, const VT1 & > LeftOperand
Composite type of the left-hand side sparse vector expression.
Definition: SVecSVecKronExpr.h:130
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.
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SVecSVecKronExpr.h:236
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:595
Constraint on the data type.
Constraint on the data type.
Header file for the Computation base class.
Header file for the reset shim.
ResultType_t< VT2 > RT2
Result type of the right-hand side sparse vector expression.
Definition: SVecSVecKronExpr.h:95
typename T::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.The ReturnType_t alias declaration provides ...
Definition: Aliases.h:410
decltype(auto) kron(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the Kronecker product of two dense matrices ( ).
Definition: DMatDMatKronExpr.h:954
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.The ElementType_t alias declaration provide...
Definition: Aliases.h:170
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: SVecSVecKronExpr.h:138
Expression object for sparse vector-sparse vector Kronecker products.The SVecSVecKronExpr class repre...
Definition: Forward.h:161
Header file for the DisableIf class template.
Header file for the IsTemporary type trait class.
ResultType_t< VT1 > RT1
Result type of the left-hand side sparse vector expression.
Definition: SVecSVecKronExpr.h:94
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the If class template.
ReturnType_t< VT2 > RN2
Return type of the right-hand side sparse vector expression.
Definition: SVecSVecKronExpr.h:97
#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
typename KronTrait< T1, T2 >::Type KronTrait_t
Auxiliary alias declaration for the KronTrait class template.The KronTrait_t alias declaration provid...
Definition: KronTrait.h:163
#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
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:76
Header file for the VecVecKronExpr base class.
#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
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: SVecSVecKronExpr.h:121
Constraint on the data type.
Header file for the Kron product trait.
Constraint on the data type.
RightOperand rhs_
Right-hand side sparse vector of the Kronecker product expression.
Definition: SVecSVecKronExpr.h:244
Header file for the exception macros of the math module.
Header file for the EnableIf class template.
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: SVecSVecKronExpr.h:169
CompositeType_t< VT2 > CT2
Composite type of the right-hand side sparse vector expression.
Definition: SVecSVecKronExpr.h:99
const ResultType CompositeType
Data type for composite expression templates.
Definition: SVecSVecKronExpr.h:127
typename T::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.The TransposeType_t alias declaration pro...
Definition: Aliases.h:470
KronTrait_t< RT1, RT2 > ResultType
Result type for expression template evaluations.
Definition: SVecSVecKronExpr.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
LeftOperand lhs_
Left-hand side sparse vector of the Kronecker product expression.
Definition: SVecSVecKronExpr.h:243
Header file for the Unique class template.
CompositeType_t< VT1 > CT1
Composite type of the left-hand side sparse vector expression.
Definition: SVecSVecKronExpr.h:98
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
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:808
size_t nonZeros() const
Returns the number of non-zero elements in the sparse vector.
Definition: SVecSVecKronExpr.h:192
static constexpr bool returnExpr
Compilation switch for the selection of the subscript operator return type.
Definition: SVecSVecKronExpr.h:109
decltype(std::declval< RN1 >() *std::declval< RN2 >()) ExprReturnType
Expression return type for the subscript operator.
Definition: SVecSVecKronExpr.h:112
#define BLAZE_CONSTRAINT_MUST_FORM_VALID_VECVECKRONEXPR(T1, T2)
Constraint on the data type.In case the given data types T1 and T2 do not form a valid vector/vector ...
Definition: VecVecKronExpr.h:102
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SVecSVecKronExpr.h:224
If_t< IsExpression_v< VT2 >, const VT2, const VT2 & > RightOperand
Composite type of the right-hand side sparse vector expression.
Definition: SVecSVecKronExpr.h:133
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:146
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SVecSVecKronExpr.h:156
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
ReturnType_t< VT1 > RN1
Return type of the left-hand side sparse vector expression.
Definition: SVecSVecKronExpr.h:96
#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_CONSTRAINT_MUST_BE_VECTOR_WITH_TRANSPOSE_FLAG(T, TF)
Constraint on the data type.In case the given data type T is not a dense or sparse vector type and in...
Definition: TransposeFlag.h:63
#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
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse vector operand.
Definition: SVecSVecKronExpr.h:202
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: SVecSVecKronExpr.h:182
Header file for the IsExpression type trait class.
Header file for the function trace functionality.
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: SVecSVecKronExpr.h:120