IT++ Logo Newcom Logo

elmatfunc.cpp

Go to the documentation of this file.
00001 
00033 #include <itpp/base/elmatfunc.h>
00034 #include <cstdlib>
00035 
00036 namespace itpp { 
00037 
00038   vec sqr(const cvec &x)
00039   {
00040     vec temp(x.length());
00041     for (int i=0; i<temp.length(); i++)
00042       temp(i) = sqr(x(i));
00043 
00044     return temp;
00045   }
00046 
00047   mat sqr(const cmat &x)
00048   {
00049     mat temp(x.rows(), x.cols());
00050     for (int i=0; i<temp.rows(); i++) {
00051       for (int j=0; j<temp.cols(); j++) {
00052         temp(i,j) = sqr(x(i,j));
00053       }
00054     }
00055 
00056     return temp;
00057   }
00058 
00059 
00060   ivec abs(const ivec &data)
00061   {
00062     ivec temp(data.length());
00063 
00064     for (int i=0;i<data.length();i++)
00065       temp[i]=std::abs(data[i]);
00066 
00067     return temp;
00068   }
00069 
00070   imat abs(const imat &data)
00071   {
00072     imat temp(data.rows(),data.cols());
00073 
00074     for (int i=0;i<temp.rows();i++) {
00075       for (int j=0;j<temp.cols();j++) {
00076         temp(i,j)=std::abs(data(i,j));
00077       }
00078     }
00079 
00080     return temp;
00081   }
00082 
00083   vec abs(const cvec &data)
00084   {
00085     vec temp(data.length());
00086 
00087     for (int i=0;i<data.length();i++)
00088       temp[i]=std::abs(data[i]);
00089 
00090     return temp;
00091   }
00092 
00093   mat abs(const cmat &data)
00094   {
00095     mat temp(data.rows(),data.cols());
00096 
00097     for (int i=0;i<temp.rows();i++) {
00098       for (int j=0;j<temp.cols();j++) {
00099         temp(i,j)=std::abs(data(i,j));
00100       }
00101     }
00102 
00103     return temp;
00104   }
00105 
00106   vec real(const cvec &data)
00107   {
00108     vec temp(data.length());
00109 
00110     for (int i=0;i<data.length();i++)
00111       temp[i]=data[i].real();
00112 
00113     return temp;
00114   }
00115 
00116   mat real(const cmat &data)
00117   {
00118     mat temp(data.rows(),data.cols());
00119 
00120     for (int i=0;i<temp.rows();i++) {
00121       for (int j=0;j<temp.cols();j++) {
00122         temp(i,j)=data(i,j).real();
00123       }
00124     }
00125 
00126     return temp;
00127   }
00128 
00129   vec imag(const cvec &data)
00130   {
00131     vec temp(data.length());
00132 
00133     for (int i=0;i<data.length();i++)
00134       temp[i]=data[i].imag();
00135     return temp;
00136   }
00137 
00138   mat imag(const cmat &data)
00139   {
00140     mat temp(data.rows(),data.cols());
00141   
00142     for (int i=0;i<temp.rows();i++) {
00143       for (int j=0;j<temp.cols();j++) {
00144         temp(i,j)=data(i,j).imag();
00145       }
00146     }
00147 
00148     return temp;
00149   }
00150 
00151   vec arg(const cvec &data)
00152   {
00153     vec temp(data.length());
00154 
00155     for (int i=0;i<data.length();i++)
00156                 temp[i]=std::arg(data[i]);
00157         
00158     return temp;
00159   }
00160 
00161   mat arg(const cmat &data)
00162   {
00163     mat temp(data.rows(),data.cols());
00164   
00165     for (int i=0;i<temp.rows();i++) {
00166       for (int j=0;j<temp.cols();j++) {
00167                   temp(i,j)=std::arg(data(i,j));
00168       }
00169     }
00170 
00171     return temp;
00172   }
00173 
00174   cvec conj(const cvec &data)
00175   {
00176     cvec        temp(data);
00177 
00178     for (int i=0;i<data.length();i++)
00179                 temp(i)=std::conj(temp[i]);
00180 
00181     return temp;
00182   }
00183 
00184   cmat conj(const cmat &data)
00185   {
00186     cmat        temp(data);
00187 
00188     for (int i=0;i<temp.rows();i++) {
00189       for (int j=0;j<temp.cols();j++) {
00190                   temp(i,j)=std::conj(data(i,j));
00191       }
00192     }
00193 
00194     return temp;
00195   }
00196 
00197   bool all(const Vec<bin> &testvec)
00198   {
00199     for (int i=0; i<testvec.length(); i++) 
00200       if (!testvec(i)) return false;
00201     return true;
00202   }
00203   
00204   bool any(const Vec<bin> &testvec)
00205   {
00206     for (int i=0; i<testvec.length(); i++) 
00207       if (testvec(i)) return true;
00208     return false;
00209   } 
00210 
00211   cvec round_to_zero(const cvec &x, double threshold) {
00212     cvec temp(x.length());
00213 
00214     for (int i = 0; i < x.length(); i++)
00215       temp(i) = round_to_zero(x(i), threshold);
00216 
00217     return temp;
00218   }
00219 
00220   cmat round_to_zero(const cmat &x, double threshold) {
00221     cmat temp(x.rows(), x.cols());
00222 
00223     for (int i = 0; i < x.rows(); i++) {
00224       for (int j = 0; j < x.cols(); j++) {
00225         temp(i, j) = round_to_zero(x(i, j), threshold);
00226       }
00227     }
00228 
00229     return temp;
00230   }
00231 
00232 } // namespace itpp
SourceForge Logo

Generated on Sat Aug 25 23:37:26 2007 for IT++ by Doxygen 1.5.2