Subvector.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_VIEWS_SUBVECTOR_H_
36 #define _BLAZE_MATH_VIEWS_SUBVECTOR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
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 //*************************************************************************************************
140 template< typename VT // Type of the vector
141  , bool TF > // Transpose flag
142 inline typename SubvectorExprTrait<VT,unaligned>::Type
143  subvector( Vector<VT,TF>& vector, size_t index, size_t size )
144 {
146 
147  return subvector<unaligned>( ~vector, index, size );
148 }
149 //*************************************************************************************************
150 
151 
152 //*************************************************************************************************
208 template< typename VT // Type of the vector
209  , bool TF > // Transpose flag
210 inline typename SubvectorExprTrait<const VT,unaligned>::Type
211  subvector( const Vector<VT,TF>& vector, size_t index, size_t size )
212 {
214 
215  return subvector<unaligned>( ~vector, index, size );
216 }
217 //*************************************************************************************************
218 
219 
220 //*************************************************************************************************
291 template< bool AF // Alignment flag
292  , typename VT // Type of the dense vector
293  , bool TF > // Transpose flag
294 inline typename DisableIf< Or< IsComputation<VT>, IsTransExpr<VT> >
295  , typename SubvectorExprTrait<VT,AF>::Type >::Type
296  subvector( Vector<VT,TF>& vector, size_t index, size_t size )
297 {
299 
301  return ReturnType( ~vector, index, size );
302 }
303 //*************************************************************************************************
304 
305 
306 //*************************************************************************************************
377 template< bool AF // Alignment flag
378  , typename VT // Type of the dense vector
379  , bool TF > // Transpose flag
380 inline typename DisableIf< Or< IsComputation<VT>, IsTransExpr<VT> >
381  , typename SubvectorExprTrait<const VT,AF>::Type >::Type
382  subvector( const Vector<VT,TF>& vector, size_t index, size_t size )
383 {
385 
387  return ReturnType( ~vector, index, size );
388 }
389 //*************************************************************************************************
390 
391 
392 
393 
394 //=================================================================================================
395 //
396 // GLOBAL RESTRUCTURING OPERATORS
397 //
398 //=================================================================================================
399 
400 //*************************************************************************************************
413 template< bool AF // Alignment flag
414  , typename VT // Type of the vector
415  , bool TF > // Transpose flag
416 inline typename EnableIf< IsVecVecAddExpr<VT>, typename SubvectorExprTrait<VT,AF>::Type >::Type
417  subvector( const Vector<VT,TF>& vector, size_t index, size_t size )
418 {
420 
421  return subvector<AF>( (~vector).leftOperand() , index, size ) +
422  subvector<AF>( (~vector).rightOperand(), index, size );
423 }
425 //*************************************************************************************************
426 
427 
428 //*************************************************************************************************
441 template< bool AF // Alignment flag
442  , typename VT // Type of the vector
443  , bool TF > // Transpose flag
444 inline typename EnableIf< IsVecVecSubExpr<VT>, typename SubvectorExprTrait<VT,AF>::Type >::Type
445  subvector( const Vector<VT,TF>& vector, size_t index, size_t size )
446 {
448 
449  return subvector<AF>( (~vector).leftOperand() , index, size ) -
450  subvector<AF>( (~vector).rightOperand(), index, size );
451 }
453 //*************************************************************************************************
454 
455 
456 //*************************************************************************************************
469 template< bool AF // Alignment flag
470  , typename VT // Type of the vector
471  , bool TF > // Transpose flag
472 inline typename EnableIf< IsVecVecMultExpr<VT>, typename SubvectorExprTrait<VT,AF>::Type >::Type
473  subvector( const Vector<VT,TF>& vector, size_t index, size_t size )
474 {
476 
477  return subvector<AF>( (~vector).leftOperand() , index, size ) *
478  subvector<AF>( (~vector).rightOperand(), index, size );
479 }
481 //*************************************************************************************************
482 
483 
484 //*************************************************************************************************
497 template< bool AF // Alignment flag
498  , typename VT // Type of the vector
499  , bool TF > // Transpose flag
500 inline typename EnableIf< IsCrossExpr<VT>, typename SubvectorExprTrait<VT,unaligned>::Type >::Type
501  subvector( const Vector<VT,TF>& vector, size_t index, size_t size )
502 {
504 
505  typedef typename SubvectorExprTrait<VT,unaligned>::Type ReturnType;
506  return ReturnType( ~vector, index, size );
507 }
509 //*************************************************************************************************
510 
511 
512 //*************************************************************************************************
525 template< bool AF // Alignment flag
526  , typename VT // Type of the vector
527  , bool TF > // Transpose flag
528 inline typename EnableIf< IsMatVecMultExpr<VT>, typename SubvectorExprTrait<VT,AF>::Type >::Type
529  subvector( const Vector<VT,TF>& vector, size_t index, size_t size )
530 {
532 
533  typedef typename RemoveReference< typename VT::LeftOperand >::Type MT;
534 
535  typename VT::LeftOperand left ( (~vector).leftOperand() );
536  typename VT::RightOperand right( (~vector).rightOperand() );
537 
538  const size_t column( ( IsUpper<MT>::value )
539  ?( ( !AF && IsStrictlyUpper<MT>::value )?( index + 1UL ):( index ) )
540  :( 0UL ) );
541  const size_t n( ( IsLower<MT>::value )
542  ?( ( IsUpper<MT>::value )?( size )
543  :( ( IsStrictlyLower<MT>::value && size > 0UL )
544  ?( index + size - 1UL )
545  :( index + size ) ) )
546  :( ( IsUpper<MT>::value )?( left.columns() - column )
547  :( left.columns() ) ) );
548 
549  return submatrix<AF>( left, index, column, size, n ) * subvector<AF>( right, column, n );
550 }
552 //*************************************************************************************************
553 
554 
555 //*************************************************************************************************
568 template< bool AF // Alignment flag
569  , typename VT // Type of the vector
570  , bool TF > // Transpose flag
571 inline typename EnableIf< IsTVecMatMultExpr<VT>, typename SubvectorExprTrait<VT,AF>::Type >::Type
572  subvector( const Vector<VT,TF>& vector, size_t index, size_t size )
573 {
575 
576  typedef typename RemoveReference< typename VT::RightOperand>::Type MT;
577 
578  typename VT::LeftOperand left ( (~vector).leftOperand() );
579  typename VT::RightOperand right( (~vector).rightOperand() );
580 
581  const size_t row( ( IsLower<MT>::value )
582  ?( ( !AF && IsStrictlyLower<MT>::value )?( index + 1UL ):( index ) )
583  :( 0UL ) );
584  const size_t m( ( IsUpper<MT>::value )
585  ?( ( IsLower<MT>::value )?( size )
586  :( ( IsStrictlyUpper<MT>::value && size > 0UL )
587  ?( index + size - 1UL )
588  :( index + size ) ) )
589  :( ( IsLower<MT>::value )?( right.rows() - row )
590  :( right.rows() ) ) );
591 
592  return subvector<AF>( left, row, m ) * submatrix<AF>( right, row, index, m, size );
593 }
595 //*************************************************************************************************
596 
597 
598 //*************************************************************************************************
611 template< bool AF // Alignment flag
612  , typename VT // Type of the vector
613  , bool TF > // Transpose flag
614 inline typename EnableIf< IsVecScalarMultExpr<VT>, typename SubvectorExprTrait<VT,AF>::Type >::Type
615  subvector( const Vector<VT,TF>& vector, size_t index, size_t size )
616 {
618 
619  return subvector<AF>( (~vector).leftOperand(), index, size ) * (~vector).rightOperand();
620 }
622 //*************************************************************************************************
623 
624 
625 //*************************************************************************************************
638 template< bool AF // Alignment flag
639  , typename VT // Type of the vector
640  , bool TF > // Transpose flag
641 inline typename EnableIf< IsVecScalarDivExpr<VT>, typename SubvectorExprTrait<VT,AF>::Type >::Type
642  subvector( const Vector<VT,TF>& vector, size_t index, size_t size )
643 {
645 
646  return subvector<AF>( (~vector).leftOperand(), index, size ) / (~vector).rightOperand();
647 }
649 //*************************************************************************************************
650 
651 
652 //*************************************************************************************************
665 template< bool AF // Alignment flag
666  , typename VT // Type of the vector
667  , bool TF > // Transpose flag
668 inline typename EnableIf< IsVecAbsExpr<VT>, typename SubvectorExprTrait<VT,AF>::Type >::Type
669  subvector( const Vector<VT,TF>& vector, size_t index, size_t size )
670 {
672 
673  return abs( subvector<AF>( (~vector).operand(), index, size ) );
674 }
676 //*************************************************************************************************
677 
678 
679 //*************************************************************************************************
692 template< bool AF // Alignment flag
693  , typename VT // Type of the vector
694  , bool TF > // Transpose flag
695 inline typename EnableIf< IsVecConjExpr<VT>, typename SubvectorExprTrait<VT,AF>::Type >::Type
696  subvector( const Vector<VT,TF>& vector, size_t index, size_t size )
697 {
699 
700  return conj( subvector<AF>( (~vector).operand(), index, size ) );
701 }
703 //*************************************************************************************************
704 
705 
706 //*************************************************************************************************
719 template< bool AF // Alignment flag
720  , typename VT // Type of the vector
721  , bool TF > // Transpose flag
722 inline typename EnableIf< IsVecRealExpr<VT>, typename SubvectorExprTrait<VT,AF>::Type >::Type
723  subvector( const Vector<VT,TF>& vector, size_t index, size_t size )
724 {
726 
727  return real( subvector<AF>( (~vector).operand(), index, size ) );
728 }
730 //*************************************************************************************************
731 
732 
733 //*************************************************************************************************
746 template< bool AF // Alignment flag
747  , typename VT // Type of the vector
748  , bool TF > // Transpose flag
749 inline typename EnableIf< IsVecImagExpr<VT>, typename SubvectorExprTrait<VT,AF>::Type >::Type
750  subvector( const Vector<VT,TF>& vector, size_t index, size_t size )
751 {
753 
754  return imag( subvector<AF>( (~vector).operand(), index, size ) );
755 }
757 //*************************************************************************************************
758 
759 
760 //*************************************************************************************************
773 template< bool AF // Alignment flag
774  , typename VT // Type of the vector
775  , bool TF > // Transpose flag
776 inline typename EnableIf< IsVecEvalExpr<VT>, typename SubvectorExprTrait<VT,AF>::Type >::Type
777  subvector( const Vector<VT,TF>& vector, size_t index, size_t size )
778 {
780 
781  return eval( subvector<AF>( (~vector).operand(), index, size ) );
782 }
784 //*************************************************************************************************
785 
786 
787 //*************************************************************************************************
800 template< bool AF // Alignment flag
801  , typename VT // Type of the vector
802  , bool TF > // Transpose flag
803 inline typename EnableIf< IsVecSerialExpr<VT>, typename SubvectorExprTrait<VT,AF>::Type >::Type
804  subvector( const Vector<VT,TF>& vector, size_t index, size_t size )
805 {
807 
808  return serial( subvector<AF>( (~vector).operand(), index, size ) );
809 }
811 //*************************************************************************************************
812 
813 
814 //*************************************************************************************************
827 template< bool AF // Alignment flag
828  , typename VT // Type of the vector
829  , bool TF > // Transpose flag
830 inline typename EnableIf< IsVecTransExpr<VT>, typename SubvectorExprTrait<VT,AF>::Type >::Type
831  subvector( const Vector<VT,TF>& vector, size_t index, size_t size )
832 {
834 
835  return trans( subvector<AF>( (~vector).operand(), index, size ) );
836 }
838 //*************************************************************************************************
839 
840 } // namespace blaze
841 
842 #endif
Evaluation of the expression type type of a subvector operation.Via this type trait it is possible to...
Definition: SubvectorExprTrait.h:78
Header file for the alignment flag values.
Header file for the IsVecRealExpr type trait class.
Header file for basic type definitions.
Header file for the IsTVecMatMultExpr type trait class.
Header file for the IsVecVecMultExpr type trait class.
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:252
Header file for the IsCrossExpr type trait class.
Header file for the IsVecVecSubExpr type trait class.
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 IsMatVecMultExpr type trait class.
Header file for the IsVecSerialExpr 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
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 IsVecEvalExpr type trait class.
Header file for the IsVecVecAddExpr type trait class.
Header file for the DisableIf class template.
Header file for the IsVecImagExpr type trait class.
Header file for the IsStrictlyUpper type trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for the Or class template.
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
Header file for the IsVecScalarDivExpr type trait class.
Header file for the IsLower type trait.
Header file for the IsVecAbsExpr type trait class.
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 IsVecTransExpr type trait class.
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2587
Header file for the IsVecConjExpr type trait class.
SubvectorExprTrait< VT, unaligned >::Type subvector(Vector< VT, TF > &vector, size_t index, size_t size)
Creating a view on a specific subvector of the given vector.
Definition: Subvector.h:143
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 RemoveReference type trait.
Header file for the IsVecScalarMultExpr type trait class.
Base class for N-dimensional vectors.The Vector class is a base class for all arbitrarily sized (N-di...
Definition: Forward.h:164
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 SubvectorExprTrait class template.
Header file for the IsUpper type trait.
Header file for the Vector CRTP base class.
Header file for the FunctionTrace class.