Blaze 3.9
Dense.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_ADAPTORS_DIAGONALMATRIX_DENSE_H_
36#define _BLAZE_MATH_ADAPTORS_DIAGONALMATRIX_DENSE_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <iterator>
44#include <utility>
47#include <blaze/math/Aliases.h>
77#include <blaze/system/Inline.h>
78#include <blaze/util/Assert.h>
84#include <blaze/util/EnableIf.h>
87#include <blaze/util/mpl/If.h>
89#include <blaze/util/Types.h>
93
94
95namespace blaze {
96
97//=================================================================================================
98//
99// CLASS TEMPLATE SPECIALIZATION FOR DENSE MATRICES
100//
101//=================================================================================================
102
103//*************************************************************************************************
111template< typename MT // Type of the adapted dense matrix
112 , bool SO > // Storage order of the adapted dense matrix
113class DiagonalMatrix<MT,SO,true>
114 : public DenseMatrix< DiagonalMatrix<MT,SO,true>, SO >
115{
116 private:
117 //**Type definitions****************************************************************************
118 using OT = OppositeType_t<MT>;
119 using TT = TransposeType_t<MT>;
120 using ET = ElementType_t<MT>;
121 //**********************************************************************************************
122
123 public:
124 //**Type definitions****************************************************************************
125 using This = DiagonalMatrix<MT,SO,true>;
126 using BaseType = DenseMatrix<This,SO>;
127 using ResultType = This;
128 using OppositeType = DiagonalMatrix<OT,!SO,true>;
129 using TransposeType = DiagonalMatrix<TT,!SO,true>;
130 using ElementType = ET;
131 using SIMDType = SIMDType_t<MT>;
132 using TagType = TagType_t<MT>;
133 using ReturnType = ReturnType_t<MT>;
134 using CompositeType = const This&;
135 using Reference = DiagonalProxy<MT>;
136 using ConstReference = ConstReference_t<MT>;
137 using Pointer = Pointer_t<MT>;
138 using ConstPointer = ConstPointer_t<MT>;
139 using ConstIterator = ConstIterator_t<MT>;
140 //**********************************************************************************************
141
142 //**Rebind struct definition********************************************************************
145 template< typename NewType > // Data type of the other matrix
146 struct Rebind {
148 using Other = DiagonalMatrix< typename MT::template Rebind<NewType>::Other >;
149 };
150 //**********************************************************************************************
151
152 //**Resize struct definition********************************************************************
155 template< size_t NewM // Number of rows of the other matrix
156 , size_t NewN > // Number of columns of the other matrix
157 struct Resize {
159 using Other = DiagonalMatrix< typename MT::template Resize<NewM,NewN>::Other >;
160 };
161 //**********************************************************************************************
162
163 //**Iterator class definition*******************************************************************
166 class Iterator
167 {
168 public:
169 //**Type definitions*************************************************************************
170 using IteratorCategory = std::random_access_iterator_tag;
171 using ValueType = ElementType_t<MT>;
172 using PointerType = DiagonalProxy<MT>;
173 using ReferenceType = DiagonalProxy<MT>;
174 using DifferenceType = ptrdiff_t;
175
176 // STL iterator requirements
177 using iterator_category = IteratorCategory;
178 using value_type = ValueType;
179 using pointer = PointerType;
180 using reference = ReferenceType;
181 using difference_type = DifferenceType;
182 //*******************************************************************************************
183
184 //**Constructor******************************************************************************
187 inline Iterator() noexcept
188 : matrix_( nullptr ) // Reference to the adapted dense matrix
189 , row_ ( 0UL ) // The current row index of the iterator
190 , column_( 0UL ) // The current column index of the iterator
191 {}
192 //*******************************************************************************************
193
194 //**Constructor******************************************************************************
201 inline Iterator( MT& matrix, size_t row, size_t column ) noexcept
202 : matrix_( &matrix ) // Reference to the adapted dense matrix
203 , row_ ( row ) // The current row-index of the iterator
204 , column_( column ) // The current column-index of the iterator
205 {}
206 //*******************************************************************************************
207
208 //**Addition assignment operator*************************************************************
214 inline Iterator& operator+=( size_t inc ) noexcept {
215 ( SO )?( row_ += inc ):( column_ += inc );
216 return *this;
217 }
218 //*******************************************************************************************
219
220 //**Subtraction assignment operator**********************************************************
226 inline Iterator& operator-=( size_t dec ) noexcept {
227 ( SO )?( row_ -= dec ):( column_ -= dec );
228 return *this;
229 }
230 //*******************************************************************************************
231
232 //**Prefix increment operator****************************************************************
237 inline Iterator& operator++() noexcept {
238 ( SO )?( ++row_ ):( ++column_ );
239 return *this;
240 }
241 //*******************************************************************************************
242
243 //**Postfix increment operator***************************************************************
248 inline const Iterator operator++( int ) noexcept {
249 const Iterator tmp( *this );
250 ++(*this);
251 return tmp;
252 }
253 //*******************************************************************************************
254
255 //**Prefix decrement operator****************************************************************
260 inline Iterator& operator--() noexcept {
261 ( SO )?( --row_ ):( --column_ );
262 return *this;
263 }
264 //*******************************************************************************************
265
266 //**Postfix decrement operator***************************************************************
271 inline const Iterator operator--( int ) noexcept {
272 const Iterator tmp( *this );
273 --(*this);
274 return tmp;
275 }
276 //*******************************************************************************************
277
278 //**Element access operator******************************************************************
283 inline ReferenceType operator*() const {
284 return ReferenceType( *matrix_, row_, column_ );
285 }
286 //*******************************************************************************************
287
288 //**Element access operator******************************************************************
293 inline PointerType operator->() const {
294 return PointerType( *matrix_, row_, column_ );
295 }
296 //*******************************************************************************************
297
298 //**Load function****************************************************************************
308 inline SIMDType load() const {
309 return (*matrix_).load(row_,column_);
310 }
311 //*******************************************************************************************
312
313 //**Loada function***************************************************************************
323 inline SIMDType loada() const {
324 return (*matrix_).loada(row_,column_);
325 }
326 //*******************************************************************************************
327
328 //**Loadu function***************************************************************************
338 inline SIMDType loadu() const {
339 return (*matrix_).loadu(row_,column_);
340 }
341 //*******************************************************************************************
342
343 //**Conversion operator**********************************************************************
348 inline operator ConstIterator() const {
349 if( SO )
350 return matrix_->begin( column_ ) + row_;
351 else
352 return matrix_->begin( row_ ) + column_;
353 }
354 //*******************************************************************************************
355
356 //**Equality operator************************************************************************
363 friend inline bool operator==( const Iterator& lhs, const Iterator& rhs ) noexcept {
364 return ( SO )?( lhs.row_ == rhs.row_ ):( lhs.column_ == rhs.column_ );
365 }
366 //*******************************************************************************************
367
368 //**Equality operator************************************************************************
375 friend inline bool operator==( const Iterator& lhs, const ConstIterator& rhs ) {
376 return ( ConstIterator( lhs ) == rhs );
377 }
378 //*******************************************************************************************
379
380 //**Equality operator************************************************************************
387 friend inline bool operator==( const ConstIterator& lhs, const Iterator& rhs ) {
388 return ( lhs == ConstIterator( rhs ) );
389 }
390 //*******************************************************************************************
391
392 //**Inequality operator**********************************************************************
399 friend inline bool operator!=( const Iterator& lhs, const Iterator& rhs ) noexcept {
400 return ( SO )?( lhs.row_ != rhs.row_ ):( lhs.column_ != rhs.column_ );
401 }
402 //*******************************************************************************************
403
404 //**Inequality operator**********************************************************************
411 friend inline bool operator!=( const Iterator& lhs, const ConstIterator& rhs ) {
412 return ( ConstIterator( lhs ) != rhs );
413 }
414 //*******************************************************************************************
415
416 //**Inequality operator**********************************************************************
423 friend inline bool operator!=( const ConstIterator& lhs, const Iterator& rhs ) {
424 return ( lhs != ConstIterator( rhs ) );
425 }
426 //*******************************************************************************************
427
428 //**Less-than operator***********************************************************************
435 friend inline bool operator<( const Iterator& lhs, const Iterator& rhs ) noexcept {
436 return ( SO )?( lhs.row_ < rhs.row_ ):( lhs.column_ < rhs.column_ );
437 }
438 //*******************************************************************************************
439
440 //**Less-than operator***********************************************************************
447 friend inline bool operator<( const Iterator& lhs, const ConstIterator& rhs ) {
448 return ( ConstIterator( lhs ) < rhs );
449 }
450 //*******************************************************************************************
451
452 //**Less-than operator***********************************************************************
459 friend inline bool operator<( const ConstIterator& lhs, const Iterator& rhs ) {
460 return ( lhs < ConstIterator( rhs ) );
461 }
462 //*******************************************************************************************
463
464 //**Greater-than operator********************************************************************
471 friend inline bool operator>( const Iterator& lhs, const Iterator& rhs ) noexcept {
472 return ( SO )?( lhs.row_ > rhs.row_ ):( lhs.column_ > rhs.column_ );
473 }
474 //*******************************************************************************************
475
476 //**Greater-than operator********************************************************************
483 friend inline bool operator>( const Iterator& lhs, const ConstIterator& rhs ) {
484 return ( ConstIterator( lhs ) > rhs );
485 }
486 //*******************************************************************************************
487
488 //**Greater-than operator********************************************************************
495 friend inline bool operator>( const ConstIterator& lhs, const Iterator& rhs ) {
496 return ( lhs > ConstIterator( rhs ) );
497 }
498 //*******************************************************************************************
499
500 //**Less-or-equal-than operator**************************************************************
507 friend inline bool operator<=( const Iterator& lhs, const Iterator& rhs ) noexcept {
508 return ( SO )?( lhs.row_ <= rhs.row_ ):( lhs.column_ <= rhs.column_ );
509 }
510 //*******************************************************************************************
511
512 //**Less-or-equal-than operator**************************************************************
519 friend inline bool operator<=( const Iterator& lhs, const ConstIterator& rhs ) {
520 return ( ConstIterator( lhs ) <= rhs );
521 }
522 //*******************************************************************************************
523
524 //**Less-or-equal-than operator**************************************************************
531 friend inline bool operator<=( const ConstIterator& lhs, const Iterator& rhs ) {
532 return ( lhs <= ConstIterator( rhs ) );
533 }
534 //*******************************************************************************************
535
536 //**Greater-or-equal-than operator***********************************************************
543 friend inline bool operator>=( const Iterator& lhs, const Iterator& rhs ) noexcept {
544 return ( SO )?( lhs.row_ >= rhs.row_ ):( lhs.column_ >= rhs.column_ );
545 }
546 //*******************************************************************************************
547
548 //**Greater-or-equal-than operator***********************************************************
555 friend inline bool operator>=( const Iterator& lhs, const ConstIterator& rhs ) {
556 return ( ConstIterator( lhs ) >= rhs );
557 }
558 //*******************************************************************************************
559
560 //**Greater-or-equal-than operator***********************************************************
567 friend inline bool operator>=( const ConstIterator& lhs, const Iterator& rhs ) {
568 return ( lhs >= ConstIterator( rhs ) );
569 }
570 //*******************************************************************************************
571
572 //**Subtraction operator*********************************************************************
578 inline DifferenceType operator-( const Iterator& rhs ) const noexcept {
579 return ( SO )?( row_ - rhs.row_ ):( column_ - rhs.column_ );
580 }
581 //*******************************************************************************************
582
583 //**Addition operator************************************************************************
590 friend inline const Iterator operator+( const Iterator& it, size_t inc ) noexcept {
591 if( SO )
592 return Iterator( *it.matrix_, it.row_ + inc, it.column_ );
593 else
594 return Iterator( *it.matrix_, it.row_, it.column_ + inc );
595 }
596 //*******************************************************************************************
597
598 //**Addition operator************************************************************************
605 friend inline const Iterator operator+( size_t inc, const Iterator& it ) noexcept {
606 if( SO )
607 return Iterator( *it.matrix_, it.row_ + inc, it.column_ );
608 else
609 return Iterator( *it.matrix_, it.row_, it.column_ + inc );
610 }
611 //*******************************************************************************************
612
613 //**Subtraction operator*********************************************************************
620 friend inline const Iterator operator-( const Iterator& it, size_t dec ) noexcept {
621 if( SO )
622 return Iterator( *it.matrix_, it.row_ - dec, it.column_ );
623 else
624 return Iterator( *it.matrix_, it.row_, it.column_ - dec );
625 }
626 //*******************************************************************************************
627
628 private:
629 //**Member variables*************************************************************************
630 MT* matrix_;
631 size_t row_;
632 size_t column_;
633 //*******************************************************************************************
634 };
635 //**********************************************************************************************
636
637 //**Compilation flags***************************************************************************
639 static constexpr bool simdEnabled = MT::simdEnabled;
640
642 static constexpr bool smpAssignable = MT::smpAssignable;
643 //**********************************************************************************************
644
645 //**Constructors********************************************************************************
648 inline DiagonalMatrix();
649 template< typename A1 > explicit inline DiagonalMatrix( const A1& a1 );
650 inline DiagonalMatrix( size_t n, const ElementType& init );
651
652 inline DiagonalMatrix( initializer_list< initializer_list<ElementType> > list );
653
654 template< typename Other >
655 inline DiagonalMatrix( size_t n, const Other* array );
656
657 template< typename Other, size_t N >
658 inline DiagonalMatrix( const Other (&array)[N][N] );
659
660 inline DiagonalMatrix( ElementType* ptr, size_t n );
661 inline DiagonalMatrix( ElementType* ptr, size_t n, size_t nn );
662
663 inline DiagonalMatrix( const DiagonalMatrix& m );
664 inline DiagonalMatrix( DiagonalMatrix&& m ) noexcept;
666 //**********************************************************************************************
667
668 //**Destructor**********************************************************************************
671 ~DiagonalMatrix() = default;
673 //**********************************************************************************************
674
675 //**Data access functions***********************************************************************
678 inline Reference operator()( size_t i, size_t j );
679 inline ConstReference operator()( size_t i, size_t j ) const;
680 inline Reference at( size_t i, size_t j );
681 inline ConstReference at( size_t i, size_t j ) const;
682 inline ConstPointer data () const noexcept;
683 inline ConstPointer data ( size_t i ) const noexcept;
684 inline Iterator begin ( size_t i );
685 inline ConstIterator begin ( size_t i ) const;
686 inline ConstIterator cbegin( size_t i ) const;
687 inline Iterator end ( size_t i );
688 inline ConstIterator end ( size_t i ) const;
689 inline ConstIterator cend ( size_t i ) const;
691 //**********************************************************************************************
692
693 //**Assignment operators************************************************************************
696 inline DiagonalMatrix& operator=( const ElementType& rhs );
697 inline DiagonalMatrix& operator=( initializer_list< initializer_list<ElementType> > list );
698
699 template< typename Other, size_t N >
700 inline DiagonalMatrix& operator=( const Other (&array)[N][N] );
701
702 inline DiagonalMatrix& operator=( const DiagonalMatrix& rhs );
703 inline DiagonalMatrix& operator=( DiagonalMatrix&& rhs ) noexcept;
704
705 template< typename MT2, bool SO2 >
706 inline auto operator=( const Matrix<MT2,SO2>& rhs )
707 -> DisableIf_t< IsComputation_v<MT2>, DiagonalMatrix& >;
708
709 template< typename MT2, bool SO2 >
710 inline auto operator=( const Matrix<MT2,SO2>& rhs )
711 -> EnableIf_t< IsComputation_v<MT2>, DiagonalMatrix& >;
712
713 template< typename MT2, bool SO2 >
714 inline auto operator+=( const Matrix<MT2,SO2>& rhs )
715 -> DisableIf_t< IsComputation_v<MT2>, DiagonalMatrix& >;
716
717 template< typename MT2, bool SO2 >
718 inline auto operator+=( const Matrix<MT2,SO2>& rhs )
719 -> EnableIf_t< IsComputation_v<MT2>, DiagonalMatrix& >;
720
721 template< typename MT2, bool SO2 >
722 inline auto operator-=( const Matrix<MT2,SO2>& rhs )
723 -> DisableIf_t< IsComputation_v<MT2>, DiagonalMatrix& >;
724
725 template< typename MT2, bool SO2 >
726 inline auto operator-=( const Matrix<MT2,SO2>& rhs )
727 -> EnableIf_t< IsComputation_v<MT2>, DiagonalMatrix& >;
728
729 template< typename MT2, bool SO2 >
730 inline auto operator%=( const Matrix<MT2,SO2>& rhs ) -> DiagonalMatrix&;
731
732 template< typename ST >
733 inline auto operator*=( ST rhs ) -> EnableIf_t< IsScalar_v<ST>, DiagonalMatrix& >;
734
735 template< typename ST >
736 inline auto operator/=( ST rhs ) -> EnableIf_t< IsScalar_v<ST>, DiagonalMatrix& >;
738 //**********************************************************************************************
739
740 //**Utility functions***************************************************************************
743 inline size_t rows() const noexcept;
744 inline size_t columns() const noexcept;
745 inline size_t spacing() const noexcept;
746 inline size_t capacity() const noexcept;
747 inline size_t capacity( size_t i ) const noexcept;
748 inline size_t nonZeros() const;
749 inline size_t nonZeros( size_t i ) const;
750 inline void reset();
751 inline void reset( size_t i );
752 inline void clear();
753 void resize ( size_t n, bool preserve=true );
754 inline void extend ( size_t n, bool preserve=true );
755 inline void reserve( size_t elements );
756 inline void shrinkToFit();
757 inline void swap( DiagonalMatrix& m ) noexcept;
759 //**********************************************************************************************
760
761 //**Numeric functions***************************************************************************
764 template< typename Other > inline DiagonalMatrix& scale( const Other& scalar );
766 //**********************************************************************************************
767
768 //**Debugging functions*************************************************************************
771 inline bool isIntact() const noexcept;
773 //**********************************************************************************************
774
775 //**Expression template evaluation functions****************************************************
778 template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
779 template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
780
781 inline bool isAligned () const noexcept;
782 inline bool canSMPAssign() const noexcept;
783
784 BLAZE_ALWAYS_INLINE SIMDType load ( size_t i, size_t j ) const noexcept;
785 BLAZE_ALWAYS_INLINE SIMDType loada( size_t i, size_t j ) const noexcept;
786 BLAZE_ALWAYS_INLINE SIMDType loadu( size_t i, size_t j ) const noexcept;
788 //**********************************************************************************************
789
790 private:
791 //**Construction functions**********************************************************************
794 inline const MT construct( size_t n , TrueType );
795 inline const MT construct( const ElementType& value, FalseType );
796
797 template< typename MT2, bool SO2, typename T >
798 inline const MT construct( const Matrix<MT2,SO2>& m, T );
800 //**********************************************************************************************
801
802 //**Member variables****************************************************************************
805 MT matrix_;
807 //**********************************************************************************************
808
809 //**Friend declarations*************************************************************************
810 template< typename MT2, bool SO2, bool DF2 >
811 friend MT2& derestrict( DiagonalMatrix<MT2,SO2,DF2>& m );
812 //**********************************************************************************************
813
814 //**Compile time checks*************************************************************************
829 BLAZE_STATIC_ASSERT( ( Size_v<MT,0UL> == Size_v<MT,1UL> ) );
830 //**********************************************************************************************
831};
833//*************************************************************************************************
834
835
836
837
838//=================================================================================================
839//
840// CONSTRUCTORS
841//
842//=================================================================================================
843
844//*************************************************************************************************
848template< typename MT // Type of the adapted dense matrix
849 , bool SO > // Storage order of the adapted dense matrix
850inline DiagonalMatrix<MT,SO,true>::DiagonalMatrix()
851 : matrix_() // The adapted dense matrix
852{
853 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
854 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
855}
857//*************************************************************************************************
858
859
860//*************************************************************************************************
878template< typename MT // Type of the adapted dense matrix
879 , bool SO > // Storage order of the adapted dense matrix
880template< typename A1 > // Type of the constructor argument
881inline DiagonalMatrix<MT,SO,true>::DiagonalMatrix( const A1& a1 )
882 : matrix_( construct( a1, IsResizable<MT>() ) ) // The adapted dense matrix
883{
884 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
885 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
886}
888//*************************************************************************************************
889
890
891//*************************************************************************************************
898template< typename MT // Type of the adapted dense matrix
899 , bool SO > // Storage order of the adapted dense matrix
900inline DiagonalMatrix<MT,SO,true>::DiagonalMatrix( size_t n, const ElementType& init )
901 : matrix_( n, n, ElementType() ) // The adapted dense matrix
902{
904
905 for( size_t i=0UL; i<n; ++i )
906 matrix_(i,i) = init;
907
908 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
909 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
910}
912//*************************************************************************************************
913
914
915//*************************************************************************************************
939template< typename MT // Type of the adapted dense matrix
940 , bool SO > // Storage order of the adapted dense matrix
941inline DiagonalMatrix<MT,SO,true>::DiagonalMatrix( initializer_list< initializer_list<ElementType> > list )
942 : matrix_( list ) // The adapted dense matrix
943{
944 if( !isDiagonal( matrix_ ) ) {
945 BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of diagonal matrix" );
946 }
947
948 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
949}
951//*************************************************************************************************
952
953
954//*************************************************************************************************
980template< typename MT // Type of the adapted dense matrix
981 , bool SO > // Storage order of the adapted dense matrix
982template< typename Other > // Data type of the initialization array
983inline DiagonalMatrix<MT,SO,true>::DiagonalMatrix( size_t n, const Other* array )
984 : matrix_( n, n, array ) // The adapted dense matrix
985{
986 if( !isDiagonal( matrix_ ) ) {
987 BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of diagonal matrix" );
988 }
989
990 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
991}
993//*************************************************************************************************
994
995
996//*************************************************************************************************
1019template< typename MT // Type of the adapted dense matrix
1020 , bool SO > // Storage order of the adapted dense matrix
1021template< typename Other // Data type of the initialization array
1022 , size_t N > // Number of rows and columns of the initialization array
1023inline DiagonalMatrix<MT,SO,true>::DiagonalMatrix( const Other (&array)[N][N] )
1024 : matrix_( array ) // The adapted dense matrix
1025{
1026 if( !isDiagonal( matrix_ ) ) {
1027 BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of diagonal matrix" );
1028 }
1029
1030 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1031}
1033//*************************************************************************************************
1034
1035
1036//*************************************************************************************************
1068template< typename MT // Type of the adapted dense matrix
1069 , bool SO > // Storage order of the adapted dense matrix
1070inline DiagonalMatrix<MT,SO,true>::DiagonalMatrix( ElementType* ptr, size_t n )
1071 : matrix_( ptr, n, n ) // The adapted dense matrix
1072{
1073 if( !isDiagonal( matrix_ ) ) {
1074 BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of diagonal matrix" );
1075 }
1076
1077 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1078}
1080//*************************************************************************************************
1081
1082
1083//*************************************************************************************************
1117template< typename MT // Type of the adapted dense matrix
1118 , bool SO > // Storage order of the adapted dense matrix
1119inline DiagonalMatrix<MT,SO,true>::DiagonalMatrix( ElementType* ptr, size_t n, size_t nn )
1120 : matrix_( ptr, n, n, nn ) // The adapted dense matrix
1121{
1122 if( !isDiagonal( matrix_ ) ) {
1123 BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of diagonal matrix" );
1124 }
1125
1126 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1127}
1129//*************************************************************************************************
1130
1131
1132//*************************************************************************************************
1138template< typename MT // Type of the adapted dense matrix
1139 , bool SO > // Storage order of the adapted dense matrix
1140inline DiagonalMatrix<MT,SO,true>::DiagonalMatrix( const DiagonalMatrix& m )
1141 : matrix_( m.matrix_ ) // The adapted dense matrix
1142{
1143 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1144 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1145}
1147//*************************************************************************************************
1148
1149
1150//*************************************************************************************************
1156template< typename MT // Type of the adapted dense matrix
1157 , bool SO > // Storage order of the adapted dense matrix
1158inline DiagonalMatrix<MT,SO,true>::DiagonalMatrix( DiagonalMatrix&& m ) noexcept
1159 : matrix_( std::move( m.matrix_ ) ) // The adapted dense matrix
1160{
1161 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1162 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1163}
1165//*************************************************************************************************
1166
1167
1168
1169
1170//=================================================================================================
1171//
1172// DATA ACCESS FUNCTIONS
1173//
1174//=================================================================================================
1175
1176//*************************************************************************************************
1192template< typename MT // Type of the adapted dense matrix
1193 , bool SO > // Storage order of the adapted dense matrix
1194inline typename DiagonalMatrix<MT,SO,true>::Reference
1195 DiagonalMatrix<MT,SO,true>::operator()( size_t i, size_t j )
1196{
1197 BLAZE_USER_ASSERT( i<rows() , "Invalid row access index" );
1198 BLAZE_USER_ASSERT( j<columns(), "Invalid column access index" );
1199
1200 return Reference( matrix_, i, j );
1201}
1203//*************************************************************************************************
1204
1205
1206//*************************************************************************************************
1222template< typename MT // Type of the adapted dense matrix
1223 , bool SO > // Storage order of the adapted dense matrix
1224inline typename DiagonalMatrix<MT,SO,true>::ConstReference
1225 DiagonalMatrix<MT,SO,true>::operator()( size_t i, size_t j ) const
1226{
1227 BLAZE_USER_ASSERT( i<rows() , "Invalid row access index" );
1228 BLAZE_USER_ASSERT( j<columns(), "Invalid column access index" );
1229
1230 return matrix_(i,j);
1231}
1233//*************************************************************************************************
1234
1235
1236//*************************************************************************************************
1253template< typename MT // Type of the adapted dense matrix
1254 , bool SO > // Storage order of the adapted dense matrix
1255inline typename DiagonalMatrix<MT,SO,true>::Reference
1256 DiagonalMatrix<MT,SO,true>::at( size_t i, size_t j )
1257{
1258 if( i >= rows() ) {
1259 BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
1260 }
1261 if( j >= columns() ) {
1262 BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
1263 }
1264 return (*this)(i,j);
1265}
1267//*************************************************************************************************
1268
1269
1270//*************************************************************************************************
1287template< typename MT // Type of the adapted dense matrix
1288 , bool SO > // Storage order of the adapted dense matrix
1289inline typename DiagonalMatrix<MT,SO,true>::ConstReference
1290 DiagonalMatrix<MT,SO,true>::at( size_t i, size_t j ) const
1291{
1292 if( i >= rows() ) {
1293 BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
1294 }
1295 if( j >= columns() ) {
1296 BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
1297 }
1298 return (*this)(i,j);
1299}
1301//*************************************************************************************************
1302
1303
1304//*************************************************************************************************
1317template< typename MT // Type of the adapted dense matrix
1318 , bool SO > // Storage order of the adapted dense matrix
1319inline typename DiagonalMatrix<MT,SO,true>::ConstPointer
1320 DiagonalMatrix<MT,SO,true>::data() const noexcept
1321{
1322 return matrix_.data();
1323}
1325//*************************************************************************************************
1326
1327
1328//*************************************************************************************************
1337template< typename MT // Type of the adapted dense matrix
1338 , bool SO > // Storage order of the adapted dense matrix
1339inline typename DiagonalMatrix<MT,SO,true>::ConstPointer
1340 DiagonalMatrix<MT,SO,true>::data( size_t i ) const noexcept
1341{
1342 return matrix_.data(i);
1343}
1345//*************************************************************************************************
1346
1347
1348//*************************************************************************************************
1360template< typename MT // Type of the adapted dense matrix
1361 , bool SO > // Storage order of the adapted dense matrix
1362inline typename DiagonalMatrix<MT,SO,true>::Iterator
1364{
1365 if( SO )
1366 return Iterator( matrix_, 0UL, i );
1367 else
1368 return Iterator( matrix_, i, 0UL );
1369}
1371//*************************************************************************************************
1372
1373
1374//*************************************************************************************************
1386template< typename MT // Type of the adapted dense matrix
1387 , bool SO > // Storage order of the adapted dense matrix
1388inline typename DiagonalMatrix<MT,SO,true>::ConstIterator
1389 DiagonalMatrix<MT,SO,true>::begin( size_t i ) const
1390{
1391 return matrix_.begin(i);
1392}
1394//*************************************************************************************************
1395
1396
1397//*************************************************************************************************
1409template< typename MT // Type of the adapted dense matrix
1410 , bool SO > // Storage order of the adapted dense matrix
1411inline typename DiagonalMatrix<MT,SO,true>::ConstIterator
1412 DiagonalMatrix<MT,SO,true>::cbegin( size_t i ) const
1413{
1414 return matrix_.cbegin(i);
1415}
1417//*************************************************************************************************
1418
1419
1420//*************************************************************************************************
1432template< typename MT // Type of the adapted dense matrix
1433 , bool SO > // Storage order of the adapted dense matrix
1434inline typename DiagonalMatrix<MT,SO,true>::Iterator
1436{
1437 if( SO )
1438 return Iterator( matrix_, rows(), i );
1439 else
1440 return Iterator( matrix_, i, columns() );
1441}
1443//*************************************************************************************************
1444
1445
1446//*************************************************************************************************
1458template< typename MT // Type of the adapted dense matrix
1459 , bool SO > // Storage order of the adapted dense matrix
1460inline typename DiagonalMatrix<MT,SO,true>::ConstIterator
1461 DiagonalMatrix<MT,SO,true>::end( size_t i ) const
1462{
1463 return matrix_.end(i);
1464}
1466//*************************************************************************************************
1467
1468
1469//*************************************************************************************************
1481template< typename MT // Type of the adapted dense matrix
1482 , bool SO > // Storage order of the adapted dense matrix
1483inline typename DiagonalMatrix<MT,SO,true>::ConstIterator
1484 DiagonalMatrix<MT,SO,true>::cend( size_t i ) const
1485{
1486 return matrix_.cend(i);
1487}
1489//*************************************************************************************************
1490
1491
1492
1493
1494//=================================================================================================
1495//
1496// ASSIGNMENT OPERATORS
1497//
1498//=================================================================================================
1499
1500//*************************************************************************************************
1507template< typename MT // Type of the adapted dense matrix
1508 , bool SO > // Storage order of the adapted dense matrix
1509inline DiagonalMatrix<MT,SO,true>&
1510 DiagonalMatrix<MT,SO,true>::operator=( const ElementType& rhs )
1511{
1512 for( size_t i=0UL; i<rows(); ++i )
1513 matrix_(i,i) = rhs;
1514
1515 return *this;
1516}
1518//*************************************************************************************************
1519
1520
1521//*************************************************************************************************
1546template< typename MT // Type of the adapted dense matrix
1547 , bool SO > // Storage order of the adapted dense matrix
1548inline DiagonalMatrix<MT,SO,true>&
1549 DiagonalMatrix<MT,SO,true>::operator=( initializer_list< initializer_list<ElementType> > list )
1550{
1551 const InitializerMatrix<ElementType> tmp( list, list.size() );
1552
1553 if( !isDiagonal( tmp ) ) {
1554 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1555 }
1556
1557 matrix_ = list;
1558
1559 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1560 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1561
1562 return *this;
1563}
1565//*************************************************************************************************
1566
1567
1568//*************************************************************************************************
1592template< typename MT // Type of the adapted dense matrix
1593 , bool SO > // Storage order of the adapted dense matrix
1594template< typename Other // Data type of the initialization array
1595 , size_t N > // Number of rows and columns of the initialization array
1596inline DiagonalMatrix<MT,SO,true>&
1597 DiagonalMatrix<MT,SO,true>::operator=( const Other (&array)[N][N] )
1598{
1599 MT tmp( array );
1600
1601 if( !isDiagonal( tmp ) ) {
1602 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1603 }
1604
1605 matrix_ = std::move( tmp );
1606
1607 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1608 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1609
1610 return *this;
1611}
1613//*************************************************************************************************
1614
1615
1616//*************************************************************************************************
1626template< typename MT // Type of the adapted dense matrix
1627 , bool SO > // Storage order of the adapted dense matrix
1628inline DiagonalMatrix<MT,SO,true>&
1629 DiagonalMatrix<MT,SO,true>::operator=( const DiagonalMatrix& rhs )
1630{
1631 matrix_ = rhs.matrix_;
1632
1633 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1634 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1635
1636 return *this;
1637}
1639//*************************************************************************************************
1640
1641
1642//*************************************************************************************************
1649template< typename MT // Type of the adapted dense matrix
1650 , bool SO > // Storage order of the adapted dense matrix
1651inline DiagonalMatrix<MT,SO,true>&
1652 DiagonalMatrix<MT,SO,true>::operator=( DiagonalMatrix&& rhs ) noexcept
1653{
1654 matrix_ = std::move( rhs.matrix_ );
1655
1656 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1657 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1658
1659 return *this;
1660}
1662//*************************************************************************************************
1663
1664
1665//*************************************************************************************************
1678template< typename MT // Type of the adapted dense matrix
1679 , bool SO > // Storage order of the adapted dense matrix
1680template< typename MT2 // Type of the right-hand side matrix
1681 , bool SO2 > // Storage order of the right-hand side matrix
1682inline auto DiagonalMatrix<MT,SO,true>::operator=( const Matrix<MT2,SO2>& rhs )
1683 -> DisableIf_t< IsComputation_v<MT2>, DiagonalMatrix& >
1684{
1685 if( !IsDiagonal_v<MT2> && !isDiagonal( *rhs ) ) {
1686 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1687 }
1688
1689 matrix_ = decldiag( *rhs );
1690
1691 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1692 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1693
1694 return *this;
1695}
1697//*************************************************************************************************
1698
1699
1700//*************************************************************************************************
1713template< typename MT // Type of the adapted dense matrix
1714 , bool SO > // Storage order of the adapted dense matrix
1715template< typename MT2 // Type of the right-hand side matrix
1716 , bool SO2 > // Storage order of the right-hand side matrix
1717inline auto DiagonalMatrix<MT,SO,true>::operator=( const Matrix<MT2,SO2>& rhs )
1718 -> EnableIf_t< IsComputation_v<MT2>, DiagonalMatrix& >
1719{
1720 if( !IsSquare_v<MT2> && !isSquare( *rhs ) ) {
1721 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1722 }
1723
1724 if( IsDiagonal_v<MT2> ) {
1725 matrix_ = *rhs;
1726 }
1727 else {
1728 MT tmp( *rhs );
1729
1730 if( !isDiagonal( tmp ) ) {
1731 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1732 }
1733
1734 matrix_ = std::move( tmp );
1735 }
1736
1737 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1738 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1739
1740 return *this;
1741}
1743//*************************************************************************************************
1744
1745
1746//*************************************************************************************************
1759template< typename MT // Type of the adapted dense matrix
1760 , bool SO > // Storage order of the adapted dense matrix
1761template< typename MT2 // Type of the right-hand side matrix
1762 , bool SO2 > // Storage order of the right-hand side matrix
1763inline auto DiagonalMatrix<MT,SO,true>::operator+=( const Matrix<MT2,SO2>& rhs )
1764 -> DisableIf_t< IsComputation_v<MT2>, DiagonalMatrix& >
1765{
1766 if( !IsDiagonal_v<MT2> && !isDiagonal( *rhs ) ) {
1767 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1768 }
1769
1770 matrix_ += decldiag( *rhs );
1771
1772 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1773 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1774
1775 return *this;
1776}
1778//*************************************************************************************************
1779
1780
1781//*************************************************************************************************
1794template< typename MT // Type of the adapted dense matrix
1795 , bool SO > // Storage order of the adapted dense matrix
1796template< typename MT2 // Type of the right-hand side matrix
1797 , bool SO2 > // Storage order of the right-hand side matrix
1798inline auto DiagonalMatrix<MT,SO,true>::operator+=( const Matrix<MT2,SO2>& rhs )
1799 -> EnableIf_t< IsComputation_v<MT2>, DiagonalMatrix& >
1800{
1801 if( !IsSquare_v<MT2> && !isSquare( *rhs ) ) {
1802 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1803 }
1804
1805 if( IsDiagonal_v<MT2> ) {
1806 matrix_ += *rhs;
1807 }
1808 else {
1809 const ResultType_t<MT2> tmp( *rhs );
1810
1811 if( !isDiagonal( tmp ) ) {
1812 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1813 }
1814
1815 matrix_ += decldiag( tmp );
1816 }
1817
1818 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1819 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1820
1821 return *this;
1822}
1824//*************************************************************************************************
1825
1826
1827//*************************************************************************************************
1840template< typename MT // Type of the adapted dense matrix
1841 , bool SO > // Storage order of the adapted dense matrix
1842template< typename MT2 // Type of the right-hand side matrix
1843 , bool SO2 > // Storage order of the right-hand side matrix
1844inline auto DiagonalMatrix<MT,SO,true>::operator-=( const Matrix<MT2,SO2>& rhs )
1845 -> DisableIf_t< IsComputation_v<MT2>, DiagonalMatrix& >
1846{
1847 if( !IsDiagonal_v<MT2> && !isDiagonal( *rhs ) ) {
1848 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1849 }
1850
1851 matrix_ -= decldiag( *rhs );
1852
1853 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1854 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1855
1856 return *this;
1857}
1859//*************************************************************************************************
1860
1861
1862//*************************************************************************************************
1875template< typename MT // Type of the adapted dense matrix
1876 , bool SO > // Storage order of the adapted dense matrix
1877template< typename MT2 // Type of the right-hand side matrix
1878 , bool SO2 > // Storage order of the right-hand side matrix
1879inline auto DiagonalMatrix<MT,SO,true>::operator-=( const Matrix<MT2,SO2>& rhs )
1880 -> EnableIf_t< IsComputation_v<MT2>, DiagonalMatrix& >
1881{
1882 if( !IsSquare_v<MT2> && !isSquare( *rhs ) ) {
1883 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1884 }
1885
1886 if( IsDiagonal_v<MT2> ) {
1887 matrix_ -= *rhs;
1888 }
1889 else {
1890 const ResultType_t<MT2> tmp( *rhs );
1891
1892 if( !isDiagonal( tmp ) ) {
1893 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1894 }
1895
1896 matrix_ -= decldiag( tmp );
1897 }
1898
1899 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1900 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1901
1902 return *this;
1903}
1905//*************************************************************************************************
1906
1907
1908//*************************************************************************************************
1919template< typename MT // Type of the adapted dense matrix
1920 , bool SO > // Storage order of the adapted dense matrix
1921template< typename MT2 // Type of the right-hand side matrix
1922 , bool SO2 > // Storage order of the right-hand side matrix
1923inline auto DiagonalMatrix<MT,SO,true>::operator%=( const Matrix<MT2,SO2>& rhs )
1924 -> DiagonalMatrix&
1925{
1926 if( !IsSquare_v<MT2> && !isSquare( *rhs ) ) {
1927 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1928 }
1929
1930 matrix_ %= *rhs;
1931
1932 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1933 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1934
1935 return *this;
1936}
1938//*************************************************************************************************
1939
1940
1941//*************************************************************************************************
1949template< typename MT // Type of the adapted dense matrix
1950 , bool SO > // Storage order of the adapted dense matrix
1951template< typename ST > // Data type of the right-hand side scalar
1952inline auto DiagonalMatrix<MT,SO,true>::operator*=( ST scalar )
1953 -> EnableIf_t< IsScalar_v<ST>, DiagonalMatrix& >
1954{
1955 diagonal( matrix_ ) *= scalar;
1956
1957 return *this;
1958}
1960//*************************************************************************************************
1961
1962
1963//*************************************************************************************************
1971template< typename MT // Type of the adapted dense matrix
1972 , bool SO > // Storage order of the adapted dense matrix
1973template< typename ST > // Data type of the right-hand side scalar
1974inline auto DiagonalMatrix<MT,SO,true>::operator/=( ST scalar )
1975 -> EnableIf_t< IsScalar_v<ST>, DiagonalMatrix& >
1976{
1977 diagonal( matrix_ ) /= scalar;
1978
1979 return *this;
1980}
1982//*************************************************************************************************
1983
1984
1985
1986
1987//=================================================================================================
1988//
1989// UTILITY FUNCTIONS
1990//
1991//=================================================================================================
1992
1993//*************************************************************************************************
1999template< typename MT // Type of the adapted dense matrix
2000 , bool SO > // Storage order of the adapted dense matrix
2001inline size_t DiagonalMatrix<MT,SO,true>::rows() const noexcept
2002{
2003 return matrix_.rows();
2004}
2006//*************************************************************************************************
2007
2008
2009//*************************************************************************************************
2015template< typename MT // Type of the adapted dense matrix
2016 , bool SO > // Storage order of the adapted dense matrix
2017inline size_t DiagonalMatrix<MT,SO,true>::columns() const noexcept
2018{
2019 return matrix_.columns();
2020}
2022//*************************************************************************************************
2023
2024
2025//*************************************************************************************************
2036template< typename MT // Type of the adapted dense matrix
2037 , bool SO > // Storage order of the adapted dense matrix
2038inline size_t DiagonalMatrix<MT,SO,true>::spacing() const noexcept
2039{
2040 return matrix_.spacing();
2041}
2043//*************************************************************************************************
2044
2045
2046//*************************************************************************************************
2052template< typename MT // Type of the adapted dense matrix
2053 , bool SO > // Storage order of the adapted dense matrix
2054inline size_t DiagonalMatrix<MT,SO,true>::capacity() const noexcept
2055{
2056 return matrix_.capacity();
2057}
2059//*************************************************************************************************
2060
2061
2062//*************************************************************************************************
2074template< typename MT // Type of the adapted dense matrix
2075 , bool SO > // Storage order of the adapted dense matrix
2076inline size_t DiagonalMatrix<MT,SO,true>::capacity( size_t i ) const noexcept
2077{
2078 return matrix_.capacity(i);
2079}
2081//*************************************************************************************************
2082
2083
2084//*************************************************************************************************
2090template< typename MT // Type of the adapted dense matrix
2091 , bool SO > // Storage order of the adapted dense matrix
2092inline size_t DiagonalMatrix<MT,SO,true>::nonZeros() const
2093{
2094 return matrix_.nonZeros();
2095}
2097//*************************************************************************************************
2098
2099
2100//*************************************************************************************************
2112template< typename MT // Type of the adapted dense matrix
2113 , bool SO > // Storage order of the adapted dense matrix
2114inline size_t DiagonalMatrix<MT,SO,true>::nonZeros( size_t i ) const
2115{
2116 return matrix_.nonZeros(i);
2117}
2119//*************************************************************************************************
2120
2121
2122//*************************************************************************************************
2128template< typename MT // Type of the adapted dense matrix
2129 , bool SO > // Storage order of the adapted dense matrix
2131{
2132 using blaze::clear;
2133
2134 for( size_t i=0UL; i<rows(); ++i )
2135 clear( matrix_(i,i) );
2136}
2138//*************************************************************************************************
2139
2140
2141//*************************************************************************************************
2154template< typename MT // Type of the adapted dense matrix
2155 , bool SO > // Storage order of the adapted dense matrix
2156inline void DiagonalMatrix<MT,SO,true>::reset( size_t i )
2157{
2158 using blaze::clear;
2159
2160 clear( matrix_(i,i) );
2161}
2163//*************************************************************************************************
2164
2165
2166//*************************************************************************************************
2178template< typename MT // Type of the adapted dense matrix
2179 , bool SO > // Storage order of the adapted dense matrix
2181{
2182 matrix_.clear();
2183
2184 BLAZE_INTERNAL_ASSERT( matrix_.rows() == 0UL, "Invalid number of rows" );
2185 BLAZE_INTERNAL_ASSERT( matrix_.columns() == 0UL, "Invalid number of columns" );
2186}
2188//*************************************************************************************************
2189
2190
2191//*************************************************************************************************
2227template< typename MT // Type of the adapted dense matrix
2228 , bool SO > // Storage order of the adapted dense matrix
2229void DiagonalMatrix<MT,SO,true>::resize( size_t n, bool preserve )
2230{
2232
2233 MAYBE_UNUSED( preserve );
2234
2235 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
2236
2237 const size_t oldsize( matrix_.rows() );
2238
2239 matrix_.resize( n, n, true );
2240
2241 if( n > oldsize ) {
2242 const size_t increment( n - oldsize );
2243 submatrix( matrix_, 0UL, oldsize, n, increment ).reset();
2244 submatrix( matrix_, oldsize, 0UL, increment, increment ).reset();
2245 }
2246}
2248//*************************************************************************************************
2249
2250
2251//*************************************************************************************************
2264template< typename MT // Type of the adapted dense matrix
2265 , bool SO > // Storage order of the adapted dense matrix
2266inline void DiagonalMatrix<MT,SO,true>::extend( size_t n, bool preserve )
2267{
2269
2270 MAYBE_UNUSED( preserve );
2271
2272 resize( rows() + n, true );
2273}
2275//*************************************************************************************************
2276
2277
2278//*************************************************************************************************
2288template< typename MT // Type of the adapted dense matrix
2289 , bool SO > // Storage order of the adapted dense matrix
2290inline void DiagonalMatrix<MT,SO,true>::reserve( size_t elements )
2291{
2292 matrix_.reserve( elements );
2293}
2295//*************************************************************************************************
2296
2297
2298//*************************************************************************************************
2308template< typename MT // Type of the adapted dense matrix
2309 , bool SO > // Storage order of the adapted dense matrix
2311{
2312 matrix_.shrinkToFit();
2313}
2315//*************************************************************************************************
2316
2317
2318//*************************************************************************************************
2325template< typename MT // Type of the adapted dense matrix
2326 , bool SO > // Storage order of the adapted dense matrix
2327inline void DiagonalMatrix<MT,SO,true>::swap( DiagonalMatrix& m ) noexcept
2328{
2329 using std::swap;
2330
2331 swap( matrix_, m.matrix_ );
2332}
2334//*************************************************************************************************
2335
2336
2337
2338
2339//=================================================================================================
2340//
2341// NUMERIC FUNCTIONS
2342//
2343//=================================================================================================
2344
2345//*************************************************************************************************
2363template< typename MT // Type of the adapted dense matrix
2364 , bool SO > // Storage order of the adapted dense matrix
2365template< typename Other > // Data type of the scalar value
2366inline DiagonalMatrix<MT,SO,true>& DiagonalMatrix<MT,SO,true>::scale( const Other& scalar )
2367{
2368 matrix_.scale( scalar );
2369 return *this;
2370}
2372//*************************************************************************************************
2373
2374
2375
2376
2377//=================================================================================================
2378//
2379// DEBUGGING FUNCTIONS
2380//
2381//=================================================================================================
2382
2383//*************************************************************************************************
2393template< typename MT // Type of the adapted dense matrix
2394 , bool SO > // Storage order of the adapted dense matrix
2395inline bool DiagonalMatrix<MT,SO,true>::isIntact() const noexcept
2396{
2397 using blaze::isIntact;
2398
2399 return ( isIntact( matrix_ ) && isDiagonal( matrix_ ) );
2400}
2402//*************************************************************************************************
2403
2404
2405
2406
2407//=================================================================================================
2408//
2409// EXPRESSION TEMPLATE EVALUATION FUNCTIONS
2410//
2411//=================================================================================================
2412
2413//*************************************************************************************************
2424template< typename MT // Type of the adapted dense matrix
2425 , bool SO > // Storage order of the adapted dense matrix
2426template< typename Other > // Data type of the foreign expression
2427inline bool DiagonalMatrix<MT,SO,true>::canAlias( const Other* alias ) const noexcept
2428{
2429 return matrix_.canAlias( alias );
2430}
2432//*************************************************************************************************
2433
2434
2435//*************************************************************************************************
2446template< typename MT // Type of the adapted dense matrix
2447 , bool SO > // Storage order of the adapted dense matrix
2448template< typename Other > // Data type of the foreign expression
2449inline bool DiagonalMatrix<MT,SO,true>::isAliased( const Other* alias ) const noexcept
2450{
2451 return matrix_.isAliased( alias );
2452}
2454//*************************************************************************************************
2455
2456
2457//*************************************************************************************************
2467template< typename MT // Type of the adapted dense matrix
2468 , bool SO > // Storage order of the adapted dense matrix
2469inline bool DiagonalMatrix<MT,SO,true>::isAligned() const noexcept
2470{
2471 return matrix_.isAligned();
2472}
2474//*************************************************************************************************
2475
2476
2477//*************************************************************************************************
2488template< typename MT // Type of the adapted dense matrix
2489 , bool SO > // Storage order of the adapted dense matrix
2490inline bool DiagonalMatrix<MT,SO,true>::canSMPAssign() const noexcept
2491{
2492 return matrix_.canSMPAssign();
2493}
2495//*************************************************************************************************
2496
2497
2498//*************************************************************************************************
2514template< typename MT // Type of the adapted dense matrix
2515 , bool SO > // Storage order of the adapted dense matrix
2516BLAZE_ALWAYS_INLINE typename DiagonalMatrix<MT,SO,true>::SIMDType
2517 DiagonalMatrix<MT,SO,true>::load( size_t i, size_t j ) const noexcept
2518{
2519 return matrix_.load( i, j );
2520}
2522//*************************************************************************************************
2523
2524
2525//*************************************************************************************************
2541template< typename MT // Type of the adapted dense matrix
2542 , bool SO > // Storage order of the adapted dense matrix
2543BLAZE_ALWAYS_INLINE typename DiagonalMatrix<MT,SO,true>::SIMDType
2544 DiagonalMatrix<MT,SO,true>::loada( size_t i, size_t j ) const noexcept
2545{
2546 return matrix_.loada( i, j );
2547}
2549//*************************************************************************************************
2550
2551
2552//*************************************************************************************************
2568template< typename MT // Type of the adapted dense matrix
2569 , bool SO > // Storage order of the adapted dense matrix
2570BLAZE_ALWAYS_INLINE typename DiagonalMatrix<MT,SO,true>::SIMDType
2571 DiagonalMatrix<MT,SO,true>::loadu( size_t i, size_t j ) const noexcept
2572{
2573 return matrix_.loadu( i, j );
2574}
2576//*************************************************************************************************
2577
2578
2579
2580
2581//=================================================================================================
2582//
2583// CONSTRUCTION FUNCTIONS
2584//
2585//=================================================================================================
2586
2587//*************************************************************************************************
2594template< typename MT // Type of the adapted dense matrix
2595 , bool SO > // Storage order of the adapted dense matrix
2596inline const MT DiagonalMatrix<MT,SO,true>::construct( size_t n, TrueType )
2597{
2599
2600 return MT( n, n, ElementType() );
2601}
2603//*************************************************************************************************
2604
2605
2606//*************************************************************************************************
2613template< typename MT // Type of the adapted dense matrix
2614 , bool SO > // Storage order of the adapted dense matrix
2615inline const MT DiagonalMatrix<MT,SO,true>::construct( const ElementType& init, FalseType )
2616{
2619
2620 MT tmp;
2621
2622 for( size_t i=0UL; i<tmp.rows(); ++i )
2623 tmp(i,i) = init;
2624
2625 return tmp;
2626}
2628//*************************************************************************************************
2629
2630
2631//*************************************************************************************************
2642template< typename MT // Type of the adapted dense matrix
2643 , bool SO > // Storage order of the adapted dense matrix
2644template< typename MT2 // Type of the foreign matrix
2645 , bool SO2 // Storage order of the foreign matrix
2646 , typename T > // Type of the third argument
2647inline const MT DiagonalMatrix<MT,SO,true>::construct( const Matrix<MT2,SO2>& m, T )
2648{
2649 const MT tmp( *m );
2650
2651 if( !IsDiagonal_v<MT2> && !isDiagonal( tmp ) ) {
2652 BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of diagonal matrix" );
2653 }
2654
2655 return tmp;
2656}
2658//*************************************************************************************************
2659
2660} // namespace blaze
2661
2662#endif
Header file for auxiliary alias declarations.
Header file for run time assertion macros.
Constraint on the data type.
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
constexpr const DenseIterator< Type, AF > operator+(const DenseIterator< Type, AF > &it, ptrdiff_t inc) noexcept
Addition between a DenseIterator and an integral value.
Definition: DenseIterator.h:719
Header file for the DiagonalProxy class.
Header file for the EnableIf class template.
Constraint on the data type.
Header file for the If class template.
Header file for the IntegralConstant class template.
Header file for the IsBuiltin type trait.
Header file for the IsComplex type trait.
Header file for the IsComputation type trait class.
Header file for the isDefault shim.
Header file for the IsDiagonal type trait.
Header file for the IsFloatingPoint type trait.
Header file for the IsInvertible type trait.
Header file for the IsResizable type trait.
Header file for the IsScalar type trait.
Header file for the IsSquare type trait.
Constraint on the data type.
Header file for the MAYBE_UNUSED function template.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Compile time assertion.
Constraint on the data type.
Header file for the UnderlyingBuiltin type trait.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Header file for the implementation of the base template of the DiagonalMatrix.
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.
Header file for utility functions for dense matrices.
Header file for the implementation of a matrix representation of an initializer list.
Header file for the DenseMatrix base class.
decltype(auto) diagonal(Matrix< MT, SO > &matrix, RDAs... args)
Creating a view on the diagonal of the given matrix.
Definition: Band.h:380
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_VOLATILE(T)
Constraint on the data type.
Definition: Volatile.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE(T)
Constraint on the data type.
Definition: Pointer.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.
Definition: Const.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) decldiag(const DenseMatrix< MT, SO > &dm)
Declares the given dense matrix expression dm as diagonal.
Definition: DMatDeclDiagExpr.h:978
MT::ElementType * data(DenseMatrix< MT, SO > &dm) noexcept
Low-level data access to the dense matrix elements.
Definition: DenseMatrix.h:182
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
size_t spacing(const DenseMatrix< MT, SO > &dm) noexcept
Returns the spacing between the beginning of two rows/columns.
Definition: DenseMatrix.h:265
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 isDiagonal(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is diagonal.
Definition: DenseMatrix.h:2456
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:207
void swap(DiagonalMatrix< MT, SO, DF > &a, DiagonalMatrix< MT, SO, DF > &b) noexcept
Swapping the contents of two matrices.
Definition: DiagonalMatrix.h:225
decltype(auto) elements(Vector< VT, TF > &vector, REAs... args)
Creating a view on a selection of elements of the given vector.
Definition: Elements.h:143
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Symmetric.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VIEW_TYPE(T)
Constraint on the data type.
Definition: View.h:81
#define BLAZE_CONSTRAINT_MUST_NOT_BE_HERMITIAN_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Hermitian.h:79
#define BLAZE_CONSTRAINT_MUST_BE_SQUARE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Square.h:60
#define BLAZE_CONSTRAINT_MUST_NOT_BE_UPPER_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Upper.h:81
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: DenseMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE(T)
Constraint on the data type.
Definition: Computation.h:81
#define BLAZE_CONSTRAINT_MUST_NOT_BE_RESIZABLE_TYPE(T)
Constraint on the data type.
Definition: Resizable.h:81
#define BLAZE_CONSTRAINT_MUST_NOT_BE_LOWER_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Lower.h:81
#define BLAZE_CONSTRAINT_MUST_BE_RESIZABLE_TYPE(T)
Constraint on the data type.
Definition: Resizable.h:61
#define BLAZE_CONSTRAINT_MUST_NOT_BE_TRANSFORMATION_TYPE(T)
Constraint on the data type.
Definition: Transformation.h:81
#define BLAZE_CONSTRAINT_MUST_BE_MATRIX_WITH_STORAGE_ORDER(T, SO)
Constraint on the data type.
Definition: StorageOrder.h:63
constexpr bool IsScalar_v
Auxiliary variable template for the IsScalar type trait.
Definition: IsScalar.h:104
constexpr ptrdiff_t Size_v
Auxiliary variable template for the Size type trait.
Definition: Size.h:176
constexpr bool IsComputation_v
Auxiliary variable template for the IsComputation type trait.
Definition: IsComputation.h:90
constexpr bool operator>(const NegativeAccuracy< A > &lhs, const T &rhs)
Greater-than comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:370
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
constexpr bool operator<(const NegativeAccuracy< A > &lhs, const T &rhs)
Less-than comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:332
constexpr bool operator>=(const NegativeAccuracy< A > &, const T &rhs)
Greater-or-equal-than comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:446
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
constexpr bool operator<=(const NegativeAccuracy< A > &, const T &rhs)
Less-or-equal-than comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:408
constexpr void clear(Matrix< MT, SO > &matrix)
Clearing the given matrix.
Definition: Matrix.h:960
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
void resize(Matrix< MT, SO > &matrix, size_t rows, size_t columns, bool preserve=true)
Changing the size of the matrix.
Definition: Matrix.h:1108
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
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 shrinkToFit(Matrix< MT, SO > &matrix)
Requesting the removal of unused capacity.
Definition: Matrix.h:1169
bool isSquare(const Matrix< MT, SO > &matrix) noexcept
Checks if the given matrix is a square matrix.
Definition: Matrix.h:1383
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 > > loadu(const T *address) noexcept
Loads a vector of 1-byte integral values.
Definition: Loadu.h:76
BLAZE_ALWAYS_INLINE const EnableIf_t< IsIntegral_v< T > &&HasSize_v< T, 1UL >, If_t< IsSigned_v< T >, SIMDint8, SIMDuint8 > > loada(const T *address) noexcept
Loads a vector of 1-byte integral values.
Definition: Loada.h:79
#define BLAZE_STATIC_ASSERT(expr)
Compile time assertion macro.
Definition: StaticAssert.h:112
decltype(auto) submatrix(Matrix< MT, SO > &, RSAs...)
Creating a view on a specific submatrix of the given matrix.
Definition: Submatrix.h:181
#define BLAZE_ALWAYS_INLINE
Platform dependent setup of an enforced inline keyword.
Definition: Inline.h:85
BoolConstant< true > TrueType
Type traits base class.
Definition: IntegralConstant.h:132
BoolConstant< false > FalseType
Type/value traits base class.
Definition: IntegralConstant.h:121
typename EnableIf< Condition, T >::Type EnableIf_t
Auxiliary type for the EnableIf class template.
Definition: EnableIf.h:138
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition: MaybeUnused.h:81
#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
typename EnableIf<!Condition, T >::Type DisableIf_t
Auxiliary type for the EnableIf class template.
Definition: EnableIf.h:175
Header file for the exception macros of the math module.
Header file for the extended initializer_list functionality.
Constraints on the storage order of matrix types.
Header file for the Size type trait.
Header file for the clear shim.
Header file for the isZero shim.
System settings for the inline keywords.
Header file for basic type definitions.
Header file for the implementation of the Band view.
Header file for the implementation of the Submatrix view.