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 
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 //*************************************************************************************************
137 template< typename VT // Type of the vector
138  , bool TF > // Transpose flag
139 inline typename SubvectorExprTrait<VT,unaligned>::Type
140  subvector( Vector<VT,TF>& vector, size_t index, size_t size )
141 {
143 
144  return subvector<unaligned>( ~vector, index, size );
145 }
146 //*************************************************************************************************
147 
148 
149 //*************************************************************************************************
205 template< typename VT // Type of the vector
206  , bool TF > // Transpose flag
207 inline typename SubvectorExprTrait<const VT,unaligned>::Type
208  subvector( const Vector<VT,TF>& vector, size_t index, size_t size )
209 {
211 
212  return subvector<unaligned>( ~vector, index, size );
213 }
214 //*************************************************************************************************
215 
216 
217 //*************************************************************************************************
290 template< bool AF // Alignment flag
291  , typename VT // Type of the dense vector
292  , bool TF > // Transpose flag
293 inline typename DisableIf< Or< IsComputation<VT>, IsTransExpr<VT> >
294  , typename SubvectorExprTrait<VT,AF>::Type >::Type
295  subvector( Vector<VT,TF>& vector, size_t index, size_t size )
296 {
298 
300  return ReturnType( ~vector, index, size );
301 }
302 //*************************************************************************************************
303 
304 
305 //*************************************************************************************************
378 template< bool AF // Alignment flag
379  , typename VT // Type of the dense vector
380  , bool TF > // Transpose flag
381 inline typename DisableIf< Or< IsComputation<VT>, IsTransExpr<VT> >
382  , typename SubvectorExprTrait<const VT,AF>::Type >::Type
383  subvector( const Vector<VT,TF>& vector, size_t index, size_t size )
384 {
386 
388  return ReturnType( ~vector, index, size );
389 }
390 //*************************************************************************************************
391 
392 
393 
394 
395 //=================================================================================================
396 //
397 // GLOBAL RESTRUCTURING OPERATORS
398 //
399 //=================================================================================================
400 
401 //*************************************************************************************************
414 template< bool AF // Alignment flag
415  , typename VT // Type of the vector
416  , bool TF > // Transpose flag
417 inline typename EnableIf< IsVecVecAddExpr<VT>, typename SubvectorExprTrait<VT,AF>::Type >::Type
418  subvector( const Vector<VT,TF>& vector, size_t index, size_t size )
419 {
421 
422  return subvector<AF>( (~vector).leftOperand() , index, size ) +
423  subvector<AF>( (~vector).rightOperand(), index, size );
424 }
426 //*************************************************************************************************
427 
428 
429 //*************************************************************************************************
442 template< bool AF // Alignment flag
443  , typename VT // Type of the vector
444  , bool TF > // Transpose flag
445 inline typename EnableIf< IsVecVecSubExpr<VT>, typename SubvectorExprTrait<VT,AF>::Type >::Type
446  subvector( const Vector<VT,TF>& vector, size_t index, size_t size )
447 {
449 
450  return subvector<AF>( (~vector).leftOperand() , index, size ) -
451  subvector<AF>( (~vector).rightOperand(), index, size );
452 }
454 //*************************************************************************************************
455 
456 
457 //*************************************************************************************************
470 template< bool AF // Alignment flag
471  , typename VT // Type of the vector
472  , bool TF > // Transpose flag
473 inline typename EnableIf< IsVecVecMultExpr<VT>, typename SubvectorExprTrait<VT,AF>::Type >::Type
474  subvector( const Vector<VT,TF>& vector, size_t index, size_t size )
475 {
477 
478  return subvector<AF>( (~vector).leftOperand() , index, size ) *
479  subvector<AF>( (~vector).rightOperand(), index, size );
480 }
482 //*************************************************************************************************
483 
484 
485 //*************************************************************************************************
498 template< bool AF // Alignment flag
499  , typename VT // Type of the vector
500  , bool TF > // Transpose flag
501 inline typename EnableIf< IsCrossExpr<VT>, typename SubvectorExprTrait<VT,unaligned>::Type >::Type
502  subvector( const Vector<VT,TF>& vector, size_t index, size_t size )
503 {
505 
506  typedef typename SubvectorExprTrait<VT,unaligned>::Type ReturnType;
507  return ReturnType( ~vector, index, size );
508 }
510 //*************************************************************************************************
511 
512 
513 //*************************************************************************************************
526 template< bool AF // Alignment flag
527  , typename VT // Type of the vector
528  , bool TF > // Transpose flag
529 inline typename EnableIf< IsMatVecMultExpr<VT>, typename SubvectorExprTrait<VT,AF>::Type >::Type
530  subvector( const Vector<VT,TF>& vector, size_t index, size_t size )
531 {
533 
534  typedef typename RemoveReference< typename VT::LeftOperand >::Type MT;
535 
536  typename VT::LeftOperand left ( (~vector).leftOperand() );
537  typename VT::RightOperand right( (~vector).rightOperand() );
538 
539  const size_t column( ( IsUpper<MT>::value )
540  ?( IsStrictlyUpper<MT>::value ? index + 1UL : index )
541  :( 0UL ) );
542  const size_t n( ( IsLower<MT>::value )
543  ?( ( IsUpper<MT>::value )?( size )
544  :( ( IsStrictlyLower<MT>::value && size > 0UL )
545  ?( index + size - 1UL )
546  :( index + size ) ) )
547  :( ( IsUpper<MT>::value )?( left.columns() - column )
548  :( left.columns() ) ) );
549 
550  return submatrix<AF>( left, index, column, size, n ) * subvector<AF>( right, column, n );
551 }
553 //*************************************************************************************************
554 
555 
556 //*************************************************************************************************
569 template< bool AF // Alignment flag
570  , typename VT // Type of the vector
571  , bool TF > // Transpose flag
572 inline typename EnableIf< IsTVecMatMultExpr<VT>, typename SubvectorExprTrait<VT,AF>::Type >::Type
573  subvector( const Vector<VT,TF>& vector, size_t index, size_t size )
574 {
576 
577  typedef typename RemoveReference< typename VT::RightOperand>::Type MT;
578 
579  typename VT::LeftOperand left ( (~vector).leftOperand() );
580  typename VT::RightOperand right( (~vector).rightOperand() );
581 
582  const size_t row( ( IsLower<MT>::value )
583  ?( IsStrictlyLower<MT>::value ? index + 1UL : index )
584  :( 0UL ) );
585  const size_t m( ( IsUpper<MT>::value )
586  ?( ( IsLower<MT>::value )?( size )
587  :( ( IsStrictlyUpper<MT>::value && size > 0UL )
588  ?( index + size - 1UL )
589  :( index + size ) ) )
590  :( ( IsLower<MT>::value )?( right.rows() - row )
591  :( right.rows() ) ) );
592 
593  return subvector<AF>( left, row, m ) * submatrix<AF>( right, row, index, m, size );
594 }
596 //*************************************************************************************************
597 
598 
599 //*************************************************************************************************
612 template< bool AF // Alignment flag
613  , typename VT // Type of the vector
614  , bool TF > // Transpose flag
615 inline typename EnableIf< IsVecScalarMultExpr<VT>, typename SubvectorExprTrait<VT,AF>::Type >::Type
616  subvector( const Vector<VT,TF>& vector, size_t index, size_t size )
617 {
619 
620  return subvector<AF>( (~vector).leftOperand(), index, size ) * (~vector).rightOperand();
621 }
623 //*************************************************************************************************
624 
625 
626 //*************************************************************************************************
639 template< bool AF // Alignment flag
640  , typename VT // Type of the vector
641  , bool TF > // Transpose flag
642 inline typename EnableIf< IsVecScalarDivExpr<VT>, typename SubvectorExprTrait<VT,AF>::Type >::Type
643  subvector( const Vector<VT,TF>& vector, size_t index, size_t size )
644 {
646 
647  return subvector<AF>( (~vector).leftOperand(), index, size ) / (~vector).rightOperand();
648 }
650 //*************************************************************************************************
651 
652 
653 //*************************************************************************************************
666 template< bool AF // Alignment flag
667  , typename VT // Type of the vector
668  , bool TF > // Transpose flag
669 inline typename EnableIf< IsVecAbsExpr<VT>, typename SubvectorExprTrait<VT,AF>::Type >::Type
670  subvector( const Vector<VT,TF>& vector, size_t index, size_t size )
671 {
673 
674  return abs( subvector<AF>( (~vector).operand(), index, size ) );
675 }
677 //*************************************************************************************************
678 
679 
680 //*************************************************************************************************
693 template< bool AF // Alignment flag
694  , typename VT // Type of the vector
695  , bool TF > // Transpose flag
696 inline typename EnableIf< IsVecEvalExpr<VT>, typename SubvectorExprTrait<VT,AF>::Type >::Type
697  subvector( const Vector<VT,TF>& vector, size_t index, size_t size )
698 {
700 
701  return eval( subvector<AF>( (~vector).operand(), index, size ) );
702 }
704 //*************************************************************************************************
705 
706 
707 //*************************************************************************************************
720 template< bool AF // Alignment flag
721  , typename VT // Type of the vector
722  , bool TF > // Transpose flag
723 inline typename EnableIf< IsVecSerialExpr<VT>, typename SubvectorExprTrait<VT,AF>::Type >::Type
724  subvector( const Vector<VT,TF>& vector, size_t index, size_t size )
725 {
727 
728  return serial( subvector<AF>( (~vector).operand(), index, size ) );
729 }
731 //*************************************************************************************************
732 
733 
734 //*************************************************************************************************
747 template< bool AF // Alignment flag
748  , typename VT // Type of the vector
749  , bool TF > // Transpose flag
750 inline typename EnableIf< IsVecTransExpr<VT>, typename SubvectorExprTrait<VT,AF>::Type >::Type
751  subvector( const Vector<VT,TF>& vector, size_t index, size_t size )
752 {
754 
755  return trans( subvector<AF>( (~vector).operand(), index, size ) );
756 }
758 //*************************************************************************************************
759 
760 } // namespace blaze
761 
762 #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 subvector/submatrix alignment flag values.
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:264
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: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 IsMatVecMultExpr type trait class.
Header file for the IsVecSerialExpr type trait class.
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 IsStrictlyUpper type trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for the Or class template.
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:103
Header file for the IsVecTransExpr type trait class.
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2506
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:140
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 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:151
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 SubvectorExprTrait class template.
Header file for the IsUpper type trait.
Header file for the Vector CRTP base class.
Header file for the FunctionTrace class.