00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 #include "./CimplTypes.h"
00059
00060
00061 namespace CIMPL
00062 {
00063
00064
00065 Vector<double> ToDouble(Vector<float> &m)
00066 {
00067 int l = m.Length();
00068 Vector<double> temp(l);
00069 for(int i=0; i<l; i++)
00070 {
00071 temp[i] = (double)m[i];
00072 }
00073 return temp;
00074 }
00075
00076 Matrix<double> ToDouble(Matrix<float> &m)
00077 {
00078 int r = m.Rows();
00079 int c = m.Columns();
00080 int l = m.Length();
00081 Matrix<double> temp(r,c);
00082 for(int i=0; i<l; i++)
00083 {
00084 temp.ElemNC(i) = (double)m.ElemNC(i);
00085 }
00086 return temp;
00087 }
00088
00089
00090 Vector<ComplexFloat> ToComplexFloat(Vector<float> &m)
00091 {
00092 int l = m.Length();
00093 Vector<ComplexFloat> temp(l);
00094 for(int i=0; i<l; i++)
00095 {
00096 temp[i] = ComplexFloat(m[i],0);
00097 }
00098 return temp;
00099 }
00100
00101 Matrix<ComplexFloat> ToComplexFloat(Matrix<float> &m)
00102 {
00103 int r = m.Rows();
00104 int c = m.Columns();
00105 int l = m.Length();
00106 Matrix<ComplexFloat> temp(r,c);
00107 for(int i=0; i<l; i++)
00108 {
00109 temp.ElemNC(i) = ComplexFloat(m.ElemNC(i),0);
00110 }
00111 return temp;
00112 }
00113
00114
00115 Vector<ComplexDouble> ToComplexDouble(Vector<double> &m)
00116 {
00117 int l = m.Length();
00118 Vector<ComplexDouble> temp(l);
00119 for(int i=0; i<l; i++)
00120 {
00121 temp[i] = ComplexDouble(m[i],0);
00122 }
00123 return temp;
00124 }
00125
00126 Matrix<ComplexDouble> ToComplexDouble(Matrix<double> &m)
00127 {
00128 int r = m.Rows();
00129 int c = m.Columns();
00130 int l = m.Length();
00131 Matrix<ComplexDouble> temp(r,c);
00132 for(int i=0; i<l; i++)
00133 {
00134 temp.ElemNC(i) = ComplexDouble(m.ElemNC(i),0);
00135 }
00136 return temp;
00137 }
00138
00139 Vector<ComplexDouble> ToComplexDouble(Vector<ComplexFloat> &m)
00140 {
00141 int l = m.Length();
00142 Vector<ComplexDouble> temp(l);
00143 for(int i=0; i<l; i++)
00144 {
00145 temp[i] = (ComplexDouble)m[i];
00146 }
00147 return temp;
00148 }
00149
00150 Matrix<ComplexDouble> ToComplexDouble(Matrix<ComplexFloat> &m)
00151 {
00152 int r = m.Rows();
00153 int c = m.Columns();
00154 int l = m.Length();
00155 Matrix<ComplexDouble> temp(r,c);
00156 for(int i=0; i<l; i++)
00157 {
00158 temp.ElemNC(i) = (ComplexDouble) m.ElemNC(i);
00159 }
00160 return temp;
00161 }
00162
00163
00164
00165
00166 Vector<float> Real(Vector<ComplexFloat> &m)
00167 {
00168 int l = m.Length();
00169 Vector<float> temp(l);
00170 for(int i=0; i<l; i++)
00171 {
00172 temp[i] = real(m[i]);
00173 }
00174 return temp;
00175 }
00176
00177 Vector<float> Imag(Vector<ComplexFloat> &m)
00178 {
00179 int l = m.Length();
00180 Vector<float> temp(l);
00181 for(int i=0; i<l; i++)
00182 {
00183 temp[i] = imag(m[i]);
00184 }
00185 return temp;
00186 }
00187
00188 Matrix<float> Real(Matrix<ComplexFloat> &m)
00189 {
00190 int r = m.Rows();
00191 int c = m.Columns();
00192 int l = m.Length();
00193 Matrix<float> temp(r,c);
00194 for(int i=0; i<l; i++)
00195 {
00196 temp.ElemNC(i) = real(m.ElemNC(i));
00197 }
00198 return temp;
00199 }
00200
00201 Matrix<float> Imag(Matrix<ComplexFloat> &m)
00202 {
00203 int r = m.Rows();
00204 int c = m.Columns();
00205 int l = m.Length();
00206 Matrix<float> temp(r,c);
00207 for(int i=0; i<l; i++)
00208 {
00209 temp.ElemNC(i) = imag(m.ElemNC(i));
00210 }
00211 return temp;
00212 }
00213
00214
00215
00216
00217
00218 Vector<double> Real(Vector<ComplexDouble> &m)
00219 {
00220 int l = m.Length();
00221 Vector<double> temp(l);
00222 for(int i=0; i<l; i++)
00223 {
00224 temp[i] = real(m[i]);
00225 }
00226 return temp;
00227 }
00228
00229 Vector<double> Imag(Vector<ComplexDouble> &m)
00230 {
00231 int l = m.Length();
00232 Vector<double> temp(l);
00233 for(int i=0; i<l; i++)
00234 {
00235 temp[i] = imag(m[i]);
00236 }
00237 return temp;
00238 }
00239
00240 Matrix<double> Real(Matrix<ComplexDouble> &m)
00241 {
00242 int r = m.Rows();
00243 int c = m.Columns();
00244 int l = m.Length();
00245 Matrix<double> temp(r,c);
00246 for(int i=0; i<l; i++)
00247 {
00248 temp.ElemNC(i) = real(m.ElemNC(i));
00249 }
00250 return temp;
00251 }
00252
00253 Matrix<double> Imag(Matrix<ComplexDouble> &m)
00254 {
00255 int r = m.Rows();
00256 int c = m.Columns();
00257 int l = m.Length();
00258 Matrix<double> temp(r,c);
00259 for(int i=0; i<l; i++)
00260 {
00261 temp.ElemNC(i) = imag(m.ElemNC(i));
00262 }
00263 return temp;
00264 }
00265
00266
00267
00268
00269
00270
00271
00272 Vector<ComplexFloat> Complex(Vector<float> &real, Vector<float> &imag)
00273 {
00274 if(real.Length() != imag.Length())
00275 {
00276 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00277 Utility::RunTimeError("Dimensions does not match!");
00278 }
00279 int l = real.Length();
00280 Vector<ComplexFloat> temp(l);
00281 for(int i=0; i<l; i++)
00282 {
00283 temp[i] = ComplexFloat(real[i], imag[i]);
00284 }
00285 return temp;
00286 }
00287
00288 Vector<ComplexDouble> Complex(Vector<double> &real, Vector<double> &imag)
00289 {
00290 if(real.Length() != imag.Length())
00291 {
00292 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00293 Utility::RunTimeError("Dimensions does not match!");
00294 }
00295 int l = real.Length();
00296 Vector<ComplexDouble> temp(l);
00297 for(int i=0; i<l; i++)
00298 {
00299 temp[i] = ComplexDouble(real[i], imag[i]);
00300 }
00301 return temp;
00302 }
00303
00304 Matrix<ComplexFloat> Complex(Matrix<float> &real, Matrix<float> &imag)
00305 {
00306 if(real.Rows() != imag.Rows() || real.Columns() != imag.Columns())
00307 {
00308 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00309 Utility::RunTimeError("Dimensions does not match!");
00310 }
00311 int r = real.Rows();
00312 int c = real.Columns();
00313 int l = real.Length();
00314 Matrix<ComplexFloat> temp(r,c);
00315 for(int i=0; i<l; i++)
00316 {
00317 temp.ElemNC(i) = ComplexFloat(real.ElemNC(i), imag.ElemNC(i));
00318 }
00319 return temp;
00320 }
00321
00322 Matrix<ComplexDouble> Complex(Matrix<double> &real, Matrix<double> &imag)
00323 {
00324 if(real.Rows() != imag.Rows() || real.Columns() != imag.Columns())
00325 {
00326 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00327 Utility::RunTimeError("Dimensions does not match!");
00328 }
00329 int r = real.Rows();
00330 int c = real.Columns();
00331 int l = real.Length();
00332 Matrix<ComplexDouble> temp(r,c);
00333 for(int i=0; i<l; i++)
00334 {
00335 temp.ElemNC(i) = ComplexDouble(real.ElemNC(i), imag.ElemNC(i));
00336 }
00337 return temp;
00338 }
00339
00340
00341 Vector<ComplexFloat> Conj(Vector<ComplexFloat> &c)
00342 {
00343 Vector<ComplexFloat> copy = c.Clone();
00344 float *temp = reinterpret_cast<float*>(copy.Data());
00345 for(int i=1; i<2*copy.Length(); i+=2)
00346 {
00347 temp[i] = -temp[i];
00348 }
00349 return copy;
00350 }
00351
00352 Vector<ComplexDouble> Conj(Vector<ComplexDouble> &c)
00353 {
00354 Vector<ComplexDouble> copy = c.Clone();
00355 double *temp = reinterpret_cast<double*>(copy.Data());
00356 for(int i=1; i<2*copy.Length(); i+=2)
00357 {
00358 temp[i] = -temp[i];
00359 }
00360 return copy;
00361 }
00362
00363
00364 Matrix<ComplexFloat> Conj(Matrix<ComplexFloat> &c)
00365 {
00366 Matrix<ComplexFloat> copy = c.Clone();
00367 float *temp = reinterpret_cast<float*>(copy.Data());
00368 for(int i=1; i<2*copy.Length(); i+=2)
00369 {
00370 temp[i] = -temp[i];
00371 }
00372 return copy;
00373 }
00374
00375 Matrix<ComplexDouble> Conj(Matrix<ComplexDouble> &c)
00376 {
00377 Matrix<ComplexDouble> copy = c.Clone();
00378 double *temp = reinterpret_cast<double*>(copy.Data());
00379 for(int i=1; i<2*copy.Length(); i+=2)
00380 {
00381 temp[i] = -temp[i];
00382 }
00383 return copy;
00384 }
00385
00386
00387
00388
00389
00390 };
00391
00392
00393
00394
00395
00396
00397
00398