1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
|
//# tMathFunc.cc: This program tests MathFunc objects
//# Copyright (C) 1993,1994,1995,1997,1998,1999,2000,2001
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This program is free software; you can redistribute it and/or modify it
//# under the terms of the GNU General Public License as published by the Free
//# Software Foundation; either version 2 of the License, or (at your option)
//# any later version.
//#
//# This program is distributed in the hope that it will be useful, but WITHOUT
//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
//# more details.
//#
//# You should have received a copy of the GNU General Public License along
//# with this program; if not, write to the Free Software Foundation, Inc.,
//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
//#
//# Correspondence concerning AIPS++ should be addressed as follows:
//# Internet email: casa-feedback@nrao.edu.
//# Postal address: AIPS++ Project Office
//# National Radio Astronomy Observatory
//# 520 Edgemont Road
//# Charlottesville, VA 22903-2475 USA
//# Includes
#include <casacore/casa/BasicMath/Math.h>
#include <casacore/casa/iostream.h>
#include <casacore/casa/BasicSL/Constants.h>
#include <casacore/casa/Exceptions/Error.h>
#include <casacore/scimath/Mathematics/MathFunc.h>
#include <casacore/casa/Utilities/Assert.h>
#include <casacore/casa/namespace.h>
int main()
{
try{
cout << "\nMathFunc<Float> constants : " << endl;
cout << "defcutoff() : " << MathFunc<Float>::defcutoff() << endl;
cout << "defwidth() : " << MathFunc<Float>::defwidth() << endl;
cout << "defKBwidth() : " << MathFunc<Float>::defKBwidth() << endl;
cout << "defKBparm() : " << MathFunc<Float>::defKBparm() << endl;
cout << "defmodKBparm() : " << MathFunc<Float>::defmodKBparm() << endl;
cout << "defSphcutoff() : " << MathFunc<Float>::defSphcutoff() << endl;
cout << "defSincparm() : " << MathFunc<Float>::defSincparm() << endl;
cout << "defSphparm() : " << MathFunc<Float>::defSphparm() << endl;
cout << "defExpPower() : " << MathFunc<Float>::defExpPower() << endl;
cout << "defExpScale() : " << MathFunc<Float>::defExpScale() << endl;
MathFunc<float> hh(new GaussianConv<float>());
cout << "\ncreate a Gaussian hh by means of call to new GaussianConv\n";
cout << " hh.sup_value() = " << hh.sup_value() << endl;
cout << "\nGaussian computation\n";
Float tmp[5] = {1, 0.193867, 0.00141258, 3.86835e-07, 3.9815e-12};
for(int k = 0; k <5; k++)
{
float result = hh.value((float) k);
AlwaysAssertExit(abs(result-tmp[k]) < 1.e-5);
cout << result <<"\n";
}
cout << " " <<"\n";
MathFunc<float> *p1;
MathFunc<float> *p2;
p1= MathFunc<float>::newMathFunc(GaussianConv<float>());
cout << "\ncreate a Gaussian pointed to by p1 by call to newMathFunc\n";
cout << " p1->sup_value() = " << p1->sup_value() << endl;
int j;
for(j = 0; j <5; j++)
{
float result = p1->value( (float) j);
AlwaysAssertExit(abs(result-tmp[j]) < 1.e-5);
cout << result <<"\n";
}
cout << " " <<"\n";
p2= MathFunc<float>::newMathFunc(Mod_KB_Conv<float>());
cout << "\na Mod Kaiser Bessel pointed to by p2 by call to newMathFunc\n";
cout << " p2->sup_value() = " << p2->sup_value() << endl;
cout << "\nMod_KB \n";
Float tmp1[5] = {1,0.315995,0.00662331,0.0268752,0.0072334};
for(j = 0; j <5; j++)
{
float result = p2->value((float) j);
AlwaysAssertExit(abs(result-tmp1[j]) < 1.e-5);
cout << result <<"\n";
}
cout << " " <<"\n";
MathFunc<float> a(MOD_KB);
MathFunc<float> aa(MOD_KB);
MathFunc<float> c(GAUSSIAN);
MathFunc<float> cc(GAUSSIAN);
MathFunc<float> d(SPHEROIDAL);
MathFunc<float> dd(SPHEROIDAL);
MathFunc<float> ee(GAUSSIAN, 2.0, 1.4);
MathFunc<float> ff(GAUSSIAN, 2.1, 1.3);
MathFunc<float> gg(MOD_KB, 2.1, 1.3,2.5,3.0);
MathFunc<float> *p;
p = &aa;
aa = a;
cc = c;
dd = d;
cout << " Gaussian ee should have support width 2 " << endl;
cout << " ee.sup_value() = " << ee.sup_value() << endl;
cout << "\nGaussian computation\n";
Float tmp2[5] = {1,0.243026,0.00348829,2.95718e-06,1.48064e-10};
for(j = 0; j <5; j++)
{
float result = ee.value((float) j);
AlwaysAssertExit(abs(result-tmp2[j]) < 1.e-5);
cout << result <<"\n";
}
cout << endl << endl;
cout << " Gaussian ff should have support width 2.1 " << endl;
cout << " ff.value(0.0) = " << ff.value(0.0) << endl;
cout << " ff.sup_value() = " << ff.sup_value() << endl;
cout << "\nGaussian computation (ff)\n";
Float tmp3[5] = {
1,
0.193867,
0.00141258,
3.86835e-07,
3.9815e-12};
for(j = 0; j <5; j++)
{
float result = ff.value((float) j);
AlwaysAssertExit(abs(result-tmp3[j]) < 1.e-5);
cout << result <<"\n";
}
cout << endl << endl;
cout << " Modified Kaiser Bessel gg should have support width 2.1 " << endl;
cout << " gg.value(0.0) = " << gg.value(0.0) << endl;
cout << " gg.sup_value() = " << gg.sup_value() << endl;
cout << "Modified Kaiser-Bessel computation(gg) \n";
Float tmp4[5] = {1,
0.0807079,
0.142924,
0.0458648,
0.000233285};
for(j = 0; j <5; j++)
{
float result = gg.value((float) j);
AlwaysAssertExit(abs(result-tmp4[j]) < 1.e-5);
cout << result <<"\n";
}
cout << endl << endl << endl;
cout << " aa.value(0.0) = " << aa.value(0.0) << endl;
cout << " p->value(0.0) = " << p->value(0.0) << endl;
cout << " aa.sup_value() = " << aa.sup_value() << endl;
cout << " cc.sup_value() = " << cc.sup_value() << endl;
cout << " dd.sup_value() = " << dd.sup_value() << endl;
cout << endl;
cout << "Modified Kaiser-Bessel computation\n";
Float tmp5[5] = {
1,
0.315995,
0.00662331,
0.0268752,
0.0072334};
int i;
for(i = 0; i <5; i++)
{
float result = aa.value((float) i);
AlwaysAssertExit(abs(result-tmp5[i]) < 1.e-5);
cout << result <<"\n";
}
Float tmp6[5] = {
1,
0.193867,
0.00141258,
3.86835e-07,
3.9815e-12};
cout << "\nGaussian computation\n";
for(i = 0; i <5; i++)
{
float result = cc.value((float) i);
AlwaysAssertExit(abs(result-tmp6[i]) < 1.e-5);
cout << result <<"\n";
}
Float tmp7[4] = {
1,
0.573245,
0.0826234,
0};
cout << "\nSpheroidal computation\n";
for(i = 0; i <4; i++)
{
float result = dd.value((float) i);
AlwaysAssertExit(abs(result-tmp7[i]) < 1.e-5);
cout << result <<"\n";
}
cout << endl << "Unary function:" <<endl;
MathFunc<float> foo(UNARY);
for(i = 0; i <4; i++)
{
float result = foo.value((float) i);
AlwaysAssertExit(abs(result-1.0) < 1.e-5);
cout << result <<"\n";
}
cout << "\nExponential*Sinc computation\n";
MathFunc<float> expsinc(EXP_SINC, 3.0, 1.2, 3.0, 2.0);
cout << " expsinc.sup_value() = " << expsinc.sup_value() << endl;
Float tmp8[4] =
{1,
0.170902,
-0.10605,
0.0468399};
for (i = 0; i<4; i++)
{
float result = expsinc.value((float) i);
AlwaysAssertExit(abs(result-tmp8[i]) < 1.e-5);
cout << result << "\n";
}
delete p1;
delete p2;
} catch(std::exception& x) {
cout << "Unexpected exception: " << x.what() << endl;
return 1;
}
cout << "OK" << endl;
return 0;
}
/*
This program should produce output similar to the following:
create a Gaussian hh by means of call to new GaussianConv
hh.sup_value() = 2
Gaussian computation
1
0.193867
0.00141258
3.86835e-07
3.9815e-12
create a Gaussian pointed to by p1 by call to newMathFunc
p1->sup_value() = 2
1
0.193867
0.00141258
3.86835e-07
3.9815e-12
a Mod Kaiser Bessel pointed to by p2 by call to newMathFunc
p2->sup_value() = 2
Mod_KB
1
0.315995
0.00662331
0.0268752
0.0072334
Gaussian ee should have support width 2
ee.sup_value() = 2
Gaussian computation
1
0.243026
0.00348829
2.95718e-06
1.48064e-10
Gaussian ff should have support width 2.1
ff.value(0.0) = 1
ff.sup_value() = 2.1
Gaussian computation (ff)
1
0.193867
0.00141258
3.86835e-07
3.9815e-12
Modified Kaiser Bessel gg should have support width 2.1
gg.value(0.0) = 1
gg.sup_value() = 2.1
Modified Kaiser-Bessel computation(gg)
1
0.0807079
0.142924
0.0458648
0.000233285
aa.value(0.0) = 1
p->value(0.0) = 1
aa.sup_value() = 2
cc.sup_value() = 2
dd.sup_value() = 3
Modified Kaiser-Bessel computation
1
0.315995
0.00662331
0.0268752
0.0072334
Gaussian computation
1
0.193867
0.00141258
3.86835e-07
3.9815e-12
Spheroidal computation
1
0.573245
0.0826234
0
Unary function:
1
1
1
1
Exponential*Sinc computation
expsinc.sup_value() = 3
1
0.170902
-0.10605
0.0468399
*/
|