26#ifndef DT_MATH_CHOLESKI_H
27#define DT_MATH_CHOLESKI_H
30#include <glib/gi18n.h>
98 float *
const restrict
L,
size_t n)
104 if(
A[0] <= 0.0f)
return 0;
106 for(
size_t i = 0;
i <
n;
i++)
107 for(
size_t j = 0; j < (
i + 1); j++)
111 for(
size_t k = 0;
k < j;
k++)
112 sum +=
L[
i *
n +
k] *
L[j *
n +
k];
114 L[
i *
n + j] = (
i == j) ?
115 sqrtf(
A[
i *
n +
i] - sum) :
116 (
A[
i *
n + j] - sum) /
L[j *
n + j];
124 float *
const restrict
L,
size_t n)
129 if(
A[0] <= 0.0f)
return 0;
133 for(
size_t i = 0;
i <
n;
i++)
134 for(
size_t j = 0; j < (
i + 1); j++)
138 for(
size_t k = 0;
k < j;
k++)
139 sum +=
L[
i *
n +
k] *
L[j *
n +
k];
143 const float temp =
A[
i *
n +
i] - sum;
151 L[
i *
n + j] = sqrtf(
A[
i *
n +
i] - sum);
155 const float temp =
L[j *
n + j];
163 L[
i *
n + j] = (
A[
i *
n + j] - sum) / temp;
172 const float *
const restrict y,
float *
const restrict b,
178 for(
size_t i = 0;
i <
n; ++
i)
181 for(
size_t j = 0; j <
i; ++j)
182 sum -=
L[
i *
n + j] * b[j];
184 b[
i] = sum /
L[
i *
n +
i];
192 const float *
const restrict y,
float *
const restrict b,
200 for(
size_t i = 0;
i <
n; ++
i)
203 for(
size_t j = 0; j <
i; ++j)
204 sum -=
L[
i *
n + j] * b[j];
206 const float temp =
L[
i *
n +
i];
222 const float *
const restrict b,
float *
const restrict
x,
228 for(
int i = (
n - 1);
i > -1 ; --
i)
231 for(
int j = (
n - 1); j >
i; --j)
232 sum -=
L[j *
n +
i] *
x[j];
234 x[
i] = sum /
L[
i *
n +
i];
242 const float *
const restrict b,
float *
const restrict
x,
250 for(
int i = (
n - 1);
i > -1 ; --
i)
253 for(
int j = (
n - 1); j >
i; --j)
254 sum -=
L[j *
n +
i] *
x[j];
256 const float temp =
L[
i *
n +
i];
271 float *
const restrict y,
272 const size_t n,
const int checks)
297 " x %" G_GSIZE_FORMAT
" decomposition\n",
n,
n);
306 const char *failed_stage = NULL;
311 if(!valid) failed_stage =
"decomposition";
318 if(!valid) failed_stage =
"LU triangular descent";
326 if(!valid) failed_stage =
"LU triangular ascent";
340 " x %" G_GSIZE_FORMAT
" matrix: not positive-definite\n",
356 float *
const restrict A_square,
357 const size_t m,
const size_t n)
362 for(
size_t i = 0;
i <
n; ++
i)
363 for(
size_t j = 0; j < (
i + 1); ++j)
366 for(
size_t k = 0;
k <
m; ++
k)
367 sum +=
A[
k *
n +
i] *
A[
k *
n + j];
369 A_square[
i *
n + j] = sum;
377 float *
const restrict y,
378 float *
const restrict y_square,
379 const size_t m,
const size_t n)
383 for(
size_t i = 0;
i <
n; ++
i)
386 for(
size_t k = 0;
k <
m; ++
k)
387 sum +=
A[
k *
n +
i] * y[
k];
397 float *
const restrict y,
398 const size_t m,
const size_t n,
const int checks)
408 fprintf(stdout,
"Pseudo solve: cannot cast %" G_GSIZE_FORMAT
" \303\227 %" G_GSIZE_FORMAT
" matrice\n",
m,
n);
418 " x %" G_GSIZE_FORMAT
" pseudo-solve\n",
n,
n);
424 #pragma omp parallel sections
static void error(char *msg)
static int transpose_dot_vector(float *const restrict A, float *const restrict y, float *const restrict y_square, const size_t m, const size_t n)
static int transpose_dot_matrix(float *const restrict A, float *const restrict A_square, const size_t m, const size_t n)
static int choleski_decompose_safe(const float *const restrict A, float *const restrict L, size_t n)
static int solve_hermitian(const float *const restrict A, float *const restrict y, const size_t n, const int checks)
static int pseudo_solve(float *const restrict A, float *const restrict y, const size_t m, const size_t n, const int checks)
static int choleski_decompose_fast(const float *const restrict A, float *const restrict L, size_t n)
static int triangular_ascent_safe(const float *const restrict L, const float *const restrict b, float *const restrict x, const size_t n)
static int triangular_ascent_fast(const float *const restrict L, const float *const restrict b, float *const restrict x, const size_t n)
static int triangular_descent_fast(const float *const restrict L, const float *const restrict y, float *const restrict b, const size_t n)
static int triangular_descent_safe(const float *const restrict L, const float *const restrict y, float *const restrict b, const size_t n)
static __DT_CLONE_TARGETS__ void dt_simd_memcpy(const float *const __restrict__ in, float *const __restrict__ out, const size_t num_elem)
void dt_print(dt_debug_thread_t thread, const char *msg,...) __attribute__((format(printf
Print to stdout when thread is enabled, prefixed with seconds since startup.
float *const restrict const size_t k
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
#define dt_free_align(ptr)
Release memory from dt_alloc_align() and set ptr to NULL.
static float * dt_alloc_align_float(size_t pixels)
Allocate pixels floats, cacheline-aligned and marked as such.
#define dt_omp_in_parallel()