inlib  1.2.0
Public Member Functions
inlib::sqm< T > Class Template Reference
Inheritance diagram for inlib::sqm< T >:
Inheritance graph
[legend]
Collaboration diagram for inlib::sqm< T >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 sqm (unsigned a_order)
virtual ~sqm ()
 sqm (const sqm &a_from)
sqmoperator= (const sqm &a_from)
bool set_order (unsigned int a_order)
unsigned int order () const
value (unsigned int aR, unsigned int aC) const
bool value (unsigned int aR, unsigned int aC, T &a_value) const
bool set_value (unsigned int aR, unsigned int aC, const T &a_value)
void set_value_no_check (unsigned int aR, unsigned int aC, const T &a_value)
trace () const
bool mx_mul (const sqm< T > &a_matrix, sqm< T > &a_result) const
bool mx_mul (const sqm< T > &a_matrix)
bool mx_left_mul (const sqm< T > &a_matrix, sqm< T > &a_result) const
bool mx_left_mul (const sqm< T > &a_matrix)
virtual T determinant () const
sub_determinant (const std::vector< unsigned int > &aRs, const std::vector< unsigned int > &aCs) const
bool invert (sqm< T > &a_result) const
void transpose ()
bool is_symmetric () const
bool is_antisymmetric () const
void set_identity ()
void set_diag (const T &a_value)
sqm symmetric_part () const
sqm antisymmetric_part () const
sqmoperator*= (const sqm< T > &a_from)
sqmoperator+= (const sqm< T > &a_from)
sqmoperator-= (const sqm< T > &a_from)

Detailed Description

template<class T>
class inlib::sqm< T >

Definition at line 14 of file sqm.


Constructor & Destructor Documentation

template<class T>
inlib::sqm< T >::sqm ( unsigned  a_order) [inline]

Definition at line 16 of file sqm.

                       :array<T>(2,a_order){
    // a_order is the matrix dimension, which must not be confused
    // with the array dimension which is 2).
  }
template<class T>
virtual inlib::sqm< T >::~sqm ( ) [inline, virtual]
template<class T>
inlib::sqm< T >::sqm ( const sqm< T > &  a_from) [inline]

Member Function Documentation

template<class T>
sqm inlib::sqm< T >::antisymmetric_part ( ) const [inline]

Definition at line 328 of file sqm.

                                 {
    sqm res(*this);
    res.transpose();
    res.multiply(array<T>::minus_one());
    res.add(*this);
    res.divide(array<T>::two());
    return res;
  }
template<class T>
virtual T inlib::sqm< T >::determinant ( ) const [inline, virtual]

Reimplemented in inlib::a3::sqm< T >, inlib::a3::sqm< double >, inlib::a4::sqm< T >, inlib::a4::sqm< double >, inlib::a4::sqm< float >, inlib::a4::sqm< std::complex< double > >, inlib::a2::sqm< T >, inlib::a2::sqm< double >, and inlib::a2::sqm< std::complex< double > >.

Definition at line 134 of file sqm.

                                {
    unsigned int ord = order();
    if(ord==0) return array<T>::zero();
    else if(ord==1) return value(0,0);
    else if(ord==2) return (value(0,0) * value(1,1) - 
                            value(1,0) * value(0,1)); //Optimize

    unsigned int rord = ord-1;
    std::vector<unsigned int> cs(rord);
    std::vector<unsigned int> rs(rord);

    T det = array<T>::zero();
   {for(unsigned int i=0;i<rord;i++) {cs[i] = i+1;}}
    unsigned int c = 0;
    //if(c>=1) cs[c-1] = c-1;

   {for(unsigned int i=0;i<rord;i++) {rs[i] = i+1;}}
    bool sg = true; //c=0+r=0
    for(unsigned int r=0;r<ord;r++) {
      if(r>=1) rs[r-1] = r-1;
      T subdet = sub_determinant(rs,cs);
      if(sg) 
        det += value(r,c) * subdet;
      else
        det -= value(r,c) * subdet;
      sg = sg?false:true;
    }

    return det;
  }
template<class T>
bool inlib::sqm< T >::invert ( sqm< T > &  a_result) const [inline]

Reimplemented in inlib::a4::sqm< double >, inlib::a4::sqm< float >, inlib::a4::sqm< std::complex< double > >, and inlib::a3::sqm< double >.

Definition at line 211 of file sqm.

                                      {
    //Generic invertion method.
    unsigned int ord = order();
    if(ord==0) return true;

    a_result.set_order(ord);
    if(ord==1) {
      T v;
      if(!value(0,0,v)) return false;
      if(v==array<T>::zero()) return false;
      if(!a_result.set_value(0,0,1./v)) return false;
      return true;
    }
  
    unsigned int rord = ord-1;
    std::vector<unsigned int> cs(rord);
    std::vector<unsigned int> rs(rord);
  
    // Get det with r = 0;
    T det = array<T>::zero();
   {
   {for(unsigned int i=0;i<rord;i++) {rs[i] = i+1;}}
    unsigned int r = 0;
    //if(r>=1) rs[r-1] = r-1;
  
   {for(unsigned int i=0;i<rord;i++) {cs[i] = i+1;}}
    bool sg = true; //r=0+c=0
    for(unsigned int c=0;c<ord;c++) {
      if(c>=1) cs[c-1] = c-1;
      T subdet = sub_determinant(rs,cs);
      T sgn = sg ? array<T>::one() : array<T>::minus_one();
      det += value(r,c) * subdet * sgn;
      T value = subdet * sgn;
      a_result.set_value_no_check(c,r,value);
      sg = sg?false:true;
    }}
  
    if(det==array<T>::zero()) return false;
  
   {for(unsigned int c=0;c<ord;c++) {
      a_result.set_value(c,0,a_result.value(c,0)/det);
    }}
  
   {for(unsigned int i=0;i<rord;i++) {rs[i] = i+1;}}
    bool sgr = false; //r=1+c=0
    for(unsigned int r=1;r<ord;r++) {
      if(r>=1) rs[r-1] = r-1;
     {for(unsigned int i=0;i<rord;i++) {cs[i] = i+1;}}
      bool sg = sgr;
      for(unsigned int c=0;c<ord;c++) {
        if(c>=1) cs[c-1] = c-1;
        T subdet = sub_determinant(rs,cs);
        T sgn = sg ? array<T>::one() : array<T>::minus_one();
        T value = (subdet * sgn)/det;
        a_result.set_value_no_check(c,r,value);
        sg = sg?false:true;
      }
      sgr = sgr?false:true;
    }
  
    return true;
  }
template<class T>
bool inlib::sqm< T >::is_antisymmetric ( ) const [inline]

Definition at line 295 of file sqm.

                                {
    unsigned int ord = order();
   {for(unsigned int r=0;r<ord;r++) {
      if(value(r,r)!=array<T>::zero()) return false;
    }}
    for(unsigned int r=0;r<ord;r++) {
      for(unsigned int c=(r+1);c<ord;c++) {
        if(value(r,c)!=-value(c,r)) return false;
      }
    }
    return true;
  }
template<class T>
bool inlib::sqm< T >::is_symmetric ( ) const [inline]

Definition at line 286 of file sqm.

                            {
    unsigned int ord = order();
    for(unsigned int r=0;r<ord;r++) {
      for(unsigned int c=(r+1);c<ord;c++) {
        if(value(r,c)!=value(c,r)) return false;
      }
    }
    return true;
  }
template<class T>
bool inlib::sqm< T >::mx_left_mul ( const sqm< T > &  a_matrix,
sqm< T > &  a_result 
) const [inline]

Definition at line 103 of file sqm.

                                                                  {
    // a_result = a_matrix * this
    unsigned int ord = order();
    if(a_matrix.order()!=ord) return false;
    if(a_result.order()!=ord) return false;
    const T* p = &(array<T>::m_vector[0]);            //WARNING : dangerous.
    const T* a_p = &(a_matrix.array<T>::m_vector[0]); //WARNING : dangerous.
    T* r_p = &(a_result.array<T>::m_vector[0]);       //WARNING : dangerous.
    for(unsigned int r=0;r<ord;r++) {
      for(unsigned int c=0;c<ord;c++) {
        T value = array<T>::zero();
        for(unsigned int i=0;i<ord;i++) {
          //value += 
          //  a_matrix.array<T>::m_vector[r+i*ord] * 
          //  array<T>::m_vector[i+c*ord];
          value += (*(a_p+r+i*ord)) * (*(p+i+c*ord)); //optimize.
        }
        //a_result.array<T>::m_vector[r+c*ord] = value;
        *(r_p+r+c*ord) = value;
      }
    }
    return true;
  }
template<class T>
bool inlib::sqm< T >::mx_left_mul ( const sqm< T > &  a_matrix) [inline]

Definition at line 127 of file sqm.

                                           {
    sqm<T> res(order());
    bool status = this->mx_left_mul(a_matrix,res);
    *this = res;
    return status;
  }
template<class T>
bool inlib::sqm< T >::mx_mul ( const sqm< T > &  a_matrix,
sqm< T > &  a_result 
) const [inline]

Definition at line 72 of file sqm.

                                                             {
    // a_result = this * a_matrix
    unsigned int ord = order();
    if(a_matrix.order()!=ord) return false;
    if(a_result.order()!=ord) return false;
    const T* p = &(array<T>::m_vector[0]);            //WARNING : dangerous.
    const T* a_p = &(a_matrix.array<T>::m_vector[0]); //WARNING : dangerous.
    T* r_p = &(a_result.array<T>::m_vector[0]);       //WARNING : dangerous.
    for(unsigned int r=0;r<ord;r++) {
      for(unsigned int c=0;c<ord;c++) {
        T value = array<T>::zero();
        for(unsigned int i=0;i<ord;i++) {
          //value += 
          //  array<T>::m_vector[r+i*ord] * 
          //  a_matrix.array<T>::m_vector[i+c*ord];
          value += (*(p+r+i*ord)) * (*(a_p+i+c*ord)); //optimize.
        }
        //a_result.array<T>::m_vector[r+c*ord] = value;
        *(r_p+r+c*ord) = value;
      }
    }
    return true;
  }
template<class T>
bool inlib::sqm< T >::mx_mul ( const sqm< T > &  a_matrix) [inline]

Definition at line 96 of file sqm.

                                      {
    sqm<T> res(order());
    bool status = this->mx_mul(a_matrix,res);
    *this = res;
    return status;
  }
template<class T>
sqm& inlib::sqm< T >::operator*= ( const sqm< T > &  a_from) [inline]

Definition at line 337 of file sqm.

                                        {
    sqm<T> res(order());
    /*bool status =*/ this->mx_mul(a_from,res); //FIXME : throw
    *this = res;
    return *this;
  }
template<class T>
sqm& inlib::sqm< T >::operator+= ( const sqm< T > &  a_from) [inline]

Definition at line 343 of file sqm.

                                        {
    /*bool status =*/ array<T>::add(a_from); //FIXME : throw
    return *this;
  }
template<class T>
sqm& inlib::sqm< T >::operator-= ( const sqm< T > &  a_from) [inline]

Definition at line 347 of file sqm.

                                        {
    /*bool status =*/ array<T>::subtract(a_from); //FIXME : throw
    return *this;
  }
template<class T>
sqm& inlib::sqm< T >::operator= ( const sqm< T > &  a_from) [inline]
template<class T>
unsigned int inlib::sqm< T >::order ( ) const [inline]

Definition at line 34 of file sqm.

{ return array<T>::m_orders[0];}
template<class T>
void inlib::sqm< T >::set_diag ( const T &  a_value) [inline]

Definition at line 314 of file sqm.

                                  {
    unsigned int ord = order();
    for(unsigned int c=0;c<ord;c++) set_value_no_check(c,c,a_value);
  }
template<class T>
void inlib::sqm< T >::set_identity ( ) [inline]

Definition at line 308 of file sqm.

                      {
    unsigned int ord = order();
    array<T>::reset();
    for(unsigned int c=0;c<ord;c++) set_value_no_check(c,c,array<T>::one());
  }
template<class T>
bool inlib::sqm< T >::set_order ( unsigned int  a_order) [inline]

Definition at line 28 of file sqm.

                                       {
    std::vector<unsigned int> orders(2);
    for(unsigned int index=0;index<2;index++) orders[index] = a_order;
    return array<T>::configure(orders);
  }
template<class T>
bool inlib::sqm< T >::set_value ( unsigned int  aR,
unsigned int  aC,
const T &  a_value 
) [inline]

Definition at line 52 of file sqm.

                                                                   { 
    unsigned int ord = order();
    if((aR>=ord)||(aC>=ord)) return false;
    array<T>::m_vector[aR + aC * ord] = a_value;
    return true;
  }
template<class T>
void inlib::sqm< T >::set_value_no_check ( unsigned int  aR,
unsigned int  aC,
const T &  a_value 
) [inline]

Definition at line 59 of file sqm.

                                               { 
    array<T>::m_vector[aR + aC * order()] = a_value;
  }
template<class T>
T inlib::sqm< T >::sub_determinant ( const std::vector< unsigned int > &  aRs,
const std::vector< unsigned int > &  aCs 
) const [inline]

Definition at line 164 of file sqm.

                                                                    {
    //WARNING : to optimize, we do not check the content of aRs, aCs.
    unsigned int ord = aRs.size();
    if(ord==0) return array<T>::zero();
    else if(ord==1) return value(aRs[0],aCs[0]);
    else if(ord==2) {
      //return (value(aRs[0],aCs[0]) * value(aRs[1],aCs[1]) -
      //        value(aRs[1],aCs[0]) * value(aRs[0],aCs[1])); 
      //Optimize the upper :

      unsigned int r_0 = aRs[0];
      unsigned int r_1 = aRs[1];
      unsigned int c_0 = aCs[0];
      unsigned int c_1 = aCs[1];

      unsigned int ord = order();
      const T* p = &(array<T>::m_vector[0]); //WARNING : dangerous.

      return ( (*(p+r_0+c_0*ord)) * (*(p+r_1+c_1*ord)) -
               (*(p+r_1+c_0*ord)) * (*(p+r_0+c_1*ord)) );
    }

    unsigned int rord = ord-1;
    std::vector<unsigned int> cs(rord);
    std::vector<unsigned int> rs(rord);

    T det = array<T>::zero();
   {for(unsigned int i=0;i<rord;i++) {cs[i] = aCs[i+1];}}
    unsigned int c = 0;
    //if(c>=1) cs[c-1] = c-1;

   {for(unsigned int i=0;i<rord;i++) {rs[i] = aRs[i+1];}}
    bool sg = true; //c=0+r=0
    for(unsigned int r=0;r<ord;r++) {
      if(r>=1) rs[r-1] = aRs[r-1];
      T subdet = sub_determinant(rs,cs);
      if(sg)
        det += value(aRs[r],aCs[c]) * subdet;
      else
        det -= value(aRs[r],aCs[c]) * subdet;
      sg = sg?false:true;
    }

    return det;
  }
template<class T>
sqm inlib::sqm< T >::symmetric_part ( ) const [inline]

Definition at line 320 of file sqm.

                             {
    sqm res(*this);
    res.transpose();
    res.add(*this);
    res.divide(array<T>::two());
    return res;
  }
template<class T>
T inlib::sqm< T >::trace ( ) const [inline]

Definition at line 65 of file sqm.

                  {
    unsigned int ord = order();
    T value = array<T>::zero();
    for(unsigned int c=0;c<ord;c++) value += array<T>::m_vector[c+c*ord];
    return value;
  }
template<class T>
void inlib::sqm< T >::transpose ( ) [inline]

Definition at line 274 of file sqm.

                   {
    unsigned int ord = order();
    for(unsigned int r=0;r<ord;r++) {
      for(unsigned int c=(r+1);c<ord;c++) {
        T vrc = value(r,c);
        T vcr = value(c,r);
        set_value_no_check(r,c,vcr);
        set_value_no_check(c,r,vrc);
      }
    }
  }
template<class T>
T inlib::sqm< T >::value ( unsigned int  aR,
unsigned int  aC 
) const [inline]

Definition at line 36 of file sqm.

                                                 { 
    //WARNING : range of aR, aC not protected.
    unsigned int ord = order();
    return array<T>::m_vector[aR + aC * ord];
  }
template<class T>
bool inlib::sqm< T >::value ( unsigned int  aR,
unsigned int  aC,
T &  a_value 
) const [inline]

Definition at line 42 of file sqm.

                                                               { 
    unsigned int ord = order();
    if((aR>=ord)||(aC>=ord)) {
      a_value = array<T>::zero();
      return false;
    }
    a_value = array<T>::m_vector[aR + aC * ord];
    return true;
  }

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