69 double pivot, biggest, mult, tempf;
79 for (i = 0; i < n; i++) {
82 for (j = 0; j < n; j++)
83 biggest = fmax(biggest, fabs(
lu[i][j] = a[i][j]));
93 for (k = 0; k < n - 1; k++) {
96 for (i = k; i < n; i++) {
97 if (biggest < (tempf = fabs(
lu[
ps[i]][k]) *
scales[
ps[i]])) {
104 if (pivotindex != k) {
106 ps[k] =
ps[pivotindex];
111 pivot =
lu[
ps[k]][k];
112 for (i = k + 1; i < n; i++) {
113 lu[
ps[i]][k] = mult =
lu[
ps[i]][k] / pivot;
114 for (j = k + 1; j < n; j++)
115 lu[
ps[i]][j] -= mult *
lu[
ps[k]][j];
119 if (
lu[
ps[n - 1]][n - 1] == 0.0)
141 for (i = 0; i < n; i++) {
143 for (j = 0; j < i; j++)
145 x[i] = b[
ps[i]] -
dot;
149 for (i = n - 1; i >= 0; i--) {
151 for (j = i + 1; j < n; j++)
153 x[i] = (x[i] -
dot) /
lu[
ps[i]][i];
Memory allocation wrappers that exit on failure.
static void * gv_calloc(size_t nmemb, size_t size)
void lu_solve(double *x, double *b, int n)
int lu_decompose(double **a, int n)
NEATOPROCS_API void free_array(double **rv)
NEATOPROCS_API double ** new_array(int i, int j, double val)