25 double *tmp_vec =
gv_calloc(n,
sizeof(
double));
26 double *last_vec =
gv_calloc(n,
sizeof(
double));
34 int Max_iterations = 30 * n;
42 for (i = 0; i < neigs; i++) {
43 curr_vector = eigs[i];
46 for (j = 0; j < n; j++)
47 curr_vector[j] = rand() % 100;
49 for (j = 0; j < i; j++) {
69 for (j = 0; j < i; j++) {
74 if (len < 1e-10 || iteration > Max_iterations) {
81 }
while (fabs(angle) <
tol);
82 evals[i] = angle *
len;
87 for (; i < neigs; i++) {
91 curr_vector = eigs[i];
93 for (j = 0; j < n; j++)
94 curr_vector[j] = rand() % 100;
96 for (j = 0; j < i; j++) {
100 len =
norm(curr_vector, n - 1);
107 for (i = 0; i < neigs - 1; i++) {
109 largest_eval = evals[largest_index];
110 for (j = i + 1; j < neigs; j++) {
111 if (largest_eval < evals[j]) {
113 largest_eval = evals[largest_index];
116 if (largest_index != i) {
121 evals[largest_index] = evals[i];
122 evals[i] = largest_eval;
129 return (iteration <= Max_iterations);
140 float *storage =
gv_calloc(dim1 * dim3,
sizeof(
A[0]));
143 for (i = 0; i < dim1; i++) {
148 for (i = 0; i < dim1; i++) {
149 for (j = 0; j < dim3; j++) {
151 for (k = 0; k < dim2; k++) {
152 sum +=
A[i][k] *
B[k][j];
154 C[i][j] = (float) (sum);
168 double *storage =
gv_calloc(dim1 * dim3,
sizeof(
double));
171 for (i = 0; i < dim1; i++) {
176 for (i = 0; i < dim1; i++) {
177 for (j = 0; j < dim3; j++) {
179 for (k = 0; k < dim2; k++) {
180 sum +=
A[i][k] *
B[k][j];
189 int dim2,
float ***
CC)
197 float *storage =
gv_calloc(dim1 * dim2,
sizeof(
A[0]));
200 for (i = 0; i < dim1; i++) {
205 for (i = 0; i < dim1; i++) {
208 const size_t nedges =
A[i].nedges;
209 for (j = 0; j < dim2; j++) {
211 for (
size_t k = 0; k <
nedges; k++) {
212 sum += ewgts[k] *
B[j][edges[k]];
214 C[i][j] = (float) (sum);
220void scadd(
double *vec1,
int end,
double fac,
double *vec2) {
223 for (i = end + 1; i; i--) {
224 (*vec1++) += fac * (*vec2++);
229double norm(
double *vec,
int end) {
242 for (i = n; i; i--) {
247 for (i = n; i; i--) {
259 for (i = 0; i < n; i++)
260 vec[i] = rand() %
RANGE;
272 for (i = 0; i < n; i++) {
274 for (
size_t j = 0; j < matrix[i].
nedges; j++)
275 res += matrix[i].ewgts[j] * vector[matrix[i].edges[j]];
287 for (i = 0; i < n; i++) {
289 for (j = 0; j < n; j++)
290 res += matrix[i][j] * vector[j];
300 for (i = 0; i < n; i++) {
301 result[i] = vector1[i] - vector2[i];
309 for (i = 0; i < n; i++) {
310 result[i] = vector1[i] + vector2[i];
317 for (i = 0; i < n; i++) {
318 result[i] = vector[i] *
alpha;
324 for (i = 0; i < n; i++)
329 const double *vector2) {
332 for (i = 0; i < n; i++) {
333 result += vector1[i] * vector2[i];
341 double max_val = -1e50;
343 for (i = 0; i < n; i++)
344 max_val = fmax(max_val, fabs(vector[i]));
352 double *vector,
double *result)
359 for (i = 0; i < dim1; i++) {
361 for (j = 0; j < dim2; j++)
362 res += matrix[j][i] * vector[j];
370 double *vector,
double *result)
377 for (i = 0; i < dim1; i++) {
379 for (j = 0; j < dim2; j++)
380 res += matrix[i][j] * vector[j];
398 for (i = n; i; i--) {
403 for (i = n; i; i--) {
409 (
float *packed_matrix,
int n,
float *vector,
float *result) {
415 for (i = 0; i < n; i++) {
418 for (index = 0, i = 0; i < n; i++) {
420 vector_i = vector[i];
422 res += packed_matrix[index++] * vector_i;
424 for (j = i + 1; j < n; j++, index++) {
425 res += packed_matrix[index] * vector[j];
426 result[j] += packed_matrix[index] * vector_i;
436 for (i = 0; i < n; i++) {
437 result[i] = vector1[i] - vector2[i];
445 for (i = 0; i < n; i++) {
446 result[i] = vector1[i] + vector2[i];
454 for (i = 0; i < n; i++) {
455 vector1[i] = vector1[i] +
alpha * vector2[i];
462 for (i = 0; i < n; i++)
470 for (i = 0; i < n; i++) {
471 result += vector1[i] * vector2[i];
480 for (i = 0; i < n; i++)
487 for (i = 0; i < n; i++)
494 float max_val = -1e30f;
495 for (i = 0; i < n; i++)
496 max_val = fmaxf(max_val, fabsf(vector[i]));
504 for (i = 0; i < n; i++) {
512 for (i = 0; i < n; i++) {
514 vec[i] = 1.0f / vec[i];
522 for (i = 0; i < n; i++) {
523 if (source[i] >= 0.0) {
524 target[i] = sqrtf(source[i]);
532 for (i = 0; i < n; i++) {
534 vec[i] = 1.0f / sqrtf(vec[i]);
Memory allocation wrappers that exit on failure.
static void * gv_calloc(size_t nmemb, size_t size)
static double len(glCompPoint p)
double vectors_inner_product(int n, const double *vector1, const double *vector2)
void orthog1f(int n, float *vec)
bool power_iteration(double **square_mat, int n, int neigs, double **eigs, double *evals)
void right_mult_with_vector_transpose(double **matrix, int dim1, int dim2, double *vector, double *result)
void init_vec_orth1(int n, double *vec)
void right_mult_with_vector(vtx_data *matrix, int n, double *vector, double *result)
void invert_vec(int n, float *vec)
void right_mult_with_vector_f(float **matrix, int n, double *vector, double *result)
static double p_iteration_threshold
void right_mult_with_vector_d(double **matrix, int dim1, int dim2, double *vector, double *result)
void mult_sparse_dense_mat_transpose(vtx_data *A, double **B, int dim1, int dim2, float ***CC)
void invert_sqrt_vec(int n, float *vec)
double max_absf(int n, float *vector)
void vectors_additionf(int n, float *vector1, float *vector2, float *result)
void mult_dense_mat(double **A, float **B, int dim1, int dim2, int dim3, float ***CC)
void set_vector_valf(int n, float val, float *result)
void orthog1(int n, double *vec)
void copy_vectorf(int n, float *source, float *dest)
void sqrt_vecf(int n, float *source, float *target)
void set_vector_val(int n, double val, double *result)
void scadd(double *vec1, int end, double fac, double *vec2)
void right_mult_with_vector_ff(float *packed_matrix, int n, float *vector, float *result)
void mult_dense_mat_d(double **A, float **B, int dim1, int dim2, int dim3, double ***CC)
void vectors_mult_additionf(int n, float *vector1, float alpha, float *vector2)
void square_vec(int n, float *vec)
double max_abs(int n, double *vector)
double norm(double *vec, int end)
void vectors_subtraction(int n, double *vector1, double *vector2, double *result)
void vectors_addition(int n, double *vector1, double *vector2, double *result)
void copy_vector(int n, const double *source, double *dest)
void vectors_scalar_mult(int n, const double *vector, double alpha, double *result)
void vectors_subtractionf(int n, float *vector1, float *vector2, float *result)
double vectors_inner_productf(int n, float *vector1, float *vector2)
static int nedges
total no. of edges used in routing