Blaze 3.9
Dense.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_ADAPTORS_STRICTLYUPPERMATRIX_DENSE_H_
36#define _BLAZE_MATH_ADAPTORS_STRICTLYUPPERMATRIX_DENSE_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <iterator>
44#include <utility>
48#include <blaze/math/Aliases.h>
77#include <blaze/system/Inline.h>
78#include <blaze/util/Assert.h>
84#include <blaze/util/EnableIf.h>
88#include <blaze/util/Types.h>
89
90
91namespace blaze {
92
93//=================================================================================================
94//
95// CLASS TEMPLATE SPECIALIZATION FOR DENSE MATRICES
96//
97//=================================================================================================
98
99//*************************************************************************************************
107template< typename MT // Type of the adapted dense matrix
108 , bool SO > // Storage order of the adapted dense matrix
109class StrictlyUpperMatrix<MT,SO,true>
110 : public DenseMatrix< StrictlyUpperMatrix<MT,SO,true>, SO >
111{
112 private:
113 //**Type definitions****************************************************************************
114 using OT = OppositeType_t<MT>;
115 using TT = TransposeType_t<MT>;
116 using ET = ElementType_t<MT>;
117 //**********************************************************************************************
118
119 public:
120 //**Type definitions****************************************************************************
121 using This = StrictlyUpperMatrix<MT,SO,true>;
122 using BaseType = DenseMatrix<This,SO>;
123 using ResultType = This;
124 using OppositeType = StrictlyUpperMatrix<OT,!SO,true>;
125 using TransposeType = StrictlyLowerMatrix<TT,!SO,true>;
126 using ElementType = ET;
127 using SIMDType = SIMDType_t<MT>;
128 using TagType = TagType_t<MT>;
129 using ReturnType = ReturnType_t<MT>;
130 using CompositeType = const This&;
131 using Reference = StrictlyUpperProxy<MT>;
132 using ConstReference = ConstReference_t<MT>;
133 using Pointer = Pointer_t<MT>;
134 using ConstPointer = ConstPointer_t<MT>;
135 using ConstIterator = ConstIterator_t<MT>;
136 //**********************************************************************************************
137
138 //**Rebind struct definition********************************************************************
141 template< typename NewType > // Data type of the other matrix
142 struct Rebind {
144 using Other = StrictlyUpperMatrix< typename MT::template Rebind<NewType>::Other >;
145 };
146 //**********************************************************************************************
147
148 //**Resize struct definition********************************************************************
151 template< size_t NewM // Number of rows of the other matrix
152 , size_t NewN > // Number of columns of the other matrix
153 struct Resize {
155 using Other = StrictlyUpperMatrix< typename MT::template Resize<NewM,NewN>::Other >;
156 };
157 //**********************************************************************************************
158
159 //**Iterator class definition*******************************************************************
162 class Iterator
163 {
164 public:
165 //**Type definitions*************************************************************************
166 using IteratorCategory = std::random_access_iterator_tag;
167 using ValueType = ElementType_t<MT>;
168 using PointerType = StrictlyUpperProxy<MT>;
169 using ReferenceType = StrictlyUpperProxy<MT>;
170 using DifferenceType = ptrdiff_t;
171
172 // STL iterator requirements
173 using iterator_category = IteratorCategory;
174 using value_type = ValueType;
175 using pointer = PointerType;
176 using reference = ReferenceType;
177 using difference_type = DifferenceType;
178 //*******************************************************************************************
179
180 //**Constructor******************************************************************************
183 inline Iterator() noexcept
184 : matrix_( nullptr ) // Reference to the adapted dense matrix
185 , row_ ( 0UL ) // The current row index of the iterator
186 , column_( 0UL ) // The current column index of the iterator
187 {}
188 //*******************************************************************************************
189
190 //**Constructor******************************************************************************
197 inline Iterator( MT& matrix, size_t row, size_t column ) noexcept
198 : matrix_( &matrix ) // Reference to the adapted dense matrix
199 , row_ ( row ) // The current row-index of the iterator
200 , column_( column ) // The current column-index of the iterator
201 {}
202 //*******************************************************************************************
203
204 //**Addition assignment operator*************************************************************
210 inline Iterator& operator+=( size_t inc ) noexcept {
211 ( SO )?( row_ += inc ):( column_ += inc );
212 return *this;
213 }
214 //*******************************************************************************************
215
216 //**Subtraction assignment operator**********************************************************
222 inline Iterator& operator-=( size_t dec ) noexcept {
223 ( SO )?( row_ -= dec ):( column_ -= dec );
224 return *this;
225 }
226 //*******************************************************************************************
227
228 //**Prefix increment operator****************************************************************
233 inline Iterator& operator++() noexcept {
234 ( SO )?( ++row_ ):( ++column_ );
235 return *this;
236 }
237 //*******************************************************************************************
238
239 //**Postfix increment operator***************************************************************
244 inline const Iterator operator++( int ) noexcept {
245 const Iterator tmp( *this );
246 ++(*this);
247 return tmp;
248 }
249 //*******************************************************************************************
250
251 //**Prefix decrement operator****************************************************************
256 inline Iterator& operator--() noexcept {
257 ( SO )?( --row_ ):( --column_ );
258 return *this;
259 }
260 //*******************************************************************************************
261
262 //**Postfix decrement operator***************************************************************
267 inline const Iterator operator--( int ) noexcept {
268 const Iterator tmp( *this );
269 --(*this);
270 return tmp;
271 }
272 //*******************************************************************************************
273
274 //**Element access operator******************************************************************
279 inline ReferenceType operator*() const {
280 return ReferenceType( *matrix_, row_, column_ );
281 }
282 //*******************************************************************************************
283
284 //**Element access operator******************************************************************
289 inline PointerType operator->() const {
290 return PointerType( *matrix_, row_, column_ );
291 }
292 //*******************************************************************************************
293
294 //**Load function****************************************************************************
304 inline SIMDType load() const {
305 return (*matrix_).load(row_,column_);
306 }
307 //*******************************************************************************************
308
309 //**Loada function***************************************************************************
319 inline SIMDType loada() const {
320 return (*matrix_).loada(row_,column_);
321 }
322 //*******************************************************************************************
323
324 //**Loadu function***************************************************************************
334 inline SIMDType loadu() const {
335 return (*matrix_).loadu(row_,column_);
336 }
337 //*******************************************************************************************
338
339 //**Conversion operator**********************************************************************
344 inline operator ConstIterator() const {
345 if( SO )
346 return matrix_->begin( column_ ) + row_;
347 else
348 return matrix_->begin( row_ ) + column_;
349 }
350 //*******************************************************************************************
351
352 //**Equality operator************************************************************************
359 friend inline bool operator==( const Iterator& lhs, const Iterator& rhs ) noexcept {
360 return ( SO )?( lhs.row_ == rhs.row_ ):( lhs.column_ == rhs.column_ );
361 }
362 //*******************************************************************************************
363
364 //**Equality operator************************************************************************
371 friend inline bool operator==( const Iterator& lhs, const ConstIterator& rhs ) {
372 return ( ConstIterator( lhs ) == rhs );
373 }
374 //*******************************************************************************************
375
376 //**Equality operator************************************************************************
383 friend inline bool operator==( const ConstIterator& lhs, const Iterator& rhs ) {
384 return ( lhs == ConstIterator( rhs ) );
385 }
386 //*******************************************************************************************
387
388 //**Inequality operator**********************************************************************
395 friend inline bool operator!=( const Iterator& lhs, const Iterator& rhs ) noexcept {
396 return ( SO )?( lhs.row_ != rhs.row_ ):( lhs.column_ != rhs.column_ );
397 }
398 //*******************************************************************************************
399
400 //**Inequality operator**********************************************************************
407 friend inline bool operator!=( const Iterator& lhs, const ConstIterator& rhs ) {
408 return ( ConstIterator( lhs ) != rhs );
409 }
410 //*******************************************************************************************
411
412 //**Inequality operator**********************************************************************
419 friend inline bool operator!=( const ConstIterator& lhs, const Iterator& rhs ) {
420 return ( lhs != ConstIterator( rhs ) );
421 }
422 //*******************************************************************************************
423
424 //**Less-than operator***********************************************************************
431 friend inline bool operator<( const Iterator& lhs, const Iterator& rhs ) noexcept {
432 return ( SO )?( lhs.row_ < rhs.row_ ):( lhs.column_ < rhs.column_ );
433 }
434 //*******************************************************************************************
435
436 //**Less-than operator***********************************************************************
443 friend inline bool operator<( const Iterator& lhs, const ConstIterator& rhs ) {
444 return ( ConstIterator( lhs ) < rhs );
445 }
446 //*******************************************************************************************
447
448 //**Less-than operator***********************************************************************
455 friend inline bool operator<( const ConstIterator& lhs, const Iterator& rhs ) {
456 return ( lhs < ConstIterator( rhs ) );
457 }
458 //*******************************************************************************************
459
460 //**Greater-than operator********************************************************************
467 friend inline bool operator>( const Iterator& lhs, const Iterator& rhs ) noexcept {
468 return ( SO )?( lhs.row_ > rhs.row_ ):( lhs.column_ > rhs.column_ );
469 }
470 //*******************************************************************************************
471
472 //**Greater-than operator********************************************************************
479 friend inline bool operator>( const Iterator& lhs, const ConstIterator& rhs ) {
480 return ( ConstIterator( lhs ) > rhs );
481 }
482 //*******************************************************************************************
483
484 //**Greater-than operator********************************************************************
491 friend inline bool operator>( const ConstIterator& lhs, const Iterator& rhs ) {
492 return ( lhs > ConstIterator( rhs ) );
493 }
494 //*******************************************************************************************
495
496 //**Less-or-equal-than operator**************************************************************
503 friend inline bool operator<=( const Iterator& lhs, const Iterator& rhs ) noexcept {
504 return ( SO )?( lhs.row_ <= rhs.row_ ):( lhs.column_ <= rhs.column_ );
505 }
506 //*******************************************************************************************
507
508 //**Less-or-equal-than operator**************************************************************
515 friend inline bool operator<=( const Iterator& lhs, const ConstIterator& rhs ) {
516 return ( ConstIterator( lhs ) <= rhs );
517 }
518 //*******************************************************************************************
519
520 //**Less-or-equal-than operator**************************************************************
527 friend inline bool operator<=( const ConstIterator& lhs, const Iterator& rhs ) {
528 return ( lhs <= ConstIterator( rhs ) );
529 }
530 //*******************************************************************************************
531
532 //**Greater-or-equal-than operator***********************************************************
539 friend inline bool operator>=( const Iterator& lhs, const Iterator& rhs ) noexcept {
540 return ( SO )?( lhs.row_ >= rhs.row_ ):( lhs.column_ >= rhs.column_ );
541 }
542 //*******************************************************************************************
543
544 //**Greater-or-equal-than operator***********************************************************
551 friend inline bool operator>=( const Iterator& lhs, const ConstIterator& rhs ) {
552 return ( ConstIterator( lhs ) >= rhs );
553 }
554 //*******************************************************************************************
555
556 //**Greater-or-equal-than operator***********************************************************
563 friend inline bool operator>=( const ConstIterator& lhs, const Iterator& rhs ) {
564 return ( lhs >= ConstIterator( rhs ) );
565 }
566 //*******************************************************************************************
567
568 //**Subtraction operator*********************************************************************
574 inline DifferenceType operator-( const Iterator& rhs ) const noexcept {
575 return ( SO )?( row_ - rhs.row_ ):( column_ - rhs.column_ );
576 }
577 //*******************************************************************************************
578
579 //**Addition operator************************************************************************
586 friend inline const Iterator operator+( const Iterator& it, size_t inc ) noexcept {
587 if( SO )
588 return Iterator( *it.matrix_, it.row_ + inc, it.column_ );
589 else
590 return Iterator( *it.matrix_, it.row_, it.column_ + inc );
591 }
592 //*******************************************************************************************
593
594 //**Addition operator************************************************************************
601 friend inline const Iterator operator+( size_t inc, const Iterator& it ) noexcept {
602 if( SO )
603 return Iterator( *it.matrix_, it.row_ + inc, it.column_ );
604 else
605 return Iterator( *it.matrix_, it.row_, it.column_ + inc );
606 }
607 //*******************************************************************************************
608
609 //**Subtraction operator*********************************************************************
616 friend inline const Iterator operator-( const Iterator& it, size_t dec ) noexcept {
617 if( SO )
618 return Iterator( *it.matrix_, it.row_ - dec, it.column_ );
619 else
620 return Iterator( *it.matrix_, it.row_, it.column_ - dec );
621 }
622 //*******************************************************************************************
623
624 private:
625 //**Member variables*************************************************************************
626 MT* matrix_;
627 size_t row_;
628 size_t column_;
629 //*******************************************************************************************
630 };
631 //**********************************************************************************************
632
633 //**Compilation flags***************************************************************************
635 static constexpr bool simdEnabled = MT::simdEnabled;
636
638 static constexpr bool smpAssignable = MT::smpAssignable;
639 //**********************************************************************************************
640
641 //**Constructors********************************************************************************
644 inline StrictlyUpperMatrix();
645 template< typename A1 > explicit inline StrictlyUpperMatrix( const A1& a1 );
646 inline StrictlyUpperMatrix( size_t n, const ElementType& init );
647
648 inline StrictlyUpperMatrix( initializer_list< initializer_list<ElementType> > list );
649
650 template< typename Other >
651 inline StrictlyUpperMatrix( size_t n, const Other* array );
652
653 template< typename Other, size_t N >
654 inline StrictlyUpperMatrix( const Other (&array)[N][N] );
655
656 inline StrictlyUpperMatrix( ElementType* ptr, size_t n );
657 inline StrictlyUpperMatrix( ElementType* ptr, size_t n, size_t nn );
658
659 inline StrictlyUpperMatrix( const StrictlyUpperMatrix& m );
660 inline StrictlyUpperMatrix( StrictlyUpperMatrix&& m ) noexcept;
662 //**********************************************************************************************
663
664 //**Destructor**********************************************************************************
667 ~StrictlyUpperMatrix() = default;
669 //**********************************************************************************************
670
671 //**Data access functions***********************************************************************
674 inline Reference operator()( size_t i, size_t j );
675 inline ConstReference operator()( size_t i, size_t j ) const;
676 inline Reference at( size_t i, size_t j );
677 inline ConstReference at( size_t i, size_t j ) const;
678 inline ConstPointer data () const noexcept;
679 inline ConstPointer data ( size_t i ) const noexcept;
680 inline Iterator begin ( size_t i );
681 inline ConstIterator begin ( size_t i ) const;
682 inline ConstIterator cbegin( size_t i ) const;
683 inline Iterator end ( size_t i );
684 inline ConstIterator end ( size_t i ) const;
685 inline ConstIterator cend ( size_t i ) const;
687 //**********************************************************************************************
688
689 //**Assignment operators************************************************************************
692 inline StrictlyUpperMatrix& operator=( initializer_list< initializer_list<ElementType> > list );
693
694 template< typename Other, size_t N >
695 inline StrictlyUpperMatrix& operator=( const Other (&array)[N][N] );
696
697 inline StrictlyUpperMatrix& operator=( const ElementType& rhs );
698 inline StrictlyUpperMatrix& operator=( const StrictlyUpperMatrix& rhs );
699 inline StrictlyUpperMatrix& operator=( StrictlyUpperMatrix&& rhs ) noexcept;
700
701 template< typename MT2, bool SO2 >
702 inline auto operator=( const Matrix<MT2,SO2>& rhs )
703 -> DisableIf_t< IsComputation_v<MT2>, StrictlyUpperMatrix& >;
704
705 template< typename MT2, bool SO2 >
706 inline auto operator=( const Matrix<MT2,SO2>& rhs )
707 -> EnableIf_t< IsComputation_v<MT2>, StrictlyUpperMatrix& >;
708
709 template< typename MT2, bool SO2 >
710 inline auto operator+=( const Matrix<MT2,SO2>& rhs )
711 -> DisableIf_t< IsComputation_v<MT2>, StrictlyUpperMatrix& >;
712
713 template< typename MT2, bool SO2 >
714 inline auto operator+=( const Matrix<MT2,SO2>& rhs )
715 -> EnableIf_t< IsComputation_v<MT2>, StrictlyUpperMatrix& >;
716
717 template< typename MT2, bool SO2 >
718 inline auto operator-=( const Matrix<MT2,SO2>& rhs )
719 -> DisableIf_t< IsComputation_v<MT2>, StrictlyUpperMatrix& >;
720
721 template< typename MT2, bool SO2 >
722 inline auto operator-=( const Matrix<MT2,SO2>& rhs )
723 -> EnableIf_t< IsComputation_v<MT2>, StrictlyUpperMatrix& >;
724
725 template< typename MT2, bool SO2 >
726 inline auto operator%=( const Matrix<MT2,SO2>& rhs ) -> StrictlyUpperMatrix&;
727
728 template< typename ST >
729 inline auto operator*=( ST rhs ) -> EnableIf_t< IsScalar_v<ST>, StrictlyUpperMatrix& >;
730
731 template< typename ST >
732 inline auto operator/=( ST rhs ) -> EnableIf_t< IsScalar_v<ST>, StrictlyUpperMatrix& >;
734 //**********************************************************************************************
735
736 //**Utility functions***************************************************************************
739 inline size_t rows() const noexcept;
740 inline size_t columns() const noexcept;
741 inline size_t spacing() const noexcept;
742 inline size_t capacity() const noexcept;
743 inline size_t capacity( size_t i ) const noexcept;
744 inline size_t nonZeros() const;
745 inline size_t nonZeros( size_t i ) const;
746 inline void reset();
747 inline void reset( size_t i );
748 inline void clear();
749 void resize ( size_t n, bool preserve=true );
750 inline void extend ( size_t n, bool preserve=true );
751 inline void reserve( size_t elements );
752 inline void shrinkToFit();
753 inline void swap( StrictlyUpperMatrix& m ) noexcept;
754
755 static constexpr size_t maxNonZeros() noexcept;
756 static constexpr size_t maxNonZeros( size_t n ) noexcept;
758 //**********************************************************************************************
759
760 //**Numeric functions***************************************************************************
763 template< typename Other > inline StrictlyUpperMatrix& scale( const Other& scalar );
765 //**********************************************************************************************
766
767 //**Debugging functions*************************************************************************
770 inline bool isIntact() const noexcept;
772 //**********************************************************************************************
773
774 //**Expression template evaluation functions****************************************************
777 template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
778 template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
779
780 inline bool isAligned () const noexcept;
781 inline bool canSMPAssign() const noexcept;
782
783 BLAZE_ALWAYS_INLINE SIMDType load ( size_t i, size_t j ) const noexcept;
784 BLAZE_ALWAYS_INLINE SIMDType loada( size_t i, size_t j ) const noexcept;
785 BLAZE_ALWAYS_INLINE SIMDType loadu( size_t i, size_t j ) const noexcept;
787 //**********************************************************************************************
788
789 private:
790 //**Construction functions**********************************************************************
793 inline const MT construct( size_t n , TrueType );
794 inline const MT construct( const ElementType& value, FalseType );
795
796 template< typename MT2, bool SO2, typename T >
797 inline const MT construct( const Matrix<MT2,SO2>& m, T );
799 //**********************************************************************************************
800
801 //**Member variables****************************************************************************
804 MT matrix_;
806 //**********************************************************************************************
807
808 //**Friend declarations*************************************************************************
809 template< typename MT2, bool SO2, bool DF2 >
810 friend MT2& derestrict( StrictlyUpperMatrix<MT2,SO2,DF2>& m );
811 //**********************************************************************************************
812
813 //**Compile time checks*************************************************************************
828 BLAZE_STATIC_ASSERT( ( Size_v<MT,0UL> == Size_v<MT,1UL> ) );
829 //**********************************************************************************************
830};
832//*************************************************************************************************
833
834
835
836
837//=================================================================================================
838//
839// CONSTRUCTORS
840//
841//=================================================================================================
842
843//*************************************************************************************************
847template< typename MT // Type of the adapted dense matrix
848 , bool SO > // Storage order of the adapted dense matrix
849inline StrictlyUpperMatrix<MT,SO,true>::StrictlyUpperMatrix()
850 : matrix_() // The adapted dense matrix
851{
852 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square strictly upper matrix detected" );
853 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
854}
856//*************************************************************************************************
857
858
859//*************************************************************************************************
877template< typename MT // Type of the adapted dense matrix
878 , bool SO > // Storage order of the adapted dense matrix
879template< typename A1 > // Type of the constructor argument
880inline StrictlyUpperMatrix<MT,SO,true>::StrictlyUpperMatrix( const A1& a1 )
881 : matrix_( construct( a1, IsResizable<MT>() ) ) // The adapted dense matrix
882{
883 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square strictly upper matrix detected" );
884 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
885}
887//*************************************************************************************************
888
889
890//*************************************************************************************************
897template< typename MT // Type of the adapted dense matrix
898 , bool SO > // Storage order of the adapted dense matrix
899inline StrictlyUpperMatrix<MT,SO,true>::StrictlyUpperMatrix( size_t n, const ElementType& init )
900 : matrix_( n, n, ElementType() ) // The adapted dense matrix
901{
903
904 if( SO ) {
905 for( size_t j=0UL; j<columns(); ++j ) {
906 for( size_t i=0UL; i<j; ++i )
907 matrix_(i,j) = init;
908 }
909 }
910 else {
911 for( size_t i=0UL; i<rows(); ++i ) {
912 for( size_t j=i+1UL; j<columns(); ++j )
913 matrix_(i,j) = init;
914 }
915 }
916
917 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square strictly upper matrix detected" );
918 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
919}
921//*************************************************************************************************
922
923
924//*************************************************************************************************
948template< typename MT // Type of the adapted dense matrix
949 , bool SO > // Storage order of the adapted dense matrix
950inline StrictlyUpperMatrix<MT,SO,true>::StrictlyUpperMatrix( initializer_list< initializer_list<ElementType> > list )
951 : matrix_( list ) // The adapted dense matrix
952{
953 if( !isStrictlyUpper( matrix_ ) ) {
954 BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of strictly upper matrix" );
955 }
956
957 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
958}
960//*************************************************************************************************
961
962
963//*************************************************************************************************
990template< typename MT // Type of the adapted dense matrix
991 , bool SO > // Storage order of the adapted dense matrix
992template< typename Other > // Data type of the initialization array
993inline StrictlyUpperMatrix<MT,SO,true>::StrictlyUpperMatrix( size_t n, const Other* array )
994 : matrix_( n, n, array ) // The adapted dense matrix
995{
996 if( !isStrictlyUpper( matrix_ ) ) {
997 BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of strictly upper matrix" );
998 }
999
1000 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1001}
1003//*************************************************************************************************
1004
1005
1006//*************************************************************************************************
1029template< typename MT // Type of the adapted dense matrix
1030 , bool SO > // Storage order of the adapted dense matrix
1031template< typename Other // Data type of the initialization array
1032 , size_t N > // Number of columns of the initialization array
1033inline StrictlyUpperMatrix<MT,SO,true>::StrictlyUpperMatrix( const Other (&array)[N][N] )
1034 : matrix_( array ) // The adapted dense matrix
1035{
1036 if( !isStrictlyUpper( matrix_ ) ) {
1037 BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of strictly upper matrix" );
1038 }
1039
1040 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1041}
1043//*************************************************************************************************
1044
1045
1046//*************************************************************************************************
1079template< typename MT // Type of the adapted dense matrix
1080 , bool SO > // Storage order of the adapted dense matrix
1081inline StrictlyUpperMatrix<MT,SO,true>::StrictlyUpperMatrix( ElementType* ptr, size_t n )
1082 : matrix_( ptr, n, n ) // The adapted dense matrix
1083{
1084 if( !isStrictlyUpper( matrix_ ) ) {
1085 BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of strictly upper matrix" );
1086 }
1087
1088 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1089}
1091//*************************************************************************************************
1092
1093
1094//*************************************************************************************************
1128template< typename MT // Type of the adapted dense matrix
1129 , bool SO > // Storage order of the adapted dense matrix
1130inline StrictlyUpperMatrix<MT,SO,true>::StrictlyUpperMatrix( ElementType* ptr, size_t n, size_t nn )
1131 : matrix_( ptr, n, n, nn ) // The adapted dense matrix
1132{
1133 if( !isStrictlyUpper( matrix_ ) ) {
1134 BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of strictly upper matrix" );
1135 }
1136
1137 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1138}
1140//*************************************************************************************************
1141
1142
1143//*************************************************************************************************
1149template< typename MT // Type of the adapted dense matrix
1150 , bool SO > // Storage order of the adapted dense matrix
1151inline StrictlyUpperMatrix<MT,SO,true>::StrictlyUpperMatrix( const StrictlyUpperMatrix& m )
1152 : matrix_( m.matrix_ ) // The adapted dense matrix
1153{
1154 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square strictly upper matrix detected" );
1155 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1156}
1158//*************************************************************************************************
1159
1160
1161//*************************************************************************************************
1167template< typename MT // Type of the adapted dense matrix
1168 , bool SO > // Storage order of the adapted dense matrix
1169inline StrictlyUpperMatrix<MT,SO,true>::StrictlyUpperMatrix( StrictlyUpperMatrix&& m ) noexcept
1170 : matrix_( std::move( m.matrix_ ) ) // The adapted dense matrix
1171{
1172 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square strictly upper matrix detected" );
1173 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1174}
1176//*************************************************************************************************
1177
1178
1179
1180
1181//=================================================================================================
1182//
1183// DATA ACCESS FUNCTIONS
1184//
1185//=================================================================================================
1186
1187//*************************************************************************************************
1203template< typename MT // Type of the adapted dense matrix
1204 , bool SO > // Storage order of the adapted dense matrix
1205inline typename StrictlyUpperMatrix<MT,SO,true>::Reference
1206 StrictlyUpperMatrix<MT,SO,true>::operator()( size_t i, size_t j )
1207{
1208 BLAZE_USER_ASSERT( i<rows() , "Invalid row access index" );
1209 BLAZE_USER_ASSERT( j<columns(), "Invalid column access index" );
1210
1211 return Reference( matrix_, i, j );
1212}
1214//*************************************************************************************************
1215
1216
1217//*************************************************************************************************
1233template< typename MT // Type of the adapted dense matrix
1234 , bool SO > // Storage order of the adapted dense matrix
1235inline typename StrictlyUpperMatrix<MT,SO,true>::ConstReference
1236 StrictlyUpperMatrix<MT,SO,true>::operator()( size_t i, size_t j ) const
1237{
1238 BLAZE_USER_ASSERT( i<rows() , "Invalid row access index" );
1239 BLAZE_USER_ASSERT( j<columns(), "Invalid column access index" );
1240
1241 return matrix_(i,j);
1242}
1244//*************************************************************************************************
1245
1246
1247//*************************************************************************************************
1264template< typename MT // Type of the adapted dense matrix
1265 , bool SO > // Storage order of the adapted dense matrix
1266inline typename StrictlyUpperMatrix<MT,SO,true>::Reference
1267 StrictlyUpperMatrix<MT,SO,true>::at( size_t i, size_t j )
1268{
1269 if( i >= rows() ) {
1270 BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
1271 }
1272 if( j >= columns() ) {
1273 BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
1274 }
1275 return (*this)(i,j);
1276}
1278//*************************************************************************************************
1279
1280
1281//*************************************************************************************************
1298template< typename MT // Type of the adapted dense matrix
1299 , bool SO > // Storage order of the adapted dense matrix
1300inline typename StrictlyUpperMatrix<MT,SO,true>::ConstReference
1301 StrictlyUpperMatrix<MT,SO,true>::at( size_t i, size_t j ) const
1302{
1303 if( i >= rows() ) {
1304 BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
1305 }
1306 if( j >= columns() ) {
1307 BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
1308 }
1309 return (*this)(i,j);
1310}
1312//*************************************************************************************************
1313
1314
1315//*************************************************************************************************
1328template< typename MT // Type of the adapted dense matrix
1329 , bool SO > // Storage order of the adapted dense matrix
1330inline typename StrictlyUpperMatrix<MT,SO,true>::ConstPointer
1332{
1333 return matrix_.data();
1334}
1336//*************************************************************************************************
1337
1338
1339//*************************************************************************************************
1348template< typename MT // Type of the adapted dense matrix
1349 , bool SO > // Storage order of the adapted dense matrix
1350inline typename StrictlyUpperMatrix<MT,SO,true>::ConstPointer
1351 StrictlyUpperMatrix<MT,SO,true>::data( size_t i ) const noexcept
1352{
1353 return matrix_.data(i);
1354}
1356//*************************************************************************************************
1357
1358
1359//*************************************************************************************************
1371template< typename MT // Type of the adapted dense matrix
1372 , bool SO > // Storage order of the adapted dense matrix
1373inline typename StrictlyUpperMatrix<MT,SO,true>::Iterator
1375{
1376 if( SO )
1377 return Iterator( matrix_, 0UL, i );
1378 else
1379 return Iterator( matrix_, i, 0UL );
1380}
1382//*************************************************************************************************
1383
1384
1385//*************************************************************************************************
1397template< typename MT // Type of the adapted dense matrix
1398 , bool SO > // Storage order of the adapted dense matrix
1399inline typename StrictlyUpperMatrix<MT,SO,true>::ConstIterator
1401{
1402 return matrix_.begin(i);
1403}
1405//*************************************************************************************************
1406
1407
1408//*************************************************************************************************
1420template< typename MT // Type of the adapted dense matrix
1421 , bool SO > // Storage order of the adapted dense matrix
1422inline typename StrictlyUpperMatrix<MT,SO,true>::ConstIterator
1424{
1425 return matrix_.cbegin(i);
1426}
1428//*************************************************************************************************
1429
1430
1431//*************************************************************************************************
1443template< typename MT // Type of the adapted dense matrix
1444 , bool SO > // Storage order of the adapted dense matrix
1445inline typename StrictlyUpperMatrix<MT,SO,true>::Iterator
1447{
1448 if( SO )
1449 return Iterator( matrix_, rows(), i );
1450 else
1451 return Iterator( matrix_, i, columns() );
1452}
1454//*************************************************************************************************
1455
1456
1457//*************************************************************************************************
1469template< typename MT // Type of the adapted dense matrix
1470 , bool SO > // Storage order of the adapted dense matrix
1471inline typename StrictlyUpperMatrix<MT,SO,true>::ConstIterator
1472 StrictlyUpperMatrix<MT,SO,true>::end( size_t i ) const
1473{
1474 return matrix_.end(i);
1475}
1477//*************************************************************************************************
1478
1479
1480//*************************************************************************************************
1492template< typename MT // Type of the adapted dense matrix
1493 , bool SO > // Storage order of the adapted dense matrix
1494inline typename StrictlyUpperMatrix<MT,SO,true>::ConstIterator
1496{
1497 return matrix_.cend(i);
1498}
1500//*************************************************************************************************
1501
1502
1503
1504
1505//=================================================================================================
1506//
1507// ASSIGNMENT OPERATORS
1508//
1509//=================================================================================================
1510
1511//*************************************************************************************************
1518template< typename MT // Type of the adapted dense matrix
1519 , bool SO > // Storage order of the adapted dense matrix
1520inline StrictlyUpperMatrix<MT,SO,true>&
1521 StrictlyUpperMatrix<MT,SO,true>::operator=( const ElementType& rhs )
1522{
1523 if( SO ) {
1524 for( size_t j=1UL; j<columns(); ++j )
1525 for( size_t i=0UL; i<j; ++i )
1526 matrix_(i,j) = rhs;
1527 }
1528 else {
1529 for( size_t i=0UL; i<rows(); ++i )
1530 for( size_t j=i+1UL; j<columns(); ++j )
1531 matrix_(i,j) = rhs;
1532 }
1533
1534 return *this;
1535}
1537//*************************************************************************************************
1538
1539
1540//*************************************************************************************************
1565template< typename MT // Type of the adapted dense matrix
1566 , bool SO > // Storage order of the adapted dense matrix
1567inline StrictlyUpperMatrix<MT,SO,true>&
1568 StrictlyUpperMatrix<MT,SO,true>::operator=( initializer_list< initializer_list<ElementType> > list )
1569{
1570 const InitializerMatrix<ElementType> tmp( list, list.size() );
1571
1572 if( !isStrictlyUpper( tmp ) ) {
1573 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to strictly upper matrix" );
1574 }
1575
1576 matrix_ = list;
1577
1578 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square strictly upper matrix detected" );
1579 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1580
1581 return *this;
1582}
1584//*************************************************************************************************
1585
1586
1587//*************************************************************************************************
1612template< typename MT // Type of the adapted dense matrix
1613 , bool SO > // Storage order of the adapted dense matrix
1614template< typename Other // Data type of the initialization array
1615 , size_t N > // Number of rows and columns of the initialization array
1616inline StrictlyUpperMatrix<MT,SO,true>&
1617 StrictlyUpperMatrix<MT,SO,true>::operator=( const Other (&array)[N][N] )
1618{
1619 MT tmp( array );
1620
1621 if( !isStrictlyUpper( tmp ) ) {
1622 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to strictly upper matrix" );
1623 }
1624
1625 matrix_ = std::move( tmp );
1626
1627 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square strictly upper matrix detected" );
1628 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1629
1630 return *this;
1631}
1633//*************************************************************************************************
1634
1635
1636//*************************************************************************************************
1646template< typename MT // Type of the adapted dense matrix
1647 , bool SO > // Storage order of the adapted dense matrix
1648inline StrictlyUpperMatrix<MT,SO,true>&
1649 StrictlyUpperMatrix<MT,SO,true>::operator=( const StrictlyUpperMatrix& rhs )
1650{
1651 matrix_ = rhs.matrix_;
1652
1653 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square strictly upper matrix detected" );
1654 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1655
1656 return *this;
1657}
1659//*************************************************************************************************
1660
1661
1662//*************************************************************************************************
1669template< typename MT // Type of the adapted dense matrix
1670 , bool SO > // Storage order of the adapted dense matrix
1671inline StrictlyUpperMatrix<MT,SO,true>&
1672 StrictlyUpperMatrix<MT,SO,true>::operator=( StrictlyUpperMatrix&& rhs ) noexcept
1673{
1674 matrix_ = std::move( rhs.matrix_ );
1675
1676 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square strictly upper matrix detected" );
1677 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1678
1679 return *this;
1680}
1682//*************************************************************************************************
1683
1684
1685//*************************************************************************************************
1698template< typename MT // Type of the adapted dense matrix
1699 , bool SO > // Storage order of the adapted dense matrix
1700template< typename MT2 // Type of the right-hand side matrix
1701 , bool SO2 > // Storage order of the right-hand side matrix
1702inline auto StrictlyUpperMatrix<MT,SO,true>::operator=( const Matrix<MT2,SO2>& rhs )
1703 -> DisableIf_t< IsComputation_v<MT2>, StrictlyUpperMatrix& >
1704{
1705 if( IsUniTriangular_v<MT2> ||
1706 ( !IsStrictlyUpper_v<MT2> && !isStrictlyUpper( *rhs ) ) ) {
1707 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to strictly upper matrix" );
1708 }
1709
1710 matrix_ = declupp( *rhs );
1711
1712 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square strictly upper matrix detected" );
1713 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1714
1715 return *this;
1716}
1718//*************************************************************************************************
1719
1720
1721//*************************************************************************************************
1734template< typename MT // Type of the adapted dense matrix
1735 , bool SO > // Storage order of the adapted dense matrix
1736template< typename MT2 // Type of the right-hand side matrix
1737 , bool SO2 > // Storage order of the right-hand side matrix
1738inline auto StrictlyUpperMatrix<MT,SO,true>::operator=( const Matrix<MT2,SO2>& rhs )
1739 -> EnableIf_t< IsComputation_v<MT2>, StrictlyUpperMatrix& >
1740{
1741 if( IsUniTriangular_v<MT2> || ( !IsSquare_v<MT2> && !isSquare( *rhs ) ) ) {
1742 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to strictly upper matrix" );
1743 }
1744
1745 if( IsStrictlyUpper_v<MT2> ) {
1746 matrix_ = *rhs;
1747 }
1748 else {
1749 MT tmp( *rhs );
1750
1751 if( !isStrictlyUpper( tmp ) ) {
1752 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to strictly upper matrix" );
1753 }
1754
1755 matrix_ = std::move( tmp );
1756 }
1757
1758 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square strictly upper matrix detected" );
1759 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1760
1761 return *this;
1762}
1764//*************************************************************************************************
1765
1766
1767//*************************************************************************************************
1780template< typename MT // Type of the adapted dense matrix
1781 , bool SO > // Storage order of the adapted dense matrix
1782template< typename MT2 // Type of the right-hand side matrix
1783 , bool SO2 > // Storage order of the right-hand side matrix
1784inline auto StrictlyUpperMatrix<MT,SO,true>::operator+=( const Matrix<MT2,SO2>& rhs )
1785 -> DisableIf_t< IsComputation_v<MT2>, StrictlyUpperMatrix& >
1786{
1787 if( IsUniTriangular_v<MT2> ||
1788 ( !IsStrictlyUpper_v<MT2> && !isStrictlyUpper( *rhs ) ) ) {
1789 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to strictly upper matrix" );
1790 }
1791
1792 matrix_ += declupp( *rhs );
1793
1794 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square strictly upper matrix detected" );
1795 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1796
1797 return *this;
1798}
1800//*************************************************************************************************
1801
1802
1803//*************************************************************************************************
1816template< typename MT // Type of the adapted dense matrix
1817 , bool SO > // Storage order of the adapted dense matrix
1818template< typename MT2 // Type of the right-hand side matrix
1819 , bool SO2 > // Storage order of the right-hand side matrix
1820inline auto StrictlyUpperMatrix<MT,SO,true>::operator+=( const Matrix<MT2,SO2>& rhs )
1821 -> EnableIf_t< IsComputation_v<MT2>, StrictlyUpperMatrix& >
1822{
1823 if( IsUniTriangular_v<MT2> || ( !IsSquare_v<MT2> && !isSquare( *rhs ) ) ) {
1824 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to strictly upper matrix" );
1825 }
1826
1827 if( IsStrictlyUpper_v<MT2> ) {
1828 matrix_ += *rhs;
1829 }
1830 else {
1831 const ResultType_t<MT2> tmp( *rhs );
1832
1833 if( !isStrictlyUpper( tmp ) ) {
1834 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to strictly upper matrix" );
1835 }
1836
1837 matrix_ += declupp( tmp );
1838 }
1839
1840 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square strictly upper matrix detected" );
1841 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1842
1843 return *this;
1844}
1846//*************************************************************************************************
1847
1848
1849//*************************************************************************************************
1862template< typename MT // Type of the adapted dense matrix
1863 , bool SO > // Storage order of the adapted dense matrix
1864template< typename MT2 // Type of the right-hand side matrix
1865 , bool SO2 > // Storage order of the right-hand side matrix
1866inline auto StrictlyUpperMatrix<MT,SO,true>::operator-=( const Matrix<MT2,SO2>& rhs )
1867 -> DisableIf_t< IsComputation_v<MT2>, StrictlyUpperMatrix& >
1868{
1869 if( !IsStrictlyUpper_v<MT2> && !isStrictlyUpper( *rhs ) ) {
1870 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to strictly upper matrix" );
1871 }
1872
1873 matrix_ -= declupp( *rhs );
1874
1875 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square strictly upper matrix detected" );
1876 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1877
1878 return *this;
1879}
1881//*************************************************************************************************
1882
1883
1884//*************************************************************************************************
1897template< typename MT // Type of the adapted dense matrix
1898 , bool SO > // Storage order of the adapted dense matrix
1899template< typename MT2 // Type of the right-hand side matrix
1900 , bool SO2 > // Storage order of the right-hand side matrix
1901inline auto StrictlyUpperMatrix<MT,SO,true>::operator-=( const Matrix<MT2,SO2>& rhs )
1902 -> EnableIf_t< IsComputation_v<MT2>, StrictlyUpperMatrix& >
1903{
1904 if( !IsSquare_v<MT2> && !isSquare( *rhs ) ) {
1905 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to strictly upper matrix" );
1906 }
1907
1908 if( IsStrictlyUpper_v<MT2> ) {
1909 matrix_ -= *rhs;
1910 }
1911 else {
1912 const ResultType_t<MT2> tmp( *rhs );
1913
1914 if( !isStrictlyUpper( tmp ) ) {
1915 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to strictly upper matrix" );
1916 }
1917
1918 matrix_ -= declupp( tmp );
1919 }
1920
1921 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square strictly upper matrix detected" );
1922 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1923
1924 return *this;
1925}
1927//*************************************************************************************************
1928
1929
1930//*************************************************************************************************
1941template< typename MT // Type of the adapted dense matrix
1942 , bool SO > // Storage order of the adapted dense matrix
1943template< typename MT2 // Type of the right-hand side matrix
1944 , bool SO2 > // Storage order of the right-hand side matrix
1945inline auto StrictlyUpperMatrix<MT,SO,true>::operator%=( const Matrix<MT2,SO2>& rhs )
1946 -> StrictlyUpperMatrix&
1947{
1948 if( !IsSquare_v<MT2> && !isSquare( *rhs ) ) {
1949 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to strictly upper matrix" );
1950 }
1951
1952 matrix_ %= *rhs;
1953
1954 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square strictly upper matrix detected" );
1955 BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
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
1975 -> EnableIf_t< IsScalar_v<ST>, StrictlyUpperMatrix& >
1976{
1977 matrix_ *= rhs;
1978 return *this;
1979}
1980//*************************************************************************************************
1981
1982
1983//*************************************************************************************************
1991template< typename MT // Type of the adapted dense matrix
1992 , bool SO > // Storage order of the adapted dense matrix
1993template< typename ST > // Data type of the right-hand side scalar
1995 -> EnableIf_t< IsScalar_v<ST>, StrictlyUpperMatrix& >
1996{
1997 BLAZE_USER_ASSERT( !isZero( rhs ), "Division by zero detected" );
1998
1999 matrix_ /= rhs;
2000 return *this;
2001}
2003//*************************************************************************************************
2004
2005
2006
2007
2008//=================================================================================================
2009//
2010// UTILITY FUNCTIONS
2011//
2012//=================================================================================================
2013
2014//*************************************************************************************************
2020template< typename MT // Type of the adapted dense matrix
2021 , bool SO > // Storage order of the adapted dense matrix
2022inline size_t StrictlyUpperMatrix<MT,SO,true>::rows() const noexcept
2023{
2024 return matrix_.rows();
2025}
2027//*************************************************************************************************
2028
2029
2030//*************************************************************************************************
2036template< typename MT // Type of the adapted dense matrix
2037 , bool SO > // Storage order of the adapted dense matrix
2038inline size_t StrictlyUpperMatrix<MT,SO,true>::columns() const noexcept
2039{
2040 return matrix_.columns();
2041}
2043//*************************************************************************************************
2044
2045
2046//*************************************************************************************************
2057template< typename MT // Type of the adapted dense matrix
2058 , bool SO > // Storage order of the adapted dense matrix
2059inline size_t StrictlyUpperMatrix<MT,SO,true>::spacing() const noexcept
2060{
2061 return matrix_.spacing();
2062}
2064//*************************************************************************************************
2065
2066
2067//*************************************************************************************************
2073template< typename MT // Type of the adapted dense matrix
2074 , bool SO > // Storage order of the adapted dense matrix
2075inline size_t StrictlyUpperMatrix<MT,SO,true>::capacity() const noexcept
2076{
2077 return matrix_.capacity();
2078}
2080//*************************************************************************************************
2081
2082
2083//*************************************************************************************************
2095template< typename MT // Type of the adapted dense matrix
2096 , bool SO > // Storage order of the adapted dense matrix
2097inline size_t StrictlyUpperMatrix<MT,SO,true>::capacity( size_t i ) const noexcept
2098{
2099 return matrix_.capacity(i);
2100}
2102//*************************************************************************************************
2103
2104
2105//*************************************************************************************************
2111template< typename MT // Type of the adapted dense matrix
2112 , bool SO > // Storage order of the adapted dense matrix
2114{
2115 return matrix_.nonZeros();
2116}
2118//*************************************************************************************************
2119
2120
2121//*************************************************************************************************
2133template< typename MT // Type of the adapted dense matrix
2134 , bool SO > // Storage order of the adapted dense matrix
2135inline size_t StrictlyUpperMatrix<MT,SO,true>::nonZeros( size_t i ) const
2136{
2137 return matrix_.nonZeros(i);
2138}
2140//*************************************************************************************************
2141
2142
2143//*************************************************************************************************
2149template< typename MT // Type of the adapted dense matrix
2150 , bool SO > // Storage order of the adapted dense matrix
2152{
2153 using blaze::clear;
2154
2155 if( SO ) {
2156 for( size_t j=1UL; j<columns(); ++j )
2157 for( size_t i=0UL; i<j; ++i )
2158 clear( matrix_(i,j) );
2159 }
2160 else {
2161 for( size_t i=0UL; i<rows(); ++i )
2162 for( size_t j=i+1UL; j<columns(); ++j )
2163 clear( matrix_(i,j) );
2164 }
2165}
2167//*************************************************************************************************
2168
2169
2170//*************************************************************************************************
2183template< typename MT // Type of the adapted dense matrix
2184 , bool SO > // Storage order of the adapted dense matrix
2185inline void StrictlyUpperMatrix<MT,SO,true>::reset( size_t i )
2186{
2187 using blaze::clear;
2188
2189 if( SO ) {
2190 for( size_t j=0UL; j<i; ++j )
2191 clear( matrix_(j,i) );
2192 }
2193 else {
2194 for( size_t j=i+1UL; j<columns(); ++j )
2195 clear( matrix_(i,j) );
2196 }
2197}
2199//*************************************************************************************************
2200
2201
2202//*************************************************************************************************
2214template< typename MT // Type of the adapted dense matrix
2215 , bool SO > // Storage order of the adapted dense matrix
2217{
2218 matrix_.clear();
2219
2220 BLAZE_INTERNAL_ASSERT( matrix_.rows() == 0UL, "Invalid number of rows" );
2221 BLAZE_INTERNAL_ASSERT( matrix_.columns() == 0UL, "Invalid number of columns" );
2222}
2224//*************************************************************************************************
2225
2226
2227//*************************************************************************************************
2263template< typename MT // Type of the adapted dense matrix
2264 , bool SO > // Storage order of the adapted dense matrix
2265void StrictlyUpperMatrix<MT,SO,true>::resize( size_t n, bool preserve )
2266{
2268
2269 MAYBE_UNUSED( preserve );
2270
2271 BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square strictly upper matrix detected" );
2272
2273 const size_t oldsize( matrix_.rows() );
2274
2275 matrix_.resize( n, n, true );
2276
2277 if( n > oldsize )
2278 {
2279 const size_t increment( n - oldsize );
2280 submatrix( matrix_, oldsize, 0UL, increment, n ).reset();
2281 }
2282}
2284//*************************************************************************************************
2285
2286
2287//*************************************************************************************************
2300template< typename MT // Type of the adapted dense matrix
2301 , bool SO > // Storage order of the adapted dense matrix
2302inline void StrictlyUpperMatrix<MT,SO,true>::extend( size_t n, bool preserve )
2303{
2305
2306 MAYBE_UNUSED( preserve );
2307
2308 resize( rows() + n, true );
2309}
2310//*************************************************************************************************
2311
2312
2313//*************************************************************************************************
2323template< typename MT // Type of the adapted dense matrix
2324 , bool SO > // Storage order of the adapted dense matrix
2325inline void StrictlyUpperMatrix<MT,SO,true>::reserve( size_t elements )
2326{
2327 matrix_.reserve( elements );
2328}
2330//*************************************************************************************************
2331
2332
2333//*************************************************************************************************
2343template< typename MT // Type of the adapted dense matrix
2344 , bool SO > // Storage order of the adapted dense matrix
2346{
2347 matrix_.shrinkToFit();
2348}
2350//*************************************************************************************************
2351
2352
2353//*************************************************************************************************
2360template< typename MT // Type of the adapted dense matrix
2361 , bool SO > // Storage order of the adapted dense matrix
2362inline void StrictlyUpperMatrix<MT,SO,true>::swap( StrictlyUpperMatrix& m ) noexcept
2363{
2364 using std::swap;
2365
2366 swap( matrix_, m.matrix_ );
2367}
2369//*************************************************************************************************
2370
2371
2372//*************************************************************************************************
2384template< typename MT // Type of the adapted dense matrix
2385 , bool SO > // Storage order of the adapted dense matrix
2386constexpr size_t StrictlyUpperMatrix<MT,SO,true>::maxNonZeros() noexcept
2387{
2389
2390 return maxNonZeros( Size_v<MT,0UL> );
2391}
2393//*************************************************************************************************
2394
2395
2396//*************************************************************************************************
2406template< typename MT // Type of the adapted dense matrix
2407 , bool SO > // Storage order of the adapted dense matrix
2408constexpr size_t StrictlyUpperMatrix<MT,SO,true>::maxNonZeros( size_t n ) noexcept
2409{
2410 return ( ( n - 1UL ) * n ) / 2UL;
2411}
2413//*************************************************************************************************
2414
2415
2416
2417
2418//=================================================================================================
2419//
2420// NUMERIC FUNCTIONS
2421//
2422//=================================================================================================
2423
2424//*************************************************************************************************
2442template< typename MT // Type of the adapted dense matrix
2443 , bool SO > // Storage order of the adapted dense matrix
2444template< typename Other > // Data type of the scalar value
2445inline StrictlyUpperMatrix<MT,SO,true>&
2446 StrictlyUpperMatrix<MT,SO,true>::scale( const Other& scalar )
2447{
2448 matrix_.scale( scalar );
2449 return *this;
2450}
2452//*************************************************************************************************
2453
2454
2455
2456
2457//=================================================================================================
2458//
2459// DEBUGGING FUNCTIONS
2460//
2461//=================================================================================================
2462
2463//*************************************************************************************************
2473template< typename MT // Type of the adapted dense matrix
2474 , bool SO > // Storage order of the adapted dense matrix
2475inline bool StrictlyUpperMatrix<MT,SO,true>::isIntact() const noexcept
2476{
2477 using blaze::isIntact;
2478
2479 return ( isIntact( matrix_ ) && isStrictlyUpper( matrix_ ) );
2480}
2482//*************************************************************************************************
2483
2484
2485
2486
2487//=================================================================================================
2488//
2489// EXPRESSION TEMPLATE EVALUATION FUNCTIONS
2490//
2491//=================================================================================================
2492
2493//*************************************************************************************************
2504template< typename MT // Type of the adapted dense matrix
2505 , bool SO > // Storage order of the adapted dense matrix
2506template< typename Other > // Data type of the foreign expression
2507inline bool StrictlyUpperMatrix<MT,SO,true>::canAlias( const Other* alias ) const noexcept
2508{
2509 return matrix_.canAlias( alias );
2510}
2512//*************************************************************************************************
2513
2514
2515//*************************************************************************************************
2526template< typename MT // Type of the adapted dense matrix
2527 , bool SO > // Storage order of the adapted dense matrix
2528template< typename Other > // Data type of the foreign expression
2529inline bool StrictlyUpperMatrix<MT,SO,true>::isAliased( const Other* alias ) const noexcept
2530{
2531 return matrix_.isAliased( alias );
2532}
2534//*************************************************************************************************
2535
2536
2537//*************************************************************************************************
2547template< typename MT // Type of the adapted dense matrix
2548 , bool SO > // Storage order of the adapted dense matrix
2549inline bool StrictlyUpperMatrix<MT,SO,true>::isAligned() const noexcept
2550{
2551 return matrix_.isAligned();
2552}
2554//*************************************************************************************************
2555
2556
2557//*************************************************************************************************
2568template< typename MT // Type of the adapted dense matrix
2569 , bool SO > // Storage order of the adapted dense matrix
2570inline bool StrictlyUpperMatrix<MT,SO,true>::canSMPAssign() const noexcept
2571{
2572 return matrix_.canSMPAssign();
2573}
2575//*************************************************************************************************
2576
2577
2578//*************************************************************************************************
2594template< typename MT // Type of the adapted dense matrix
2595 , bool SO > // Storage order of the adapted dense matrix
2596BLAZE_ALWAYS_INLINE typename StrictlyUpperMatrix<MT,SO,true>::SIMDType
2597 StrictlyUpperMatrix<MT,SO,true>::load( size_t i, size_t j ) const noexcept
2598{
2599 return matrix_.load( i, j );
2600}
2602//*************************************************************************************************
2603
2604
2605//*************************************************************************************************
2621template< typename MT // Type of the adapted dense matrix
2622 , bool SO > // Storage order of the adapted dense matrix
2623BLAZE_ALWAYS_INLINE typename StrictlyUpperMatrix<MT,SO,true>::SIMDType
2624 StrictlyUpperMatrix<MT,SO,true>::loada( size_t i, size_t j ) const noexcept
2625{
2626 return matrix_.loada( i, j );
2627}
2629//*************************************************************************************************
2630
2631
2632//*************************************************************************************************
2648template< typename MT // Type of the adapted dense matrix
2649 , bool SO > // Storage order of the adapted dense matrix
2650BLAZE_ALWAYS_INLINE typename StrictlyUpperMatrix<MT,SO,true>::SIMDType
2651 StrictlyUpperMatrix<MT,SO,true>::loadu( size_t i, size_t j ) const noexcept
2652{
2653 return matrix_.loadu( i, j );
2654}
2656//*************************************************************************************************
2657
2658
2659
2660
2661//=================================================================================================
2662//
2663// CONSTRUCTION FUNCTIONS
2664//
2665//=================================================================================================
2666
2667//*************************************************************************************************
2674template< typename MT // Type of the adapted dense matrix
2675 , bool SO > // Storage order of the adapted dense matrix
2676inline const MT StrictlyUpperMatrix<MT,SO,true>::construct( size_t n, TrueType )
2677{
2679
2680 return MT( n, n, ElementType() );
2681}
2683//*************************************************************************************************
2684
2685
2686//*************************************************************************************************
2693template< typename MT // Type of the adapted dense matrix
2694 , bool SO > // Storage order of the adapted dense matrix
2695inline const MT StrictlyUpperMatrix<MT,SO,true>::construct( const ElementType& init, FalseType )
2696{
2699
2700 MT tmp;
2701
2702 if( SO ) {
2703 for( size_t j=0UL; j<columns(); ++j ) {
2704 for( size_t i=0UL; i<j; ++i )
2705 tmp(i,j) = init;
2706 }
2707 }
2708 else {
2709 for( size_t i=0UL; i<rows(); ++i ) {
2710 for( size_t j=i+1UL; j<columns(); ++j )
2711 tmp(i,j) = init;
2712 }
2713 }
2714
2715 return tmp;
2716}
2718//*************************************************************************************************
2719
2720
2721//*************************************************************************************************
2732template< typename MT // Type of the adapted dense matrix
2733 , bool SO > // Storage order of the adapted dense matrix
2734template< typename MT2 // Type of the foreign matrix
2735 , bool SO2 // Storage order of the foreign matrix
2736 , typename T > // Type of the third argument
2737inline const MT StrictlyUpperMatrix<MT,SO,true>::construct( const Matrix<MT2,SO2>& m, T )
2738{
2739 const MT tmp( *m );
2740
2741 if( IsUniTriangular_v<MT2> ||
2742 ( !IsStrictlyUpper_v<MT2> && !isStrictlyUpper( tmp ) ) ) {
2743 BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of strictly upper matrix" );
2744 }
2745
2746 return tmp;
2747}
2749//*************************************************************************************************
2750
2751} // namespace blaze
2752
2753#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 EnableIf class template.
Constraint on the data type.
Header file for the IntegralConstant class template.
Header file for the IsComputation type trait class.
Header file for the isDefault shim.
Header file for the IsResizable type trait.
Header file for the IsScalar type trait.
Header file for the IsSquare type trait.
Header file for the IsStrictlyUpper type trait.
Header file for the IsUniTriangular 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 StrictlyUpperProxy class.
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 the base template of the StrictlyUpperMatrix.
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) 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
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
bool isStrictlyUpper(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a strictly upper triangular matrix.
Definition: DenseMatrix.h:2363
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) declupp(const DenseMatrix< MT, SO > &dm)
Declares the given dense matrix expression dm as upper.
Definition: DMatDeclUppExpr.h:1004
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 isZero(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a zero matrix.
Definition: DenseMatrix.h:1819
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_BE_STATIC_TYPE(T)
Constraint on the data type.
Definition: Static.h:61
#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.
Header file for all adaptor forward declarations.
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 Submatrix view.