85static inline void _sp_nd_order(
int *
const restrict unknown_ids,
const int count,
const int *
const restrict unknown_x,
86 const int *
const restrict unknown_y,
const int reach)
94 _index_range *stack = (_index_range *)malloc(
sizeof(_index_range) * capacity);
96 stack[stack_top++] = (_index_range){ 0, count };
104 const _index_range range = stack[--stack_top];
105 const int length = range.end - range.begin;
106 if(length <= 64)
continue;
108 int xmin = INT_MAX, xmax = INT_MIN, ymin = INT_MAX, ymax = INT_MIN;
109 for(
int i = range.begin;
i < range.end;
i++)
111 const int unknown_id = unknown_ids[
i];
112 xmin =
MIN(xmin, unknown_x[unknown_id]);
113 xmax =
MAX(xmax, unknown_x[unknown_id]);
114 ymin =
MIN(ymin, unknown_y[unknown_id]);
115 ymax =
MAX(ymax, unknown_y[unknown_id]);
118 const int extent_x = xmax - xmin + 1;
119 const int extent_y = ymax - ymin + 1;
120 if(
MAX(extent_x, extent_y) <= 2 * reach + 1)
continue;
124 const int split_on_x = (extent_x >= extent_y);
125 const int *
const coord = split_on_x ? unknown_x : unknown_y;
126 const int cut_position = (split_on_x ? xmin + extent_x / 2 : ymin + extent_y / 2);
132 int left_end = range.begin;
133 int right_end = range.end;
137 const int coord_value = coord[unknown_ids[
i]];
138 if(coord_value < cut_position)
140 const int swap_id = unknown_ids[
i];
141 unknown_ids[
i] = unknown_ids[left_end];
142 unknown_ids[left_end] = swap_id;
146 else if(coord_value >= cut_position + reach)
153 const int swap_id = unknown_ids[
i];
154 unknown_ids[
i] = unknown_ids[right_end];
155 unknown_ids[right_end] = swap_id;
160 if(left_end == range.begin && right_end == range.end)
continue;
161 if(stack_top + 2 > capacity)
164 _index_range *grown = (_index_range *)realloc(stack,
sizeof(_index_range) * capacity);
168 if(left_end - range.begin > 64) stack[stack_top++] = (_index_range){ range.begin, left_end };
169 if(right_end - left_end > 64) stack[stack_top++] = (_index_range){ left_end, right_end };
268 const int *
const restrict matrix_row_index,
295 const int reach_top =
_sp_ereach(
dimension, matrix_col_ptr, matrix_row_index,
k, parent, elim_stack, mark);
296 for(
int reach_pos = reach_top; reach_pos <
dimension; reach_pos++) col_count[elim_stack[reach_pos]]++;
314 col_fill[
i] =
factor->col_ptr[
i] + 1;
326 const int reach_top =
_sp_ereach(
dimension, matrix_col_ptr, matrix_row_index,
k, parent, elim_stack, mark);
330 for(
int entry = matrix_col_ptr[
k]; entry < matrix_col_ptr[
k + 1]; entry++)
332 const int i = matrix_row_index[entry];
334 work[
i] = matrix_values[entry];
336 pivot = matrix_values[entry];
338 for(
int reach_pos = reach_top; reach_pos <
dimension; reach_pos++)
340 const int j = elim_stack[reach_pos];
344 const double multiplier = work[j] /
factor->values[
factor->col_ptr[j]];
348 for(
int entry =
factor->col_ptr[j] + 1; entry < col_fill[j]; entry++)
349 work[
factor->row_index[entry]] -=
factor->values[entry] * multiplier;
350 pivot -= multiplier * multiplier;
352 const int slot = col_fill[j]++;
354 factor->values[slot] = multiplier;
356 if(!(pivot > 0.0))
goto fail;
static int _sp_ereach(const int dimension, const int *const restrict col_ptr, const int *const restrict row_index, const int k, const int *const restrict parent, int *const restrict pattern_stack, int *const restrict mark)
static void _sp_nd_order(int *const restrict unknown_ids, const int count, const int *const restrict unknown_x, const int *const restrict unknown_y, const int reach)
static _sp_chol_t * _sp_chol_factor(const int dimension, const int *const restrict matrix_col_ptr, const int *const restrict matrix_row_index, const double *const restrict matrix_values, const dt_dev_pixelpipe_t *pipe)
static void _sp_etree(const int dimension, const int *const restrict col_ptr, const int *const restrict row_index, int *const restrict parent, int *const restrict ancestor)