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>
49 #include <blaze/math/shims/Equal.h>
51 #include <blaze/math/shims/IsNaN.h>
52 #include <blaze/math/shims/IsOne.h>
68 #include <blaze/util/Assert.h>
69 #include <blaze/util/EnableIf.h>
70 #include <blaze/util/FalseType.h>
71 #include <blaze/util/mpl/If.h>
72 #include <blaze/util/TrueType.h>
73 #include <blaze/util/Types.h>
76 
77 
78 namespace blaze {
79 
80 //=================================================================================================
81 //
82 // GLOBAL OPERATORS
83 //
84 //=================================================================================================
85 
86 //*************************************************************************************************
89 template< typename T1, typename T2 >
90 inline bool operator==( const DenseMatrix<T1,false>& lhs, const DenseMatrix<T2,false>& rhs );
91 
92 template< typename T1, typename T2 >
93 inline bool operator==( const DenseMatrix<T1,true>& lhs, const DenseMatrix<T2,true>& rhs );
94 
95 template< typename T1, typename T2, bool SO >
96 inline bool operator==( const DenseMatrix<T1,SO>& lhs, const DenseMatrix<T2,!SO>& rhs );
97 
98 template< typename T1, typename T2, bool SO >
99 inline bool operator==( const DenseMatrix<T1,SO>& lhs, const SparseMatrix<T2,false>& rhs );
100 
101 template< typename T1, typename T2, bool SO >
102 inline bool operator==( const DenseMatrix<T1,SO>& lhs, const SparseMatrix<T2,true>& rhs );
103 
104 template< typename T1, bool SO1, typename T2, bool SO2 >
105 inline bool operator==( const SparseMatrix<T1,SO1>& lhs, const DenseMatrix<T2,SO2>& rhs );
106 
107 template< typename T1, typename T2 >
108 inline typename EnableIf< IsNumeric<T2>, bool >::Type
109  operator==( const DenseMatrix<T1,false>& mat, T2 scalar );
110 
111 template< typename T1, typename T2 >
112 inline typename EnableIf< IsNumeric<T2>, bool >::Type
113  operator==( const DenseMatrix<T1,true>& mat, T2 scalar );
114 
115 template< typename T1, typename T2, bool SO >
116 inline typename EnableIf< IsNumeric<T2>, bool >::Type
117  operator==( T1 scalar, const DenseMatrix<T2,SO>& mat );
118 
119 template< typename T1, bool SO1, typename T2, bool SO2 >
120 inline bool operator!=( const DenseMatrix<T1,SO1>& lhs, const DenseMatrix<T2,SO2>& rhs );
121 
122 template< typename T1, bool SO1, typename T2, bool SO2 >
123 inline bool operator!=( const DenseMatrix<T1,SO1>& lhs, const SparseMatrix<T2,SO2>& rhs );
124 
125 template< typename T1, bool SO1, typename T2, bool SO2 >
126 inline bool operator!=( const SparseMatrix<T1,SO1>& lhs, const DenseMatrix<T2,SO2>& rhs );
127 
128 template< typename T1, typename T2, bool SO >
129 inline typename EnableIf< IsNumeric<T2>, bool >::Type
130  operator!=( const DenseMatrix<T1,SO>& mat, T2 scalar );
131 
132 template< typename T1, typename T2, bool SO >
133 inline typename EnableIf< IsNumeric<T2>, bool >::Type
134  operator!=( T1 scalar, const DenseMatrix<T2,SO>& mat );
136 //*************************************************************************************************
137 
138 
139 //*************************************************************************************************
147 template< typename T1 // Type of the left-hand side dense matrix
148  , typename T2 > // Type of the right-hand side dense matrix
149 inline bool operator==( const DenseMatrix<T1,false>& lhs, const DenseMatrix<T2,false>& rhs )
150 {
151  typedef typename T1::CompositeType CT1;
152  typedef typename T2::CompositeType CT2;
153 
154  // Early exit in case the matrix sizes don't match
155  if( (~lhs).rows() != (~rhs).rows() || (~lhs).columns() != (~rhs).columns() )
156  return false;
157 
158  // Evaluation of the two dense matrix operands
159  CT1 A( ~lhs );
160  CT2 B( ~rhs );
161 
162  // In order to compare the two matrices, the data values of the lower-order data
163  // type are converted to the higher-order data type within the equal function.
164  for( size_t i=0; i<A.rows(); ++i ) {
165  for( size_t j=0; j<A.columns(); ++j ) {
166  if( !equal( A(i,j), B(i,j) ) ) return false;
167  }
168  }
169 
170  return true;
171 }
172 //*************************************************************************************************
173 
174 
175 //*************************************************************************************************
183 template< typename T1 // Type of the left-hand side dense matrix
184  , typename T2 > // Type of the right-hand side dense matrix
185 inline bool operator==( const DenseMatrix<T1,true>& lhs, const DenseMatrix<T2,true>& rhs )
186 {
187  typedef typename T1::CompositeType CT1;
188  typedef typename T2::CompositeType CT2;
189 
190  // Early exit in case the matrix sizes don't match
191  if( (~lhs).rows() != (~rhs).rows() || (~lhs).columns() != (~rhs).columns() )
192  return false;
193 
194  // Evaluation of the two dense matrix operands
195  CT1 A( ~lhs );
196  CT2 B( ~rhs );
197 
198  // In order to compare the two matrices, the data values of the lower-order data
199  // type are converted to the higher-order data type within the equal function.
200  for( size_t j=0; j<A.columns(); ++j ) {
201  for( size_t i=0; i<A.rows(); ++i ) {
202  if( !equal( A(i,j), B(i,j) ) ) return false;
203  }
204  }
205 
206  return true;
207 }
208 //*************************************************************************************************
209 
210 
211 //*************************************************************************************************
219 template< typename T1 // Type of the left-hand side dense matrix
220  , typename T2 // Type of the right-hand side dense matrix
221  , bool SO > // Storage order
222 inline bool operator==( const DenseMatrix<T1,SO>& lhs, const DenseMatrix<T2,!SO>& rhs )
223 {
224  typedef typename T1::CompositeType CT1;
225  typedef typename T2::CompositeType CT2;
226 
227  // Early exit in case the matrix sizes don't match
228  if( (~lhs).rows() != (~rhs).rows() || (~lhs).columns() != (~rhs).columns() )
229  return false;
230 
231  // Evaluation of the two dense matrix operands
232  CT1 A( ~lhs );
233  CT2 B( ~rhs );
234 
235  // In order to compare the two matrices, the data values of the lower-order data
236  // type are converted to the higher-order data type within the equal function.
237  const size_t rows ( A.rows() );
238  const size_t columns( A.columns() );
239  const size_t block ( 16 );
240 
241  for( size_t ii=0; ii<rows; ii+=block ) {
242  const size_t iend( ( rows < ii+block )?( rows ):( ii+block ) );
243  for( size_t jj=0; jj<columns; jj+=block ) {
244  const size_t jend( ( columns < jj+block )?( columns ):( jj+block ) );
245  for( size_t i=ii; i<iend; ++i ) {
246  for( size_t j=jj; j<jend; ++j ) {
247  if( !equal( A(i,j), B(i,j) ) ) return false;
248  }
249  }
250  }
251  }
252 
253  return true;
254 }
255 //*************************************************************************************************
256 
257 
258 //*************************************************************************************************
266 template< typename T1 // Type of the left-hand side dense matrix
267  , typename T2 // Type of the right-hand side sparse matrix
268  , bool SO > // Storage order of the left-hand side dense matrix
269 inline bool operator==( const DenseMatrix<T1,SO>& lhs, const SparseMatrix<T2,false>& rhs )
270 {
271  typedef typename T1::CompositeType CT1;
272  typedef typename T2::CompositeType CT2;
274 
275  // Early exit in case the matrix sizes don't match
276  if( (~lhs).rows() != (~rhs).rows() || (~lhs).columns() != (~rhs).columns() )
277  return false;
278 
279  // Evaluation of the dense matrix and sparse matrix operand
280  CT1 A( ~lhs );
281  CT2 B( ~rhs );
282 
283  // In order to compare the two matrices, the data values of the lower-order data
284  // type are converted to the higher-order data type within the equal function.
285  size_t j( 0 );
286 
287  for( size_t i=0; i<B.rows(); ++i ) {
288  j = 0;
289  for( ConstIterator element=B.begin(i); element!=B.end(i); ++element, ++j ) {
290  for( ; j<element->index(); ++j ) {
291  if( !isDefault( A(i,j) ) ) return false;
292  }
293  if( !equal( element->value(), A(i,j) ) ) return false;
294  }
295  for( ; j<A.columns(); ++j ) {
296  if( !isDefault( A(i,j) ) ) return false;
297  }
298  }
299 
300  return true;
301 }
302 //*************************************************************************************************
303 
304 
305 //*************************************************************************************************
313 template< typename T1 // Type of the left-hand side dense matrix
314  , typename T2 // Type of the right-hand side sparse matrix
315  , bool SO > // Storage order of the left-hand side dense matrix
316 inline bool operator==( const DenseMatrix<T1,SO>& lhs, const SparseMatrix<T2,true>& rhs )
317 {
318  typedef typename T1::CompositeType CT1;
319  typedef typename T2::CompositeType CT2;
321 
322  // Early exit in case the matrix sizes don't match
323  if( (~lhs).rows() != (~rhs).rows() || (~lhs).columns() != (~rhs).columns() )
324  return false;
325 
326  // Evaluation of the dense matrix and sparse matrix operand
327  CT1 A( ~lhs );
328  CT2 B( ~rhs );
329 
330  // In order to compare the two matrices, the data values of the lower-order data
331  // type are converted to the higher-order data type within the equal function.
332  size_t i( 0 );
333 
334  for( size_t j=0; j<B.columns(); ++j ) {
335  i = 0;
336  for( ConstIterator element=B.begin(j); element!=B.end(j); ++element, ++i ) {
337  for( ; i<element->index(); ++i ) {
338  if( !isDefault( A(i,j) ) ) return false;
339  }
340  if( !equal( element->value(), A(i,j) ) ) return false;
341  }
342  for( ; i<A.rows(); ++i ) {
343  if( !isDefault( A(i,j) ) ) return false;
344  }
345  }
346 
347  return true;
348 }
349 //*************************************************************************************************
350 
351 
352 //*************************************************************************************************
360 template< typename T1 // Type of the left-hand side sparse matrix
361  , bool SO1 // Storage order of the left-hand side sparse matrix
362  , typename T2 // Type of the right-hand side dense matrix
363  , bool SO2 > // Storage order of the right-hand side sparse matrix
364 inline bool operator==( const SparseMatrix<T1,SO1>& lhs, const DenseMatrix<T2,SO2>& rhs )
365 {
366  return ( rhs == lhs );
367 }
368 //*************************************************************************************************
369 
370 
371 //*************************************************************************************************
383 template< typename T1 // Type of the left-hand side dense matrix
384  , typename T2 > // Type of the right-hand side scalar
385 inline typename EnableIf< IsNumeric<T2>, bool >::Type
386  operator==( const DenseMatrix<T1,false>& mat, T2 scalar )
387 {
388  typedef typename T1::CompositeType CT1;
389 
390  // Evaluation of the dense matrix operand
391  CT1 A( ~mat );
392 
393  // In order to compare the matrix and the scalar value, the data values of the lower-order
394  // data type are converted to the higher-order data type within the equal function.
395  for( size_t i=0; i<A.rows(); ++i ) {
396  for( size_t j=0; j<A.columns(); ++j ) {
397  if( !equal( A(i,j), scalar ) ) return false;
398  }
399  }
400 
401  return true;
402 }
403 //*************************************************************************************************
404 
405 
406 //*************************************************************************************************
418 template< typename T1 // Type of the left-hand side dense matrix
419  , typename T2 > // Type of the right-hand side scalar
420 inline typename EnableIf< IsNumeric<T2>, bool >::Type
421  operator==( const DenseMatrix<T1,true>& mat, T2 scalar )
422 {
423  typedef typename T1::CompositeType CT1;
424 
425  // Evaluation of the dense matrix operand
426  CT1 A( ~mat );
427 
428  // In order to compare the matrix and the scalar value, the data values of the lower-order
429  // data type are converted to the higher-order data type within the equal function.
430  for( size_t j=0; j<A.columns(); ++j ) {
431  for( size_t i=0; i<A.rows(); ++i ) {
432  if( !equal( A(i,j), scalar ) ) return false;
433  }
434  }
435 
436  return true;
437 }
438 //*************************************************************************************************
439 
440 
441 //*************************************************************************************************
453 template< typename T1 // Type of the left-hand side scalar
454  , typename T2 // Type of the right-hand side dense matrix
455  , bool SO > // Storage order
456 inline typename EnableIf< IsNumeric<T1>, bool >::Type
457  operator==( T1 scalar, const DenseMatrix<T2,SO>& mat )
458 {
459  return ( mat == scalar );
460 }
461 //*************************************************************************************************
462 
463 
464 //*************************************************************************************************
472 template< typename T1 // Type of the left-hand side dense matrix
473  , bool SO1 // Storage order of the left-hand side dense matrix
474  , typename T2 // Type of the right-hand side dense matrix
475  , bool SO2 > // Storage order of the right-hand side dense matrix
476 inline bool operator!=( const DenseMatrix<T1,SO1>& lhs, const DenseMatrix<T2,SO2>& rhs )
477 {
478  return !( lhs == rhs );
479 }
480 //*************************************************************************************************
481 
482 
483 //*************************************************************************************************
491 template< typename T1 // Type of the left-hand side dense matrix
492  , bool SO1 // Storage order of the left-hand side dense matrix
493  , typename T2 // Type of the right-hand side sparse matrix
494  , bool SO2 > // Storage order of the right-hand side sparse matrix
495 inline bool operator!=( const DenseMatrix<T1,SO1>& lhs, const SparseMatrix<T2,SO2>& rhs )
496 {
497  return !( lhs == rhs );
498 }
499 //*************************************************************************************************
500 
501 
502 //*************************************************************************************************
510 template< typename T1 // Type of the left-hand side sparse matrix
511  , bool SO1 // Storage order of the left-hand side sparse matrix
512  , typename T2 // Type of the right-hand side dense matrix
513  , bool SO2 > // Storage order right-hand side dense matrix
514 inline bool operator!=( const SparseMatrix<T1,SO1>& lhs, const DenseMatrix<T2,SO2>& rhs )
515 {
516  return !( rhs == lhs );
517 }
518 //*************************************************************************************************
519 
520 
521 //*************************************************************************************************
533 template< typename T1 // Type of the left-hand side dense matrix
534  , typename T2 // Type of the right-hand side scalar
535  , bool SO > // Storage order
536 inline typename EnableIf< IsNumeric<T2>, bool >::Type
537  operator!=( const DenseMatrix<T1,SO>& mat, T2 scalar )
538 {
539  return !( mat == scalar );
540 }
541 //*************************************************************************************************
542 
543 
544 //*************************************************************************************************
556 template< typename T1 // Type of the left-hand side scalar
557  , typename T2 // Type of the right-hand side dense matrix
558  , bool SO > // Storage order
559 inline typename EnableIf< IsNumeric<T1>, bool >::Type
560  operator!=( T1 scalar, const DenseMatrix<T2,SO>& mat )
561 {
562  return !( mat == scalar );
563 }
564 //*************************************************************************************************
565 
566 
567 
568 
569 //=================================================================================================
570 //
571 // GLOBAL FUNCTIONS
572 //
573 //=================================================================================================
574 
575 //*************************************************************************************************
578 template< typename MT, bool SO >
579 bool isnan( const DenseMatrix<MT,SO>& dm );
580 
581 template< typename MT, bool SO >
582 bool isSymmetric( const DenseMatrix<MT,SO>& dm );
583 
584 template< typename MT, bool SO >
585 bool isHermitian( const DenseMatrix<MT,SO>& dm );
586 
587 template< typename MT, bool SO >
588 bool isUniform( const DenseMatrix<MT,SO>& dm );
589 
590 template< typename MT, bool SO >
591 bool isLower( const DenseMatrix<MT,SO>& dm );
592 
593 template< typename MT, bool SO >
594 bool isUniLower( const DenseMatrix<MT,SO>& dm );
595 
596 template< typename MT, bool SO >
597 bool isStrictlyLower( const DenseMatrix<MT,SO>& dm );
598 
599 template< typename MT, bool SO >
600 bool isUpper( const DenseMatrix<MT,SO>& dm );
601 
602 template< typename MT, bool SO >
603 bool isUniUpper( const DenseMatrix<MT,SO>& dm );
604 
605 template< typename MT, bool SO >
606 bool isStrictlyUpper( const DenseMatrix<MT,SO>& dm );
607 
608 template< typename MT, bool SO >
609 bool isDiagonal( const DenseMatrix<MT,SO>& dm );
610 
611 template< typename MT, bool SO >
612 bool isIdentity( const DenseMatrix<MT,SO>& dm );
613 
614 template< typename MT, bool SO >
615 const typename MT::ElementType min( const DenseMatrix<MT,SO>& dm );
616 
617 template< typename MT, bool SO >
618 const typename MT::ElementType max( const DenseMatrix<MT,SO>& dm );
620 //*************************************************************************************************
621 
622 
623 //*************************************************************************************************
643 template< typename MT // Type of the dense matrix
644  , bool SO > // Storage order
645 bool isnan( const DenseMatrix<MT,SO>& dm )
646 {
647  typedef typename MT::CompositeType CT;
648 
649  CT A( ~dm ); // Evaluation of the dense matrix operand
650 
651  if( SO == rowMajor ) {
652  for( size_t i=0UL; i<A.rows(); ++i ) {
653  for( size_t j=0UL; j<A.columns(); ++j )
654  if( isnan( A(i,j) ) ) return true;
655  }
656  }
657  else {
658  for( size_t j=0UL; j<A.columns(); ++j ) {
659  for( size_t i=0UL; i<A.rows(); ++i )
660  if( isnan( A(i,j) ) ) return true;
661  }
662  }
663 
664  return false;
665 }
666 //*************************************************************************************************
667 
668 
669 //*************************************************************************************************
695 template< typename MT // Type of the dense matrix
696  , bool SO > // Storage order
698 {
699  typedef typename MT::CompositeType CT;
700 
702  return true;
703 
704  if( !isSquare( ~dm ) )
705  return false;
706 
707  if( (~dm).rows() < 2UL )
708  return true;
709 
711  return isDiagonal( ~dm );
712 
713  CT A( ~dm ); // Evaluation of the dense matrix operand
714 
715  if( SO == rowMajor ) {
716  for( size_t i=1UL; i<A.rows(); ++i ) {
717  for( size_t j=0UL; j<i; ++j ) {
718  if( !equal( A(i,j), A(j,i) ) )
719  return false;
720  }
721  }
722  }
723  else {
724  for( size_t j=1UL; j<A.columns(); ++j ) {
725  for( size_t i=0UL; i<j; ++i ) {
726  if( !equal( A(i,j), A(j,i) ) )
727  return false;
728  }
729  }
730  }
731 
732  return true;
733 }
734 //*************************************************************************************************
735 
736 
737 //*************************************************************************************************
765 template< typename MT // Type of the dense matrix
766  , bool SO > // Storage order
768 {
769  typedef typename MT::ElementType ET;
770  typedef typename MT::CompositeType CT;
771 
773  return true;
774 
775  if( !IsNumeric<ET>::value || !isSquare( ~dm ) )
776  return false;
777 
778  if( (~dm).rows() < 2UL )
779  return true;
780 
782  return isDiagonal( ~dm );
783 
784  CT A( ~dm ); // Evaluation of the dense matrix operand
785 
786  if( SO == rowMajor ) {
787  for( size_t i=0UL; i<A.rows(); ++i ) {
788  for( size_t j=0UL; j<i; ++j ) {
789  if( !equal( A(i,j), conj( A(j,i) ) ) )
790  return false;
791  }
792  if( !isReal( A(i,i) ) )
793  return false;
794  }
795  }
796  else {
797  for( size_t j=0UL; j<A.columns(); ++j ) {
798  for( size_t i=0UL; i<j; ++i ) {
799  if( !equal( A(i,j), conj( A(j,i) ) ) )
800  return false;
801  }
802  if( !isReal( A(j,j) ) )
803  return false;
804  }
805  }
806 
807  return true;
808 }
809 //*************************************************************************************************
810 
811 
812 //*************************************************************************************************
820 template< typename MT > // Type of the dense matrix
821 bool isUniform_backend( const DenseMatrix<MT,false>& dm, TrueType )
822 {
825 
826  BLAZE_INTERNAL_ASSERT( (~dm).rows() != 0UL, "Invalid number of rows detected" );
827  BLAZE_INTERNAL_ASSERT( (~dm).columns() != 0UL, "Invalid number of columns detected" );
828 
829  const size_t ibegin( ( IsStrictlyLower<MT>::value )?( 1UL ):( 0UL ) );
830  const size_t iend ( ( IsStrictlyUpper<MT>::value )?( (~dm).rows()-1UL ):( (~dm).rows() ) );
831 
832  for( size_t i=ibegin; i<iend; ++i ) {
833  if( !IsUpper<MT>::value ) {
834  for( size_t j=0UL; j<i; ++j ) {
835  if( !isDefault( (~dm)(i,j) ) )
836  return false;
837  }
838  }
839  if( !isDefault( (~dm)(i,i) ) )
840  return false;
841  if( !IsLower<MT>::value ) {
842  for( size_t j=i+1UL; j<(~dm).columns(); ++j ) {
843  if( !isDefault( (~dm)(i,j) ) )
844  return false;
845  }
846  }
847  }
848 
849  return true;
850 }
852 //*************************************************************************************************
853 
854 
855 //*************************************************************************************************
863 template< typename MT > // Type of the dense matrix
864 bool isUniform_backend( const DenseMatrix<MT,true>& dm, TrueType )
865 {
868 
869  BLAZE_INTERNAL_ASSERT( (~dm).rows() != 0UL, "Invalid number of rows detected" );
870  BLAZE_INTERNAL_ASSERT( (~dm).columns() != 0UL, "Invalid number of columns detected" );
871 
872  const size_t jbegin( ( IsStrictlyUpper<MT>::value )?( 1UL ):( 0UL ) );
873  const size_t jend ( ( IsStrictlyLower<MT>::value )?( (~dm).columns()-1UL ):( (~dm).columns() ) );
874 
875  for( size_t j=jbegin; j<jend; ++j ) {
876  if( !IsLower<MT>::value ) {
877  for( size_t i=0UL; i<j; ++i ) {
878  if( !isDefault( (~dm)(i,j) ) )
879  return false;
880  }
881  }
882  if( !isDefault( (~dm)(j,j) ) )
883  return false;
884  if( !IsUpper<MT>::value ) {
885  for( size_t i=j+1UL; i<(~dm).rows(); ++i ) {
886  if( !isDefault( (~dm)(i,j) ) )
887  return false;
888  }
889  }
890  }
891 
892  return true;
893 }
895 //*************************************************************************************************
896 
897 
898 //*************************************************************************************************
906 template< typename MT > // Type of the dense matrix
907 bool isUniform_backend( const DenseMatrix<MT,false>& dm, FalseType )
908 {
911 
912  BLAZE_INTERNAL_ASSERT( (~dm).rows() != 0UL, "Invalid number of rows detected" );
913  BLAZE_INTERNAL_ASSERT( (~dm).columns() != 0UL, "Invalid number of columns detected" );
914 
915  typename MT::ConstReference cmp( (~dm)(0UL,0UL) );
916 
917  for( size_t i=0UL; i<(~dm).rows(); ++i ) {
918  for( size_t j=0UL; j<(~dm).columns(); ++j ) {
919  if( (~dm)(i,j) != cmp )
920  return false;
921  }
922  }
923 
924  return true;
925 }
927 //*************************************************************************************************
928 
929 
930 //*************************************************************************************************
938 template< typename MT > // Type of the dense matrix
939 bool isUniform_backend( const DenseMatrix<MT,true>& dm, FalseType )
940 {
943 
944  BLAZE_INTERNAL_ASSERT( (~dm).rows() != 0UL, "Invalid number of rows detected" );
945  BLAZE_INTERNAL_ASSERT( (~dm).columns() != 0UL, "Invalid number of columns detected" );
946 
947  typename MT::ConstReference cmp( (~dm)(0UL,0UL) );
948 
949  for( size_t j=0UL; j<(~dm).columns(); ++j ) {
950  for( size_t i=0UL; i<(~dm).rows(); ++i ) {
951  if( (~dm)(i,j) != cmp )
952  return false;
953  }
954  }
955 
956  return true;
957 }
959 //*************************************************************************************************
960 
961 
962 //*************************************************************************************************
988 template< typename MT // Type of the dense matrix
989  , bool SO > // Storage order
990 bool isUniform( const DenseMatrix<MT,SO>& dm )
991 {
993  return false;
994 
995  if( (~dm).rows() == 0UL || (~dm).columns() == 0UL ||
996  ( (~dm).rows() == 1UL && (~dm).columns() == 1UL ) )
997  return true;
998 
999  typename MT::CompositeType A( ~dm ); // Evaluation of the dense matrix operand
1000 
1001  return isUniform_backend( A, typename IsTriangular<MT>::Type() );
1002 }
1003 //*************************************************************************************************
1004 
1005 
1006 //*************************************************************************************************
1042 template< typename MT // Type of the dense matrix
1043  , bool SO > // Storage order
1044 bool isLower( const DenseMatrix<MT,SO>& dm )
1045 {
1046  typedef typename MT::ResultType RT;
1047  typedef typename MT::ReturnType RN;
1048  typedef typename MT::CompositeType CT;
1049  typedef typename If< IsExpression<RN>, const RT, CT >::Type Tmp;
1050 
1051  if( IsLower<MT>::value )
1052  return true;
1053 
1054  if( !isSquare( ~dm ) )
1055  return false;
1056 
1057  if( (~dm).rows() < 2UL )
1058  return true;
1059 
1060  Tmp A( ~dm ); // Evaluation of the dense matrix operand
1061 
1062  if( SO == rowMajor ) {
1063  for( size_t i=0UL; i<A.rows()-1UL; ++i ) {
1064  for( size_t j=i+1UL; j<A.columns(); ++j ) {
1065  if( !isDefault( A(i,j) ) )
1066  return false;
1067  }
1068  }
1069  }
1070  else {
1071  for( size_t j=1UL; j<A.columns(); ++j ) {
1072  for( size_t i=0UL; i<j; ++i ) {
1073  if( !isDefault( A(i,j) ) )
1074  return false;
1075  }
1076  }
1077  }
1078 
1079  return true;
1080 }
1081 //*************************************************************************************************
1082 
1083 
1084 //*************************************************************************************************
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 
1129  if( IsUniLower<MT>::value )
1130  return true;
1131 
1132  if( !isSquare( ~dm ) )
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  if( !isOne( A(i,i) ) )
1140  return false;
1141  for( size_t j=i+1UL; j<A.columns(); ++j ) {
1142  if( !isDefault( A(i,j) ) )
1143  return false;
1144  }
1145  }
1146  }
1147  else {
1148  for( size_t j=0UL; j<A.columns(); ++j ) {
1149  for( size_t i=0UL; i<j; ++i ) {
1150  if( !isDefault( A(i,j) ) )
1151  return false;
1152  }
1153  if( !isOne( A(j,j) ) )
1154  return false;
1155  }
1156  }
1157 
1158  return true;
1159 }
1160 //*************************************************************************************************
1161 
1162 
1163 //*************************************************************************************************
1199 template< typename MT // Type of the dense matrix
1200  , bool SO > // Storage order
1202 {
1203  typedef typename MT::ResultType RT;
1204  typedef typename MT::ElementType ET;
1205  typedef typename MT::ReturnType RN;
1206  typedef typename MT::CompositeType CT;
1207  typedef typename If< IsExpression<RN>, const RT, CT >::Type Tmp;
1208 
1210  return true;
1211 
1213  return false;
1214 
1215  Tmp A( ~dm ); // Evaluation of the dense matrix operand
1216 
1217  if( SO == rowMajor ) {
1218  for( size_t i=0UL; i<A.rows(); ++i ) {
1219  for( size_t j=i; j<A.columns(); ++j ) {
1220  if( !isDefault( A(i,j) ) )
1221  return false;
1222  }
1223  }
1224  }
1225  else {
1226  for( size_t j=0UL; j<A.columns(); ++j ) {
1227  for( size_t i=0UL; i<=j; ++i ) {
1228  if( !isDefault( A(i,j) ) )
1229  return false;
1230  }
1231  }
1232  }
1233 
1234  return true;
1235 }
1236 //*************************************************************************************************
1237 
1238 
1239 //*************************************************************************************************
1275 template< typename MT // Type of the dense matrix
1276  , bool SO > // Storage order
1277 bool isUpper( const DenseMatrix<MT,SO>& dm )
1278 {
1279  typedef typename MT::ResultType RT;
1280  typedef typename MT::ReturnType RN;
1281  typedef typename MT::CompositeType CT;
1282  typedef typename If< IsExpression<RN>, const RT, CT >::Type Tmp;
1283 
1284  if( IsUpper<MT>::value )
1285  return true;
1286 
1287  if( !isSquare( ~dm ) )
1288  return false;
1289 
1290  if( (~dm).rows() < 2UL )
1291  return true;
1292 
1293  Tmp A( ~dm ); // Evaluation of the dense matrix operand
1294 
1295  if( SO == rowMajor ) {
1296  for( size_t i=1UL; i<A.rows(); ++i ) {
1297  for( size_t j=0UL; j<i; ++j ) {
1298  if( !isDefault( A(i,j) ) )
1299  return false;
1300  }
1301  }
1302  }
1303  else {
1304  for( size_t j=0UL; j<A.columns()-1UL; ++j ) {
1305  for( size_t i=j+1UL; i<A.rows(); ++i ) {
1306  if( !isDefault( A(i,j) ) )
1307  return false;
1308  }
1309  }
1310  }
1311 
1312  return true;
1313 }
1314 //*************************************************************************************************
1315 
1316 
1317 //*************************************************************************************************
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 
1362  if( IsUniUpper<MT>::value )
1363  return true;
1364 
1365  if( !isSquare( ~dm ) )
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  if( !isOne( A(i,i) ) )
1377  return false;
1378  }
1379  }
1380  else {
1381  for( size_t j=0UL; j<A.columns(); ++j ) {
1382  if( !isOne( A(j,j) ) )
1383  return false;
1384  for( size_t i=j+1UL; i<A.rows(); ++i ) {
1385  if( !isDefault( A(i,j) ) )
1386  return false;
1387  }
1388  }
1389  }
1390 
1391  return true;
1392 }
1393 //*************************************************************************************************
1394 
1395 
1396 //*************************************************************************************************
1432 template< typename MT // Type of the dense matrix
1433  , bool SO > // Storage order
1435 {
1436  typedef typename MT::ResultType RT;
1437  typedef typename MT::ElementType ET;
1438  typedef typename MT::ReturnType RN;
1439  typedef typename MT::CompositeType CT;
1440  typedef typename If< IsExpression<RN>, const RT, CT >::Type Tmp;
1441 
1443  return true;
1444 
1446  return false;
1447 
1448  Tmp A( ~dm ); // Evaluation of the dense matrix operand
1449 
1450  if( SO == rowMajor ) {
1451  for( size_t i=0UL; i<A.rows(); ++i ) {
1452  for( size_t j=0UL; j<=i; ++j ) {
1453  if( !isDefault( A(i,j) ) )
1454  return false;
1455  }
1456  }
1457  }
1458  else {
1459  for( size_t j=0UL; j<A.columns(); ++j ) {
1460  for( size_t i=j; i<A.rows(); ++i ) {
1461  if( !isDefault( A(i,j) ) )
1462  return false;
1463  }
1464  }
1465  }
1466 
1467  return true;
1468 }
1469 //*************************************************************************************************
1470 
1471 
1472 //*************************************************************************************************
1509 template< typename MT // Type of the dense matrix
1510  , bool SO > // Storage order
1512 {
1513  typedef typename MT::ResultType RT;
1514  typedef typename MT::ReturnType RN;
1515  typedef typename MT::CompositeType CT;
1516  typedef typename If< IsExpression<RN>, const RT, CT >::Type Tmp;
1517 
1518  if( IsDiagonal<MT>::value )
1519  return true;
1520 
1521  if( !isSquare( ~dm ) )
1522  return false;
1523 
1524  if( (~dm).rows() < 2UL )
1525  return true;
1526 
1527  Tmp A( ~dm ); // Evaluation of the dense matrix operand
1528 
1529  if( SO == rowMajor ) {
1530  for( size_t i=0UL; i<A.rows(); ++i ) {
1531  if( !IsUpper<MT>::value ) {
1532  for( size_t j=0UL; j<i; ++j ) {
1533  if( !isDefault( A(i,j) ) )
1534  return false;
1535  }
1536  }
1537  if( !IsLower<MT>::value ) {
1538  for( size_t j=i+1UL; j<A.columns(); ++j ) {
1539  if( !isDefault( A(i,j) ) )
1540  return false;
1541  }
1542  }
1543  }
1544  }
1545  else {
1546  for( size_t j=0UL; j<A.columns(); ++j ) {
1547  if( !IsLower<MT>::value ) {
1548  for( size_t i=0UL; i<j; ++i ) {
1549  if( !isDefault( A(i,j) ) )
1550  return false;
1551  }
1552  }
1553  if( !IsUpper<MT>::value ) {
1554  for( size_t i=j+1UL; i<A.rows(); ++i ) {
1555  if( !isDefault( A(i,j) ) )
1556  return false;
1557  }
1558  }
1559  }
1560  }
1561 
1562  return true;
1563 }
1564 //*************************************************************************************************
1565 
1566 
1567 //*************************************************************************************************
1603 template< typename MT // Type of the dense matrix
1604  , bool SO > // Storage order
1606 {
1607  typedef typename MT::ResultType RT;
1608  typedef typename MT::ElementType ET;
1609  typedef typename MT::ReturnType RN;
1610  typedef typename MT::CompositeType CT;
1611  typedef typename If< IsExpression<RN>, const RT, CT >::Type Tmp;
1612 
1613  if( IsIdentity<MT>::value )
1614  return true;
1615 
1616  if( !isSquare( ~dm ) )
1617  return false;
1618 
1619  if( (~dm).rows() == 0UL )
1620  return true;
1621 
1622  Tmp A( ~dm ); // Evaluation of the dense matrix operand
1623 
1624  if( SO == rowMajor ) {
1625  for( size_t i=0UL; i<A.rows(); ++i ) {
1626  if( !IsUpper<MT>::value ) {
1627  for( size_t j=0UL; j<i; ++j ) {
1628  if( !isDefault( A(i,j) ) )
1629  return false;
1630  }
1631  }
1632  if( !IsUniLower<MT>::value && !IsUniUpper<MT>::value && !isOne( A(i,i) ) ) {
1633  return false;
1634  }
1635  if( !IsLower<MT>::value ) {
1636  for( size_t j=i+1UL; j<A.columns(); ++j ) {
1637  if( !isDefault( A(i,j) ) )
1638  return false;
1639  }
1640  }
1641  }
1642  }
1643  else {
1644  for( size_t j=0UL; j<A.columns(); ++j ) {
1645  if( !IsLower<MT>::value ) {
1646  for( size_t i=0UL; i<j; ++i ) {
1647  if( !isDefault( A(i,j) ) )
1648  return false;
1649  }
1650  }
1651  if( !IsUniLower<MT>::value && !IsUniUpper<MT>::value && !isOne( A(j,j) ) ) {
1652  return false;
1653  }
1654  if( !IsUpper<MT>::value ) {
1655  for( size_t i=j+1UL; i<A.rows(); ++i ) {
1656  if( !isDefault( A(i,j) ) )
1657  return false;
1658  }
1659  }
1660  }
1661  }
1662 
1663  return true;
1664 }
1665 //*************************************************************************************************
1666 
1667 
1668 //*************************************************************************************************
1680 template< typename MT // Type of the dense matrix
1681  , bool SO > // Storage order
1682 const typename MT::ElementType min( const DenseMatrix<MT,SO>& dm )
1683 {
1684  using blaze::min;
1685 
1686  typedef typename MT::ElementType ET;
1687  typedef typename MT::CompositeType CT;
1688 
1689  CT A( ~dm ); // Evaluation of the dense matrix operand
1690 
1691  if( A.rows() == 0UL || A.columns() == 0UL ) return ET();
1692 
1693  ET minimum( A(0,0) );
1694 
1695  if( SO == rowMajor ) {
1696  for( size_t j=1UL; j<A.columns(); ++j )
1697  minimum = min( minimum, A(0UL,j) );
1698  for( size_t i=1UL; i<A.rows(); ++i )
1699  for( size_t j=0UL; j<A.columns(); ++j )
1700  minimum = min( minimum, A(i,j) );
1701  }
1702  else {
1703  for( size_t i=1UL; i<A.rows(); ++i )
1704  minimum = min( minimum, A(i,0UL) );
1705  for( size_t j=1UL; j<A.columns(); ++j )
1706  for( size_t i=0UL; i<A.rows(); ++i )
1707  minimum = min( minimum, A(i,j) );
1708  }
1709 
1710  return minimum;
1711 }
1712 //*************************************************************************************************
1713 
1714 
1715 //*************************************************************************************************
1727 template< typename MT // Type of the dense matrix
1728  , bool SO > // Transpose flag
1729 const typename MT::ElementType max( const DenseMatrix<MT,SO>& dm )
1730 {
1731  using blaze::max;
1732 
1733  typedef typename MT::ElementType ET;
1734  typedef typename MT::CompositeType CT;
1735 
1736  CT A( ~dm ); // Evaluation of the dense matrix operand
1737 
1738  if( A.rows() == 0UL || A.columns() == 0UL ) return ET();
1739 
1740  ET maximum( A(0,0) );
1741 
1742  if( SO == rowMajor ) {
1743  for( size_t j=1UL; j<A.columns(); ++j )
1744  maximum = max( maximum, A(0UL,j) );
1745  for( size_t i=1UL; i<A.rows(); ++i )
1746  for( size_t j=0UL; j<A.columns(); ++j )
1747  maximum = max( maximum, A(i,j) );
1748  }
1749  else {
1750  for( size_t i=1UL; i<A.rows(); ++i )
1751  maximum = max( maximum, A(i,0UL) );
1752  for( size_t j=1UL; j<A.columns(); ++j )
1753  for( size_t i=0UL; i<A.rows(); ++i )
1754  maximum = max( maximum, A(i,j) );
1755  }
1756 
1757  return maximum;
1758 }
1759 //*************************************************************************************************
1760 
1761 } // namespace blaze
1762 
1763 #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.
bool isOne(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 1.
Definition: DiagonalProxy.h:609
const MT::ElementType max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:1729
Compile time check for numeric types.This type trait tests whether or not the given template paramete...
Definition: IsNumeric.h:98
Header file for mathematical functions.
bool isDiagonal(const DenseMatrix< MT, SO > &dm)
Checks if the give dense matrix is diagonal.
Definition: DenseMatrix.h:1511
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:603
#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:1201
bool isStrictlyUpper(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a strictly upper triangular matrix.
Definition: DenseMatrix.h:1434
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:569
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:697
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2588
BLAZE_ALWAYS_INLINE size_t rows(const Matrix< MT, SO > &matrix)
Returns the current number of rows of the matrix.
Definition: Matrix.h:308
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.
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:1044
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:117
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:547
Header file for the SparseMatrix base class.
ConjExprTrait< typename DiagonalProxy< MT >::RepresentedType >::Type conj(const DiagonalProxy< MT > &proxy)
Computing the complex conjugate of the represented element.
Definition: DiagonalProxy.h:487
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:2592
const MT::ElementType min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1682
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:1277
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:629
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:1121
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2586
Constraint on the data type.
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2590
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 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:92
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2587
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:73
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: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:990
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 isHermitian(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is Hermitian.
Definition: DenseMatrix.h:767
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:2583
BLAZE_ALWAYS_INLINE size_t columns(const Matrix< MT, SO > &matrix)
Returns the current number of columns of the matrix.
Definition: Matrix.h:324
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:1354
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
Header file for the IsHermitian type trait.
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:105
bool isIdentity(const DenseMatrix< MT, SO > &dm)
Checks if the give dense matrix is an identity matrix.
Definition: DenseMatrix.h:1605
Header file for the IsExpression type trait class.