diff --git a/src/Core/CopyHelper.h b/src/Core/CopyHelper.h index 75d3af2e8..8c5fc0c13 100644 --- a/src/Core/CopyHelper.h +++ b/src/Core/CopyHelper.h @@ -40,6 +40,17 @@ template struct CopyHelperUnroller } }; +// prevent buggy user code from causing an infinite recursion +template struct CopyHelperUnroller +{ + template + static void run(Derived1 &dst, const Derived2 &src) + { + EIGEN_UNUSED(dst); + EIGEN_UNUSED(src); + } +}; + template struct CopyHelperUnroller<1, Rows> { template @@ -63,7 +74,7 @@ template template void MatrixBase::_copy_helper(const MatrixBase& other) { - if(SizeAtCompileTime != Dynamic && SizeAtCompileTime <= 25) + if(EIGEN_UNROLLED_LOOPS && SizeAtCompileTime != Dynamic && SizeAtCompileTime <= 25) CopyHelperUnroller::run(*this, other); else for(int i = 0; i < rows(); i++) diff --git a/src/Core/Dot.h b/src/Core/Dot.h index 4a0629e56..96d945c7f 100644 --- a/src/Core/Dot.h +++ b/src/Core/Dot.h @@ -32,7 +32,7 @@ struct DotUnroller static void run(const Derived1 &v1, const Derived2& v2, typename Derived1::Scalar &dot) { DotUnroller::run(v1, v2, dot); - dot += v1[Index] * conj(v2[Index]); + dot += v1.read(Index) * conj(v2.read(Index)); } }; @@ -41,7 +41,7 @@ struct DotUnroller<0, Size, Derived1, Derived2> { static void run(const Derived1 &v1, const Derived2& v2, typename Derived1::Scalar &dot) { - dot = v1[0] * conj(v2[0]); + dot = v1.read(0) * conj(v2.read(0)); } }; @@ -56,20 +56,32 @@ struct DotUnroller } }; +// prevent buggy user code from causing an infinite recursion +template +struct DotUnroller +{ + static void run(const Derived1 &v1, const Derived2& v2, typename Derived1::Scalar &dot) + { + EIGEN_UNUSED(v1); + EIGEN_UNUSED(v2); + EIGEN_UNUSED(dot); + } +}; + template template Scalar MatrixBase::dot(const OtherDerived& other) const { assert(IsVector && OtherDerived::IsVector && size() == other.size()); Scalar res; - if(SizeAtCompileTime != Dynamic && SizeAtCompileTime <= 16) + if(EIGEN_UNROLLED_LOOPS && SizeAtCompileTime != Dynamic && SizeAtCompileTime <= 16) DotUnroller ::run(*static_cast(this), other, res); else { - res = (*this)[0] * conj(other[0]); + res = (*this).read(0) * conj(other.read(0)); for(int i = 1; i < size(); i++) - res += (*this)[i]* conj(other[i]); + res += (*this).read(i)* conj(other.read(i)); } return res; } diff --git a/src/Core/Product.h b/src/Core/Product.h index d1d434c9b..b4acfa2c3 100644 --- a/src/Core/Product.h +++ b/src/Core/Product.h @@ -61,6 +61,21 @@ struct ProductUnroller } }; +// prevent buggy user code from causing an infinite recursion +template +struct ProductUnroller +{ + static void run(int row, int col, const Lhs& lhs, const Rhs& rhs, + typename Lhs::Scalar &res) + { + EIGEN_UNUSED(row); + EIGEN_UNUSED(col); + EIGEN_UNUSED(lhs); + EIGEN_UNUSED(rhs); + EIGEN_UNUSED(res); + } +}; + template class Product : public MatrixBase > { @@ -93,14 +108,15 @@ template class Product Scalar _read(int row, int col) const { Scalar res; - if(Lhs::ColsAtCompileTime != Dynamic && Lhs::ColsAtCompileTime <= 16) + if(EIGEN_UNROLLED_LOOPS + && Lhs::ColsAtCompileTime != Dynamic && Lhs::ColsAtCompileTime <= 16) ProductUnroller ::run(row, col, m_lhs, m_rhs, res); else { - res = m_lhs(row, 0) * m_rhs(0, col); + res = m_lhs.read(row, 0) * m_rhs.read(0, col); for(int i = 1; i < m_lhs.cols(); i++) - res += m_lhs(row, i) * m_rhs(i, col); + res += m_lhs.read(row, i) * m_rhs.read(i, col); } return res; } @@ -112,7 +128,7 @@ template class Product template template -Product +const Product MatrixBase::lazyProduct(const MatrixBase &other) const { return Product(ref(), other.ref()); diff --git a/src/Core/Trace.h b/src/Core/Trace.h index 86241da7c..16926bedc 100644 --- a/src/Core/Trace.h +++ b/src/Core/Trace.h @@ -31,7 +31,7 @@ template struct TraceUnroller static void run(const Derived &mat, typename Derived::Scalar &trace) { TraceUnroller::run(mat, trace); - trace += mat(Index, Index); + trace += mat.read(Index, Index); } }; @@ -39,7 +39,7 @@ template struct TraceUnroller<0, Rows, Derived> { static void run(const Derived &mat, typename Derived::Scalar &trace) { - trace = mat(0, 0); + trace = mat.read(0, 0); } }; @@ -52,12 +52,22 @@ template struct TraceUnroller struct TraceUnroller +{ + static void run(const Derived &mat, typename Derived::Scalar &trace) + { + EIGEN_UNUSED(mat); + EIGEN_UNUSED(trace); + } +}; + template Scalar MatrixBase::trace() const { assert(rows() == cols()); Scalar res; - if(RowsAtCompileTime != Dynamic && RowsAtCompileTime <= 16) + if(EIGEN_UNROLLED_LOOPS && RowsAtCompileTime != Dynamic && RowsAtCompileTime <= 16) TraceUnroller ::run(*static_cast(this), res); else