| 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 | |
|---|
| 20 | //Returns the cached value of the k-th basic function for an |
|---|
| 21 | //array of points given as the rows of a matrix |
|---|
| 22 | VMatrix function.v(Real k, VMatrix X) |
|---|
| 23 | { |
|---|
| 24 | SubCol(_.function,[[k]]) |
|---|
| 25 | }; |
|---|
| 26 | //Returns the cached value of the first partial derivative of k-th basic |
|---|
| 27 | //function for an array of points given as the rows of a matrix |
|---|
| 28 | VMatrix partial.derivative.1.v(Real k, VMatrix X, Real i) |
|---|
| 29 | { |
|---|
| 30 | SubCol(_.partial.derivative.1[i],[[k]]) |
|---|
| 31 | }; |
|---|
| 32 | //Returns the cached value of the second partial derivative of k-th basic |
|---|
| 33 | //function for an array of points given as the rows of a matrix |
|---|
| 34 | VMatrix partial.derivative.2.v(Real k, VMatrix X, Real i, Real j) |
|---|
| 35 | { |
|---|
| 36 | Real i_ = Max(i,j); |
|---|
| 37 | Real j_ = Min(i,j); |
|---|
| 38 | SubCol(_.partial.derivative.2[i_][j_],[[k]]) |
|---|
| 39 | }; |
|---|
| 40 | |
|---|
| 41 | //Evaluates all basic functions, one in each returned column, for an |
|---|
| 42 | //array of points given as the rows of a matrix |
|---|
| 43 | VMatrix function.m(VMatrix X) |
|---|
| 44 | { |
|---|
| 45 | _.function |
|---|
| 46 | }; |
|---|
| 47 | //Evaluates the first partial derivative of all basic functions, one in |
|---|
| 48 | //each returned column, for an array of points given as the rows of a |
|---|
| 49 | //matrix |
|---|
| 50 | VMatrix partial.derivative.1.m(VMatrix X, Real i) |
|---|
| 51 | { |
|---|
| 52 | _.partial.derivative.1[i] |
|---|
| 53 | }; |
|---|
| 54 | //Evaluates the second 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.2.m(VMatrix X, Real i, Real j) |
|---|
| 58 | { |
|---|
| 59 | Real i_ = Max(i,j); |
|---|
| 60 | Real j_ = Min(i,j); |
|---|
| 61 | _.partial.derivative.2[i_][j_] |
|---|
| 62 | }; |
|---|
| 63 | |
|---|
| 64 | //Some bases are more efficient using cache |
|---|
| 65 | Real _build.cache(VMatrix X, Real order) |
|---|
| 66 | { |
|---|
| 67 | VMatrix If(order>=0, { _.function.r := |
|---|
| 68 | _build.function.m(X) |
|---|
| 69 | }); |
|---|
| 70 | Set If(order>=1, { _.partial.derivative.1 := |
|---|
| 71 | For(1, _.n, VMatrix(Real i) |
|---|
| 72 | { _build.partial.derivative.1.m(X,i) }) |
|---|
| 73 | }); |
|---|
| 74 | Set If(order>=2, { _.partial.derivative.2 := |
|---|
| 75 | For(1, _.n, Set(Real i) |
|---|
| 76 | { |
|---|
| 77 | For(1, i, VMatrix(Real j) |
|---|
| 78 | { |
|---|
| 79 | _build.partial.derivative.2.m(X,i,j) |
|---|
| 80 | }) |
|---|
| 81 | }) |
|---|
| 82 | }); |
|---|
| 83 | True |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | }; |
|---|
| 87 | |
|---|