47 EIGEN_DEVICE_FUNC Scalar& c() {
return m_c; }
48 EIGEN_DEVICE_FUNC Scalar c()
const {
return m_c; }
49 EIGEN_DEVICE_FUNC Scalar& s() {
return m_s; }
50 EIGEN_DEVICE_FUNC Scalar s()
const {
return m_s; }
69 template<
typename Derived>
73 bool makeJacobi(
const RealScalar& x,
const Scalar& y,
const RealScalar& z);
76 void makeGivens(
const Scalar& p,
const Scalar&
q, Scalar* r=0);
92template<
typename Scalar>
99 RealScalar
deno = RealScalar(2)*abs(y);
100 if(
deno < (std::numeric_limits<RealScalar>::min)())
109 RealScalar w = sqrt(numext::abs2(
tau) + RealScalar(1));
111 if(
tau>RealScalar(0))
113 t = RealScalar(1) / (
tau + w);
117 t = RealScalar(1) / (
tau - w);
119 RealScalar
sign_t = t > RealScalar(0) ? RealScalar(1) : RealScalar(-1);
120 RealScalar n = RealScalar(1) / sqrt(numext::abs2(t)+RealScalar(1));
121 m_s = -
sign_t * (numext::conj(y) / abs(y)) * abs(t) * n;
136template<
typename Scalar>
137template<
typename Derived>
141 return makeJacobi(numext::real(m.coeff(p,p)), m.coeff(p,
q), numext::real(m.coeff(
q,
q)));
160template<
typename Scalar>
169template<
typename Scalar>
179 m_c = numext::real(p)<0 ? Scalar(-1) : Scalar(1);
183 else if(p==Scalar(0))
191 RealScalar p1 = numext::norm1(p);
192 RealScalar q1 = numext::norm1(q);
196 RealScalar p2 = numext::abs2(ps);
198 RealScalar q2 = numext::abs2(qs);
200 RealScalar u = sqrt(RealScalar(1) + q2/p2);
201 if(numext::real(p)<RealScalar(0))
205 m_s = -qs*conj(ps)*(m_c/p2);
211 RealScalar p2 = numext::abs2(ps);
213 RealScalar q2 = numext::abs2(qs);
215 RealScalar u = q1 * sqrt(p2 + q2);
216 if(numext::real(p)<RealScalar(0))
222 m_s = -conj(ps) * (q/u);
229template<
typename Scalar>
231void JacobiRotation<Scalar>::makeGivens(
const Scalar& p,
const Scalar& q, Scalar* r, internal::false_type)
237 m_c = p<Scalar(0) ? Scalar(-1) : Scalar(1);
241 else if(p==Scalar(0))
244 m_s = q<Scalar(0) ? Scalar(1) : Scalar(-1);
247 else if(abs(p) > abs(q))
250 Scalar u = sqrt(Scalar(1) + numext::abs2(t));
260 Scalar u = sqrt(Scalar(1) + numext::abs2(t));
281template<
typename VectorX,
typename VectorY,
typename OtherScalar>
283void apply_rotation_in_the_plane(DenseBase<VectorX>& xpr_x, DenseBase<VectorY>& xpr_y,
const JacobiRotation<OtherScalar>& j);
292template<
typename Derived>
293template<
typename OtherScalar>
297 RowXpr x(this->row(p));
298 RowXpr y(this->row(
q));
299 internal::apply_rotation_in_the_plane(x, y, j);
308template<
typename Derived>
309template<
typename OtherScalar>
313 ColXpr x(this->col(p));
314 ColXpr y(this->col(
q));
315 internal::apply_rotation_in_the_plane(x, y, j.
transpose());
321 int SizeAtCompileTime,
int MinAlignment,
bool Vectorizable>
324 static EIGEN_DEVICE_FUNC
327 for(
Index i=0; i<size; ++i)
331 *x = c *
xi + numext::conj(s) *
yi;
332 *y = -s *
xi + numext::conj(c) *
yi;
349 typedef typename packet_traits<Scalar>::type
Packet;
350 typedef typename packet_traits<OtherScalar>::type
OtherPacket;
370 x[i] = c *
xi + numext::conj(s) *
yi;
371 y[i] = -s *
xi + numext::conj(c) *
yi;
377 if(internal::first_default_aligned(x, size)==
alignedStart)
418 x[i] = c *
xi + numext::conj(s) *
yi;
419 y[i] = -s *
xi + numext::conj(c) *
yi;
430 Scalar* EIGEN_RESTRICT
px = x;
431 Scalar* EIGEN_RESTRICT
py = y;
432 for(
Index i=0; i<size; i+=PacketSize)
446 apply_rotation_in_the_plane_selector<Scalar,OtherScalar,SizeAtCompileTime,MinAlignment,false>::run(x,incrx,y,incry,size,c,s);
451template<
typename VectorX,
typename VectorY,
typename OtherScalar>
453void apply_rotation_in_the_plane(DenseBase<VectorX>& xpr_x, DenseBase<VectorY>& xpr_y,
const JacobiRotation<OtherScalar>& j)
455 typedef typename VectorX::Scalar Scalar;
456 const bool Vectorizable = (int(VectorX::Flags) & int(VectorY::Flags) &
PacketAccessBit)
457 && (
int(packet_traits<Scalar>::size) == int(packet_traits<OtherScalar>::size));
459 eigen_assert(xpr_x.size() == xpr_y.size());
460 Index size = xpr_x.size();
461 Index incrx = xpr_x.derived().innerStride();
462 Index incry = xpr_y.derived().innerStride();
464 Scalar* EIGEN_RESTRICT x = &xpr_x.derived().coeffRef(0);
465 Scalar* EIGEN_RESTRICT y = &xpr_y.derived().coeffRef(0);
467 OtherScalar c = j.c();
468 OtherScalar s = j.s();
469 if (c==OtherScalar(1) && s==OtherScalar(0))
472 apply_rotation_in_the_plane_selector<
474 VectorX::SizeAtCompileTime,
475 EIGEN_PLAIN_ENUM_MIN(evaluator<VectorX>::Alignment, evaluator<VectorY>::Alignment),
476 Vectorizable>::run(x,incrx,y,incry,size,c,s);
EIGEN_DEVICE_FUNC TransposeReturnType transpose()
Definition Transpose.h:182
\jacobi_module
Definition Jacobi.h:35
EIGEN_DEVICE_FUNC void makeGivens(const Scalar &p, const Scalar &q, Scalar *r=0)
Makes *this as a Givens rotation G such that applying to the left of the vector yields: .
Definition Jacobi.h:162
EIGEN_DEVICE_FUNC JacobiRotation transpose() const
Returns the transposed transformation.
Definition Jacobi.h:63
EIGEN_DEVICE_FUNC JacobiRotation operator*(const JacobiRotation &other)
Concatenates two planar rotation.
Definition Jacobi.h:54
EIGEN_DEVICE_FUNC JacobiRotation()
Default constructor without any initialization.
Definition Jacobi.h:41
EIGEN_DEVICE_FUNC JacobiRotation adjoint() const
Returns the adjoint transformation.
Definition Jacobi.h:67
EIGEN_DEVICE_FUNC JacobiRotation(const Scalar &c, const Scalar &s)
Construct a planar rotation from a cosine-sine pair (c, s).
Definition Jacobi.h:45
EIGEN_DEVICE_FUNC bool makeJacobi(const MatrixBase< Derived > &, Index p, Index q)
Makes *this as a Jacobi rotation J such that applying J on both the right and left sides of the 2x2 s...
Definition Jacobi.h:139
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:50
const unsigned int PacketAccessBit
Short version: means the expression might be vectorized.
Definition Constants.h:94
Namespace containing all symbols from the Eigen library.
Definition LDLT.h:16
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:74
const int Dynamic
This value means that a positive quantity (e.g., a size) is not known at compile-time,...
Definition Constants.h:22
Holds information about the various numeric (i.e.
Definition NumTraits.h:236
Definition GenericPacketMath.h:107
Definition PacketMath.h:47