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