DenseMatrix.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_DENSE_DENSEMATRIX_H_
36 #define _BLAZE_MATH_DENSE_DENSEMATRIX_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <blaze/math/Aliases.h>
48 #include <blaze/math/Functions.h>
50 #include <blaze/math/shims/Equal.h>
52 #include <blaze/math/shims/IsNaN.h>
53 #include <blaze/math/shims/IsOne.h>
70 #include <blaze/util/Assert.h>
71 #include <blaze/util/EnableIf.h>
72 #include <blaze/util/FalseType.h>
73 #include <blaze/util/mpl/If.h>
74 #include <blaze/util/TrueType.h>
75 #include <blaze/util/Types.h>
78 
79 
80 namespace blaze {
81 
82 //=================================================================================================
83 //
84 // GLOBAL OPERATORS
85 //
86 //=================================================================================================
87 
88 //*************************************************************************************************
91 template< typename T1, typename T2 >
92 inline bool operator==( const DenseMatrix<T1,false>& lhs, const DenseMatrix<T2,false>& rhs );
93 
94 template< typename T1, typename T2 >
95 inline bool operator==( const DenseMatrix<T1,true>& lhs, const DenseMatrix<T2,true>& rhs );
96 
97 template< typename T1, typename T2, bool SO >
98 inline bool operator==( const DenseMatrix<T1,SO>& lhs, const DenseMatrix<T2,!SO>& rhs );
99 
100 template< typename T1, typename T2, bool SO >
101 inline bool operator==( const DenseMatrix<T1,SO>& lhs, const SparseMatrix<T2,false>& rhs );
102 
103 template< typename T1, typename T2, bool SO >
104 inline bool operator==( const DenseMatrix<T1,SO>& lhs, const SparseMatrix<T2,true>& rhs );
105 
106 template< typename T1, bool SO1, typename T2, bool SO2 >
107 inline bool operator==( const SparseMatrix<T1,SO1>& lhs, const DenseMatrix<T2,SO2>& rhs );
108 
109 template< typename T1, typename T2 >
110 inline EnableIf_<IsNumeric<T2>, bool > operator==( const DenseMatrix<T1,false>& mat, T2 scalar );
111 
112 template< typename T1, typename T2 >
113 inline EnableIf_<IsNumeric<T2>, bool > operator==( const DenseMatrix<T1,true>& mat, T2 scalar );
114 
115 template< typename T1, typename T2, bool SO >
116 inline EnableIf_<IsNumeric<T2>, bool > operator==( T1 scalar, const DenseMatrix<T2,SO>& mat );
117 
118 template< typename T1, bool SO1, typename T2, bool SO2 >
119 inline bool operator!=( const DenseMatrix<T1,SO1>& lhs, const DenseMatrix<T2,SO2>& rhs );
120 
121 template< typename T1, bool SO1, typename T2, bool SO2 >
122 inline bool operator!=( const DenseMatrix<T1,SO1>& lhs, const SparseMatrix<T2,SO2>& rhs );
123 
124 template< typename T1, bool SO1, typename T2, bool SO2 >
125 inline bool operator!=( const SparseMatrix<T1,SO1>& lhs, const DenseMatrix<T2,SO2>& rhs );
126 
127 template< typename T1, typename T2, bool SO >
128 inline EnableIf_<IsNumeric<T2>, bool > operator!=( const DenseMatrix<T1,SO>& mat, T2 scalar );
129 
130 template< typename T1, typename T2, bool SO >
131 inline EnableIf_<IsNumeric<T2>, bool > operator!=( T1 scalar, const DenseMatrix<T2,SO>& mat );
133 //*************************************************************************************************
134 
135 
136 //*************************************************************************************************
144 template< typename T1 // Type of the left-hand side dense matrix
145  , typename T2 > // Type of the right-hand side dense matrix
146 inline bool operator==( const DenseMatrix<T1,false>& lhs, const DenseMatrix<T2,false>& rhs )
147 {
148  typedef CompositeType_<T1> CT1;
149  typedef CompositeType_<T2> CT2;
150 
151  // Early exit in case the matrix sizes don't match
152  if( (~lhs).rows() != (~rhs).rows() || (~lhs).columns() != (~rhs).columns() )
153  return false;
154 
155  // Evaluation of the two dense matrix operands
156  CT1 A( ~lhs );
157  CT2 B( ~rhs );
158 
159  // In order to compare the two matrices, the data values of the lower-order data
160  // type are converted to the higher-order data type within the equal function.
161  for( size_t i=0; i<A.rows(); ++i ) {
162  for( size_t j=0; j<A.columns(); ++j ) {
163  if( !equal( A(i,j), B(i,j) ) ) return false;
164  }
165  }
166 
167  return true;
168 }
169 //*************************************************************************************************
170 
171 
172 //*************************************************************************************************
180 template< typename T1 // Type of the left-hand side dense matrix
181  , typename T2 > // Type of the right-hand side dense matrix
182 inline bool operator==( const DenseMatrix<T1,true>& lhs, const DenseMatrix<T2,true>& rhs )
183 {
184  typedef CompositeType_<T1> CT1;
185  typedef CompositeType_<T2> CT2;
186 
187  // Early exit in case the matrix sizes don't match
188  if( (~lhs).rows() != (~rhs).rows() || (~lhs).columns() != (~rhs).columns() )
189  return false;
190 
191  // Evaluation of the two dense matrix operands
192  CT1 A( ~lhs );
193  CT2 B( ~rhs );
194 
195  // In order to compare the two matrices, the data values of the lower-order data
196  // type are converted to the higher-order data type within the equal function.
197  for( size_t j=0; j<A.columns(); ++j ) {
198  for( size_t i=0; i<A.rows(); ++i ) {
199  if( !equal( A(i,j), B(i,j) ) ) return false;
200  }
201  }
202 
203  return true;
204 }
205 //*************************************************************************************************
206 
207 
208 //*************************************************************************************************
216 template< typename T1 // Type of the left-hand side dense matrix
217  , typename T2 // Type of the right-hand side dense matrix
218  , bool SO > // Storage order
219 inline bool operator==( const DenseMatrix<T1,SO>& lhs, const DenseMatrix<T2,!SO>& rhs )
220 {
221  typedef CompositeType_<T1> CT1;
222  typedef CompositeType_<T2> CT2;
223 
224  // Early exit in case the matrix sizes don't match
225  if( (~lhs).rows() != (~rhs).rows() || (~lhs).columns() != (~rhs).columns() )
226  return false;
227 
228  // Evaluation of the two dense matrix operands
229  CT1 A( ~lhs );
230  CT2 B( ~rhs );
231 
232  // In order to compare the two matrices, the data values of the lower-order data
233  // type are converted to the higher-order data type within the equal function.
234  const size_t rows ( A.rows() );
235  const size_t columns( A.columns() );
236  const size_t block ( 16 );
237 
238  for( size_t ii=0; ii<rows; ii+=block ) {
239  const size_t iend( ( rows < ii+block )?( rows ):( ii+block ) );
240  for( size_t jj=0; jj<columns; jj+=block ) {
241  const size_t jend( ( columns < jj+block )?( columns ):( jj+block ) );
242  for( size_t i=ii; i<iend; ++i ) {
243  for( size_t j=jj; j<jend; ++j ) {
244  if( !equal( A(i,j), B(i,j) ) ) return false;
245  }
246  }
247  }
248  }
249 
250  return true;
251 }
252 //*************************************************************************************************
253 
254 
255 //*************************************************************************************************
263 template< typename T1 // Type of the left-hand side dense matrix
264  , typename T2 // Type of the right-hand side sparse matrix
265  , bool SO > // Storage order of the left-hand side dense matrix
266 inline bool operator==( const DenseMatrix<T1,SO>& lhs, const SparseMatrix<T2,false>& rhs )
267 {
268  typedef CompositeType_<T1> CT1;
269  typedef CompositeType_<T2> CT2;
271 
272  // Early exit in case the matrix sizes don't match
273  if( (~lhs).rows() != (~rhs).rows() || (~lhs).columns() != (~rhs).columns() )
274  return false;
275 
276  // Evaluation of the dense matrix and sparse matrix operand
277  CT1 A( ~lhs );
278  CT2 B( ~rhs );
279 
280  // In order to compare the two matrices, the data values of the lower-order data
281  // type are converted to the higher-order data type within the equal function.
282  size_t j( 0 );
283 
284  for( size_t i=0; i<B.rows(); ++i ) {
285  j = 0;
286  for( ConstIterator element=B.begin(i); element!=B.end(i); ++element, ++j ) {
287  for( ; j<element->index(); ++j ) {
288  if( !isDefault( A(i,j) ) ) return false;
289  }
290  if( !equal( element->value(), A(i,j) ) ) return false;
291  }
292  for( ; j<A.columns(); ++j ) {
293  if( !isDefault( A(i,j) ) ) return false;
294  }
295  }
296 
297  return true;
298 }
299 //*************************************************************************************************
300 
301 
302 //*************************************************************************************************
310 template< typename T1 // Type of the left-hand side dense matrix
311  , typename T2 // Type of the right-hand side sparse matrix
312  , bool SO > // Storage order of the left-hand side dense matrix
313 inline bool operator==( const DenseMatrix<T1,SO>& lhs, const SparseMatrix<T2,true>& rhs )
314 {
315  typedef CompositeType_<T1> CT1;
316  typedef CompositeType_<T2> CT2;
318 
319  // Early exit in case the matrix sizes don't match
320  if( (~lhs).rows() != (~rhs).rows() || (~lhs).columns() != (~rhs).columns() )
321  return false;
322 
323  // Evaluation of the dense matrix and sparse matrix operand
324  CT1 A( ~lhs );
325  CT2 B( ~rhs );
326 
327  // In order to compare the two matrices, the data values of the lower-order data
328  // type are converted to the higher-order data type within the equal function.
329  size_t i( 0 );
330 
331  for( size_t j=0; j<B.columns(); ++j ) {
332  i = 0;
333  for( ConstIterator element=B.begin(j); element!=B.end(j); ++element, ++i ) {
334  for( ; i<element->index(); ++i ) {
335  if( !isDefault( A(i,j) ) ) return false;
336  }
337  if( !equal( element->value(), A(i,j) ) ) return false;
338  }
339  for( ; i<A.rows(); ++i ) {
340  if( !isDefault( A(i,j) ) ) return false;
341  }
342  }
343 
344  return true;
345 }
346 //*************************************************************************************************
347 
348 
349 //*************************************************************************************************
357 template< typename T1 // Type of the left-hand side sparse matrix
358  , bool SO1 // Storage order of the left-hand side sparse matrix
359  , typename T2 // Type of the right-hand side dense matrix
360  , bool SO2 > // Storage order of the right-hand side sparse matrix
361 inline bool operator==( const SparseMatrix<T1,SO1>& lhs, const DenseMatrix<T2,SO2>& rhs )
362 {
363  return ( rhs == lhs );
364 }
365 //*************************************************************************************************
366 
367 
368 //*************************************************************************************************
380 template< typename T1 // Type of the left-hand side dense matrix
381  , typename T2 > // Type of the right-hand side scalar
382 inline EnableIf_<IsNumeric<T2>, bool > operator==( const DenseMatrix<T1,false>& mat, T2 scalar )
383 {
384  typedef CompositeType_<T1> CT1;
385 
386  // Evaluation of the dense matrix operand
387  CT1 A( ~mat );
388 
389  // In order to compare the matrix and the scalar value, the data values of the lower-order
390  // data type are converted to the higher-order data type within the equal function.
391  for( size_t i=0; i<A.rows(); ++i ) {
392  for( size_t j=0; j<A.columns(); ++j ) {
393  if( !equal( A(i,j), scalar ) ) return false;
394  }
395  }
396 
397  return true;
398 }
399 //*************************************************************************************************
400 
401 
402 //*************************************************************************************************
414 template< typename T1 // Type of the left-hand side dense matrix
415  , typename T2 > // Type of the right-hand side scalar
416 inline EnableIf_<IsNumeric<T2>, bool > operator==( const DenseMatrix<T1,true>& mat, T2 scalar )
417 {
418  typedef CompositeType_<T1> CT1;
419 
420  // Evaluation of the dense matrix operand
421  CT1 A( ~mat );
422 
423  // In order to compare the matrix and the scalar value, the data values of the lower-order
424  // data type are converted to the higher-order data type within the equal function.
425  for( size_t j=0; j<A.columns(); ++j ) {
426  for( size_t i=0; i<A.rows(); ++i ) {
427  if( !equal( A(i,j), scalar ) ) return false;
428  }
429  }
430 
431  return true;
432 }
433 //*************************************************************************************************
434 
435 
436 //*************************************************************************************************
448 template< typename T1 // Type of the left-hand side scalar
449  , typename T2 // Type of the right-hand side dense matrix
450  , bool SO > // Storage order
451 inline EnableIf_<IsNumeric<T1>, bool > operator==( T1 scalar, const DenseMatrix<T2,SO>& mat )
452 {
453  return ( mat == scalar );
454 }
455 //*************************************************************************************************
456 
457 
458 //*************************************************************************************************
466 template< typename T1 // Type of the left-hand side dense matrix
467  , bool SO1 // Storage order of the left-hand side dense matrix
468  , typename T2 // Type of the right-hand side dense matrix
469  , bool SO2 > // Storage order of the right-hand side dense matrix
470 inline bool operator!=( const DenseMatrix<T1,SO1>& lhs, const DenseMatrix<T2,SO2>& rhs )
471 {
472  return !( lhs == rhs );
473 }
474 //*************************************************************************************************
475 
476 
477 //*************************************************************************************************
485 template< typename T1 // Type of the left-hand side dense matrix
486  , bool SO1 // Storage order of the left-hand side dense matrix
487  , typename T2 // Type of the right-hand side sparse matrix
488  , bool SO2 > // Storage order of the right-hand side sparse matrix
489 inline bool operator!=( const DenseMatrix<T1,SO1>& lhs, const SparseMatrix<T2,SO2>& rhs )
490 {
491  return !( lhs == rhs );
492 }
493 //*************************************************************************************************
494 
495 
496 //*************************************************************************************************
504 template< typename T1 // Type of the left-hand side sparse matrix
505  , bool SO1 // Storage order of the left-hand side sparse matrix
506  , typename T2 // Type of the right-hand side dense matrix
507  , bool SO2 > // Storage order right-hand side dense matrix
508 inline bool operator!=( const SparseMatrix<T1,SO1>& lhs, const DenseMatrix<T2,SO2>& rhs )
509 {
510  return !( rhs == lhs );
511 }
512 //*************************************************************************************************
513 
514 
515 //*************************************************************************************************
527 template< typename T1 // Type of the left-hand side dense matrix
528  , typename T2 // Type of the right-hand side scalar
529  , bool SO > // Storage order
530 inline EnableIf_<IsNumeric<T2>, bool > operator!=( const DenseMatrix<T1,SO>& mat, T2 scalar )
531 {
532  return !( mat == scalar );
533 }
534 //*************************************************************************************************
535 
536 
537 //*************************************************************************************************
549 template< typename T1 // Type of the left-hand side scalar
550  , typename T2 // Type of the right-hand side dense matrix
551  , bool SO > // Storage order
552 inline EnableIf_<IsNumeric<T1>, bool > operator!=( T1 scalar, const DenseMatrix<T2,SO>& mat )
553 {
554  return !( mat == scalar );
555 }
556 //*************************************************************************************************
557 
558 
559 
560 
561 //=================================================================================================
562 //
563 // GLOBAL FUNCTIONS
564 //
565 //=================================================================================================
566 
567 //*************************************************************************************************
570 template< typename MT, bool SO >
571 bool isnan( const DenseMatrix<MT,SO>& dm );
572 
573 template< typename MT, bool SO >
574 bool isSymmetric( const DenseMatrix<MT,SO>& dm );
575 
576 template< typename MT, bool SO >
577 bool isHermitian( const DenseMatrix<MT,SO>& dm );
578 
579 template< typename MT, bool SO >
580 bool isUniform( const DenseMatrix<MT,SO>& dm );
581 
582 template< typename MT, bool SO >
583 bool isLower( const DenseMatrix<MT,SO>& dm );
584 
585 template< typename MT, bool SO >
586 bool isUniLower( const DenseMatrix<MT,SO>& dm );
587 
588 template< typename MT, bool SO >
589 bool isStrictlyLower( const DenseMatrix<MT,SO>& dm );
590 
591 template< typename MT, bool SO >
592 bool isUpper( const DenseMatrix<MT,SO>& dm );
593 
594 template< typename MT, bool SO >
595 bool isUniUpper( const DenseMatrix<MT,SO>& dm );
596 
597 template< typename MT, bool SO >
598 bool isStrictlyUpper( const DenseMatrix<MT,SO>& dm );
599 
600 template< typename MT, bool SO >
601 bool isDiagonal( const DenseMatrix<MT,SO>& dm );
602 
603 template< typename MT, bool SO >
604 bool isIdentity( const DenseMatrix<MT,SO>& dm );
605 
606 template< typename MT, bool SO >
607 const ElementType_<MT> min( const DenseMatrix<MT,SO>& dm );
608 
609 template< typename MT, bool SO >
610 const ElementType_<MT> max( const DenseMatrix<MT,SO>& dm );
612 //*************************************************************************************************
613 
614 
615 //*************************************************************************************************
635 template< typename MT // Type of the dense matrix
636  , bool SO > // Storage order
637 bool isnan( const DenseMatrix<MT,SO>& dm )
638 {
639  typedef CompositeType_<MT> CT;
640 
641  CT A( ~dm ); // Evaluation of the dense matrix operand
642 
643  if( SO == rowMajor ) {
644  for( size_t i=0UL; i<A.rows(); ++i ) {
645  for( size_t j=0UL; j<A.columns(); ++j )
646  if( isnan( A(i,j) ) ) return true;
647  }
648  }
649  else {
650  for( size_t j=0UL; j<A.columns(); ++j ) {
651  for( size_t i=0UL; i<A.rows(); ++i )
652  if( isnan( A(i,j) ) ) return true;
653  }
654  }
655 
656  return false;
657 }
658 //*************************************************************************************************
659 
660 
661 //*************************************************************************************************
687 template< typename MT // Type of the dense matrix
688  , bool SO > // Storage order
690 {
691  typedef CompositeType_<MT> CT;
692 
694  return true;
695 
696  if( !isSquare( ~dm ) )
697  return false;
698 
699  if( (~dm).rows() < 2UL )
700  return true;
701 
703  return isDiagonal( ~dm );
704 
705  CT A( ~dm ); // Evaluation of the dense matrix operand
706 
707  if( SO == rowMajor ) {
708  for( size_t i=1UL; i<A.rows(); ++i ) {
709  for( size_t j=0UL; j<i; ++j ) {
710  if( !equal( A(i,j), A(j,i) ) )
711  return false;
712  }
713  }
714  }
715  else {
716  for( size_t j=1UL; j<A.columns(); ++j ) {
717  for( size_t i=0UL; i<j; ++i ) {
718  if( !equal( A(i,j), A(j,i) ) )
719  return false;
720  }
721  }
722  }
723 
724  return true;
725 }
726 //*************************************************************************************************
727 
728 
729 //*************************************************************************************************
757 template< typename MT // Type of the dense matrix
758  , bool SO > // Storage order
760 {
761  typedef ElementType_<MT> ET;
762  typedef CompositeType_<MT> CT;
763 
765  return true;
766 
767  if( !IsNumeric<ET>::value || !isSquare( ~dm ) )
768  return false;
769 
770  if( (~dm).rows() < 2UL )
771  return true;
772 
774  return isDiagonal( ~dm );
775 
776  CT A( ~dm ); // Evaluation of the dense matrix operand
777 
778  if( SO == rowMajor ) {
779  for( size_t i=0UL; i<A.rows(); ++i ) {
780  for( size_t j=0UL; j<i; ++j ) {
781  if( !equal( A(i,j), conj( A(j,i) ) ) )
782  return false;
783  }
784  if( !isReal( A(i,i) ) )
785  return false;
786  }
787  }
788  else {
789  for( size_t j=0UL; j<A.columns(); ++j ) {
790  for( size_t i=0UL; i<j; ++i ) {
791  if( !equal( A(i,j), conj( A(j,i) ) ) )
792  return false;
793  }
794  if( !isReal( A(j,j) ) )
795  return false;
796  }
797  }
798 
799  return true;
800 }
801 //*************************************************************************************************
802 
803 
804 //*************************************************************************************************
812 template< typename MT > // Type of the dense matrix
813 bool isUniform_backend( const DenseMatrix<MT,false>& dm, TrueType )
814 {
817 
818  BLAZE_INTERNAL_ASSERT( (~dm).rows() != 0UL, "Invalid number of rows detected" );
819  BLAZE_INTERNAL_ASSERT( (~dm).columns() != 0UL, "Invalid number of columns detected" );
820 
821  const size_t ibegin( ( IsStrictlyLower<MT>::value )?( 1UL ):( 0UL ) );
822  const size_t iend ( ( IsStrictlyUpper<MT>::value )?( (~dm).rows()-1UL ):( (~dm).rows() ) );
823 
824  for( size_t i=ibegin; i<iend; ++i ) {
825  if( !IsUpper<MT>::value ) {
826  for( size_t j=0UL; j<i; ++j ) {
827  if( !isDefault( (~dm)(i,j) ) )
828  return false;
829  }
830  }
831  if( !isDefault( (~dm)(i,i) ) )
832  return false;
833  if( !IsLower<MT>::value ) {
834  for( size_t j=i+1UL; j<(~dm).columns(); ++j ) {
835  if( !isDefault( (~dm)(i,j) ) )
836  return false;
837  }
838  }
839  }
840 
841  return true;
842 }
844 //*************************************************************************************************
845 
846 
847 //*************************************************************************************************
855 template< typename MT > // Type of the dense matrix
856 bool isUniform_backend( const DenseMatrix<MT,true>& dm, TrueType )
857 {
860 
861  BLAZE_INTERNAL_ASSERT( (~dm).rows() != 0UL, "Invalid number of rows detected" );
862  BLAZE_INTERNAL_ASSERT( (~dm).columns() != 0UL, "Invalid number of columns detected" );
863 
864  const size_t jbegin( ( IsStrictlyUpper<MT>::value )?( 1UL ):( 0UL ) );
865  const size_t jend ( ( IsStrictlyLower<MT>::value )?( (~dm).columns()-1UL ):( (~dm).columns() ) );
866 
867  for( size_t j=jbegin; j<jend; ++j ) {
868  if( !IsLower<MT>::value ) {
869  for( size_t i=0UL; i<j; ++i ) {
870  if( !isDefault( (~dm)(i,j) ) )
871  return false;
872  }
873  }
874  if( !isDefault( (~dm)(j,j) ) )
875  return false;
876  if( !IsUpper<MT>::value ) {
877  for( size_t i=j+1UL; i<(~dm).rows(); ++i ) {
878  if( !isDefault( (~dm)(i,j) ) )
879  return false;
880  }
881  }
882  }
883 
884  return true;
885 }
887 //*************************************************************************************************
888 
889 
890 //*************************************************************************************************
898 template< typename MT > // Type of the dense matrix
899 bool isUniform_backend( const DenseMatrix<MT,false>& dm, FalseType )
900 {
903 
904  BLAZE_INTERNAL_ASSERT( (~dm).rows() != 0UL, "Invalid number of rows detected" );
905  BLAZE_INTERNAL_ASSERT( (~dm).columns() != 0UL, "Invalid number of columns detected" );
906 
907  ConstReference_<MT> cmp( (~dm)(0UL,0UL) );
908 
909  for( size_t i=0UL; i<(~dm).rows(); ++i ) {
910  for( size_t j=0UL; j<(~dm).columns(); ++j ) {
911  if( (~dm)(i,j) != cmp )
912  return false;
913  }
914  }
915 
916  return true;
917 }
919 //*************************************************************************************************
920 
921 
922 //*************************************************************************************************
930 template< typename MT > // Type of the dense matrix
931 bool isUniform_backend( const DenseMatrix<MT,true>& dm, FalseType )
932 {
935 
936  BLAZE_INTERNAL_ASSERT( (~dm).rows() != 0UL, "Invalid number of rows detected" );
937  BLAZE_INTERNAL_ASSERT( (~dm).columns() != 0UL, "Invalid number of columns detected" );
938 
939  ConstReference_<MT> cmp( (~dm)(0UL,0UL) );
940 
941  for( size_t j=0UL; j<(~dm).columns(); ++j ) {
942  for( size_t i=0UL; i<(~dm).rows(); ++i ) {
943  if( (~dm)(i,j) != cmp )
944  return false;
945  }
946  }
947 
948  return true;
949 }
951 //*************************************************************************************************
952 
953 
954 //*************************************************************************************************
980 template< typename MT // Type of the dense matrix
981  , bool SO > // Storage order
982 bool isUniform( const DenseMatrix<MT,SO>& dm )
983 {
985  return false;
986 
987  if( (~dm).rows() == 0UL || (~dm).columns() == 0UL ||
988  ( (~dm).rows() == 1UL && (~dm).columns() == 1UL ) )
989  return true;
990 
991  CompositeType_<MT> A( ~dm ); // Evaluation of the dense matrix operand
992 
993  return isUniform_backend( A, typename IsTriangular<MT>::Type() );
994 }
995 //*************************************************************************************************
996 
997 
998 //*************************************************************************************************
1034 template< typename MT // Type of the dense matrix
1035  , bool SO > // Storage order
1036 bool isLower( const DenseMatrix<MT,SO>& dm )
1037 {
1038  typedef ResultType_<MT> RT;
1039  typedef ReturnType_<MT> RN;
1040  typedef CompositeType_<MT> CT;
1041  typedef If_< IsExpression<RN>, const RT, CT > Tmp;
1042 
1043  if( IsLower<MT>::value )
1044  return true;
1045 
1046  if( !isSquare( ~dm ) )
1047  return false;
1048 
1049  if( (~dm).rows() < 2UL )
1050  return true;
1051 
1052  Tmp A( ~dm ); // Evaluation of the dense matrix operand
1053 
1054  if( SO == rowMajor ) {
1055  for( size_t i=0UL; i<A.rows()-1UL; ++i ) {
1056  for( size_t j=i+1UL; j<A.columns(); ++j ) {
1057  if( !isDefault( A(i,j) ) )
1058  return false;
1059  }
1060  }
1061  }
1062  else {
1063  for( size_t j=1UL; j<A.columns(); ++j ) {
1064  for( size_t i=0UL; i<j; ++i ) {
1065  if( !isDefault( A(i,j) ) )
1066  return false;
1067  }
1068  }
1069  }
1070 
1071  return true;
1072 }
1073 //*************************************************************************************************
1074 
1075 
1076 //*************************************************************************************************
1111 template< typename MT // Type of the dense matrix
1112  , bool SO > // Storage order
1114 {
1115  typedef ResultType_<MT> RT;
1116  typedef ReturnType_<MT> RN;
1117  typedef CompositeType_<MT> CT;
1118  typedef If_< IsExpression<RN>, const RT, CT > Tmp;
1119 
1120  if( IsUniLower<MT>::value )
1121  return true;
1122 
1123  if( !isSquare( ~dm ) )
1124  return false;
1125 
1126  Tmp A( ~dm ); // Evaluation of the dense matrix operand
1127 
1128  if( SO == rowMajor ) {
1129  for( size_t i=0UL; i<A.rows(); ++i ) {
1130  if( !isOne( A(i,i) ) )
1131  return false;
1132  for( size_t j=i+1UL; j<A.columns(); ++j ) {
1133  if( !isZero( A(i,j) ) )
1134  return false;
1135  }
1136  }
1137  }
1138  else {
1139  for( size_t j=0UL; j<A.columns(); ++j ) {
1140  for( size_t i=0UL; i<j; ++i ) {
1141  if( !isZero( A(i,j) ) )
1142  return false;
1143  }
1144  if( !isOne( A(j,j) ) )
1145  return false;
1146  }
1147  }
1148 
1149  return true;
1150 }
1151 //*************************************************************************************************
1152 
1153 
1154 //*************************************************************************************************
1190 template< typename MT // Type of the dense matrix
1191  , bool SO > // Storage order
1193 {
1194  typedef ResultType_<MT> RT;
1195  typedef ReturnType_<MT> RN;
1196  typedef CompositeType_<MT> CT;
1197  typedef If_< IsExpression<RN>, const RT, CT > Tmp;
1198 
1200  return true;
1201 
1203  return false;
1204 
1205  Tmp A( ~dm ); // Evaluation of the dense matrix operand
1206 
1207  if( SO == rowMajor ) {
1208  for( size_t i=0UL; i<A.rows(); ++i ) {
1209  for( size_t j=i; j<A.columns(); ++j ) {
1210  if( !isDefault( A(i,j) ) )
1211  return false;
1212  }
1213  }
1214  }
1215  else {
1216  for( size_t j=0UL; j<A.columns(); ++j ) {
1217  for( size_t i=0UL; i<=j; ++i ) {
1218  if( !isDefault( A(i,j) ) )
1219  return false;
1220  }
1221  }
1222  }
1223 
1224  return true;
1225 }
1226 //*************************************************************************************************
1227 
1228 
1229 //*************************************************************************************************
1265 template< typename MT // Type of the dense matrix
1266  , bool SO > // Storage order
1267 bool isUpper( const DenseMatrix<MT,SO>& dm )
1268 {
1269  typedef ResultType_<MT> RT;
1270  typedef ReturnType_<MT> RN;
1271  typedef CompositeType_<MT> CT;
1272  typedef If_< IsExpression<RN>, const RT, CT > Tmp;
1273 
1274  if( IsUpper<MT>::value )
1275  return true;
1276 
1277  if( !isSquare( ~dm ) )
1278  return false;
1279 
1280  if( (~dm).rows() < 2UL )
1281  return true;
1282 
1283  Tmp A( ~dm ); // Evaluation of the dense matrix operand
1284 
1285  if( SO == rowMajor ) {
1286  for( size_t i=1UL; i<A.rows(); ++i ) {
1287  for( size_t j=0UL; j<i; ++j ) {
1288  if( !isDefault( A(i,j) ) )
1289  return false;
1290  }
1291  }
1292  }
1293  else {
1294  for( size_t j=0UL; j<A.columns()-1UL; ++j ) {
1295  for( size_t i=j+1UL; i<A.rows(); ++i ) {
1296  if( !isDefault( A(i,j) ) )
1297  return false;
1298  }
1299  }
1300  }
1301 
1302  return true;
1303 }
1304 //*************************************************************************************************
1305 
1306 
1307 //*************************************************************************************************
1342 template< typename MT // Type of the dense matrix
1343  , bool SO > // Storage order
1345 {
1346  typedef ResultType_<MT> RT;
1347  typedef ReturnType_<MT> RN;
1348  typedef CompositeType_<MT> CT;
1349  typedef If_< IsExpression<RN>, const RT, CT > Tmp;
1350 
1351  if( IsUniUpper<MT>::value )
1352  return true;
1353 
1354  if( !isSquare( ~dm ) )
1355  return false;
1356 
1357  Tmp A( ~dm ); // Evaluation of the dense matrix operand
1358 
1359  if( SO == rowMajor ) {
1360  for( size_t i=0UL; i<A.rows(); ++i ) {
1361  for( size_t j=0UL; j<i; ++j ) {
1362  if( !isZero( A(i,j) ) )
1363  return false;
1364  }
1365  if( !isOne( A(i,i) ) )
1366  return false;
1367  }
1368  }
1369  else {
1370  for( size_t j=0UL; j<A.columns(); ++j ) {
1371  if( !isOne( A(j,j) ) )
1372  return false;
1373  for( size_t i=j+1UL; i<A.rows(); ++i ) {
1374  if( !isZero( A(i,j) ) )
1375  return false;
1376  }
1377  }
1378  }
1379 
1380  return true;
1381 }
1382 //*************************************************************************************************
1383 
1384 
1385 //*************************************************************************************************
1421 template< typename MT // Type of the dense matrix
1422  , bool SO > // Storage order
1424 {
1425  typedef ResultType_<MT> RT;
1426  typedef ReturnType_<MT> RN;
1427  typedef CompositeType_<MT> CT;
1428  typedef If_< IsExpression<RN>, const RT, CT > Tmp;
1429 
1431  return true;
1432 
1434  return false;
1435 
1436  Tmp A( ~dm ); // Evaluation of the dense matrix operand
1437 
1438  if( SO == rowMajor ) {
1439  for( size_t i=0UL; i<A.rows(); ++i ) {
1440  for( size_t j=0UL; j<=i; ++j ) {
1441  if( !isDefault( A(i,j) ) )
1442  return false;
1443  }
1444  }
1445  }
1446  else {
1447  for( size_t j=0UL; j<A.columns(); ++j ) {
1448  for( size_t i=j; i<A.rows(); ++i ) {
1449  if( !isDefault( A(i,j) ) )
1450  return false;
1451  }
1452  }
1453  }
1454 
1455  return true;
1456 }
1457 //*************************************************************************************************
1458 
1459 
1460 //*************************************************************************************************
1497 template< typename MT // Type of the dense matrix
1498  , bool SO > // Storage order
1500 {
1501  typedef ResultType_<MT> RT;
1502  typedef ReturnType_<MT> RN;
1503  typedef CompositeType_<MT> CT;
1504  typedef If_< IsExpression<RN>, const RT, CT > Tmp;
1505 
1506  if( IsDiagonal<MT>::value )
1507  return true;
1508 
1509  if( !isSquare( ~dm ) )
1510  return false;
1511 
1512  if( (~dm).rows() < 2UL )
1513  return true;
1514 
1515  Tmp A( ~dm ); // Evaluation of the dense matrix operand
1516 
1517  if( SO == rowMajor ) {
1518  for( size_t i=0UL; i<A.rows(); ++i ) {
1519  if( !IsUpper<MT>::value ) {
1520  for( size_t j=0UL; j<i; ++j ) {
1521  if( !isDefault( A(i,j) ) )
1522  return false;
1523  }
1524  }
1525  if( !IsLower<MT>::value ) {
1526  for( size_t j=i+1UL; j<A.columns(); ++j ) {
1527  if( !isDefault( A(i,j) ) )
1528  return false;
1529  }
1530  }
1531  }
1532  }
1533  else {
1534  for( size_t j=0UL; j<A.columns(); ++j ) {
1535  if( !IsLower<MT>::value ) {
1536  for( size_t i=0UL; i<j; ++i ) {
1537  if( !isDefault( A(i,j) ) )
1538  return false;
1539  }
1540  }
1541  if( !IsUpper<MT>::value ) {
1542  for( size_t i=j+1UL; i<A.rows(); ++i ) {
1543  if( !isDefault( A(i,j) ) )
1544  return false;
1545  }
1546  }
1547  }
1548  }
1549 
1550  return true;
1551 }
1552 //*************************************************************************************************
1553 
1554 
1555 //*************************************************************************************************
1591 template< typename MT // Type of the dense matrix
1592  , bool SO > // Storage order
1594 {
1595  typedef ResultType_<MT> RT;
1596  typedef ReturnType_<MT> RN;
1597  typedef CompositeType_<MT> CT;
1598  typedef If_< IsExpression<RN>, const RT, CT > Tmp;
1599 
1600  if( IsIdentity<MT>::value )
1601  return true;
1602 
1603  if( !isSquare( ~dm ) )
1604  return false;
1605 
1606  if( (~dm).rows() == 0UL )
1607  return true;
1608 
1609  Tmp A( ~dm ); // Evaluation of the dense matrix operand
1610 
1611  if( SO == rowMajor ) {
1612  for( size_t i=0UL; i<A.rows(); ++i ) {
1613  if( !IsUpper<MT>::value ) {
1614  for( size_t j=0UL; j<i; ++j ) {
1615  if( !isZero( A(i,j) ) )
1616  return false;
1617  }
1618  }
1619  if( !IsUniLower<MT>::value && !IsUniUpper<MT>::value && !isOne( A(i,i) ) ) {
1620  return false;
1621  }
1622  if( !IsLower<MT>::value ) {
1623  for( size_t j=i+1UL; j<A.columns(); ++j ) {
1624  if( !isZero( A(i,j) ) )
1625  return false;
1626  }
1627  }
1628  }
1629  }
1630  else {
1631  for( size_t j=0UL; j<A.columns(); ++j ) {
1632  if( !IsLower<MT>::value ) {
1633  for( size_t i=0UL; i<j; ++i ) {
1634  if( !isZero( A(i,j) ) )
1635  return false;
1636  }
1637  }
1638  if( !IsUniLower<MT>::value && !IsUniUpper<MT>::value && !isOne( A(j,j) ) ) {
1639  return false;
1640  }
1641  if( !IsUpper<MT>::value ) {
1642  for( size_t i=j+1UL; i<A.rows(); ++i ) {
1643  if( !isZero( A(i,j) ) )
1644  return false;
1645  }
1646  }
1647  }
1648  }
1649 
1650  return true;
1651 }
1652 //*************************************************************************************************
1653 
1654 
1655 //*************************************************************************************************
1667 template< typename MT // Type of the dense matrix
1668  , bool SO > // Storage order
1670 {
1671  using blaze::min;
1672 
1673  typedef ElementType_<MT> ET;
1674  typedef CompositeType_<MT> CT;
1675 
1676  CT A( ~dm ); // Evaluation of the dense matrix operand
1677 
1678  if( A.rows() == 0UL || A.columns() == 0UL ) return ET();
1679 
1680  ET minimum( A(0,0) );
1681 
1682  if( SO == rowMajor ) {
1683  for( size_t j=1UL; j<A.columns(); ++j )
1684  minimum = min( minimum, A(0UL,j) );
1685  for( size_t i=1UL; i<A.rows(); ++i )
1686  for( size_t j=0UL; j<A.columns(); ++j )
1687  minimum = min( minimum, A(i,j) );
1688  }
1689  else {
1690  for( size_t i=1UL; i<A.rows(); ++i )
1691  minimum = min( minimum, A(i,0UL) );
1692  for( size_t j=1UL; j<A.columns(); ++j )
1693  for( size_t i=0UL; i<A.rows(); ++i )
1694  minimum = min( minimum, A(i,j) );
1695  }
1696 
1697  return minimum;
1698 }
1699 //*************************************************************************************************
1700 
1701 
1702 //*************************************************************************************************
1714 template< typename MT // Type of the dense matrix
1715  , bool SO > // Transpose flag
1717 {
1718  using blaze::max;
1719 
1720  typedef ElementType_<MT> ET;
1721  typedef CompositeType_<MT> CT;
1722 
1723  CT A( ~dm ); // Evaluation of the dense matrix operand
1724 
1725  if( A.rows() == 0UL || A.columns() == 0UL ) return ET();
1726 
1727  ET maximum( A(0,0) );
1728 
1729  if( SO == rowMajor ) {
1730  for( size_t j=1UL; j<A.columns(); ++j )
1731  maximum = max( maximum, A(0UL,j) );
1732  for( size_t i=1UL; i<A.rows(); ++i )
1733  for( size_t j=0UL; j<A.columns(); ++j )
1734  maximum = max( maximum, A(i,j) );
1735  }
1736  else {
1737  for( size_t i=1UL; i<A.rows(); ++i )
1738  maximum = max( maximum, A(i,0UL) );
1739  for( size_t j=1UL; j<A.columns(); ++j )
1740  for( size_t i=0UL; i<A.rows(); ++i )
1741  maximum = max( maximum, A(i,j) );
1742  }
1743 
1744  return maximum;
1745 }
1746 //*************************************************************************************************
1747 
1748 } // namespace blaze
1749 
1750 #endif
#define BLAZE_CONSTRAINT_MUST_BE_TRIANGULAR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a lower or upper triangular matrix t...
Definition: Triangular.h:61
Header file for the isnan shim.
BoolConstant< false > FalseType
Type/value traits base class.The FalseType class is used as base class for type traits and value trai...
Definition: FalseType.h:61
bool isOne(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 1.
Definition: DiagonalProxy.h:635
const DMatForEachExpr< MT, Conj, SO > conj(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the complex conjugate of each single element of dm.
Definition: DMatForEachExpr.h:1158
Header file for auxiliary alias declarations.
Compile time check for numeric types.This type trait tests whether or not the given template paramete...
Definition: IsNumeric.h:79
Header file for mathematical functions.
bool isDiagonal(const DenseMatrix< MT, SO > &dm)
Checks if the give dense matrix is diagonal.
Definition: DenseMatrix.h:1499
Header file for the IsUniUpper type trait.
Compile time check for triangular matrix types.This type trait tests whether or not the given templat...
Definition: IsTriangular.h:87
Header file for basic type definitions.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_TRIANGULAR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a lower or upper triangular matrix type...
Definition: Triangular.h:81
bool isStrictlyLower(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a strictly lower triangular matrix.
Definition: DenseMatrix.h:1192
bool isStrictlyUpper(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a strictly upper triangular matrix.
Definition: DenseMatrix.h:1423
Header file for the FalseType type/value trait base class.
bool isReal(const DiagonalProxy< MT > &proxy)
Returns whether the matrix element represents a real number.
Definition: DiagonalProxy.h:595
Header file for the IsDiagonal type trait.
bool isSymmetric(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is symmetric.
Definition: DenseMatrix.h:689
const ElementType_< MT > min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1669
Compile time check for lower triangular matrices.This type trait tests whether or not the given templ...
Definition: IsLower.h:88
Header file for the IsIdentity type trait.
Compile time check for upper triangular matrices.This type trait tests whether or not the given templ...
Definition: IsUpper.h:88
BoolConstant< true > TrueType
Type traits base class.The TrueType class is used as base class for type traits and value traits that...
Definition: TrueType.h:61
Header file for the IsUniLower type trait.
typename T::ResultType ResultType_
Alias declaration for nested ResultType type definitions.The ResultType_ alias declaration provides a...
Definition: Aliases.h:323
const ElementType_< MT > max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:1716
bool isLower(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a lower triangular matrix.
Definition: DenseMatrix.h:1036
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes...
Definition: DenseMatrix.h:70
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:109
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:573
typename T::ReturnType ReturnType_
Alias declaration for nested ReturnType type definitions.The ReturnType_ alias declaration provides a...
Definition: Aliases.h:343
Header file for the SparseMatrix base class.
Header file for the matrix storage order types.
Constraint on the data type.
typename T::CompositeType CompositeType_
Alias declaration for nested CompositeType type definitions.The CompositeType_ alias declaration prov...
Definition: Aliases.h:83
Compile time check for upper unitriangular matrices.This type trait tests whether or not the given te...
Definition: IsUniUpper.h:86
Header file for the IsStrictlyUpper type trait.
Header file for the IsSymmetric type trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for the If class template.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2647
Header file for the DenseMatrix base class.
Header file for the isZero shim.
typename T::ElementType ElementType_
Alias declaration for nested ElementType type definitions.The ElementType_ alias declaration provides...
Definition: Aliases.h:163
Header file for the IsLower type trait.
Compile time check for diagonal matrices.This type trait tests whether or not the given template para...
Definition: IsDiagonal.h:90
BLAZE_ALWAYS_INLINE size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:330
Header file for the equal shim.
Header file for the IsUniTriangular type trait.
Header file for the IsTriangular type trait.
bool isUpper(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is an upper triangular matrix.
Definition: DenseMatrix.h:1267
Compile time check for symmetric matrices.This type trait tests whether or not the given template par...
Definition: IsSymmetric.h:85
bool isnan(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is not a number.
Definition: DiagonalProxy.h:655
Compile time check for strictly upper triangular matrices.This type trait tests whether or not the gi...
Definition: IsStrictlyUpper.h:86
bool isUniLower(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a lower unitriangular matrix.
Definition: DenseMatrix.h:1113
Constraint on the data type.
Header file for the EnableIf class template.
Header file for the IsStrictlyLower type trait.
Header file for the isOne shim.
Compile time check for lower unitriangular matrices.This type trait tests whether or not the given te...
Definition: IsUniLower.h:86
Header file for the conjugate shim.
Header file for the IsNumeric type trait.
Compile time check for identity matrices.This type trait tests whether or not the given template para...
Definition: IsIdentity.h:90
Header file for run time assertion macros.
bool equal(const T1 &a, const T2 &b)
Generic equality check.
Definition: Equal.h:73
typename If< T1, T2, T3 >::Type If_
Auxiliary alias declaration for the If class template.The If_ alias declaration provides a convenient...
Definition: If.h:160
Header file for the isDefault shim.
Compile time check for Hermitian matrices.This type trait tests whether or not the given template par...
Definition: IsHermitian.h:85
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.In case the given data type T requires an intermediate evaluation within ...
Definition: RequiresEvaluation.h:81
Header file for the RemoveReference type trait.
typename EnableIf< Condition, T >::Type EnableIf_
Auxiliary alias declaration for the EnableIf class template.The EnableIf_ alias declaration provides ...
Definition: EnableIf.h:223
Compile time check for strictly lower triangular matrices.This type trait tests whether or not the gi...
Definition: IsStrictlyLower.h:86
BLAZE_ALWAYS_INLINE size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:314
typename T::ConstIterator ConstIterator_
Alias declaration for nested ConstIterator type definitions.The ConstIterator_ alias declaration prov...
Definition: Aliases.h:103
bool isUniform(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a uniform matrix.
Definition: DenseMatrix.h:982
const bool rowMajor
Storage order flag for row-major matrices.
Definition: StorageOrder.h:71
bool isHermitian(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is Hermitian.
Definition: DenseMatrix.h:759
bool isZero(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 0.
Definition: DiagonalProxy.h:615
bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:249
bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:289
bool isUniUpper(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is an upper unitriangular matrix.
Definition: DenseMatrix.h:1344
Header file for the IsUpper type trait.
Header file for the IsHermitian type trait.
BLAZE_ALWAYS_INLINE bool isSquare(const Matrix< MT, SO > &matrix) noexcept
Checks if the given matrix is a square matrix.
Definition: Matrix.h:609
Header file for the isReal shim.
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101
Header file for the TrueType type/value trait base class.
Compile time check for unitriangular matrix types.This type trait tests whether or not the given temp...
Definition: IsUniTriangular.h:87
bool isIdentity(const DenseMatrix< MT, SO > &dm)
Checks if the give dense matrix is an identity matrix.
Definition: DenseMatrix.h:1593
Header file for the IsExpression type trait class.