MOAB  4.9.3pre
Eigen::JacobiRotation< Scalar > Class Template Reference

Rotation given by a cosine-sine pair. More...

#include <Jacobi.h>

Collaboration diagram for Eigen::JacobiRotation< Scalar >:

List of all members.

Public Types

typedef NumTraits< Scalar >::Real RealScalar

Public Member Functions

 JacobiRotation ()
 JacobiRotation (const Scalar &c, const Scalar &s)
Scalar & c ()
Scalar c () const
Scalar & s ()
Scalar s () const
JacobiRotation operator* (const JacobiRotation &other)
JacobiRotation transpose () const
JacobiRotation adjoint () const
template<typename Derived >
bool makeJacobi (const MatrixBase< Derived > &, Index p, Index q)
bool makeJacobi (const RealScalar &x, const Scalar &y, const RealScalar &z)
void makeGivens (const Scalar &p, const Scalar &q, Scalar *z=0)

Protected Member Functions

void makeGivens (const Scalar &p, const Scalar &q, Scalar *z, internal::true_type)
void makeGivens (const Scalar &p, const Scalar &q, Scalar *z, internal::false_type)

Protected Attributes

Scalar m_c
Scalar m_s

Detailed Description

template<typename Scalar>
class Eigen::JacobiRotation< Scalar >

Rotation given by a cosine-sine pair.

This class represents a Jacobi or Givens rotation. This is a 2D rotation in the plane J of angle $ \theta $ defined by its cosine c and sine s as follow: $ J = \left ( \begin{array}{cc} c & \overline s \\ -s & \overline c \end{array} \right ) $

You can apply the respective counter-clockwise rotation to a column vector v by applying its adjoint on the left: $ v = J^* v $ that translates to the following Eigen code:

 v.applyOnTheLeft(J.adjoint());
See also:
MatrixBase::applyOnTheLeft(), MatrixBase::applyOnTheRight()

Definition at line 34 of file Jacobi.h.


Member Typedef Documentation

template<typename Scalar>
typedef NumTraits<Scalar>::Real Eigen::JacobiRotation< Scalar >::RealScalar

Definition at line 37 of file Jacobi.h.


Constructor & Destructor Documentation

template<typename Scalar>
Eigen::JacobiRotation< Scalar >::JacobiRotation ( ) [inline]

Default constructor without any initialization.

Definition at line 40 of file Jacobi.h.

{}
template<typename Scalar>
Eigen::JacobiRotation< Scalar >::JacobiRotation ( const Scalar &  c,
const Scalar &  s 
) [inline]

Construct a planar rotation from a cosine-sine pair (c, s).

Definition at line 43 of file Jacobi.h.

: m_c(c), m_s(s) {}

Member Function Documentation

template<typename Scalar>
JacobiRotation Eigen::JacobiRotation< Scalar >::adjoint ( ) const [inline]

Returns the adjoint transformation

Definition at line 62 of file Jacobi.h.

{ using numext::conj; return JacobiRotation(conj(m_c), -m_s); }
template<typename Scalar>
Scalar& Eigen::JacobiRotation< Scalar >::c ( ) [inline]

Definition at line 45 of file Jacobi.h.

{ return m_c; }
template<typename Scalar>
Scalar Eigen::JacobiRotation< Scalar >::c ( ) const [inline]

Definition at line 46 of file Jacobi.h.

{ return m_c; }
template<typename Scalar >
void Eigen::JacobiRotation< Scalar >::makeGivens ( const Scalar &  p,
const Scalar &  q,
Scalar *  z = 0 
)

Makes *this as a Givens rotation G such that applying $ G^* $ to the left of the vector $ V = \left ( \begin{array}{c} p \\ q \end{array} \right )$ yields: $ G^* V = \left ( \begin{array}{c} r \\ 0 \end{array} \right )$.

The value of z is returned if z is not null (the default is null). Also note that G is built such that the cosine is always real.

Example:

Output:

This function implements the continuous Givens rotation generation algorithm found in Anderson (2000), Discontinuous Plane Rotations and the Symmetric Eigenvalue Problem. LAPACK Working Note 150, University of Tennessee, UT-CS-00-454, December 4, 2000.

See also:
MatrixBase::applyOnTheLeft(), MatrixBase::applyOnTheRight()

Definition at line 148 of file Jacobi.h.

{
  makeGivens(p, q, z, typename internal::conditional<NumTraits<Scalar>::IsComplex, internal::true_type, internal::false_type>::type());
}
template<typename Scalar >
void Eigen::JacobiRotation< Scalar >::makeGivens ( const Scalar &  p,
const Scalar &  q,
Scalar *  z,
internal::true_type   
) [protected]

Definition at line 156 of file Jacobi.h.

{
  using std::sqrt;
  using std::abs;
  using numext::conj;
  
  if(q==Scalar(0))
  {
    m_c = numext::real(p)<0 ? Scalar(-1) : Scalar(1);
    m_s = 0;
    if(r) *r = m_c * p;
  }
  else if(p==Scalar(0))
  {
    m_c = 0;
    m_s = -q/abs(q);
    if(r) *r = abs(q);
  }
  else
  {
    RealScalar p1 = numext::norm1(p);
    RealScalar q1 = numext::norm1(q);
    if(p1>=q1)
    {
      Scalar ps = p / p1;
      RealScalar p2 = numext::abs2(ps);
      Scalar qs = q / p1;
      RealScalar q2 = numext::abs2(qs);

      RealScalar u = sqrt(RealScalar(1) + q2/p2);
      if(numext::real(p)<RealScalar(0))
        u = -u;

      m_c = Scalar(1)/u;
      m_s = -qs*conj(ps)*(m_c/p2);
      if(r) *r = p * u;
    }
    else
    {
      Scalar ps = p / q1;
      RealScalar p2 = numext::abs2(ps);
      Scalar qs = q / q1;
      RealScalar q2 = numext::abs2(qs);

      RealScalar u = q1 * sqrt(p2 + q2);
      if(numext::real(p)<RealScalar(0))
        u = -u;

      p1 = abs(p);
      ps = p/p1;
      m_c = p1/u;
      m_s = -conj(ps) * (q/u);
      if(r) *r = ps * u;
    }
  }
}
template<typename Scalar >
void Eigen::JacobiRotation< Scalar >::makeGivens ( const Scalar &  p,
const Scalar &  q,
Scalar *  z,
internal::false_type   
) [protected]

Definition at line 215 of file Jacobi.h.

{
  using std::sqrt;
  using std::abs;
  if(q==Scalar(0))
  {
    m_c = p<Scalar(0) ? Scalar(-1) : Scalar(1);
    m_s = Scalar(0);
    if(r) *r = abs(p);
  }
  else if(p==Scalar(0))
  {
    m_c = Scalar(0);
    m_s = q<Scalar(0) ? Scalar(1) : Scalar(-1);
    if(r) *r = abs(q);
  }
  else if(abs(p) > abs(q))
  {
    Scalar t = q/p;
    Scalar u = sqrt(Scalar(1) + numext::abs2(t));
    if(p<Scalar(0))
      u = -u;
    m_c = Scalar(1)/u;
    m_s = -t * m_c;
    if(r) *r = p * u;
  }
  else
  {
    Scalar t = p/q;
    Scalar u = sqrt(Scalar(1) + numext::abs2(t));
    if(q<Scalar(0))
      u = -u;
    m_s = -Scalar(1)/u;
    m_c = -t * m_s;
    if(r) *r = q * u;
  }

}
template<typename Scalar >
template<typename Derived >
bool Eigen::JacobiRotation< Scalar >::makeJacobi ( const MatrixBase< Derived > &  m,
Index  p,
Index  q 
) [inline]

Makes *this as a Jacobi rotation J such that applying J on both the right and left sides of the 2x2 selfadjoint matrix $ B = \left ( \begin{array}{cc} \text{this}_{pp} & \text{this}_{pq} \\ (\text{this}_{pq})^* & \text{this}_{qq} \end{array} \right )$ yields a diagonal matrix $ A = J^* B J $

Example:

Output:

See also:
JacobiRotation::makeJacobi(RealScalar, Scalar, RealScalar), MatrixBase::applyOnTheLeft(), MatrixBase::applyOnTheRight()

Definition at line 126 of file Jacobi.h.

{
  return makeJacobi(numext::real(m.coeff(p,p)), m.coeff(p,q), numext::real(m.coeff(q,q)));
}
template<typename Scalar >
bool Eigen::JacobiRotation< Scalar >::makeJacobi ( const RealScalar x,
const Scalar &  y,
const RealScalar z 
)

Makes *this as a Jacobi rotation J such that applying J on both the right and left sides of the selfadjoint 2x2 matrix $ B = \left ( \begin{array}{cc} x & y \\ \overline y & z \end{array} \right )$ yields a diagonal matrix $ A = J^* B J $

See also:
MatrixBase::makeJacobi(const MatrixBase<Derived>&, Index, Index), MatrixBase::applyOnTheLeft(), MatrixBase::applyOnTheRight()

Definition at line 83 of file Jacobi.h.

{
  using std::sqrt;
  using std::abs;
  typedef typename NumTraits<Scalar>::Real RealScalar;
  if(y == Scalar(0))
  {
    m_c = Scalar(1);
    m_s = Scalar(0);
    return false;
  }
  else
  {
    RealScalar tau = (x-z)/(RealScalar(2)*abs(y));
    RealScalar w = sqrt(numext::abs2(tau) + RealScalar(1));
    RealScalar t;
    if(tau>RealScalar(0))
    {
      t = RealScalar(1) / (tau + w);
    }
    else
    {
      t = RealScalar(1) / (tau - w);
    }
    RealScalar sign_t = t > RealScalar(0) ? RealScalar(1) : RealScalar(-1);
    RealScalar n = RealScalar(1) / sqrt(numext::abs2(t)+RealScalar(1));
    m_s = - sign_t * (numext::conj(y) / abs(y)) * abs(t) * n;
    m_c = n;
    return true;
  }
}
template<typename Scalar>
JacobiRotation Eigen::JacobiRotation< Scalar >::operator* ( const JacobiRotation< Scalar > &  other) [inline]

Concatenates two planar rotation

Definition at line 51 of file Jacobi.h.

    {
      using numext::conj;
      return JacobiRotation(m_c * other.m_c - conj(m_s) * other.m_s,
                            conj(m_c * conj(other.m_s) + conj(m_s) * conj(other.m_c)));
    }
template<typename Scalar>
Scalar& Eigen::JacobiRotation< Scalar >::s ( ) [inline]

Definition at line 47 of file Jacobi.h.

{ return m_s; }
template<typename Scalar>
Scalar Eigen::JacobiRotation< Scalar >::s ( ) const [inline]

Definition at line 48 of file Jacobi.h.

{ return m_s; }
template<typename Scalar>
JacobiRotation Eigen::JacobiRotation< Scalar >::transpose ( ) const [inline]

Returns the transposed transformation

Definition at line 59 of file Jacobi.h.

{ using numext::conj; return JacobiRotation(m_c, -conj(m_s)); }

Member Data Documentation

template<typename Scalar>
Scalar Eigen::JacobiRotation< Scalar >::m_c [protected]

Definition at line 74 of file Jacobi.h.

template<typename Scalar>
Scalar Eigen::JacobiRotation< Scalar >::m_s [protected]

Definition at line 74 of file Jacobi.h.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines