Submatrix.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_VIEWS_SUBMATRIX_H_
36 #define _BLAZE_MATH_VIEWS_SUBMATRIX_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
45 #include <blaze/math/Functions.h>
68 #include <blaze/util/DisableIf.h>
69 #include <blaze/util/EnableIf.h>
71 #include <blaze/util/mpl/Or.h>
72 #include <blaze/util/Types.h>
74 
75 
76 namespace blaze {
77 
78 //=================================================================================================
79 //
80 // GLOBAL FUNCTION
81 //
82 //=================================================================================================
83 
84 //*************************************************************************************************
143 template< typename MT // Type of the dense matrix
144  , bool SO > // Storage order
145 inline typename SubmatrixExprTrait<MT,unaligned>::Type
146  submatrix( Matrix<MT,SO>& matrix, size_t row, size_t column, size_t m, size_t n )
147 {
149 
150  return submatrix<unaligned>( ~matrix, row, column, m, n );
151 }
152 //*************************************************************************************************
153 
154 
155 //*************************************************************************************************
214 template< typename MT // Type of the dense matrix
215  , bool SO > // Storage order
216 inline typename SubmatrixExprTrait<const MT,unaligned>::Type
217  submatrix( const Matrix<MT,SO>& matrix, size_t row, size_t column, size_t m, size_t n )
218 {
220 
221  return submatrix<unaligned>( ~matrix, row, column, m, n );
222 }
223 //*************************************************************************************************
224 
225 
226 //*************************************************************************************************
300 template< bool AF // Alignment flag
301  , typename MT // Type of the dense matrix
302  , bool SO > // Storage order
303 inline typename DisableIf< Or< IsComputation<MT>, IsTransExpr<MT> >
304  , typename SubmatrixExprTrait<MT,AF>::Type >::Type
305  submatrix( Matrix<MT,SO>& matrix, size_t row, size_t column, size_t m, size_t n )
306 {
308 
310  return ReturnType( ~matrix, row, column, m, n );
311 }
312 //*************************************************************************************************
313 
314 
315 //*************************************************************************************************
389 template< bool AF // Alignment flag
390  , typename MT // Type of the dense matrix
391  , bool SO > // Storage order
392 inline typename DisableIf< Or< IsComputation<MT>, IsTransExpr<MT> >
393  , typename SubmatrixExprTrait<const MT,AF>::Type >::Type
394  submatrix( const Matrix<MT,SO>& matrix, size_t row, size_t column, size_t m, size_t n )
395 {
397 
399  return ReturnType( ~matrix, row, column, m, n );
400 }
401 //*************************************************************************************************
402 
403 
404 
405 
406 //=================================================================================================
407 //
408 // GLOBAL RESTRUCTURING OPERATORS
409 //
410 //=================================================================================================
411 
412 //*************************************************************************************************
427 template< bool AF // Alignment flag
428  , typename MT // Type of the matrix
429  , bool SO > // Storage order
430 inline typename EnableIf< IsMatMatAddExpr<MT>, typename SubmatrixExprTrait<MT,AF>::Type >::Type
431  submatrix( const Matrix<MT,SO>& matrix, size_t row, size_t column, size_t m, size_t n )
432 {
434 
435  return submatrix<AF>( (~matrix).leftOperand() , row, column, m, n ) +
436  submatrix<AF>( (~matrix).rightOperand(), row, column, m, n );
437 }
439 //*************************************************************************************************
440 
441 
442 //*************************************************************************************************
457 template< bool AF // Alignment flag
458  , typename MT // Type of the matrix
459  , bool SO > // Storage order
460 inline typename EnableIf< IsMatMatSubExpr<MT>, typename SubmatrixExprTrait<MT,AF>::Type >::Type
461  submatrix( const Matrix<MT,SO>& matrix, size_t row, size_t column, size_t m, size_t n )
462 {
464 
465  return submatrix<AF>( (~matrix).leftOperand() , row, column, m, n ) -
466  submatrix<AF>( (~matrix).rightOperand(), row, column, m, n );
467 }
469 //*************************************************************************************************
470 
471 
472 //*************************************************************************************************
487 template< bool AF // Alignment flag
488  , typename MT // Type of the matrix
489  , bool SO > // Storage order
490 inline typename EnableIf< IsMatMatMultExpr<MT>, typename SubmatrixExprTrait<MT,AF>::Type >::Type
491  submatrix( const Matrix<MT,SO>& matrix, size_t row, size_t column, size_t m, size_t n )
492 {
494 
495  typedef typename RemoveReference< typename MT::LeftOperand >::Type MT1;
496  typedef typename RemoveReference< typename MT::RightOperand >::Type MT2;
497 
498  typename MT::LeftOperand left ( (~matrix).leftOperand() );
499  typename MT::RightOperand right( (~matrix).rightOperand() );
500 
501  const size_t begin( max( ( IsUpper<MT1>::value )
502  ?( ( !AF && IsStrictlyUpper<MT1>::value )?( row + 1UL ):( row ) )
503  :( 0UL )
504  , ( IsLower<MT2>::value )
505  ?( ( !AF && IsStrictlyLower<MT2>::value )?( column + 1UL ):( column ) )
506  :( 0UL ) ) );
507  const size_t end( min( ( IsLower<MT1>::value )
508  ?( ( IsStrictlyLower<MT1>::value && m > 0UL )?( row + m - 1UL ):( row + m ) )
509  :( left.columns() )
510  , ( IsUpper<MT2>::value )
511  ?( ( IsStrictlyUpper<MT2>::value && n > 0UL )?( column + n - 1UL ):( column + n ) )
512  :( left.columns() ) ) );
513 
514  const size_t diff( ( begin < end )?( end - begin ):( 0UL ) );
515 
516  return submatrix<AF>( left, row, begin, m, diff ) *
517  submatrix<AF>( right, begin, column, diff, n );
518 }
520 //*************************************************************************************************
521 
522 
523 //*************************************************************************************************
538 template< bool AF // Alignment flag
539  , typename MT // Type of the matrix
540  , bool SO > // Storage order
541 inline typename EnableIf< IsVecTVecMultExpr<MT>, typename SubmatrixExprTrait<MT,AF>::Type >::Type
542  submatrix( const Matrix<MT,SO>& matrix, size_t row, size_t column, size_t m, size_t n )
543 {
545 
546  return subvector<AF>( (~matrix).leftOperand(), row, m ) *
547  subvector<AF>( (~matrix).rightOperand(), column, n );
548 }
550 //*************************************************************************************************
551 
552 
553 //*************************************************************************************************
568 template< bool AF // Alignment flag
569  , typename MT // Type of the matrix
570  , bool SO > // Storage order
571 inline typename EnableIf< IsMatScalarMultExpr<MT>, typename SubmatrixExprTrait<MT,AF>::Type >::Type
572  submatrix( const Matrix<MT,SO>& matrix, size_t row, size_t column, size_t m, size_t n )
573 {
575 
576  return submatrix<AF>( (~matrix).leftOperand(), row, column, m, n ) * (~matrix).rightOperand();
577 }
579 //*************************************************************************************************
580 
581 
582 //*************************************************************************************************
597 template< bool AF // Alignment flag
598  , typename MT // Type of the matrix
599  , bool SO > // Storage order
600 inline typename EnableIf< IsMatScalarDivExpr<MT>, typename SubmatrixExprTrait<MT,AF>::Type >::Type
601  submatrix( const Matrix<MT,SO>& matrix, size_t row, size_t column, size_t m, size_t n )
602 {
604 
605  return submatrix<AF>( (~matrix).leftOperand(), row, column, m, n ) / (~matrix).rightOperand();
606 }
608 //*************************************************************************************************
609 
610 
611 //*************************************************************************************************
626 template< bool AF // Alignment flag
627  , typename MT // Type of the matrix
628  , bool SO > // Storage order
629 inline typename EnableIf< IsMatAbsExpr<MT>, typename SubmatrixExprTrait<MT,AF>::Type >::Type
630  submatrix( const Matrix<MT,SO>& matrix, size_t row, size_t column, size_t m, size_t n )
631 {
633 
634  return abs( submatrix<AF>( (~matrix).operand(), row, column, m, n ) );
635 }
637 //*************************************************************************************************
638 
639 
640 //*************************************************************************************************
655 template< bool AF // Alignment flag
656  , typename MT // Type of the matrix
657  , bool SO > // Storage order
658 inline typename EnableIf< IsMatConjExpr<MT>, typename SubmatrixExprTrait<MT,AF>::Type >::Type
659  submatrix( const Matrix<MT,SO>& matrix, size_t row, size_t column, size_t m, size_t n )
660 {
662 
663  return conj( submatrix<AF>( (~matrix).operand(), row, column, m, n ) );
664 }
666 //*************************************************************************************************
667 
668 
669 //*************************************************************************************************
684 template< bool AF // Alignment flag
685  , typename MT // Type of the matrix
686  , bool SO > // Storage order
687 inline typename EnableIf< IsMatRealExpr<MT>, typename SubmatrixExprTrait<MT,AF>::Type >::Type
688  submatrix( const Matrix<MT,SO>& matrix, size_t row, size_t column, size_t m, size_t n )
689 {
691 
692  return real( submatrix<AF>( (~matrix).operand(), row, column, m, n ) );
693 }
695 //*************************************************************************************************
696 
697 
698 //*************************************************************************************************
713 template< bool AF // Alignment flag
714  , typename MT // Type of the matrix
715  , bool SO > // Storage order
716 inline typename EnableIf< IsMatImagExpr<MT>, typename SubmatrixExprTrait<MT,AF>::Type >::Type
717  submatrix( const Matrix<MT,SO>& matrix, size_t row, size_t column, size_t m, size_t n )
718 {
720 
721  return imag( submatrix<AF>( (~matrix).operand(), row, column, m, n ) );
722 }
724 //*************************************************************************************************
725 
726 
727 //*************************************************************************************************
742 template< bool AF // Alignment flag
743  , typename MT // Type of the matrix
744  , bool SO > // Storage order
745 inline typename EnableIf< IsMatEvalExpr<MT>, typename SubmatrixExprTrait<MT,AF>::Type >::Type
746  submatrix( const Matrix<MT,SO>& matrix, size_t row, size_t column, size_t m, size_t n )
747 {
749 
750  return eval( submatrix<AF>( (~matrix).operand(), row, column, m, n ) );
751 }
753 //*************************************************************************************************
754 
755 
756 //*************************************************************************************************
771 template< bool AF // Alignment flag
772  , typename MT // Type of the matrix
773  , bool SO > // Storage order
774 inline typename EnableIf< IsMatSerialExpr<MT>, typename SubmatrixExprTrait<MT,AF>::Type >::Type
775  submatrix( const Matrix<MT,SO>& matrix, size_t row, size_t column, size_t m, size_t n )
776 {
778 
779  return serial( submatrix<AF>( (~matrix).operand(), row, column, m, n ) );
780 }
782 //*************************************************************************************************
783 
784 
785 //*************************************************************************************************
800 template< bool AF // Alignment flag
801  , typename MT // Type of the matrix
802  , bool SO > // Storage order
803 inline typename EnableIf< IsMatTransExpr<MT>, typename SubmatrixExprTrait<MT,AF>::Type >::Type
804  submatrix( const Matrix<MT,SO>& matrix, size_t row, size_t column, size_t m, size_t n )
805 {
807 
808  return trans( submatrix<AF>( (~matrix).operand(), column, row, n, m ) );
809 }
811 //*************************************************************************************************
812 
813 } // namespace blaze
814 
815 #endif
const MT::ElementType max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:1729
Header file for mathematical functions.
Header file for the alignment flag values.
Header file for basic type definitions.
BLAZE_ALWAYS_INLINE MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:250
DisableIf< Or< IsComputation< MT >, IsTransExpr< MT > >, typename ColumnExprTrait< MT >::Type >::Type column(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific column of the given matrix.
Definition: Column.h:107
const DMatAbsExpr< MT, SO > abs(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the absolute values of each single element of dm.
Definition: DMatAbsExpr.h:938
Header file for the IsTransExpr type trait class.
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:721
Header file for the IsMatMatAddExpr type trait class.
const ImagExprTrait< MT >::Type imag(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the imaginary part of each single element of dm.
Definition: DMatImagExpr.h:920
Header file for the IsMatTransExpr type trait 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 all restructuring subvector functions.
Header file for the IsMatAbsExpr type trait class.
Header file for the DisableIf class template.
Header file for the IsStrictlyUpper type trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for the IsVecTVecMultExpr type trait class.
Header file for the Or class template.
Header file for the IsMatMatMultExpr type trait class.
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 IsMatSerialExpr type trait class.
Header file for the IsMatScalarMultExpr type trait class.
const RealExprTrait< MT >::Type real(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the real part of each single element of dm.
Definition: DMatRealExpr.h:920
Evaluation of the expression type type of a submatrix operation.Via this type trait it is possible to...
Definition: SubmatrixExprTrait.h:78
Header file for the IsLower type trait.
Header file for the IsMatEvalExpr type trait class.
BLAZE_ALWAYS_INLINE MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:187
Header file for the EnableIf class template.
Header file for the IsStrictlyLower type trait.
Header file for the serial shim.
DisableIf< Or< IsComputation< MT >, IsTransExpr< MT > >, typename RowExprTrait< MT >::Type >::Type row(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific row of the given matrix.
Definition: Row.h:107
Header file for the Matrix base class.
Header file for the SubmatrixExprTrait class template.
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2587
Header file for the IsMatScalarDivExpr type trait class.
Base class for matrices.The Matrix class is a base class for all dense and sparse matrix classes with...
Definition: Forward.h:94
const DMatEvalExpr< MT, SO > eval(const DenseMatrix< MT, SO > &dm)
Forces the evaluation of the given dense matrix expression dm.
Definition: DMatEvalExpr.h:703
Header file for the IsMatMatSubExpr type trait class.
Header file for the RemoveReference type trait.
SubmatrixExprTrait< MT, unaligned >::Type submatrix(Matrix< MT, SO > &matrix, size_t row, size_t column, size_t m, size_t n)
Creating a view on a specific submatrix of the given matrix.
Definition: Submatrix.h:146
Header file for the IsMatRealExpr type trait class.
const DMatTransExpr< MT,!SO > trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:944
Header file for the IsComputation type trait class.
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:157
Header file for the IsMatConjExpr type trait class.
Header file for the IsMatImagExpr type trait class.
Header file for the IsUpper type trait.
Header file for the FunctionTrace class.