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 
44 #include <blaze/math/Functions.h>
65 #include <blaze/util/DisableIf.h>
66 #include <blaze/util/EnableIf.h>
68 #include <blaze/util/mpl/Or.h>
69 #include <blaze/util/Types.h>
71 
72 
73 namespace blaze {
74 
75 //=================================================================================================
76 //
77 // GLOBAL FUNCTION
78 //
79 //=================================================================================================
80 
81 //*************************************************************************************************
140 template< typename MT // Type of the dense matrix
141  , bool SO > // Storage order
142 inline typename SubmatrixExprTrait<MT,unaligned>::Type
143  submatrix( Matrix<MT,SO>& matrix, size_t row, size_t column, size_t m, size_t n )
144 {
146 
147  return submatrix<unaligned>( ~matrix, row, column, m, n );
148 }
149 //*************************************************************************************************
150 
151 
152 //*************************************************************************************************
211 template< typename MT // Type of the dense matrix
212  , bool SO > // Storage order
213 inline typename SubmatrixExprTrait<const MT,unaligned>::Type
214  submatrix( const Matrix<MT,SO>& matrix, size_t row, size_t column, size_t m, size_t n )
215 {
217 
218  return submatrix<unaligned>( ~matrix, row, column, m, n );
219 }
220 //*************************************************************************************************
221 
222 
223 //*************************************************************************************************
305 template< bool AF // Alignment flag
306  , typename MT // Type of the dense matrix
307  , bool SO > // Storage order
308 inline typename DisableIf< Or< IsComputation<MT>, IsTransExpr<MT> >
309  , typename SubmatrixExprTrait<MT,AF>::Type >::Type
310  submatrix( Matrix<MT,SO>& matrix, size_t row, size_t column, size_t m, size_t n )
311 {
313 
315  return ReturnType( ~matrix, row, column, m, n );
316 }
317 //*************************************************************************************************
318 
319 
320 //*************************************************************************************************
402 template< bool AF // Alignment flag
403  , typename MT // Type of the dense matrix
404  , bool SO > // Storage order
405 inline typename DisableIf< Or< IsComputation<MT>, IsTransExpr<MT> >
406  , typename SubmatrixExprTrait<const MT,AF>::Type >::Type
407  submatrix( const Matrix<MT,SO>& matrix, size_t row, size_t column, size_t m, size_t n )
408 {
410 
412  return ReturnType( ~matrix, row, column, m, n );
413 }
414 //*************************************************************************************************
415 
416 
417 
418 
419 //=================================================================================================
420 //
421 // GLOBAL RESTRUCTURING OPERATORS
422 //
423 //=================================================================================================
424 
425 //*************************************************************************************************
440 template< bool AF // Alignment flag
441  , typename MT // Type of the matrix
442  , bool SO > // Storage order
443 inline typename EnableIf< IsMatMatAddExpr<MT>, typename SubmatrixExprTrait<MT,AF>::Type >::Type
444  submatrix( const Matrix<MT,SO>& matrix, size_t row, size_t column, size_t m, size_t n )
445 {
447 
448  return submatrix<AF>( (~matrix).leftOperand() , row, column, m, n ) +
449  submatrix<AF>( (~matrix).rightOperand(), row, column, m, n );
450 }
452 //*************************************************************************************************
453 
454 
455 //*************************************************************************************************
470 template< bool AF // Alignment flag
471  , typename MT // Type of the matrix
472  , bool SO > // Storage order
473 inline typename EnableIf< IsMatMatSubExpr<MT>, typename SubmatrixExprTrait<MT,AF>::Type >::Type
474  submatrix( const Matrix<MT,SO>& matrix, size_t row, size_t column, size_t m, size_t n )
475 {
477 
478  return submatrix<AF>( (~matrix).leftOperand() , row, column, m, n ) -
479  submatrix<AF>( (~matrix).rightOperand(), row, column, m, n );
480 }
482 //*************************************************************************************************
483 
484 
485 //*************************************************************************************************
500 template< bool AF // Alignment flag
501  , typename MT // Type of the matrix
502  , bool SO > // Storage order
503 inline typename EnableIf< IsMatMatMultExpr<MT>, typename SubmatrixExprTrait<MT,AF>::Type >::Type
504  submatrix( const Matrix<MT,SO>& matrix, size_t row, size_t column, size_t m, size_t n )
505 {
507 
508  typedef typename RemoveReference< typename MT::LeftOperand >::Type MT1;
509  typedef typename RemoveReference< typename MT::RightOperand >::Type MT2;
510 
511  typename MT::LeftOperand left ( (~matrix).leftOperand() );
512  typename MT::RightOperand right( (~matrix).rightOperand() );
513 
514  const size_t begin( max( ( IsUpper<MT1>::value )
515  ?( IsStrictlyUpper<MT1>::value ? row + 1UL : row )
516  :( 0UL )
517  , ( IsLower<MT2>::value )
518  ?( IsStrictlyLower<MT2>::value ? column + 1UL : column )
519  :( 0UL ) ) );
520  const size_t end( min( ( IsLower<MT1>::value )
521  ?( IsStrictlyLower<MT1>::value && m > 0UL ? row + m - 1UL : row + m )
522  :( left.columns() )
523  , ( IsUpper<MT2>::value )
524  ?( IsStrictlyUpper<MT2>::value && n > 0UL ? column + n - 1UL : column + n )
525  :( left.columns() ) ) );
526 
527  const size_t diff( ( begin < end )?( end - begin ):( 0UL ) );
528 
529  return submatrix<AF>( left, row, begin, m, diff ) *
530  submatrix<AF>( right, begin, column, diff, n );
531 }
533 //*************************************************************************************************
534 
535 
536 //*************************************************************************************************
551 template< bool AF // Alignment flag
552  , typename MT // Type of the matrix
553  , bool SO > // Storage order
554 inline typename EnableIf< IsVecTVecMultExpr<MT>, typename SubmatrixExprTrait<MT,AF>::Type >::Type
555  submatrix( const Matrix<MT,SO>& matrix, size_t row, size_t column, size_t m, size_t n )
556 {
558 
559  return subvector<AF>( (~matrix).leftOperand(), row, m ) *
560  subvector<AF>( (~matrix).rightOperand(), column, n );
561 }
563 //*************************************************************************************************
564 
565 
566 //*************************************************************************************************
581 template< bool AF // Alignment flag
582  , typename MT // Type of the matrix
583  , bool SO > // Storage order
584 inline typename EnableIf< IsMatScalarMultExpr<MT>, typename SubmatrixExprTrait<MT,AF>::Type >::Type
585  submatrix( const Matrix<MT,SO>& matrix, size_t row, size_t column, size_t m, size_t n )
586 {
588 
589  return submatrix<AF>( (~matrix).leftOperand(), row, column, m, n ) * (~matrix).rightOperand();
590 }
592 //*************************************************************************************************
593 
594 
595 //*************************************************************************************************
610 template< bool AF // Alignment flag
611  , typename MT // Type of the matrix
612  , bool SO > // Storage order
613 inline typename EnableIf< IsMatScalarDivExpr<MT>, typename SubmatrixExprTrait<MT,AF>::Type >::Type
614  submatrix( const Matrix<MT,SO>& matrix, size_t row, size_t column, size_t m, size_t n )
615 {
617 
618  return submatrix<AF>( (~matrix).leftOperand(), row, column, m, n ) / (~matrix).rightOperand();
619 }
621 //*************************************************************************************************
622 
623 
624 //*************************************************************************************************
639 template< bool AF // Alignment flag
640  , typename MT // Type of the matrix
641  , bool SO > // Storage order
642 inline typename EnableIf< IsMatAbsExpr<MT>, typename SubmatrixExprTrait<MT,AF>::Type >::Type
643  submatrix( const Matrix<MT,SO>& matrix, size_t row, size_t column, size_t m, size_t n )
644 {
646 
647  return abs( submatrix<AF>( (~matrix).operand(), row, column, m, n ) );
648 }
650 //*************************************************************************************************
651 
652 
653 //*************************************************************************************************
668 template< bool AF // Alignment flag
669  , typename MT // Type of the matrix
670  , bool SO > // Storage order
671 inline typename EnableIf< IsMatEvalExpr<MT>, typename SubmatrixExprTrait<MT,AF>::Type >::Type
672  submatrix( const Matrix<MT,SO>& matrix, size_t row, size_t column, size_t m, size_t n )
673 {
675 
676  return eval( submatrix<AF>( (~matrix).operand(), row, column, m, n ) );
677 }
679 //*************************************************************************************************
680 
681 
682 //*************************************************************************************************
697 template< bool AF // Alignment flag
698  , typename MT // Type of the matrix
699  , bool SO > // Storage order
700 inline typename EnableIf< IsMatSerialExpr<MT>, typename SubmatrixExprTrait<MT,AF>::Type >::Type
701  submatrix( const Matrix<MT,SO>& matrix, size_t row, size_t column, size_t m, size_t n )
702 {
704 
705  return serial( submatrix<AF>( (~matrix).operand(), row, column, m, n ) );
706 }
708 //*************************************************************************************************
709 
710 
711 //*************************************************************************************************
726 template< bool AF // Alignment flag
727  , typename MT // Type of the matrix
728  , bool SO > // Storage order
729 inline typename EnableIf< IsMatTransExpr<MT>, typename SubmatrixExprTrait<MT,AF>::Type >::Type
730  submatrix( const Matrix<MT,SO>& matrix, size_t row, size_t column, size_t m, size_t n )
731 {
733 
734  return trans( submatrix<AF>( (~matrix).operand(), column, row, n, m ) );
735 }
737 //*************************************************************************************************
738 
739 } // namespace blaze
740 
741 #endif
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.
Header file for the subvector/submatrix 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:258
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:103
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:914
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:699
Header file for the IsMatMatAddExpr type trait class.
Header file for the IsMatTransExpr type trait class.
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:1602
Header file for the IsMatSerialExpr type trait class.
Header file for the IsMatScalarMultExpr type trait class.
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:195
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:103
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:2506
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:87
const DMatEvalExpr< MT, SO > eval(const DenseMatrix< MT, SO > &dm)
Forces the evaluation of the given dense matrix expression dm.
Definition: DMatEvalExpr.h:681
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:143
const DMatTransExpr< MT,!SO > trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:937
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 IsUpper type trait.
Header file for the FunctionTrace class.