mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-11 19:29:02 +08:00
Make is_same_dense compatible with different scalar types.
This commit is contained in:
parent
67ec37f7b0
commit
3ae2083e23
@ -680,13 +680,18 @@ template<typename S1, typename S2> struct glue_shapes;
|
|||||||
template<> struct glue_shapes<DenseShape,TriangularShape> { typedef TriangularShape type; };
|
template<> struct glue_shapes<DenseShape,TriangularShape> { typedef TriangularShape type; };
|
||||||
|
|
||||||
template<typename T1, typename T2>
|
template<typename T1, typename T2>
|
||||||
bool is_same_dense(const T1 &mat1, const T2 &mat2, typename enable_if<has_direct_access<T1>::ret&&has_direct_access<T2>::ret, T1>::type * = 0)
|
struct possibly_same_dense {
|
||||||
|
enum { value = has_direct_access<T1>::ret && has_direct_access<T2>::ret && is_same<typename T1::Scalar,typename T2::Scalar>::value };
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T1, typename T2>
|
||||||
|
bool is_same_dense(const T1 &mat1, const T2 &mat2, typename enable_if<possibly_same_dense<T1,T2>::value>::type * = 0)
|
||||||
{
|
{
|
||||||
return (mat1.data()==mat2.data()) && (mat1.innerStride()==mat2.innerStride()) && (mat1.outerStride()==mat2.outerStride());
|
return (mat1.data()==mat2.data()) && (mat1.innerStride()==mat2.innerStride()) && (mat1.outerStride()==mat2.outerStride());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T1, typename T2>
|
template<typename T1, typename T2>
|
||||||
bool is_same_dense(const T1 &, const T2 &, typename enable_if<!(has_direct_access<T1>::ret&&has_direct_access<T2>::ret), T1>::type * = 0)
|
bool is_same_dense(const T1 &, const T2 &, typename enable_if<!possibly_same_dense<T1,T2>::value>::type * = 0)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -14,9 +14,13 @@ using internal::is_same_dense;
|
|||||||
void test_is_same_dense()
|
void test_is_same_dense()
|
||||||
{
|
{
|
||||||
typedef Matrix<double,Dynamic,Dynamic,ColMajor> ColMatrixXd;
|
typedef Matrix<double,Dynamic,Dynamic,ColMajor> ColMatrixXd;
|
||||||
|
typedef Matrix<std::complex<double>,Dynamic,Dynamic,ColMajor> ColMatrixXcd;
|
||||||
ColMatrixXd m1(10,10);
|
ColMatrixXd m1(10,10);
|
||||||
|
ColMatrixXcd m2(10,10);
|
||||||
Ref<ColMatrixXd> ref_m1(m1);
|
Ref<ColMatrixXd> ref_m1(m1);
|
||||||
|
Ref<ColMatrixXd,0, Stride<Dynamic,Dynamic> > ref_m2_real(m2.real());
|
||||||
Ref<const ColMatrixXd> const_ref_m1(m1);
|
Ref<const ColMatrixXd> const_ref_m1(m1);
|
||||||
|
|
||||||
VERIFY(is_same_dense(m1,m1));
|
VERIFY(is_same_dense(m1,m1));
|
||||||
VERIFY(is_same_dense(m1,ref_m1));
|
VERIFY(is_same_dense(m1,ref_m1));
|
||||||
VERIFY(is_same_dense(const_ref_m1,m1));
|
VERIFY(is_same_dense(const_ref_m1,m1));
|
||||||
@ -30,4 +34,8 @@ void test_is_same_dense()
|
|||||||
|
|
||||||
Ref<const ColMatrixXd> const_ref_m1_col(m1.col(1));
|
Ref<const ColMatrixXd> const_ref_m1_col(m1.col(1));
|
||||||
VERIFY(is_same_dense(m1.col(1),const_ref_m1_col));
|
VERIFY(is_same_dense(m1.col(1),const_ref_m1_col));
|
||||||
|
|
||||||
|
|
||||||
|
VERIFY(!is_same_dense(m1, ref_m2_real));
|
||||||
|
VERIFY(!is_same_dense(m2, ref_m2_real));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user