23#define _XOPEN_SOURCE 600
43 double *data, intptr_t dstride,
44 double *coefs, intptr_t cstride);
52 bands[4*(0)+1] /= bands[4*(0)+0];
53 bands[4*(0)+2] /= bands[4*(0)+0];
54 bands[4*(0)+3] /= bands[4*(0)+0];
56 bands[4*(1)+1] -= bands[4*(1)+0]*bands[4*(0)+1];
57 bands[4*(1)+2] -= bands[4*(1)+0]*bands[4*(0)+2];
58 bands[4*(1)+3] -= bands[4*(1)+0]*bands[4*(0)+3];
60 bands[4*(1)+2] /= bands[4*(1)+1];
61 bands[4*(1)+3] /= bands[4*(1)+1];
65 for (
int row=2; row < (M+1); row++) {
66 bands[4*(row)+1] -= bands[4*(row)+0]*bands[4*(row-1)+2];
67 bands[4*(row)+3] -= bands[4*(row)+0]*bands[4*(row-1)+3];
68 bands[4*(row)+2] /= bands[4*(row)+1];
69 bands[4*(row)+3] /= bands[4*(row)+1];
70 bands[4*(row)+0] = 0.0;
71 bands[4*(row)+1] = 1.0;
75 bands[4*(M+1)+1] -= bands[4*(M+1)+0]*bands[4*(M-1)+2];
76 bands[4*(M+1)+3] -= bands[4*(M+1)+0]*bands[4*(M-1)+3];
77 bands[4*(M+1)+2] -= bands[4*(M+1)+1]*bands[4*(M)+2];
78 bands[4*(M+1)+3] -= bands[4*(M+1)+1]*bands[4*(M)+3];
79 bands[4*(M+1)+3] /= bands[4*(M+1)+2];
80 bands[4*(M+1)+2] = 1.0;
82 coefs[(M+1)*cstride] = bands[4*(M+1)+3];
84 for (
int row=M; row>0; row--)
85 coefs[row*cstride] = bands[4*(row)+3] - bands[4*(row)+2]*coefs[cstride*(row+1)];
88 coefs[0] = bands[4*(0)+3] - bands[4*(0)+1]*coefs[1*cstride] - bands[4*(0)+2]*coefs[2*cstride];
101 std::vector<float> lastCol(M);
105 bands[4*(0)+2] /= bands[4*(0)+1];
106 bands[4*(0)+0] /= bands[4*(0)+1];
107 bands[4*(0)+3] /= bands[4*(0)+1];
108 bands[4*(0)+1] = 1.0;
109 bands[4*(M-1)+1] -= bands[4*(M-1)+2]*bands[4*(0)+0];
110 bands[4*(M-1)+3] -= bands[4*(M-1)+2]*bands[4*(0)+3];
111 bands[4*(M-1)+2] = -bands[4*(M-1)+2]*bands[4*(0)+2];
112 lastCol[0] = bands[4*(0)+0];
114 for (
int row=1; row < (M-1); row++) {
115 bands[4*(row)+1] -= bands[4*(row)+0] * bands[4*(row-1)+2];
116 bands[4*(row)+3] -= bands[4*(row)+0] * bands[4*(row-1)+3];
117 lastCol[row] = -bands[4*(row)+0] * lastCol[row-1];
118 bands[4*(row)+0] = 0.0;
119 bands[4*(row)+2] /= bands[4*(row)+1];
120 bands[4*(row)+3] /= bands[4*(row)+1];
121 lastCol[row] /= bands[4*(row)+1];
122 bands[4*(row)+1] = 1.0;
124 bands[4*(M-1)+3] -= bands[4*(M-1)+2]*bands[4*(row)+3];
125 bands[4*(M-1)+1] -= bands[4*(M-1)+2]*lastCol[row];
126 bands[4*(M-1)+2] = -bands[4*(M-1)+2]*bands[4*(row)+2];
132 bands[4*(M-1)+0] += bands[4*(M-1)+2];
133 bands[4*(M-1)+1] -= bands[4*(M-1)+0] * (bands[4*(M-2)+2]+lastCol[M-2]);
134 bands[4*(M-1)+3] -= bands[4*(M-1)+0] * bands[4*(M-2)+3];
135 bands[4*(M-1)+3] /= bands[4*(M-1)+1];
136 coefs[M*cstride] = bands[4*(M-1)+3];
137 for (
int row=M-2; row>=0; row--)
138 coefs[(row+1)*cstride] =
139 bands[4*(row)+3] - bands[4*(row)+2]*coefs[(row+2)*cstride] - lastCol[row]*coefs[M*cstride];
141 coefs[0*cstride] = coefs[M*cstride];
142 coefs[(M+1)*cstride] = coefs[1*cstride];
143 coefs[(M+2)*cstride] = coefs[2*cstride];
159 bands[4*0+0] *= -1.0;
160 bands[4*(M-1)+2] *= -1.0;
162 std::vector<float> lastCol(M);
166 bands[4*(0)+2] /= bands[4*(0)+1];
167 bands[4*(0)+0] /= bands[4*(0)+1];
168 bands[4*(0)+3] /= bands[4*(0)+1];
169 bands[4*(0)+1] = 1.0;
170 bands[4*(M-1)+1] -= bands[4*(M-1)+2]*bands[4*(0)+0];
171 bands[4*(M-1)+3] -= bands[4*(M-1)+2]*bands[4*(0)+3];
172 bands[4*(M-1)+2] = -bands[4*(M-1)+2]*bands[4*(0)+2];
173 lastCol[0] = bands[4*(0)+0];
175 for (
int row=1; row < (M-1); row++) {
176 bands[4*(row)+1] -= bands[4*(row)+0] * bands[4*(row-1)+2];
177 bands[4*(row)+3] -= bands[4*(row)+0] * bands[4*(row-1)+3];
178 lastCol[row] = -bands[4*(row)+0] * lastCol[row-1];
179 bands[4*(row)+0] = 0.0;
180 bands[4*(row)+2] /= bands[4*(row)+1];
181 bands[4*(row)+3] /= bands[4*(row)+1];
182 lastCol[row] /= bands[4*(row)+1];
183 bands[4*(row)+1] = 1.0;
185 bands[4*(M-1)+3] -= bands[4*(M-1)+2]*bands[4*(row)+3];
186 bands[4*(M-1)+1] -= bands[4*(M-1)+2]*lastCol[row];
187 bands[4*(M-1)+2] = -bands[4*(M-1)+2]*bands[4*(row)+2];
193 bands[4*(M-1)+0] += bands[4*(M-1)+2];
194 bands[4*(M-1)+1] -= bands[4*(M-1)+0] * (bands[4*(M-2)+2]+lastCol[M-2]);
195 bands[4*(M-1)+3] -= bands[4*(M-1)+0] * bands[4*(M-2)+3];
196 bands[4*(M-1)+3] /= bands[4*(M-1)+1];
197 coefs[M*cstride] = bands[4*(M-1)+3];
198 for (
int row=M-2; row>=0; row--)
199 coefs[(row+1)*cstride] =
200 bands[4*(row)+3] - bands[4*(row)+2]*coefs[(row+2)*cstride] - lastCol[row]*coefs[M*cstride];
202 coefs[0*cstride] = -coefs[M*cstride];
203 coefs[(M+1)*cstride] = -coefs[1*cstride];
204 coefs[(M+2)*cstride] = -coefs[2*cstride];
215 float *data, intptr_t dstride,
216 float *coefs, intptr_t cstride)
219 double *d_data, *d_coefs;
227 d_data =
new double[N];
228 d_coefs =
new double[N];
229 for (
int i=0; i<M; i++)
230 d_data[i] = data[i*dstride];
232 for (
int i=0; i<N; i++)
233 coefs[i*cstride] = d_coefs[i];
241 float *data, intptr_t dstride,
242 float *coefs, intptr_t cstride)
245 float basis[4] = {1.0/6.0, 2.0/3.0, 1.0/6.0, 0.0};
248 float *bands =
new float[4*M];
250 for (
int i=0; i<M; i++) {
251 bands[4*i+0] = basis[0];
252 bands[4*i+1] = basis[1];
253 bands[4*i+2] = basis[2];
254 bands[4*i+3] = data[i*dstride];
267 for (
int i = 0; i < 4; i++) {
279 abcd_left[3] = bc.
lVal;
285 abcd_left[3] = bc.
lVal;
295 abcd_right[3] = bc.
rVal;
301 abcd_right[3] = bc.
rVal;
304 float *bands =
new float[4*(M+2)];
305 for (
int i=0; i<4; i++) {
306 bands[4*( 0 )+i] = abcd_left[i];
307 bands[4*(M+1)+i] = abcd_right[i];
309 for (
int i=0; i<M; i++) {
310 for (
int j=0; j<3; j++)
311 bands[4*(i+1)+j] = basis[j];
312 bands[4*(i+1)+3] = data[i*dstride];
341 spline->xBC = xBC; spline->x_grid = x_grid;
357 spline->x_grid = x_grid;
359 spline->coefs = (
float*)malloc (
sizeof(
float)*N);
395 spline->x_grid = x_grid;
401 spline->y_grid = y_grid;
402 spline->x_stride = Ny;
404 spline->coefs = (
float*)malloc (
sizeof(
float)*Nx*Ny);
410 for (
int iy=0; iy<My; iy++) {
411 intptr_t doffset = iy;
412 intptr_t coffset = iy;
414 spline->coefs+coffset, Ny);
418 for (
int ix=0; ix<Nx; ix++) {
419 intptr_t doffset = ix*Ny;
420 intptr_t coffset = ix*Ny;
421 find_coefs_1d_s (spline->y_grid, spline->yBC, spline->coefs+doffset, 1,
422 spline->coefs+coffset, 1);
441 for (
int iy=0; iy<My; iy++) {
442 intptr_t doffset = iy;
443 intptr_t coffset = iy;
445 spline->
coefs+coffset, Ny);
449 for (
int ix=0; ix<Nx; ix++) {
450 intptr_t doffset = ix*Ny;
451 intptr_t coffset = ix*Ny;
453 spline->
coefs+coffset, 1);
471 int Mx = x_grid.
num;
int My = y_grid.
num;
int Mz = z_grid.
num;
478 spline->x_grid = x_grid;
484 spline->y_grid = y_grid;
490 spline->z_grid = z_grid;
492 spline->x_stride = Ny*Nz;
493 spline->y_stride = Nz;
496 spline->coefs =
new float[Nx*Ny*Nz];
498 posix_memalign ((
void**)&spline->coefs, 16, (
sizeof(
float)*Nx*Ny*Nz));
502 for (
int iy=0; iy<My; iy++)
503 for (
int iz=0; iz<Mz; iz++) {
504 intptr_t doffset = iy*Mz+iz;
505 intptr_t coffset = iy*Nz+iz;
507 spline->coefs+coffset, Ny*Nz);
511 for (
int ix=0; ix<Nx; ix++)
512 for (
int iz=0; iz<Nz; iz++) {
513 intptr_t doffset = ix*Ny*Nz + iz;
514 intptr_t coffset = ix*Ny*Nz + iz;
516 spline->coefs+coffset, Nz);
520 for (
int ix=0; ix<Nx; ix++)
521 for (
int iy=0; iy<Ny; iy++) {
522 intptr_t doffset = (ix*Ny+iy)*Nz;
523 intptr_t coffset = (ix*Ny+iy)*Nz;
525 spline->coefs+coffset, 1);
547 for (
int iy=0; iy<My; iy++)
548 for (
int iz=0; iz<Mz; iz++) {
549 intptr_t doffset = iy*Mz+iz;
550 intptr_t coffset = iy*Nz+iz;
552 spline->
coefs+coffset, Ny*Nz);
556 for (
int ix=0; ix<Nx; ix++)
557 for (
int iz=0; iz<Nz; iz++) {
558 intptr_t doffset = ix*Ny*Nz + iz;
559 intptr_t coffset = ix*Ny*Nz + iz;
561 spline->
coefs+coffset, Nz);
565 for (
int ix=0; ix<Nx; ix++)
566 for (
int iy=0; iy<Ny; iy++) {
567 intptr_t doffset = (ix*Ny+iy)*Nz;
568 intptr_t coffset = (ix*Ny+iy)*Nz;
570 spline->
coefs+coffset, 1);
609 spline->x_grid = x_grid;
623 (
float*)data, 2, (
float*)spline->coefs, 2);
626 ((
float*)data)+1, 2, ((
float*)spline->coefs+1), 2);
644 (
float*)data, 2, (
float*)spline->
coefs, 2);
647 ((
float*)data)+1, 2, ((
float*)spline->
coefs+1), 2);
672 spline->x_grid = x_grid;
678 spline->y_grid = y_grid;
679 spline->x_stride = Ny;
682 spline->coefs = (
complex_float*)malloc (2*
sizeof(
float)*Nx*Ny);
684 posix_memalign ((
void**)&spline->coefs, 16, 2*
sizeof(
float)*Nx*Ny);
687 BCtype_s xBC_r, xBC_i, yBC_r, yBC_i;
697 for (
int iy=0; iy<My; iy++) {
698 intptr_t doffset = 2*iy;
699 intptr_t coffset = 2*iy;
702 (
float*)spline->coefs+coffset, 2*Ny);
704 find_coefs_1d_s (spline->x_grid, xBC_i, ((
float*)data)+doffset+1, 2*My,
705 ((
float*)spline->coefs)+coffset+1, 2*Ny);
709 for (
int ix=0; ix<Nx; ix++) {
710 intptr_t doffset = 2*ix*Ny;
711 intptr_t coffset = 2*ix*Ny;
713 find_coefs_1d_s (spline->y_grid, yBC_r, ((
float*)spline->coefs)+doffset, 2,
714 ((
float*)spline->coefs)+coffset, 2);
716 find_coefs_1d_s (spline->y_grid, yBC_i, ((
float*)spline->coefs)+doffset+1, 2,
717 ((
float*)spline->coefs)+coffset+1, 2);
741 BCtype_s xBC_r, xBC_i, yBC_r, yBC_i;
752 for (
int iy=0; iy<My; iy++) {
753 intptr_t doffset = 2*iy;
754 intptr_t coffset = 2*iy;
757 (
float*)spline->
coefs+coffset, 2*Ny);
760 ((
float*)spline->
coefs)+coffset+1, 2*Ny);
764 for (
int ix=0; ix<Nx; ix++) {
765 intptr_t doffset = 2*ix*Ny;
766 intptr_t coffset = 2*ix*Ny;
769 ((
float*)spline->
coefs)+coffset, 2);
772 ((
float*)spline->
coefs)+coffset+1, 2);
790 int Mx = x_grid.
num;
int My = y_grid.
num;
int Mz = z_grid.
num;
797 spline->x_grid = x_grid;
803 spline->y_grid = y_grid;
809 spline->z_grid = z_grid;
811 spline->x_stride = Ny*Nz;
812 spline->y_stride = Nz;
817 posix_memalign ((
void**)&spline->coefs, 16, 2*
sizeof(
float)*Nx*Ny*Nz);
820 BCtype_s xBC_r, xBC_i, yBC_r, yBC_i, zBC_r, zBC_i;
834 for (
int iy=0; iy<My; iy++)
835 for (
int iz=0; iz<Mz; iz++) {
836 intptr_t doffset = 2*(iy*Mz+iz);
837 intptr_t coffset = 2*(iy*Nz+iz);
839 find_coefs_1d_s (spline->x_grid, xBC_r, ((
float*)data)+doffset, 2*My*Mz,
840 ((
float*)spline->coefs)+coffset, 2*Ny*Nz);
842 find_coefs_1d_s (spline->x_grid, xBC_i, ((
float*)data)+doffset+1, 2*My*Mz,
843 ((
float*)spline->coefs)+coffset+1, 2*Ny*Nz);
847 for (
int ix=0; ix<Nx; ix++)
848 for (
int iz=0; iz<Nz; iz++) {
849 intptr_t doffset = 2*(ix*Ny*Nz + iz);
850 intptr_t coffset = 2*(ix*Ny*Nz + iz);
852 find_coefs_1d_s (spline->y_grid, yBC_r, ((
float*)spline->coefs)+doffset, 2*Nz,
853 ((
float*)spline->coefs)+coffset, 2*Nz);
855 find_coefs_1d_s (spline->y_grid, yBC_i, ((
float*)spline->coefs)+doffset+1, 2*Nz,
856 ((
float*)spline->coefs)+coffset+1, 2*Nz);
860 for (
int ix=0; ix<Nx; ix++)
861 for (
int iy=0; iy<Ny; iy++) {
862 intptr_t doffset = 2*((ix*Ny+iy)*Nz);
863 intptr_t coffset = 2*((ix*Ny+iy)*Nz);
865 find_coefs_1d_s (spline->z_grid, zBC_r, ((
float*)spline->coefs)+doffset, 2,
866 ((
float*)spline->coefs)+coffset, 2);
868 find_coefs_1d_s (spline->z_grid, zBC_i, ((
float*)spline->coefs)+doffset+1, 2,
869 ((
float*)spline->coefs)+coffset+1, 2);
892 BCtype_s xBC_r, xBC_i, yBC_r, yBC_i, zBC_r, zBC_i;
906 for (
int iy=0; iy<My; iy++)
907 for (
int iz=0; iz<Mz; iz++) {
908 intptr_t doffset = 2*(iy*Mz+iz);
909 intptr_t coffset = 2*(iy*Nz+iz);
912 ((
float*)spline->
coefs)+coffset, 2*Ny*Nz);
915 ((
float*)spline->
coefs)+coffset+1, 2*Ny*Nz);
919 for (
int ix=0; ix<Nx; ix++)
920 for (
int iz=0; iz<Nz; iz++) {
921 intptr_t doffset = 2*(ix*Ny*Nz + iz);
922 intptr_t coffset = 2*(ix*Ny*Nz + iz);
925 ((
float*)spline->
coefs)+coffset, 2*Nz);
928 ((
float*)spline->
coefs)+coffset+1, 2*Nz);
932 for (
int ix=0; ix<Nx; ix++)
933 for (
int iy=0; iy<Ny; iy++) {
934 intptr_t doffset = 2*((ix*Ny+iy)*Nz);
935 intptr_t coffset = 2*((ix*Ny+iy)*Nz);
938 ((
float*)spline->
coefs)+coffset, 2);
941 ((
float*)spline->
coefs)+coffset+1, 2);
964 bands[4*(0)+1] /= bands[4*(0)+0];
965 bands[4*(0)+2] /= bands[4*(0)+0];
966 bands[4*(0)+3] /= bands[4*(0)+0];
967 bands[4*(0)+0] = 1.0;
968 bands[4*(1)+1] -= bands[4*(1)+0]*bands[4*(0)+1];
969 bands[4*(1)+2] -= bands[4*(1)+0]*bands[4*(0)+2];
970 bands[4*(1)+3] -= bands[4*(1)+0]*bands[4*(0)+3];
971 bands[4*(0)+0] = 0.0;
972 bands[4*(1)+2] /= bands[4*(1)+1];
973 bands[4*(1)+3] /= bands[4*(1)+1];
974 bands[4*(1)+1] = 1.0;
977 for (
int row=2; row < (M+1); row++) {
978 bands[4*(row)+1] -= bands[4*(row)+0]*bands[4*(row-1)+2];
979 bands[4*(row)+3] -= bands[4*(row)+0]*bands[4*(row-1)+3];
980 bands[4*(row)+2] /= bands[4*(row)+1];
981 bands[4*(row)+3] /= bands[4*(row)+1];
982 bands[4*(row)+0] = 0.0;
983 bands[4*(row)+1] = 1.0;
987 bands[4*(M+1)+1] -= bands[4*(M+1)+0]*bands[4*(M-1)+2];
988 bands[4*(M+1)+3] -= bands[4*(M+1)+0]*bands[4*(M-1)+3];
989 bands[4*(M+1)+2] -= bands[4*(M+1)+1]*bands[4*(M)+2];
990 bands[4*(M+1)+3] -= bands[4*(M+1)+1]*bands[4*(M)+3];
991 bands[4*(M+1)+3] /= bands[4*(M+1)+2];
992 bands[4*(M+1)+2] = 1.0;
994 coefs[(M+1)*cstride] = bands[4*(M+1)+3];
996 for (
int row=M; row>0; row--)
997 coefs[row*cstride] = bands[4*(row)+3] - bands[4*(row)+2]*coefs[cstride*(row+1)];
1000 coefs[0] = bands[4*(0)+3] - bands[4*(0)+1]*coefs[1*cstride] - bands[4*(0)+2]*coefs[2*cstride];
1013 std::vector<double> lastCol(M);
1017 bands[4*(0)+2] /= bands[4*(0)+1];
1018 bands[4*(0)+0] /= bands[4*(0)+1];
1019 bands[4*(0)+3] /= bands[4*(0)+1];
1020 bands[4*(0)+1] = 1.0;
1021 bands[4*(M-1)+1] -= bands[4*(M-1)+2]*bands[4*(0)+0];
1022 bands[4*(M-1)+3] -= bands[4*(M-1)+2]*bands[4*(0)+3];
1023 bands[4*(M-1)+2] = -bands[4*(M-1)+2]*bands[4*(0)+2];
1024 lastCol[0] = bands[4*(0)+0];
1026 for (
int row=1; row < (M-1); row++) {
1027 bands[4*(row)+1] -= bands[4*(row)+0] * bands[4*(row-1)+2];
1028 bands[4*(row)+3] -= bands[4*(row)+0] * bands[4*(row-1)+3];
1029 lastCol[row] = -bands[4*(row)+0] * lastCol[row-1];
1030 bands[4*(row)+0] = 0.0;
1031 bands[4*(row)+2] /= bands[4*(row)+1];
1032 bands[4*(row)+3] /= bands[4*(row)+1];
1033 lastCol[row] /= bands[4*(row)+1];
1034 bands[4*(row)+1] = 1.0;
1036 bands[4*(M-1)+3] -= bands[4*(M-1)+2]*bands[4*(row)+3];
1037 bands[4*(M-1)+1] -= bands[4*(M-1)+2]*lastCol[row];
1038 bands[4*(M-1)+2] = -bands[4*(M-1)+2]*bands[4*(row)+2];
1044 bands[4*(M-1)+0] += bands[4*(M-1)+2];
1045 bands[4*(M-1)+1] -= bands[4*(M-1)+0] * (bands[4*(M-2)+2]+lastCol[M-2]);
1046 bands[4*(M-1)+3] -= bands[4*(M-1)+0] * bands[4*(M-2)+3];
1047 bands[4*(M-1)+3] /= bands[4*(M-1)+1];
1048 coefs[M*cstride] = bands[4*(M-1)+3];
1049 for (
int row=M-2; row>=0; row--)
1050 coefs[(row+1)*cstride] =
1051 bands[4*(row)+3] - bands[4*(row)+2]*coefs[(row+2)*cstride] - lastCol[row]*coefs[M*cstride];
1053 coefs[0*cstride] = coefs[M*cstride];
1054 coefs[(M+1)*cstride] = coefs[1*cstride];
1055 coefs[(M+2)*cstride] = coefs[2*cstride];
1068 std::vector<double> lastCol(M);
1070 bands[4*0+0] *= -1.0;
1071 bands[4*(M-1)+2] *= -1.0;
1074 bands[4*(0)+2] /= bands[4*(0)+1];
1075 bands[4*(0)+0] /= bands[4*(0)+1];
1076 bands[4*(0)+3] /= bands[4*(0)+1];
1077 bands[4*(0)+1] = 1.0;
1078 bands[4*(M-1)+1] -= bands[4*(M-1)+2]*bands[4*(0)+0];
1079 bands[4*(M-1)+3] -= bands[4*(M-1)+2]*bands[4*(0)+3];
1080 bands[4*(M-1)+2] = -bands[4*(M-1)+2]*bands[4*(0)+2];
1081 lastCol[0] = bands[4*(0)+0];
1083 for (
int row=1; row < (M-1); row++) {
1084 bands[4*(row)+1] -= bands[4*(row)+0] * bands[4*(row-1)+2];
1085 bands[4*(row)+3] -= bands[4*(row)+0] * bands[4*(row-1)+3];
1086 lastCol[row] = -bands[4*(row)+0] * lastCol[row-1];
1087 bands[4*(row)+0] = 0.0;
1088 bands[4*(row)+2] /= bands[4*(row)+1];
1089 bands[4*(row)+3] /= bands[4*(row)+1];
1090 lastCol[row] /= bands[4*(row)+1];
1091 bands[4*(row)+1] = 1.0;
1093 bands[4*(M-1)+3] -= bands[4*(M-1)+2]*bands[4*(row)+3];
1094 bands[4*(M-1)+1] -= bands[4*(M-1)+2]*lastCol[row];
1095 bands[4*(M-1)+2] = -bands[4*(M-1)+2]*bands[4*(row)+2];
1101 bands[4*(M-1)+0] += bands[4*(M-1)+2];
1102 bands[4*(M-1)+1] -= bands[4*(M-1)+0] * (bands[4*(M-2)+2]+lastCol[M-2]);
1103 bands[4*(M-1)+3] -= bands[4*(M-1)+0] * bands[4*(M-2)+3];
1104 bands[4*(M-1)+3] /= bands[4*(M-1)+1];
1105 coefs[M*cstride] = bands[4*(M-1)+3];
1106 for (
int row=M-2; row>=0; row--)
1107 coefs[(row+1)*cstride] =
1108 bands[4*(row)+3] - bands[4*(row)+2]*coefs[(row+2)*cstride] - lastCol[row]*coefs[M*cstride];
1110 coefs[0*cstride] = -coefs[M*cstride];
1111 coefs[(M+1)*cstride] = -coefs[1*cstride];
1112 coefs[(M+2)*cstride] = -coefs[2*cstride];
1119 double *data, intptr_t dstride,
1120 double *coefs, intptr_t cstride)
1123 double basis[4] = {1.0/6.0, 2.0/3.0, 1.0/6.0, 0.0};
1125#ifdef HAVE_C_VARARRAYS
1128 double *bands =
new double[4*M];
1130 for (
int i=0; i<M; i++) {
1131 bands[4*i+0] = basis[0];
1132 bands[4*i+1] = basis[1];
1133 bands[4*i+2] = basis[2];
1134 bands[4*i+3] = data[i*dstride];
1142#ifndef HAVE_C_VARARRAYS
1148 double abcd_left[4];
1149 double abcd_right[4];
1150 for (
int i = 0; i < 4; i++) {
1152 abcd_right[i] = 0.0;
1161 abcd_left[3] = bc.
lVal;
1167 abcd_left[3] = bc.
lVal;
1177 abcd_right[3] = bc.
rVal;
1183 abcd_right[3] = bc.
rVal;
1185#ifdef HAVE_C_VARARRAYS
1186 double bands[(M+2)*4];
1188 double *bands =
new double[(M+2)*4];
1190 for (
int i=0; i<4; i++) {
1191 bands[4*( 0 )+i] = abcd_left[i];
1192 bands[4*(M+1)+i] = abcd_right[i];
1194 for (
int i=0; i<M; i++) {
1195 for (
int j=0; j<3; j++)
1196 bands[4*(i+1)+j] = basis[j];
1197 bands[4*(i+1)+3] = data[i*dstride];
1201#ifndef HAVE_C_VARARRAYS
1232 spline->x_grid = x_grid;
1235 spline->coefs = (
double*)malloc (
sizeof(
double)*N);
1264 int Mx = x_grid.
num;
1265 int My = y_grid.
num;
1272 spline->x_grid = x_grid;
1278 spline->y_grid = y_grid;
1279 spline->x_stride = Ny;
1282 spline->coefs = (
double*)malloc (
sizeof(
double)*Nx*Ny);
1284 posix_memalign ((
void**)&spline->coefs, 16, (
sizeof(
double)*Nx*Ny));
1288 for (
int iy=0; iy<My; iy++) {
1289 intptr_t doffset = iy;
1290 intptr_t coffset = iy;
1292 spline->coefs+coffset, Ny);
1296 for (
int ix=0; ix<Nx; ix++) {
1297 intptr_t doffset = ix*Ny;
1298 intptr_t coffset = ix*Ny;
1300 spline->coefs+coffset, 1);
1325 for (
int iy=0; iy<My; iy++) {
1326 intptr_t doffset = iy;
1327 intptr_t coffset = iy;
1329 spline->
coefs+coffset, Ny);
1333 for (
int ix=0; ix<Nx; ix++) {
1334 intptr_t doffset = ix*Ny;
1335 intptr_t coffset = ix*Ny;
1337 spline->
coefs+coffset, 1);
1356 int Mx = x_grid.
num;
int My = y_grid.
num;
int Mz = z_grid.
num;
1363 spline->x_grid = x_grid;
1369 spline->y_grid = y_grid;
1375 spline->z_grid = z_grid;
1377 spline->x_stride = Ny*Nz;
1378 spline->y_stride = Nz;
1381 spline->coefs =
new double[Nx*Ny*Nz];
1383 posix_memalign ((
void**)&spline->coefs, 16, (
sizeof(
double)*Nx*Ny*Nz));
1387 for (
int iy=0; iy<My; iy++)
1388 for (
int iz=0; iz<Mz; iz++) {
1389 intptr_t doffset = iy*Mz+iz;
1390 intptr_t coffset = iy*Nz+iz;
1392 spline->coefs+coffset, Ny*Nz);
1396 for (
int ix=0; ix<Nx; ix++)
1397 for (
int iz=0; iz<Nz; iz++) {
1398 intptr_t doffset = ix*Ny*Nz + iz;
1399 intptr_t coffset = ix*Ny*Nz + iz;
1401 spline->coefs+coffset, Nz);
1405 for (
int ix=0; ix<Nx; ix++)
1406 for (
int iy=0; iy<Ny; iy++) {
1407 intptr_t doffset = (ix*Ny+iy)*Nz;
1408 intptr_t coffset = (ix*Ny+iy)*Nz;
1410 spline->coefs+coffset, 1);
1439 for (
int iy=0; iy<My; iy++)
1440 for (
int iz=0; iz<Mz; iz++) {
1441 intptr_t doffset = iy*Mz+iz;
1442 intptr_t coffset = iy*Nz+iz;
1444 spline->
coefs+coffset, Ny*Nz);
1448 for (
int ix=0; ix<Nx; ix++)
1449 for (
int iz=0; iz<Nz; iz++) {
1450 intptr_t doffset = ix*Ny*Nz + iz;
1451 intptr_t coffset = ix*Ny*Nz + iz;
1453 spline->
coefs+coffset, Nz);
1457 for (
int ix=0; ix<Nx; ix++)
1458 for (
int iy=0; iy<Ny; iy++) {
1459 intptr_t doffset = (ix*Ny+iy)*Nz;
1460 intptr_t coffset = (ix*Ny+iy)*Nz;
1462 spline->
coefs+coffset, 1);
1504 spline->x_grid = x_grid;
1518 (
double*)spline->coefs, 2);
1521 ((
double*)spline->coefs)+1, 2);
1545 (
double*)spline->
coefs, 2);
1548 ((
double*)spline->
coefs)+1, 2);
1565 int Mx = x_grid.
num;
1566 int My = y_grid.
num;
1575 spline->x_grid = x_grid;
1583 spline->y_grid = y_grid;
1584 spline->x_stride = Ny;
1587 spline->coefs = (
complex_double*)malloc (2*
sizeof(
double)*Nx*Ny);
1589 posix_memalign ((
void**)&spline->coefs, 16, 2*
sizeof(
double)*Nx*Ny);
1592 BCtype_d xBC_r, xBC_i, yBC_r, yBC_i;
1602 for (
int iy=0; iy<My; iy++) {
1603 intptr_t doffset = 2*iy;
1604 intptr_t coffset = 2*iy;
1606 find_coefs_1d_d (spline->x_grid, xBC_r, ((
double*)data+doffset), 2*My,
1607 (
double*)spline->coefs+coffset, 2*Ny);
1609 find_coefs_1d_d (spline->x_grid, xBC_i, ((
double*)data)+doffset+1, 2*My,
1610 ((
double*)spline->coefs)+coffset+1, 2*Ny);
1614 for (
int ix=0; ix<Nx; ix++) {
1615 intptr_t doffset = 2*ix*Ny;
1616 intptr_t coffset = 2*ix*Ny;
1618 find_coefs_1d_d (spline->y_grid, yBC_r, ((
double*)spline->coefs)+doffset, 2,
1619 (
double*)spline->coefs+coffset, 2);
1621 find_coefs_1d_d (spline->y_grid, yBC_i, (
double*)spline->coefs+doffset+1, 2,
1622 ((
double*)spline->coefs)+coffset+1, 2);
1646 BCtype_d xBC_r, xBC_i, yBC_r, yBC_i;
1657 for (
int iy=0; iy<My; iy++) {
1658 intptr_t doffset = 2*iy;
1659 intptr_t coffset = 2*iy;
1662 (
double*)spline->
coefs+coffset, 2*Ny);
1665 ((
double*)spline->
coefs)+coffset+1, 2*Ny);
1669 for (
int ix=0; ix<Nx; ix++) {
1670 intptr_t doffset = 2*ix*Ny;
1671 intptr_t coffset = 2*ix*Ny;
1674 (
double*)spline->
coefs+coffset, 2);
1677 ((
double*)spline->
coefs)+coffset+1, 2);
1697 int Mx = x_grid.
num;
int My = y_grid.
num;
int Mz = z_grid.
num;
1704 spline->x_grid = x_grid;
1710 spline->y_grid = y_grid;
1716 spline->z_grid = z_grid;
1718 spline->x_stride = Ny*Nz;
1719 spline->y_stride = Nz;
1724 posix_memalign ((
void**)&spline->coefs, 16, 2*
sizeof(
double)*Nx*Ny*Nz);
1727 BCtype_d xBC_r, xBC_i, yBC_r, yBC_i, zBC_r, zBC_i;
1741 for (
int iy=0; iy<My; iy++)
1742 for (
int iz=0; iz<Mz; iz++) {
1743 intptr_t doffset = 2*(iy*Mz+iz);
1744 intptr_t coffset = 2*(iy*Nz+iz);
1746 find_coefs_1d_d (spline->x_grid, xBC_r, ((
double*)data)+doffset, 2*My*Mz,
1747 ((
double*)spline->coefs)+coffset, 2*Ny*Nz);
1749 find_coefs_1d_d (spline->x_grid, xBC_i, ((
double*)data)+doffset+1, 2*My*Mz,
1750 ((
double*)spline->coefs)+coffset+1, 2*Ny*Nz);
1754 for (
int ix=0; ix<Nx; ix++)
1755 for (
int iz=0; iz<Nz; iz++) {
1756 intptr_t doffset = 2*(ix*Ny*Nz + iz);
1757 intptr_t coffset = 2*(ix*Ny*Nz + iz);
1759 find_coefs_1d_d (spline->y_grid, yBC_r, ((
double*)spline->coefs)+doffset, 2*Nz,
1760 ((
double*)spline->coefs)+coffset, 2*Nz);
1762 find_coefs_1d_d (spline->y_grid, yBC_i, ((
double*)spline->coefs)+doffset+1, 2*Nz,
1763 ((
double*)spline->coefs)+coffset+1, 2*Nz);
1767 for (
int ix=0; ix<Nx; ix++)
1768 for (
int iy=0; iy<Ny; iy++) {
1769 intptr_t doffset = 2*((ix*Ny+iy)*Nz);
1770 intptr_t coffset = 2*((ix*Ny+iy)*Nz);
1772 find_coefs_1d_d (spline->z_grid, zBC_r, ((
double*)spline->coefs)+doffset, 2,
1773 ((
double*)spline->coefs)+coffset, 2);
1775 find_coefs_1d_d (spline->z_grid, zBC_i, ((
double*)spline->coefs)+doffset+1, 2,
1776 ((
double*)spline->coefs)+coffset+1, 2);
1804 BCtype_d xBC_r, xBC_i, yBC_r, yBC_i, zBC_r, zBC_i;
1818 for (
int iy=0; iy<My; iy++)
1819 for (
int iz=0; iz<Mz; iz++) {
1820 intptr_t doffset = 2*(iy*Mz+iz);
1821 intptr_t coffset = 2*(iy*Nz+iz);
1824 ((
double*)spline->
coefs)+coffset, 2*Ny*Nz);
1827 ((
double*)spline->
coefs)+coffset+1, 2*Ny*Nz);
1831 for (
int ix=0; ix<Nx; ix++)
1832 for (
int iz=0; iz<Nz; iz++) {
1833 intptr_t doffset = 2*(ix*Ny*Nz + iz);
1834 intptr_t coffset = 2*(ix*Ny*Nz + iz);
1837 ((
double*)spline->
coefs)+coffset, 2*Nz);
1840 ((
double*)spline->
coefs)+coffset+1, 2*Nz);
1844 for (
int ix=0; ix<Nx; ix++)
1845 for (
int iy=0; iy<Ny; iy++) {
1846 intptr_t doffset = 2*((ix*Ny+iy)*Nz);
1847 intptr_t coffset = 2*((ix*Ny+iy)*Nz);
1850 ((
double*)spline->
coefs)+coffset, 2);
1853 ((
double*)spline->
coefs)+coffset+1, 2);
1861 free(spline->
coefs);
1882 fprintf (stderr,
"Error in destroy_Bspline: invalid spline code %d.\n",
complex float complex_float
complex double complex_double
UBspline_1d_z * create_UBspline_1d_z(Ugrid x_grid, BCtype_z xBC, complex_double *data)
void find_coefs_1d_s(Ugrid grid, BCtype_s bc, float *data, intptr_t dstride, float *coefs, intptr_t cstride)
void recompute_UBspline_1d_c(UBspline_1d_c *spline, complex_float *data)
void recompute_UBspline_3d_s(UBspline_3d_s *spline, float *data)
void recompute_UBspline_3d_d(UBspline_3d_d *spline, double *data)
void destroy_UBspline(Bspline *spline)
UBspline_2d_z * create_UBspline_2d_z(Ugrid x_grid, Ugrid y_grid, BCtype_z xBC, BCtype_z yBC, complex_double *data)
void destroy_NUBspline(Bspline *spline)
UBspline_2d_s * create_UBspline_2d_s(Ugrid x_grid, Ugrid y_grid, BCtype_s xBC, BCtype_s yBC, float *data)
void recompute_UBspline_2d_s(UBspline_2d_s *spline, float *data)
UBspline_1d_s * create_UBspline_1d_s(Ugrid x_grid, BCtype_s xBC, float *data)
void solve_periodic_interp_1d_d(double bands[], double coefs[], int M, int cstride)
UBspline_3d_c * create_UBspline_3d_c(Ugrid x_grid, Ugrid y_grid, Ugrid z_grid, BCtype_c xBC, BCtype_c yBC, BCtype_c zBC, complex_float *data)
UBspline_2d_c * create_UBspline_2d_c(Ugrid x_grid, Ugrid y_grid, BCtype_c xBC, BCtype_c yBC, complex_float *data)
void recompute_UBspline_2d_c(UBspline_2d_c *spline, complex_float *data)
void solve_deriv_interp_1d_d(double bands[], double coefs[], int M, int cstride)
void recompute_UBspline_3d_c(UBspline_3d_c *spline, complex_float *data)
void solve_deriv_interp_1d_s(float bands[], float coefs[], int M, int cstride)
void recompute_UBspline_1d_d(UBspline_1d_d *spline, double *data)
UBspline_1d_c * create_UBspline_1d_c(Ugrid x_grid, BCtype_c xBC, complex_float *data)
void recompute_UBspline_1d_s(UBspline_1d_s *spline, float *data)
void solve_periodic_interp_1d_s(float bands[], float coefs[], int M, int cstride)
void recompute_UBspline_2d_z(UBspline_2d_z *spline, complex_double *data)
void find_coefs_1d_d(Ugrid grid, BCtype_d bc, double *data, intptr_t dstride, double *coefs, intptr_t cstride)
UBspline_2d_d * create_UBspline_2d_d(Ugrid x_grid, Ugrid y_grid, BCtype_d xBC, BCtype_d yBC, double *data)
void solve_antiperiodic_interp_1d_d(double bands[], double coefs[], int M, int cstride)
void recompute_UBspline_3d_z(UBspline_3d_z *spline, complex_double *data)
UBspline_3d_d * create_UBspline_3d_d(Ugrid x_grid, Ugrid y_grid, Ugrid z_grid, BCtype_d xBC, BCtype_d yBC, BCtype_d zBC, double *data)
void recompute_UBspline_2d_d(UBspline_2d_d *spline, double *data)
UBspline_3d_s * create_UBspline_3d_s(Ugrid x_grid, Ugrid y_grid, Ugrid z_grid, BCtype_s xBC, BCtype_s yBC, BCtype_s zBC, float *data)
int posix_memalign(void **memptr, size_t alignment, size_t size)
void destroy_Bspline(void *spline)
void recompute_UBspline_1d_z(UBspline_1d_z *spline, complex_double *data)
UBspline_3d_z * create_UBspline_3d_z(Ugrid x_grid, Ugrid y_grid, Ugrid z_grid, BCtype_z xBC, BCtype_z yBC, BCtype_z zBC, complex_double *data)
void destroy_multi_UBspline(Bspline *spline)
UBspline_1d_d * create_UBspline_1d_d(Ugrid x_grid, BCtype_d xBC, double *data)
void solve_antiperiodic_interp_1d_s(float bands[], float coefs[], int M, int cstride)
complex_float *restrict coefs
complex_double *restrict coefs
complex_float *restrict coefs
complex_double *restrict coefs
complex_float *restrict coefs
complex_double *restrict coefs