CimplTypes.cpp

Go to the documentation of this file.
00001 //Copyright (c) 2004-2005, Baris Sumengen
00002 //All rights reserved.
00003 //
00004 // CIMPL Matrix Performance Library
00005 //
00006 //Redistribution and use in source and binary
00007 //forms, with or without modification, are
00008 //permitted provided that the following
00009 //conditions are met:
00010 //
00011 //    * No commercial use is allowed. 
00012 //    This software can only be used
00013 //    for non-commercial purposes. This 
00014 //    distribution is mainly intended for
00015 //    academic research and teaching.
00016 //    * Redistributions of source code must
00017 //    retain the above copyright notice, this
00018 //    list of conditions and the following
00019 //    disclaimer.
00020 //    * Redistributions of binary form must
00021 //    mention the above copyright notice, this
00022 //    list of conditions and the following
00023 //    disclaimer in a clearly visible part 
00024 //    in associated product manual, 
00025 //    readme, and web site of the redistributed 
00026 //    software.
00027 //    * Redistributions in binary form must
00028 //    reproduce the above copyright notice,
00029 //    this list of conditions and the
00030 //    following disclaimer in the
00031 //    documentation and/or other materials
00032 //    provided with the distribution.
00033 //    * The name of Baris Sumengen may not be
00034 //    used to endorse or promote products
00035 //    derived from this software without
00036 //    specific prior written permission.
00037 //
00038 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
00039 //HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
00040 //EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
00041 //NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00042 //MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00043 //PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00044 //CONTRIBUTORS BE LIABLE FOR ANY
00045 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00046 //EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00047 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00048 //OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00049 //DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00050 //HOWEVER CAUSED AND ON ANY THEORY OF
00051 //LIABILITY, WHETHER IN CONTRACT, STRICT
00052 //LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00053 //OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00054 //OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00055 //POSSIBILITY OF SUCH DAMAGE.
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.