22 #ifndef _BLAZE_MATH_EXPRESSIONS_SMATTSMATADDEXPR_H_
23 #define _BLAZE_MATH_EXPRESSIONS_SMATTSMATADDEXPR_H_
69 template<
typename MT1
71 class SMatTSMatAddExpr :
public SparseMatrix< SMatTSMatAddExpr<MT1,MT2>, false >
72 ,
private MatMatAddExpr
77 typedef typename MT1::ResultType
RT1;
78 typedef typename MT2::ResultType
RT2;
79 typedef typename MT1::ReturnType
RN1;
80 typedef typename MT2::ReturnType
RN2;
81 typedef typename MT1::CompositeType
CT1;
82 typedef typename MT2::CompositeType
CT2;
164 return lhs_.columns();
174 return lhs_.nonZeros() +
rhs_.nonZeros();
185 return lhs_.nonZeros(i) +
rhs_.nonZeros(i);
215 template<
typename T >
217 return (
lhs_.canAlias( alias ) ||
rhs_.canAlias( alias ) );
227 template<
typename T >
229 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
251 template<
typename MT
276 for(
size_t j=0UL; j<(~lhs).
columns(); ++j ) {
277 const RightIterator end( B.end(j) );
278 for( RightIterator element=B.begin(j); element!=end; ++element ) {
279 if(
isDefault( (~lhs)(element->index(),j) ) )
280 (~lhs)(element->index(),j) = element->value();
282 (~lhs)(element->index(),j) += element->value();
302 template<
typename MT >
311 typedef typename RT2::OppositeType::ConstIterator RightIterator;
317 const typename RT2::OppositeType B( rhs.rhs_ );
326 for(
size_t i=0UL; i<(~lhs).
rows(); ++i )
328 const LeftIterator lend( A.end(i) );
329 const RightIterator rend( B.end(i) );
331 LeftIterator l( A.begin(i) );
332 RightIterator r( B.begin(i) );
333 size_t nonzeros( A.nonZeros(i) + B.nonZeros(i) );
335 for( ; l!=lend && r!=rend; ++l ) {
336 while( r->index() < l->index() && ++r != rend ) {}
337 if( r!=rend && l->index() == r->index() ) {
345 (~lhs).reserve( i, nonzeros );
350 while( l != lend && r != rend )
352 if( l->index() < r->index() ) {
353 (~lhs).append( i, l->index(), l->value() );
356 else if( l->index() > r->index() ) {
357 (~lhs).append( i, r->index(), r->value() );
361 (~lhs).append( i, l->index(), l->value()+r->value() );
368 (~lhs).append( i, l->index(), l->value() );
373 (~lhs).append( i, r->index(), r->value() );
393 template<
typename MT >
401 typedef typename RT1::OppositeType::ConstIterator LeftIterator;
402 typedef typename RemoveReference<CT2>::Type::ConstIterator RightIterator;
405 const typename RT1::OppositeType A( rhs.lhs_ );
417 for(
size_t j=0UL; j<(~lhs).
columns(); ++j )
419 const LeftIterator lend( A.end(j) );
420 const RightIterator rend( B.end(j) );
422 LeftIterator l( A.begin(j) );
423 RightIterator r( B.begin(j) );
424 size_t nonzeros( A.nonZeros(j) + B.nonZeros(j) );
426 for( ; l!=lend && r!=rend; ++l ) {
427 while( r->index() < l->index() && ++r != rend ) {}
428 if( r!=rend && l->index() == r->index() ) {
436 (~lhs).reserve( j, nonzeros );
441 while( l != lend && r != rend )
443 if( l->index() < r->index() ) {
444 (~lhs).append( l->index(), j, l->value() );
447 else if( l->index() > r->index() ) {
448 (~lhs).append( r->index(), j, r->value() );
452 (~lhs).append( l->index(), j, l->value()+r->value() );
459 (~lhs).append( l->index(), j, l->value() );
464 (~lhs).append( r->index(), j, r->value() );
485 template<
typename MT
517 template<
typename MT
593 template<
typename T1
595 inline const SMatTSMatAddExpr<T1,T2>
601 throw std::invalid_argument(
"Matrix sizes do not match" );
637 template<
typename T1
639 inline const SMatTSMatAddExpr<T2,T1>
645 throw std::invalid_argument(
"Matrix sizes do not match" );
662 template<
typename MT1,
typename MT2 >
663 struct RowExprTrait< SMatTSMatAddExpr<MT1,MT2> >
667 typedef typename AddExprTrait< typename RowExprTrait<const MT1>::Type
668 ,
typename RowExprTrait<const MT2>::Type >::Type Type;
677 template<
typename MT1,
typename MT2 >
678 struct ColumnExprTrait< SMatTSMatAddExpr<MT1,MT2> >
682 typedef typename AddExprTrait< typename ColumnExprTrait<const MT1>::Type
683 ,
typename ColumnExprTrait<const MT2>::Type >::Type Type;