Make NoAlias and JacobiRotation compatible with CUDA.

This commit is contained in:
Gael Guennebaud 2017-08-17 11:51:22 +02:00
parent 1f4b24d2df
commit 687bedfcad
3 changed files with 19 additions and 5 deletions

View File

@ -296,7 +296,7 @@ template<typename Derived> class MatrixBase
EIGEN_DEVICE_FUNC inline bool operator!=(const MatrixBase<OtherDerived>& other) const EIGEN_DEVICE_FUNC inline bool operator!=(const MatrixBase<OtherDerived>& other) const
{ return cwiseNotEqual(other).any(); } { return cwiseNotEqual(other).any(); }
NoAlias<Derived,Eigen::MatrixBase > noalias(); NoAlias<Derived,Eigen::MatrixBase > EIGEN_DEVICE_FUNC noalias();
// TODO forceAlignedAccess is temporarily disabled // TODO forceAlignedAccess is temporarily disabled
// Need to find a nicer workaround. // Need to find a nicer workaround.
@ -428,8 +428,10 @@ template<typename Derived> class MatrixBase
///////// Jacobi module ///////// ///////// Jacobi module /////////
template<typename OtherScalar> template<typename OtherScalar>
EIGEN_DEVICE_FUNC
void applyOnTheLeft(Index p, Index q, const JacobiRotation<OtherScalar>& j); void applyOnTheLeft(Index p, Index q, const JacobiRotation<OtherScalar>& j);
template<typename OtherScalar> template<typename OtherScalar>
EIGEN_DEVICE_FUNC
void applyOnTheRight(Index p, Index q, const JacobiRotation<OtherScalar>& j); void applyOnTheRight(Index p, Index q, const JacobiRotation<OtherScalar>& j);
///////// SparseCore module ///////// ///////// SparseCore module /////////

View File

@ -33,6 +33,7 @@ class NoAlias
public: public:
typedef typename ExpressionType::Scalar Scalar; typedef typename ExpressionType::Scalar Scalar;
EIGEN_DEVICE_FUNC
explicit NoAlias(ExpressionType& expression) : m_expression(expression) {} explicit NoAlias(ExpressionType& expression) : m_expression(expression) {}
template<typename OtherDerived> template<typename OtherDerived>

View File

@ -37,17 +37,20 @@ template<typename Scalar> class JacobiRotation
typedef typename NumTraits<Scalar>::Real RealScalar; typedef typename NumTraits<Scalar>::Real RealScalar;
/** Default constructor without any initialization. */ /** Default constructor without any initialization. */
EIGEN_DEVICE_FUNC
JacobiRotation() {} JacobiRotation() {}
/** Construct a planar rotation from a cosine-sine pair (\a c, \c s). */ /** Construct a planar rotation from a cosine-sine pair (\a c, \c s). */
EIGEN_DEVICE_FUNC
JacobiRotation(const Scalar& c, const Scalar& s) : m_c(c), m_s(s) {} JacobiRotation(const Scalar& c, const Scalar& s) : m_c(c), m_s(s) {}
Scalar& c() { return m_c; } EIGEN_DEVICE_FUNC Scalar& c() { return m_c; }
Scalar c() const { return m_c; } EIGEN_DEVICE_FUNC Scalar c() const { return m_c; }
Scalar& s() { return m_s; } EIGEN_DEVICE_FUNC Scalar& s() { return m_s; }
Scalar s() const { return m_s; } EIGEN_DEVICE_FUNC Scalar s() const { return m_s; }
/** Concatenates two planar rotation */ /** Concatenates two planar rotation */
EIGEN_DEVICE_FUNC
JacobiRotation operator*(const JacobiRotation& other) JacobiRotation operator*(const JacobiRotation& other)
{ {
using numext::conj; using numext::conj;
@ -56,19 +59,26 @@ template<typename Scalar> class JacobiRotation
} }
/** Returns the transposed transformation */ /** Returns the transposed transformation */
EIGEN_DEVICE_FUNC
JacobiRotation transpose() const { using numext::conj; return JacobiRotation(m_c, -conj(m_s)); } JacobiRotation transpose() const { using numext::conj; return JacobiRotation(m_c, -conj(m_s)); }
/** Returns the adjoint transformation */ /** Returns the adjoint transformation */
EIGEN_DEVICE_FUNC
JacobiRotation adjoint() const { using numext::conj; return JacobiRotation(conj(m_c), -m_s); } JacobiRotation adjoint() const { using numext::conj; return JacobiRotation(conj(m_c), -m_s); }
template<typename Derived> template<typename Derived>
EIGEN_DEVICE_FUNC
bool makeJacobi(const MatrixBase<Derived>&, Index p, Index q); bool makeJacobi(const MatrixBase<Derived>&, Index p, Index q);
EIGEN_DEVICE_FUNC
bool makeJacobi(const RealScalar& x, const Scalar& y, const RealScalar& z); bool makeJacobi(const RealScalar& x, const Scalar& y, const RealScalar& z);
EIGEN_DEVICE_FUNC
void makeGivens(const Scalar& p, const Scalar& q, Scalar* z=0); void makeGivens(const Scalar& p, const Scalar& q, Scalar* z=0);
protected: protected:
EIGEN_DEVICE_FUNC
void makeGivens(const Scalar& p, const Scalar& q, Scalar* z, internal::true_type); void makeGivens(const Scalar& p, const Scalar& q, Scalar* z, internal::true_type);
EIGEN_DEVICE_FUNC
void makeGivens(const Scalar& p, const Scalar& q, Scalar* z, internal::false_type); void makeGivens(const Scalar& p, const Scalar& q, Scalar* z, internal::false_type);
Scalar m_c, m_s; Scalar m_c, m_s;
@ -264,6 +274,7 @@ namespace internal {
* \sa MatrixBase::applyOnTheLeft(), MatrixBase::applyOnTheRight() * \sa MatrixBase::applyOnTheLeft(), MatrixBase::applyOnTheRight()
*/ */
template<typename VectorX, typename VectorY, typename OtherScalar> template<typename VectorX, typename VectorY, typename OtherScalar>
EIGEN_DEVICE_FUNC
void apply_rotation_in_the_plane(DenseBase<VectorX>& xpr_x, DenseBase<VectorY>& xpr_y, const JacobiRotation<OtherScalar>& j); void apply_rotation_in_the_plane(DenseBase<VectorX>& xpr_x, DenseBase<VectorY>& xpr_y, const JacobiRotation<OtherScalar>& j);
} }