#include "LinkedList.h"
#include "memory.h"
-SingleLinkedList *SingleLinkedList_new(void *data)
+SingleLinkedList SingleLinkedList_new(void *data)
{
- SingleLinkedList *head;
- head = GNEW(SingleLinkedList);
+ SingleLinkedList head;
+ head = GNEW(struct SingleLinkedList_s);
head->data = data;
head->next = NULL;
return head;
}
-void SingleLinkedList_delete(SingleLinkedList * head,
+void SingleLinkedList_delete(SingleLinkedList head,
void (*linklist_deallocator) (void *))
{
- SingleLinkedList *next;
+ SingleLinkedList next;
if (!head)
return;
}
-SingleLinkedList *SingleLinkedList_prepend(SingleLinkedList * l,
+SingleLinkedList SingleLinkedList_prepend(SingleLinkedList l,
void *data)
{
- SingleLinkedList *head = SingleLinkedList_new(data);
+ SingleLinkedList head = SingleLinkedList_new(data);
head->next = l;
return head;
}
-void *SingleLinkedList_get_data(SingleLinkedList * l)
+void *SingleLinkedList_get_data(SingleLinkedList l)
{
return l->data;
}
-SingleLinkedList *SingleLinkedList_get_next(SingleLinkedList * l)
+SingleLinkedList SingleLinkedList_get_next(SingleLinkedList l)
{
return l->next;
}
#ifndef LINKED_LIST_H
#define LINKED_LIST_H
-typedef struct SingleLinkedList_s {
+struct SingleLinkedList_s {
void *data;
struct SingleLinkedList_s *next;
-} SingleLinkedList;
+};
-SingleLinkedList *SingleLinkedList_new(void *data);
-void SingleLinkedList_delete(SingleLinkedList * head,
+typedef struct SingleLinkedList_s* SingleLinkedList;
+
+SingleLinkedList SingleLinkedList_new(void *data);
+void SingleLinkedList_delete(SingleLinkedList head,
void (*linklist_deallocator) (void *));
-SingleLinkedList *SingleLinkedList_prepend(SingleLinkedList * l,
+SingleLinkedList SingleLinkedList_prepend(SingleLinkedList l,
void *data);
-void *SingleLinkedList_get_data(SingleLinkedList * l);
+void *SingleLinkedList_get_data(SingleLinkedList l);
-SingleLinkedList *SingleLinkedList_get_next(SingleLinkedList * l);
+SingleLinkedList SingleLinkedList_get_next(SingleLinkedList l);
#endif
#include "assert.h"
#include "arith.h"
-Multilevel_control *Multilevel_control_new()
+Multilevel_control Multilevel_control_new()
{
- Multilevel_control *ctrl;
+ Multilevel_control ctrl;
- ctrl = GNEW(Multilevel_control);
+ ctrl = GNEW(struct Multilevel_control_s);
ctrl->minsize = 4;
ctrl->min_coarsen_factor = 0.75;
ctrl->maxlevel = 1 << 30;
return ctrl;
}
-void Multilevel_control_delete(Multilevel_control * ctrl)
+void Multilevel_control_delete(Multilevel_control ctrl)
{
free(ctrl);
}
-static Multilevel *Multilevel_init(SparseMatrix * A, real * node_weights)
+static Multilevel Multilevel_init(SparseMatrix A, real * node_weights)
{
- Multilevel *grid;
+ Multilevel grid;
if (!A)
return NULL;
assert(A->m == A->n);
- grid = GNEW(Multilevel);
+ grid = GNEW(struct Multilevel_s);
grid->level = 0;
grid->n = A->n;
grid->A = A;
return grid;
}
-void Multilevel_delete(Multilevel * grid)
+void Multilevel_delete(Multilevel grid)
{
if (!grid)
return;
return p;
}
-static void maximal_independent_vertex_set(SparseMatrix * A, int randomize,
+static void maximal_independent_vertex_set(SparseMatrix A, int randomize,
int **vset, int *nvset,
int *nzc)
{
}
-static void maximal_independent_edge_set(SparseMatrix * A, int randomize,
+static void maximal_independent_edge_set(SparseMatrix A, int randomize,
int **matching, int *nmatch)
{
int i, ii, j, *ia, *ja, m, n, *p = NULL;
}
}
-
-
-static void maximal_independent_edge_set_heavest_edge_pernode(SparseMatrix
- * A,
- int
- randomize,
- int
- **matching,
- int *nmatch)
+static void
+maximal_independent_edge_set_heavest_edge_pernode(SparseMatrix A,
+ int randomize, int **matching, int *nmatch)
{
int i, ii, j, *ia, *ja, m, n, *p = NULL;
real *a, amax = 0;
#define node_degree(i) (ia[(i)+1] - ia[(i)])
static void
-maximal_independent_edge_set_heavest_edge_pernode_leaves_first(SparseMatrix
- * A,
- int
- randomize,
- int
- **cluster,
- int
- **clusterp,
- int
- *ncluster)
+maximal_independent_edge_set_heavest_edge_pernode_leaves_first(
+ SparseMatrix A,
+ int randomize,
+ int **cluster,
+ int **clusterp,
+ int *ncluster)
{
int i, ii, j, *ia, *ja, m, n, *p = NULL, q;
real *a, amax = 0;
static void
maximal_independent_edge_set_heavest_edge_pernode_supernodes_first
-(SparseMatrix * A, int randomize, int **cluster, int **clusterp, int *ncluster)
+(SparseMatrix A, int randomize, int **cluster, int **clusterp, int *ncluster)
{
int i, ii, j, *ia, *ja, m, n, *p = NULL;
real *a, amax = 0;
static void
maximal_independent_edge_set_heavest_cluster_pernode_leaves_first
-(SparseMatrix * A, int csize, int randomize, int **cluster, int **clusterp,
+(SparseMatrix A, int csize, int randomize, int **cluster, int **clusterp,
int *ncluster)
{
int i, ii, j, *ia, *ja, m, n, *p = NULL, q, iv, ncmax;
free(matched);
}
static void
-maximal_independent_edge_set_heavest_edge_pernode_scaled(SparseMatrix * A,
+maximal_independent_edge_set_heavest_edge_pernode_scaled(SparseMatrix A,
int randomize,
int **matching,
int *nmatch)
}
}
-static void Multilevel_coarsen(SparseMatrix * A, SparseMatrix * *cA,
+static void Multilevel_coarsen(SparseMatrix A, SparseMatrix *cA,
real * node_wgt, real ** cnode_wgt,
- SparseMatrix * *P, SparseMatrix * *R,
- Multilevel_control * ctrl,
+ SparseMatrix *P, SparseMatrix *R,
+ Multilevel_control ctrl,
int *coarsen_scheme_used)
{
int *matching = NULL, nmatch, nc, nzc, n, i;
int *irn = NULL, *jcn = NULL, *ia = NULL, *ja = NULL;
real *val = NULL;
- SparseMatrix *B = NULL;
+ SparseMatrix B = NULL;
int *vset = NULL, nvset, ncov, j;
int *cluster, *clusterp, ncluster;
for (i = 0; i < n; i++)
fputs(" ", stderr);
}
-static Multilevel *Multilevel_establish(Multilevel * grid,
- Multilevel_control * ctrl)
+static Multilevel Multilevel_establish(Multilevel grid,
+ Multilevel_control ctrl)
{
- Multilevel *cgrid;
+ Multilevel cgrid;
int coarsen_scheme_used;
real *cnode_weights = NULL;
- SparseMatrix *P, *R, *A, *cA;
+ SparseMatrix P, R, A, cA;
#ifdef DEBUG_PRINT
if (Verbose) {
}
-Multilevel *Multilevel_new(SparseMatrix * A0, real * node_weights,
- Multilevel_control * ctrl)
+Multilevel Multilevel_new(SparseMatrix A0, real * node_weights,
+ Multilevel_control ctrl)
{
- Multilevel *grid;
- SparseMatrix *A = A0;
+ Multilevel grid;
+ SparseMatrix A = A0;
if (!SparseMatrix_is_symmetric(A, FALSE)
|| A->type != MATRIX_TYPE_REAL) {
}
-Multilevel *Multilevel_get_coarsest(Multilevel * grid)
+Multilevel Multilevel_get_coarsest(Multilevel grid)
{
while (grid->next) {
grid = grid->next;
#include "SparseMatrix.h"
-typedef struct Multilevel_s {
+struct Multilevel_s {
int level; /* 0, 1, ... */
int n;
- SparseMatrix *A;
- SparseMatrix *P;
- SparseMatrix *R;
+ SparseMatrix A;
+ SparseMatrix P;
+ SparseMatrix R;
real *node_weights;
struct Multilevel_s *next;
struct Multilevel_s *prev;
int delete_top_level_A;
int coarsen_scheme_used; /* to get from previous level to here */
-} Multilevel;
+};
+
+typedef struct Multilevel_s* Multilevel;
enum { MAX_IND_VTX_SET_0 = -100, MAX_IND_VTX_SET_U =
-1, MAX_IND_VTX_SET_C = 0 };
VERTEX_BASED_STO, COARSEN_HYBRID };
-typedef struct {
+struct Multilevel_control_s {
int minsize;
real min_coarsen_factor;
int maxlevel;
int randomize;
int coarsen_scheme;
-} Multilevel_control;
+};
+typedef struct Multilevel_control_s* Multilevel_control;
-Multilevel_control *Multilevel_control_new();
+Multilevel_control Multilevel_control_new();
-void Multilevel_control_delete(Multilevel_control * ctrl);
+void Multilevel_control_delete(Multilevel_control ctrl);
-void Multilevel_delete(Multilevel * grid);
+void Multilevel_delete(Multilevel grid);
-Multilevel *Multilevel_new(SparseMatrix * A, real * node_weights,
- Multilevel_control * ctrl);
+Multilevel Multilevel_new(SparseMatrix A, real * node_weights,
+ Multilevel_control ctrl);
-Multilevel *Multilevel_get_coarsest(Multilevel * grid);
+Multilevel Multilevel_get_coarsest(Multilevel grid);
void print_padding(int n);
return nsupermax;
}
-void QuadTree_get_supernodes_internal(QuadTree * qt, real bh, real * point,
+void QuadTree_get_supernodes_internal(QuadTree qt, real bh, real * point,
int nodeid, int *nsuper,
int *nsupermax, real ** center,
real ** supernode_wgts,
real ** distances, real * counts,
int *flag)
{
- SingleLinkedList *l;
+ SingleLinkedList l;
real *coord, dist;
int dim = qt->dim, i;
}
-void QuadTree_get_supernodes(QuadTree * qt, real bh, real * point,
+void QuadTree_get_supernodes(QuadTree qt, real bh, real * point,
int nodeid, int *nsuper, int *nsupermax,
real ** center, real ** supernode_wgts,
real ** distances, double *counts, int *flag)
-QuadTree *QuadTree_new_from_point_list(int dim, int n, int max_level,
+QuadTree QuadTree_new_from_point_list(int dim, int n, int max_level,
real * coord, real * weight)
{
/* form a new QuadTree data structure from a list of coordinates of n points
weight: node weight of lentgth n. If NULL, unit weight assumed.
*/
real *xmin, *xmax, *center, width;
- QuadTree *qt = NULL;
+ QuadTree qt = NULL;
int i, k;
xmin = N_GNEW(dim, real);
return qt;
}
-QuadTree *QuadTree_new(int dim, real * center, real width, int max_level)
+QuadTree QuadTree_new(int dim, real * center, real width, int max_level)
{
- QuadTree *q;
+ QuadTree q;
int i;
- q = GNEW(QuadTree);
+ q = GNEW(struct QuadTree_s);
q->dim = dim;
q->n = 0;
q->center = N_GNEW(dim, real);
return q;
}
-void QuadTree_delete(QuadTree * q)
+void QuadTree_delete(QuadTree q)
{
int i, dim = q->dim;
if (!q)
return d;
}
-static QuadTree *QuadTree_add_internal(QuadTree * q, real * coord,
+static QuadTree QuadTree_add_internal(QuadTree q, real * coord,
real weight, int id, int level)
{
int i, dim = q->dim, ii, k;
q->average[i] =
((q->average[i]) * q->n + coord[i]) / (q->n + 1);
if (!q->qts) {
- q->qts = N_GNEW(1 << dim, QuadTree *);
+ q->qts = N_GNEW(1 << dim, QuadTree );
for (i = 0; i < 1 << dim; i++) {
width = (q->width) / 2;
q->qts[i] =
}
-QuadTree *QuadTree_add(QuadTree * q, real * coord, real weight, int id)
+QuadTree QuadTree_add(QuadTree q, real * coord, real weight, int id)
{
if (!q)
return q;
}
-static void QuadTree_print_internal(FILE * fp, QuadTree * q, int level)
+static void QuadTree_print_internal(FILE * fp, QuadTree q, int level)
{
/* dump a quad tree in Mathematica format. */
- SingleLinkedList *l;
- SingleLinkedList *l0;
+ SingleLinkedList l;
+ SingleLinkedList l0;
real *coord;
int i, dim = q->dim;
}
-void QuadTree_print(FILE * fp, QuadTree * q)
+void QuadTree_print(FILE * fp, QuadTree q)
{
if (!fp)
return;
#include "sfdpinternal.h"
#include <stdio.h>
-typedef struct QuadTree_struct QuadTree;
+typedef struct QuadTree_s* QuadTree;
-struct QuadTree_struct {
+struct QuadTree_s {
/* a data structure containing coordinates of n items, their average is in "average".
The current level is a square or cube of width "width", which is subdivided into
2^dim QuadTrees qts. At the last level, all coordinates are stored in a single linked list l.
real width; /* center +/- width gives the lower/upper bound, so really width is the
"radius" */
real *average; /* the average coordinates. Array of length dim. Allocated inside */
- QuadTree **qts; /* subtree . If dim = 2, there are 4, dim = 3 gives 8 */
- SingleLinkedList *l;
+ QuadTree *qts; /* subtree . If dim = 2, there are 4, dim = 3 gives 8 */
+ SingleLinkedList l;
int max_level;
};
-QuadTree *QuadTree_new(int dim, real * center, real width, int max_level);
+QuadTree QuadTree_new(int dim, real * center, real width, int max_level);
-void QuadTree_delete(QuadTree * q);
+void QuadTree_delete(QuadTree q);
-QuadTree *QuadTree_add(QuadTree * q, real * coord, real weight, int id); /* coord is copied in */
+QuadTree QuadTree_add(QuadTree q, real * coord, real weight, int id); /* coord is copied in */
-void QuadTree_print(FILE * fp, QuadTree * q);
+void QuadTree_print(FILE * fp, QuadTree q);
-QuadTree *QuadTree_new_from_point_list(int dim, int n, int max_level,
+QuadTree QuadTree_new_from_point_list(int dim, int n, int max_level,
real * coord, real * weight);
real point_distance(real * p1, real * p2, int dim);
-void QuadTree_get_supernodes(QuadTree * qt, real bh, real * point,
+void QuadTree_get_supernodes(QuadTree qt, real bh, real * point,
int nodeid, int *nsuper, int *nsupermax,
real ** center, real ** supernode_wgts,
real ** distances, real * counts, int *flag);
return size;
}
-SparseMatrix *SparseMatrix_make_undirected(SparseMatrix * A)
+SparseMatrix SparseMatrix_make_undirected(SparseMatrix A)
{
/* make it strictly low diag only, and set flag to undirected */
- SparseMatrix *B;
+ SparseMatrix B;
B = SparseMatrix_symmetrize(A, FALSE);
SparseMatrix_set_undirected(B);
return SparseMatrix_remove_upper(B);
}
-SparseMatrix *SparseMatrix_transpose(SparseMatrix * A)
+SparseMatrix SparseMatrix_transpose(SparseMatrix A)
{
int *ia = A->ia, *ja = A->ja, *ib, *jb, nz = A->nz, m = A->m, n =
A->n, type = A->type, format = A->format;
- SparseMatrix *B;
+ SparseMatrix B;
int i, j;
if (!A)
return B;
}
-SparseMatrix *SparseMatrix_symmetrize(SparseMatrix * A,
+SparseMatrix SparseMatrix_symmetrize(SparseMatrix A,
int pattern_symmetric_only)
{
- SparseMatrix *B;
+ SparseMatrix B;
if (SparseMatrix_is_symmetric(A, pattern_symmetric_only))
return SparseMatrix_copy(A);
B = SparseMatrix_transpose(A);
return A;
}
-int SparseMatrix_is_symmetric(SparseMatrix * A,
+int SparseMatrix_is_symmetric(SparseMatrix A,
int test_pattern_symmetry_only)
{
/* assume no repeated entries! */
- SparseMatrix *B;
+ SparseMatrix B;
int *ia, *ja, *ib, *jb, type, m;
int *mask;
int res = FALSE;
return res;
}
-static SparseMatrix *SparseMatrix_init(int m, int n, int type, int format)
+static SparseMatrix SparseMatrix_init(int m, int n, int type, int format)
{
- SparseMatrix *A;
+ SparseMatrix A;
- A = GNEW(SparseMatrix);
+ A = GNEW(struct SparseMatrix_s);
A->m = m;
A->n = n;
A->nz = 0;
return A;
}
-static SparseMatrix *SparseMatrix_alloc(SparseMatrix * A, int nz)
+static SparseMatrix SparseMatrix_alloc(SparseMatrix A, int nz)
{
int type = A->type, format = A->format;
return A;
}
-static SparseMatrix *SparseMatrix_realloc(SparseMatrix * A, int nz)
+static SparseMatrix SparseMatrix_realloc(SparseMatrix A, int nz)
{
int type = A->type, format = A->format;
switch (format) {
return A;
}
-SparseMatrix *SparseMatrix_new(int m, int n, int nz, int type, int format)
+SparseMatrix SparseMatrix_new(int m, int n, int nz, int type, int format)
{
/* return a sparse matrix skeleton with row dimension m and storage nz. If nz == 0,
only row pointers are allocated */
- SparseMatrix *A;
+ SparseMatrix A;
A = SparseMatrix_init(m, n, type, format);
if (nz > 0)
}
-void SparseMatrix_delete(SparseMatrix * A)
+void SparseMatrix_delete(SparseMatrix A)
{
/* return a sparse matrix skeleton with row dimension m and storage nz. If nz == 0,
only row pointers are allocated */
free(A->a);
free(A);
}
-void SparseMatrix_print_csr(char *c, SparseMatrix * A)
+void SparseMatrix_print_csr(char *c, SparseMatrix A)
{
int *ia, *ja;
real *a;
-void SparseMatrix_print_coord(char *c, SparseMatrix * A)
+void SparseMatrix_print_coord(char *c, SparseMatrix A)
{
int *ia, *ja;
real *a;
-void SparseMatrix_print(char *c, SparseMatrix * A)
+void SparseMatrix_print(char *c, SparseMatrix A)
{
switch (A->format) {
case FORMAT_CSR:
-static void SparseMatrix_export_csr(FILE * f, SparseMatrix * A)
+static void SparseMatrix_export_csr(FILE * f, SparseMatrix A)
{
int *ia, *ja;
real *a;
}
-void SparseMatrix_export_binary(char *name, SparseMatrix * A, int *flag)
+void SparseMatrix_export_binary(char *name, SparseMatrix A, int *flag)
{
FILE *f;
}
-SparseMatrix *SparseMatrix_import_binary(char *name)
+SparseMatrix SparseMatrix_import_binary(char *name)
{
- SparseMatrix *A = NULL;
+ SparseMatrix A = NULL;
int m, n, nz, nzmax, type, format, property;
FILE *f;
return A;
}
-static void SparseMatrix_export_coord(FILE * f, SparseMatrix * A)
+static void SparseMatrix_export_coord(FILE * f, SparseMatrix A)
{
int *ia, *ja;
real *a;
-void SparseMatrix_export(FILE * f, SparseMatrix * A)
+void SparseMatrix_export(FILE * f, SparseMatrix A)
{
switch (A->format) {
}
-SparseMatrix *SparseMatrix_from_coordinate_format(SparseMatrix * A)
+SparseMatrix SparseMatrix_from_coordinate_format(SparseMatrix A)
{
/* convert a sparse matrix in coordinate form to one in compressed row form. */
int *irn, *jcn;
}
-SparseMatrix *SparseMatrix_from_coordinate_arrays(int nz, int m, int n,
+SparseMatrix SparseMatrix_from_coordinate_arrays(int nz, int m, int n,
int *irn, int *jcn,
void *val0, int type)
{
type: matrix type
*/
- SparseMatrix *A = NULL;
+ SparseMatrix A = NULL;
int *ia, *ja;
real *a, *val;
int *ai, *vali;
}
-SparseMatrix *SparseMatrix_add(SparseMatrix * A, SparseMatrix * B)
+SparseMatrix SparseMatrix_add(SparseMatrix A, SparseMatrix B)
{
int m, n;
- SparseMatrix *C = NULL;
+ SparseMatrix C = NULL;
int *mask = NULL;
int *ia = A->ia, *ja = A->ja, *ib = B->ia, *jb = B->ja, *ic, *jc;
int i, j, nz, nzmax;
}
-static void SparseMatrix_multiply_dense1(SparseMatrix * A, real * v,
+static void SparseMatrix_multiply_dense1(SparseMatrix A, real * v,
real ** res, int dim,
int transposed,
int res_transposed)
}
-static void SparseMatrix_multiply_dense2(SparseMatrix * A, real * v,
+static void SparseMatrix_multiply_dense2(SparseMatrix A, real * v,
real ** res, int dim,
int transposed,
int res_transposed)
-void SparseMatrix_multiply_dense(SparseMatrix * A, int ATransposed,
+void SparseMatrix_multiply_dense(SparseMatrix A, int ATransposed,
real * v, int vTransposed, real ** res,
int res_transposed, int dim)
{
-void SparseMatrix_multiply_vector(SparseMatrix * A, real * v, real ** res,
+void SparseMatrix_multiply_vector(SparseMatrix A, real * v, real ** res,
int transposed)
{
/* A v or A^T v. Real only for now. */
-SparseMatrix *SparseMatrix_scaled_by_vector(SparseMatrix * A, real * v,
+SparseMatrix SparseMatrix_scaled_by_vector(SparseMatrix A, real * v,
int apply_to_row)
{
/* A SCALED BY VECOTR V IN ROW/COLUMN. Real only for now. */
}
-SparseMatrix *SparseMatrix_multiply_by_scaler(SparseMatrix * A, real s)
+SparseMatrix SparseMatrix_multiply_by_scaler(SparseMatrix A, real s)
{
/* A scaled by a number */
int i, j, *ia, m;
}
-SparseMatrix *SparseMatrix_multiply(SparseMatrix * A, SparseMatrix * B)
+SparseMatrix SparseMatrix_multiply(SparseMatrix A, SparseMatrix B)
{
int m, n;
- SparseMatrix *C = NULL;
+ SparseMatrix C = NULL;
int *mask = NULL;
int *ia = A->ia, *ja = A->ja, *ib = B->ia, *jb = B->ja, *ic, *jc;
int i, j, k, jj, type, nz;
}
-SparseMatrix *SparseMatrix_sum_repeat_entries(SparseMatrix * A)
+SparseMatrix SparseMatrix_sum_repeat_entries(SparseMatrix A)
{
/* sum repeated entries in the same row, i.e., {1,1}->1, {1,1}->2 becomes {1,1}->3 */
int *ia = A->ia, *ja = A->ja, type = A->type, n = A->n;
return A;
}
-SparseMatrix *SparseMatrix_coordinate_form_add_entries(SparseMatrix * A,
+SparseMatrix SparseMatrix_coordinate_form_add_entries(SparseMatrix A,
int nentries,
int *irn, int *jcn,
void *val)
}
-SparseMatrix *SparseMatrix_remove_diagonal(SparseMatrix * A)
+SparseMatrix SparseMatrix_remove_diagonal(SparseMatrix A)
{
int i, j, *ia, *ja, nz, sta;
}
-SparseMatrix *SparseMatrix_remove_upper(SparseMatrix * A)
+SparseMatrix SparseMatrix_remove_upper(SparseMatrix A)
{ /* remove diag and upper diag */
int i, j, *ia, *ja, nz, sta;
-SparseMatrix *SparseMatrix_divide_row_by_degree(SparseMatrix * A)
+SparseMatrix SparseMatrix_divide_row_by_degree(SparseMatrix A)
{
int i, j, *ia, *ja;
real deg;
SparseMatrix
- *SparseMatrix_get_real_adjacency_matrix_symmetrized(SparseMatrix * A)
+SparseMatrix_get_real_adjacency_matrix_symmetrized(SparseMatrix A)
{
/* symmetric, all entries to 1, diaginal removed */
int i, *ia, *ja, nz, m, n;
real *a;
- SparseMatrix *B;
+ SparseMatrix B;
if (!A)
return A;
-SparseMatrix *SparseMatrix_normalize_to_rowsum1(SparseMatrix * A)
+SparseMatrix SparseMatrix_normalize_to_rowsum1(SparseMatrix A)
{
int i, j;
real sum, *a;
-SparseMatrix *SparseMatrix_normalize_by_row(SparseMatrix * A)
+SparseMatrix SparseMatrix_normalize_by_row(SparseMatrix A)
{
int i, j;
real max, *a;
}
-SparseMatrix *SparseMatrix_apply_fun(SparseMatrix * A,
+SparseMatrix SparseMatrix_apply_fun(SparseMatrix A,
double (*fun) (double x))
{
int i, j;
}
-SparseMatrix *SparseMatrix_crop(SparseMatrix * A, real epsilon)
+SparseMatrix SparseMatrix_crop(SparseMatrix A, real epsilon)
{
int i, j, *ia, *ja, nz, sta;
return A;
}
-SparseMatrix *SparseMatrix_copy(SparseMatrix * A)
+SparseMatrix SparseMatrix_copy(SparseMatrix A)
{
- SparseMatrix *B;
+ SparseMatrix B;
if (!A)
return A;
B = SparseMatrix_new(A->m, A->n, A->nz, A->type, A->format);
return B;
}
-int SparseMatrix_has_diagonal(SparseMatrix * A)
+int SparseMatrix_has_diagonal(SparseMatrix A)
{
int i, j, m = A->m, *ia = A->ia, *ja = A->ja;
return FALSE;
}
-void SparseMatrix_level_sets(SparseMatrix * A, int root, int *nlevel,
+void SparseMatrix_level_sets(SparseMatrix A, int root, int *nlevel,
int **levelset_ptr, int **levelset,
int **mask, int reinitialize_mask)
{
(*mask)[(*levelset)[i]] = UNMASKED;
}
-void SparseMatrix_weakly_connected_components(SparseMatrix * A0,
+void SparseMatrix_weakly_connected_components(SparseMatrix A0,
int *ncomp, int **comps,
int **comps_ptr)
{
- SparseMatrix *A = A0;
+ SparseMatrix A = A0;
int *levelset_ptr = NULL, *levelset = NULL, *mask = NULL, nlevel;
int m = A->m, i, nn;
free(mask);
}
-int SparseMatrix_pseudo_diameter(SparseMatrix * A0, int root,
+int SparseMatrix_pseudo_diameter(SparseMatrix A0, int root,
int aggressive, int *end1, int *end2,
int *connectedQ)
{
/* assume unit edge length, unsymmetric matrix ill be symmetrized */
- SparseMatrix *A = A0;
+ SparseMatrix A = A0;
int m = A->m, i;
int nlevel;
int *levelset_ptr = NULL, *levelset = NULL, *mask = NULL;
return nlevel0;
}
-int SparseMatrix_pseudo_diameter_only(SparseMatrix * A)
+int SparseMatrix_pseudo_diameter_only(SparseMatrix A)
{
int end1, end2, connectedQ;
return SparseMatrix_pseudo_diameter(A, 0, FALSE, &end1, &end2,
&connectedQ);
}
-int SparseMatrix_connectedQ(SparseMatrix * A0)
+int SparseMatrix_connectedQ(SparseMatrix A0)
{
int root = 0, nlevel, *levelset_ptr = NULL, *levelset = NULL, *mask =
NULL, connected;
- SparseMatrix *A = A0;
+ SparseMatrix A = A0;
if (!SparseMatrix_is_symmetric(A, TRUE)) {
A = SparseMatrix_symmetrize(A, TRUE);
}
-void SparseMatrix_decompose_to_supervariables(SparseMatrix * A,
+void SparseMatrix_decompose_to_supervariables(SparseMatrix A,
int *ncluster, int **cluster,
int **clusterp)
{
1 << 3, MATRIX_UNDIRECTED = 1 << 4
};
-typedef struct {
+struct SparseMatrix_s {
int m; /* row dimension */
int n; /* column dimension */
int nz; /* The actual length used is nz, for CSR/CSC matrix this is the same as ia[n] */
void *a; /* entry values. If NULL, pattern matrix */
int format; /* whether it is CSR, CSC, COORD. By default it is in CSR format */
int property; /* pattern_symmetric/symmetric/skew/hermitian */
-} SparseMatrix;
+};
+
+typedef struct SparseMatrix_s* SparseMatrix;
enum { MATRIX_TYPE_REAL = 1 << 0, MATRIX_TYPE_COMPLEX =
1 << 1, MATRIX_TYPE_INTEGER = 1 << 2, MATRIX_TYPE_PATTERN =
1 << 3, MATRIX_TYPE_UNKNOWN = 1 << 4
};
-SparseMatrix *SparseMatrix_new(int m, int n, int nz, int type, int format);
+SparseMatrix SparseMatrix_new(int m, int n, int nz, int type, int format);
-SparseMatrix *SparseMatrix_from_coordinate_format(SparseMatrix * A);
+SparseMatrix SparseMatrix_from_coordinate_format(SparseMatrix A);
-SparseMatrix *SparseMatrix_from_coordinate_arrays(int nz, int m, int n,
+SparseMatrix SparseMatrix_from_coordinate_arrays(int nz, int m, int n,
int *irn, int *jcn,
void *val, int type);
-void SparseMatrix_print(char *, SparseMatrix * A); /*print to stdout in Mathematica format */
+void SparseMatrix_print(char *, SparseMatrix A); /*print to stdout in Mathematica format */
-void SparseMatrix_export(FILE * f, SparseMatrix * A); /* export into MM format except the header */
+void SparseMatrix_export(FILE * f, SparseMatrix A); /* export into MM format except the header */
-SparseMatrix *SparseMatrix_import_binary(char *name);
+SparseMatrix SparseMatrix_import_binary(char *name);
-void SparseMatrix_export_binary(char *name, SparseMatrix * A, int *flag);
+void SparseMatrix_export_binary(char *name, SparseMatrix A, int *flag);
-void SparseMatrix_delete(SparseMatrix * A);
+void SparseMatrix_delete(SparseMatrix A);
-SparseMatrix *SparseMatrix_add(SparseMatrix * A, SparseMatrix * B);
-SparseMatrix *SparseMatrix_multiply(SparseMatrix * A, SparseMatrix * B);
-SparseMatrix *SparseMatrix_sum_repeat_entries(SparseMatrix * A);
-SparseMatrix *SparseMatrix_coordinate_form_add_entries(SparseMatrix * A,
+SparseMatrix SparseMatrix_add(SparseMatrix A, SparseMatrix B);
+SparseMatrix SparseMatrix_multiply(SparseMatrix A, SparseMatrix B);
+SparseMatrix SparseMatrix_sum_repeat_entries(SparseMatrix A);
+SparseMatrix SparseMatrix_coordinate_form_add_entries(SparseMatrix A,
int nentries,
int *irn, int *jcn,
void *val);
-int SparseMatrix_is_symmetric(SparseMatrix * A,
+int SparseMatrix_is_symmetric(SparseMatrix A,
int test_pattern_symmetry_only);
-SparseMatrix *SparseMatrix_transpose(SparseMatrix * A);
-SparseMatrix *SparseMatrix_symmetrize(SparseMatrix * A,
+SparseMatrix SparseMatrix_transpose(SparseMatrix A);
+SparseMatrix SparseMatrix_symmetrize(SparseMatrix A,
int pattern_symmetric_only);
-void SparseMatrix_multiply_vector(SparseMatrix * A, real * v, real ** res, int transposed); /* if v = NULL, v is assumed to be {1,1,...,1} */
-SparseMatrix *SparseMatrix_remove_diagonal(SparseMatrix * A);
-SparseMatrix *SparseMatrix_remove_upper(SparseMatrix * A); /* remove diag and upper diag */
-SparseMatrix *SparseMatrix_divide_row_by_degree(SparseMatrix * A);
-SparseMatrix *SparseMatrix_get_real_adjacency_matrix_symmetrized(SparseMatrix * A); /* symmetric, all entries to 1, diaginal removed */
-SparseMatrix *SparseMatrix_normalize_to_rowsum1(SparseMatrix * A); /* for real only! */
-void SparseMatrix_multiply_dense(SparseMatrix * A, int ATranspose,
+void SparseMatrix_multiply_vector(SparseMatrix A, real * v, real ** res, int transposed); /* if v = NULL, v is assumed to be {1,1,...,1} */
+SparseMatrix SparseMatrix_remove_diagonal(SparseMatrix A);
+SparseMatrix SparseMatrix_remove_upper(SparseMatrix A); /* remove diag and upper diag */
+SparseMatrix SparseMatrix_divide_row_by_degree(SparseMatrix A);
+SparseMatrix SparseMatrix_get_real_adjacency_matrix_symmetrized(SparseMatrix A); /* symmetric, all entries to 1, diaginal removed */
+SparseMatrix SparseMatrix_normalize_to_rowsum1(SparseMatrix A); /* for real only! */
+void SparseMatrix_multiply_dense(SparseMatrix A, int ATranspose,
real * v, int vTransposed, real ** res,
int res_transpose, int dim);
-SparseMatrix *SparseMatrix_apply_fun(SparseMatrix * A, double (*fun) (double x)); /* for real only! */
-SparseMatrix *SparseMatrix_copy(SparseMatrix * A);
-int SparseMatrix_has_diagonal(SparseMatrix * A);
-SparseMatrix *SparseMatrix_normalize_by_row(SparseMatrix * A); /* divide by max of each row */
-SparseMatrix *SparseMatrix_crop(SparseMatrix * A, real epsilon); /*remove any entry <= epsilon */
-SparseMatrix *SparseMatrix_scaled_by_vector(SparseMatrix * A, real * v,
+SparseMatrix SparseMatrix_apply_fun(SparseMatrix A, double (*fun) (double x)); /* for real only! */
+SparseMatrix SparseMatrix_copy(SparseMatrix A);
+int SparseMatrix_has_diagonal(SparseMatrix A);
+SparseMatrix SparseMatrix_normalize_by_row(SparseMatrix A); /* divide by max of each row */
+SparseMatrix SparseMatrix_crop(SparseMatrix A, real epsilon); /*remove any entry <= epsilon */
+SparseMatrix SparseMatrix_scaled_by_vector(SparseMatrix A, real * v,
int apply_to_row);
-SparseMatrix *SparseMatrix_multiply_by_scaler(SparseMatrix * A, real s);
-SparseMatrix *SparseMatrix_make_undirected(SparseMatrix * A); /* make it strictly low diag only, and set flag to undirected */
-int SparseMatrix_connectedQ(SparseMatrix * A);
-int SparseMatrix_pseudo_diameter_only(SparseMatrix * A);
-int SparseMatrix_pseudo_diameter(SparseMatrix * A0, int root, int aggressive, int *end1, int *end2, int *connectedQ); /* assume unit edge length, unsymmetric matrix ill be symmetrized */
-void SparseMatrix_level_sets(SparseMatrix * A, int root, int *nlevel,
+SparseMatrix SparseMatrix_multiply_by_scaler(SparseMatrix A, real s);
+SparseMatrix SparseMatrix_make_undirected(SparseMatrix A); /* make it strictly low diag only, and set flag to undirected */
+int SparseMatrix_connectedQ(SparseMatrix A);
+int SparseMatrix_pseudo_diameter_only(SparseMatrix A);
+int SparseMatrix_pseudo_diameter(SparseMatrix A0, int root, int aggressive, int *end1, int *end2, int *connectedQ); /* assume unit edge length, unsymmetric matrix ill be symmetrized */
+void SparseMatrix_level_sets(SparseMatrix A, int root, int *nlevel,
int **levelset_ptr, int **levelset,
int **mask, int reintialize_mask);
-void SparseMatrix_weakly_connected_components(SparseMatrix * A0,
+void SparseMatrix_weakly_connected_components(SparseMatrix A0,
int *ncomp, int **comps,
int **comps_ptr);
-void SparseMatrix_decompose_to_supervariables(SparseMatrix * A,
+void SparseMatrix_decompose_to_supervariables(SparseMatrix A,
int *ncluster, int **cluster,
int **clusterp);
#include "memory.h"
#include "delaunay.h"
-SparseMatrix *call_tri(int n, int dim, real * x)
+SparseMatrix call_tri(int n, int dim, real * x)
{
real one = 1;
int i, ii, jj;
- SparseMatrix *A;
- SparseMatrix *B;
+ SparseMatrix A;
+ SparseMatrix B;
int* edgelist = NULL;
real* xv = N_GNEW(n, real);
real* yv = N_GNEW(n, real);
return B;
}
-SparseMatrix *call_tri2(int n, int dim, real * xx)
+SparseMatrix call_tri2(int n, int dim, real * xx)
{
real *x, *y;
v_data *delaunay;
int i, j;
- SparseMatrix *A;
- SparseMatrix *B;
+ SparseMatrix A;
+ SparseMatrix B;
real one = 1;
x = N_GNEW(n, real);
y = N_GNEW(n, real);
#ifndef CALL_TRI_H
#define CALL_TRI_H
-SparseMatrix *call_tri(int n, int dim, real * x);
-SparseMatrix *call_tri2(int n, int dim, real * x);
+SparseMatrix call_tri(int n, int dim, real * x);
+SparseMatrix call_tri2(int n, int dim, real * x);
#endif
#define MACHINEACC 1.0e-16
-static void ideal_distance_avoid_overlap(int dim, SparseMatrix * A,
+static void ideal_distance_avoid_overlap(int dim, SparseMatrix A,
real * x, real * width,
real * ideal_distance,
real * tmax, real * tmin)
;
}
-static SparseMatrix *get_overlap_graph(int dim, int n, real * x,
+static SparseMatrix get_overlap_graph(int dim, int n, real * x,
real * width)
{
scan_point *scanpointsx, *scanpointsy;
int i, k, neighbor;
- SparseMatrix *A = NULL;
- SparseMatrix *B = NULL;
+ SparseMatrix A = NULL;
+ SparseMatrix B = NULL;
rb_red_blk_node *newNode, *newNode0;
rb_red_blk_tree *treey;
real one = 1;
/* ============================== label overlap smoother ==================*/
+#define OverlapSmoother_s StressMajorizationSmoother_s
-OverlapSmoother *OverlapSmoother_new(SparseMatrix * A, int dim,
+OverlapSmoother OverlapSmoother_new(SparseMatrix A, int dim,
real lambda0, real * x, real * width,
int include_original_graph,
int neighborhood_only,
real * max_overlap,
real * min_overlap)
{
- OverlapSmoother *sm;
+ OverlapSmoother sm;
int i, j, k, m = A->m, *iw, *jw, *id, *jd, jdiag;
- SparseMatrix *B;
+ SparseMatrix B;
real *lambda, *d, *w, diag_d, diag_w, dist;
assert((!A) || SparseMatrix_is_symmetric(A, FALSE));
- sm = GNEW(OverlapSmoother);
+ sm = GNEW(struct OverlapSmoother_s);
lambda = sm->lambda = N_GNEW(m, real);
for (i = 0; i < m; i++)
sm->lambda[i] = lambda0;
B = call_tri(m, dim, x);
if (!neighborhood_only) {
- SparseMatrix *C;
- SparseMatrix *D;
+ SparseMatrix C;
+ SparseMatrix D;
C = get_overlap_graph(dim, A->m, x, width);
D = SparseMatrix_add(B, C);
SparseMatrix_delete(B);
return sm;
}
-void OverlapSmoother_delete(OverlapSmoother * sm)
+void OverlapSmoother_delete(OverlapSmoother sm)
{
StressMajorizationSmoother_delete(sm);
}
-void OverlapSmoother_smooth(OverlapSmoother * sm, int dim, real * x)
+void OverlapSmoother_smooth(OverlapSmoother sm, int dim, real * x)
{
int maxit_sm = 1; /* only using 1 iteration of stress majorization
is found to give better results and save time! */
/*================================= end OverlapSmoother =============*/
-static void scale_to_edge_length(int dim, SparseMatrix * A, real * x,
+static void scale_to_edge_length(int dim, SparseMatrix A, real * x,
real avg_label_size)
{
real dist;
free(xmax);
}
-int remove_overlap(int dim, SparseMatrix * A, real * x,
+int remove_overlap(int dim, SparseMatrix A, real * x,
real * label_sizes, int ntry)
{
real lambda = 0.00;
- OverlapSmoother *sm;
+ OverlapSmoother sm;
int include_original_graph = 0, i;
real avg_label_size;
real max_overlap = 0, min_overlap = 999;
typedef StressMajorizationSmoother OverlapSmoother;
-void OverlapSmoother_delete(OverlapSmoother * sm);
+void OverlapSmoother_delete(OverlapSmoother sm);
-OverlapSmoother *OverlapSmoother_new(SparseMatrix * A, int dim,
+OverlapSmoother OverlapSmoother_new(SparseMatrix A, int dim,
real lambda0, real * x, real * width,
int include_original_graph,
int neighborhood_only,
real * max_overlap,
real * min_overlap);
-void OverlapSmoother_smooth(OverlapSmoother * sm, int dim, real * x);
+void OverlapSmoother_smooth(OverlapSmoother sm, int dim, real * x);
-int remove_overlap(int dim, SparseMatrix * A, real * x,
+int remove_overlap(int dim, SparseMatrix A, real * x,
real * label_sizes, int ntry);
#endif
#define node_degree(i) (ia[(i)+1] - ia[(i)])
-SparseMatrix *ideal_distance_matrix(SparseMatrix * A, int dim, real * x)
+SparseMatrix ideal_distance_matrix(SparseMatrix A, int dim, real * x)
{
/* find the ideal distance between edges, either 1, or |N[i] \Union N[j]| - |N[i] \Intersection N[j]|
*/
- SparseMatrix *D;
+ SparseMatrix D;
int *ia, *ja, i, j, k, l, nz;
real *d;
int *mask = NULL;
return D;
}
-StressMajorizationSmoother *StressMajorizationSmoother_new(SparseMatrix *
+StressMajorizationSmoother StressMajorizationSmoother_new(SparseMatrix
A, int dim,
real lambda0,
real * x,
int
ideal_dist_scheme)
{
- StressMajorizationSmoother *sm;
+ StressMajorizationSmoother sm;
int i, j, k, l, m = A->m, *ia = A->ia, *ja = A->ja, *iw, *jw, *id, *jd;
int *mask, nz;
real *d, *w, *lambda;
real *avg_dist, diag_d, diag_w, *dd, dist, s = 0, stop = 0, sbot = 0;
- SparseMatrix *ID;
+ SparseMatrix ID;
assert(SparseMatrix_is_symmetric(A, FALSE));
ID = ideal_distance_matrix(A, dim, x);
dd = (real *) ID->a;
- sm = GNEW(StressMajorizationSmoother);
+ sm = GNEW(struct StressMajorizationSmoother_s);
lambda = sm->lambda = N_GNEW(m, real);
for (i = 0; i < m; i++)
sm->lambda[i] = lambda0;
-void StressMajorizationSmoother_smooth(StressMajorizationSmoother * sm,
+void StressMajorizationSmoother_smooth(StressMajorizationSmoother sm,
int dim, real * x, int maxit_sm)
{
- SparseMatrix *Lw = sm->Lw;
- SparseMatrix *Lwd = sm->Lwd;
- SparseMatrix *Lwdd = NULL;
+ SparseMatrix Lw = sm->Lw;
+ SparseMatrix Lwd = sm->Lwd;
+ SparseMatrix Lwdd = NULL;
int i, j, m, *id, *jd, idiag, flag = 0, iter = 0;
real *dd, *d, *y = NULL, *x0 = NULL, diag, diff = 1, tol =
0.001, *lambda = sm->lambda, maxit, res;
free(y);
}
-void StressMajorizationSmoother_delete(StressMajorizationSmoother * sm)
+void StressMajorizationSmoother_delete(StressMajorizationSmoother sm)
{
if (!sm)
return;
}
-TriangleSmoother *TriangleSmoother_new(SparseMatrix * A, int dim,
+#define TriangleSmoother_s StressMajorizationSmoother_s
+
+TriangleSmoother TriangleSmoother_new(SparseMatrix A, int dim,
real lambda0, real * x,
int use_triangularization)
{
- TriangleSmoother *sm;
+ TriangleSmoother sm;
int i, j, k, m = A->m, *ia = A->ia, *ja =
A->ja, *iw, *jw, *id, *jd, jdiag, nz;
- SparseMatrix *B;
+ SparseMatrix B;
real *avg_dist, *lambda, *d, *w, diag_d, diag_w, dist;
real s = 0, stop = 0, sbot = 0;
avg_dist[i] /= nz;
}
- sm = GNEW(TriangleSmoother);
+ sm = GNEW(struct TriangleSmoother_s);
lambda = sm->lambda = N_GNEW(m, real);
for (i = 0; i < m; i++)
sm->lambda[i] = lambda0;
return sm;
}
-void TriangleSmoother_delete(TriangleSmoother * sm)
+void TriangleSmoother_delete(TriangleSmoother sm)
{
StressMajorizationSmoother_delete(sm);
}
-void TriangleSmoother_smooth(TriangleSmoother * sm, int dim, real * x)
+void TriangleSmoother_smooth(TriangleSmoother sm, int dim, real * x)
{
StressMajorizationSmoother_smooth(sm, dim, x, 50);
/* ================================ spring and spring-electrical based smoother ================ */
-SpringSmoother *SpringSmoother_new(SparseMatrix * A, int dim,
- spring_electrical_control * ctrl,
+SpringSmoother SpringSmoother_new(SparseMatrix A, int dim,
+ spring_electrical_control ctrl,
real * x)
{
- SpringSmoother *sm;
+ SpringSmoother sm;
int i, j, k, l, m = A->m, *ia = A->ia, *ja = A->ja, *id, *jd;
int *mask, nz;
real *d, *dd;
real *avg_dist;
- SparseMatrix *ID = NULL;
+ SparseMatrix ID = NULL;
assert(SparseMatrix_is_symmetric(A, FALSE));
ID = ideal_distance_matrix(A, dim, x);
dd = (real *) ID->a;
- sm = GNEW(SpringSmoother);
+ sm = GNEW(struct SpringSmoother_s);
mask = N_GNEW(m, int);
avg_dist = N_GNEW(m, real);
}
-void SpringSmoother_delete(SpringSmoother * sm)
+void SpringSmoother_delete(SpringSmoother sm)
{
if (!sm)
return;
-void SpringSmoother_smooth(SpringSmoother * sm, SparseMatrix * A,
+void SpringSmoother_smooth(SpringSmoother sm, SparseMatrix A,
real * node_weights, int dim, real * x)
{
int flag = 0;
/*=============================== end of spring and spring-electrical based smoother =========== */
-int post_process_smoothing(int dim, SparseMatrix * A,
- spring_electrical_control * ctrl,
+int post_process_smoothing(int dim, SparseMatrix A,
+ spring_electrical_control ctrl,
real * node_weights, real * x)
{
#ifdef DEBUG
switch (ctrl->smoothing) {
case SMOOTHING_RNG:
case SMOOTHING_TRIANGLE:{
- TriangleSmoother *sm;
+ TriangleSmoother sm;
if (ctrl->smoothing == SMOOTHING_RNG) {
sm = TriangleSmoother_new(A, dim, 0, x, FALSE);
case SMOOTHING_STRESS_MAJORIZATION_POWER_DIST:
case SMOOTHING_STRESS_MAJORIZATION_AVG_DIST:
{
- StressMajorizationSmoother *sm;
+ StressMajorizationSmoother sm;
int k, dist_scheme = IDEAL_AVG_DIST;
if (ctrl->smoothing ==
break;
}
case SMOOTHING_SPRING:{
- SpringSmoother *sm;
+ SpringSmoother sm;
int k;
for (k = 0; k < 1; k++) {
#include <spring_electrical.h>
-typedef struct {
- SparseMatrix *Lw;
- SparseMatrix *Lwd;
+struct StressMajorizationSmoother_s {
+ SparseMatrix Lw;
+ SparseMatrix Lwd;
real *lambda;
-} StressMajorizationSmoother;
+};
-void StressMajorizationSmoother_delete(StressMajorizationSmoother * sm);
+typedef struct StressMajorizationSmoother_s* StressMajorizationSmoother;
+
+void StressMajorizationSmoother_delete(StressMajorizationSmoother sm);
enum { IDEAL_GRAPH_DIST, IDEAL_AVG_DIST, IDEAL_POWER_DIST };
-StressMajorizationSmoother *StressMajorizationSmoother_new(SparseMatrix *
+StressMajorizationSmoother StressMajorizationSmoother_new(SparseMatrix
A, int dim,
real lambda,
real * x,
int
ideal_dist_scheme);
-void StressMajorizationSmoother_smooth(StressMajorizationSmoother * sm,
+void StressMajorizationSmoother_smooth(StressMajorizationSmoother sm,
int dim, real * x, int maxit);
/*-------------------- triangle/neirhborhood graph based smoother ------------------- */
typedef StressMajorizationSmoother TriangleSmoother;
-/* #define TriangleSmoother_struct StressMajorizationSmoother_struct */
-
-void TriangleSmoother_delete(TriangleSmoother * sm);
+void TriangleSmoother_delete(TriangleSmoother sm);
-TriangleSmoother *TriangleSmoother_new(SparseMatrix * A, int dim,
+TriangleSmoother TriangleSmoother_new(SparseMatrix A, int dim,
real lambda, real * x,
int use_triangularization);
-void TriangleSmoother_smooth(TriangleSmoother * sm, int dim, real * x);
+void TriangleSmoother_smooth(TriangleSmoother sm, int dim, real * x);
/*------------------ spring and spring-electrical based smoother */
-typedef struct {
- SparseMatrix *D;
- spring_electrical_control *ctrl;
-} SpringSmoother;
+struct SpringSmoother_s {
+ SparseMatrix D;
+ spring_electrical_control ctrl;
+};
+typedef struct SpringSmoother_s* SpringSmoother;
-SpringSmoother *SpringSmoother_new(SparseMatrix * A, int dim,
- spring_electrical_control * ctrl,
+SpringSmoother SpringSmoother_new(SparseMatrix A, int dim,
+ spring_electrical_control ctrl,
real * x);
-void SpringSmoother_delete(SpringSmoother * sm);
+void SpringSmoother_delete(SpringSmoother sm);
-void SpringSmoother_smooth(SpringSmoother * sm, SparseMatrix * A,
+void SpringSmoother_smooth(SpringSmoother sm, SparseMatrix A,
real * node_weights, int dim, real * x);
/*------------------------------------------------------------------*/
-int post_process_smoothing(int dim, SparseMatrix * A,
- spring_electrical_control * ctrl,
+int post_process_smoothing(int dim, SparseMatrix A,
+ spring_electrical_control ctrl,
real * node_weights, real * x);
#endif
* Assumes g is connected and simple, i.e., we can have a->b and b->a
* but not a->b and a->b
*/
-static SparseMatrix *makeMatrix(Agraph_t * g, int dim)
+static SparseMatrix makeMatrix(Agraph_t * g, int dim)
{
- SparseMatrix *A = 0;
+ SparseMatrix A = 0;
Agnode_t *n;
Agedge_t *e;
Agsym_t *sym;
int
fdpAdjust (graph_t* g)
{
- SparseMatrix *A = makeMatrix(g, Ndim);
+ SparseMatrix A = makeMatrix(g, Ndim);
real *sizes;
real *pos = N_NEW(Ndim * agnnodes(g), real);
Agnode_t *n;
return flag;
}
-static void sfdpLayout(graph_t * g, spring_electrical_control * ctrl,
+static void sfdpLayout(graph_t * g, spring_electrical_control ctrl,
pointf pad)
{
real *sizes;
Agnode_t *n;
int flag, i;
- SparseMatrix *A = makeMatrix(g, Ndim);
+ SparseMatrix A = makeMatrix(g, Ndim);
if (ctrl->overlap)
sizes = getSizes(g, pad);
else
* ctrl->use_node_weights
*/
static void
-tuneControl (graph_t* g, spring_electrical_control* ctrl)
+tuneControl (graph_t* g, spring_electrical_control ctrl)
{
ctrl->p = -1.0*late_double(g, agfindattr(g, "K"), -AUTOP, 0.0);
ctrl->multilevels = late_int(g, agfindattr(g, "maxiter"), INT_MAX, 0);
int i;
expand_t sep;
pointf pad;
- spring_electrical_control *ctrl = spring_electrical_control_new();
+ spring_electrical_control ctrl = spring_electrical_control_new();
tuneControl (g, ctrl);
return res;
}
-real *Operator_matmul_apply(Operator * o, real * x, real * y)
+real *Operator_matmul_apply(Operator o, real * x, real * y)
{
- SparseMatrix *A = (SparseMatrix *) o->data;
+ SparseMatrix A = (SparseMatrix) o->data;
SparseMatrix_multiply_vector(A, x, &y, FALSE);
return y;
}
-Operator *Operator_matmul_new(SparseMatrix * A)
+Operator Operator_matmul_new(SparseMatrix A)
{
- Operator *o = GNEW(Operator);
+ Operator o = GNEW(struct Operator_s);
o->data = (void *) A;
o->Operator_apply = Operator_matmul_apply;
return o;
}
-void Operator_matmul_delete(Operator * o)
+void Operator_matmul_delete(Operator o)
{
}
-real *Operator_diag_precon_apply(Operator * o, real * x, real * y)
+real *Operator_diag_precon_apply(Operator o, real * x, real * y)
{
int i, m;
real *diag = (real *) o->data;
return y;
}
-Operator *Operator_diag_precon_new(SparseMatrix * A)
+Operator Operator_diag_precon_new(SparseMatrix A)
{
- Operator *o;
+ Operator o;
real *diag;
int i, j, m = A->m, *ia = A->ia, *ja = A->ja;
real *a = (real *) A->a;
assert(a);
- o = GNEW(Operator);
+ o = GNEW(struct Operator_s);
o->data = N_GNEW(A->m + 1, real);
diag = (real *) o->data;
return o;
}
-void Operator_diag_precon_delete(Operator * o)
+void Operator_diag_precon_delete(Operator o)
{
free(o->data);
}
-static real conjugate_gradient(Operator * A, Operator * precon, int n, real * x,
+static real conjugate_gradient(Operator A, Operator precon, int n, real * x,
real * rhs, real tol, int maxit, int *flag)
{
real *z, *r, *p, *q, res = 10 * tol, alpha;
return res;
}
-real SparseMatrix_solve(SparseMatrix * A, int dim, real * x0, real * rhs,
+real SparseMatrix_solve(SparseMatrix A, int dim, real * x0, real * rhs,
real tol, int maxit, int method, int *flag)
{
- Operator *Ax;
- Operator *precond;
+ Operator Ax;
+ Operator precond;
real *x, *b, res = 0;
int n = A->m, k, i;
enum { SOLVE_METHOD_CG };
-typedef struct Operator_struct Operator;
+typedef struct Operator_s* Operator;
-typedef real *(*op_apply_fn) (Operator * o, real * in, real * out);
+typedef real *(*op_apply_fn) (Operator o, real * in, real * out);
-struct Operator_struct {
+struct Operator_s {
void *data;
op_apply_fn Operator_apply;
};
-real SparseMatrix_solve(SparseMatrix * A, int dim, real * x0, real * rhs,
+real SparseMatrix_solve(SparseMatrix A, int dim, real * x0, real * rhs,
real tol, int maxit, int method, int *flag);
#endif
#define drand() (rand()/(real) RAND_MAX)
-spring_electrical_control *spring_electrical_control_new()
+spring_electrical_control spring_electrical_control_new()
{
- spring_electrical_control *ctrl;
- ctrl = GNEW(spring_electrical_control);
+ spring_electrical_control ctrl;
+ ctrl = GNEW(struct spring_electrical_control_s);
ctrl->p = AUTOP; /*a negativve number default to -1. repulsive force = dist^p */
ctrl->random_start = TRUE; /* whether to apply SE from a random layout, or from exisiting layout */
ctrl->K = -1; /* the natural distance. If K < 0, K will be set to the average distance of an edge */
return ctrl;
}
-void spring_electrical_control_delete(spring_electrical_control * ctrl)
+void spring_electrical_control_delete(spring_electrical_control ctrl)
{
free(ctrl);
}
}
-real average_edge_length(SparseMatrix * A, int dim, real * coord)
+real average_edge_length(SparseMatrix A, int dim, real * coord)
{
real dist = 0, d;
int *ia = A->ia, *ja = A->ja, i, j, k;
}
#ifdef ENERGY
-static real spring_electrical_energy(int dim, SparseMatrix * A, real * x,
+static real spring_electrical_energy(int dim, SparseMatrix A, real * x,
real p, real CRK, real KP)
{
/* 1. Grad[||x-y||^k,x] = k||x-y||^(k-1)*0.5*(x-y)/||x-y|| = k/2*||x-y||^(k-2) (x-y)
#endif
-void export_embedding(FILE * fp, int dim, SparseMatrix * A, real * x,
+void export_embedding(FILE * fp, int dim, SparseMatrix A, real * x,
real * width)
{
int i, j, k, *ia = A->ia, *ja = A->ja;
x[dim * j + 1] = sin(ang) * dist + x[dim * i + 1];
}
-static void beautify_leaves(int dim, SparseMatrix * A, real * x)
+static void beautify_leaves(int dim, SparseMatrix A, real * x)
{
int m = A->m, i, j, *ia = A->ia, *ja = A->ja, k;
int *checked, p;
free(leaves);
}
-void spring_electrical_spring_embedding(int dim, SparseMatrix * A0,
- SparseMatrix * D,
- spring_electrical_control * ctrl,
+void spring_electrical_spring_embedding(int dim, SparseMatrix A0,
+ SparseMatrix D,
+ spring_electrical_control ctrl,
real * node_weights, real * x,
int *flag)
{
/* x is a point to a 1D array, x[i*dim+j] gives the coordinate of the i-th node at dimension j. Same as the spring-electrical except we also
introduce force due to spring length
*/
- SparseMatrix *A = A0;
+ SparseMatrix A = A0;
int m, n;
int i, j, k;
real p = ctrl->p, K = ctrl->K, C = ctrl->C, CRK, tol =
real *f = NULL, dist, F, Fnorm = 0, Fnorm0;
int iter = 0;
int adaptive_cooling = ctrl->adaptive_cooling;
- QuadTree *qt = NULL;
+ QuadTree qt = NULL;
int USE_QT = FALSE;
int nsuper = 0, nsupermax = 10;
real *center = NULL, *supernode_wgts = NULL, *distances =
}
-int spring_electrical_embedding(int dim, SparseMatrix * A0,
- spring_electrical_control * ctrl,
+int spring_electrical_embedding(int dim, SparseMatrix A0,
+ spring_electrical_control ctrl,
real * node_weights, real * x)
{
/* x is a point to a 1D array, x[i*dim+j] gives the coordinate of the i-th node at dimension j. */
- SparseMatrix *A = A0;
+ SparseMatrix A = A0;
int m, n;
int i, j, k;
real p = ctrl->p, K = ctrl->K, C = ctrl->C, CRK, tol =
real *f = NULL, dist, F, Fnorm = 0, Fnorm0;
int iter = 0;
int adaptive_cooling = ctrl->adaptive_cooling;
- QuadTree *qt = NULL;
+ QuadTree qt = NULL;
int USE_QT = FALSE;
int nsuper = 0, nsupermax = 10;
real *center = NULL, *supernode_wgts = NULL, *distances =
}
-static void interpolate(int dim, SparseMatrix * A, real * x)
+static void interpolate(int dim, SparseMatrix A, real * x)
{
int i, j, k, *ia = A->ia, *ja = A->ja, nz;
real alpha = 0.5, beta, *y;
free(y);
}
-static void prolongate(int dim, SparseMatrix * A, SparseMatrix * P,
- SparseMatrix * R, real * x, real * y,
+static void prolongate(int dim, SparseMatrix A, SparseMatrix P,
+ SparseMatrix R, real * x, real * y,
int coarsen_scheme_used, real delta)
{
int nc, *ia, *ja, i, j, k;
-int power_law_graph(SparseMatrix * A)
+int power_law_graph(SparseMatrix A)
{
int *mask, m, max = 0, i, *ia = A->ia, *ja = A->ja, j, deg;
int res = FALSE;
}
-int multilevel_spring_electrical_embedding(int dim, SparseMatrix * A0,
- spring_electrical_control *
+int multilevel_spring_electrical_embedding(int dim, SparseMatrix A0,
+ spring_electrical_control
ctrl, real * node_weights,
real * label_sizes, real * x)
{
- Multilevel_control *mctrl = NULL;
+ Multilevel_control mctrl = NULL;
int n, plg, coarsen_scheme_used;
- SparseMatrix *A = A0;
- SparseMatrix *P = NULL;
- Multilevel *grid;
- Multilevel *grid0;
+ SparseMatrix A = A0;
+ SparseMatrix P = NULL;
+ Multilevel grid;
+ Multilevel grid0;
real *xc = NULL, *xf = NULL;
int flag = 0;
#ifdef DEBUG
SMOOTHING_RNG
} smooth_t;
-typedef struct {
+struct spring_electrical_control_s {
real p; /*a negative number default to -1. repulsive force = dist^p */
int random_start; /* whether to apply SE from a random layout, or from exisiting layout */
real K; /* the natural distance. If K < 0, K will be set to the average distance of an edge */
int use_node_weights;
int smoothing;
int overlap;
-} spring_electrical_control;
+};
-spring_electrical_control *spring_electrical_control_new();
-int spring_electrical_embedding(int dim, SparseMatrix * A0,
- spring_electrical_control * ctrl,
+typedef struct spring_electrical_control_s* spring_electrical_control;
+
+spring_electrical_control spring_electrical_control_new();
+int spring_electrical_embedding(int dim, SparseMatrix A0,
+ spring_electrical_control ctrl,
real * node_weights, real * x);
-int multilevel_spring_electrical_embedding(int dim, SparseMatrix * A0,
- spring_electrical_control *
+int multilevel_spring_electrical_embedding(int dim, SparseMatrix A0,
+ spring_electrical_control
ctrl0, real * node_weights,
real * label_sizes, real * x);
-void export_embedding(FILE * fp, int dim, SparseMatrix * A, real * x,
+void export_embedding(FILE * fp, int dim, SparseMatrix A, real * x,
real * width);
-void spring_electrical_control_delete(spring_electrical_control *);
+void spring_electrical_control_delete(spring_electrical_control);
void print_matrix(real * x, int n, int dim);
real distance(real * x, int dim, int i, int j);
real distance_cropped(real * x, int dim, int i, int j);
-real average_edge_length(SparseMatrix * A, int dim, real * coord);
+real average_edge_length(SparseMatrix A, int dim, real * coord);
-void spring_electrical_spring_embedding(int dim, SparseMatrix * A,
- SparseMatrix * D,
- spring_electrical_control * ctrl,
+void spring_electrical_spring_embedding(int dim, SparseMatrix A,
+ SparseMatrix D,
+ spring_electrical_control ctrl,
real * node_weights, real * x,
int *flag);