Core.h

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 #pragma once
00058 #ifndef MATHCORE_CORE_H
00059 #define MATHCORE_CORE_H
00060 
00061 
00062 #include "./cimpl.h"
00063 using namespace CIMPL;
00064 
00065 
00066 #include <vector>
00067 #include <cmath>
00068 
00069 
00070 
00071 namespace MathCore
00072 {
00073 
00074 
00075 
00076         
00077         
00078         // Core functions
00079         
00080         
00081         template <class T>
00082         Vector<int> Find(Vector<T>& m);
00083         template <class T>
00084         Vector<int> Find(Matrix<T>& m);
00085         template <class T>
00086         void Find(Matrix<T>& m, Vector<int>& I, Vector<int>& J);
00087         
00088         void Ind2Sub(int rows, int cols, Vector<int>& ind, Vector<int>& I, Vector<int>& J);
00089         
00090         Vector<int> Sub2Ind(int rows, int cols, Vector<int>& I, Vector<int>& J);
00091         
00092         template <class T>
00093         Vector<T> Cross(Vector<T>& x, Vector<T>& y);
00094         template <class T>
00095         Matrix<T> Cross(Matrix<T>& x, Matrix<T>& y); 
00096         template <class T>
00097         Matrix<T> Cross(Matrix<T>& x, Matrix<T>& y, int dimension); 
00098         
00099         template <class T>
00100         Vector<T> CumSum(Vector<T>& m);
00101         template <class T>
00102         Matrix<T> CumSum(Matrix<T>& m);
00103         template <class T>
00104         Matrix<T> CumSum(Matrix<T>& m, int dimension);
00105         template <class T>
00106         Vector<T>& CumSumI(Vector<T>& m);
00107         template <class T>
00108         Matrix<T>& CumSumI(Matrix<T>& m);
00109         template <class T>
00110         Matrix<T>& CumSumI(Matrix<T>& m, int dimension);
00111 
00112         template <class T>
00113         Vector<T> CumProd(Vector<T>& m);
00114         template <class T>
00115         Matrix<T> CumProd(Matrix<T>& m);
00116         template <class T>
00117         Matrix<T> CumProd(Matrix<T>& m, int dimension);
00118         template <class T>
00119         Vector<T>& CumProdI(Vector<T>& m);
00120         template <class T>
00121         Matrix<T>& CumProdI(Matrix<T>& m);
00122         template <class T>
00123         Matrix<T>& CumProdI(Matrix<T>& m, int dimension);
00124 
00125         template <class T>
00126         Matrix<T> Diag(Vector<T>& m);
00127         template <class T>
00128         Matrix<T> Diag(Vector<T>& m, int k);
00129         template <class T>
00130         Vector<T> Diag(Matrix<T>& m);
00131         template <class T>
00132         Vector<T> Diag(Matrix<T>& m, int k);
00133 
00134         template <class T>
00135         Matrix<T> FlipLR(Matrix<T>& m);
00136         template <class T>
00137         Matrix<T>& FlipLRI(Matrix<T>& m);
00138 
00139         template <class T>
00140         Matrix<T> FlipUD(Matrix<T>& m);
00141         template <class T>
00142         Matrix<T>& FlipUDI(Matrix<T>& m);
00143 
00144         template <class T>
00145         Vector<T> Reverse(Vector<T>& m);
00146         template <class T>
00147         Vector<T>& ReverseI(Vector<T>& m);
00148 
00149         template <class T>
00150         Matrix<T> Rot90(Matrix<T>& m);
00151 
00152         template <class T>
00153         Matrix<T> Rot90(Matrix<T>& m, int k);
00154 
00155         //Kron();
00156 
00157         template <class T>
00158         Vector<T> Maximum(Matrix<T>& m);
00159         template <class T>
00160         T Maximum(Vector<T>& m);
00161         
00162         template <class T>
00163         Vector<T> Minimum(Matrix<T>& m);
00164         template <class T>
00165         T Minimum(Vector<T>& m);
00166 
00167         template <class T>
00168         Vector<double> Mean(Matrix<T>& m);
00169         template <class T>
00170         double Mean(Vector<T>& m);
00171         
00172         template <class T>
00173         inline void Swap(T& a, T& b)
00174         {
00175                 T temp = a;
00176                 a = b;
00177                 b = temp;
00178         }
00179 
00180         template <class T>
00181         Vector<T> Median(Matrix<T>& m);
00182         template <class T>
00183         T Median(Vector<T>& m);
00184 
00185         template <class T>
00186         Vector<double> Std(Matrix<T>& m);
00187         template <class T>
00188         double Std(Vector<T>& m);
00189 
00190         template <class T>
00191         Vector<double> Var(Matrix<T>& m);
00192         template <class T>
00193         double Var(Vector<T>& m);
00194 
00195 
00196         template <class T>
00197         Vector<T> Sum(Matrix<T>& m);
00198         template <class T>
00199         Vector<T> Sum(Matrix<T>& m, int dimension);
00200         template <class T>
00201         T Sum(Vector<T>& m);
00202 
00203         
00204         template <class T>
00205         Vector<T> Prod(Matrix<T>& m);
00206         template <class T>
00207         Vector<T> Prod(Matrix<T>& m, int dimension);
00208         template <class T>
00209         T Prod(Vector<T>& m);
00210 
00211         template <class T>
00212         Vector<T> Diff(Vector<T>& m);
00213         template <class T>
00214         Matrix<T> Diff(Matrix<T>& m);
00215 
00216         template <class T>
00217         Matrix<T> RepMat(Matrix<T>& m, int M, int N);
00218         
00219         template <class T>
00220         Matrix<T> Reshape(Matrix<T>& m, int M, int N);
00221         template <class T>
00222         Matrix<T> Reshape(Vector<T>& m, int M, int N);
00223         
00224         template <class T>
00225         Vector<T>& QuickSort(Vector<T>& m);
00226         
00227         template <class T>
00228         Vector<T> Sort(Vector<T>& m);
00229         template <class T>
00230         Matrix<T> Sort(Matrix<T>& m, int dimension);
00231         template <class T>
00232         Matrix<T> Sort(Matrix<T>& m);
00233         template <class T>
00234         Vector<T>& SortI(Vector<T>& m);
00235         template <class T>
00236         Matrix<T>& SortI(Matrix<T>& m, int dimension);
00237         template <class T>
00238         Matrix<T>& SortI(Matrix<T>& m);
00239         //SortRows();
00240         //
00241         //
00242         //FreqSpace();
00243         Vector<double> LinSpace(double x, double y, int N);
00244         Vector<double> LinSpace(double x, double y);
00245 
00246         Vector<double> LogSpace(double x, double y, int N);
00247         Vector<double> LogSpace(double x, double y);
00248 
00249         template <class T>
00250         void MeshGrid(Vector<T>& x, Vector<T>& y, Matrix<T>& X, Matrix<T>& Y);
00251         
00252         //template <class T>
00253         //Matrix<T>& Rand(Matrix<T>& m, T max);
00254         //template <class T>
00255         //Vector<T>& Rand(Vector<T>& m, T max);
00256 
00257         Matrix<ComplexFloat>& Rand(Matrix<ComplexFloat>& m, float max);
00258         Vector<ComplexFloat>& Rand(Vector<ComplexFloat>& m, float max);
00259 
00260         Matrix<ComplexDouble>& Rand(Matrix<ComplexDouble>& m, double max);
00261         Vector<ComplexDouble>& Rand(Vector<ComplexDouble>& m, double max);
00262 
00263         
00264         Matrix<float>& RandN(Matrix<float>& m);
00265         Vector<float>& RandN(Vector<float>& m);
00266         Matrix<double>& RandN(Matrix<double>& m);
00267         Vector<double>& RandN(Vector<double>& m);
00268         
00269         int NextPow2(int n);
00270         
00272 
00273         //Vector<float> Abs(Vector<ComplexFloat>& m);
00274         //Matrix<float> Abs(Matrix<ComplexFloat>& m);
00275         //Vector<double> Abs(Vector<ComplexDouble>& m);
00276         //Matrix<double> Abs(Matrix<ComplexDouble>& m);
00277 
00278         
00279         //Abs();
00280         //Angle();
00281 
00282         // OTHER
00283         
00284         template <class T>
00285         Vector<int> Floor(Vector<T>& m);
00286         template <class T>
00287         Matrix<int> Floor(Matrix<T>& m);
00288 
00289         template <class T>
00290         Vector<int> Ceil(Vector<T>& m);
00291         template <class T>
00292         Matrix<int> Ceil(Matrix<T>& m);
00293         
00294         template <class T>
00295         Vector<int> Fix(Vector<T>& m);
00296         template <class T>
00297         Matrix<int> Fix(Matrix<T>& m);
00298 
00299         template <class T>
00300         Vector<int> Round(Vector<T>& m);
00301         template <class T>
00302         Matrix<int> Round(Matrix<T>& m);
00303 
00304         //template <class T>
00305         //Vector<double> Mod(Vector<T>& m);
00306         //template <class T>
00307         //Matrix<double> Mod(Matrix<T>& m);
00308 
00309         //template <class T>
00310         //Vector<double> Rem(Vector<T>& m);
00311         //template <class T>
00312         //Matrix<double> Rem(Matrix<T>& m);
00313 
00314 
00315         
00316         template <class T>
00317         Vector<int> Sign(Vector<T>& m);
00318         template <class T>
00319         Matrix<int> Sign(Matrix<T>& m);
00320         
00321         template <class T>
00322         Vector<double> Gradient(Vector<T>& m);
00323         template <class T>
00324         void Gradient(Matrix<T>& m, Matrix<double>& X, Matrix<double>& Y);
00325         
00326         template <class T>
00327         Vector<double> Del2(Vector<T>& m);
00328         template <class T>
00329         Matrix<double> Del2(Matrix<T>& m);
00330 
00331         
00332         template <class T>
00333         Vector<T> CircShift(Vector<T>& m, int shift);
00334         template <class T>
00335         Matrix<T> CircShift(Matrix<T>& m, int rshift, int cshift);
00336 
00337         template <class T>
00338         Vector<T> FFTShift(Vector<T>& m);
00339         template <class T>
00340         Matrix<T> FFTShift(Matrix<T>& m);
00341         
00342 
00343         template <class T>
00344         Vector<T> IFFTShift(Vector<T>& m);
00345         template <class T>
00346         Matrix<T> IFFTShift(Matrix<T>& m);
00347 
00348 
00349         
00350         
00351         
00352         
00353         
00354         
00355         
00356         
00357 };      
00358         
00359         
00360         
00361         
00362 #include "Core.inl"
00363 
00364 
00365 
00366 
00367 
00368 
00369 
00370 
00371 
00372 
00373 #endif
00374 
00375 
00376 

Generated on Thu Jan 20 08:43:41 2005 for CIMPL by  doxygen 1.3.9.1