22 #ifndef _BLAZE_MATH_EXPRESSIONS_TSMATTSMATSUBEXPR_H_
23 #define _BLAZE_MATH_EXPRESSIONS_TSMATTSMATSUBEXPR_H_
69 template<
typename MT1
71 class TSMatTSMatSubExpr :
public SparseMatrix< TSMatTSMatSubExpr<MT1,MT2>, true >
72 ,
private MatMatSubExpr
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 ) );
252 template<
typename MT
277 for(
size_t j=0UL; j<(~lhs).
columns(); ++j ) {
278 const RightIterator end( B.end(j) );
279 for( RightIterator element=B.begin(j); element!=end; ++element ) {
280 if(
isDefault( (~lhs)(element->index(),j) ) )
281 (~lhs)(element->index(),j) = -element->value();
283 (~lhs)(element->index(),j) -= element->value();
304 template<
typename MT >
325 const size_t m( rhs.rows() );
326 const size_t n( rhs.columns() );
329 std::vector<size_t> nonzeros( m, 0UL );
330 for(
size_t j=0UL; j<n; ++j )
332 const LeftIterator lend( A.end(j) );
333 const RightIterator rend( B.end(j) );
335 LeftIterator l( A.begin(j) );
336 RightIterator r( B.begin(j) );
338 while( l != lend && r != rend )
340 if( l->index() < r->index() ) {
341 ++nonzeros[l->index()];
344 else if( l->index() > r->index() ) {
345 ++nonzeros[r->index()];
349 ++nonzeros[l->index()];
356 ++nonzeros[l->index()];
361 ++nonzeros[r->index()];
367 for(
size_t i=0UL; i<m; ++i ) {
368 (~lhs).reserve( i, nonzeros[i] );
372 for(
size_t j=0UL; j<n; ++j )
374 const LeftIterator lend( A.end(j) );
375 const RightIterator rend( B.end(j) );
377 LeftIterator l( A.begin(j) );
378 RightIterator r( B.begin(j) );
380 while( l != lend && r != rend )
382 if( l->index() < r->index() ) {
383 (~lhs).append( l->index(), j, l->value() );
386 else if( l->index() > r->index() ) {
387 (~lhs).append( r->index(), j, -r->value() );
391 (~lhs).append( l->index(), j, l->value()-r->value() );
398 (~lhs).append( l->index(), j, l->value() );
403 (~lhs).append( r->index(), j, -r->value() );
424 template<
typename MT >
432 typedef typename RemoveReference<CT1>::Type::ConstIterator LeftIterator;
433 typedef typename RemoveReference<CT2>::Type::ConstIterator RightIterator;
445 for(
size_t j=0UL; j<(~lhs).
columns(); ++j )
447 const LeftIterator lend( A.end(j) );
448 const RightIterator rend( B.end(j) );
450 LeftIterator l( A.begin(j) );
451 RightIterator r( B.begin(j) );
452 size_t nonzeros( A.nonZeros(j) + B.nonZeros(j) );
454 for( ; l!=lend && r!=rend; ++l ) {
455 while( r->index() < l->index() && ++r != rend ) {}
456 if( r!=rend && l->index() == r->index() ) {
464 (~lhs).reserve( j, nonzeros );
469 while( l != lend && r != rend )
471 if( l->index() < r->index() ) {
472 (~lhs).append( l->index(), j, l->value() );
475 else if( l->index() > r->index() ) {
476 (~lhs).append( r->index(), j, -r->value() );
480 (~lhs).append( l->index(), j, l->value()-r->value() );
487 (~lhs).append( l->index(), j, l->value() );
492 (~lhs).append( r->index(), j, -r->value() );
513 template<
typename MT
545 template<
typename MT
619 template<
typename T1
621 inline const TSMatTSMatSubExpr<T1,T2>
627 throw std::invalid_argument(
"Matrix sizes do not match" );
644 template<
typename MT1,
typename MT2 >
645 struct RowExprTrait< TSMatTSMatSubExpr<MT1,MT2> >
649 typedef typename SubExprTrait< typename RowExprTrait<const MT1>::Type
650 ,
typename RowExprTrait<const MT2>::Type >::Type Type;
659 template<
typename MT1,
typename MT2 >
660 struct ColumnExprTrait< TSMatTSMatSubExpr<MT1,MT2> >
664 typedef typename SubExprTrait< typename ColumnExprTrait<const MT1>::Type
665 ,
typename ColumnExprTrait<const MT2>::Type >::Type Type;