26 for (
int row = 0; row < M; row++)
28 for (
int col = 0; col < N; col++) printf(
"% 9.3g\t", A[row][col]);
49#pragma omp parallel for reduction(+ : mag)
51 for (i = 0; i <
L; i++) mag += a[i] * b[i];
83 const double scalar = num / deno;
89 for (i = 0; i <
L; i++) out[i] = scalar * b[i];
112 for (i = 0; i <
L; i++) out[i] = a[i] - b[i];
149 double *col_vector = (
double *)
malloc(M *
sizeof(
double));
150 double *col_vector2 = (
double *)
malloc(M *
sizeof(
double));
151 double *tmp_vector = (
double *)
malloc(M *
sizeof(
double));
152 for (
int i = 0; i < N;
160 for (j = 0; j < i; j++)
168 for (j = 0; j < M; j++)
170 tmp_vector[j] = A[j][i];
171 col_vector[j] = A[j][i];
173 for (j = 0; j < i; j++)
175 for (
int k = 0; k < M; k++) col_vector2[k] = Q[k][j];
176 vector_proj(col_vector, col_vector2, col_vector2, M);
177 vector_sub(tmp_vector, col_vector2, tmp_vector, M);
185 for (j = 0; j < M; j++) Q[j][i] = tmp_vector[j] / mag;
188 for (
int kk = 0; kk < M; kk++) col_vector[kk] = Q[kk][i];
189 for (
int k = i; k < N; k++)
191 for (
int kk = 0; kk < M; kk++) col_vector2[kk] = A[kk][k];
192 R[i][k] =
vector_dot(col_vector, col_vector2, M);
#define malloc(bytes)
This macro replace the standard malloc function with malloc_dbg.
Definition malloc_dbg.h:18
#define free(ptr)
This macro replace the standard free function with free_dbg.
Definition malloc_dbg.h:26
double * vector_proj(double *a, double *b, double *out, int L)
Compute projection of vector on defined as.
Definition qr_decompose.h:76
double vector_dot(double *a, double *b, int L)
Compute dot product of two vectors of equal lengths.
Definition qr_decompose.h:43
void qr_decompose(double **A, double **Q, double **R, int M, int N)
Decompose matrix using Gram-Schmidt process.
Definition qr_decompose.h:142
double * vector_sub(double *a, double *b, double *out, int L)
Compute vector subtraction.
Definition qr_decompose.h:101
void print_matrix(double **A, int M, int N)
function to display matrix on stdout
Definition qr_decompose.h:22
double vector_mag(double *vector, int L)
Compute magnitude of vector.
Definition qr_decompose.h:64