22 #ifndef _BLAZE_MATH_EXPRESSIONS_TSMATSMATSUBEXPR_H_
23 #define _BLAZE_MATH_EXPRESSIONS_TSMATSMATSUBEXPR_H_
31 #include <boost/type_traits/remove_reference.hpp>
69 template<
typename MT1
71 class TSMatSMatSubExpr :
public SparseMatrix< TSMatSMatSubExpr<MT1,MT2>, false >
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
260 typedef typename boost::remove_reference<CT2>::type::ConstIterator RightIterator;
276 for(
size_t i=0UL; i<(~lhs).
rows(); ++i ) {
277 const RightIterator end( B.end(i) );
278 for( RightIterator element=B.begin(i); element!=end; ++element ) {
279 if(
isDefault( (~lhs)(i,element->index()) ) )
280 (~lhs)(i,element->index()) = -element->value();
282 (~lhs)(i,element->index()) -= element->value();
303 template<
typename MT >
311 typedef typename RT1::OppositeType::ConstIterator LeftIterator;
312 typedef typename boost::remove_reference<CT2>::type::ConstIterator RightIterator;
315 const typename RT1::OppositeType A( rhs.lhs_ );
327 for(
size_t i=0UL; i<(~lhs).
rows(); ++i )
329 const LeftIterator lend( A.end(i) );
330 const RightIterator rend( B.end(i) );
332 LeftIterator l( A.begin(i) );
333 RightIterator r( B.begin(i) );
334 size_t nonzeros( A.nonZeros(i) + B.nonZeros(i) );
336 for( ; l!=lend && r!=rend; ++l ) {
337 while( r->index() < l->index() && ++r != rend ) {}
338 if( r!=rend && l->index() == r->index() ) {
346 (~lhs).reserve( i, nonzeros );
351 while( l != lend && r != rend )
353 if( l->index() < r->index() ) {
354 (~lhs).append( i, l->index(), l->value() );
357 else if( l->index() > r->index() ) {
358 (~lhs).append( i, r->index(), -r->value() );
362 (~lhs).append( i, l->index(), l->value()-r->value() );
369 (~lhs).append( i, l->index(), l->value() );
374 (~lhs).append( i, r->index(), -r->value() );
395 template<
typename MT >
403 typedef typename boost::remove_reference<CT1>::type::ConstIterator LeftIterator;
404 typedef typename RT2::OppositeType::ConstIterator RightIterator;
410 const typename RT2::OppositeType B( rhs.rhs_ );
419 for(
size_t j=0UL; j<(~lhs).
columns(); ++j )
421 const LeftIterator lend( A.end(j) );
422 const RightIterator rend( B.end(j) );
424 LeftIterator l( A.begin(j) );
425 RightIterator r( B.begin(j) );
426 size_t nonzeros( A.nonZeros(j) + B.nonZeros(j) );
428 for( ; l!=lend && r!=rend; ++l ) {
429 while( r->index() < l->index() && ++r != rend ) {}
430 if( r!=rend && l->index() == r->index() ) {
438 (~lhs).reserve( j, nonzeros );
443 while( l != lend && r != rend )
445 if( l->index() < r->index() ) {
446 (~lhs).append( l->index(), j, l->value() );
449 else if( l->index() > r->index() ) {
450 (~lhs).append( r->index(), j, -r->value() );
454 (~lhs).append( l->index(), j, l->value()-r->value() );
461 (~lhs).append( l->index(), j, l->value() );
466 (~lhs).append( r->index(), j, -r->value() );
487 template<
typename MT
519 template<
typename MT
595 template<
typename T1
597 inline const TSMatSMatSubExpr<T1,T2>
603 throw std::invalid_argument(
"Matrix sizes do not match" );
631 template<
typename T1
633 inline typename RowExprTrait< TSMatSMatSubExpr<T1,T2> >::Type
634 row(
const TSMatSMatSubExpr<T1,T2>& sm,
size_t index )
638 return row( sm.leftOperand(), index ) -
row( sm.rightOperand(), index );
657 template<
typename T1
659 inline typename ColumnExprTrait< TSMatSMatSubExpr<T1,T2> >::Type
660 column(
const TSMatSMatSubExpr<T1,T2>& sm,
size_t index )
664 return column( sm.leftOperand(), index ) -
column( sm.rightOperand(), index );
680 template<
typename MT1,
typename MT2 >
681 struct RowExprTrait< TSMatSMatSubExpr<MT1,MT2> >
685 typedef typename SubExprTrait< typename RowExprTrait<const MT1>::Type
686 ,
typename RowExprTrait<const MT2>::Type >::Type Type;
695 template<
typename MT1,
typename MT2 >
696 struct ColumnExprTrait< TSMatSMatSubExpr<MT1,MT2> >
700 typedef typename SubExprTrait< typename ColumnExprTrait<const MT1>::Type
701 ,
typename ColumnExprTrait<const MT2>::Type >::Type Type;