casadi_nd_boor_eval.hpp
1 //
2 // MIT No Attribution
3 //
4 // Copyright (C) 2010-2023 Joel Andersson, Joris Gillis, Moritz Diehl, KU Leuven.
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy of this
7 // software and associated documentation files (the "Software"), to deal in the Software
8 // without restriction, including without limitation the rights to use, copy, modify,
9 // merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
10 // permit persons to whom the Software is furnished to do so.
11 //
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
14 // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
15 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
16 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
17 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18 //
19 
20 // SYMBOL "nd_boor_eval"
21 template<typename T1>
22 void casadi_nd_boor_eval(T1* ret, casadi_int n_dims, const T1* all_knots, const casadi_int* offset, const casadi_int* all_degree, const casadi_int* strides, const T1* c, casadi_int m, const T1* all_x, const casadi_int* lookup_mode, casadi_int* iw, T1* w) { // NOLINT(whitespace/line_length)
23  casadi_int k;
24  casadi_int *boor_offset, *starts;
25  T1 *all_boor;
26 
27  boor_offset = iw; iw+=n_dims+1;
28  starts = iw; iw+=n_dims;
29 
30  all_boor = w;
31 
32  boor_offset[0] = 0;
33 
34  for (k=0;k<n_dims;++k) {
35  T1 *boor;
36  const T1* knots;
37  T1 x;
38  casadi_int degree, n_knots, n_b, L, start;
39  boor = all_boor+boor_offset[k];
40 
41  degree = all_degree[k];
42  knots = all_knots + offset[k];
43  n_knots = offset[k+1]-offset[k];
44  n_b = n_knots-degree-1;
45 
46  x = all_x[k];
47  L = casadi_low(x, knots+degree, n_knots-2*degree, lookup_mode[k]);
48 
49  start = L;
50  if (start>n_b-degree-1) start = n_b-degree-1;
51 
52  starts[k] = start;
53 
54  casadi_clear(boor, 2*degree+1);
55  if (x>=knots[0] && x<=knots[n_knots-1]) {
56  if (x==knots[1]) {
57  casadi_fill(boor, degree+1, 1.0);
58  } else if (x==knots[n_knots-1]) {
59  boor[degree] = 1;
60  } else if (knots[L+degree]==x) {
61  boor[degree-1] = 1;
62  } else {
63  boor[degree] = 1;
64  }
65  }
66  casadi_de_boor(x, knots+start, 2*degree+2, degree, boor);
67  boor+= degree+1;
68  boor_offset[k+1] = boor_offset[k] + degree+1;
69  }
70 
71  casadi_tensor_ttv(ret, n_dims-1, n_dims, all_boor, boor_offset,
72  starts, strides, c, m, 1.0, 0);
73 }