37 typedef typename NumTraits<Scalar>::Real RealScalar;
45 Scalar& c() {
return m_c; }
46 Scalar c()
const {
return m_c; }
47 Scalar& s() {
return m_s; }
48 Scalar s()
const {
return m_s; }
64 template<
typename Derived>
66 bool makeJacobi(
const RealScalar& x,
const Scalar& y,
const RealScalar& z);
68 void makeGivens(
const Scalar& p,
const Scalar&
q, Scalar* z=0);
82template<
typename Scalar>
87 typedef typename NumTraits<Scalar>::Real RealScalar;
96 RealScalar
tau = (x-z)/(RealScalar(2)*abs(y));
97 RealScalar w = sqrt(numext::abs2(
tau) + RealScalar(1));
101 t = RealScalar(1) / (
tau + w);
105 t = RealScalar(1) / (
tau - w);
107 RealScalar
sign_t = t > RealScalar(0) ? RealScalar(1) : RealScalar(-1);
108 RealScalar n = RealScalar(1) / sqrt(numext::abs2(t)+RealScalar(1));
109 m_s = -
sign_t * (numext::conj(y) / abs(y)) * abs(t) * n;
124template<
typename Scalar>
125template<
typename Derived>
128 return makeJacobi(numext::real(m.coeff(p,p)), m.coeff(p,
q), numext::real(m.coeff(
q,
q)));
147template<
typename Scalar>
155template<
typename Scalar>
164 m_c = numext::real(p)<0 ? Scalar(-1) : Scalar(1);
168 else if(p==Scalar(0))
176 RealScalar p1 = numext::norm1(p);
177 RealScalar q1 = numext::norm1(q);
181 RealScalar p2 = numext::abs2(ps);
183 RealScalar q2 = numext::abs2(qs);
185 RealScalar u = sqrt(RealScalar(1) + q2/p2);
186 if(numext::real(p)<RealScalar(0))
190 m_s = -qs*conj(ps)*(m_c/p2);
196 RealScalar p2 = numext::abs2(ps);
198 RealScalar q2 = numext::abs2(qs);
200 RealScalar u = q1 * sqrt(p2 + q2);
201 if(numext::real(p)<RealScalar(0))
207 m_s = -conj(ps) * (q/u);
214template<
typename Scalar>
215void JacobiRotation<Scalar>::makeGivens(
const Scalar& p,
const Scalar& q, Scalar* r, internal::false_type)
221 m_c = p<Scalar(0) ? Scalar(-1) : Scalar(1);
225 else if(p==Scalar(0))
228 m_s = q<Scalar(0) ? Scalar(1) : Scalar(-1);
231 else if(abs(p) > abs(q))
234 Scalar u = sqrt(Scalar(1) + numext::abs2(t));
244 Scalar u = sqrt(Scalar(1) + numext::abs2(t));
265template<
typename VectorX,
typename VectorY,
typename OtherScalar>
266void apply_rotation_in_the_plane(DenseBase<VectorX>& xpr_x, DenseBase<VectorY>& xpr_y,
const JacobiRotation<OtherScalar>& j);
275template<
typename Derived>
276template<
typename OtherScalar>
279 RowXpr x(this->row(p));
280 RowXpr y(this->row(
q));
281 internal::apply_rotation_in_the_plane(x, y,
j);
290template<
typename Derived>
291template<
typename OtherScalar>
294 ColXpr x(this->col(p));
295 ColXpr y(this->col(
q));
296 internal::apply_rotation_in_the_plane(x, y,
j.transpose());
300template<
typename VectorX,
typename VectorY,
typename OtherScalar>
303 typedef typename VectorX::Scalar Scalar;
304 enum { PacketSize = packet_traits<Scalar>::size };
305 typedef typename packet_traits<Scalar>::type Packet;
306 eigen_assert(xpr_x.size() == xpr_y.size());
307 Index size = xpr_x.size();
308 Index incrx = xpr_x.derived().innerStride();
309 Index incry = xpr_y.derived().innerStride();
311 Scalar* EIGEN_RESTRICT x = &xpr_x.derived().coeffRef(0);
312 Scalar* EIGEN_RESTRICT y = &xpr_y.derived().coeffRef(0);
314 OtherScalar c = j.c();
315 OtherScalar s = j.s();
316 if (c==OtherScalar(1) && s==OtherScalar(0))
321 if(VectorX::SizeAtCompileTime == Dynamic &&
323 ((incrx==1 && incry==1) || PacketSize == 1))
326 enum { Peeling = 2 };
328 Index alignedStart = internal::first_default_aligned(y, size);
329 Index alignedEnd = alignedStart + ((size-alignedStart)/PacketSize)*PacketSize;
331 const Packet pc = pset1<Packet>(c);
332 const Packet ps = pset1<Packet>(s);
333 conj_helper<Packet,Packet,NumTraits<Scalar>::IsComplex,
false> pcj;
335 for(Index i=0; i<alignedStart; ++i)
339 x[i] = c * xi + numext::conj(s) * yi;
340 y[i] = -s * xi + numext::conj(c) * yi;
343 Scalar* EIGEN_RESTRICT px = x + alignedStart;
344 Scalar* EIGEN_RESTRICT py = y + alignedStart;
346 if(internal::first_default_aligned(x, size)==alignedStart)
348 for(Index i=alignedStart; i<alignedEnd; i+=PacketSize)
350 Packet xi = pload<Packet>(px);
351 Packet yi = pload<Packet>(py);
352 pstore(px, padd(pmul(pc,xi),pcj.pmul(ps,yi)));
353 pstore(py, psub(pcj.pmul(pc,yi),pmul(ps,xi)));
360 Index peelingEnd = alignedStart + ((size-alignedStart)/(Peeling*PacketSize))*(Peeling*PacketSize);
361 for(Index i=alignedStart; i<peelingEnd; i+=Peeling*PacketSize)
363 Packet xi = ploadu<Packet>(px);
364 Packet xi1 = ploadu<Packet>(px+PacketSize);
365 Packet yi = pload <Packet>(py);
366 Packet yi1 = pload <Packet>(py+PacketSize);
367 pstoreu(px, padd(pmul(pc,xi),pcj.pmul(ps,yi)));
368 pstoreu(px+PacketSize, padd(pmul(pc,xi1),pcj.pmul(ps,yi1)));
369 pstore (py, psub(pcj.pmul(pc,yi),pmul(ps,xi)));
370 pstore (py+PacketSize, psub(pcj.pmul(pc,yi1),pmul(ps,xi1)));
371 px += Peeling*PacketSize;
372 py += Peeling*PacketSize;
374 if(alignedEnd!=peelingEnd)
376 Packet xi = ploadu<Packet>(x+peelingEnd);
377 Packet yi = pload <Packet>(y+peelingEnd);
378 pstoreu(x+peelingEnd, padd(pmul(pc,xi),pcj.pmul(ps,yi)));
379 pstore (y+peelingEnd, psub(pcj.pmul(pc,yi),pmul(ps,xi)));
383 for(Index i=alignedEnd; i<size; ++i)
387 x[i] = c * xi + numext::conj(s) * yi;
388 y[i] = -s * xi + numext::conj(c) * yi;
393 else if(VectorX::SizeAtCompileTime != Dynamic &&
395 (EIGEN_PLAIN_ENUM_MIN(evaluator<VectorX>::Alignment, evaluator<VectorY>::Alignment)>0))
397 const Packet pc = pset1<Packet>(c);
398 const Packet ps = pset1<Packet>(s);
399 conj_helper<Packet,Packet,NumTraits<Scalar>::IsComplex,
false> pcj;
400 Scalar* EIGEN_RESTRICT px = x;
401 Scalar* EIGEN_RESTRICT py = y;
402 for(Index i=0; i<size; i+=PacketSize)
404 Packet xi = pload<Packet>(px);
405 Packet yi = pload<Packet>(py);
406 pstore(px, padd(pmul(pc,xi),pcj.pmul(ps,yi)));
407 pstore(py, psub(pcj.pmul(pc,yi),pmul(ps,xi)));
416 for(Index i=0; i<size; ++i)
420 *x = c * xi + numext::conj(s) * yi;
421 *y = -s * xi + numext::conj(c) * yi;
\jacobi_module
Definition Jacobi.h:35
JacobiRotation()
Default constructor without any initialization.
Definition Jacobi.h:40
JacobiRotation(const Scalar &c, const Scalar &s)
Construct a planar rotation from a cosine-sine pair (c, s).
Definition Jacobi.h:43
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:126
JacobiRotation adjoint() const
Returns the adjoint transformation.
Definition Jacobi.h:62
JacobiRotation transpose() const
Returns the transposed transformation.
Definition Jacobi.h:59
JacobiRotation operator*(const JacobiRotation &other)
Concatenates two planar rotation.
Definition Jacobi.h:51
void makeGivens(const Scalar &p, const Scalar &q, Scalar *z=0)
Makes *this as a Givens rotation G such that applying to the left of the vector yields: .
Definition Jacobi.h:148
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:50
Pseudo expression representing a solving operation.
Definition Solve.h:63
const unsigned int PacketAccessBit
Short version: means the expression might be vectorized.
Definition Constants.h:88
Holds information about the various numeric (i.e.
Definition NumTraits.h:108