casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CExp.new3.h
Go to the documentation of this file.
1 //# CExp.cc: Implementation of CExp (tabulated complex exponential) class
2 //# Copyright (C) 1997,1998,1999,2000,2001,2002,2003
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 #if !defined(CEXP3_H)
28 #define CEXP3_H
29 
30 #include <stdlib.h>
31 #include <math.h>
32 #include <iostream>
33 #include <sstream>
34 #include <complex>
35 #include <vector>
36 #include <ctime>
37 
38 namespace casa{
39 # define PI2 6.28318530717958623
40 # define CE_TYPE float
41 
42 using namespace std;
43 
44 template <class T> class CExp3
45 {
46 public:
47  CExp3() { Size = 0; ITable=RTable=NULL; };
48  CExp3(int n) { Size = n; build(Size); };
49  ~CExp3(){if (ITable) {free(ITable);free(RTable);}}
50  inline void build(int n)
51  {
52  Size = n;
53  // ITable.resize(Size); RTable.resize(Size);
54  ITable = (T*)malloc(sizeof(T)*Size);
55  RTable = (T*)malloc(sizeof(T)*Size);
56  Step = PI2/Size;
57  for (int i=0; i<Size; i++) {
58  ITable[i] = sin(i*Step);
59  RTable[i] = cos(i*Step);
60  }
61  }
62  inline int f(register T arg)
63  {
64  return (int)((arg<0)?((arg+1-(int)arg)*Size):((arg-(int)arg)*Size));
65  // if (arg < 0) return (int)((arg+1-(int)arg)*Size); return (int)((arg-(int)arg)*Size);
66  }
67 
68  inline int hashFunction(T arg)
69  {
70  return f(arg/PI2);
71  // return (int)(fmodf(fabsf(arg+PI2),PI2)/Step);
72  }
73 
74  inline std::complex<T> operator()(T& arg)
75  {
76  int N=hashFunction(arg);
77  return std::complex<T>(RTable[N],ITable[N]);
78  }
79 
80  inline T imag(T arg) { return ITable[hashFunction(arg)]; }
81  inline T real(T arg) { return RTable[hashFunction(arg)]; }
82  inline void reim(T& arg,T& re, T&im)
83  { int N = hashFunction(arg);
84  re = RTable[N]; im = ITable[N];
85  }
86 private:
87  // vector<T> RTable, ITable;
88  T *RTable, *ITable;
89  T Step;
90  int Size;
91 };
92 };
93 #endif
LatticeExprNode arg(const LatticeExprNode &expr)
void build(int n)
Definition: CExp.new3.h:50
LatticeExprNode cos(const LatticeExprNode &expr)
T imag(T arg)
Definition: CExp.new3.h:80
T real(T arg)
Definition: CExp.new3.h:81
int hashFunction(T arg)
Definition: CExp.new3.h:68
void reim(T &arg, T &re, T &im)
Definition: CExp.new3.h:82
#define PI2
Definition: CExp.new3.h:39
CExp3(int n)
Definition: CExp.new3.h:48
uInt N
Axis number.
Definition: ArrayAccessor.h:60
free(pool)
int f(register T arg)
Definition: CExp.new3.h:62
T * RTable
vector&lt;T&gt; RTable, ITable;
Definition: CExp.new3.h:88
std::complex< T > operator()(T &arg)
Definition: CExp.new3.h:74
LatticeExprNode sin(const LatticeExprNode &expr)
Numerical 1-argument functions.