Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

converters.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*
00002  *                                   IT++                                    *
00003  *---------------------------------------------------------------------------*
00004  * Copyright (c) 1995-2001 by Tony Ottosson, Thomas Eriksson, Pål Frenger,   *
00005  * Tobias Ringström, and Jonas Samuelsson.                                   *
00006  *                                                                           *
00007  * Permission to use, copy, modify, and distribute this software and its     *
00008  * documentation under the terms of the GNU General Public License is hereby *
00009  * granted. No representations are made about the suitability of this        *
00010  * software for any purpose. It is provided "as is" without expressed or     *
00011  * implied warranty. See the GNU General Public License for more details.    *
00012  *---------------------------------------------------------------------------*/
00013 
00023 #ifndef _convertersh
00024 #define _convertersh
00025 
00026 #include <scalfunc.h>
00027 #include <binary.h>
00028 #include <vector.h>
00029 #include <matrix.h>
00030 namespace SPUC {
00031 //--------------- Converters for vectors ------------------
00032 
00033 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00034 
00035 template <class T>
00036 bvec to_bvec(const Vec<T> &v)
00037 {
00038     bvec temp(v.length());
00039     for (int i=0;i<v.length();i++)
00040         temp(i)=bin(v(i));
00041                 
00042     return temp;
00043 }
00044 
00045 template <class T>
00046 svec to_svec(const Vec<T> &v)
00047 {
00048     svec temp(v.length());
00049     for (int i=0;i<v.length();i++)
00050         temp(i)=short(v(i));
00051                 
00052     return temp;
00053 }
00054 
00055 template <class T>
00056 ivec to_ivec(const Vec<T> &v)
00057 {
00058     ivec temp(v.length());
00059     for (int i=0;i<v.length();i++)
00060         temp(i)=int(v(i));
00061                 
00062     return temp;
00063 }
00064 
00065 template <class T>
00066 llvec to_llvec(const Vec<T> &v)
00067 {
00068     llvec temp(v.length());
00069     for (int i=0;i<v.length();i++)
00070         temp(i)=(long_long)(v(i));
00071                 
00072     return temp;
00073 }
00074 
00075 template <class T>
00076 vec to_vec(const Vec<T> &v)
00077 {
00078     vec temp(v.length());
00079     for (int i=0;i<v.length();i++)
00080         temp(i)=double(v(i));
00081                 
00082     return temp;
00083 }
00084 
00085 template <class T>
00086 cvec to_cvec(const Vec<T> &v)
00087 {
00088     cvec temp(v.length());
00089     for (int i=0;i<v.length();i++)
00090         temp(i)=complex<double>(v(i));
00091                 
00092     return temp;
00093 }
00094 
00095 #endif //DOXYGEN_SHOULD_SKIP_THIS
00096 
00097 //--------------- Converters for matricies ------------------
00098 
00099 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00100 
00101 template <class T>
00102 bmat to_bmat(const Mat<T> &m)
00103 {
00104     bmat temp(m.rows(),m.cols());
00105 
00106     for (int i=0;i<temp.rows();i++) {
00107         for (int j=0;j<temp.cols();j++) {
00108             temp(i,j)=bin(m(i,j));
00109         }
00110     }
00111 
00112     return temp;
00113 }
00114 
00115 template <class T>
00116 smat to_smat(const Mat<T> &m)
00117 {
00118     smat temp(m.rows(),m.cols());
00119 
00120     for (int i=0;i<temp.rows();i++) {
00121         for (int j=0;j<temp.cols();j++) {
00122             temp(i,j)=short(m(i,j));
00123         }
00124     }
00125                 
00126     return temp;
00127 }
00128 
00129 template <class T>
00130 imat to_imat(const Mat<T> &m)
00131 {
00132     imat temp(m.rows(),m.cols());
00133 
00134     for (int i=0;i<temp.rows();i++) {
00135         for (int j=0;j<temp.cols();j++) {
00136             temp(i,j)=int(m(i,j));
00137         }
00138     }
00139   
00140     return temp;
00141 }
00142 
00143 template <class T>
00144 llmat to_llmat(const Mat<T> &m)
00145 {
00146     llmat temp(m.rows(),m.cols());
00147 
00148     for (int i=0;i<temp.rows();i++) {
00149         for (int j=0;j<temp.cols();j++) {
00150             temp(i,j)=(long_long)(m(i,j));
00151         }
00152     }
00153   
00154     return temp;
00155 }
00156 
00157 template <class T>
00158 mat to_mat(const Mat<T> &m)
00159 {
00160     mat temp(m.rows(),m.cols());
00161 
00162     for (int i=0;i<temp.rows();i++) {
00163         for (int j=0;j<temp.cols();j++) {
00164             temp(i,j)=double(m(i,j));
00165         }
00166     }
00167 
00168     return temp;
00169 }
00170 
00171 template <class T>
00172 cmat to_cmat(const Mat<T> &m)
00173 {
00174     cmat temp(m.rows(),m.cols());
00175 
00176     for (int i=0;i<temp.rows();i++) {
00177         for (int j=0;j<temp.cols();j++) {
00178             temp(i,j)=complex<double>(m(i,j));
00179         }
00180     }
00181           
00182     return temp;
00183 }
00184 
00185 //------------- end of converters for matricies -------------
00186 
00187 template <class T>
00188 cvec to_cvec(const Vec<T> &real, const Vec<T> &imag)
00189 {
00190     assert(real.length()==imag.length());
00191     cvec temp(real.length());
00192     for(int i=0;i<real.length();i++)
00193         temp(i)=complex<double>(real(i),imag(i));
00194                 
00195     return temp;
00196 }
00197 
00198 template <class T>
00199 cmat to_cmat(const Mat<T> &real, const Mat<T> &imag)
00200 {
00201     it_assert1(real.rows()==imag.rows() && real.cols()==imag.cols(), "to_cmat::real and imag part sizes does not match");
00202     cmat temp(real.rows(),real.cols());
00203 
00204     for (int i=0;i<temp.rows();i++) {
00205         for (int j=0;j<temp.cols();j++) {
00206             temp(i,j)=complex<double>(real(i,j), imag(i,j));
00207         }
00208     }
00209     
00210     return temp;
00211 }
00212 
00213 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
00214 int bin2dec(const bvec &inbvec, bool msb_first=0);
00215 bvec dec2bin(int length, int index);
00216 bvec dec2bin(int index, bool msb_first);
00217 void dec2bin(int index, bvec &v);
00218 bvec oct2bin(const ivec &octalindex, short keepzeros=0);
00219 ivec bin2oct(const bvec &inbits);
00220 ivec bin2pol(const bvec &inbvec);
00221 bvec pol2bin(const ivec &inpol);
00222 
00223 }
00224 #endif

Generated on Fri Sep 16 11:02:28 2005 for spuc by  doxygen 1.4.4