int main() {
  
  const int nodes=10, skip=3;
  igraph_matrix_t mat2;
  igraph_vector_complex_t values, values2;
  igraph_matrix_complex_t vectors, vectors2;
  igraph_eigen_which_t which;
  int i;

  igraph_rng_seed(igraph_rng_default(), 42);
  igraph_matrix_init(&mat2, nodes, nodes);
  for (i=0; i<nodes; i++) {
    int j;
    for (j=0; j<nodes; j++) {
      MATRIX(mat2, i, j) = igraph_rng_get_integer(igraph_rng_default(), 1, 10);
    }
  }

  igraph_vector_complex_init(&values, 0);
  igraph_matrix_complex_init(&vectors, 0, 0);
  which.pos=IGRAPH_EIGEN_LI;
  which.howmany=nodes;
  igraph_eigen_matrix(&mat2, /*sparsemat=*/ 0, /*fun=*/ 0, nodes, 
		      /*extra=*/ 0, IGRAPH_EIGEN_LAPACK, &which,
		      /*options=*/ 0, /*storage=*/ 0, &values, &vectors);
  
  igraph_vector_complex_init(&values2, 0);
  igraph_matrix_complex_init(&vectors2, 0, 0);
  which.pos=IGRAPH_EIGEN_SI;
  which.howmany=nodes;
  igraph_eigen_matrix(&mat2, /*sparsemat=*/ 0, /*fun=*/ 0, nodes, 
		      /*extra=*/ 0, IGRAPH_EIGEN_LAPACK, &which, 
		      /*options=*/ 0, /*storage=*/ 0, &values2, &vectors2);

  igraph_vector_complex_print(&values);
  igraph_vector_complex_print(&values2);

  for (i=0; i<nodes; i++) { 
    int j;
    igraph_real_t d=
      igraph_complex_abs(igraph_complex_sub(VECTOR(values)[i],
					    VECTOR(values2)[nodes-i-1]));
    if (d > 1e-15) { DUMP(); return 2; }
    for (j=0; j<nodes; j++) { 
      igraph_real_t d=
	igraph_complex_abs(igraph_complex_sub(MATRIX(vectors, j, i), 
					      MATRIX(vectors2, j,
						     nodes-i-1)));
      if (d > 1e-15) { DUMP(); return 3; }
    }
  }

  igraph_vector_complex_destroy(&values);
  igraph_matrix_complex_destroy(&vectors);
  igraph_vector_complex_destroy(&values2);
  igraph_matrix_complex_destroy(&vectors2);
  igraph_matrix_destroy(&mat2);
  
  return 0;
}
Exemple #2
0
int igraph_vector_complex_create_polar(igraph_vector_complex_t *v,
				       const igraph_vector_t *r,
				       const igraph_vector_t *theta) {
  int i, n=igraph_vector_size(r);
  if (n != igraph_vector_size(theta)) {
    IGRAPH_ERROR("'r' and 'theta' vector sizes don't match", IGRAPH_EINVAL);
  }
  
  IGRAPH_CHECK(igraph_vector_complex_init(v, n));
  /* FINALLY not needed */
  
  for (i=0; i<n; i++) {
    VECTOR(*v)[i] = igraph_complex_polar(VECTOR(*r)[i], VECTOR(*theta)[i]);
  }

  return 0;
}
Exemple #3
0
int igraph_vector_complex_create(igraph_vector_complex_t *v,
				 const igraph_vector_t *real,
				 const igraph_vector_t *imag) {
  int i, n=igraph_vector_size(real);
  if (n != igraph_vector_size(imag)) {
    IGRAPH_ERROR("Real and imag vector sizes don't match", IGRAPH_EINVAL);
  }
  
  IGRAPH_CHECK(igraph_vector_complex_init(v, n));
  /* FINALLY not needed */
  
  for (i=0; i<n; i++) {
    VECTOR(*v)[i] = igraph_complex(VECTOR(*real)[i], VECTOR(*imag)[i]);
  }

  return 0;
}
Exemple #4
0
int main() {

  igraph_t g;
  igraph_vector_t ev;
  igraph_t scg_graph;
  igraph_matrix_t scg_matrix;
  igraph_sparsemat_t scg_sparsemat;
  igraph_matrix_t L, R;
  igraph_sparsemat_t Lsparse, Rsparse;
  igraph_vector_t groups;
  igraph_vector_complex_t eval;
  igraph_matrix_complex_t evec;
  
  igraph_tree(&g, 10, /* children= */ 3, IGRAPH_TREE_UNDIRECTED);
  
  igraph_vector_init(&ev, 1);
  igraph_matrix_init(&L, 0, 0);
  igraph_matrix_init(&R, 0, 0);
  igraph_matrix_init(&scg_matrix, 0, 0);
  igraph_vector_init(&groups, 0);
  igraph_vector_complex_init(&eval, 0);
  igraph_matrix_complex_init(&evec, 0, 0);

#define CALLLAP() do {							 \
    igraph_vector_resize(&groups, 0);					 \
    igraph_vector_complex_resize(&eval, 0);				 \
    igraph_matrix_complex_resize(&evec, 0, 0);				 \
    igraph_scg_laplacian(&g, /*matrix=*/ 0, /*sparsemat=*/ 0, &ev,	 \
			 /* intervals= */ 2, /* intervals_vector= */ 0, \
			 /* algorithm= */ IGRAPH_SCG_EXACT,		\
			 IGRAPH_SCG_NORM_ROW,				\
			 IGRAPH_SCG_DIRECTION_DEFAULT, &eval, &evec,	\
			 &groups, /* use_arpack= */ 0,			\
			 /* maxiter= */ 0, &scg_graph, &scg_matrix,	\
			 &scg_sparsemat, &L, &R,			\
			 &Lsparse, &Rsparse);				\
} while (0)

#define PRINTRES()						\
  do {								\
    printf("--------------------------------\n");		\
    igraph_vector_print(&groups);				\
    printf("---\n");						\
    igraph_vector_complex_print(&eval);				\
    igraph_matrix_complex_print(&evec);				\
    printf("---\n");						\
    igraph_write_graph_edgelist(&scg_graph, stdout);		\
    printf("---\n");						\
    igraph_sparsemat_print(&scg_sparsemat, stdout);		\
    printf("---\n");						\
    igraph_sparsemat_print(&Lsparse, stdout);			\
    printf("---\n");						\
    igraph_sparsemat_print(&Rsparse, stdout);			\
    printf("---\n");						\
  } while (0)

  VECTOR(ev)[0] = 1;
  CALLLAP();
  PRINTRES();
  igraph_destroy(&scg_graph);
  igraph_sparsemat_destroy(&scg_sparsemat);
  igraph_sparsemat_destroy(&Lsparse);
  igraph_sparsemat_destroy(&Rsparse);

  VECTOR(ev)[0] = 3;
  CALLLAP();
  PRINTRES();
  igraph_destroy(&scg_graph);
  igraph_sparsemat_destroy(&scg_sparsemat);
  igraph_sparsemat_destroy(&Lsparse);
  igraph_sparsemat_destroy(&Rsparse);

  igraph_vector_resize(&ev, 2);
  VECTOR(ev)[0] = 1; VECTOR(ev)[1] = 3;
  CALLLAP();
  PRINTRES();
  igraph_destroy(&scg_graph);
  igraph_sparsemat_destroy(&scg_sparsemat);
  igraph_sparsemat_destroy(&Lsparse);
  igraph_sparsemat_destroy(&Rsparse);

  igraph_matrix_complex_destroy(&evec);
  igraph_vector_complex_destroy(&eval);
  igraph_vector_destroy(&groups);
  igraph_matrix_destroy(&scg_matrix);
  igraph_matrix_destroy(&L);
  igraph_matrix_destroy(&R);
  igraph_vector_destroy(&ev);
  igraph_destroy(&g);

  /* -------------------------------------------------------------------- */

  return 0;
}