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; }
int main() { igraph_matrix_t A; igraph_vector_t values; igraph_matrix_t vectors; int i, j; igraph_eigen_which_t which; igraph_rng_seed(igraph_rng_default(), 42 * 42); igraph_matrix_init(&A, DIM, DIM); igraph_matrix_init(&vectors, 0, 0); igraph_vector_init(&values, 0); /* All eigenvalues and eigenvectors */ for (i=0; i<DIM; i++) { for (j=i; j<DIM; j++) { MATRIX(A, i, j) = MATRIX(A, j, i) = igraph_rng_get_integer(igraph_rng_default(), 1, 10); } } which.pos=IGRAPH_EIGEN_LM; which.howmany=5; igraph_eigen_matrix_symmetric(&A, /*sA=*/ 0, /*fun=*/ 0, DIM, /*extra=*/ 0, IGRAPH_EIGEN_LAPACK, &which, /*options=*/ 0, /*storage=*/ 0, &values, &vectors); igraph_vector_print(&values); check_ev(&A, &values, &vectors); which.howmany=8; igraph_eigen_matrix_symmetric(&A, /*sA=*/ 0, /*fun=*/ 0, DIM, /*extra=*/ 0, IGRAPH_EIGEN_LAPACK, &which, /*options=*/ 0, /*storage=*/ 0, &values, &vectors); igraph_vector_print(&values); check_ev(&A, &values, &vectors); which.pos=IGRAPH_EIGEN_BE; which.howmany=5; igraph_eigen_matrix_symmetric(&A, /*sA=*/ 0, /*fun=*/ 0, DIM, /*extra=*/ 0, IGRAPH_EIGEN_LAPACK, &which, /*options=*/ 0, /*storage=*/ 0, &values, &vectors); igraph_vector_print(&values); check_ev(&A, &values, &vectors); which.pos=IGRAPH_EIGEN_SM; which.howmany=5; igraph_eigen_matrix_symmetric(&A, /*sA=*/ 0, /*fun=*/ 0, DIM, /*extra=*/ 0, IGRAPH_EIGEN_LAPACK, &which, /*options=*/ 0, /*storage=*/ 0, &values, &vectors); igraph_vector_print(&values); check_ev(&A, &values, &vectors); igraph_vector_destroy(&values); igraph_matrix_destroy(&vectors); igraph_matrix_destroy(&A); return 0; }
int main() { igraph_matrix_t A; igraph_matrix_t vectors_left, vectors_right; igraph_vector_t values_real, values_imag; int i, j; int info=1; int ilo, ihi; igraph_real_t abnrm; igraph_rng_seed(igraph_rng_default(), 42); igraph_matrix_init(&A, DIM, DIM); igraph_matrix_init(&vectors_left, 0, 0); igraph_matrix_init(&vectors_right, 0, 0); igraph_vector_init(&values_real, 0); igraph_vector_init(&values_imag, 0); for (i=0; i<DIM; i++) { for (j=0; j<DIM; j++) { MATRIX(A, i, j) = igraph_rng_get_integer(igraph_rng_default(), 1, 10); } } igraph_lapack_dgeevx(IGRAPH_LAPACK_DGEEVX_BALANCE_BOTH, &A, &values_real, &values_imag, &vectors_left, &vectors_right, &ilo, &ihi, /*scale=*/ 0, &abnrm, /*rconde=*/ 0, /*rcondv=*/ 0, &info); if (check_ev(&A, &values_real, &values_imag, &vectors_left, &vectors_right, /*tol=*/ 1e-8)) { return 1; } /* igraph_matrix_print(&A); */ /* igraph_vector_print(&values_real); */ /* igraph_vector_print(&values_imag); */ /* igraph_matrix_print(&vectors_left); */ /* igraph_matrix_print(&vectors_right); */ igraph_vector_destroy(&values_imag); igraph_vector_destroy(&values_real); igraph_matrix_destroy(&vectors_right); igraph_matrix_destroy(&vectors_left); igraph_matrix_destroy(&A); return 0; }
int main() { igraph_matrix_t A; igraph_matrix_t values, vectors; igraph_arpack_options_t options; cb2_data_t data = { &A }; int i, j; igraph_rng_seed(igraph_rng_default(), 42 * 42); igraph_matrix_init(&A, DIM, DIM); for (i=0; i<DIM; i++) { for (j=0; j<DIM; j++) { MATRIX(A, i, j) = igraph_rng_get_integer(igraph_rng_default(), -10, 10); } } igraph_arpack_options_init(&options); options.n=DIM; options.start=0; options.nev=4; options.ncv=9; options.which[0]='L' ; options.which[1]='M'; igraph_matrix_init(&values, 0, 0); igraph_matrix_init(&vectors, options.n, 1); igraph_arpack_rnsolve(cb2, /*extra=*/ &data, &options, /*storage=*/ 0, &values, &vectors); if (MATRIX(values, 2, 1) > 0) { MATRIX(values, 2, 1) = -MATRIX(values, 2, 1); MATRIX(values, 3, 1) = -MATRIX(values, 3, 1); } igraph_matrix_print(&values); printf("---\n"); igraph_matrix_print(&vectors); printf("---\n"); /* -------------- */ options.nev=3; options.which[0]='L' ; options.which[1]='M'; igraph_arpack_rnsolve(cb2, /*extra=*/ &data, &options, /*storage=*/ 0, &values, &vectors); if (MATRIX(values, 2, 1) > 0) { MATRIX(values, 2, 1) = -MATRIX(values, 2, 1); } igraph_matrix_print(&values); printf("---\n"); igraph_matrix_print(&vectors); printf("---\n"); /* -------------- */ options.nev=3; options.which[0]='S' ; options.which[1]='R'; igraph_arpack_rnsolve(cb2, /*extra=*/ &data, &options, /*storage=*/ 0, &values, &vectors); igraph_matrix_print(&values); printf("---\n"); igraph_matrix_print(&vectors); printf("---\n"); /* -------------- */ options.nev=3; options.which[0]='L' ; options.which[1]='I'; igraph_arpack_rnsolve(cb2, /*extra=*/ &data, &options, /*storage=*/ 0, &values, &vectors); igraph_matrix_print(&values); printf("---\n"); igraph_matrix_print(&vectors); printf("---\n"); /* -------------- */ igraph_matrix_destroy(&values); igraph_matrix_destroy(&vectors); igraph_matrix_destroy(&A); return 0; }
static PyObject *ignp_fun_propagate(PyObject *self, PyObject *args) { long int num_active = 0; long int num_susc = 1; long int limit = 30; long int i; float lrAct; PyObject* mem_addr_o; long int mem_addr; /* StateTracker Vars */ PyArrayObject *py_trkr; // 'i64' /* By EdgeID */ PyArrayObject *py_tie_r; // 'f32' /* By NodeID */ PyArrayObject *py_act_n; // 'i8' PyArrayObject *py_thr_n; // 'f32' PyArrayObject *py_exp_n; // 'i64' /* By Infection Order*/ PyArrayObject *py_deg; // i64 PyArrayObject *py_nSuc; // i64 PyArrayObject *py_nAct; // i64 PyArrayObject *py_lrAct; // f32 PyArrayObject *py_hom; // i64 PyArrayObject *py_eComp; // i64 PyArrayObject *py_iComp; // i64 PyArrayObject *py_eTri; // i64 PyArrayObject *py_iTri; // i64 PyArrayObject *py_thr; // i32 PyArrayObject *py_exp; // i64 PyArrayObject *py_cTime; // i64 PyObject *g_obj; igraph_t *g; igraph_t gc; long int randID; long int low = 0; long int high = -1; long int ctime = 0; igraph_rng_t *rGen; igraph_vit_t nbr_iter; igraph_vs_t nbr_sel; igraph_integer_t eid; igraph_integer_t vdeg; igraph_integer_t e_comp = 0; igraph_integer_t i_comp = 0; igraph_integer_t e_tri = 0; igraph_integer_t i_tri = 0; int actv_nbr_count; //int res, j; igraph_vector_t temp; //igraph_vector_t actv_nbrs; //PySys_WriteStdout("Parse Started\n"); if (!PyArg_ParseTuple(args, "OO!O!O!O!O!O!O!O!O!O!O!O!O!O!O!O!O!", &g_obj, &PyArray_Type, &py_trkr, // i64 &PyArray_Type, &py_tie_r, // 'f32' &PyArray_Type, &py_act_n, // 'i8' &PyArray_Type, &py_thr_n, // 'i32' &PyArray_Type, &py_exp_n, // 'i64' &PyArray_Type, &py_deg, // i64 &PyArray_Type, &py_nSuc, // i64 &PyArray_Type, &py_nAct, // i64 &PyArray_Type, &py_lrAct, // f32 &PyArray_Type, &py_hom, // i64 &PyArray_Type, &py_eComp, // i64 &PyArray_Type, &py_iComp, // i64 &PyArray_Type, &py_eTri, // i64 &PyArray_Type, &py_iTri, // i64 &PyArray_Type, &py_thr, // i64 &PyArray_Type, &py_exp, // i64 &PyArray_Type, &py_cTime // i64 )) { printf("Parse Failed\n"); Py_RETURN_NONE; } //PySys_WriteStdout("Getting Tracker Vars\n"); num_active = (long) ax_i64(py_trkr, 0); num_susc = (long) ax_i64(py_trkr, 1); limit = (long) ax_i64(py_trkr, 2); mem_addr_o = PyObject_CallMethod(g_obj, "_raw_pointer", "()"); mem_addr = PyInt_AsLong(mem_addr_o); Py_DECREF(mem_addr_o); if (mem_addr == -1) { printf("PyInt to Long Failed"); return NULL; } g = (igraph_t*) mem_addr; //Setup Vars rGen = igraph_rng_default(); //igraph_rng_init(rGen, time(NULL)); high += (long) igraph_vcount(g); //PySys_WriteStdout("Propagate Starting with %li active of target %li with %li open\n", // num_active, limit, num_susc); //Propagate do { // get random node ctime += 1; randID = igraph_rng_get_integer(rGen, low, high); if ( ax_i8(py_act_n, randID) != 1 && ax_i64(py_exp_n, randID)>=ax_i32(py_thr_n, randID) ){ //activate ax_i8(py_act_n,randID) = 1; lrAct = 0; //update nbrs actv_nbr_count = 0; igraph_vs_adj( &nbr_sel, randID, IGRAPH_ALL); igraph_vit_create(g, nbr_sel, &nbr_iter); igraph_vs_size(g, &nbr_sel, &vdeg); igraph_vector_init(&temp, vdeg); while( !IGRAPH_VIT_END(nbr_iter) ){ i = (long int) IGRAPH_VIT_GET(nbr_iter); ax_i64( py_exp_n, i ) += 1; /* update active nbr count and collect id of active */ if ( ax_i8(py_act_n, i) == i ) { VECTOR(temp)[actv_nbr_count]=i; actv_nbr_count += 1; } /* update num_susc */ if ( ax_i8(py_act_n, i) == 0 && \ ax_i32(py_thr_n, i) > (float) (ax_i64(py_exp_n, i)-1) && \ ax_i32(py_thr_n, i) <= (float) ax_i64(py_exp_n, i) ){ /*PySys_WriteStdout("%li < %i <= %li\n", (ax_i64(py_exp_n, i)-1), ax_i32(py_thr_n, i), ax_i64(py_exp_n, i) );*/ num_susc += 1; } /* Get #active long ties */ if ( ax_i8(py_act_n, i) == 1 ){ igraph_get_eid(g, &eid, randID, i, 0, 1); lrAct += ax_f32( py_tie_r, eid )>2 ; } IGRAPH_VIT_NEXT(nbr_iter); } igraph_vit_destroy(&nbr_iter); igraph_vs_destroy(&nbr_sel); //Compute Components (among all and active nbrs) igraph_vs_adj( &nbr_sel, randID, IGRAPH_ALL); igraph_induced_subgraph(g, &gc, nbr_sel, IGRAPH_SUBGRAPH_CREATE_FROM_SCRATCH); igraph_clusters(&gc, NULL, NULL, &e_comp, IGRAPH_WEAK); e_tri = igraph_vcount(&gc); igraph_destroy(&gc); igraph_vs_destroy(&nbr_sel); igraph_induced_subgraph(g, &gc, igraph_vss_vector(&temp), \ IGRAPH_SUBGRAPH_CREATE_FROM_SCRATCH); igraph_clusters(&gc, NULL, NULL, &i_comp, IGRAPH_WEAK); i_tri = igraph_vcount(&gc); //Clean up igraph_destroy(&gc); igraph_vector_destroy(&temp); //PySys_WriteStdout("e_comp: %i, i_comp: %i\n", e_comp, i_comp); //PySys_WriteStdout("e_tri: %i, i_tri: %i\n", e_tri, i_tri); //update tracking vars ax_f32( py_lrAct, num_active ) = (npy_float32) lrAct; ax_i32( py_thr, num_active) = ax_i32(py_thr_n, randID); ax_i64( py_deg, num_active) = (npy_int64) vdeg; ax_i64( py_nSuc, num_active) = (npy_int64) num_susc; ax_i64( py_nAct, num_active) = (npy_int64) num_active; //ax_i64( py_hom, num_active) = (npy_int64) num_susc; ax_i64( py_eComp, num_active) = (npy_int64) e_comp; ax_i64( py_iComp, num_active) = (npy_int64) i_comp; ax_i64( py_eTri, num_active) = (npy_int64) e_tri; ax_i64( py_iTri, num_active) = (npy_int64) i_tri; ax_i64( py_exp, num_active) = ax_i64(py_exp_n, randID); ax_i64( py_cTime, num_active) = (npy_int64) ctime; num_active += 1; } } while( num_susc > num_active && num_active < limit); //PySys_WriteStdout("Propagate Finished with %li active of target %li with %li open\n", // num_active, limit, num_susc); //igraph_rng_destroy(rGen); ax_i64(py_trkr, 0) = (npy_int64) num_active; ax_i64(py_trkr, 1) = (npy_int64) num_susc ; ax_i64(py_trkr, 2) = (npy_int64) limit ; Py_RETURN_NONE; }