17#define GAUSS_WEIGHT_SUM_TOL (1e-9)
21 double * weights,
double const dummy) {
27 double weight = 1.0 / (double)n;
28 for (
size_t i = 0; i < n; ++i) weights[i] = weight;
33 double * weights,
double const dummy) {
37 for (
size_t i = 0; i < n; ++i) {
43 for (
size_t j = 0; j < n; ++j) weights[j] = 0.0;
48 weights[i] = 1.0 / distance;
52 double inv_distance_sum = 0.0;
53 for (
size_t i = 0; i < n; ++i) inv_distance_sum += weights[i];
54 double scale = 1.0 / inv_distance_sum;
56 for (
size_t i = 0; i < n; ++i) weights[i] *= scale;
61 double * weights,
double const gauss_scale) {
69 for (
size_t i = 0; i < n; ++i) {
73 weights[i] = distance * distance;
77 double src_distances_sum = 0.0;
78 double src_distances_count = 0.5 * (double)(n * n - n);
79 for (
size_t i = 0; i < n-1; ++i)
80 for (
size_t j = i + 1; j < n; ++j)
85 "all %zu source points for target point (tgt_coord: %.3lf; %.3lf; %.3lf) "
86 "are nearly identical (src_coords[0]: %.3lf; %.3lf; %.3lf)",
87 n, tgt_coord[0], tgt_coord[1], tgt_coord[2],
88 src_coords[0][0], src_coords[0][1], src_coords[0][2]);
91 double src_distances_mean = src_distances_sum / src_distances_count;
92 double scale = -1.0 / (gauss_scale * src_distances_mean * src_distances_mean);
97 double weights_sum = 0.0;
98 for (
size_t i = 0; i < n; ++i) {
99 weights[i] = exp(scale * weights[i]);
100 weights_sum += weights[i];
112 tgt_coord, src_coords, n, weights, gauss_scale);
117 for (
size_t i = 0; i < n; ++i) weights[i] /= weights_sum;
123#ifdef YAC_LAPACK_NO_DSYTR
124 lapack_int ipiv[n+1];
127 for (
size_t i = 0; i < n+1; ++i) ipiv[i] = 0;
128 for (
size_t i = 0; i < n*n; ++i) work[i] = 0;
132 LAPACK_COL_MAJOR, (lapack_int) n, (lapack_int) n,
133 A, (lapack_int) n, ipiv),
"internal ERROR: dgetrf")
136 !LAPACKE_dgetri_work(
137 LAPACK_COL_MAJOR, (lapack_int) n, A, (lapack_int) n,
138 ipiv, work, (lapack_int) (n * n)),
"internal ERROR: dgetri")
144 !LAPACKE_dsytrf_work(
145 LAPACK_COL_MAJOR,
'L', (lapack_int) n , A,
146 (lapack_int) n, ipiv, work, (lapack_int) n),
"internal ERROR: dsytrf")
149 !LAPACKE_dsytri_work(
150 LAPACK_COL_MAJOR,
'L', (lapack_int) n , A,
151 (lapack_int) n, ipiv, work),
"internal ERROR: dsytri")
153 for (
size_t i = 0; i < n; ++i)
154 for (
size_t j = i + 1; j < n; ++j)
161 double * weights,
double const rbf_scale) {
166 double sum_d = 0.0, scale_d = 1.0;
169 for (
size_t i = 0; i < n; ++i) A[i][i] = 0.0;
170 for (
size_t i = 0; i < n - 1; ++i) {
171 for (
size_t j = i + 1; j < n; ++j) {
181 scale_d = ((double)((n - 1) * n)) / (2.0 * sum_d);
182 scale_d /= rbf_scale;
184 double sq_scale_d = scale_d * scale_d;
189 for (
size_t i = 0; i < n; ++i) {
190 for (
size_t j = 0; j < n; ++j) {
193 A[i][j] = exp(-1.0 * d * d * sq_scale_d);
208 for (
size_t i = 0; i < n; ++i) {
211 a[i] = exp(-1.0 * d * d * sq_scale_d);
216 for (
size_t i = 0; i < n; ++i) {
218 for (
size_t j = 0; j < n; ++j) weights[i] += A[i][j] * a[j];
#define YAC_ASSERT(exp, msg)
static double get_vector_angle(double const a[3], double const b[3])
void yac_interp_compute_weights_gauss(double tgt_coord[3], yac_const_coordinate_pointer src_coords, size_t const n, double *weights, double const gauss_scale)
#define GAUSS_WEIGHT_SUM_TOL
void yac_interp_compute_weights_avg(double tgt_coord[3], yac_const_coordinate_pointer src_coords, size_t const n, double *weights, double const dummy)
void yac_interp_compute_weights_dist(double tgt_coord[3], yac_const_coordinate_pointer src_coords, size_t const n, double *weights, double const dummy)
void yac_interp_compute_weights_rbf(double tgt_coord[3], yac_const_coordinate_pointer src_coords, size_t const n, double *weights, double const rbf_scale)
static void inverse(double *A, size_t n)
#define YAC_ASSERT_F(exp, format,...)
double const (* yac_const_coordinate_pointer)[3]