source: Sophya/trunk/SophyaLib/TArray/matharr.cc@ 787

Last change on this file since 787 was 787, checked in by ansari, 26 years ago

Introduction de BaseArray comme classe parente de TArray<T>
Separation des operations math (fonctions) ds la classe MathArr<T>

Reza 20/3/2000

File size: 2.3 KB
Line 
1// Usuall mathematical functions and operations on arrays
2// R. Ansari, C.Magneville 03/2000
3
4#include "machdefs.h"
5#include <stdlib.h>
6#include "matharr.h"
7
8// ----------------------------------------------------
9// Application d'une fonction
10// ----------------------------------------------------
11
12template <class T>
13TArray<T>& MathArray<T>::ApplyFunctionInPlace(TArray<T> & a, Arr_DoubleFunctionOfX f)
14{
15 T * pe;
16 uint_8 j,k;
17 if (a.AvgStep() > 0) { // regularly spaced elements
18 uint_8 step = a.AvgStep();
19 uint_8 maxx = a.Size()*step;
20 pe = a.Data();
21 for(k=0; k<maxx; k+=step ) pe[k] = (T)(f((double)pe[k]));
22 }
23 else { // Non regular data spacing ...
24 uint_4 ka = a.MaxSizeKA();
25 uint_8 step = a.Step(ka);
26 uint_8 gpas = a.Size(ka)*step;
27 for(j=0; j<a.Size(); j += a.Size(ka)) {
28 pe = a.DataBlock().Begin()+a.Offset(j);
29 for(k=0; k<gpas; k+=step) pe[k] = (T)(f((double)pe[k]));
30 }
31 }
32 return(a);
33}
34
35template <class T>
36TArray<T>& MathArray<T>::ApplyFunctionInPlace(TArray<T> & a, Arr_FloatFunctionOfX f)
37{
38 T * pe;
39 uint_8 j,k;
40 if (a.AvgStep() > 0) { // regularly spaced elements
41 uint_8 step = a.AvgStep();
42 uint_8 maxx = a.Size()*step;
43 pe = a.Data();
44 for(k=0; k<maxx; k+=step ) pe[k] = (T)(f((float)pe[k]));
45 }
46 else { // Non regular data spacing ...
47 uint_4 ka = a.MaxSizeKA();
48 uint_8 step = a.Step(ka);
49 uint_8 gpas = a.Size(ka)*step;
50 for(j=0; j<a.Size(); j += a.Size(ka)) {
51 pe = a.DataBlock().Begin()+a.Offset(j);
52 for(k=0; k<gpas; k+=step) pe[k] = (T)(f((float)pe[k]));
53 }
54 }
55 return(a);
56}
57
58
59template <class T>
60TArray<T> MathArray<T>::ApplyFunction(TArray<T> const & a, Arr_DoubleFunctionOfX f)
61{
62 TArray<T> ra;
63 ra = a;
64 ApplyFunctionInPlace(ra, f);
65 return(ra);
66}
67
68template <class T>
69TArray<T> MathArray<T>::ApplyFunction(TArray<T> const & a, Arr_FloatFunctionOfX f)
70{
71 TArray<T> ra;
72 ra = a;
73 ApplyFunctionInPlace(ra, f);
74 return(ra);
75}
76
77///////////////////////////////////////////////////////////////
78#ifdef __CXX_PRAGMA_TEMPLATES__
79#pragma define_template MathArray<r_4>
80#pragma define_template MathArray<r_8>
81#endif
82
83#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
84template class MathArray<r_4>;
85template class MathArray<r_8>;
86#endif
Note: See TracBrowser for help on using the repository browser.