35 #ifndef _BLAZE_MATH_VIEWS_SUBVECTOR_H_
36 #define _BLAZE_MATH_VIEWS_SUBVECTOR_H_
149 template<
typename VT
151 inline SubvectorExprTrait_<VT,unaligned>
156 return subvector<unaligned>( ~vector, index,
size );
217 template<
typename VT
219 inline const SubvectorExprTrait_<const VT,unaligned>
224 return subvector<unaligned>( ~vector, index,
size );
244 template<
typename VT
246 inline SubvectorExprTrait_<VT,unaligned>
251 return subvector<unaligned>( ~vector, index,
size );
330 inline DisableIf_< Or< IsComputation<VT>, IsTransExpr<VT> >, SubvectorExprTrait_<VT,AF> >
412 inline const DisableIf_< Or< IsComputation<VT>, IsTransExpr<VT> >, SubvectorExprTrait_<const VT,AF> >
442 inline DisableIf_< Or< IsComputation<VT>, IsTransExpr<VT> >, SubvectorExprTrait_<VT,AF> >
476 inline const EnableIf_< IsVecVecAddExpr<VT>, SubvectorExprTrait_<VT,AF> >
477 subvector(
const Vector<VT,TF>& vector,
size_t index,
size_t size )
481 return subvector<AF>( (~vector).leftOperand() , index,
size ) +
482 subvector<AF>( (~vector).rightOperand(), index,
size );
504 inline const EnableIf_< IsVecVecSubExpr<VT>, SubvectorExprTrait_<VT,AF> >
505 subvector(
const Vector<VT,TF>& vector,
size_t index,
size_t size )
509 return subvector<AF>( (~vector).leftOperand() , index,
size ) -
510 subvector<AF>( (~vector).rightOperand(), index,
size );
532 inline const EnableIf_< IsVecVecMultExpr<VT>, SubvectorExprTrait_<VT,AF> >
533 subvector(
const Vector<VT,TF>& vector,
size_t index,
size_t size )
537 return subvector<AF>( (~vector).leftOperand() , index,
size ) *
538 subvector<AF>( (~vector).rightOperand(), index,
size );
560 inline const EnableIf_< IsVecVecDivExpr<VT>, SubvectorExprTrait_<VT,AF> >
561 subvector(
const Vector<VT,TF>& vector,
size_t index,
size_t size )
565 return subvector<AF>( (~vector).leftOperand() , index,
size ) /
566 subvector<AF>( (~vector).rightOperand(), index,
size );
588 inline const EnableIf_< IsCrossExpr<VT>, SubvectorExprTrait_<VT,unaligned> >
589 subvector(
const Vector<VT,TF>& vector,
size_t index,
size_t size )
593 return SubvectorExprTrait_<VT,unaligned>( ~vector, index,
size );
615 inline const EnableIf_< IsVecScalarMultExpr<VT>, SubvectorExprTrait_<VT,AF> >
616 subvector(
const Vector<VT,TF>& vector,
size_t index,
size_t size )
620 return subvector<AF>( (~vector).leftOperand(), index,
size ) * (~vector).rightOperand();
642 inline const EnableIf_< IsVecScalarDivExpr<VT>, SubvectorExprTrait_<VT,AF> >
643 subvector(
const Vector<VT,TF>& vector,
size_t index,
size_t size )
647 return subvector<AF>( (~vector).leftOperand(), index,
size ) / (~vector).rightOperand();
669 inline const EnableIf_< IsVecForEachExpr<VT>, SubvectorExprTrait_<VT,AF> >
670 subvector(
const Vector<VT,TF>& vector,
size_t index,
size_t size )
674 return forEach( subvector<AF>( (~vector).operand(), index, size ), (~vector).operation() );
696 inline const EnableIf_< IsVecEvalExpr<VT>, SubvectorExprTrait_<VT,AF> >
697 subvector(
const Vector<VT,TF>& vector,
size_t index,
size_t size )
701 return eval( subvector<AF>( (~vector).operand(), index, size ) );
723 inline const EnableIf_< IsVecSerialExpr<VT>, SubvectorExprTrait_<VT,AF> >
724 subvector(
const Vector<VT,TF>& vector,
size_t index,
size_t size )
728 return serial( subvector<AF>( (~vector).operand(), index, size ) );
750 inline const EnableIf_< IsVecTransExpr<VT>, SubvectorExprTrait_<VT,AF> >
751 subvector(
const Vector<VT,TF>& vector,
size_t index,
size_t size )
755 return trans( subvector<AF>( (~vector).operand(), index, size ) );
778 inline const Subvector<VT,AF1,TF,DF>
779 subvector(
const Subvector<VT,AF2,TF,DF>& sv,
size_t index,
size_t size )
783 if( index + size > sv.size() ) {
787 return Subvector<VT,AF1,TF,DF>( sv.vector_, sv.offset_ + index,
size );
804 template<
typename VT,
bool AF,
bool TF,
bool DF >
805 inline void reset( Subvector<VT,AF,TF,DF>& sv );
807 template<
typename VT,
bool AF,
bool TF,
bool DF >
808 inline void clear( Subvector<VT,AF,TF,DF>& sv );
810 template<
typename VT,
bool AF,
bool TF,
bool DF >
811 inline bool isDefault(
const Subvector<VT,AF,TF,DF>& sv );
813 template<
typename VT,
bool AF,
bool TF,
bool DF >
814 inline bool isIntact(
const Subvector<VT,AF,TF,DF>& sv ) noexcept;
816 template<
typename VT,
bool AF,
bool TF,
bool DF >
817 inline bool isSame(
const Subvector<VT,AF,TF,DF>& a,
const Vector<VT,TF>& b ) noexcept;
819 template<
typename VT,
bool AF,
bool TF,
bool DF >
820 inline bool isSame(
const Vector<VT,TF>& a,
const Subvector<VT,AF,TF,DF>& b ) noexcept;
822 template<
typename VT,
bool AF,
bool TF,
bool DF >
823 inline bool isSame(
const Subvector<VT,AF,TF,DF>& a,
const Subvector<VT,AF,TF,DF>& b ) noexcept;
835 template<
typename VT
853 template<
typename VT
883 template<
typename VT
889 for(
size_t i=0UL; i<sv.size(); ++i )
915 template<
typename VT
918 inline bool isDefault(
const Subvector<VT,AF,TF,false>& sv )
920 typedef ConstIterator_< Subvector<VT,AF,TF,false> >
ConstIterator;
922 const ConstIterator
end( sv.end() );
923 for( ConstIterator element=sv.begin(); element!=
end; ++element )
924 if( !
isDefault( element->value() ) )
return false;
948 template<
typename VT
954 return ( sv.offset_ + sv.size_ <= sv.vector_.size() &&
972 template<
typename VT
978 return (
isSame( a.vector_, ~b ) && ( a.size() == (~b).
size() ) );
995 template<
typename VT
1001 return (
isSame( ~a, b.vector_ ) && ( (~a).size() == b.size() ) );
1018 template<
typename VT
1024 return (
isSame( a.vector_, b.vector_ ) && ( a.offset_ == b.offset_ ) && ( a.size_ == b.size_ ) );
1044 template<
typename VT1
1049 inline bool tryAssign(
const Subvector<VT1,AF,TF,DF>& lhs,
const Vector<VT2,TF>& rhs,
size_t index )
1054 return tryAssign( lhs.vector_, ~rhs, lhs.offset_ + index );
1075 template<
typename VT1
1080 inline bool tryAddAssign(
const Subvector<VT1,AF,TF,DF>& lhs,
const Vector<VT2,TF>& rhs,
size_t index )
1085 return tryAddAssign( lhs.vector_, ~rhs, lhs.offset_ + index );
1106 template<
typename VT1
1111 inline bool trySubAssign(
const Subvector<VT1,AF,TF,DF>& lhs,
const Vector<VT2,TF>& rhs,
size_t index )
1116 return trySubAssign( lhs.vector_, ~rhs, lhs.offset_ + index );
1137 template<
typename VT1
1142 inline bool tryMultAssign(
const Subvector<VT1,AF,TF,DF>& lhs,
const Vector<VT2,TF>& rhs,
size_t index )
1147 return tryMultAssign( lhs.vector_, ~rhs, lhs.offset_ + index );
1168 template<
typename VT1
1173 inline bool tryDivAssign(
const Subvector<VT1,AF,TF,DF>& lhs,
const Vector<VT2,TF>& rhs,
size_t index )
1178 return tryDivAssign( lhs.vector_, ~rhs, lhs.offset_ + index );
1199 template<
typename VT
1203 inline DerestrictTrait_< Subvector<VT,AF,TF,DF> > derestrict( Subvector<VT,AF,TF,DF>& sv )
1205 typedef DerestrictTrait_< Subvector<VT,AF,TF,DF> >
ReturnType;
1206 return ReturnType( derestrict( sv.vector_ ), sv.offset_, sv.size_ );
1222 template<
typename VT,
bool AF,
bool TF,
bool DF >
1223 struct IsRestricted< Subvector<VT,AF,TF,DF> >
1240 template<
typename VT,
bool AF,
bool TF,
bool DF >
1241 struct DerestrictTrait< Subvector<VT,AF,TF,DF> >
1243 using Type = Subvector< RemoveReference_< DerestrictTrait_<VT> >, AF, TF, DF >;
1259 template<
typename VT,
bool AF,
bool TF >
1260 struct HasConstDataAccess< Subvector<VT,AF,TF,true> >
1277 template<
typename VT,
bool AF,
bool TF >
1278 struct HasMutableDataAccess< Subvector<VT,AF,TF,true> >
1279 :
public BoolConstant< HasMutableDataAccess<VT>::value >
1295 template<
typename VT,
bool TF >
1312 template<
typename VT,
bool AF,
bool TF,
bool DF,
typename T >
1313 struct AddTrait< Subvector<VT,AF,TF,DF>, T >
1315 using Type = AddTrait_< SubvectorTrait_<VT>, T >;
1318 template<
typename T,
typename VT,
bool AF,
bool TF,
bool DF >
1319 struct AddTrait< T, Subvector<VT,AF,TF,DF> >
1321 using Type = AddTrait_< T, SubvectorTrait_<VT> >;
1337 template<
typename VT,
bool AF,
bool TF,
bool DF,
typename T >
1338 struct SubTrait< Subvector<VT,AF,TF,DF>, T >
1340 using Type = SubTrait_< SubvectorTrait_<VT>, T >;
1343 template<
typename T,
typename VT,
bool AF,
bool TF,
bool DF >
1344 struct SubTrait< T, Subvector<VT,AF,TF,DF> >
1346 using Type = SubTrait_< T, SubvectorTrait_<VT> >;
1362 template<
typename VT,
bool AF,
bool TF,
bool DF,
typename T >
1363 struct MultTrait< Subvector<VT,AF,TF,DF>, T >
1365 using Type = MultTrait_< SubvectorTrait_<VT>, T >;
1368 template<
typename T,
typename VT,
bool AF,
bool TF,
bool DF >
1369 struct MultTrait< T, Subvector<VT,AF,TF,DF> >
1371 using Type = MultTrait_< T, SubvectorTrait_<VT> >;
1387 template<
typename VT,
bool AF,
bool TF,
bool DF,
typename T >
1388 struct CrossTrait< Subvector<VT,AF,TF,DF>, T >
1390 using Type = CrossTrait_< SubvectorTrait_<VT>, T >;
1393 template<
typename T,
typename VT,
bool AF,
bool TF,
bool DF >
1394 struct CrossTrait< T, Subvector<VT,AF,TF,DF> >
1396 using Type = CrossTrait_< T, SubvectorTrait_<VT> >;
1412 template<
typename VT,
bool AF,
bool TF,
bool DF,
typename T >
1413 struct DivTrait< Subvector<VT,AF,TF,DF>, T >
1415 using Type = DivTrait_< SubvectorTrait_<VT>, T >;
1418 template<
typename T,
typename VT,
bool AF,
bool TF,
bool DF >
1419 struct DivTrait< T, Subvector<VT,AF,TF,DF> >
1421 using Type = DivTrait_< T, SubvectorTrait_<VT> >;
1437 template<
typename VT,
bool AF,
bool TF,
bool DF >
1438 struct SubvectorTrait< Subvector<VT,AF,TF,DF> >
1440 using Type = SubvectorTrait_< ResultType_< Subvector<VT,AF,TF,DF> > >;
1456 template<
typename VT,
bool AF1,
bool TF,
bool DF,
bool AF2 >
1457 struct SubvectorExprTrait< Subvector<VT,AF1,TF,DF>, AF2 >
1459 using Type = Subvector<VT,AF2,TF,DF>;
1467 template<
typename VT,
bool AF1,
bool TF,
bool DF,
bool AF2 >
1468 struct SubvectorExprTrait< const Subvector<VT,AF1,TF,DF>, AF2 >
1470 using Type = Subvector<VT,AF2,TF,DF>;
1478 template<
typename VT,
bool AF1,
bool TF,
bool DF,
bool AF2 >
1479 struct SubvectorExprTrait< volatile Subvector<VT,AF1,TF,DF>, AF2 >
1481 using Type = Subvector<VT,AF2,TF,DF>;
1489 template<
typename VT,
bool AF1,
bool TF,
bool DF,
bool AF2 >
1490 struct SubvectorExprTrait< const volatile Subvector<VT,AF1,TF,DF>, AF2 >
1492 using Type = Subvector<VT,AF2,TF,DF>;
1500 template<
typename VT1,
typename VT2,
bool TF,
bool AF >
1501 struct SubvectorExprTrait< DVecDVecCrossExpr<VT1,VT2,TF>, AF >
1505 using Type = Subvector< DVecDVecCrossExpr<VT1,VT2,TF>,
unaligned, TF,
true >;
1514 template<
typename VT1,
typename VT2,
bool TF,
bool AF >
1515 struct SubvectorExprTrait< DVecSVecCrossExpr<VT1,VT2,TF>, AF >
1519 using Type = Subvector< DVecSVecCrossExpr<VT1,VT2,TF>,
unaligned, TF,
true >;
1528 template<
typename VT1,
typename VT2,
bool TF,
bool AF >
1529 struct SubvectorExprTrait< SVecDVecCrossExpr<VT1,VT2,TF>, AF >
1533 using Type = Subvector< SVecDVecCrossExpr<VT1,VT2,TF>,
unaligned, TF,
true >;
1542 template<
typename VT1,
typename VT2,
bool TF,
bool AF >
1543 struct SubvectorExprTrait< SVecSVecCrossExpr<VT1,VT2,TF>, AF >
1547 using Type = Subvector< SVecSVecCrossExpr<VT1,VT2,TF>,
unaligned, TF,
true >;
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.This macro encapsulates the default way o...
Definition: Exception.h:235
Header file for auxiliary alias declarations.
View on a specific subvector of a dense or sparse vector.The Subvector class template represents a vi...
Definition: Forward.h:50
Header file for the alignment flag values.
Header file for the subtraction trait.
BLAZE_ALWAYS_INLINE bool isSame(const Matrix< MT1, SO1 > &a, const Matrix< MT2, SO2 > &b) noexcept
Returns whether the two given matrices represent the same observable state.
Definition: Matrix.h:653
Header file for basic type definitions.
Header file for the IsVecVecMultExpr type trait class.
Header file for the IsCrossExpr type trait class.
Header file for the serial shim.
Header file for the IsVecVecSubExpr type trait class.
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector) noexcept
Returns the current size/dimension of the vector.
Definition: Vector.h:258
Subvector specialization for sparse vectors.
const bool aligned
Alignment flag for aligned vectors and matrices.Via this flag it is possible to specify subvectors...
Definition: AlignmentFlag.h:85
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:533
Header file for the IsVecForEachExpr type trait class.
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:723
BoolConstant< true > 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 IsVecSerialExpr type trait class.
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:573
Subvector specialization for dense vectors.
Header file for the IsVecEvalExpr type trait class.
SubvectorExprTrait_< VT, unaligned > 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:152
Header file for the IsVecVecAddExpr type trait class.
Header file for the DisableIf class template.
Header file for the multiplication trait.
Header file for the IsVecVecDivExpr type trait class.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2647
Header file for the Or class template.
const DMatForEachExpr< MT, OP, SO > forEach(const DenseMatrix< MT, SO > &dm, OP op)
Evaluates the given custom operation on each single element of the dense matrix dm.
Definition: DMatForEachExpr.h:1046
Header file for the implementation of the Subvector base template.
typename SubvectorExprTrait< VT, AF >::Type SubvectorExprTrait_
Auxiliary alias declaration for the SubvectorExprTrait type trait.The SubvectorExprTrait_ alias decla...
Definition: SubvectorExprTrait.h:133
Header file for the subvector trait.
Header file for the IsVecScalarDivExpr type trait class.
Header file for the IsAligned type trait.
Header file for the exception macros of the math module.
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:254
const bool unaligned
Alignment flag for unaligned vectors and matrices.Via this flag it is possible to specify subvectors...
Definition: AlignmentFlag.h:64
Header file for the EnableIf class template.
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:553
Header file for the HasConstDataAccess type trait.
Header file for the IsVecTransExpr type trait class.
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2642
Header file for the addition trait.
Header file for the cross product trait.
Header file for the division trait.
Header file for the isDefault shim.
Header file for the HasMutableDataAccess type trait.
const DMatEvalExpr< MT, SO > eval(const DenseMatrix< MT, SO > &dm)
Forces the evaluation of the given dense matrix expression dm.
Definition: DMatEvalExpr.h:705
IntegralConstant< bool, B > BoolConstant
Generic wrapper for a compile time constant boolean value.The BoolConstant class template represents ...
Definition: IntegralConstant.h:100
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:154
const DMatTransExpr< MT,!SO > trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:950
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 IntegralConstant class template.
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:240
Header file for the SubvectorExprTrait class template.
Header file for the Vector CRTP base class.
#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.
Header file for the FunctionTrace class.