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 
47 #include <blaze/math/Functions.h>
48 #include <blaze/math/shims/Equal.h>
50 #include <blaze/math/shims/IsNaN.h>
51 #include <blaze/math/shims/IsOne.h>
66 #include <blaze/util/Assert.h>
67 #include <blaze/util/EnableIf.h>
68 #include <blaze/util/FalseType.h>
69 #include <blaze/util/mpl/If.h>
70 #include <blaze/util/TrueType.h>
71 #include <blaze/util/Types.h>
74 
75 
76 namespace blaze {
77 
78 //=================================================================================================
79 //
80 // GLOBAL OPERATORS
81 //
82 //=================================================================================================
83 
84 //*************************************************************************************************
87 template< typename T1, typename T2 >
88 inline bool operator==( const DenseMatrix<T1,false>& lhs, const DenseMatrix<T2,false>& rhs );
89 
90 template< typename T1, typename T2 >
91 inline bool operator==( const DenseMatrix<T1,true>& lhs, const DenseMatrix<T2,true>& rhs );
92 
93 template< typename T1, typename T2, bool SO >
94 inline bool operator==( const DenseMatrix<T1,SO>& lhs, const DenseMatrix<T2,!SO>& rhs );
95 
96 template< typename T1, typename T2, bool SO >
97 inline bool operator==( const DenseMatrix<T1,SO>& lhs, const SparseMatrix<T2,false>& rhs );
98 
99 template< typename T1, typename T2, bool SO >
100 inline bool operator==( const DenseMatrix<T1,SO>& lhs, const SparseMatrix<T2,true>& rhs );
101 
102 template< typename T1, bool SO1, typename T2, bool SO2 >
103 inline bool operator==( const SparseMatrix<T1,SO1>& lhs, const DenseMatrix<T2,SO2>& rhs );
104 
105 template< typename T1, typename T2 >
106 inline typename EnableIf< IsNumeric<T2>, bool >::Type
107  operator==( const DenseMatrix<T1,false>& mat, T2 scalar );
108 
109 template< typename T1, typename T2 >
110 inline typename EnableIf< IsNumeric<T2>, bool >::Type
111  operator==( const DenseMatrix<T1,true>& mat, T2 scalar );
112 
113 template< typename T1, typename T2, bool SO >
114 inline typename EnableIf< IsNumeric<T2>, bool >::Type
115  operator==( T1 scalar, const DenseMatrix<T2,SO>& mat );
116 
117 template< typename T1, bool SO1, typename T2, bool SO2 >
118 inline bool operator!=( const DenseMatrix<T1,SO1>& lhs, const DenseMatrix<T2,SO2>& rhs );
119 
120 template< typename T1, bool SO1, typename T2, bool SO2 >
121 inline bool operator!=( const DenseMatrix<T1,SO1>& lhs, const SparseMatrix<T2,SO2>& rhs );
122 
123 template< typename T1, bool SO1, typename T2, bool SO2 >
124 inline bool operator!=( const SparseMatrix<T1,SO1>& lhs, const DenseMatrix<T2,SO2>& rhs );
125 
126 template< typename T1, typename T2, bool SO >
127 inline typename EnableIf< IsNumeric<T2>, bool >::Type
128  operator!=( const DenseMatrix<T1,SO>& mat, T2 scalar );
129 
130 template< typename T1, typename T2, bool SO >
131 inline typename EnableIf< IsNumeric<T2>, bool >::Type
132  operator!=( T1 scalar, const DenseMatrix<T2,SO>& mat );
134 //*************************************************************************************************
135 
136 
137 //*************************************************************************************************
145 template< typename T1 // Type of the left-hand side dense matrix
146  , typename T2 > // Type of the right-hand side dense matrix
147 inline bool operator==( const DenseMatrix<T1,false>& lhs, const DenseMatrix<T2,false>& rhs )
148 {
149  typedef typename T1::CompositeType CT1;
150  typedef typename T2::CompositeType CT2;
151 
152  // Early exit in case the matrix sizes don't match
153  if( (~lhs).rows() != (~rhs).rows() || (~lhs).columns() != (~rhs).columns() )
154  return false;
155 
156  // Evaluation of the two dense matrix operands
157  CT1 A( ~lhs );
158  CT2 B( ~rhs );
159 
160  // In order to compare the two matrices, the data values of the lower-order data
161  // type are converted to the higher-order data type within the equal function.
162  for( size_t i=0; i<A.rows(); ++i ) {
163  for( size_t j=0; j<A.columns(); ++j ) {
164  if( !equal( A(i,j), B(i,j) ) ) return false;
165  }
166  }
167 
168  return true;
169 }
170 //*************************************************************************************************
171 
172 
173 //*************************************************************************************************
181 template< typename T1 // Type of the left-hand side dense matrix
182  , typename T2 > // Type of the right-hand side dense matrix
183 inline bool operator==( const DenseMatrix<T1,true>& lhs, const DenseMatrix<T2,true>& rhs )
184 {
185  typedef typename T1::CompositeType CT1;
186  typedef typename T2::CompositeType CT2;
187 
188  // Early exit in case the matrix sizes don't match
189  if( (~lhs).rows() != (~rhs).rows() || (~lhs).columns() != (~rhs).columns() )
190  return false;
191 
192  // Evaluation of the two dense matrix operands
193  CT1 A( ~lhs );
194  CT2 B( ~rhs );
195 
196  // In order to compare the two matrices, the data values of the lower-order data
197  // type are converted to the higher-order data type within the equal function.
198  for( size_t j=0; j<A.columns(); ++j ) {
199  for( size_t i=0; i<A.rows(); ++i ) {
200  if( !equal( A(i,j), B(i,j) ) ) return false;
201  }
202  }
203 
204  return true;
205 }
206 //*************************************************************************************************
207 
208 
209 //*************************************************************************************************
217 template< typename T1 // Type of the left-hand side dense matrix
218  , typename T2 // Type of the right-hand side dense matrix
219  , bool SO > // Storage order
220 inline bool operator==( const DenseMatrix<T1,SO>& lhs, const DenseMatrix<T2,!SO>& rhs )
221 {
222  typedef typename T1::CompositeType CT1;
223  typedef typename T2::CompositeType CT2;
224 
225  // Early exit in case the matrix sizes don't match
226  if( (~lhs).rows() != (~rhs).rows() || (~lhs).columns() != (~rhs).columns() )
227  return false;
228 
229  // Evaluation of the two dense matrix operands
230  CT1 A( ~lhs );
231  CT2 B( ~rhs );
232 
233  // In order to compare the two matrices, the data values of the lower-order data
234  // type are converted to the higher-order data type within the equal function.
235  const size_t rows ( A.rows() );
236  const size_t columns( A.columns() );
237  const size_t block ( 16 );
238 
239  for( size_t ii=0; ii<rows; ii+=block ) {
240  const size_t iend( ( rows < ii+block )?( rows ):( ii+block ) );
241  for( size_t jj=0; jj<columns; jj+=block ) {
242  const size_t jend( ( columns < jj+block )?( columns ):( jj+block ) );
243  for( size_t i=ii; i<iend; ++i ) {
244  for( size_t j=jj; j<jend; ++j ) {
245  if( !equal( A(i,j), B(i,j) ) ) return false;
246  }
247  }
248  }
249  }
250 
251  return true;
252 }
253 //*************************************************************************************************
254 
255 
256 //*************************************************************************************************
264 template< typename T1 // Type of the left-hand side dense matrix
265  , typename T2 // Type of the right-hand side sparse matrix
266  , bool SO > // Storage order of the left-hand side dense matrix
267 inline bool operator==( const DenseMatrix<T1,SO>& lhs, const SparseMatrix<T2,false>& rhs )
268 {
269  typedef typename T1::CompositeType CT1;
270  typedef typename T2::CompositeType CT2;
272 
273  // Early exit in case the matrix sizes don't match
274  if( (~lhs).rows() != (~rhs).rows() || (~lhs).columns() != (~rhs).columns() )
275  return false;
276 
277  // Evaluation of the dense matrix and sparse matrix operand
278  CT1 A( ~lhs );
279  CT2 B( ~rhs );
280 
281  // In order to compare the two matrices, the data values of the lower-order data
282  // type are converted to the higher-order data type within the equal function.
283  size_t j( 0 );
284 
285  for( size_t i=0; i<B.rows(); ++i ) {
286  j = 0;
287  for( ConstIterator element=B.begin(i); element!=B.end(i); ++element, ++j ) {
288  for( ; j<element->index(); ++j ) {
289  if( !isDefault( A(i,j) ) ) return false;
290  }
291  if( !equal( element->value(), A(i,j) ) ) return false;
292  }
293  for( ; j<A.columns(); ++j ) {
294  if( !isDefault( A(i,j) ) ) return false;
295  }
296  }
297 
298  return true;
299 }
300 //*************************************************************************************************
301 
302 
303 //*************************************************************************************************
311 template< typename T1 // Type of the left-hand side dense matrix
312  , typename T2 // Type of the right-hand side sparse matrix
313  , bool SO > // Storage order of the left-hand side dense matrix
314 inline bool operator==( const DenseMatrix<T1,SO>& lhs, const SparseMatrix<T2,true>& rhs )
315 {
316  typedef typename T1::CompositeType CT1;
317  typedef typename T2::CompositeType CT2;
319 
320  // Early exit in case the matrix sizes don't match
321  if( (~lhs).rows() != (~rhs).rows() || (~lhs).columns() != (~rhs).columns() )
322  return false;
323 
324  // Evaluation of the dense matrix and sparse matrix operand
325  CT1 A( ~lhs );
326  CT2 B( ~rhs );
327 
328  // In order to compare the two matrices, the data values of the lower-order data
329  // type are converted to the higher-order data type within the equal function.
330  size_t i( 0 );
331 
332  for( size_t j=0; j<B.columns(); ++j ) {
333  i = 0;
334  for( ConstIterator element=B.begin(j); element!=B.end(j); ++element, ++i ) {
335  for( ; i<element->index(); ++i ) {
336  if( !isDefault( A(i,j) ) ) return false;
337  }
338  if( !equal( element->value(), A(i,j) ) ) return false;
339  }
340  for( ; i<A.rows(); ++i ) {
341  if( !isDefault( A(i,j) ) ) return false;
342  }
343  }
344 
345  return true;
346 }
347 //*************************************************************************************************
348 
349 
350 //*************************************************************************************************
358 template< typename T1 // Type of the left-hand side sparse matrix
359  , bool SO1 // Storage order of the left-hand side sparse matrix
360  , typename T2 // Type of the right-hand side dense matrix
361  , bool SO2 > // Storage order of the right-hand side sparse matrix
362 inline bool operator==( const SparseMatrix<T1,SO1>& lhs, const DenseMatrix<T2,SO2>& rhs )
363 {
364  return ( rhs == lhs );
365 }
366 //*************************************************************************************************
367 
368 
369 //*************************************************************************************************
381 template< typename T1 // Type of the left-hand side dense matrix
382  , typename T2 > // Type of the right-hand side scalar
383 inline typename EnableIf< IsNumeric<T2>, bool >::Type
384  operator==( const DenseMatrix<T1,false>& mat, T2 scalar )
385 {
386  typedef typename T1::CompositeType CT1;
387 
388  // Evaluation of the dense matrix operand
389  CT1 A( ~mat );
390 
391  // In order to compare the matrix and the scalar value, the data values of the lower-order
392  // data type are converted to the higher-order data type within the equal function.
393  for( size_t i=0; i<A.rows(); ++i ) {
394  for( size_t j=0; j<A.columns(); ++j ) {
395  if( !equal( A(i,j), scalar ) ) return false;
396  }
397  }
398 
399  return true;
400 }
401 //*************************************************************************************************
402 
403 
404 //*************************************************************************************************
416 template< typename T1 // Type of the left-hand side dense matrix
417  , typename T2 > // Type of the right-hand side scalar
418 inline typename EnableIf< IsNumeric<T2>, bool >::Type
419  operator==( const DenseMatrix<T1,true>& mat, T2 scalar )
420 {
421  typedef typename T1::CompositeType CT1;
422 
423  // Evaluation of the dense matrix operand
424  CT1 A( ~mat );
425 
426  // In order to compare the matrix and the scalar value, the data values of the lower-order
427  // data type are converted to the higher-order data type within the equal function.
428  for( size_t j=0; j<A.columns(); ++j ) {
429  for( size_t i=0; i<A.rows(); ++i ) {
430  if( !equal( A(i,j), scalar ) ) return false;
431  }
432  }
433 
434  return true;
435 }
436 //*************************************************************************************************
437 
438 
439 //*************************************************************************************************
451 template< typename T1 // Type of the left-hand side scalar
452  , typename T2 // Type of the right-hand side dense matrix
453  , bool SO > // Storage order
454 inline typename EnableIf< IsNumeric<T1>, bool >::Type
455  operator==( T1 scalar, const DenseMatrix<T2,SO>& mat )
456 {
457  return ( mat == scalar );
458 }
459 //*************************************************************************************************
460 
461 
462 //*************************************************************************************************
470 template< typename T1 // Type of the left-hand side dense matrix
471  , bool SO1 // Storage order of the left-hand side dense matrix
472  , typename T2 // Type of the right-hand side dense matrix
473  , bool SO2 > // Storage order of the right-hand side dense matrix
474 inline bool operator!=( const DenseMatrix<T1,SO1>& lhs, const DenseMatrix<T2,SO2>& rhs )
475 {
476  return !( lhs == rhs );
477 }
478 //*************************************************************************************************
479 
480 
481 //*************************************************************************************************
489 template< typename T1 // Type of the left-hand side dense matrix
490  , bool SO1 // Storage order of the left-hand side dense matrix
491  , typename T2 // Type of the right-hand side sparse matrix
492  , bool SO2 > // Storage order of the right-hand side sparse matrix
493 inline bool operator!=( const DenseMatrix<T1,SO1>& lhs, const SparseMatrix<T2,SO2>& rhs )
494 {
495  return !( lhs == rhs );
496 }
497 //*************************************************************************************************
498 
499 
500 //*************************************************************************************************
508 template< typename T1 // Type of the left-hand side sparse matrix
509  , bool SO1 // Storage order of the left-hand side sparse matrix
510  , typename T2 // Type of the right-hand side dense matrix
511  , bool SO2 > // Storage order right-hand side dense matrix
512 inline bool operator!=( const SparseMatrix<T1,SO1>& lhs, const DenseMatrix<T2,SO2>& rhs )
513 {
514  return !( rhs == lhs );
515 }
516 //*************************************************************************************************
517 
518 
519 //*************************************************************************************************
531 template< typename T1 // Type of the left-hand side dense matrix
532  , typename T2 // Type of the right-hand side scalar
533  , bool SO > // Storage order
534 inline typename EnableIf< IsNumeric<T2>, bool >::Type
535  operator!=( const DenseMatrix<T1,SO>& mat, T2 scalar )
536 {
537  return !( mat == scalar );
538 }
539 //*************************************************************************************************
540 
541 
542 //*************************************************************************************************
554 template< typename T1 // Type of the left-hand side scalar
555  , typename T2 // Type of the right-hand side dense matrix
556  , bool SO > // Storage order
557 inline typename EnableIf< IsNumeric<T1>, bool >::Type
558  operator!=( T1 scalar, const DenseMatrix<T2,SO>& mat )
559 {
560  return !( mat == scalar );
561 }
562 //*************************************************************************************************
563 
564 
565 
566 
567 //=================================================================================================
568 //
569 // GLOBAL FUNCTIONS
570 //
571 //=================================================================================================
572 
573 //*************************************************************************************************
576 template< typename MT, bool SO >
577 bool isnan( const DenseMatrix<MT,SO>& dm );
578 
579 template< typename MT, bool SO >
580 bool isSymmetric( const DenseMatrix<MT,SO>& dm );
581 
582 template< typename MT, bool SO >
583 bool isUniform( const DenseMatrix<MT,SO>& dm );
584 
585 template< typename MT, bool SO >
586 bool isLower( const DenseMatrix<MT,SO>& dm );
587 
588 template< typename MT, bool SO >
589 bool isUniLower( const DenseMatrix<MT,SO>& dm );
590 
591 template< typename MT, bool SO >
592 bool isStrictlyLower( const DenseMatrix<MT,SO>& dm );
593 
594 template< typename MT, bool SO >
595 bool isUpper( const DenseMatrix<MT,SO>& dm );
596 
597 template< typename MT, bool SO >
598 bool isUniUpper( const DenseMatrix<MT,SO>& dm );
599 
600 template< typename MT, bool SO >
601 bool isStrictlyUpper( const DenseMatrix<MT,SO>& dm );
602 
603 template< typename MT, bool SO >
604 bool isDiagonal( const DenseMatrix<MT,SO>& dm );
605 
606 template< typename MT, bool SO >
607 bool isIdentity( const DenseMatrix<MT,SO>& dm );
608 
609 template< typename MT, bool SO >
610 const typename MT::ElementType min( const DenseMatrix<MT,SO>& dm );
611 
612 template< typename MT, bool SO >
613 const typename MT::ElementType max( const DenseMatrix<MT,SO>& dm );
615 //*************************************************************************************************
616 
617 
618 //*************************************************************************************************
638 template< typename MT // Type of the dense matrix
639  , bool SO > // Storage order
640 bool isnan( const DenseMatrix<MT,SO>& dm )
641 {
642  typedef typename MT::CompositeType CT;
643 
644  CT A( ~dm ); // Evaluation of the dense matrix operand
645 
646  if( SO == rowMajor ) {
647  for( size_t i=0UL; i<A.rows(); ++i ) {
648  for( size_t j=0UL; j<A.columns(); ++j )
649  if( isnan( A(i,j) ) ) return true;
650  }
651  }
652  else {
653  for( size_t j=0UL; j<A.columns(); ++j ) {
654  for( size_t i=0UL; i<A.rows(); ++i )
655  if( isnan( A(i,j) ) ) return true;
656  }
657  }
658 
659  return false;
660 }
661 //*************************************************************************************************
662 
663 
664 //*************************************************************************************************
690 template< typename MT // Type of the dense matrix
691  , bool SO > // Storage order
693 {
694  typedef typename MT::CompositeType CT;
695 
697  return true;
698 
699  if( !isSquare( ~dm ) )
700  return false;
701 
702  if( (~dm).rows() < 2UL )
703  return true;
704 
706  return isDiagonal( ~dm );
707 
708  CT A( ~dm ); // Evaluation of the dense matrix operand
709 
710  if( SO == rowMajor ) {
711  for( size_t i=1UL; i<A.rows(); ++i ) {
712  for( size_t j=0UL; j<i; ++j ) {
713  if( !equal( A(i,j), A(j,i) ) )
714  return false;
715  }
716  }
717  }
718  else {
719  for( size_t j=1UL; j<A.columns(); ++j ) {
720  for( size_t i=0UL; i<j; ++i ) {
721  if( !equal( A(i,j), A(j,i) ) )
722  return false;
723  }
724  }
725  }
726 
727  return true;
728 }
729 //*************************************************************************************************
730 
731 
732 //*************************************************************************************************
740 template< typename MT > // Type of the dense matrix
741 bool isUniform_backend( const DenseMatrix<MT,false>& dm, TrueType )
742 {
745 
746  BLAZE_INTERNAL_ASSERT( (~dm).rows() != 0UL, "Invalid number of rows detected" );
747  BLAZE_INTERNAL_ASSERT( (~dm).columns() != 0UL, "Invalid number of columns detected" );
748 
749  const size_t ibegin( ( IsStrictlyLower<MT>::value )?( 1UL ):( 0UL ) );
750  const size_t iend ( ( IsStrictlyUpper<MT>::value )?( (~dm).rows()-1UL ):( (~dm).rows() ) );
751 
752  for( size_t i=ibegin; i<iend; ++i ) {
753  if( !IsUpper<MT>::value ) {
754  for( size_t j=0UL; j<i; ++j ) {
755  if( !isDefault( (~dm)(i,j) ) )
756  return false;
757  }
758  }
759  if( !isDefault( (~dm)(i,i) ) )
760  return false;
761  if( !IsLower<MT>::value ) {
762  for( size_t j=i+1UL; j<(~dm).columns(); ++j ) {
763  if( !isDefault( (~dm)(i,j) ) )
764  return false;
765  }
766  }
767  }
768 
769  return true;
770 }
772 //*************************************************************************************************
773 
774 
775 //*************************************************************************************************
783 template< typename MT > // Type of the dense matrix
784 bool isUniform_backend( const DenseMatrix<MT,true>& dm, TrueType )
785 {
788 
789  BLAZE_INTERNAL_ASSERT( (~dm).rows() != 0UL, "Invalid number of rows detected" );
790  BLAZE_INTERNAL_ASSERT( (~dm).columns() != 0UL, "Invalid number of columns detected" );
791 
792  const size_t jbegin( ( IsStrictlyUpper<MT>::value )?( 1UL ):( 0UL ) );
793  const size_t jend ( ( IsStrictlyLower<MT>::value )?( (~dm).columns()-1UL ):( (~dm).columns() ) );
794 
795  for( size_t j=jbegin; j<jend; ++j ) {
796  if( !IsLower<MT>::value ) {
797  for( size_t i=0UL; i<j; ++i ) {
798  if( !isDefault( (~dm)(i,j) ) )
799  return false;
800  }
801  }
802  if( !isDefault( (~dm)(j,j) ) )
803  return false;
804  if( !IsUpper<MT>::value ) {
805  for( size_t i=j+1UL; i<(~dm).rows(); ++i ) {
806  if( !isDefault( (~dm)(i,j) ) )
807  return false;
808  }
809  }
810  }
811 
812  return true;
813 }
815 //*************************************************************************************************
816 
817 
818 //*************************************************************************************************
826 template< typename MT > // Type of the dense matrix
827 bool isUniform_backend( const DenseMatrix<MT,false>& dm, FalseType )
828 {
831 
832  BLAZE_INTERNAL_ASSERT( (~dm).rows() != 0UL, "Invalid number of rows detected" );
833  BLAZE_INTERNAL_ASSERT( (~dm).columns() != 0UL, "Invalid number of columns detected" );
834 
835  typename MT::ConstReference cmp( (~dm)(0UL,0UL) );
836 
837  for( size_t i=0UL; i<(~dm).rows(); ++i ) {
838  for( size_t j=0UL; j<(~dm).columns(); ++j ) {
839  if( (~dm)(i,j) != cmp )
840  return false;
841  }
842  }
843 
844  return true;
845 }
847 //*************************************************************************************************
848 
849 
850 //*************************************************************************************************
858 template< typename MT > // Type of the dense matrix
859 bool isUniform_backend( const DenseMatrix<MT,true>& dm, FalseType )
860 {
863 
864  BLAZE_INTERNAL_ASSERT( (~dm).rows() != 0UL, "Invalid number of rows detected" );
865  BLAZE_INTERNAL_ASSERT( (~dm).columns() != 0UL, "Invalid number of columns detected" );
866 
867  typename MT::ConstReference cmp( (~dm)(0UL,0UL) );
868 
869  for( size_t j=0UL; j<(~dm).columns(); ++j ) {
870  for( size_t i=0UL; i<(~dm).rows(); ++i ) {
871  if( (~dm)(i,j) != cmp )
872  return false;
873  }
874  }
875 
876  return true;
877 }
879 //*************************************************************************************************
880 
881 
882 //*************************************************************************************************
908 template< typename MT // Type of the dense matrix
909  , bool SO > // Storage order
910 bool isUniform( const DenseMatrix<MT,SO>& dm )
911 {
913  return false;
914 
915  if( (~dm).rows() == 0UL || (~dm).columns() == 0UL ||
916  ( (~dm).rows() == 1UL && (~dm).columns() == 1UL ) )
917  return true;
918 
919  typename MT::CompositeType A( ~dm ); // Evaluation of the dense matrix operand
920 
921  return isUniform_backend( A, typename IsTriangular<MT>::Type() );
922 }
923 //*************************************************************************************************
924 
925 
926 //*************************************************************************************************
962 template< typename MT // Type of the dense matrix
963  , bool SO > // Storage order
964 bool isLower( const DenseMatrix<MT,SO>& dm )
965 {
966  typedef typename MT::ResultType RT;
967  typedef typename MT::ReturnType RN;
968  typedef typename MT::CompositeType CT;
969  typedef typename If< IsExpression<RN>, const RT, CT >::Type Tmp;
970 
971  if( IsLower<MT>::value )
972  return true;
973 
974  if( !isSquare( ~dm ) )
975  return false;
976 
977  if( (~dm).rows() < 2UL )
978  return true;
979 
980  Tmp A( ~dm ); // Evaluation of the dense matrix operand
981 
982  if( SO == rowMajor ) {
983  for( size_t i=0UL; i<A.rows()-1UL; ++i ) {
984  for( size_t j=i+1UL; j<A.columns(); ++j ) {
985  if( !isDefault( A(i,j) ) )
986  return false;
987  }
988  }
989  }
990  else {
991  for( size_t j=1UL; j<A.columns(); ++j ) {
992  for( size_t i=0UL; i<j; ++i ) {
993  if( !isDefault( A(i,j) ) )
994  return false;
995  }
996  }
997  }
998 
999  return true;
1000 }
1001 //*************************************************************************************************
1002 
1003 
1004 //*************************************************************************************************
1039 template< typename MT // Type of the dense matrix
1040  , bool SO > // Storage order
1042 {
1043  typedef typename MT::ResultType RT;
1044  typedef typename MT::ElementType ET;
1045  typedef typename MT::ReturnType RN;
1046  typedef typename MT::CompositeType CT;
1047  typedef typename If< IsExpression<RN>, const RT, CT >::Type Tmp;
1048 
1049  if( IsUniLower<MT>::value )
1050  return true;
1051 
1052  if( !isSquare( ~dm ) )
1053  return false;
1054 
1055  Tmp A( ~dm ); // Evaluation of the dense matrix operand
1056 
1057  if( SO == rowMajor ) {
1058  for( size_t i=0UL; i<A.rows(); ++i ) {
1059  if( !isOne( A(i,i) ) )
1060  return false;
1061  for( size_t j=i+1UL; j<A.columns(); ++j ) {
1062  if( !isDefault( A(i,j) ) )
1063  return false;
1064  }
1065  }
1066  }
1067  else {
1068  for( size_t j=0UL; j<A.columns(); ++j ) {
1069  for( size_t i=0UL; i<j; ++i ) {
1070  if( !isDefault( A(i,j) ) )
1071  return false;
1072  }
1073  if( !isOne( A(j,j) ) )
1074  return false;
1075  }
1076  }
1077 
1078  return true;
1079 }
1080 //*************************************************************************************************
1081 
1082 
1083 //*************************************************************************************************
1119 template< typename MT // Type of the dense matrix
1120  , bool SO > // Storage order
1122 {
1123  typedef typename MT::ResultType RT;
1124  typedef typename MT::ElementType ET;
1125  typedef typename MT::ReturnType RN;
1126  typedef typename MT::CompositeType CT;
1127  typedef typename If< IsExpression<RN>, const RT, CT >::Type Tmp;
1128 
1130  return true;
1131 
1133  return false;
1134 
1135  Tmp A( ~dm ); // Evaluation of the dense matrix operand
1136 
1137  if( SO == rowMajor ) {
1138  for( size_t i=0UL; i<A.rows(); ++i ) {
1139  for( size_t j=i; j<A.columns(); ++j ) {
1140  if( !isDefault( A(i,j) ) )
1141  return false;
1142  }
1143  }
1144  }
1145  else {
1146  for( size_t j=0UL; j<A.columns(); ++j ) {
1147  for( size_t i=0UL; i<=j; ++i ) {
1148  if( !isDefault( A(i,j) ) )
1149  return false;
1150  }
1151  }
1152  }
1153 
1154  return true;
1155 }
1156 //*************************************************************************************************
1157 
1158 
1159 //*************************************************************************************************
1195 template< typename MT // Type of the dense matrix
1196  , bool SO > // Storage order
1197 bool isUpper( const DenseMatrix<MT,SO>& dm )
1198 {
1199  typedef typename MT::ResultType RT;
1200  typedef typename MT::ReturnType RN;
1201  typedef typename MT::CompositeType CT;
1202  typedef typename If< IsExpression<RN>, const RT, CT >::Type Tmp;
1203 
1204  if( IsUpper<MT>::value )
1205  return true;
1206 
1207  if( !isSquare( ~dm ) )
1208  return false;
1209 
1210  if( (~dm).rows() < 2UL )
1211  return true;
1212 
1213  Tmp A( ~dm ); // Evaluation of the dense matrix operand
1214 
1215  if( SO == rowMajor ) {
1216  for( size_t i=1UL; i<A.rows(); ++i ) {
1217  for( size_t j=0UL; j<i; ++j ) {
1218  if( !isDefault( A(i,j) ) )
1219  return false;
1220  }
1221  }
1222  }
1223  else {
1224  for( size_t j=0UL; j<A.columns()-1UL; ++j ) {
1225  for( size_t i=j+1UL; i<A.rows(); ++i ) {
1226  if( !isDefault( A(i,j) ) )
1227  return false;
1228  }
1229  }
1230  }
1231 
1232  return true;
1233 }
1234 //*************************************************************************************************
1235 
1236 
1237 //*************************************************************************************************
1272 template< typename MT // Type of the dense matrix
1273  , bool SO > // Storage order
1275 {
1276  typedef typename MT::ResultType RT;
1277  typedef typename MT::ElementType ET;
1278  typedef typename MT::ReturnType RN;
1279  typedef typename MT::CompositeType CT;
1280  typedef typename If< IsExpression<RN>, const RT, CT >::Type Tmp;
1281 
1282  if( IsUniUpper<MT>::value )
1283  return true;
1284 
1285  if( !isSquare( ~dm ) )
1286  return false;
1287 
1288  Tmp A( ~dm ); // Evaluation of the dense matrix operand
1289 
1290  if( SO == rowMajor ) {
1291  for( size_t i=0UL; i<A.rows(); ++i ) {
1292  for( size_t j=0UL; j<i; ++j ) {
1293  if( !isDefault( A(i,j) ) )
1294  return false;
1295  }
1296  if( !isOne( A(i,i) ) )
1297  return false;
1298  }
1299  }
1300  else {
1301  for( size_t j=0UL; j<A.columns(); ++j ) {
1302  if( !isOne( A(j,j) ) )
1303  return false;
1304  for( size_t i=j+1UL; i<A.rows(); ++i ) {
1305  if( !isDefault( A(i,j) ) )
1306  return false;
1307  }
1308  }
1309  }
1310 
1311  return true;
1312 }
1313 //*************************************************************************************************
1314 
1315 
1316 //*************************************************************************************************
1352 template< typename MT // Type of the dense matrix
1353  , bool SO > // Storage order
1355 {
1356  typedef typename MT::ResultType RT;
1357  typedef typename MT::ElementType ET;
1358  typedef typename MT::ReturnType RN;
1359  typedef typename MT::CompositeType CT;
1360  typedef typename If< IsExpression<RN>, const RT, CT >::Type Tmp;
1361 
1363  return true;
1364 
1366  return false;
1367 
1368  Tmp A( ~dm ); // Evaluation of the dense matrix operand
1369 
1370  if( SO == rowMajor ) {
1371  for( size_t i=0UL; i<A.rows(); ++i ) {
1372  for( size_t j=0UL; j<=i; ++j ) {
1373  if( !isDefault( A(i,j) ) )
1374  return false;
1375  }
1376  }
1377  }
1378  else {
1379  for( size_t j=0UL; j<A.columns(); ++j ) {
1380  for( size_t i=j; i<A.rows(); ++i ) {
1381  if( !isDefault( A(i,j) ) )
1382  return false;
1383  }
1384  }
1385  }
1386 
1387  return true;
1388 }
1389 //*************************************************************************************************
1390 
1391 
1392 //*************************************************************************************************
1429 template< typename MT // Type of the dense matrix
1430  , bool SO > // Storage order
1432 {
1433  typedef typename MT::ResultType RT;
1434  typedef typename MT::ReturnType RN;
1435  typedef typename MT::CompositeType CT;
1436  typedef typename If< IsExpression<RN>, const RT, CT >::Type Tmp;
1437 
1438  if( IsDiagonal<MT>::value )
1439  return true;
1440 
1441  if( !isSquare( ~dm ) )
1442  return false;
1443 
1444  if( (~dm).rows() < 2UL )
1445  return true;
1446 
1447  Tmp A( ~dm ); // Evaluation of the dense matrix operand
1448 
1449  if( SO == rowMajor ) {
1450  for( size_t i=0UL; i<A.rows(); ++i ) {
1451  if( !IsUpper<MT>::value ) {
1452  for( size_t j=0UL; j<i; ++j ) {
1453  if( !isDefault( A(i,j) ) )
1454  return false;
1455  }
1456  }
1457  if( !IsLower<MT>::value ) {
1458  for( size_t j=i+1UL; j<A.columns(); ++j ) {
1459  if( !isDefault( A(i,j) ) )
1460  return false;
1461  }
1462  }
1463  }
1464  }
1465  else {
1466  for( size_t j=0UL; j<A.columns(); ++j ) {
1467  if( !IsLower<MT>::value ) {
1468  for( size_t i=0UL; i<j; ++i ) {
1469  if( !isDefault( A(i,j) ) )
1470  return false;
1471  }
1472  }
1473  if( !IsUpper<MT>::value ) {
1474  for( size_t i=j+1UL; i<A.rows(); ++i ) {
1475  if( !isDefault( A(i,j) ) )
1476  return false;
1477  }
1478  }
1479  }
1480  }
1481 
1482  return true;
1483 }
1484 //*************************************************************************************************
1485 
1486 
1487 //*************************************************************************************************
1523 template< typename MT // Type of the dense matrix
1524  , bool SO > // Storage order
1526 {
1527  typedef typename MT::ResultType RT;
1528  typedef typename MT::ElementType ET;
1529  typedef typename MT::ReturnType RN;
1530  typedef typename MT::CompositeType CT;
1531  typedef typename If< IsExpression<RN>, const RT, CT >::Type Tmp;
1532 
1533  if( IsIdentity<MT>::value )
1534  return true;
1535 
1536  if( !isSquare( ~dm ) )
1537  return false;
1538 
1539  if( (~dm).rows() == 0UL )
1540  return true;
1541 
1542  Tmp A( ~dm ); // Evaluation of the dense matrix operand
1543 
1544  if( SO == rowMajor ) {
1545  for( size_t i=0UL; i<A.rows(); ++i ) {
1546  if( !IsUpper<MT>::value ) {
1547  for( size_t j=0UL; j<i; ++j ) {
1548  if( !isDefault( A(i,j) ) )
1549  return false;
1550  }
1551  }
1552  if( !IsUniLower<MT>::value && !IsUniUpper<MT>::value && !isOne( A(i,i) ) ) {
1553  return false;
1554  }
1555  if( !IsLower<MT>::value ) {
1556  for( size_t j=i+1UL; j<A.columns(); ++j ) {
1557  if( !isDefault( A(i,j) ) )
1558  return false;
1559  }
1560  }
1561  }
1562  }
1563  else {
1564  for( size_t j=0UL; j<A.columns(); ++j ) {
1565  if( !IsLower<MT>::value ) {
1566  for( size_t i=0UL; i<j; ++i ) {
1567  if( !isDefault( A(i,j) ) )
1568  return false;
1569  }
1570  }
1571  if( !IsUniLower<MT>::value && !IsUniUpper<MT>::value && !isOne( A(j,j) ) ) {
1572  return false;
1573  }
1574  if( !IsUpper<MT>::value ) {
1575  for( size_t i=j+1UL; i<A.rows(); ++i ) {
1576  if( !isDefault( A(i,j) ) )
1577  return false;
1578  }
1579  }
1580  }
1581  }
1582 
1583  return true;
1584 }
1585 //*************************************************************************************************
1586 
1587 
1588 //*************************************************************************************************
1600 template< typename MT // Type of the dense matrix
1601  , bool SO > // Storage order
1602 const typename MT::ElementType min( const DenseMatrix<MT,SO>& dm )
1603 {
1604  using blaze::min;
1605 
1606  typedef typename MT::ElementType ET;
1607  typedef typename MT::CompositeType CT;
1608 
1609  CT A( ~dm ); // Evaluation of the dense matrix operand
1610 
1611  if( A.rows() == 0UL || A.columns() == 0UL ) return ET();
1612 
1613  ET minimum( A(0,0) );
1614 
1615  if( SO == rowMajor ) {
1616  for( size_t j=1UL; j<A.columns(); ++j )
1617  minimum = min( minimum, A(0UL,j) );
1618  for( size_t i=1UL; i<A.rows(); ++i )
1619  for( size_t j=0UL; j<A.columns(); ++j )
1620  minimum = min( minimum, A(i,j) );
1621  }
1622  else {
1623  for( size_t i=1UL; i<A.rows(); ++i )
1624  minimum = min( minimum, A(i,0UL) );
1625  for( size_t j=1UL; j<A.columns(); ++j )
1626  for( size_t i=0UL; i<A.rows(); ++i )
1627  minimum = min( minimum, A(i,j) );
1628  }
1629 
1630  return minimum;
1631 }
1632 //*************************************************************************************************
1633 
1634 
1635 //*************************************************************************************************
1647 template< typename MT // Type of the dense matrix
1648  , bool SO > // Transpose flag
1649 const typename MT::ElementType max( const DenseMatrix<MT,SO>& dm )
1650 {
1651  using blaze::max;
1652 
1653  typedef typename MT::ElementType ET;
1654  typedef typename MT::CompositeType CT;
1655 
1656  CT A( ~dm ); // Evaluation of the dense matrix operand
1657 
1658  if( A.rows() == 0UL || A.columns() == 0UL ) return ET();
1659 
1660  ET maximum( A(0,0) );
1661 
1662  if( SO == rowMajor ) {
1663  for( size_t j=1UL; j<A.columns(); ++j )
1664  maximum = max( maximum, A(0UL,j) );
1665  for( size_t i=1UL; i<A.rows(); ++i )
1666  for( size_t j=0UL; j<A.columns(); ++j )
1667  maximum = max( maximum, A(i,j) );
1668  }
1669  else {
1670  for( size_t i=1UL; i<A.rows(); ++i )
1671  maximum = max( maximum, A(i,0UL) );
1672  for( size_t j=1UL; j<A.columns(); ++j )
1673  for( size_t i=0UL; i<A.rows(); ++i )
1674  maximum = max( maximum, A(i,j) );
1675  }
1676 
1677  return maximum;
1678 }
1679 //*************************************************************************************************
1680 
1681 } // namespace blaze
1682 
1683 #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:79
Header file for the isnan shim.
const MT::ElementType max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:1649
Header file for mathematical functions.
bool isDiagonal(const DenseMatrix< MT, SO > &dm)
Checks if the give dense matrix is diagonal.
Definition: DenseMatrix.h:1431
Header file for the IsUniUpper type trait.
Compile time type selection.The If class template selects one of the two given types T2 and T3 depend...
Definition: If.h:112
Compile time check for triangular matrix types.This type trait tests whether or not the given templat...
Definition: IsTriangular.h:105
Header file for basic type definitions.
BLAZE_ALWAYS_INLINE bool isSquare(const Matrix< MT, SO > &matrix)
Checks if the given matrix is a square matrix.
Definition: Matrix.h:902
#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:118
bool isStrictlyLower(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a strictly lower triangular matrix.
Definition: DenseMatrix.h:1121
bool isStrictlyUpper(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a strictly upper triangular matrix.
Definition: DenseMatrix.h:1354
Header file for the FalseType type/value trait base class.
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:692
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2507
BLAZE_ALWAYS_INLINE size_t rows(const Matrix< MT, SO > &matrix)
Returns the current number of rows of the matrix.
Definition: Matrix.h:316
Compile time check for lower triangular matrices.This type trait tests whether or not the given templ...
Definition: IsLower.h:90
Header file for the IsIdentity type trait.
bool isnan(const DenseMatrix< MT, SO > &dm)
Checks the given dense matrix for not-a-number elements.
Definition: DenseMatrix.h:640
Compile time check for upper triangular matrices.This type trait tests whether or not the given templ...
Definition: IsUpper.h:90
Header file for the IsUniLower type trait.
bool isLower(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a lower triangular matrix.
Definition: DenseMatrix.h:964
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:107
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:861
Header file for the SparseMatrix base class.
Header file for the IsSquare type trait.
Header file for the matrix storage order types.
Constraint on the data type.
Compile time check for upper unitriangular matrices.This type trait tests whether or not the given te...
Definition: IsUniUpper.h:85
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:2511
const MT::ElementType min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1602
Header file for the DenseMatrix base class.
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:92
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:1197
Compile time check for symmetric matrices.This type trait tests whether or not the given template par...
Definition: IsSymmetric.h:85
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:1041
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2505
Constraint on the data type.
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2509
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:85
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:92
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2506
Removal of reference modifiers.The RemoveCV type trait removes any reference modifiers from the given...
Definition: RemoveReference.h:69
Header file for run time assertion macros.
bool equal(const T1 &a, const T2 &b)
Generic equality check.
Definition: Equal.h:376
Header file for the isDefault shim.
#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:118
Header file for the RemoveReference type trait.
Compile time check for strictly lower triangular matrices.This type trait tests whether or not the gi...
Definition: IsStrictlyLower.h:86
bool isUniform(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a uniform matrix.
Definition: DenseMatrix.h:910
const bool rowMajor
Storage order flag for row-major matrices.
Definition: StorageOrder.h:71
boost::false_type 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 operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:249
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2502
BLAZE_ALWAYS_INLINE size_t columns(const Matrix< MT, SO > &matrix)
Returns the current number of columns of the matrix.
Definition: Matrix.h:332
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:1274
Header file for the IsUpper type trait.
boost::true_type TrueType
Type traits base class.The TrueType class is used as base class for type traits and value traits that...
Definition: TrueType.h:61
EnableIf< IsNumeric< Type >, bool >::Type isOne(const Type &v)
Returns whether the given value/object represents the numeric value 1.
Definition: IsOne.h:80
#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:105
bool isIdentity(const DenseMatrix< MT, SO > &dm)
Checks if the give dense matrix is an identity matrix.
Definition: DenseMatrix.h:1525
Header file for the IsExpression type trait class.