mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-04-20 08:39:37 +08:00
Enable construction of Ref<VectorType> from a runtime vector.
This commit is contained in:
parent
9ba81cf0ff
commit
b0d406d91c
@ -28,12 +28,13 @@ struct traits<Ref<_PlainObjectType, _Options, _StrideType> >
|
|||||||
|
|
||||||
template<typename Derived> struct match {
|
template<typename Derived> struct match {
|
||||||
enum {
|
enum {
|
||||||
|
IsVectorAtCompileTime = PlainObjectType::IsVectorAtCompileTime || Derived::IsVectorAtCompileTime,
|
||||||
HasDirectAccess = internal::has_direct_access<Derived>::ret,
|
HasDirectAccess = internal::has_direct_access<Derived>::ret,
|
||||||
StorageOrderMatch = PlainObjectType::IsVectorAtCompileTime || Derived::IsVectorAtCompileTime || ((PlainObjectType::Flags&RowMajorBit)==(Derived::Flags&RowMajorBit)),
|
StorageOrderMatch = IsVectorAtCompileTime || ((PlainObjectType::Flags&RowMajorBit)==(Derived::Flags&RowMajorBit)),
|
||||||
InnerStrideMatch = int(StrideType::InnerStrideAtCompileTime)==int(Dynamic)
|
InnerStrideMatch = int(StrideType::InnerStrideAtCompileTime)==int(Dynamic)
|
||||||
|| int(StrideType::InnerStrideAtCompileTime)==int(Derived::InnerStrideAtCompileTime)
|
|| int(StrideType::InnerStrideAtCompileTime)==int(Derived::InnerStrideAtCompileTime)
|
||||||
|| (int(StrideType::InnerStrideAtCompileTime)==0 && int(Derived::InnerStrideAtCompileTime)==1),
|
|| (int(StrideType::InnerStrideAtCompileTime)==0 && int(Derived::InnerStrideAtCompileTime)==1),
|
||||||
OuterStrideMatch = Derived::IsVectorAtCompileTime
|
OuterStrideMatch = IsVectorAtCompileTime
|
||||||
|| int(StrideType::OuterStrideAtCompileTime)==int(Dynamic) || int(StrideType::OuterStrideAtCompileTime)==int(Derived::OuterStrideAtCompileTime),
|
|| int(StrideType::OuterStrideAtCompileTime)==int(Dynamic) || int(StrideType::OuterStrideAtCompileTime)==int(Derived::OuterStrideAtCompileTime),
|
||||||
// NOTE, this indirection of evaluator<Derived>::Alignment is needed
|
// NOTE, this indirection of evaluator<Derived>::Alignment is needed
|
||||||
// to workaround a very strange bug in MSVC related to the instantiation
|
// to workaround a very strange bug in MSVC related to the instantiation
|
||||||
|
12
test/ref.cpp
12
test/ref.cpp
@ -102,10 +102,14 @@ template<typename VectorType> void ref_vector(const VectorType& m)
|
|||||||
Index i = internal::random<Index>(0,size-1);
|
Index i = internal::random<Index>(0,size-1);
|
||||||
Index bsize = internal::random<Index>(1,size-i);
|
Index bsize = internal::random<Index>(1,size-i);
|
||||||
|
|
||||||
RefMat rm0 = v1;
|
{ RefMat rm0 = v1; VERIFY_IS_EQUAL(rm0, v1); }
|
||||||
VERIFY_IS_EQUAL(rm0, v1);
|
{ RefMat rm0 = v1.block(0,0,size,1); VERIFY_IS_EQUAL(rm0, v1); }
|
||||||
RefDynMat rv1 = v1;
|
{ RefDynMat rv1 = v1; VERIFY_IS_EQUAL(rv1, v1); }
|
||||||
VERIFY_IS_EQUAL(rv1, v1);
|
{ RefDynMat rv1 = v1.block(0,0,size,1); VERIFY_IS_EQUAL(rv1, v1); }
|
||||||
|
{ VERIFY_RAISES_ASSERT( RefMat rm0 = v1.block(0, 0, size, 0); EIGEN_UNUSED_VARIABLE(rm0); ); }
|
||||||
|
if(VectorType::SizeAtCompileTime!=1)
|
||||||
|
{ VERIFY_RAISES_ASSERT( RefDynMat rv1 = v1.block(0, 0, size, 0); EIGEN_UNUSED_VARIABLE(rv1); ); }
|
||||||
|
|
||||||
RefDynMat rv2 = v1.segment(i,bsize);
|
RefDynMat rv2 = v1.segment(i,bsize);
|
||||||
VERIFY_IS_EQUAL(rv2, v1.segment(i,bsize));
|
VERIFY_IS_EQUAL(rv2, v1.segment(i,bsize));
|
||||||
rv2.setOnes();
|
rv2.setOnes();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user