11 #ifndef EIGEN_JACOBI_H
12 #define EIGEN_JACOBI_H
71 template<
typename Derived>
78 void makeGivens(
const Scalar&
p,
const Scalar& q, Scalar* r=0);
82 void makeGivens(
const Scalar&
p,
const Scalar& q, Scalar* r, internal::true_type);
84 void makeGivens(
const Scalar&
p,
const Scalar& q, Scalar* r, internal::false_type);
94 template<
typename Scalar>
138 template<
typename Scalar>
139 template<
typename Derived>
162 template<
typename Scalar>
171 template<
typename Scalar>
185 else if(
p==Scalar(0))
207 m_s = -qs*
conj(ps)*(m_c/p2);
224 m_s = -
conj(ps) * (q/u);
231 template<
typename Scalar>
239 m_c =
p<Scalar(0) ? Scalar(-1) : Scalar(1);
246 m_s = q<Scalar(0) ? Scalar(1) : Scalar(-1);
283 template<
typename VectorX,
typename VectorY,
typename OtherScalar>
294 template<
typename Derived>
295 template<
typename OtherScalar>
299 RowXpr
x(this->
row(p));
300 RowXpr
y(this->
row(q));
310 template<
typename Derived>
311 template<
typename OtherScalar>
315 ColXpr
x(this->
col(p));
316 ColXpr
y(this->
col(q));
322 template<
typename Scalar,
typename OtherScalar,
323 int SizeAtCompileTime,
int MinAlignment,
bool Vectorizable>
324 struct apply_rotation_in_the_plane_selector
341 template<
typename Scalar,
typename OtherScalar,
342 int SizeAtCompileTime,
int MinAlignment>
343 struct apply_rotation_in_the_plane_selector<Scalar,OtherScalar,SizeAtCompileTime,MinAlignment,true >
345 static inline void run(Scalar *
x,
Index incrx, Scalar *
y,
Index incry,
Index size, OtherScalar
c, OtherScalar s)
347 typedef typename packet_traits<Scalar>::type Packet;
348 typedef typename packet_traits<OtherScalar>::type OtherPacket;
350 constexpr
int RequiredAlignment =
351 (
std::max)(unpacket_traits<Packet>::alignment, unpacket_traits<OtherPacket>::alignment);
355 if(
size >= 2 * PacketSize && SizeAtCompileTime ==
Dynamic && ((incrx == 1 && incry == 1) || PacketSize == 1))
358 constexpr
Index Peeling = 2;
361 Index alignedEnd = alignedStart + ((
size-alignedStart)/PacketSize)*PacketSize;
363 const OtherPacket pc = pset1<OtherPacket>(
c);
364 const OtherPacket ps = pset1<OtherPacket>(s);
365 conj_helper<OtherPacket,Packet,NumTraits<OtherScalar>::IsComplex,
false> pcj;
366 conj_helper<OtherPacket,Packet,false,false>
pm;
381 for(
Index i=alignedStart;
i<alignedEnd;
i+=PacketSize)
383 Packet xi = pload<Packet>(px);
384 Packet yi = pload<Packet>(py);
393 Index peelingEnd = alignedStart + ((
size-alignedStart)/(Peeling*PacketSize))*(Peeling*PacketSize);
394 for(
Index i=alignedStart;
i<peelingEnd;
i+=Peeling*PacketSize)
396 Packet xi = ploadu<Packet>(px);
397 Packet xi1 = ploadu<Packet>(px+PacketSize);
398 Packet yi = pload <Packet>(py);
399 Packet yi1 = pload <Packet>(py+PacketSize);
401 pstoreu(px+PacketSize,
padd(
pm.pmul(pc,xi1),pcj.pmul(ps,yi1)));
403 pstore (py+PacketSize,
psub(pcj.pmul(pc,yi1),
pm.pmul(ps,xi1)));
404 px += Peeling*PacketSize;
405 py += Peeling*PacketSize;
407 if(alignedEnd!=peelingEnd)
409 Packet xi = ploadu<Packet>(
x+peelingEnd);
410 Packet yi = pload <Packet>(
y+peelingEnd);
426 else if(SizeAtCompileTime !=
Dynamic && MinAlignment >= RequiredAlignment)
428 const OtherPacket pc = pset1<OtherPacket>(
c);
429 const OtherPacket ps = pset1<OtherPacket>(s);
430 conj_helper<OtherPacket,Packet,NumTraits<OtherScalar>::IsComplex,
false> pcj;
431 conj_helper<OtherPacket,Packet,false,false>
pm;
436 Packet xi = pload<Packet>(px);
437 Packet yi = pload<Packet>(py);
448 apply_rotation_in_the_plane_selector<Scalar,OtherScalar,SizeAtCompileTime,MinAlignment,false>::run(
x,incrx,
y,incry,
size,
c,s);
453 template<
typename VectorX,
typename VectorY,
typename OtherScalar>
458 constexpr
bool Vectorizable = (int(evaluator<VectorX>::Flags) & int(evaluator<VectorY>::Flags) &
PacketAccessBit) &&
469 OtherScalar
c =
j.c();
470 OtherScalar s =
j.s();
474 constexpr
int Alignment = (
std::min)(
int(evaluator<VectorX>::Alignment), int(evaluator<VectorY>::Alignment));
475 apply_rotation_in_the_plane_selector<Scalar, OtherScalar, VectorX::SizeAtCompileTime, Alignment, Vectorizable>::run(
476 x, incrx,
y, incry,
size,
c, s);
const AbsReturnType abs() const
const SqrtReturnType sqrt() const
RowXpr row(Index i)
This is the const version of row(). */.
ColXpr col(Index i)
This is the const version of col().
RealReturnType real() const
G makeGivens(v.x(), v.y())
#define EIGEN_DEVICE_FUNC
Base class for all dense matrices, vectors, and arrays.
internal::traits< Derived >::Scalar Scalar
EIGEN_CONSTEXPR Index size() const EIGEN_NOEXCEPT
Rotation given by a cosine-sine pair.
JacobiRotation(const Scalar &c, const Scalar &s)
bool makeJacobi(const MatrixBase< Derived > &, Index p, Index q)
JacobiRotation adjoint() const
NumTraits< Scalar >::Real RealScalar
JacobiRotation transpose() const
JacobiRotation operator*(const JacobiRotation &other)
void makeGivens(const Scalar &p, const Scalar &q, Scalar *r=0)
Base class for all dense matrices, vectors, and expressions.
void applyOnTheLeft(const EigenBase< OtherDerived > &other)
void applyOnTheRight(const EigenBase< OtherDerived > &other)
constexpr const Scalar & coeff(Index rowId, Index colId) const
const unsigned int PacketAccessBit
bfloat16() max(const bfloat16 &a, const bfloat16 &b)
bfloat16() min(const bfloat16 &a, const bfloat16 &b)
Packet padd(const Packet &a, const Packet &b)
void pstore(Scalar *to, const Packet &from)
void apply_rotation_in_the_plane(DenseBase< VectorX > &xpr_x, DenseBase< VectorY > &xpr_y, const JacobiRotation< OtherScalar > &j)
void pstoreu(Scalar *to, const Packet &from)
Packet psub(const Packet &a, const Packet &b)
static Index first_default_aligned(const DenseBase< Derived > &m)
bool is_exactly_one(const X &x)
bool is_exactly_zero(const X &x)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_conjugate_op< typename Derived::Scalar >, const Derived > conj(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_abs_op< typename Derived::Scalar >, const Derived > abs(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_sqrt_op< typename Derived::Scalar >, const Derived > sqrt(const Eigen::ArrayBase< Derived > &x)
Eigen::Index Index
The interface type of indices.
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.