35 #ifndef _BLAZE_MATH_VIEWS_SUBVECTOR_H_ 36 #define _BLAZE_MATH_VIEWS_SUBVECTOR_H_ 156 return subvector<unaligned,I,N>( ~vector, args... );
224 return subvector<unaligned,I,N>( ~vector, args... );
252 return subvector<unaligned,I,N>( ~vector, args... );
413 using ReturnType =
const Subvector_<const VT,AF,I,N>;
507 template<
typename VT
514 return subvector<unaligned>( ~vector, index,
size, args... );
575 template<
typename VT
582 return subvector<unaligned>( ~vector, index,
size, args... );
603 template<
typename VT
610 return subvector<unaligned>( ~vector, index,
size, args... );
771 using ReturnType =
const Subvector_<const VT,AF>;
833 inline decltype(
auto)
subvector( const VecVecAddExpr<VT>& vector, RSAs... args )
837 return subvector<AF,CSAs...>( (~vector).leftOperand(), args... ) +
838 subvector<AF,CSAs...>( (~vector).rightOperand(), args... );
860 inline decltype(
auto)
subvector( const VecVecSubExpr<VT>& vector, RSAs... args )
864 return subvector<AF,CSAs...>( (~vector).leftOperand(), args... ) -
865 subvector<AF,CSAs...>( (~vector).rightOperand(), args... );
887 inline decltype(
auto)
subvector( const VecVecMultExpr<VT>& vector, RSAs... args )
891 return subvector<AF,CSAs...>( (~vector).leftOperand(), args... ) *
892 subvector<AF,CSAs...>( (~vector).rightOperand(), args... );
914 inline decltype(
auto)
subvector( const VecVecDivExpr<VT>& vector, RSAs... args )
918 return subvector<AF,CSAs...>( (~vector).leftOperand(), args... ) /
919 subvector<AF,CSAs...>( (~vector).rightOperand(), args... );
941 inline decltype(
auto)
subvector( const CrossExpr<VT>& vector, RSAs... args )
945 using ReturnType = Subvector_< VectorType_t<VT>, AF, CSAs... >;
968 inline decltype(
auto)
subvector( const VecScalarMultExpr<VT>& vector, RSAs... args )
972 return subvector<AF,CSAs...>( (~vector).leftOperand(), args... ) * (~vector).rightOperand();
994 inline decltype(
auto)
subvector( const VecScalarDivExpr<VT>& vector, RSAs... args )
998 return subvector<AF,CSAs...>( (~vector).leftOperand(), args... ) / (~vector).rightOperand();
1019 ,
typename... RSAs >
1020 inline decltype(
auto)
subvector( const VecMapExpr<VT>& vector, RSAs... args )
1024 return map( subvector<AF,CSAs...>( (~vector).operand(), args... ), (~vector).operation() );
1045 ,
typename... RSAs >
1046 inline decltype(
auto)
subvector( const VecVecMapExpr<VT>& vector, RSAs... args )
1050 return map( subvector<AF,CSAs...>( (~vector).leftOperand(), args... ),
1051 subvector<AF,CSAs...>( (~vector).rightOperand(), args... ),
1052 (~vector).operation() );
1073 ,
typename... RSAs >
1074 inline decltype(
auto)
subvector( const VecEvalExpr<VT>& vector, RSAs... args )
1078 return eval( subvector<AF,CSAs...>( (~vector).operand(), args... ) );
1099 ,
typename... RSAs >
1100 inline decltype(
auto)
subvector( const VecSerialExpr<VT>& vector, RSAs... args )
1104 return serial( subvector<AF,CSAs...>( (~vector).operand(), args... ) );
1125 ,
typename... RSAs >
1126 inline decltype(
auto)
subvector( const VecTransExpr<VT>& vector, RSAs... args )
1130 return trans( subvector<AF,CSAs...>( (~vector).operand(), args... ) );
1156 ,
typename... RSAs >
1157 inline decltype(
auto)
subvector( Subvector<VT,AF2,TF,DF,I2,N2>& sv, RSAs... args )
1163 return subvector<AF1,I1+I2,N1>( sv.operand(), args... );
1190 ,
typename... RSAs >
1191 inline decltype(
auto)
subvector( const Subvector<VT,AF2,TF,DF,I2,N2>& sv, RSAs... args )
1197 return subvector<AF1,I1+I2,N1>( sv.operand(), args... );
1224 ,
typename... RSAs >
1225 inline decltype(
auto)
subvector( Subvector<VT,AF2,TF,DF,I2,N2>&& sv, RSAs... args )
1231 return subvector<AF1,I1+I2,N1>( sv.operand(), args... );
1256 ,
typename... RSAs >
1257 inline decltype(
auto)
subvector( Subvector<VT,AF2,TF,DF>& sv, RSAs... args )
1264 if( I + N > sv.size() ) {
1272 return subvector<AF1>( sv.operand(), sv.offset() + I, N, args... );
1298 ,
typename... RSAs >
1299 inline decltype(
auto)
subvector( const Subvector<VT,AF2,TF,DF>& sv, RSAs... args )
1306 if( I + N > sv.size() ) {
1314 return subvector<AF1>( sv.operand(), sv.offset() + I, N, args... );
1340 ,
typename... RSAs >
1341 inline decltype(
auto)
subvector( Subvector<VT,AF2,TF,DF>&& sv, RSAs... args )
1348 if( I + N > sv.size() ) {
1356 return subvector<AF1>( sv.operand(), sv.offset() + I, N, args... );
1382 ,
typename... RSAs >
1383 inline decltype(
auto)
1384 subvector( Subvector<VT,AF2,TF,DF,CSAs...>& sv,
size_t index,
size_t size, RSAs... args )
1391 if( index +
size > sv.size() ) {
1399 return subvector<AF1>( sv.operand(), sv.offset() + index,
size, args... );
1426 ,
typename... RSAs >
1427 inline decltype(
auto)
1428 subvector( const Subvector<VT,AF2,TF,DF,CSAs...>& sv,
size_t index,
size_t size, RSAs... args )
1435 if( index +
size > sv.size() ) {
1443 return subvector<AF1>( sv.operand(), sv.offset() + index,
size, args... );
1470 ,
typename... RSAs >
1471 inline decltype(
auto)
1472 subvector( Subvector<VT,AF2,TF,DF,CSAs...>&& sv,
size_t index,
size_t size, RSAs... args )
1479 if( index +
size > sv.size() ) {
1487 return subvector<AF1>( sv.operand(), sv.offset() + index,
size, args... );
1521 ,
typename... REAs >
1522 inline decltype(
auto)
1523 elements( Subvector<VT,AF,TF,DF,I2,N>& sv, REAs... args )
1553 ,
typename... REAs >
1554 inline decltype(
auto)
1555 elements( const Subvector<VT,AF,TF,DF,I2,N>& sv, REAs... args )
1585 ,
typename... REAs >
1586 inline decltype(
auto)
1587 elements( Subvector<VT,AF,TF,DF,I2,N>&& sv, REAs... args )
1616 ,
typename... REAs >
1617 inline decltype(
auto)
elements( Subvector<VT,AF,TF,DF>& sv, REAs... args )
1624 static constexpr
size_t indices[] = { I, Is... };
1625 for(
size_t i=0UL; i<
sizeof...(Is)+1UL; ++i ) {
1626 if( sv.size() <= indices[i] ) {
1632 return elements( sv.operand(), { I+sv.offset(), Is+sv.offset()... }, args... );
1657 ,
typename... REAs >
1658 inline decltype(
auto)
elements( const Subvector<VT,AF,TF,DF>& sv, REAs... args )
1665 static constexpr
size_t indices[] = { I, Is... };
1666 for(
size_t i=0UL; i<
sizeof...(Is)+1UL; ++i ) {
1667 if( sv.size() <= indices[i] ) {
1673 return elements( sv.operand(), { I+sv.offset(), Is+sv.offset()... }, args... );
1698 ,
typename... REAs >
1699 inline decltype(
auto)
elements( Subvector<VT,AF,TF,DF>&& sv, REAs... args )
1706 static constexpr
size_t indices[] = { I, Is... };
1707 for(
size_t i=0UL; i<
sizeof...(Is)+1UL; ++i ) {
1708 if( sv.size() <= indices[i] ) {
1714 return elements( sv.operand(), { I+sv.offset(), Is+sv.offset()... }, args... );
1735 template<
typename VT
1741 ,
typename... REAs >
1742 inline decltype(
auto)
1743 elements( Subvector<VT,AF,TF,DF,CSAs...>& sv, const T* indices,
size_t n, REAs... args )
1750 for(
size_t i=0UL; i<n; ++i ) {
1751 if( sv.size() <= indices[i] ) {
1757 SmallArray<size_t,128UL> newIndices( indices, indices+n );
1758 std::for_each( newIndices.begin(), newIndices.end(),
1759 [offset=sv.offset()](
size_t& index ){ index += offset; } );
1761 return elements( sv.operand(), newIndices.data(), n, args... );
1782 template<
typename VT
1788 ,
typename... REAs >
1789 inline decltype(
auto)
1790 elements( const Subvector<VT,AF,TF,DF,CSAs...>& sv, const T* indices,
size_t n, REAs... args )
1797 for(
size_t i=0UL; i<n; ++i ) {
1798 if( sv.size() <= indices[i] ) {
1804 SmallArray<size_t,128UL> newIndices( indices, indices+n );
1805 std::for_each( newIndices.begin(), newIndices.end(),
1806 [offset=sv.offset()](
size_t& index ){ index += offset; } );
1808 return elements( sv.operand(), newIndices.data(), n, args... );
1829 template<
typename VT
1835 ,
typename... REAs >
1836 inline decltype(
auto)
1837 elements( Subvector<VT,AF,TF,DF,CSAs...>&& sv, const T* indices,
size_t n, REAs... args )
1844 for(
size_t i=0UL; i<n; ++i ) {
1845 if( sv.size() <= indices[i] ) {
1851 SmallArray<size_t,128UL> newIndices( indices, indices+n );
1852 std::for_each( newIndices.begin(), newIndices.end(),
1853 [offset=sv.offset()](
size_t& index ){ index += offset; } );
1855 return elements( sv.operand(), newIndices.data(), n, args... );
1877 template<
typename VT
1882 inline void reset( Subvector<VT,AF,TF,DF,CSAs...>& sv )
1898 template<
typename VT
1903 inline void reset( Subvector<VT,AF,TF,DF,CSAs...>&& sv )
1919 template<
typename VT
1924 inline void clear( Subvector<VT,AF,TF,DF,CSAs...>& sv )
1940 template<
typename VT
1945 inline void clear( Subvector<VT,AF,TF,DF,CSAs...>&& sv )
1985 inline bool isDefault(
const Subvector<VT,AF,TF,true,CSAs...>& sv )
1989 for(
size_t i=0UL; i<sv.size(); ++i )
1990 if( !isDefault<RF>( sv[i] ) )
return false;
2029 inline bool isDefault(
const Subvector<VT,AF,TF,false,CSAs...>& sv )
2033 for(
const auto& element : ~sv )
2034 if( !isDefault<RF>( element.value() ) )
return false;
2059 template<
typename VT
2064 inline bool isIntact(
const Subvector<VT,AF,TF,DF,CSAs...>& sv ) noexcept
2066 return ( sv.offset() + sv.size() <= sv.operand().size() &&
2086 template<
typename VT
2091 inline bool isSame(
const Subvector<VT,AF,TF,DF,CSAs...>& a,
const Vector<VT,TF>& b ) noexcept
2093 return (
isSame( a.operand(), ~b ) && ( a.size() == (~b).
size() ) );
2112 template<
typename VT
2117 inline bool isSame(
const Vector<VT,TF>& a,
const Subvector<VT,AF,TF,DF,CSAs...>& b ) noexcept
2138 template<
typename VT1
2148 inline bool isSame(
const Subvector<VT1,AF1,TF1,DF1,CSAs1...>& a,
2149 const Subvector<VT2,AF2,TF2,DF2,CSAs2...>& b ) noexcept
2151 return (
isSame( a.operand(), b.operand() ) &&
2152 ( a.offset() == b.offset() ) &&
2153 ( a.size() == b.size() ) );
2174 template<
typename VT
2180 inline bool trySet(
const Subvector<VT,AF,TF,DF,CSAs...>& sv,
size_t index,
const ET& value )
2184 return trySet( sv.operand(), sv.offset()+index, value );
2205 template<
typename VT
2211 inline bool tryAdd(
const Subvector<VT,AF,TF,DF,CSAs...>& sv,
size_t index,
const ET& value )
2215 return tryAdd( sv.operand(), sv.offset()+index, value );
2236 template<
typename VT
2242 inline bool trySub(
const Subvector<VT,AF,TF,DF,CSAs...>& sv,
size_t index,
const ET& value )
2246 return trySub( sv.operand(), sv.offset()+index, value );
2267 template<
typename VT
2273 inline bool tryMult(
const Subvector<VT,AF,TF,DF,CSAs...>& sv,
size_t index,
const ET& value )
2277 return tryMult( sv.operand(), sv.offset()+index, value );
2299 template<
typename VT
2306 tryMult(
const Subvector<VT,AF,TF,DF,CSAs...>& sv,
size_t index,
size_t size,
const ET& value )
2311 return tryMult( sv.operand(), sv.offset()+index,
size, value );
2332 template<
typename VT
2338 inline bool tryDiv(
const Subvector<VT,AF,TF,DF,CSAs...>& sv,
size_t index,
const ET& value )
2342 return tryDiv( sv.operand(), sv.offset()+index, value );
2364 template<
typename VT
2371 tryDiv(
const Subvector<VT,AF,TF,DF,CSAs...>& sv,
size_t index,
size_t size,
const ET& value )
2376 return tryDiv( sv.operand(), sv.offset()+index,
size, value );
2397 template<
typename VT1
2403 inline bool tryAssign(
const Subvector<VT1,AF,TF,DF,CSAs...>& lhs,
2404 const Vector<VT2,TF>& rhs,
size_t index )
2409 return tryAssign( lhs.operand(), ~rhs, lhs.offset() + index );
2430 template<
typename VT1
2436 inline bool tryAddAssign(
const Subvector<VT1,AF,TF,DF,CSAs...>& lhs,
2437 const Vector<VT2,TF>& rhs,
size_t index )
2442 return tryAddAssign( lhs.operand(), ~rhs, lhs.offset() + index );
2463 template<
typename VT1
2469 inline bool trySubAssign(
const Subvector<VT1,AF,TF,DF,CSAs...>& lhs,
2470 const Vector<VT2,TF>& rhs,
size_t index )
2475 return trySubAssign( lhs.operand(), ~rhs, lhs.offset() + index );
2496 template<
typename VT1
2502 inline bool tryMultAssign(
const Subvector<VT1,AF,TF,DF,CSAs...>& lhs,
2503 const Vector<VT2,TF>& rhs,
size_t index )
2508 return tryMultAssign( lhs.operand(), ~rhs, lhs.offset() + index );
2529 template<
typename VT1
2535 inline bool tryDivAssign(
const Subvector<VT1,AF,TF,DF,CSAs...>& lhs,
2536 const Vector<VT2,TF>& rhs,
size_t index )
2541 return tryDivAssign( lhs.operand(), ~rhs, lhs.offset() + index );
2562 template<
typename VT
2568 inline decltype(
auto) derestrict( Subvector<VT,AF,TF,DF,I,N>& sv )
2570 return subvector<AF,I,N>( derestrict( sv.operand() ),
unchecked );
2591 template<
typename VT
2597 inline decltype(
auto) derestrict( Subvector<VT,AF,TF,DF,I,N>&& sv )
2599 return subvector<AF,I,N>( derestrict( sv.operand() ),
unchecked );
2620 template<
typename VT
2624 inline decltype(
auto) derestrict( Subvector<VT,AF,TF,DF>& sv )
2626 return subvector<AF>( derestrict( sv.operand() ), sv.offset(), sv.size(),
unchecked );
2647 template<
typename VT
2651 inline decltype(
auto) derestrict( Subvector<VT,AF,TF,DF>&& sv )
2653 return subvector<AF>( derestrict( sv.operand() ), sv.offset(), sv.size(),
unchecked );
2669 template<
typename VT, AlignmentFlag AF,
bool TF,
bool DF,
size_t I,
size_t N >
2670 struct Size< Subvector<VT,AF,TF,DF,I,N>, 0UL >
2687 template<
typename VT, AlignmentFlag AF,
bool TF,
bool DF,
size_t I,
size_t N >
2688 struct MaxSize< Subvector<VT,AF,TF,DF,I,N>, 0UL >
2705 template<
typename VT,
AlignmentFlag AF,
bool TF,
bool DF,
size_t... CSAs >
2706 struct IsRestricted< Subvector<VT,AF,TF,DF,CSAs...> >
2707 :
public IsRestricted<VT>
2723 template<
typename VT,
AlignmentFlag AF,
bool TF,
size_t... CSAs >
2724 struct HasConstDataAccess< Subvector<VT,AF,TF,true,CSAs...> >
2725 :
public HasConstDataAccess<VT>
2741 template<
typename VT,
AlignmentFlag AF,
bool TF,
size_t... CSAs >
2742 struct HasMutableDataAccess< Subvector<VT,AF,TF,true,CSAs...> >
2743 :
public HasMutableDataAccess<VT>
2759 template<
typename VT,
bool TF,
size_t... CSAs >
2760 struct IsAligned< Subvector<VT,
aligned,TF,true,CSAs...> >
2777 template<
typename VT,
AlignmentFlag AF,
bool TF,
size_t... CSAs >
2778 struct IsContiguous< Subvector<VT,AF,TF,true,CSAs...> >
2779 :
public IsContiguous<VT>
decltype(auto) subvector(Vector< VT, TF > &, RSAs...)
Creating a view on a specific subvector of the given vector.
Definition: Subvector.h:329
AlignmentFlag
Alignment flag for (un-)aligned vectors and matrices.Via these flags it is possible to specify subvec...
Definition: AlignmentFlag.h:62
#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.
Header file for the blaze::checked and blaze::unchecked instances.
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_USER_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERT flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:117
Header file for the alignment flag values.
Header file for the VecVecDivExpr base class.
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:992
Header file for basic type definitions.
Header file for the serial shim.
Subvector specialization for sparse vectors.
Header file for the VecMapExpr base class.
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:591
Header file for the VecScalarDivExpr base class.
constexpr Unchecked unchecked
Global Unchecked instance.The blaze::unchecked instance is an optional token for the creation of view...
Definition: Check.h:138
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
#define BLAZE_STATIC_ASSERT_MSG(expr, msg)
Compile time assertion macro.In case of an invalid compile time expression, a compilation error is cr...
Definition: StaticAssert.h:123
Header file for the VecEvalExpr base class.
Header file for the VecScalarMultExpr base class.
Header file for the MaxSize type trait.
Header file for the VecVecMapExpr base class.
Subvector specialization for dense vectors.
Header file for the SmallArray implementation.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
#define BLAZE_ALWAYS_INLINE
Platform dependent setup of an enforced inline keyword.
Definition: Inline.h:85
Header file for the VecVecAddExpr base class.
Header file for the implementation of the Subvector base template.
constexpr bool Contains_v
Auxiliary variable template for the Contains type trait.The Contains_v variable template provides a c...
Definition: Contains.h:139
Header file for the IsAligned type trait.
decltype(auto) eval(const DenseMatrix< MT, SO > &dm)
Forces the evaluation of the given dense matrix expression dm.
Definition: DMatEvalExpr.h:786
decltype(auto) elements(Vector< VT, TF > &vector, REAs... args)
Creating a view on a selection of elements of the given vector.
Definition: Elements.h:135
Header file for the exception macros of the math module.
Header file for the VecVecMultExpr base class.
Header file for the VecVecSubExpr base class.
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:611
Header file for the CrossExpr base class.
Flag for aligned vectors and matrices.
Definition: AlignmentFlag.h:65
Header file for the HasConstDataAccess type trait.
IntegralConstant< ptrdiff_t, N > PtrdiffT
Compile time integral constant wrapper for ptrdiff_t.The PtrdiffT class template represents an integr...
Definition: PtrdiffT.h:72
Header file for the VecSerialExpr base class.
Header file for the PtrdiffT class template.
Header file for the VecTransExpr base class.
decltype(subsequence< Is... >(shift< Offset >(make_index_sequence< N >()))) make_shifted_index_subsequence
Auxiliary alias declaration for the setup of shifted index subsequences.The make_shifted_index_subseq...
Definition: IntegerSequence.h:243
Header file for run time assertion macros.
Header file for the Unique class template.
Header file for the IsContiguous type trait.
Check< false > Unchecked
Type of the blaze::unchecked instance.blaze::Unchecked is the type of the blaze::unchecked instance...
Definition: Check.h:96
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:94
Header file for the isDefault shim.
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:530
Header file for the integer_sequence and index_sequence aliases.
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:808
Header file for the HasMutableDataAccess type trait.
Header file for the RemoveReference type trait.
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:3081
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:765
Base class for N-dimensional vectors.The Vector class is a base class for all arbitrarily sized (N-di...
Definition: Forward.h:186
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:263
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:631
Header file for the IsRestricted type trait.
Header file for the Vector CRTP base class.
Header file for the Size type trait.
#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 function trace functionality.
decltype(auto) map(const DenseMatrix< MT1, SO > &lhs, const DenseMatrix< MT2, SO > &rhs, OP op)
Evaluates the given binary operation on each single element of the dense matrices lhs and rhs...
Definition: DMatDMatMapExpr.h:1110