Blaze 3.9
Sparse.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_VIEWS_SUBMATRIX_SPARSE_H_
36#define _BLAZE_MATH_VIEWS_SUBMATRIX_SPARSE_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <iterator>
44#include <vector>
45#include <blaze/math/Aliases.h>
86#include <blaze/util/Assert.h>
89#include <blaze/util/mpl/If.h>
90#include <blaze/util/Types.h>
93
94
95namespace blaze {
96
97//=================================================================================================
98//
99// CLASS TEMPLATE SPECIALIZATION FOR ROW-MAJOR SPARSE MATRICES
100//
101//=================================================================================================
102
103//*************************************************************************************************
111template< typename MT // Type of the sparse matrix
112 , AlignmentFlag AF // Alignment flag
113 , size_t... CSAs > // Compile time submatrix arguments
114class Submatrix<MT,AF,false,false,CSAs...>
115 : public View< SparseMatrix< Submatrix<MT,AF,false,false,CSAs...>, false > >
116 , private SubmatrixData<CSAs...>
117{
118 private:
119 //**Type definitions****************************************************************************
120 using DataType = SubmatrixData<CSAs...>;
121 using Operand = If_t< IsExpression_v<MT>, MT, MT& >;
122 //**********************************************************************************************
123
124 public:
125 //**Type definitions****************************************************************************
127 using This = Submatrix<MT,AF,false,false,CSAs...>;
128
130 using BaseType = View< SparseMatrix<This,false> >;
131
132 using ViewedType = MT;
133 using ResultType = SubmatrixTrait_t<MT,CSAs...>;
134 using OppositeType = OppositeType_t<ResultType>;
135 using TransposeType = TransposeType_t<ResultType>;
136 using ElementType = ElementType_t<MT>;
137 using ReturnType = ReturnType_t<MT>;
138 using CompositeType = const Submatrix&;
139
141 using ConstReference = ConstReference_t<MT>;
142
144 using Reference = If_t< IsConst_v<MT>, ConstReference, Reference_t<MT> >;
145 //**********************************************************************************************
146
147 //**SubmatrixElement class definition***********************************************************
150 template< typename MatrixType // Type of the sparse matrix
151 , typename IteratorType > // Type of the sparse matrix iterator
152 class SubmatrixElement
153 : private SparseElement
154 {
155 public:
156 //**Constructor******************************************************************************
162 inline SubmatrixElement( IteratorType pos, size_t offset )
163 : pos_ ( pos ) // Iterator to the current position within the sparse submatrix
164 , offset_( offset ) // Row offset within the according sparse matrix
165 {}
166 //*******************************************************************************************
167
168 //**Assignment operator**********************************************************************
174 template< typename T > inline SubmatrixElement& operator=( const T& v ) {
175 *pos_ = v;
176 return *this;
177 }
178 //*******************************************************************************************
179
180 //**Addition assignment operator*************************************************************
186 template< typename T > inline SubmatrixElement& operator+=( const T& v ) {
187 *pos_ += v;
188 return *this;
189 }
190 //*******************************************************************************************
191
192 //**Subtraction assignment operator**********************************************************
198 template< typename T > inline SubmatrixElement& operator-=( const T& v ) {
199 *pos_ -= v;
200 return *this;
201 }
202 //*******************************************************************************************
203
204 //**Multiplication assignment operator*******************************************************
210 template< typename T > inline SubmatrixElement& operator*=( const T& v ) {
211 *pos_ *= v;
212 return *this;
213 }
214 //*******************************************************************************************
215
216 //**Division assignment operator*************************************************************
222 template< typename T > inline SubmatrixElement& operator/=( const T& v ) {
223 *pos_ /= v;
224 return *this;
225 }
226 //*******************************************************************************************
227
228 //**Element access operator******************************************************************
233 inline const SubmatrixElement* operator->() const {
234 return this;
235 }
236 //*******************************************************************************************
237
238 //**Value function***************************************************************************
243 inline decltype(auto) value() const {
244 return pos_->value();
245 }
246 //*******************************************************************************************
247
248 //**Index function***************************************************************************
253 inline size_t index() const {
254 return pos_->index() - offset_;
255 }
256 //*******************************************************************************************
257
258 private:
259 //**Member variables*************************************************************************
260 IteratorType pos_;
261 size_t offset_;
262 //*******************************************************************************************
263 };
264 //**********************************************************************************************
265
266 //**SubmatrixIterator class definition**********************************************************
269 template< typename MatrixType // Type of the sparse matrix
270 , typename IteratorType > // Type of the sparse matrix iterator
271 class SubmatrixIterator
272 {
273 public:
274 //**Type definitions*************************************************************************
275 using IteratorCategory = std::forward_iterator_tag;
276 using ValueType = SubmatrixElement<MatrixType,IteratorType>;
277 using PointerType = ValueType;
278 using ReferenceType = ValueType;
279 using DifferenceType = ptrdiff_t;
280
281 // STL iterator requirements
282 using iterator_category = IteratorCategory;
283 using value_type = ValueType;
284 using pointer = PointerType;
285 using reference = ReferenceType;
286 using difference_type = DifferenceType;
287 //*******************************************************************************************
288
289 //**Default constructor**********************************************************************
292 inline SubmatrixIterator()
293 : pos_ () // Iterator to the current sparse element
294 , offset_() // The offset of the according row/column of the sparse matrix
295 {}
296 //*******************************************************************************************
297
298 //**Constructor******************************************************************************
304 inline SubmatrixIterator( IteratorType iterator, size_t index )
305 : pos_ ( iterator ) // Iterator to the current sparse element
306 , offset_( index ) // The offset of the according row/column of the sparse matrix
307 {}
308 //*******************************************************************************************
309
310 //**Constructor******************************************************************************
315 template< typename MatrixType2, typename IteratorType2 >
316 inline SubmatrixIterator( const SubmatrixIterator<MatrixType2,IteratorType2>& it )
317 : pos_ ( it.base() ) // Iterator to the current sparse element.
318 , offset_( it.offset() ) // The offset of the according row/column of the sparse matrix
319 {}
320 //*******************************************************************************************
321
322 //**Prefix increment operator****************************************************************
327 inline SubmatrixIterator& operator++() {
328 ++pos_;
329 return *this;
330 }
331 //*******************************************************************************************
332
333 //**Postfix increment operator***************************************************************
338 inline const SubmatrixIterator operator++( int ) {
339 const SubmatrixIterator tmp( *this );
340 ++(*this);
341 return tmp;
342 }
343 //*******************************************************************************************
344
345 //**Element access operator******************************************************************
350 inline ReferenceType operator*() const {
351 return ReferenceType( pos_, offset_ );
352 }
353 //*******************************************************************************************
354
355 //**Element access operator******************************************************************
360 inline PointerType operator->() const {
361 return PointerType( pos_, offset_ );
362 }
363 //*******************************************************************************************
364
365 //**Equality operator************************************************************************
371 template< typename MatrixType2, typename IteratorType2 >
372 inline bool operator==( const SubmatrixIterator<MatrixType2,IteratorType2>& rhs ) const {
373 return base() == rhs.base();
374 }
375 //*******************************************************************************************
376
377 //**Inequality operator**********************************************************************
383 template< typename MatrixType2, typename IteratorType2 >
384 inline bool operator!=( const SubmatrixIterator<MatrixType2,IteratorType2>& rhs ) const {
385 return !( *this == rhs );
386 }
387 //*******************************************************************************************
388
389 //**Subtraction operator*********************************************************************
395 inline DifferenceType operator-( const SubmatrixIterator& rhs ) const {
396 return pos_ - rhs.pos_;
397 }
398 //*******************************************************************************************
399
400 //**Base function****************************************************************************
405 inline IteratorType base() const {
406 return pos_;
407 }
408 //*******************************************************************************************
409
410 //**Offset function**************************************************************************
415 inline size_t offset() const noexcept {
416 return offset_;
417 }
418 //*******************************************************************************************
419
420 private:
421 //**Member variables*************************************************************************
422 IteratorType pos_;
423 size_t offset_;
424 //*******************************************************************************************
425 };
426 //**********************************************************************************************
427
428 //**Type definitions****************************************************************************
430 using ConstIterator = SubmatrixIterator< const MT, ConstIterator_t<MT> >;
431
433 using Iterator = If_t< IsConst_v<MT>, ConstIterator, SubmatrixIterator< MT, Iterator_t<MT> > >;
434 //**********************************************************************************************
435
436 //**Compilation flags***************************************************************************
438 static constexpr bool smpAssignable = MT::smpAssignable;
439
441 static constexpr bool compileTimeArgs = DataType::compileTimeArgs;
442 //**********************************************************************************************
443
444 //**Constructors********************************************************************************
447 template< typename... RSAs >
448 explicit inline Submatrix( MT& matrix, RSAs... args );
449
450 Submatrix( const Submatrix& ) = default;
452 //**********************************************************************************************
453
454 //**Destructor**********************************************************************************
457 ~Submatrix() = default;
459 //**********************************************************************************************
460
461 //**Data access functions***********************************************************************
464 inline Reference operator()( size_t i, size_t j );
465 inline ConstReference operator()( size_t i, size_t j ) const;
466 inline Reference at( size_t i, size_t j );
467 inline ConstReference at( size_t i, size_t j ) const;
468 inline Iterator begin ( size_t i );
469 inline ConstIterator begin ( size_t i ) const;
470 inline ConstIterator cbegin( size_t i ) const;
471 inline Iterator end ( size_t i );
472 inline ConstIterator end ( size_t i ) const;
473 inline ConstIterator cend ( size_t i ) const;
475 //**********************************************************************************************
476
477 //**Assignment operators************************************************************************
480 inline Submatrix& operator=( initializer_list< initializer_list<ElementType> > list );
481 inline Submatrix& operator=( const Submatrix& rhs );
482
483 template< typename MT2, bool SO > inline Submatrix& operator= ( const Matrix<MT2,SO>& rhs );
484 template< typename MT2, bool SO > inline Submatrix& operator+=( const Matrix<MT2,SO>& rhs );
485 template< typename MT2, bool SO > inline Submatrix& operator-=( const Matrix<MT2,SO>& rhs );
486 template< typename MT2, bool SO > inline Submatrix& operator%=( const Matrix<MT2,SO>& rhs );
488 //**********************************************************************************************
489
490 //**Utility functions***************************************************************************
493 using DataType::row;
494 using DataType::column;
495 using DataType::rows;
496 using DataType::columns;
497
498 inline MT& operand() noexcept;
499 inline const MT& operand() const noexcept;
500
501 inline size_t capacity() const noexcept;
502 inline size_t capacity( size_t i ) const noexcept;
503 inline size_t nonZeros() const;
504 inline size_t nonZeros( size_t i ) const;
505 inline void reset();
506 inline void reset( size_t i );
507 inline void reserve( size_t nonzeros );
508 void reserve( size_t i, size_t nonzeros );
509 inline void trim();
510 inline void trim( size_t i );
512 //**********************************************************************************************
513
514 //**Insertion functions*************************************************************************
517 inline Iterator set ( size_t i, size_t j, const ElementType& value );
518 inline Iterator insert ( size_t i, size_t j, const ElementType& value );
519 inline void append ( size_t i, size_t j, const ElementType& value, bool check=false );
520 inline void finalize( size_t i );
522 //**********************************************************************************************
523
524 //**Erase functions*****************************************************************************
527 inline void erase( size_t i, size_t j );
528 inline Iterator erase( size_t i, Iterator pos );
529 inline Iterator erase( size_t i, Iterator first, Iterator last );
530
531 template< typename Pred >
532 inline void erase( Pred predicate );
533
534 template< typename Pred >
535 inline void erase( size_t i, Iterator first, Iterator last, Pred predicate );
537 //**********************************************************************************************
538
539 //**Lookup functions****************************************************************************
542 inline Iterator find ( size_t i, size_t j );
543 inline ConstIterator find ( size_t i, size_t j ) const;
544 inline Iterator lowerBound( size_t i, size_t j );
545 inline ConstIterator lowerBound( size_t i, size_t j ) const;
546 inline Iterator upperBound( size_t i, size_t j );
547 inline ConstIterator upperBound( size_t i, size_t j ) const;
549 //**********************************************************************************************
550
551 //**Numeric functions***************************************************************************
554 inline Submatrix& transpose();
555 inline Submatrix& ctranspose();
556
557 template< typename Other > inline Submatrix& scale( const Other& scalar );
559 //**********************************************************************************************
560
561 //**Expression template evaluation functions****************************************************
564 template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
565 template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
566
567 inline bool canSMPAssign() const noexcept;
568
569 template< typename MT2, bool SO > inline void assign ( const DenseMatrix<MT2,SO>& rhs );
570 template< typename MT2 > inline void assign ( const SparseMatrix<MT2,false>& rhs );
571 template< typename MT2 > inline void assign ( const SparseMatrix<MT2,true>& rhs );
572 template< typename MT2, bool SO > inline void addAssign ( const Matrix<MT2,SO>& rhs );
573 template< typename MT2, bool SO > inline void subAssign ( const Matrix<MT2,SO>& rhs );
574 template< typename MT2, bool SO > inline void schurAssign( const Matrix<MT2,SO>& rhs );
576 //**********************************************************************************************
577
578 private:
579 //**Member variables****************************************************************************
582 Operand matrix_;
584 //**********************************************************************************************
585
586 //**Compile time checks*************************************************************************
594 //**********************************************************************************************
595};
597//*************************************************************************************************
598
599
600
601
602//=================================================================================================
603//
604// CONSTRUCTORS
605//
606//=================================================================================================
607
608//*************************************************************************************************
621template< typename MT // Type of the sparse matrix
622 , AlignmentFlag AF // Alignment flag
623 , size_t... CSAs > // Compile time submatrix arguments
624template< typename... RSAs > // Runtime submatrix arguments
625inline Submatrix<MT,AF,false,false,CSAs...>::Submatrix( MT& matrix, RSAs... args )
626 : DataType( args... ) // Base class initialization
627 , matrix_ ( matrix ) // The matrix containing the submatrix
628{
629 if( isChecked( args... ) ) {
630 if( ( row() + rows() > matrix_.rows() ) || ( column() + columns() > matrix_.columns() ) ) {
631 BLAZE_THROW_INVALID_ARGUMENT( "Invalid submatrix specification" );
632 }
633 }
634 else {
635 BLAZE_USER_ASSERT( row() + rows() <= matrix_.rows() , "Invalid submatrix specification" );
636 BLAZE_USER_ASSERT( column() + columns() <= matrix_.columns(), "Invalid submatrix specification" );
637 }
638}
640//*************************************************************************************************
641
642
643
644
645//=================================================================================================
646//
647// DATA ACCESS FUNCTIONS
648//
649//=================================================================================================
650
651//*************************************************************************************************
662template< typename MT // Type of the sparse matrix
663 , AlignmentFlag AF // Alignment flag
664 , size_t... CSAs > // Compile time submatrix arguments
665inline typename Submatrix<MT,AF,false,false,CSAs...>::Reference
666 Submatrix<MT,AF,false,false,CSAs...>::operator()( size_t i, size_t j )
667{
668 BLAZE_USER_ASSERT( i < rows() , "Invalid row access index" );
669 BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
670
671 return matrix_(row()+i,column()+j);
672}
674//*************************************************************************************************
675
676
677//*************************************************************************************************
688template< typename MT // Type of the sparse matrix
689 , AlignmentFlag AF // Alignment flag
690 , size_t... CSAs > // Compile time submatrix arguments
691inline typename Submatrix<MT,AF,false,false,CSAs...>::ConstReference
692 Submatrix<MT,AF,false,false,CSAs...>::operator()( size_t i, size_t j ) const
693{
694 BLAZE_USER_ASSERT( i < rows() , "Invalid row access index" );
695 BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
696
697 return const_cast<const MT&>( matrix_ )(row()+i,column()+j);
698}
700//*************************************************************************************************
701
702
703//*************************************************************************************************
715template< typename MT // Type of the sparse matrix
716 , AlignmentFlag AF // Alignment flag
717 , size_t... CSAs > // Compile time submatrix arguments
718inline typename Submatrix<MT,AF,false,false,CSAs...>::Reference
719 Submatrix<MT,AF,false,false,CSAs...>::at( size_t i, size_t j )
720{
721 if( i >= rows() ) {
722 BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
723 }
724 if( j >= columns() ) {
725 BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
726 }
727 return (*this)(i,j);
728}
730//*************************************************************************************************
731
732
733//*************************************************************************************************
745template< typename MT // Type of the sparse matrix
746 , AlignmentFlag AF // Alignment flag
747 , size_t... CSAs > // Compile time submatrix arguments
748inline typename Submatrix<MT,AF,false,false,CSAs...>::ConstReference
749 Submatrix<MT,AF,false,false,CSAs...>::at( size_t i, size_t j ) const
750{
751 if( i >= rows() ) {
752 BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
753 }
754 if( j >= columns() ) {
755 BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
756 }
757 return (*this)(i,j);
758}
760//*************************************************************************************************
761
762
763//*************************************************************************************************
775template< typename MT // Type of the sparse matrix
776 , AlignmentFlag AF // Alignment flag
777 , size_t... CSAs > // Compile time submatrix arguments
778inline typename Submatrix<MT,AF,false,false,CSAs...>::Iterator
780{
781 BLAZE_USER_ASSERT( i < rows(), "Invalid sparse submatrix row access index" );
782
783 if( column() == 0UL )
784 return Iterator( matrix_.begin( i + row() ), column() );
785 else
786 return Iterator( matrix_.lowerBound( i + row(), column() ), column() );
787}
789//*************************************************************************************************
790
791
792//*************************************************************************************************
804template< typename MT // Type of the sparse matrix
805 , AlignmentFlag AF // Alignment flag
806 , size_t... CSAs > // Compile time submatrix arguments
807inline typename Submatrix<MT,AF,false,false,CSAs...>::ConstIterator
809{
810 BLAZE_USER_ASSERT( i < rows(), "Invalid sparse submatrix row access index" );
811
812 if( column() == 0UL )
813 return ConstIterator( matrix_.cbegin( i + row() ), column() );
814 else
815 return ConstIterator( matrix_.lowerBound( i + row(), column() ), column() );
816}
818//*************************************************************************************************
819
820
821//*************************************************************************************************
833template< typename MT // Type of the sparse matrix
834 , AlignmentFlag AF // Alignment flag
835 , size_t... CSAs > // Compile time submatrix arguments
836inline typename Submatrix<MT,AF,false,false,CSAs...>::ConstIterator
838{
839 BLAZE_USER_ASSERT( i < rows(), "Invalid sparse submatrix row access index" );
840
841 if( column() == 0UL )
842 return ConstIterator( matrix_.cbegin( i + row() ), column() );
843 else
844 return ConstIterator( matrix_.lowerBound( i + row(), column() ), column() );
845}
847//*************************************************************************************************
848
849
850//*************************************************************************************************
862template< typename MT // Type of the sparse matrix
863 , AlignmentFlag AF // Alignment flag
864 , size_t... CSAs > // Compile time submatrix arguments
865inline typename Submatrix<MT,AF,false,false,CSAs...>::Iterator
867{
868 BLAZE_USER_ASSERT( i < rows(), "Invalid sparse submatrix row access index" );
869
870 if( matrix_.columns() == column() + columns() )
871 return Iterator( matrix_.end( i + row() ), column() );
872 else
873 return Iterator( matrix_.lowerBound( i + row(), column() + columns() ), column() );
874}
876//*************************************************************************************************
877
878
879//*************************************************************************************************
891template< typename MT // Type of the sparse matrix
892 , AlignmentFlag AF // Alignment flag
893 , size_t... CSAs > // Compile time submatrix arguments
894inline typename Submatrix<MT,AF,false,false,CSAs...>::ConstIterator
896{
897 BLAZE_USER_ASSERT( i < rows(), "Invalid sparse submatrix row access index" );
898
899 if( matrix_.columns() == column() + columns() )
900 return ConstIterator( matrix_.cend( i + row() ), column() );
901 else
902 return ConstIterator( matrix_.lowerBound( i + row(), column() + columns() ), column() );
903}
905//*************************************************************************************************
906
907
908//*************************************************************************************************
920template< typename MT // Type of the sparse matrix
921 , AlignmentFlag AF // Alignment flag
922 , size_t... CSAs > // Compile time submatrix arguments
923inline typename Submatrix<MT,AF,false,false,CSAs...>::ConstIterator
925{
926 BLAZE_USER_ASSERT( i < rows(), "Invalid sparse submatrix row access index" );
927
928 if( matrix_.columns() == column() + columns() )
929 return ConstIterator( matrix_.cend( i + row() ), column() );
930 else
931 return ConstIterator( matrix_.lowerBound( i + row(), column() + columns() ), column() );
932}
934//*************************************************************************************************
935
936
937
938
939//=================================================================================================
940//
941// ASSIGNMENT OPERATORS
942//
943//=================================================================================================
944
945//*************************************************************************************************
961template< typename MT // Type of the sparse matrix
962 , AlignmentFlag AF // Alignment flag
963 , size_t... CSAs > // Compile time submatrix arguments
964inline Submatrix<MT,AF,false,false,CSAs...>&
965 Submatrix<MT,AF,false,false,CSAs...>::operator=( initializer_list< initializer_list<ElementType> > list )
966{
967 using blaze::assign;
968
969 if( list.size() != rows() ) {
970 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to submatrix" );
971 }
972
973 const InitializerMatrix<ElementType> tmp( list, columns() );
974
975 if( !tryAssign( matrix_, tmp, row(), column() ) ) {
976 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
977 }
978
979 decltype(auto) left( derestrict( *this ) );
980
981 left.reset();
982 assign( left, tmp );
983
984 return *this;
985}
987//*************************************************************************************************
988
989
990//*************************************************************************************************
1005template< typename MT // Type of the sparse matrix
1006 , AlignmentFlag AF // Alignment flag
1007 , size_t... CSAs > // Compile time submatrix arguments
1008inline Submatrix<MT,AF,false,false,CSAs...>&
1009 Submatrix<MT,AF,false,false,CSAs...>::operator=( const Submatrix& rhs )
1010{
1011 using blaze::assign;
1012
1015
1016 if( this == &rhs || ( &matrix_ == &rhs.matrix_ && row() == rhs.row() && column() == rhs.column() ) )
1017 return *this;
1018
1019 if( rows() != rhs.rows() || columns() != rhs.columns() ) {
1020 BLAZE_THROW_INVALID_ARGUMENT( "Submatrix sizes do not match" );
1021 }
1022
1023 if( !tryAssign( matrix_, rhs, row(), column() ) ) {
1024 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
1025 }
1026
1027 decltype(auto) left( derestrict( *this ) );
1028
1029 if( rhs.canAlias( this ) ) {
1030 const ResultType tmp( rhs );
1031 left.reset();
1032 assign( left, tmp );
1033 }
1034 else {
1035 left.reset();
1036 assign( left, rhs );
1037 }
1038
1039 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
1040
1041 return *this;
1042}
1044//*************************************************************************************************
1045
1046
1047//*************************************************************************************************
1062template< typename MT // Type of the sparse matrix
1063 , AlignmentFlag AF // Alignment flag
1064 , size_t... CSAs > // Compile time submatrix arguments
1065template< typename MT2 // Type of the right-hand side matrix
1066 , bool SO > // Storage order of the right-hand side matrix
1067inline Submatrix<MT,AF,false,false,CSAs...>&
1068 Submatrix<MT,AF,false,false,CSAs...>::operator=( const Matrix<MT2,SO>& rhs )
1069{
1070 using blaze::assign;
1071
1073
1074 if( rows() != (*rhs).rows() || columns() != (*rhs).columns() ) {
1075 BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
1076 }
1077
1078 using Right = CompositeType_t<MT2>;
1079 Right right( *rhs );
1080
1081 if( !tryAssign( matrix_, right, row(), column() ) ) {
1082 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
1083 }
1084
1085 decltype(auto) left( derestrict( *this ) );
1086
1087 if( IsReference_v<Right> && right.canAlias( this ) ) {
1088 const ResultType_t<MT2> tmp( right );
1089 left.reset();
1090 assign( left, transIf< IsSymmetric_v<This> >( tmp ) );
1091 }
1092 else {
1093 left.reset();
1094 assign( left, transIf< IsSymmetric_v<This> >( right ) );
1095 }
1096
1097 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
1098
1099 return *this;
1100}
1102//*************************************************************************************************
1103
1104
1105//*************************************************************************************************
1119template< typename MT // Type of the sparse matrix
1120 , AlignmentFlag AF // Alignment flag
1121 , size_t... CSAs > // Compile time submatrix arguments
1122template< typename MT2 // Type of the right-hand side matrix
1123 , bool SO > // Storage order of the right-hand side matrix
1124inline Submatrix<MT,AF,false,false,CSAs...>&
1125 Submatrix<MT,AF,false,false,CSAs...>::operator+=( const Matrix<MT2,SO>& rhs )
1126{
1127 using blaze::assign;
1128
1132
1133 using AddType = AddTrait_t< ResultType, ResultType_t<MT2> >;
1134
1136
1137 if( rows() != (*rhs).rows() || columns() != (*rhs).columns() ) {
1138 BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
1139 }
1140
1141 const AddType tmp( *this + (*rhs) );
1142
1143 if( !tryAssign( matrix_, tmp, row(), column() ) ) {
1144 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
1145 }
1146
1147 decltype(auto) left( derestrict( *this ) );
1148
1149 left.reset();
1150 assign( left, transIf< IsSymmetric_v<This> >( tmp ) );
1151
1152 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
1153
1154 return *this;
1155}
1157//*************************************************************************************************
1158
1159
1160//*************************************************************************************************
1174template< typename MT // Type of the sparse matrix
1175 , AlignmentFlag AF // Alignment flag
1176 , size_t... CSAs > // Compile time submatrix arguments
1177template< typename MT2 // Type of the right-hand side matrix
1178 , bool SO > // Storage order of the right-hand side matrix
1179inline Submatrix<MT,AF,false,false,CSAs...>&
1180 Submatrix<MT,AF,false,false,CSAs...>::operator-=( const Matrix<MT2,SO>& rhs )
1181{
1182 using blaze::assign;
1183
1187
1188 using SubType = SubTrait_t< ResultType, ResultType_t<MT2> >;
1189
1191
1192 if( rows() != (*rhs).rows() || columns() != (*rhs).columns() ) {
1193 BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
1194 }
1195
1196 const SubType tmp( *this - (*rhs) );
1197
1198 if( !tryAssign( matrix_, tmp, row(), column() ) ) {
1199 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
1200 }
1201
1202 decltype(auto) left( derestrict( *this ) );
1203
1204 left.reset();
1205 assign( left, transIf< IsSymmetric_v<This> >( tmp ) );
1206
1207 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
1208
1209 return *this;
1210}
1212//*************************************************************************************************
1213
1214
1215//*************************************************************************************************
1229template< typename MT // Type of the sparse matrix
1230 , AlignmentFlag AF // Alignment flag
1231 , size_t... CSAs > // Compile time submatrix arguments
1232template< typename MT2 // Type of the right-hand side matrix
1233 , bool SO > // Storage order of the right-hand side matrix
1234inline Submatrix<MT,AF,false,false,CSAs...>&
1235 Submatrix<MT,AF,false,false,CSAs...>::operator%=( const Matrix<MT2,SO>& rhs )
1236{
1237 using blaze::assign;
1238
1242
1243 using SchurType = SchurTrait_t< ResultType, ResultType_t<MT2> >;
1244
1246
1247 if( rows() != (*rhs).rows() || columns() != (*rhs).columns() ) {
1248 BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
1249 }
1250
1251 const SchurType tmp( *this % (*rhs) );
1252
1253 if( !tryAssign( matrix_, tmp, row(), column() ) ) {
1254 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
1255 }
1256
1257 decltype(auto) left( derestrict( *this ) );
1258
1259 left.reset();
1260 assign( left, transIf< IsSymmetric_v<This> >( tmp ) );
1261
1262 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
1263
1264 return *this;
1265}
1267//*************************************************************************************************
1268
1269
1270
1271
1272//=================================================================================================
1273//
1274// UTILITY FUNCTIONS
1275//
1276//=================================================================================================
1277
1278//*************************************************************************************************
1284template< typename MT // Type of the sparse matrix
1285 , AlignmentFlag AF // Alignment flag
1286 , size_t... CSAs > // Compile time submatrix arguments
1287inline MT& Submatrix<MT,AF,false,false,CSAs...>::operand() noexcept
1288{
1289 return matrix_;
1290}
1292//*************************************************************************************************
1293
1294
1295//*************************************************************************************************
1301template< typename MT // Type of the sparse matrix
1302 , AlignmentFlag AF // Alignment flag
1303 , size_t... CSAs > // Compile time submatrix arguments
1304inline const MT& Submatrix<MT,AF,false,false,CSAs...>::operand() const noexcept
1305{
1306 return matrix_;
1307}
1309//*************************************************************************************************
1310
1311
1312//*************************************************************************************************
1318template< typename MT // Type of the sparse matrix
1319 , AlignmentFlag AF // Alignment flag
1320 , size_t... CSAs > // Compile time submatrix arguments
1321inline size_t Submatrix<MT,AF,false,false,CSAs...>::capacity() const noexcept
1322{
1323 return nonZeros() + matrix_.capacity() - matrix_.nonZeros();
1324}
1326//*************************************************************************************************
1327
1328
1329//*************************************************************************************************
1341template< typename MT // Type of the sparse matrix
1342 , AlignmentFlag AF // Alignment flag
1343 , size_t... CSAs > // Compile time submatrix arguments
1344inline size_t Submatrix<MT,AF,false,false,CSAs...>::capacity( size_t i ) const noexcept
1345{
1346 BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
1347 return nonZeros( i ) + matrix_.capacity( row()+i ) - matrix_.nonZeros( row()+i );
1348}
1350//*************************************************************************************************
1351
1352
1353//*************************************************************************************************
1359template< typename MT // Type of the sparse matrix
1360 , AlignmentFlag AF // Alignment flag
1361 , size_t... CSAs > // Compile time submatrix arguments
1363{
1364 size_t nonzeros( 0UL );
1365
1366 for( size_t i=0UL; i<rows(); ++i )
1367 nonzeros += nonZeros( i );
1368
1369 return nonzeros;
1370}
1372//*************************************************************************************************
1373
1374
1375//*************************************************************************************************
1387template< typename MT // Type of the sparse matrix
1388 , AlignmentFlag AF // Alignment flag
1389 , size_t... CSAs > // Compile time submatrix arguments
1390inline size_t Submatrix<MT,AF,false,false,CSAs...>::nonZeros( size_t i ) const
1391{
1392 BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
1393 return end(i) - begin(i);
1394}
1396//*************************************************************************************************
1397
1398
1399//*************************************************************************************************
1405template< typename MT // Type of the sparse matrix
1406 , AlignmentFlag AF // Alignment flag
1407 , size_t... CSAs > // Compile time submatrix arguments
1409{
1410 for( size_t i=row(); i<row()+rows(); ++i )
1411 {
1412 const size_t jbegin( ( IsUpper_v<MT> )
1413 ?( ( IsUniUpper_v<MT> || IsStrictlyUpper_v<MT> )
1414 ?( max( i+1UL, column() ) )
1415 :( max( i, column() ) ) )
1416 :( column() ) );
1417 const size_t jend ( ( IsLower_v<MT> )
1418 ?( ( IsUniLower_v<MT> || IsStrictlyLower_v<MT> )
1419 ?( min( i, column()+columns() ) )
1420 :( min( i+1UL, column()+columns() ) ) )
1421 :( column()+columns() ) );
1422
1423 matrix_.erase( i, matrix_.lowerBound( i, jbegin ), matrix_.lowerBound( i, jend ) );
1424 }
1425}
1427//*************************************************************************************************
1428
1429
1430//*************************************************************************************************
1442template< typename MT // Type of the sparse matrix
1443 , AlignmentFlag AF // Alignment flag
1444 , size_t... CSAs > // Compile time submatrix arguments
1445inline void Submatrix<MT,AF,false,false,CSAs...>::reset( size_t i )
1446{
1447 BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
1448
1449 const size_t index( row() + i );
1450
1451 const size_t jbegin( ( IsUpper_v<MT> )
1452 ?( ( IsUniUpper_v<MT> || IsStrictlyUpper_v<MT> )
1453 ?( max( i+1UL, column() ) )
1454 :( max( i, column() ) ) )
1455 :( column() ) );
1456 const size_t jend ( ( IsLower_v<MT> )
1457 ?( ( IsUniLower_v<MT> || IsStrictlyLower_v<MT> )
1458 ?( min( i, column()+columns() ) )
1459 :( min( i+1UL, column()+columns() ) ) )
1460 :( column()+columns() ) );
1461
1462 matrix_.erase( index, matrix_.lowerBound( index, jbegin ), matrix_.lowerBound( index, jend ) );
1463}
1465//*************************************************************************************************
1466
1467
1468//*************************************************************************************************
1479template< typename MT // Type of the sparse matrix
1480 , AlignmentFlag AF // Alignment flag
1481 , size_t... CSAs > // Compile time submatrix arguments
1482inline void Submatrix<MT,AF,false,false,CSAs...>::reserve( size_t nonzeros )
1483{
1484 const size_t current( capacity() );
1485
1486 if( nonzeros > current ) {
1487 matrix_.reserve( matrix_.capacity() + nonzeros - current );
1488 }
1489}
1491//*************************************************************************************************
1492
1493
1494//*************************************************************************************************
1510template< typename MT // Type of the sparse matrix
1511 , AlignmentFlag AF // Alignment flag
1512 , size_t... CSAs > // Compile time submatrix arguments
1513void Submatrix<MT,AF,false,false,CSAs...>::reserve( size_t i, size_t nonzeros )
1514{
1515 const size_t current( capacity( i ) );
1516 const size_t index ( row() + i );
1517
1518 if( nonzeros > current ) {
1519 matrix_.reserve( index, matrix_.capacity( index ) + nonzeros - current );
1520 }
1521}
1523//*************************************************************************************************
1524
1525
1526//*************************************************************************************************
1537template< typename MT // Type of the sparse matrix
1538 , AlignmentFlag AF // Alignment flag
1539 , size_t... CSAs > // Compile time submatrix arguments
1540void Submatrix<MT,AF,false,false,CSAs...>::trim()
1541{
1542 for( size_t i=0UL; i<rows(); ++i )
1543 trim( i );
1544}
1546//*************************************************************************************************
1547
1548
1549//*************************************************************************************************
1561template< typename MT // Type of the sparse matrix
1562 , AlignmentFlag AF // Alignment flag
1563 , size_t... CSAs > // Compile time submatrix arguments
1564void Submatrix<MT,AF,false,false,CSAs...>::trim( size_t i )
1565{
1566 BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
1567 matrix_.trim( row() + i );
1568}
1570//*************************************************************************************************
1571
1572
1573
1574
1575//=================================================================================================
1576//
1577// INSERTION FUNCTIONS
1578//
1579//=================================================================================================
1580
1581//*************************************************************************************************
1594template< typename MT // Type of the sparse matrix
1595 , AlignmentFlag AF // Alignment flag
1596 , size_t... CSAs > // Compile time submatrix arguments
1597inline typename Submatrix<MT,AF,false,false,CSAs...>::Iterator
1598 Submatrix<MT,AF,false,false,CSAs...>::set( size_t i, size_t j, const ElementType& value )
1599{
1600 return Iterator( matrix_.set( row()+i, column()+j, value ), column() );
1601}
1603//*************************************************************************************************
1604
1605
1606//*************************************************************************************************
1620template< typename MT // Type of the sparse matrix
1621 , AlignmentFlag AF // Alignment flag
1622 , size_t... CSAs > // Compile time submatrix arguments
1623inline typename Submatrix<MT,AF,false,false,CSAs...>::Iterator
1624 Submatrix<MT,AF,false,false,CSAs...>::insert( size_t i, size_t j, const ElementType& value )
1625{
1626 return Iterator( matrix_.insert( row()+i, column()+j, value ), column() );
1627}
1629//*************************************************************************************************
1630
1631
1632//*************************************************************************************************
1676template< typename MT // Type of the sparse matrix
1677 , AlignmentFlag AF // Alignment flag
1678 , size_t... CSAs > // Compile time submatrix arguments
1679inline void Submatrix<MT,AF,false,false,CSAs...>::append( size_t i, size_t j, const ElementType& value, bool check )
1680{
1681 if( column() + columns() == matrix_.columns() ) {
1682 matrix_.append( row() + i, column() + j, value, check );
1683 }
1684 else if( !check || !isDefault<strict>( value ) ) {
1685 matrix_.insert( row() + i, column() + j, value );
1686 }
1687}
1689//*************************************************************************************************
1690
1691
1692//*************************************************************************************************
1706template< typename MT // Type of the sparse matrix
1707 , AlignmentFlag AF // Alignment flag
1708 , size_t... CSAs > // Compile time submatrix arguments
1709inline void Submatrix<MT,AF,false,false,CSAs...>::finalize( size_t i )
1710{
1711 matrix_.trim( row() + i );
1712}
1714//*************************************************************************************************
1715
1716
1717
1718
1719//=================================================================================================
1720//
1721// ERASE FUNCTIONS
1722//
1723//=================================================================================================
1724
1725//*************************************************************************************************
1735template< typename MT // Type of the sparse matrix
1736 , AlignmentFlag AF // Alignment flag
1737 , size_t... CSAs > // Compile time submatrix arguments
1738inline void Submatrix<MT,AF,false,false,CSAs...>::erase( size_t i, size_t j )
1739{
1740 BLAZE_USER_ASSERT( i < rows() , "Invalid row access index" );
1741 BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
1742
1743 matrix_.erase( row() + i, column() + j );
1744}
1746//*************************************************************************************************
1747
1748
1749//*************************************************************************************************
1761template< typename MT // Type of the sparse matrix
1762 , AlignmentFlag AF // Alignment flag
1763 , size_t... CSAs > // Compile time submatrix arguments
1764inline typename Submatrix<MT,AF,false,false,CSAs...>::Iterator
1765 Submatrix<MT,AF,false,false,CSAs...>::erase( size_t i, Iterator pos )
1766{
1767 BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
1768 return Iterator( matrix_.erase( row()+i, pos.base() ), column() );
1769}
1771//*************************************************************************************************
1772
1773
1774//*************************************************************************************************
1788template< typename MT // Type of the sparse matrix
1789 , AlignmentFlag AF // Alignment flag
1790 , size_t... CSAs > // Compile time submatrix arguments
1791inline typename Submatrix<MT,AF,false,false,CSAs...>::Iterator
1792 Submatrix<MT,AF,false,false,CSAs...>::erase( size_t i, Iterator first, Iterator last )
1793{
1794 BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
1795 return Iterator( matrix_.erase( row()+i, first.base(), last.base() ), column() );
1796}
1798//*************************************************************************************************
1799
1800
1801//*************************************************************************************************
1824template< typename MT // Type of the sparse matrix
1825 , AlignmentFlag AF // Alignment flag
1826 , size_t... CSAs > // Compile time submatrix arguments
1827template< typename Pred > // Type of the unary predicate
1828inline void Submatrix<MT,AF,false,false,CSAs...>::erase( Pred predicate )
1829{
1830 for( size_t i=0UL; i<rows(); ++i ) {
1831 matrix_.erase( row()+i, begin(i).base(), end(i).base(), predicate );
1832 }
1833}
1835//*************************************************************************************************
1836
1837
1838//*************************************************************************************************
1867template< typename MT // Type of the sparse matrix
1868 , AlignmentFlag AF // Alignment flag
1869 , size_t... CSAs > // Compile time submatrix arguments
1870template< typename Pred > // Type of the unary predicate
1871inline void Submatrix<MT,AF,false,false,CSAs...>::erase( size_t i, Iterator first, Iterator last, Pred predicate )
1872{
1873 BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
1874 matrix_.erase( row()+i, first.base(), last.base(), predicate );
1875}
1877//*************************************************************************************************
1878
1879
1880
1881
1882//=================================================================================================
1883//
1884// LOOKUP FUNCTIONS
1885//
1886//=================================================================================================
1887
1888//*************************************************************************************************
1904template< typename MT // Type of the sparse matrix
1905 , AlignmentFlag AF // Alignment flag
1906 , size_t... CSAs > // Compile time submatrix arguments
1907inline typename Submatrix<MT,AF,false,false,CSAs...>::Iterator
1908 Submatrix<MT,AF,false,false,CSAs...>::find( size_t i, size_t j )
1909{
1910 const Iterator_t<MT> pos( matrix_.find( row() + i, column() + j ) );
1911
1912 if( pos != matrix_.end( row() + i ) )
1913 return Iterator( pos, column() );
1914 else
1915 return end( i );
1916}
1918//*************************************************************************************************
1919
1920
1921//*************************************************************************************************
1937template< typename MT // Type of the sparse matrix
1938 , AlignmentFlag AF // Alignment flag
1939 , size_t... CSAs > // Compile time submatrix arguments
1940inline typename Submatrix<MT,AF,false,false,CSAs...>::ConstIterator
1941 Submatrix<MT,AF,false,false,CSAs...>::find( size_t i, size_t j ) const
1942{
1943 const ConstIterator_t<MT> pos( matrix_.find( row() + i, column() + j ) );
1944
1945 if( pos != matrix_.end( row() + i ) )
1946 return ConstIterator( pos, column() );
1947 else
1948 return end( i );
1949}
1951//*************************************************************************************************
1952
1953
1954//*************************************************************************************************
1970template< typename MT // Type of the sparse matrix
1971 , AlignmentFlag AF // Alignment flag
1972 , size_t... CSAs > // Compile time submatrix arguments
1973inline typename Submatrix<MT,AF,false,false,CSAs...>::Iterator
1975{
1976 return Iterator( matrix_.lowerBound( row() + i, column() + j ), column() );
1977}
1979//*************************************************************************************************
1980
1981
1982//*************************************************************************************************
1998template< typename MT // Type of the sparse matrix
1999 , AlignmentFlag AF // Alignment flag
2000 , size_t... CSAs > // Compile time submatrix arguments
2001inline typename Submatrix<MT,AF,false,false,CSAs...>::ConstIterator
2002 Submatrix<MT,AF,false,false,CSAs...>::lowerBound( size_t i, size_t j ) const
2003{
2004 return ConstIterator( matrix_.lowerBound( row() + i, column() + j ), column() );
2005}
2007//*************************************************************************************************
2008
2009
2010//*************************************************************************************************
2026template< typename MT // Type of the sparse matrix
2027 , AlignmentFlag AF // Alignment flag
2028 , size_t... CSAs > // Compile time submatrix arguments
2029inline typename Submatrix<MT,AF,false,false,CSAs...>::Iterator
2031{
2032 return Iterator( matrix_.upperBound( row() + i, column() + j ), column() );
2033}
2035//*************************************************************************************************
2036
2037
2038//*************************************************************************************************
2054template< typename MT // Type of the sparse matrix
2055 , AlignmentFlag AF // Alignment flag
2056 , size_t... CSAs > // Compile time submatrix arguments
2057inline typename Submatrix<MT,AF,false,false,CSAs...>::ConstIterator
2058 Submatrix<MT,AF,false,false,CSAs...>::upperBound( size_t i, size_t j ) const
2059{
2060 return ConstIterator( matrix_.upperBound( row() + i, column() + j ), column() );
2061}
2063//*************************************************************************************************
2064
2065
2066
2067
2068//=================================================================================================
2069//
2070// NUMERIC FUNCTIONS
2071//
2072//=================================================================================================
2073
2074//*************************************************************************************************
2092template< typename MT // Type of the sparse matrix
2093 , AlignmentFlag AF // Alignment flag
2094 , size_t... CSAs > // Compile time submatrix arguments
2095inline Submatrix<MT,AF,false,false,CSAs...>&
2097{
2098 using blaze::assign;
2099
2100 if( rows() != columns() ) {
2101 BLAZE_THROW_LOGIC_ERROR( "Invalid transpose of a non-quadratic submatrix" );
2102 }
2103
2104 if( !tryAssign( matrix_, trans( *this ), row(), column() ) ) {
2105 BLAZE_THROW_LOGIC_ERROR( "Invalid transpose operation" );
2106 }
2107
2108 decltype(auto) left( derestrict( *this ) );
2109 const ResultType tmp( trans( *this ) );
2110
2111 reset();
2112 assign( left, tmp );
2113
2114 return *this;
2115}
2117//*************************************************************************************************
2118
2119
2120//*************************************************************************************************
2138template< typename MT // Type of the sparse matrix
2139 , AlignmentFlag AF // Alignment flag
2140 , size_t... CSAs > // Compile time submatrix arguments
2141inline Submatrix<MT,AF,false,false,CSAs...>&
2143{
2144 using blaze::assign;
2145
2146 if( rows() != columns() ) {
2147 BLAZE_THROW_LOGIC_ERROR( "Invalid transpose of a non-quadratic submatrix" );
2148 }
2149
2150 if( !tryAssign( matrix_, trans( *this ), row(), column() ) ) {
2151 BLAZE_THROW_LOGIC_ERROR( "Invalid transpose operation" );
2152 }
2153
2154 decltype(auto) left( derestrict( *this ) );
2155 const ResultType tmp( ctrans( *this ) );
2156
2157 reset();
2158 assign( left, tmp );
2159
2160 return *this;
2161}
2163//*************************************************************************************************
2164
2165
2166//*************************************************************************************************
2179template< typename MT // Type of the sparse matrix
2180 , AlignmentFlag AF // Alignment flag
2181 , size_t... CSAs > // Compile time submatrix arguments
2182template< typename Other > // Data type of the scalar value
2183inline Submatrix<MT,AF,false,false,CSAs...>&
2184 Submatrix<MT,AF,false,false,CSAs...>::scale( const Other& scalar )
2185{
2187
2188 for( size_t i=0UL; i<rows(); ++i ) {
2189 const Iterator last( end(i) );
2190 for( Iterator element=begin(i); element!=last; ++element )
2191 element->value() *= scalar;
2192 }
2193
2194 return *this;
2195}
2197//*************************************************************************************************
2198
2199
2200
2201
2202//=================================================================================================
2203//
2204// EXPRESSION TEMPLATE EVALUATION FUNCTIONS
2205//
2206//=================================================================================================
2207
2208//*************************************************************************************************
2219template< typename MT // Type of the sparse matrix
2220 , AlignmentFlag AF // Alignment flag
2221 , size_t... CSAs > // Compile time submatrix arguments
2222template< typename Other > // Data type of the foreign expression
2223inline bool Submatrix<MT,AF,false,false,CSAs...>::canAlias( const Other* alias ) const noexcept
2224{
2225 return matrix_.isAliased( &unview( *alias ) );
2226}
2228//*************************************************************************************************
2229
2230
2231//*************************************************************************************************
2242template< typename MT // Type of the sparse matrix
2243 , AlignmentFlag AF // Alignment flag
2244 , size_t... CSAs > // Compile time submatrix arguments
2245template< typename Other > // Data type of the foreign expression
2246inline bool Submatrix<MT,AF,false,false,CSAs...>::isAliased( const Other* alias ) const noexcept
2247{
2248 return matrix_.isAliased( &unview( *alias ) );
2249}
2251//*************************************************************************************************
2252
2253
2254//*************************************************************************************************
2265template< typename MT // Type of the sparse matrix
2266 , AlignmentFlag AF // Alignment flag
2267 , size_t... CSAs > // Compile time submatrix arguments
2268inline bool Submatrix<MT,AF,false,false,CSAs...>::canSMPAssign() const noexcept
2269{
2270 return false;
2271}
2273//*************************************************************************************************
2274
2275
2276//*************************************************************************************************
2288template< typename MT // Type of the sparse matrix
2289 , AlignmentFlag AF // Alignment flag
2290 , size_t... CSAs > // Compile time submatrix arguments
2291template< typename MT2 // Type of the right-hand side dense matrix
2292 , bool SO > // Storage order of the right-hand side dense matrix
2293inline void Submatrix<MT,AF,false,false,CSAs...>::assign( const DenseMatrix<MT2,SO>& rhs )
2294{
2295 BLAZE_INTERNAL_ASSERT( rows() == (*rhs).rows() , "Invalid number of rows" );
2296 BLAZE_INTERNAL_ASSERT( columns() == (*rhs).columns(), "Invalid number of columns" );
2297
2298 reserve( 0UL, rows() * columns() );
2299
2300 for( size_t i=0UL; i<rows(); ++i ) {
2301 for( size_t j=0UL; j<columns(); ++j ) {
2302 if( IsSymmetric_v<MT> || IsHermitian_v<MT> ) {
2303 const ElementType& value( (*rhs)(i,j) );
2304 if( !isDefault<strict>( value ) )
2305 set( i, j, value );
2306 }
2307 else {
2308 append( i, j, (*rhs)(i,j), true );
2309 }
2310 }
2311 finalize( i );
2312 }
2313}
2315//*************************************************************************************************
2316
2317
2318//*************************************************************************************************
2330template< typename MT // Type of the sparse matrix
2331 , AlignmentFlag AF // Alignment flag
2332 , size_t... CSAs > // Compile time submatrix arguments
2333template< typename MT2 > // Type of the right-hand side sparse matrix
2334inline void Submatrix<MT,AF,false,false,CSAs...>::assign( const SparseMatrix<MT2,false>& rhs )
2335{
2336 BLAZE_INTERNAL_ASSERT( rows() == (*rhs).rows() , "Invalid number of rows" );
2337 BLAZE_INTERNAL_ASSERT( columns() == (*rhs).columns(), "Invalid number of columns" );
2338
2339 reserve( 0UL, (*rhs).nonZeros() );
2340
2341 for( size_t i=0UL; i<(*rhs).rows(); ++i ) {
2342 for( ConstIterator_t<MT2> element=(*rhs).begin(i); element!=(*rhs).end(i); ++element ) {
2343 if( IsSymmetric_v<MT> || IsHermitian_v<MT> ) {
2344 const ElementType& value( element->value() );
2345 if( !isDefault<strict>( value ) )
2346 set( i, element->index(), value );
2347 }
2348 else {
2349 append( i, element->index(), element->value(), true );
2350 }
2351 }
2352 finalize( i );
2353 }
2354}
2356//*************************************************************************************************
2357
2358
2359//*************************************************************************************************
2371template< typename MT // Type of the sparse matrix
2372 , AlignmentFlag AF // Alignment flag
2373 , size_t... CSAs > // Compile time submatrix arguments
2374template< typename MT2 > // Type of the right-hand side sparse matrix
2375inline void Submatrix<MT,AF,false,false,CSAs...>::assign( const SparseMatrix<MT2,true>& rhs )
2376{
2378
2379 BLAZE_INTERNAL_ASSERT( rows() == (*rhs).rows() , "Invalid number of rows" );
2380 BLAZE_INTERNAL_ASSERT( columns() == (*rhs).columns(), "Invalid number of columns" );
2381
2382 // Counting the number of elements per row
2383 std::vector<size_t> rowLengths( rows(), 0UL );
2384 for( size_t j=0UL; j<columns(); ++j ) {
2385 for( auto element=(*rhs).begin(j); element!=(*rhs).end(j); ++element )
2386 ++rowLengths[element->index()];
2387 }
2388
2389 // Resizing the sparse matrix
2390 for( size_t i=0UL; i<rows(); ++i ) {
2391 reserve( i, rowLengths[i] );
2392 }
2393
2394 // Appending the elements to the rows of the sparse submatrix
2395 for( size_t j=0UL; j<columns(); ++j ) {
2396 for( auto element=(*rhs).begin(j); element!=(*rhs).end(j); ++element )
2397 if( IsSymmetric_v<MT> || IsHermitian_v<MT> ) {
2398 const ElementType& value( element->value() );
2399 if( !isDefault<strict>( value ) )
2400 set( element->index(), j, value );
2401 }
2402 else {
2403 append( element->index(), j, element->value(), true );
2404 }
2405 }
2406}
2408//*************************************************************************************************
2409
2410
2411//*************************************************************************************************
2423template< typename MT // Type of the sparse matrix
2424 , AlignmentFlag AF // Alignment flag
2425 , size_t... CSAs > // Compile time submatrix arguments
2426template< typename MT2 // Type of the right-hand side matrix
2427 , bool SO > // Storage order of the right-hand side matrix
2428inline void Submatrix<MT,AF,false,false,CSAs...>::addAssign( const Matrix<MT2,SO>& rhs )
2429{
2430 using AddType = AddTrait_t< ResultType, ResultType_t<MT2> >;
2431
2433
2434 BLAZE_INTERNAL_ASSERT( rows() == (*rhs).rows() , "Invalid number of rows" );
2435 BLAZE_INTERNAL_ASSERT( columns() == (*rhs).columns(), "Invalid number of columns" );
2436
2437 const AddType tmp( serial( *this + (*rhs) ) );
2438 reset();
2439 assign( tmp );
2440}
2442//*************************************************************************************************
2443
2444
2445//*************************************************************************************************
2457template< typename MT // Type of the sparse matrix
2458 , AlignmentFlag AF // Alignment flag
2459 , size_t... CSAs > // Compile time submatrix arguments
2460template< typename MT2 // Type of the right-hand side matrix
2461 , bool SO > // Storage order of the right-hand side matrix
2462inline void Submatrix<MT,AF,false,false,CSAs...>::subAssign( const Matrix<MT2,SO>& rhs )
2463{
2464 using SubType = SubTrait_t< ResultType, ResultType_t<MT2> >;
2465
2467
2468 BLAZE_INTERNAL_ASSERT( rows() == (*rhs).rows() , "Invalid number of rows" );
2469 BLAZE_INTERNAL_ASSERT( columns() == (*rhs).columns(), "Invalid number of columns" );
2470
2471 const SubType tmp( serial( *this - (*rhs) ) );
2472 reset();
2473 assign( tmp );
2474}
2476//*************************************************************************************************
2477
2478
2479//*************************************************************************************************
2491template< typename MT // Type of the sparse matrix
2492 , AlignmentFlag AF // Alignment flag
2493 , size_t... CSAs > // Compile time submatrix arguments
2494template< typename MT2 // Type of the right-hand side matrix
2495 , bool SO > // Storage order of the right-hand side matrix
2496inline void Submatrix<MT,AF,false,false,CSAs...>::schurAssign( const Matrix<MT2,SO>& rhs )
2497{
2498 using SchurType = SchurTrait_t< ResultType, ResultType_t<MT2> >;
2499
2502
2503 BLAZE_INTERNAL_ASSERT( rows() == (*rhs).rows() , "Invalid number of rows" );
2504 BLAZE_INTERNAL_ASSERT( columns() == (*rhs).columns(), "Invalid number of columns" );
2505
2506 const SchurType tmp( serial( *this % (*rhs) ) );
2507 reset();
2508 assign( tmp );
2509}
2511//*************************************************************************************************
2512
2513
2514
2515
2516
2517
2518
2519
2520//=================================================================================================
2521//
2522// CLASS TEMPLATE SPECIALIZATION FOR COLUMN-MAJOR SPARSE MATRICES
2523//
2524//=================================================================================================
2525
2526//*************************************************************************************************
2534template< typename MT // Type of the sparse matrix
2535 , AlignmentFlag AF // Alignment flag
2536 , size_t... CSAs > // Compile time submatrix arguments
2537class Submatrix<MT,AF,true,false,CSAs...>
2538 : public View< SparseMatrix< Submatrix<MT,AF,true,false,CSAs...>, true > >
2539 , private SubmatrixData<CSAs...>
2540{
2541 private:
2542 //**Type definitions****************************************************************************
2543 using DataType = SubmatrixData<CSAs...>;
2544 using Operand = If_t< IsExpression_v<MT>, MT, MT& >;
2545 //**********************************************************************************************
2546
2547 public:
2548 //**Type definitions****************************************************************************
2550 using This = Submatrix<MT,AF,true,false,CSAs...>;
2551
2553 using BaseType = View< SparseMatrix<This,true> >;
2554
2555 using ViewedType = MT;
2556 using ResultType = SubmatrixTrait_t<MT,CSAs...>;
2557 using OppositeType = OppositeType_t<ResultType>;
2558 using TransposeType = TransposeType_t<ResultType>;
2559 using ElementType = ElementType_t<MT>;
2560 using ReturnType = ReturnType_t<MT>;
2561 using CompositeType = const Submatrix&;
2562
2564 using ConstReference = ConstReference_t<MT>;
2565
2567 using Reference = If_t< IsConst_v<MT>, ConstReference, Reference_t<MT> >;
2568 //**********************************************************************************************
2569
2570 //**SubmatrixElement class definition***********************************************************
2573 template< typename MatrixType // Type of the sparse matrix
2574 , typename IteratorType > // Type of the sparse matrix iterator
2575 class SubmatrixElement
2576 : private SparseElement
2577 {
2578 public:
2579 //**Constructor******************************************************************************
2585 inline SubmatrixElement( IteratorType pos, size_t offset )
2586 : pos_ ( pos ) // Iterator to the current position within the sparse submatrix
2587 , offset_( offset ) // Row offset within the according sparse matrix
2588 {}
2589 //*******************************************************************************************
2590
2591 //**Assignment operator**********************************************************************
2597 template< typename T > inline SubmatrixElement& operator=( const T& v ) {
2598 *pos_ = v;
2599 return *this;
2600 }
2601 //*******************************************************************************************
2602
2603 //**Addition assignment operator*************************************************************
2609 template< typename T > inline SubmatrixElement& operator+=( const T& v ) {
2610 *pos_ += v;
2611 return *this;
2612 }
2613 //*******************************************************************************************
2614
2615 //**Subtraction assignment operator**********************************************************
2621 template< typename T > inline SubmatrixElement& operator-=( const T& v ) {
2622 *pos_ -= v;
2623 return *this;
2624 }
2625 //*******************************************************************************************
2626
2627 //**Multiplication assignment operator*******************************************************
2633 template< typename T > inline SubmatrixElement& operator*=( const T& v ) {
2634 *pos_ *= v;
2635 return *this;
2636 }
2637 //*******************************************************************************************
2638
2639 //**Division assignment operator*************************************************************
2645 template< typename T > inline SubmatrixElement& operator/=( const T& v ) {
2646 *pos_ /= v;
2647 return *this;
2648 }
2649 //*******************************************************************************************
2650
2651 //**Element access operator******************************************************************
2656 inline const SubmatrixElement* operator->() const {
2657 return this;
2658 }
2659 //*******************************************************************************************
2660
2661 //**Value function***************************************************************************
2666 inline decltype(auto) value() const {
2667 return pos_->value();
2668 }
2669 //*******************************************************************************************
2670
2671 //**Index function***************************************************************************
2676 inline size_t index() const {
2677 return pos_->index() - offset_;
2678 }
2679 //*******************************************************************************************
2680
2681 private:
2682 //**Member variables*************************************************************************
2683 IteratorType pos_;
2684 size_t offset_;
2685 //*******************************************************************************************
2686 };
2687 //**********************************************************************************************
2688
2689 //**SubmatrixIterator class definition**********************************************************
2692 template< typename MatrixType // Type of the sparse matrix
2693 , typename IteratorType > // Type of the sparse matrix iterator
2694 class SubmatrixIterator
2695 {
2696 public:
2697 //**Type definitions*************************************************************************
2698 using IteratorCategory = std::forward_iterator_tag;
2699 using ValueType = SubmatrixElement<MatrixType,IteratorType>;
2700 using PointerType = ValueType;
2701 using ReferenceType = ValueType;
2702 using DifferenceType = ptrdiff_t;
2703
2704 // STL iterator requirements
2705 using iterator_category = IteratorCategory;
2706 using value_type = ValueType;
2707 using pointer = PointerType;
2708 using reference = ReferenceType;
2709 using difference_type = DifferenceType;
2710 //*******************************************************************************************
2711
2712 //**Default constructor**********************************************************************
2715 inline SubmatrixIterator()
2716 : pos_ () // Iterator to the current sparse element
2717 , offset_() // The offset of the according row/column of the sparse matrix
2718 {}
2719 //*******************************************************************************************
2720
2721 //**Constructor******************************************************************************
2727 inline SubmatrixIterator( IteratorType iterator, size_t index )
2728 : pos_ ( iterator ) // Iterator to the current sparse element
2729 , offset_( index ) // The offset of the according row/column of the sparse matrix
2730 {}
2731 //*******************************************************************************************
2732
2733 //**Constructor******************************************************************************
2738 template< typename MatrixType2, typename IteratorType2 >
2739 inline SubmatrixIterator( const SubmatrixIterator<MatrixType2,IteratorType2>& it )
2740 : pos_ ( it.base() ) // Iterator to the current sparse element.
2741 , offset_( it.offset() ) // The offset of the according row/column of the sparse matrix
2742 {}
2743 //*******************************************************************************************
2744
2745 //**Prefix increment operator****************************************************************
2750 inline SubmatrixIterator& operator++() {
2751 ++pos_;
2752 return *this;
2753 }
2754 //*******************************************************************************************
2755
2756 //**Postfix increment operator***************************************************************
2761 inline const SubmatrixIterator operator++( int ) {
2762 const SubmatrixIterator tmp( *this );
2763 ++(*this);
2764 return tmp;
2765 }
2766 //*******************************************************************************************
2767
2768 //**Element access operator******************************************************************
2773 inline ReferenceType operator*() const {
2774 return ReferenceType( pos_, offset_ );
2775 }
2776 //*******************************************************************************************
2777
2778 //**Element access operator******************************************************************
2783 inline PointerType operator->() const {
2784 return PointerType( pos_, offset_ );
2785 }
2786 //*******************************************************************************************
2787
2788 //**Equality operator************************************************************************
2794 template< typename MatrixType2, typename IteratorType2 >
2795 inline bool operator==( const SubmatrixIterator<MatrixType2,IteratorType2>& rhs ) const {
2796 return base() == rhs.base();
2797 }
2798 //*******************************************************************************************
2799
2800 //**Inequality operator**********************************************************************
2806 template< typename MatrixType2, typename IteratorType2 >
2807 inline bool operator!=( const SubmatrixIterator<MatrixType2,IteratorType2>& rhs ) const {
2808 return !( *this == rhs );
2809 }
2810 //*******************************************************************************************
2811
2812 //**Subtraction operator*********************************************************************
2818 inline DifferenceType operator-( const SubmatrixIterator& rhs ) const {
2819 return pos_ - rhs.pos_;
2820 }
2821 //*******************************************************************************************
2822
2823 //**Base function****************************************************************************
2828 inline IteratorType base() const {
2829 return pos_;
2830 }
2831 //*******************************************************************************************
2832
2833 //**Offset function**************************************************************************
2838 inline size_t offset() const noexcept {
2839 return offset_;
2840 }
2841 //*******************************************************************************************
2842
2843 private:
2844 //**Member variables*************************************************************************
2845 IteratorType pos_;
2846 size_t offset_;
2847 //*******************************************************************************************
2848 };
2849 //**********************************************************************************************
2850
2851 //**Type definitions****************************************************************************
2853 using ConstIterator = SubmatrixIterator< const MT, ConstIterator_t<MT> >;
2854
2856 using Iterator = If_t< IsConst_v<MT>, ConstIterator, SubmatrixIterator< MT, Iterator_t<MT> > >;
2857 //**********************************************************************************************
2858
2859 //**Compilation flags***************************************************************************
2861 static constexpr bool smpAssignable = MT::smpAssignable;
2862
2864 static constexpr bool compileTimeArgs = DataType::compileTimeArgs;
2865 //**********************************************************************************************
2866
2867 //**Constructors********************************************************************************
2870 template< typename... RSAs >
2871 explicit inline Submatrix( MT& matrix, RSAs... args );
2872
2873 Submatrix( const Submatrix& ) = default;
2875 //**********************************************************************************************
2876
2877 //**Destructor**********************************************************************************
2880 ~Submatrix() = default;
2882 //**********************************************************************************************
2883
2884 //**Data access functions***********************************************************************
2887 inline Reference operator()( size_t i, size_t j );
2888 inline ConstReference operator()( size_t i, size_t j ) const;
2889 inline Reference at( size_t i, size_t j );
2890 inline ConstReference at( size_t i, size_t j ) const;
2891 inline Iterator begin ( size_t i );
2892 inline ConstIterator begin ( size_t i ) const;
2893 inline ConstIterator cbegin( size_t i ) const;
2894 inline Iterator end ( size_t i );
2895 inline ConstIterator end ( size_t i ) const;
2896 inline ConstIterator cend ( size_t i ) const;
2898 //**********************************************************************************************
2899
2900 //**Assignment operators************************************************************************
2903 inline Submatrix& operator=( initializer_list< initializer_list<ElementType> > list );
2904 inline Submatrix& operator=( const Submatrix& rhs );
2905
2906 template< typename MT2, bool SO > inline Submatrix& operator= ( const Matrix<MT2,SO>& rhs );
2907 template< typename MT2, bool SO > inline Submatrix& operator+=( const Matrix<MT2,SO>& rhs );
2908 template< typename MT2, bool SO > inline Submatrix& operator-=( const Matrix<MT2,SO>& rhs );
2909 template< typename MT2, bool SO > inline Submatrix& operator%=( const Matrix<MT2,SO>& rhs );
2911 //**********************************************************************************************
2912
2913 //**Utility functions***************************************************************************
2916 using DataType::row;
2917 using DataType::column;
2918 using DataType::rows;
2919 using DataType::columns;
2920
2921 inline MT& operand() noexcept;
2922 inline const MT& operand() const noexcept;
2923
2924 inline size_t capacity() const noexcept;
2925 inline size_t capacity( size_t i ) const noexcept;
2926 inline size_t nonZeros() const;
2927 inline size_t nonZeros( size_t i ) const;
2928 inline void reset();
2929 inline void reset( size_t i );
2930 inline void reserve( size_t nonzeros );
2931 void reserve( size_t i, size_t nonzeros );
2932 inline void trim();
2933 inline void trim( size_t j );
2935 //**********************************************************************************************
2936
2937 //**Insertion functions*************************************************************************
2940 inline Iterator set ( size_t i, size_t j, const ElementType& value );
2941 inline Iterator insert ( size_t i, size_t j, const ElementType& value );
2942 inline void append ( size_t i, size_t j, const ElementType& value, bool check=false );
2943 inline void finalize( size_t i );
2945 //**********************************************************************************************
2946
2947 //**Erase functions*****************************************************************************
2950 inline void erase( size_t i, size_t j );
2951 inline Iterator erase( size_t i, Iterator pos );
2952 inline Iterator erase( size_t i, Iterator first, Iterator last );
2953
2954 template< typename Pred >
2955 inline void erase( Pred predicate );
2956
2957 template< typename Pred >
2958 inline void erase( size_t i, Iterator first, Iterator last, Pred predicate );
2960 //**********************************************************************************************
2961
2962 //**Lookup functions****************************************************************************
2965 inline Iterator find ( size_t i, size_t j );
2966 inline ConstIterator find ( size_t i, size_t j ) const;
2967 inline Iterator lowerBound( size_t i, size_t j );
2968 inline ConstIterator lowerBound( size_t i, size_t j ) const;
2969 inline Iterator upperBound( size_t i, size_t j );
2970 inline ConstIterator upperBound( size_t i, size_t j ) const;
2972 //**********************************************************************************************
2973
2974 //**Numeric functions***************************************************************************
2977 inline Submatrix& transpose();
2978 inline Submatrix& ctranspose();
2979
2980 template< typename Other > inline Submatrix& scale( const Other& scalar );
2982 //**********************************************************************************************
2983
2984 //**Expression template evaluation functions****************************************************
2987 template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
2988 template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
2989
2990 inline bool canSMPAssign() const noexcept;
2991
2992 template< typename MT2, bool SO > inline void assign ( const DenseMatrix<MT2,SO>& rhs );
2993 template< typename MT2 > inline void assign ( const SparseMatrix<MT2,true>& rhs );
2994 template< typename MT2 > inline void assign ( const SparseMatrix<MT2,false>& rhs );
2995 template< typename MT2, bool SO > inline void addAssign ( const Matrix<MT2,SO>& rhs );
2996 template< typename MT2, bool SO > inline void subAssign ( const Matrix<MT2,SO>& rhs );
2997 template< typename MT2, bool SO > inline void schurAssign( const Matrix<MT2,SO>& rhs );
2999 //**********************************************************************************************
3000
3001 private:
3002 //**Member variables****************************************************************************
3005 Operand matrix_;
3007 //**********************************************************************************************
3008
3009 //**Compile time checks*************************************************************************
3017 //**********************************************************************************************
3018};
3020//*************************************************************************************************
3021
3022
3023
3024
3025//=================================================================================================
3026//
3027// CONSTRUCTORS
3028//
3029//=================================================================================================
3030
3031//*************************************************************************************************
3044template< typename MT // Type of the sparse matrix
3045 , AlignmentFlag AF // Alignment flag
3046 , size_t... CSAs > // Compile time submatrix arguments
3047template< typename... RSAs > // Runtime submatrix arguments
3048inline Submatrix<MT,AF,true,false,CSAs...>::Submatrix( MT& matrix, RSAs... args )
3049 : DataType( args... ) // Base class initialization
3050 , matrix_ ( matrix ) // The matrix containing the submatrix
3051{
3052 if( isChecked( args... ) ) {
3053 if( ( row() + rows() > matrix_.rows() ) || ( column() + columns() > matrix_.columns() ) ) {
3054 BLAZE_THROW_INVALID_ARGUMENT( "Invalid submatrix specification" );
3055 }
3056 }
3057 else {
3058 BLAZE_USER_ASSERT( row() + rows() <= matrix_.rows() , "Invalid submatrix specification" );
3059 BLAZE_USER_ASSERT( column() + columns() <= matrix_.columns(), "Invalid submatrix specification" );
3060 }
3061}
3063//*************************************************************************************************
3064
3065
3066
3067
3068//=================================================================================================
3069//
3070// DATA ACCESS FUNCTIONS
3071//
3072//=================================================================================================
3073
3074//*************************************************************************************************
3085template< typename MT // Type of the sparse matrix
3086 , AlignmentFlag AF // Alignment flag
3087 , size_t... CSAs > // Compile time submatrix arguments
3088inline typename Submatrix<MT,AF,true,false,CSAs...>::Reference
3089 Submatrix<MT,AF,true,false,CSAs...>::operator()( size_t i, size_t j )
3090{
3091 BLAZE_USER_ASSERT( i < rows() , "Invalid row access index" );
3092 BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
3093
3094 return matrix_(row()+i,column()+j);
3095}
3097//*************************************************************************************************
3098
3099
3100//*************************************************************************************************
3111template< typename MT // Type of the sparse matrix
3112 , AlignmentFlag AF // Alignment flag
3113 , size_t... CSAs > // Compile time submatrix arguments
3114inline typename Submatrix<MT,AF,true,false,CSAs...>::ConstReference
3115 Submatrix<MT,AF,true,false,CSAs...>::operator()( size_t i, size_t j ) const
3116{
3117 BLAZE_USER_ASSERT( i < rows() , "Invalid row access index" );
3118 BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
3119
3120 return const_cast<const MT&>( matrix_ )(row()+i,column()+j);
3121}
3123//*************************************************************************************************
3124
3125
3126//*************************************************************************************************
3138template< typename MT // Type of the sparse matrix
3139 , AlignmentFlag AF // Alignment flag
3140 , size_t... CSAs > // Compile time submatrix arguments
3141inline typename Submatrix<MT,AF,true,false,CSAs...>::Reference
3142 Submatrix<MT,AF,true,false,CSAs...>::at( size_t i, size_t j )
3143{
3144 if( i >= rows() ) {
3145 BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
3146 }
3147 if( j >= columns() ) {
3148 BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
3149 }
3150 return (*this)(i,j);
3151}
3153//*************************************************************************************************
3154
3155
3156//*************************************************************************************************
3168template< typename MT // Type of the sparse matrix
3169 , AlignmentFlag AF // Alignment flag
3170 , size_t... CSAs > // Compile time submatrix arguments
3171inline typename Submatrix<MT,AF,true,false,CSAs...>::ConstReference
3172 Submatrix<MT,AF,true,false,CSAs...>::at( size_t i, size_t j ) const
3173{
3174 if( i >= rows() ) {
3175 BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
3176 }
3177 if( j >= columns() ) {
3178 BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
3179 }
3180 return (*this)(i,j);
3181}
3183//*************************************************************************************************
3184
3185
3186//*************************************************************************************************
3193template< typename MT // Type of the sparse matrix
3194 , AlignmentFlag AF // Alignment flag
3195 , size_t... CSAs > // Compile time submatrix arguments
3196inline typename Submatrix<MT,AF,true,false,CSAs...>::Iterator
3198{
3199 BLAZE_USER_ASSERT( j < columns(), "Invalid sparse submatrix column access index" );
3200
3201 if( row() == 0UL )
3202 return Iterator( matrix_.begin( j + column() ), row() );
3203 else
3204 return Iterator( matrix_.lowerBound( row(), j + column() ), row() );
3205}
3207//*************************************************************************************************
3208
3209
3210//*************************************************************************************************
3217template< typename MT // Type of the sparse matrix
3218 , AlignmentFlag AF // Alignment flag
3219 , size_t... CSAs > // Compile time submatrix arguments
3220inline typename Submatrix<MT,AF,true,false,CSAs...>::ConstIterator
3222{
3223 BLAZE_USER_ASSERT( j < columns(), "Invalid sparse submatrix column access index" );
3224
3225 if( row() == 0UL )
3226 return ConstIterator( matrix_.cbegin( j + column() ), row() );
3227 else
3228 return ConstIterator( matrix_.lowerBound( row(), j + column() ), row() );
3229}
3231//*************************************************************************************************
3232
3233
3234//*************************************************************************************************
3241template< typename MT // Type of the sparse matrix
3242 , AlignmentFlag AF // Alignment flag
3243 , size_t... CSAs > // Compile time submatrix arguments
3244inline typename Submatrix<MT,AF,true,false,CSAs...>::ConstIterator
3246{
3247 BLAZE_USER_ASSERT( j < columns(), "Invalid sparse submatrix column access index" );
3248
3249 if( row() == 0UL )
3250 return ConstIterator( matrix_.cbegin( j + column() ), row() );
3251 else
3252 return ConstIterator( matrix_.lowerBound( row(), j + column() ), row() );
3253}
3255//*************************************************************************************************
3256
3257
3258//*************************************************************************************************
3265template< typename MT // Type of the sparse matrix
3266 , AlignmentFlag AF // Alignment flag
3267 , size_t... CSAs > // Compile time submatrix arguments
3268inline typename Submatrix<MT,AF,true,false,CSAs...>::Iterator
3270{
3271 BLAZE_USER_ASSERT( j < columns(), "Invalid sparse submatrix column access index" );
3272
3273 if( matrix_.rows() == row() + rows() )
3274 return Iterator( matrix_.end( j + column() ), row() );
3275 else
3276 return Iterator( matrix_.lowerBound( row() + rows(), j + column() ), row() );
3277}
3279//*************************************************************************************************
3280
3281
3282//*************************************************************************************************
3289template< typename MT // Type of the sparse matrix
3290 , AlignmentFlag AF // Alignment flag
3291 , size_t... CSAs > // Compile time submatrix arguments
3292inline typename Submatrix<MT,AF,true,false,CSAs...>::ConstIterator
3294{
3295 BLAZE_USER_ASSERT( j < columns(), "Invalid sparse submatrix column access index" );
3296
3297 if( matrix_.rows() == row() + rows() )
3298 return ConstIterator( matrix_.cend( j + column() ), row() );
3299 else
3300 return ConstIterator( matrix_.lowerBound( row() + rows(), j + column() ), row() );
3301}
3303//*************************************************************************************************
3304
3305
3306//*************************************************************************************************
3313template< typename MT // Type of the sparse matrix
3314 , AlignmentFlag AF // Alignment flag
3315 , size_t... CSAs > // Compile time submatrix arguments
3316inline typename Submatrix<MT,AF,true,false,CSAs...>::ConstIterator
3318{
3319 BLAZE_USER_ASSERT( j < columns(), "Invalid sparse submatrix column access index" );
3320
3321 if( matrix_.rows() == row() + rows() )
3322 return ConstIterator( matrix_.cend( j + column() ), row() );
3323 else
3324 return ConstIterator( matrix_.lowerBound( row() + rows(), j + column() ), row() );
3325}
3327//*************************************************************************************************
3328
3329
3330
3331
3332//=================================================================================================
3333//
3334// ASSIGNMENT OPERATORS
3335//
3336//=================================================================================================
3337
3338//*************************************************************************************************
3354template< typename MT // Type of the sparse matrix
3355 , AlignmentFlag AF // Alignment flag
3356 , size_t... CSAs > // Compile time submatrix arguments
3357inline Submatrix<MT,AF,true,false,CSAs...>&
3358 Submatrix<MT,AF,true,false,CSAs...>::operator=( initializer_list< initializer_list<ElementType> > list )
3359{
3360 using blaze::assign;
3361
3362 if( list.size() != rows() ) {
3363 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to submatrix" );
3364 }
3365
3366 const InitializerMatrix<ElementType> tmp( list, columns() );
3367
3368 if( !tryAssign( matrix_, tmp, row(), column() ) ) {
3369 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
3370 }
3371
3372 decltype(auto) left( derestrict( *this ) );
3373
3374 left.reset();
3375 assign( left, tmp );
3376
3377 return *this;
3378}
3380//*************************************************************************************************
3381
3382
3383//*************************************************************************************************
3398template< typename MT // Type of the sparse matrix
3399 , AlignmentFlag AF // Alignment flag
3400 , size_t... CSAs > // Compile time submatrix arguments
3401inline Submatrix<MT,AF,true,false,CSAs...>&
3402 Submatrix<MT,AF,true,false,CSAs...>::operator=( const Submatrix& rhs )
3403{
3404 using blaze::assign;
3405
3408
3409 if( this == &rhs || ( &matrix_ == &rhs.matrix_ && row() == rhs.row() && column() == rhs.column() ) )
3410 return *this;
3411
3412 if( rows() != rhs.rows() || columns() != rhs.columns() ) {
3413 BLAZE_THROW_INVALID_ARGUMENT( "Submatrix sizes do not match" );
3414 }
3415
3416 if( !tryAssign( matrix_, rhs, row(), column() ) ) {
3417 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
3418 }
3419
3420 decltype(auto) left( derestrict( *this ) );
3421
3422 if( rhs.canAlias( this ) ) {
3423 const ResultType tmp( rhs );
3424 left.reset();
3425 assign( left, tmp );
3426 }
3427 else {
3428 left.reset();
3429 assign( left, rhs );
3430 }
3431
3432 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
3433
3434 return *this;
3435}
3437//*************************************************************************************************
3438
3439
3440//*************************************************************************************************
3455template< typename MT // Type of the sparse matrix
3456 , AlignmentFlag AF // Alignment flag
3457 , size_t... CSAs > // Compile time submatrix arguments
3458template< typename MT2 // Type of the right-hand side matrix
3459 , bool SO > // Storage order of the right-hand side matrix
3460inline Submatrix<MT,AF,true,false,CSAs...>&
3461 Submatrix<MT,AF,true,false,CSAs...>::operator=( const Matrix<MT2,SO>& rhs )
3462{
3463 using blaze::assign;
3464
3466
3467 if( rows() != (*rhs).rows() || columns() != (*rhs).columns() ) {
3468 BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
3469 }
3470
3471 using Right = CompositeType_t<MT2>;
3472 Right right( *rhs );
3473
3474 if( !tryAssign( matrix_, right, row(), column() ) ) {
3475 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
3476 }
3477
3478 decltype(auto) left( derestrict( *this ) );
3479
3480 if( IsReference_v<Right> && right.canAlias( this ) ) {
3481 const ResultType_t<MT2> tmp( right );
3482 left.reset();
3483 assign( left, transIf< IsSymmetric_v<This> >( tmp ) );
3484 }
3485 else {
3486 left.reset();
3487 assign( left, transIf< IsSymmetric_v<This> >( right ) );
3488 }
3489
3490 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
3491
3492 return *this;
3493}
3495//*************************************************************************************************
3496
3497
3498//*************************************************************************************************
3512template< typename MT // Type of the sparse matrix
3513 , AlignmentFlag AF // Alignment flag
3514 , size_t... CSAs > // Compile time submatrix arguments
3515template< typename MT2 // Type of the right-hand side matrix
3516 , bool SO > // Storage order of the right-hand side matrix
3517inline Submatrix<MT,AF,true,false,CSAs...>&
3518 Submatrix<MT,AF,true,false,CSAs...>::operator+=( const Matrix<MT2,SO>& rhs )
3519{
3520 using blaze::assign;
3521
3525
3526 using AddType = AddTrait_t< ResultType, ResultType_t<MT2> >;
3527
3529
3530 if( rows() != (*rhs).rows() || columns() != (*rhs).columns() ) {
3531 BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
3532 }
3533
3534 const AddType tmp( *this + (*rhs) );
3535
3536 if( !tryAssign( matrix_, tmp, row(), column() ) ) {
3537 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
3538 }
3539
3540 decltype(auto) left( derestrict( *this ) );
3541
3542 left.reset();
3543 assign( left, transIf< IsSymmetric_v<This> >( tmp ) );
3544
3545 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
3546
3547 return *this;
3548}
3550//*************************************************************************************************
3551
3552
3553//*************************************************************************************************
3567template< typename MT // Type of the sparse matrix
3568 , AlignmentFlag AF // Alignment flag
3569 , size_t... CSAs > // Compile time submatrix arguments
3570template< typename MT2 // Type of the right-hand side matrix
3571 , bool SO > // Storage order of the right-hand side matrix
3572inline Submatrix<MT,AF,true,false,CSAs...>&
3573 Submatrix<MT,AF,true,false,CSAs...>::operator-=( const Matrix<MT2,SO>& rhs )
3574{
3575 using blaze::assign;
3576
3580
3581 using SubType = SubTrait_t< ResultType, ResultType_t<MT2> >;
3582
3584
3585 if( rows() != (*rhs).rows() || columns() != (*rhs).columns() ) {
3586 BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
3587 }
3588
3589 const SubType tmp( *this - (*rhs) );
3590
3591 if( !tryAssign( matrix_, tmp, row(), column() ) ) {
3592 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
3593 }
3594
3595 decltype(auto) left( derestrict( *this ) );
3596
3597 left.reset();
3598 assign( left, transIf< IsSymmetric_v<This> >( tmp ) );
3599
3600 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
3601
3602 return *this;
3603}
3605//*************************************************************************************************
3606
3607
3608//*************************************************************************************************
3622template< typename MT // Type of the sparse matrix
3623 , AlignmentFlag AF // Alignment flag
3624 , size_t... CSAs > // Compile time submatrix arguments
3625template< typename MT2 // Type of the right-hand side matrix
3626 , bool SO > // Storage order of the right-hand side matrix
3627inline Submatrix<MT,AF,true,false,CSAs...>&
3628 Submatrix<MT,AF,true,false,CSAs...>::operator%=( const Matrix<MT2,SO>& rhs )
3629{
3630 using blaze::assign;
3631
3635
3636 using SchurType = SchurTrait_t< ResultType, ResultType_t<MT2> >;
3637
3639
3640 if( rows() != (*rhs).rows() || columns() != (*rhs).columns() ) {
3641 BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
3642 }
3643
3644 const SchurType tmp( *this % (*rhs) );
3645
3646 if( !tryAssign( matrix_, tmp, row(), column() ) ) {
3647 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
3648 }
3649
3650 decltype(auto) left( derestrict( *this ) );
3651
3652 left.reset();
3653 assign( left, transIf< IsSymmetric_v<This> >( tmp ) );
3654
3655 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
3656
3657 return *this;
3658}
3660//*************************************************************************************************
3661
3662
3663
3664
3665//=================================================================================================
3666//
3667// UTILITY FUNCTIONS
3668//
3669//=================================================================================================
3670
3671//*************************************************************************************************
3677template< typename MT // Type of the sparse matrix
3678 , AlignmentFlag AF // Alignment flag
3679 , size_t... CSAs > // Compile time submatrix arguments
3680inline MT& Submatrix<MT,AF,true,false,CSAs...>::operand() noexcept
3681{
3682 return matrix_;
3683}
3685//*************************************************************************************************
3686
3687
3688//*************************************************************************************************
3694template< typename MT // Type of the sparse matrix
3695 , AlignmentFlag AF // Alignment flag
3696 , size_t... CSAs > // Compile time submatrix arguments
3697inline const MT& Submatrix<MT,AF,true,false,CSAs...>::operand() const noexcept
3698{
3699 return matrix_;
3700}
3702//*************************************************************************************************
3703
3704
3705//*************************************************************************************************
3711template< typename MT // Type of the sparse matrix
3712 , AlignmentFlag AF // Alignment flag
3713 , size_t... CSAs > // Compile time submatrix arguments
3714inline size_t Submatrix<MT,AF,true,false,CSAs...>::capacity() const noexcept
3715{
3716 return nonZeros() + matrix_.capacity() - matrix_.nonZeros();
3717}
3719//*************************************************************************************************
3720
3721
3722//*************************************************************************************************
3729template< typename MT // Type of the sparse matrix
3730 , AlignmentFlag AF // Alignment flag
3731 , size_t... CSAs > // Compile time submatrix arguments
3732inline size_t Submatrix<MT,AF,true,false,CSAs...>::capacity( size_t j ) const noexcept
3733{
3734 BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
3735 return nonZeros( j ) + matrix_.capacity( column()+j ) - matrix_.nonZeros( column()+j );
3736}
3738//*************************************************************************************************
3739
3740
3741//*************************************************************************************************
3747template< typename MT // Type of the sparse matrix
3748 , AlignmentFlag AF // Alignment flag
3749 , size_t... CSAs > // Compile time submatrix arguments
3751{
3752 size_t nonzeros( 0UL );
3753
3754 for( size_t i=0UL; i<columns(); ++i )
3755 nonzeros += nonZeros( i );
3756
3757 return nonzeros;
3758}
3760//*************************************************************************************************
3761
3762
3763//*************************************************************************************************
3770template< typename MT // Type of the sparse matrix
3771 , AlignmentFlag AF // Alignment flag
3772 , size_t... CSAs > // Compile time submatrix arguments
3773inline size_t Submatrix<MT,AF,true,false,CSAs...>::nonZeros( size_t j ) const
3774{
3775 BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
3776 return end(j) - begin(j);
3777}
3779//*************************************************************************************************
3780
3781
3782//*************************************************************************************************
3788template< typename MT // Type of the sparse matrix
3789 , AlignmentFlag AF // Alignment flag
3790 , size_t... CSAs > // Compile time submatrix arguments
3792{
3793 for( size_t j=column(); j<column()+columns(); ++j )
3794 {
3795 const size_t ibegin( ( IsLower_v<MT> )
3796 ?( ( IsUniLower_v<MT> || IsStrictlyLower_v<MT> )
3797 ?( max( j+1UL, row() ) )
3798 :( max( j, row() ) ) )
3799 :( row() ) );
3800 const size_t iend ( ( IsUpper_v<MT> )
3801 ?( ( IsUniUpper_v<MT> || IsStrictlyUpper_v<MT> )
3802 ?( min( j, row()+rows() ) )
3803 :( min( j+1UL, row()+rows() ) ) )
3804 :( row()+rows() ) );
3805
3806 matrix_.erase( j, matrix_.lowerBound( ibegin, j ), matrix_.lowerBound( iend, j ) );
3807 }
3808}
3810//*************************************************************************************************
3811
3812
3813//*************************************************************************************************
3820template< typename MT // Type of the sparse matrix
3821 , AlignmentFlag AF // Alignment flag
3822 , size_t... CSAs > // Compile time submatrix arguments
3823inline void Submatrix<MT,AF,true,false,CSAs...>::reset( size_t j )
3824{
3825 BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
3826
3827 const size_t index( column() + j );
3828
3829 const size_t ibegin( ( IsLower_v<MT> )
3830 ?( ( IsUniLower_v<MT> || IsStrictlyLower_v<MT> )
3831 ?( max( j+1UL, row() ) )
3832 :( max( j, row() ) ) )
3833 :( row() ) );
3834 const size_t iend ( ( IsUpper_v<MT> )
3835 ?( ( IsUniUpper_v<MT> || IsStrictlyUpper_v<MT> )
3836 ?( min( j, row()+rows() ) )
3837 :( min( j+1UL, row()+rows() ) ) )
3838 :( row()+rows() ) );
3839
3840 matrix_.erase( index, matrix_.lowerBound( ibegin, index ), matrix_.lowerBound( iend, index ) );
3841}
3843//*************************************************************************************************
3844
3845
3846//*************************************************************************************************
3857template< typename MT // Type of the sparse matrix
3858 , AlignmentFlag AF // Alignment flag
3859 , size_t... CSAs > // Compile time submatrix arguments
3860inline void Submatrix<MT,AF,true,false,CSAs...>::reserve( size_t nonzeros )
3861{
3862 const size_t current( capacity() );
3863
3864 if( nonzeros > current ) {
3865 matrix_.reserve( matrix_.capacity() + nonzeros - current );
3866 }
3867}
3869//*************************************************************************************************
3870
3871
3872//*************************************************************************************************
3884template< typename MT // Type of the sparse matrix
3885 , AlignmentFlag AF // Alignment flag
3886 , size_t... CSAs > // Compile time submatrix arguments
3887void Submatrix<MT,AF,true,false,CSAs...>::reserve( size_t j, size_t nonzeros )
3888{
3889 const size_t current( capacity( j ) );
3890 const size_t index ( column() + j );
3891
3892 if( nonzeros > current ) {
3893 matrix_.reserve( index, matrix_.capacity( index ) + nonzeros - current );
3894 }
3895}
3897//*************************************************************************************************
3898
3899
3900//*************************************************************************************************
3910template< typename MT // Type of the sparse matrix
3911 , AlignmentFlag AF // Alignment flag
3912 , size_t... CSAs > // Compile time submatrix arguments
3913void Submatrix<MT,AF,true,false,CSAs...>::trim()
3914{
3915 for( size_t j=0UL; j<columns(); ++j )
3916 trim( j );
3917}
3919//*************************************************************************************************
3920
3921
3922//*************************************************************************************************
3933template< typename MT // Type of the sparse matrix
3934 , AlignmentFlag AF // Alignment flag
3935 , size_t... CSAs > // Compile time submatrix arguments
3936void Submatrix<MT,AF,true,false,CSAs...>::trim( size_t j )
3937{
3938 BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
3939 matrix_.trim( column() + j );
3940}
3942//*************************************************************************************************
3943
3944
3945
3946
3947//=================================================================================================
3948//
3949// INSERTION FUNCTIONS
3950//
3951//=================================================================================================
3952
3953//*************************************************************************************************
3966template< typename MT // Type of the sparse matrix
3967 , AlignmentFlag AF // Alignment flag
3968 , size_t... CSAs > // Compile time submatrix arguments
3969inline typename Submatrix<MT,AF,true,false,CSAs...>::Iterator
3970 Submatrix<MT,AF,true,false,CSAs...>::set( size_t i, size_t j, const ElementType& value )
3971{
3972 return Iterator( matrix_.set( row()+i, column()+j, value ), row() );
3973}
3975//*************************************************************************************************
3976
3977
3978//*************************************************************************************************
3992template< typename MT // Type of the sparse matrix
3993 , AlignmentFlag AF // Alignment flag
3994 , size_t... CSAs > // Compile time submatrix arguments
3995inline typename Submatrix<MT,AF,true,false,CSAs...>::Iterator
3996 Submatrix<MT,AF,true,false,CSAs...>::insert( size_t i, size_t j, const ElementType& value )
3997{
3998 return Iterator( matrix_.insert( row()+i, column()+j, value ), row() );
3999}
4001//*************************************************************************************************
4002
4003
4004//*************************************************************************************************
4048template< typename MT // Type of the sparse matrix
4049 , AlignmentFlag AF // Alignment flag
4050 , size_t... CSAs > // Compile time submatrix arguments
4051inline void Submatrix<MT,AF,true,false,CSAs...>::append( size_t i, size_t j, const ElementType& value, bool check )
4052{
4053 if( row() + rows() == matrix_.rows() ) {
4054 matrix_.append( row() + i, column() + j, value, check );
4055 }
4056 else if( !check || !isDefault<strict>( value ) ) {
4057 matrix_.insert( row() + i, column() + j, value );
4058 }
4059}
4061//*************************************************************************************************
4062
4063
4064//*************************************************************************************************
4078template< typename MT // Type of the sparse matrix
4079 , AlignmentFlag AF // Alignment flag
4080 , size_t... CSAs > // Compile time submatrix arguments
4081inline void Submatrix<MT,AF,true,false,CSAs...>::finalize( size_t j )
4082{
4083 matrix_.trim( column() + j );
4084}
4086//*************************************************************************************************
4087
4088
4089
4090
4091//=================================================================================================
4092//
4093// ERASE FUNCTIONS
4094//
4095//=================================================================================================
4096
4097//*************************************************************************************************
4107template< typename MT // Type of the sparse matrix
4108 , AlignmentFlag AF // Alignment flag
4109 , size_t... CSAs > // Compile time submatrix arguments
4110inline void Submatrix<MT,AF,true,false,CSAs...>::erase( size_t i, size_t j )
4111{
4112 BLAZE_USER_ASSERT( i < rows() , "Invalid row access index" );
4113 BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
4114
4115 matrix_.erase( row() + i, column() + j );
4116}
4118//*************************************************************************************************
4119
4120
4121//*************************************************************************************************
4131template< typename MT // Type of the sparse matrix
4132 , AlignmentFlag AF // Alignment flag
4133 , size_t... CSAs > // Compile time submatrix arguments
4134inline typename Submatrix<MT,AF,true,false,CSAs...>::Iterator
4135 Submatrix<MT,AF,true,false,CSAs...>::erase( size_t j, Iterator pos )
4136{
4137 BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
4138 return Iterator( matrix_.erase( column()+j, pos.base() ), row() );
4139}
4141//*************************************************************************************************
4142
4143
4144//*************************************************************************************************
4155template< typename MT // Type of the sparse matrix
4156 , AlignmentFlag AF // Alignment flag
4157 , size_t... CSAs > // Compile time submatrix arguments
4158inline typename Submatrix<MT,AF,true,false,CSAs...>::Iterator
4159 Submatrix<MT,AF,true,false,CSAs...>::erase( size_t j, Iterator first, Iterator last )
4160{
4161 BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
4162 return Iterator( matrix_.erase( column()+j, first.base(), last.base() ), row() );
4163}
4165//*************************************************************************************************
4166
4167
4168//*************************************************************************************************
4191template< typename MT // Type of the sparse matrix
4192 , AlignmentFlag AF // Alignment flag
4193 , size_t... CSAs > // Compile time submatrix arguments
4194template< typename Pred > // Type of the unary predicate
4195inline void Submatrix<MT,AF,true,false,CSAs...>::erase( Pred predicate )
4196{
4197 for( size_t j=0UL; j<columns(); ++j ) {
4198 matrix_.erase( column()+j, begin(j).base(), end(j).base(), predicate );
4199 }
4200}
4202//*************************************************************************************************
4203
4204
4205//*************************************************************************************************
4231template< typename MT // Type of the sparse matrix
4232 , AlignmentFlag AF // Alignment flag
4233 , size_t... CSAs > // Compile time submatrix arguments
4234template< typename Pred > // Type of the unary predicate
4235inline void Submatrix<MT,AF,true,false,CSAs...>::erase( size_t j, Iterator first, Iterator last, Pred predicate )
4236{
4237 BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
4238 matrix_.erase( column()+j, first.base(), last.base(), predicate );
4239}
4241//*************************************************************************************************
4242
4243
4244
4245
4246//=================================================================================================
4247//
4248// LOOKUP FUNCTIONS
4249//
4250//=================================================================================================
4251
4252//*************************************************************************************************
4268template< typename MT // Type of the sparse matrix
4269 , AlignmentFlag AF // Alignment flag
4270 , size_t... CSAs > // Compile time submatrix arguments
4271inline typename Submatrix<MT,AF,true,false,CSAs...>::Iterator
4272 Submatrix<MT,AF,true,false,CSAs...>::find( size_t i, size_t j )
4273{
4274 const Iterator_t<MT> pos( matrix_.find( row() + i, column() + j ) );
4275
4276 if( pos != matrix_.end( column() + j ) )
4277 return Iterator( pos, row() );
4278 else
4279 return end( j );
4280}
4282//*************************************************************************************************
4283
4284
4285//*************************************************************************************************
4301template< typename MT // Type of the sparse matrix
4302 , AlignmentFlag AF // Alignment flag
4303 , size_t... CSAs > // Compile time submatrix arguments
4304inline typename Submatrix<MT,AF,true,false,CSAs...>::ConstIterator
4305 Submatrix<MT,AF,true,false,CSAs...>::find( size_t i, size_t j ) const
4306{
4307 const ConstIterator_t<MT> pos( matrix_.find( row() + i, column() + j ) );
4308
4309 if( pos != matrix_.end( column() + j ) )
4310 return ConstIterator( pos, row() );
4311 else
4312 return end( j );
4313}
4315//*************************************************************************************************
4316
4317
4318//*************************************************************************************************
4334template< typename MT // Type of the sparse matrix
4335 , AlignmentFlag AF // Alignment flag
4336 , size_t... CSAs > // Compile time submatrix arguments
4337inline typename Submatrix<MT,AF,true,false,CSAs...>::Iterator
4339{
4340 return Iterator( matrix_.lowerBound( row() + i, column() + j ), row() );
4341}
4343//*************************************************************************************************
4344
4345
4346//*************************************************************************************************
4362template< typename MT // Type of the sparse matrix
4363 , AlignmentFlag AF // Alignment flag
4364 , size_t... CSAs > // Compile time submatrix arguments
4365inline typename Submatrix<MT,AF,true,false,CSAs...>::ConstIterator
4366 Submatrix<MT,AF,true,false,CSAs...>::lowerBound( size_t i, size_t j ) const
4367{
4368 return ConstIterator( matrix_.lowerBound( row() + i, column() + j ), row() );
4369}
4371//*************************************************************************************************
4372
4373
4374//*************************************************************************************************
4390template< typename MT // Type of the sparse matrix
4391 , AlignmentFlag AF // Alignment flag
4392 , size_t... CSAs > // Compile time submatrix arguments
4393inline typename Submatrix<MT,AF,true,false,CSAs...>::Iterator
4395{
4396 return Iterator( matrix_.upperBound( row() + i, column() + j ), row() );
4397}
4399//*************************************************************************************************
4400
4401
4402//*************************************************************************************************
4418template< typename MT // Type of the sparse matrix
4419 , AlignmentFlag AF // Alignment flag
4420 , size_t... CSAs > // Compile time submatrix arguments
4421inline typename Submatrix<MT,AF,true,false,CSAs...>::ConstIterator
4422 Submatrix<MT,AF,true,false,CSAs...>::upperBound( size_t i, size_t j ) const
4423{
4424 return ConstIterator( matrix_.upperBound( row() + i, column() + j ), row() );
4425}
4427//*************************************************************************************************
4428
4429
4430
4431
4432//=================================================================================================
4433//
4434// NUMERIC FUNCTIONS
4435//
4436//=================================================================================================
4437
4438//*************************************************************************************************
4456template< typename MT // Type of the sparse matrix
4457 , AlignmentFlag AF // Alignment flag
4458 , size_t... CSAs > // Compile time submatrix arguments
4459inline Submatrix<MT,AF,true,false,CSAs...>&
4461{
4462 using blaze::assign;
4463
4464 if( rows() != columns() ) {
4465 BLAZE_THROW_LOGIC_ERROR( "Invalid transpose of a non-quadratic submatrix" );
4466 }
4467
4468 if( !tryAssign( matrix_, trans( *this ), row(), column() ) ) {
4469 BLAZE_THROW_LOGIC_ERROR( "Invalid transpose operation" );
4470 }
4471
4472 decltype(auto) left( derestrict( *this ) );
4473 const ResultType tmp( trans( *this ) );
4474
4475 reset();
4476 assign( left, tmp );
4477
4478 return *this;
4479}
4481//*************************************************************************************************
4482
4483
4484//*************************************************************************************************
4502template< typename MT // Type of the sparse matrix
4503 , AlignmentFlag AF // Alignment flag
4504 , size_t... CSAs > // Compile time submatrix arguments
4505inline Submatrix<MT,AF,true,false,CSAs...>&
4507{
4508 using blaze::assign;
4509
4510 if( rows() != columns() ) {
4511 BLAZE_THROW_LOGIC_ERROR( "Invalid transpose of a non-quadratic submatrix" );
4512 }
4513
4514 if( !tryAssign( matrix_, ctrans( *this ), row(), column() ) ) {
4515 BLAZE_THROW_LOGIC_ERROR( "Invalid transpose operation" );
4516 }
4517
4518 decltype(auto) left( derestrict( *this ) );
4519 const ResultType tmp( ctrans(*this) );
4520
4521 reset();
4522 assign( left, tmp );
4523
4524 return *this;
4525}
4527//*************************************************************************************************
4528
4529
4530//*************************************************************************************************
4543template< typename MT // Type of the sparse matrix
4544 , AlignmentFlag AF // Alignment flag
4545 , size_t... CSAs > // Compile time submatrix arguments
4546template< typename Other > // Data type of the scalar value
4547inline Submatrix<MT,AF,true,false,CSAs...>&
4548 Submatrix<MT,AF,true,false,CSAs...>::scale( const Other& scalar )
4549{
4551
4552 for( size_t i=0UL; i<columns(); ++i ) {
4553 const Iterator last( end(i) );
4554 for( Iterator element=begin(i); element!=last; ++element )
4555 element->value() *= scalar;
4556 }
4557
4558 return *this;
4559}
4561//*************************************************************************************************
4562
4563
4564
4565
4566//=================================================================================================
4567//
4568// EXPRESSION TEMPLATE EVALUATION FUNCTIONS
4569//
4570//=================================================================================================
4571
4572//*************************************************************************************************
4583template< typename MT // Type of the sparse matrix
4584 , AlignmentFlag AF // Alignment flag
4585 , size_t... CSAs > // Compile time submatrix arguments
4586template< typename Other > // Data type of the foreign expression
4587inline bool Submatrix<MT,AF,true,false,CSAs...>::canAlias( const Other* alias ) const noexcept
4588{
4589 return matrix_.isAliased( &unview( *alias ) );
4590}
4592//*************************************************************************************************
4593
4594
4595//*************************************************************************************************
4606template< typename MT // Type of the sparse matrix
4607 , AlignmentFlag AF // Alignment flag
4608 , size_t... CSAs > // Compile time submatrix arguments
4609template< typename Other > // Data type of the foreign expression
4610inline bool Submatrix<MT,AF,true,false,CSAs...>::isAliased( const Other* alias ) const noexcept
4611{
4612 return matrix_.isAliased( &unview( *alias ) );
4613}
4615//*************************************************************************************************
4616
4617
4618//*************************************************************************************************
4629template< typename MT // Type of the sparse matrix
4630 , AlignmentFlag AF // Alignment flag
4631 , size_t... CSAs > // Compile time submatrix arguments
4632inline bool Submatrix<MT,AF,true,false,CSAs...>::canSMPAssign() const noexcept
4633{
4634 return false;
4635}
4637//*************************************************************************************************
4638
4639
4640//*************************************************************************************************
4652template< typename MT // Type of the sparse matrix
4653 , AlignmentFlag AF // Alignment flag
4654 , size_t... CSAs > // Compile time submatrix arguments
4655template< typename MT2 // Type of the right-hand side dense matrix
4656 , bool SO > // Storage order of the right-hand side dense matrix
4657inline void Submatrix<MT,AF,true,false,CSAs...>::assign( const DenseMatrix<MT2,SO>& rhs )
4658{
4659 BLAZE_INTERNAL_ASSERT( rows() == (*rhs).rows() , "Invalid number of rows" );
4660 BLAZE_INTERNAL_ASSERT( columns() == (*rhs).columns(), "Invalid number of columns" );
4661
4662 reserve( 0UL, rows() * columns() );
4663
4664 for( size_t j=0UL; j<columns(); ++j ) {
4665 for( size_t i=0UL; i<rows(); ++i ) {
4666 if( IsSymmetric_v<MT> || IsHermitian_v<MT> ) {
4667 const ElementType& value( (*rhs)(i,j) );
4668 if( !isDefault<strict>( value ) )
4669 set( i, j, value );
4670 }
4671 else {
4672 append( i, j, (*rhs)(i,j), true );
4673 }
4674 }
4675 finalize( j );
4676 }
4677}
4679//*************************************************************************************************
4680
4681
4682//*************************************************************************************************
4694template< typename MT // Type of the sparse matrix
4695 , AlignmentFlag AF // Alignment flag
4696 , size_t... CSAs > // Compile time submatrix arguments
4697template< typename MT2 > // Type of the right-hand side sparse matrix
4698inline void Submatrix<MT,AF,true,false,CSAs...>::assign( const SparseMatrix<MT2,true>& rhs )
4699{
4700 BLAZE_INTERNAL_ASSERT( rows() == (*rhs).rows() , "Invalid number of rows" );
4701 BLAZE_INTERNAL_ASSERT( columns() == (*rhs).columns(), "Invalid number of columns" );
4702
4703 reserve( 0UL, (*rhs).nonZeros() );
4704
4705 for( size_t j=0UL; j<(*rhs).columns(); ++j ) {
4706 for( ConstIterator_t<MT2> element=(*rhs).begin(j); element!=(*rhs).end(j); ++element ) {
4707 if( IsSymmetric_v<MT> || IsHermitian_v<MT> ) {
4708 const ElementType& value( element->value() );
4709 if( !isDefault<strict>( value ) )
4710 set( element->index(), j, value );
4711 }
4712 else
4713 append( element->index(), j, element->value(), true );
4714 }
4715 finalize( j );
4716 }
4717}
4719//*************************************************************************************************
4720
4721
4722//*************************************************************************************************
4734template< typename MT // Type of the sparse matrix
4735 , AlignmentFlag AF // Alignment flag
4736 , size_t... CSAs > // Compile time submatrix arguments
4737template< typename MT2 > // Type of the right-hand side sparse matrix
4738inline void Submatrix<MT,AF,true,false,CSAs...>::assign( const SparseMatrix<MT2,false>& rhs )
4739{
4741
4742 BLAZE_INTERNAL_ASSERT( rows() == (*rhs).rows() , "Invalid number of rows" );
4743 BLAZE_INTERNAL_ASSERT( columns() == (*rhs).columns(), "Invalid number of columns" );
4744
4745 // Counting the number of elements per column
4746 std::vector<size_t> columnLengths( columns(), 0UL );
4747 for( size_t i=0UL; i<rows(); ++i ) {
4748 for( auto element=(*rhs).begin(i); element!=(*rhs).end(i); ++element )
4749 ++columnLengths[element->index()];
4750 }
4751
4752 // Resizing the sparse matrix
4753 for( size_t j=0UL; j<columns(); ++j ) {
4754 reserve( j, columnLengths[j] );
4755 }
4756
4757 // Appending the elements to the columns of the sparse matrix
4758 for( size_t i=0UL; i<rows(); ++i ) {
4759 for( auto element=(*rhs).begin(i); element!=(*rhs).end(i); ++element )
4760 if( IsSymmetric_v<MT> || IsHermitian_v<MT> ) {
4761 const ElementType& value( element->value() );
4762 if( !isDefault<strict>( value ) )
4763 set( i, element->index(), value );
4764 }
4765 else {
4766 append( i, element->index(), element->value(), true );
4767 }
4768 }
4769}
4771//*************************************************************************************************
4772
4773
4774//*************************************************************************************************
4786template< typename MT // Type of the sparse matrix
4787 , AlignmentFlag AF // Alignment flag
4788 , size_t... CSAs > // Compile time submatrix arguments
4789template< typename MT2 // Type of the right-hand side matrix
4790 , bool SO > // Storage order of the right-hand side matrix
4791inline void Submatrix<MT,AF,true,false,CSAs...>::addAssign( const Matrix<MT2,SO>& rhs )
4792{
4793 using AddType = AddTrait_t< ResultType, ResultType_t<MT2> >;
4794
4796
4797 BLAZE_INTERNAL_ASSERT( rows() == (*rhs).rows() , "Invalid number of rows" );
4798 BLAZE_INTERNAL_ASSERT( columns() == (*rhs).columns(), "Invalid number of columns" );
4799
4800 const AddType tmp( serial( *this + (*rhs) ) );
4801 reset();
4802 assign( tmp );
4803}
4805//*************************************************************************************************
4806
4807
4808//*************************************************************************************************
4820template< typename MT // Type of the sparse matrix
4821 , AlignmentFlag AF // Alignment flag
4822 , size_t... CSAs > // Compile time submatrix arguments
4823template< typename MT2 // Type of the right-hand side matrix
4824 , bool SO > // Storage order of the right-hand side matrix
4825inline void Submatrix<MT,AF,true,false,CSAs...>::subAssign( const Matrix<MT2,SO>& rhs )
4826{
4827 using SubType = SubTrait_t< ResultType, ResultType_t<MT2> >;
4828
4830
4831 BLAZE_INTERNAL_ASSERT( rows() == (*rhs).rows() , "Invalid number of rows" );
4832 BLAZE_INTERNAL_ASSERT( columns() == (*rhs).columns(), "Invalid number of columns" );
4833
4834 const SubType tmp( serial( *this - (*rhs) ) );
4835 reset();
4836 assign( tmp );
4837}
4839//*************************************************************************************************
4840
4841
4842//*************************************************************************************************
4854template< typename MT // Type of the sparse matrix
4855 , AlignmentFlag AF // Alignment flag
4856 , size_t... CSAs > // Compile time submatrix arguments
4857template< typename MT2 // Type of the right-hand side matrix
4858 , bool SO > // Storage order of the right-hand side matrix
4859inline void Submatrix<MT,AF,true,false,CSAs...>::schurAssign( const Matrix<MT2,SO>& rhs )
4860{
4861 using SchurType = SchurTrait_t< ResultType, ResultType_t<MT2> >;
4862
4864
4865 BLAZE_INTERNAL_ASSERT( rows() == (*rhs).rows() , "Invalid number of rows" );
4866 BLAZE_INTERNAL_ASSERT( columns() == (*rhs).columns(), "Invalid number of columns" );
4867
4868 const SchurType tmp( serial( *this % (*rhs) ) );
4869 reset();
4870 assign( tmp );
4871}
4873//*************************************************************************************************
4874
4875} // namespace blaze
4876
4877#endif
Header file for the addition trait.
Header file for auxiliary alias declarations.
Header file for the alignment flag enumeration.
Header file for run time assertion macros.
Header file for the blaze::checked and blaze::unchecked instances.
Constraints on the storage order of matrix types.
constexpr const DenseIterator< Type, AF > operator-(const DenseIterator< Type, AF > &it, ptrdiff_t inc) noexcept
Subtraction between a DenseIterator and an integral value.
Definition: DenseIterator.h:751
Header file for the If class template.
Header file for the IsConst type trait.
Header file for the isDefault shim.
Header file for the IsExpression type trait class.
Header file for the IsHermitian type trait.
Header file for the IsLower type trait.
Header file for the IsReference type trait.
Header file for the IsStrictlyLower type trait.
Header file for the IsStrictlyUpper type trait.
Header file for the IsSymmetric type trait.
Header file for the IsUniLower type trait.
Header file for the IsUniUpper type trait.
Header file for the IsUpper type trait.
Constraint on the data type.
Constraint on the data type.
Constraints on the storage order of matrix types.
Header file for the Schur product trait.
Header file for the subtraction trait.
Header file for the implementation of the SubmatrixData class template.
Header file for the submatrix trait.
Constraint on the data type.
Constraint on the data type.
Initializer list type of the Blaze library.
Pointer difference type of the Blaze library.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Header file for the implementation of a matrix representation of an initializer list.
Header file for the SparseMatrix base class.
Header file for the View base class.
decltype(auto) column(Matrix< MT, SO > &matrix, RCAs... args)
Creating a view on a specific column of the given matrix.
Definition: Column.h:137
#define BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE(T)
Constraint on the data type.
Definition: Pointer.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.
Definition: Reference.h:79
auto operator/=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsScalar_v< ST >, MT & >
Division assignment operator for the division of a dense matrix by a scalar value ( ).
Definition: DenseMatrix.h:574
decltype(auto) transIf(const DenseMatrix< MT, SO > &dm)
Conditional calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:832
decltype(auto) min(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise minimum of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1339
decltype(auto) max(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise maximum of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1375
decltype(auto) ctrans(const DenseMatrix< MT, SO > &dm)
Returns the conjugate transpose matrix of dm.
Definition: DMatMapExpr.h:1501
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:766
auto operator+=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsScalar_v< ST >, MT & >
Addition assignment operator for the addition of a dense matrix and a scalar value ( ).
Definition: DenseMatrix.h:386
auto operator*=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsScalar_v< ST >, MT & >
Multiplication assignment operator for the multiplication of a dense matrix and a scalar value ( ).
Definition: DenseMatrix.h:510
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:812
decltype(auto) operator*(const DenseMatrix< MT1, false > &lhs, const DenseMatrix< MT2, false > &rhs)
Multiplication operator for the multiplication of two row-major dense matrices ( ).
Definition: DMatDMatMultExpr.h:9640
auto operator-=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsScalar_v< ST >, MT & >
Subtraction assignment operator for the subtraction of a dense matrix and a scalar value ( ).
Definition: DenseMatrix.h:448
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:207
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Symmetric.h:79
#define BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.
Definition: RowMajorMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.
Definition: RequiresEvaluation.h:81
#define BLAZE_CONSTRAINT_MUST_NOT_BE_TRANSEXPR_TYPE(T)
Constraint on the data type.
Definition: TransExpr.h:81
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SUBMATRIX_TYPE(T)
Constraint on the data type.
Definition: Submatrix.h:81
#define BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE(T)
Constraint on the data type.
Definition: Computation.h:81
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: SparseMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_NOT_BE_UNITRIANGULAR_MATRIX_TYPE(T)
Constraint on the data type.
Definition: UniTriangular.h:81
#define BLAZE_CONSTRAINT_MUST_BE_COLUMN_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.
Definition: ColumnMajorMatrix.h:61
typename SubmatrixTrait< MT, CSAs... >::Type SubmatrixTrait_t
Auxiliary alias declaration for the SubmatrixTrait type trait.
Definition: SubmatrixTrait.h:145
constexpr bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:253
AlignmentFlag
Alignment flag for (un-)aligned vectors and matrices.
Definition: AlignmentFlag.h:63
constexpr bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:293
MT::ConstIterator cend(const Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:628
constexpr size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:644
size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:730
MT::ConstIterator cbegin(const Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:562
size_t capacity(const Matrix< MT, SO > &matrix) noexcept
Returns the maximum capacity of the matrix.
Definition: Matrix.h:692
constexpr void reset(Matrix< MT, SO > &matrix)
Resetting the given matrix.
Definition: Matrix.h:806
constexpr size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:660
MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:584
void ctranspose(Matrix< MT, SO > &matrix)
In-place conjugate transpose of the given matrix.
Definition: Matrix.h:1221
MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:518
void transpose(Matrix< MT, SO > &matrix)
In-place transpose of the given matrix.
Definition: Matrix.h:1195
decltype(auto) row(Matrix< MT, SO > &, RRAs...)
Creating a view on a specific row of the given matrix.
Definition: Row.h:137
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.
Definition: Assert.h:101
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.
Definition: Assert.h:117
BLAZE_ALWAYS_INLINE const EnableIf_t< IsIntegral_v< T > &&HasSize_v< T, 1UL >, If_t< IsSigned_v< T >, SIMDint8, SIMDuint8 > > set(T value) noexcept
Sets all values in the vector to the given 1-byte integral value.
Definition: Set.h:75
MT::Iterator upperBound(SparseMatrix< MT, SO > &sm, size_t i, size_t j)
Returns an iterator to the first index greater than the given index.
Definition: SparseMatrix.h:244
MT::Iterator lowerBound(SparseMatrix< MT, SO > &sm, size_t i, size_t j)
Returns an iterator to the first index not less than the given index.
Definition: SparseMatrix.h:194
MT::Iterator find(SparseMatrix< MT, SO > &sm, size_t i, size_t j)
Searches for a specific matrix element.
Definition: SparseMatrix.h:144
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.
Definition: Exception.h:331
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.
Definition: Exception.h:235
#define BLAZE_THROW_LOGIC_ERROR(MESSAGE)
Macro for the emission of a std::logic_error exception.
Definition: Exception.h:187
constexpr bool isChecked(const Ts &... args)
Extracting blaze::Check arguments from a given list of arguments.
Definition: Check.h:225
Header file for the exception macros of the math module.
Header file for the extended initializer_list functionality.
Header file for the matrix storage order types.
Header file for the reset shim.
Header file for the serial shim.
Header file for the SparseElement base class.
Header file for basic type definitions.
Header file for the generic max algorithm.
Header file for the generic min algorithm.
Header file for the implementation of the Submatrix base template.