| 1 | /* -*- mode: C++ -*- */ |
|---|
| 2 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 3 | // FILE : BaseC2.tol |
|---|
| 4 | // PURPOSE: Defines Class @BaseC2 |
|---|
| 5 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 6 | |
|---|
| 7 | Text _.autodoc.member.BaseC2.Cache = |
|---|
| 8 | "Cacheable base"; |
|---|
| 9 | |
|---|
| 10 | Class @BaseC2.Cache : @BaseC2 |
|---|
| 11 | { |
|---|
| 12 | |
|---|
| 13 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 14 | //Auxiliar members for cache |
|---|
| 15 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 16 | VMatrix _.function = Rand(0,0,0,0); |
|---|
| 17 | Set _.partial.derivative.1 = Copy(Empty); |
|---|
| 18 | Set _.partial.derivative.2 = Copy(Empty); |
|---|
| 19 | Set _.partial.integrate.1 = Copy(Empty); |
|---|
| 20 | |
|---|
| 21 | //Returns the cached value of the k-th basic function for an |
|---|
| 22 | //array of points given as the rows of a matrix |
|---|
| 23 | VMatrix function.v(Real k, VMatrix X) |
|---|
| 24 | { |
|---|
| 25 | SubCol(_.function,[[k]]) |
|---|
| 26 | }; |
|---|
| 27 | //Returns the cached value of the first partial derivative of k-th basic |
|---|
| 28 | //function for an array of points given as the rows of a matrix |
|---|
| 29 | VMatrix partial.derivative.1.v(Real k, VMatrix X, Real i) |
|---|
| 30 | { |
|---|
| 31 | SubCol(_.partial.derivative.1[i],[[k]]) |
|---|
| 32 | }; |
|---|
| 33 | //Returns the cached value of the second partial derivative of k-th basic |
|---|
| 34 | //function for an array of points given as the rows of a matrix |
|---|
| 35 | VMatrix partial.derivative.2.v(Real k, VMatrix X, Real i, Real j) |
|---|
| 36 | { |
|---|
| 37 | Real i_ = Max(i,j); |
|---|
| 38 | Real j_ = Min(i,j); |
|---|
| 39 | SubCol(_.partial.derivative.2[i_][j_],[[k]]) |
|---|
| 40 | }; |
|---|
| 41 | //Returns the cached value of the first partial integration of k-th basic |
|---|
| 42 | //function for an array of points given as the rows of a matrix |
|---|
| 43 | VMatrix partial.integrate.1.v(Real k, VMatrix X, Real i) |
|---|
| 44 | { |
|---|
| 45 | SubCol(_.partial.integrate.1[i],[[k]]) |
|---|
| 46 | }; |
|---|
| 47 | |
|---|
| 48 | //Evaluates all basic functions, one in each returned column, for an |
|---|
| 49 | //array of points given as the rows of a matrix |
|---|
| 50 | VMatrix function.m(VMatrix X) |
|---|
| 51 | { |
|---|
| 52 | _.function |
|---|
| 53 | }; |
|---|
| 54 | //Evaluates the first partial derivative of all basic functions, one in |
|---|
| 55 | //each returned column, for an array of points given as the rows of a |
|---|
| 56 | //matrix |
|---|
| 57 | VMatrix partial.derivative.1.m(VMatrix X, Real i) |
|---|
| 58 | { |
|---|
| 59 | _.partial.derivative.1[i] |
|---|
| 60 | }; |
|---|
| 61 | //Evaluates the second partial derivative of all basic functions, one in |
|---|
| 62 | //each returned column, for an array of points given as the rows of a |
|---|
| 63 | //matrix |
|---|
| 64 | VMatrix partial.derivative.2.m(VMatrix X, Real i, Real j) |
|---|
| 65 | { |
|---|
| 66 | Real i_ = Max(i,j); |
|---|
| 67 | Real j_ = Min(i,j); |
|---|
| 68 | _.partial.derivative.2[i_][j_] |
|---|
| 69 | }; |
|---|
| 70 | |
|---|
| 71 | //Evaluates the first partial integration of all basic functions, one in |
|---|
| 72 | //each returned column, for an array of points given as the rows of a |
|---|
| 73 | //matrix |
|---|
| 74 | VMatrix partial.integrate.1.m(VMatrix X, Real i) |
|---|
| 75 | { |
|---|
| 76 | _.partial.integrate.1[i] |
|---|
| 77 | }; |
|---|
| 78 | //Some bases are more efficient using cache |
|---|
| 79 | Real _build.cache(VMatrix X, Real deriv.order, Real integ.order) |
|---|
| 80 | { |
|---|
| 81 | VMatrix _.function := _build.function.m(X); |
|---|
| 82 | Set If(deriv.order>=1, { _.partial.derivative.1 := |
|---|
| 83 | For(1, _.n, VMatrix(Real i) |
|---|
| 84 | { _build.partial.derivative.1.m(X,i) }) |
|---|
| 85 | }); |
|---|
| 86 | Set If(deriv.order>=2, { _.partial.derivative.2 := |
|---|
| 87 | For(1, _.n, Set(Real i) |
|---|
| 88 | { |
|---|
| 89 | For(1, i, VMatrix(Real j) |
|---|
| 90 | { |
|---|
| 91 | _build.partial.derivative.2.m(X,i,j) |
|---|
| 92 | }) |
|---|
| 93 | }) |
|---|
| 94 | }); |
|---|
| 95 | Set If(integ.order>=1, { _.partial.integrate.1 := |
|---|
| 96 | For(1, _.n, VMatrix(Real i) |
|---|
| 97 | { _build.partial.integrate.1.m(X,i) }) |
|---|
| 98 | }); |
|---|
| 99 | True |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | }; |
|---|
| 103 | |
|---|