From 82d111f087af65d7ea99f1a77e2025cc982c382b Mon Sep 17 00:00:00 2001 From: Alex Gutteridge Date: Wed, 11 Feb 2009 15:35:36 +0000 Subject: [PATCH] Corrected for Ruby 1.9 and iGraph 0.5.1 --- Rakefile.rb | 8 +-- ext/cIGraph.c | 6 +-- ext/cIGraph_add_delete.c | 14 ++--- ext/cIGraph_attribute_handler.c | 34 ++++++------ ext/cIGraph_centrality.c | 4 +- ext/cIGraph_community.c | 50 ++++++++--------- ext/cIGraph_connectivity.c | 8 --- ext/cIGraph_dijkstra.c | 8 +-- ext/cIGraph_file.c | 74 ++++++++++++++------------ ext/cIGraph_generators_deterministic.c | 4 +- ext/cIGraph_generators_random.c | 32 +++++------ ext/cIGraph_layout.c | 8 +-- ext/cIGraph_matrix.c | 6 +-- ext/cIGraph_min_cuts.c | 16 +++--- ext/cIGraph_motif.c | 12 ++--- ext/cIGraph_shortest_paths.c | 4 +- ext/cIGraph_spanning.c | 6 +-- ext/cIGraph_utility.c | 4 +- test/tc_add_delete.rb | 4 +- test/tc_basic_query.rb | 2 +- test/tc_cliques.rb | 2 +- test/tc_dijkstra.rb | 2 +- test/tc_file_read_write.rb | 6 +-- test/tc_independent_vertex_sets.rb | 8 +-- test/tc_other_ops.rb | 2 +- 25 files changed, 160 insertions(+), 164 deletions(-) diff --git a/Rakefile.rb b/Rakefile.rb index 04657e0..fd74a75 100644 --- a/Rakefile.rb +++ b/Rakefile.rb @@ -6,10 +6,10 @@ class IGraph VERSION = "0.9.5" end -begin - require 'igraph' -rescue RuntimeError -end +#begin +# require 'igraph' +#rescue RuntimeError +#end hoe = Hoe.new("igraph",IGraph::VERSION) do |p| diff --git a/ext/cIGraph.c b/ext/cIGraph.c index f0759ff..695e7f6 100644 --- a/ext/cIGraph.c +++ b/ext/cIGraph.c @@ -121,8 +121,8 @@ VALUE cIGraph_initialize(int argc, VALUE *argv, VALUE self){ IGRAPH_CHECK(igraph_to_undirected(graph,IGRAPH_TO_UNDIRECTED_COLLAPSE)); //Loop through objects in edge Array - for (i=0; ilen; i++) { - vertex = RARRAY(edges)->ptr[i]; + for (i=0; iptr[i/2]); + rb_ary_push((VALUE)e_attr_rec.value,RARRAY_PTR(attrs)[i/2]); } else { rb_ary_push((VALUE)e_attr_rec.value,Qnil); } diff --git a/ext/cIGraph_add_delete.c b/ext/cIGraph_add_delete.c index ebe45bd..6069b30 100644 --- a/ext/cIGraph_add_delete.c +++ b/ext/cIGraph_add_delete.c @@ -50,8 +50,8 @@ VALUE cIGraph_add_edges(int argc, VALUE *argv, VALUE self){ v_ary = ((VALUE*)graph->attr)[0]; //Loop through objects in edge Array - for (i=0; ilen; i++) { - vertex = RARRAY(edges)->ptr[i]; + for (i=0; iptr[i/2]); + rb_ary_push((VALUE)e_attr_rec.value,RARRAY_PTR(attrs)[i/2]); } else { rb_ary_push((VALUE)e_attr_rec.value,Qnil); } @@ -118,17 +118,17 @@ VALUE cIGraph_add_vertices(VALUE self, VALUE vs){ Data_Get_Struct(self, igraph_t, graph); v_ary = ((VALUE*)graph->attr)[0]; - to_add = RARRAY(vs)->len; + to_add = RARRAY_LEN(vs); //Loop through objects in vertex array - for (i=0; ilen; i++) { - vertex = RARRAY(vs)->ptr[i]; + for (i=0; iptr[i]); + rb_ary_push((VALUE)v_attr_rec.value,RARRAY_PTR(vs)[i]); } } diff --git a/ext/cIGraph_attribute_handler.c b/ext/cIGraph_attribute_handler.c index 4423a4c..9bbbec6 100644 --- a/ext/cIGraph_attribute_handler.c +++ b/ext/cIGraph_attribute_handler.c @@ -194,8 +194,8 @@ int cIGraph_attribute_add_vertices(igraph_t *graph, long int nv, igraph_vector_p values = (VALUE)((igraph_i_attribute_record_t*)VECTOR(*attr)[0])->value; Check_Type(values, T_ARRAY); - for(i=0;ilen;i++){ - rb_ary_push(vertex_array, RARRAY(values)->ptr[i]); + for(i=0;itype == IGRAPH_ATTRIBUTE_PY_OBJECT){ values = (VALUE)((igraph_i_attribute_record_t*)VECTOR(*attr)[0])->value; Check_Type(values, T_ARRAY); - for(i=0;ilen;i++){ - rb_ary_push(edge_array, RARRAY(values)->ptr[i]); + for(i=0;iattr)[i]; - VALUE obj = RARRAY(store)->ptr[0]; + VALUE obj = RARRAY_PTR(store)[0]; obj_hash = Qnil; if(rb_funcall(obj, rb_intern("respond_to?"), 1, rb_str_new2("to_hash")) == Qtrue){ @@ -468,9 +468,9 @@ int cIGraph_attribute_get_info(const igraph_t *graph, } //Push names onto n and types onto t - for(j=0;jlen;j++){ - igraph_strvector_add(n, RSTRING(RARRAY(rb_names)->ptr[j])->ptr); - igraph_vector_push_back(t, NUM2INT(RARRAY(rb_types)->ptr[j])); + for(j=0;jattr)[attrnum]; if (attrnum != 2) - obj = RARRAY(obj)->ptr[0]; + obj = RARRAY_PTR(obj)[0]; if(TYPE(obj) == T_HASH && rb_funcall(obj,rb_intern("include?"), 1, rb_str_new2(name))){ res = 1; @@ -541,7 +541,7 @@ int cIGraph_attribute_get_type(const igraph_t *graph, obj = ((VALUE*)graph->attr)[attrnum]; if (attrnum != 2) - obj = RARRAY(obj)->ptr[0]; + obj = RARRAY_PTR(obj)[0]; rb_funcall(obj,rb_intern("include?"), 1, rb_str_new2(name)); @@ -597,7 +597,7 @@ int cIGraph_get_string_graph_attr(const igraph_t *graph, VALUE val; val = rb_hash_aref(((VALUE*)graph->attr)[2],rb_str_new2(name)); - igraph_strvector_set(value,0,RSTRING(val)->ptr); + igraph_strvector_set(value,0,RSTRING_PTR(val)); #ifdef DEBUG printf("Leaving cIGraph_get_string_graph_attr\n"); @@ -626,7 +626,7 @@ int cIGraph_get_numeric_vertex_attr(const igraph_t *graph, IGRAPH_CHECK(igraph_vector_resize(value, IGRAPH_VIT_SIZE(it))); while(!IGRAPH_VIT_END(it)){ - vertex = RARRAY(array)->ptr[(int)IGRAPH_VIT_GET(it)]; + vertex = RARRAY_PTR(array)[(int)IGRAPH_VIT_GET(it)]; val = rb_hash_aref(vertex,rb_str_new2(name)); if(val == Qnil) @@ -667,13 +667,13 @@ int cIGraph_get_string_vertex_attr(const igraph_t *graph, IGRAPH_CHECK(igraph_strvector_resize(value, IGRAPH_VIT_SIZE(it))); while(!IGRAPH_VIT_END(it)){ - vertex = RARRAY(array)->ptr[(int)IGRAPH_VIT_GET(it)]; + vertex = RARRAY_PTR(array)[(int)IGRAPH_VIT_GET(it)]; val = rb_hash_aref(vertex,rb_str_new2(name)); if(val == Qnil) val = rb_str_new2(""); - igraph_strvector_set(value,i,RSTRING(val)->ptr); + igraph_strvector_set(value,i,RSTRING_PTR(val)); IGRAPH_VIT_NEXT(it); i++; } @@ -708,7 +708,7 @@ int cIGraph_get_numeric_edge_attr(const igraph_t *graph, IGRAPH_CHECK(igraph_vector_resize(value, IGRAPH_EIT_SIZE(it))); while(!IGRAPH_EIT_END(it)){ - vertex = RARRAY(array)->ptr[(int)IGRAPH_EIT_GET(it)]; + vertex = RARRAY_PTR(array)[(int)IGRAPH_EIT_GET(it)]; val = rb_hash_aref(vertex,rb_str_new2(name)); if(val == Qnil) @@ -749,7 +749,7 @@ int cIGraph_get_string_edge_attr(const igraph_t *graph, IGRAPH_CHECK(igraph_strvector_resize(value, IGRAPH_EIT_SIZE(it))); while(!IGRAPH_EIT_END(it)){ - edge = RARRAY(array)->ptr[(int)IGRAPH_EIT_GET(it)]; + edge = RARRAY_PTR(array)[(int)IGRAPH_EIT_GET(it)]; val = rb_hash_aref(edge,rb_str_new2(name)); @@ -759,7 +759,7 @@ int cIGraph_get_string_edge_attr(const igraph_t *graph, //Fix for floats when required by ncol write val = rb_funcall(val,rb_intern("to_s"),0); - igraph_strvector_set(value,i,RSTRING(val)->ptr); + igraph_strvector_set(value,i,RSTRING_PTR(val)); IGRAPH_EIT_NEXT(it); i++; } diff --git a/ext/cIGraph_centrality.c b/ext/cIGraph_centrality.c index 5465b0e..4ac58a1 100644 --- a/ext/cIGraph_centrality.c +++ b/ext/cIGraph_centrality.c @@ -213,8 +213,8 @@ VALUE cIGraph_constraint(int argc, VALUE *argv, VALUE self){ if(weights == Qnil){ IGRAPH_CHECK(igraph_constraint(graph,&res,vids,NULL)); } else { - for(i=0;ilen;i++){ - IGRAPH_CHECK(igraph_vector_push_back(&wght,NUM2DBL(RARRAY(weights)->ptr[i]))); + for(i=0;ilen;i++){ - group = RARRAY(groups)->ptr[i]; - for(j=0;jlen;j++){ + for(i=0;iptr[j]),i); + cIGraph_get_vertex_id(self,RARRAY_PTR(group)[j]),i); } } @@ -84,10 +84,10 @@ VALUE cIGraph_community_to_membership(VALUE self, VALUE merge, VALUE steps, VALU for(i=0;iptr[groupid] == Qnil){ - RARRAY(groups)->ptr[groupid] = rb_ary_new(); + if(RARRAY_PTR(groups)[groupid] == Qnil){ + RARRAY_PTR(groups)[groupid] = rb_ary_new(); } - rb_ary_push(RARRAY(groups)->ptr[groupid], + rb_ary_push(RARRAY_PTR(groups)[groupid], cIGraph_get_vertex_object(self, i)); } @@ -132,9 +132,9 @@ VALUE cIGraph_community_spinglass(VALUE self, VALUE weights, VALUE spins, VALUE igraph_vector_init(&membership,0); - igraph_vector_init(&weights_vec,RARRAY(weights)->len); - for(i=0;ilen;i++){ - VECTOR(weights_vec)[i] = NUM2DBL(RARRAY(weights)->ptr[i]); + igraph_vector_init(&weights_vec,RARRAY_LEN(weights)); + for(i=0;iptr[groupid]; + group = RARRAY_PTR(groups)[groupid]; rb_ary_push(group,cIGraph_get_vertex_object(self, i)); } @@ -206,9 +206,9 @@ VALUE cIGraph_community_spinglass_single(VALUE self, VALUE weights, VALUE vertex igraph_vector_init(&community,0); - igraph_vector_init(&weights_vec,RARRAY(weights)->len); - for(i=0;ilen;i++){ - VECTOR(weights_vec)[i] = NUM2DBL(RARRAY(weights)->ptr[i]); + igraph_vector_init(&weights_vec,RARRAY_LEN(weights)); + for(i=0;iptr[groupid]; + group = RARRAY_PTR(groups)[groupid]; rb_ary_push(group,cIGraph_get_vertex_object(self, i)); } @@ -352,7 +352,7 @@ igraph_arpack_options_init(&arpack_opt); if(groupid == -1) groupid = 0; - group = RARRAY(groups)->ptr[groupid]; + group = RARRAY_PTR(groups)[groupid]; rb_ary_push(group,cIGraph_get_vertex_object(self, i)); } @@ -396,12 +396,12 @@ igraph_arpack_options_init(&arpack_opt); igraph_vector_init(&membership_vec,igraph_vcount(graph)); igraph_vector_init(&eigenvector,0); - for(i=0;ilen;i++){ - group = RARRAY(membership)->ptr[i]; + for(i=0;ilen;j++){ + for(j=0;jptr[j]; + obj = RARRAY_PTR(group)[j]; vid = cIGraph_get_vertex_id(self,obj); VECTOR(membership_vec)[vid] = i; @@ -431,7 +431,7 @@ igraph_arpack_options_init(&arpack_opt); if(groupid == -1) groupid = 0; - group = RARRAY(groups)->ptr[groupid]; + group = RARRAY_PTR(groups)[groupid]; rb_ary_push(group,cIGraph_get_vertex_object(self, i)); } @@ -478,8 +478,8 @@ VALUE cIGraph_community_walktrap(VALUE self, VALUE weights, VALUE steps){ igraph_vector_init(&weights_vec,0); igraph_vector_init(&modularity,0); - for(i=0;ilen;i++){ - VECTOR(weights_vec)[i] = NUM2DBL(RARRAY(weights)->ptr[i]); + for(i=0;ilen;i++){ - igraph_vector_push_back(&edges_vec,NUM2INT(RARRAY(edges)->ptr[i])); + for(i=0;ilen); + igraph_vector_init(&wghts,RARRAY_LEN(weights)); - for(i=0;ilen;i++){ - VECTOR(wghts)[i] = NUM2DBL(RARRAY(weights)->ptr[i]); + for(i=0;ilen; + n_paths = RARRAY_LEN(to); //vector to hold the results of the calculations igraph_vector_ptr_init(&res,0); diff --git a/ext/cIGraph_file.c b/ext/cIGraph_file.c index 86347bb..371fc62 100644 --- a/ext/cIGraph_file.c +++ b/ext/cIGraph_file.c @@ -35,7 +35,7 @@ VALUE cIGraph_read_graph_edgelist(VALUE self, VALUE file, VALUE directed){ Data_Get_Struct(new_graph, igraph_t, graph); string = rb_funcall(file, rb_intern("read"), 0); - stream = fmemopen(RSTRING(string)->ptr,RSTRING(string)->len, "r"); + stream = fmemopen(RSTRING_PTR(string),RSTRING_LEN(string), "r"); igraph_read_graph_edgelist(graph, stream, 0, directed_b); @@ -156,16 +156,16 @@ VALUE cIGraph_read_graph_ncol(VALUE self, VALUE file, VALUE predefnames, VALUE n new_graph = cIGraph_alloc(cIGraph); Data_Get_Struct(new_graph, igraph_t, graph); - igraph_strvector_init(&names_vec,RARRAY(predefnames)->len); + igraph_strvector_init(&names_vec,RARRAY_LEN(predefnames)); - for(i=0;ilen;i++){ - igraph_strvector_set(&names_vec, i, RSTRING(RARRAY(predefnames)->ptr[i])->ptr); + for(i=0;iptr,RSTRING(string)->len, "r"); + stream = fmemopen(RSTRING_PTR(string),RSTRING_LEN(string), "r"); - if (RARRAY(predefnames)->len == 0){ + if (RARRAY_LEN(predefnames) == 0){ igraph_read_graph_ncol(graph, stream, NULL, names_b, weights_b, directed_b); } else { igraph_read_graph_ncol(graph, stream, &names_vec, names_b, weights_b, directed_b); @@ -177,8 +177,8 @@ VALUE cIGraph_read_graph_ncol(VALUE self, VALUE file, VALUE predefnames, VALUE n if(names){ v_ary = ((VALUE*)graph->attr)[0]; new_ary = rb_ary_new(); - for(i=0;ilen;i++){ - rb_ary_push(new_ary, rb_hash_aref(RARRAY(v_ary)->ptr[i], rb_str_new2("name"))); + for(i=0;iattr)[0] = new_ary; } @@ -186,8 +186,8 @@ VALUE cIGraph_read_graph_ncol(VALUE self, VALUE file, VALUE predefnames, VALUE n if(weights){ e_ary = ((VALUE*)graph->attr)[1]; new_ary = rb_ary_new(); - for(i=0;ilen;i++){ - rb_ary_push(new_ary, rb_hash_aref(RARRAY(e_ary)->ptr[i], rb_str_new2("weight"))); + for(i=0;iattr)[1] = new_ary; } @@ -224,8 +224,8 @@ VALUE cIGraph_write_graph_ncol(VALUE self, VALUE file, VALUE names, VALUE weight igraph_t *graph; int e, i; - VALUE v_ary; - VALUE e_ary; + VALUE v_ary = Qnil; + VALUE e_ary = Qnil; VALUE new_v_ary; VALUE new_e_ary; @@ -248,9 +248,9 @@ VALUE cIGraph_write_graph_ncol(VALUE self, VALUE file, VALUE names, VALUE weight if(names){ v_ary = ((VALUE*)graph->attr)[0]; new_v_ary = rb_ary_new(); - for(i=0;ilen;i++){ + for(i=0;iptr[i])); + rb_hash_aset(vertex_h, rb_str_new2("name"), StringValue(RARRAY_PTR(v_ary)[i])); rb_ary_push(new_v_ary, vertex_h); } ((VALUE*)graph->attr)[0] = new_v_ary; @@ -258,9 +258,9 @@ VALUE cIGraph_write_graph_ncol(VALUE self, VALUE file, VALUE names, VALUE weight if(weights){ e_ary = ((VALUE*)graph->attr)[1]; new_e_ary = rb_ary_new(); - for(i=0;ilen;i++){ + for(i=0;iptr[i],rb_intern("to_f"),0)); + rb_hash_aset(edge_h, rb_str_new2("weight"), rb_funcall(RARRAY_PTR(e_ary)[i],rb_intern("to_f"),0)); rb_ary_push(new_e_ary, edge_h); } ((VALUE*)graph->attr)[1] = new_e_ary; @@ -342,7 +342,7 @@ VALUE cIGraph_read_graph_lgl(VALUE self, VALUE file, VALUE names, VALUE weights) Data_Get_Struct(new_graph, igraph_t, graph); string = rb_funcall(file, rb_intern("read"), 0); - stream = fmemopen(RSTRING(string)->ptr,RSTRING(string)->len, "r"); + stream = fmemopen(RSTRING_PTR(string),RSTRING_LEN(string), "r"); igraph_read_graph_lgl(graph, stream, names_b, weights_b); @@ -352,8 +352,8 @@ VALUE cIGraph_read_graph_lgl(VALUE self, VALUE file, VALUE names, VALUE weights) if(names){ v_ary = ((VALUE*)graph->attr)[0]; new_ary = rb_ary_new(); - for(i=0;ilen;i++){ - rb_ary_push(new_ary, rb_hash_aref(RARRAY(v_ary)->ptr[i], rb_str_new2("name"))); + for(i=0;iattr)[0] = new_ary; } @@ -361,8 +361,8 @@ VALUE cIGraph_read_graph_lgl(VALUE self, VALUE file, VALUE names, VALUE weights) if(weights){ e_ary = ((VALUE*)graph->attr)[1]; new_ary = rb_ary_new(); - for(i=0;ilen;i++){ - rb_ary_push(new_ary, rb_hash_aref(RARRAY(e_ary)->ptr[i], rb_str_new2("weight"))); + for(i=0;iattr)[1] = new_ary; } @@ -400,8 +400,8 @@ VALUE cIGraph_write_graph_lgl(VALUE self, VALUE file, VALUE names, VALUE weights igraph_t *graph; int e, i; - VALUE v_ary; - VALUE e_ary; + VALUE v_ary = Qnil; + VALUE e_ary = Qnil; VALUE new_v_ary; VALUE new_e_ary; @@ -429,9 +429,9 @@ VALUE cIGraph_write_graph_lgl(VALUE self, VALUE file, VALUE names, VALUE weights if(names){ v_ary = ((VALUE*)graph->attr)[0]; new_v_ary = rb_ary_new(); - for(i=0;ilen;i++){ + for(i=0;iptr[i])); + rb_hash_aset(vertex_h, rb_str_new2("name"), StringValue(RARRAY_PTR(v_ary)[i])); rb_ary_push(new_v_ary, vertex_h); } ((VALUE*)graph->attr)[0] = new_v_ary; @@ -439,9 +439,9 @@ VALUE cIGraph_write_graph_lgl(VALUE self, VALUE file, VALUE names, VALUE weights if(weights){ e_ary = ((VALUE*)graph->attr)[1]; new_e_ary = rb_ary_new(); - for(i=0;ilen;i++){ + for(i=0;iptr[i],rb_intern("to_f"),0)); + rb_hash_aset(edge_h, rb_str_new2("weight"), rb_funcall(RARRAY_PTR(e_ary)[i],rb_intern("to_f"),0)); rb_ary_push(new_e_ary, edge_h); } ((VALUE*)graph->attr)[1] = new_e_ary; @@ -501,6 +501,8 @@ VALUE cIGraph_read_graph_dimacs(VALUE self, VALUE file, VALUE directed){ igraph_integer_t source; igraph_integer_t target; igraph_vector_t capacity; + igraph_vector_t label; + igraph_strvector_t problem; igraph_t *graph; igraph_bool_t directed_b = 0; @@ -518,14 +520,16 @@ VALUE cIGraph_read_graph_dimacs(VALUE self, VALUE file, VALUE directed){ directed_b = 1; igraph_vector_init(&capacity, 0); + igraph_vector_init(&label, 0); + igraph_strvector_init(&problem, 0); new_graph = cIGraph_alloc(cIGraph); Data_Get_Struct(new_graph, igraph_t, graph); string = rb_funcall(file, rb_intern("read"), 0); - stream = fmemopen(RSTRING(string)->ptr,RSTRING(string)->len, "r"); + stream = fmemopen(RSTRING_PTR(string),RSTRING_LEN(string), "r"); - igraph_read_graph_dimacs(graph, stream, &source, &target, &capacity, directed_b); + igraph_read_graph_dimacs(graph, stream, &problem, &label, &source, &target, &capacity, directed_b); fclose(stream); @@ -590,8 +594,8 @@ VALUE cIGraph_write_graph_dimacs(VALUE self, VALUE file, VALUE source, VALUE tar igraph_vector_init(&capacity_v,0); - for(i=0;ilen;i++){ - igraph_vector_push_back(&capacity_v,NUM2DBL(RARRAY(capacity)->ptr[i])); + for(i=0;iptr,RSTRING(string)->len, "r"); + stream = fmemopen(RSTRING_PTR(string),RSTRING_LEN(string), "r"); igraph_read_graph_graphdb(graph, stream, directed_b); @@ -685,7 +689,7 @@ VALUE cIGraph_read_graph_graphml(VALUE self, VALUE file, VALUE index){ Data_Get_Struct(new_graph, igraph_t, graph); string = rb_funcall(file, rb_intern("read"), 0); - stream = fmemopen(RSTRING(string)->ptr,RSTRING(string)->len, "r"); + stream = fmemopen(RSTRING_PTR(string),RSTRING_LEN(string), "r"); igraph_read_graph_graphml(graph, stream, NUM2INT(index)); @@ -749,7 +753,7 @@ VALUE cIGraph_read_graph_gml(VALUE self, VALUE file){ Data_Get_Struct(new_graph, igraph_t, graph); string = rb_funcall(file, rb_intern("read"), 0); - stream = fmemopen(RSTRING(string)->ptr,RSTRING(string)->len, "r"); + stream = fmemopen(RSTRING_PTR(string),RSTRING_LEN(string), "r"); igraph_read_graph_gml(graph, stream); @@ -808,7 +812,7 @@ VALUE cIGraph_read_graph_pajek(VALUE self, VALUE file){ Data_Get_Struct(new_graph, igraph_t, graph); string = rb_funcall(file, rb_intern("read"), 0); - stream = fmemopen(RSTRING(string)->ptr,RSTRING(string)->len, "r"); + stream = fmemopen(RSTRING_PTR(string),RSTRING_LEN(string), "r"); IGRAPH_CHECK(igraph_read_graph_pajek(graph, stream)); diff --git a/ext/cIGraph_generators_deterministic.c b/ext/cIGraph_generators_deterministic.c index 7d1b465..7d46d3a 100644 --- a/ext/cIGraph_generators_deterministic.c +++ b/ext/cIGraph_generators_deterministic.c @@ -112,8 +112,8 @@ VALUE cIGraph_lattice(VALUE self, VALUE dim, VALUE directed, VALUE mutual, VALUE Data_Get_Struct(new_graph, igraph_t, graph); igraph_vector_init(&dimvector,0); - for(i=0; ilen; i++){ - igraph_vector_push_back(&dimvector,NUM2INT(RARRAY(dim)->ptr[i])); + for(i=0; ilen;i++){ - igraph_vector_push_back(&out_degv,NUM2INT(RARRAY(out_deg)->ptr[i])); + for(i=0;ilen;i++){ - igraph_vector_push_back(&in_degv,NUM2INT(RARRAY(in_deg)->ptr[i])); + for(i=0;ilen;i++){ - igraph_vector_push_back(&type_distv,NUM2DBL(RARRAY(type_dist)->ptr[i])); + for(i=0;ilen;i++){ - igraph_vector_push_back(&type_distv,NUM2DBL(RARRAY(type_dist)->ptr[i])); + for(i=0;ilen;i++){ - igraph_vector_push_back(&type_distv,NUM2DBL(RARRAY(type_dist)->ptr[i])); + for(i=0;ilen;i++){ - igraph_vector_push_back(&type_distv,NUM2DBL(RARRAY(types)->ptr[i])); + for(i=0;ilen;i++){ - igraph_vector_push_back(&prefv,NUM2DBL(RARRAY(pref)->ptr[i])); + for(i=0;ilen;i++){ - igraph_vector_push_back(&typev,NUM2INT(RARRAY(types)->ptr[i])); + for(i=0;ilen;i++){ - Data_Get_Struct(RARRAY(graphs)->ptr[i], igraph_t, graph); + for(i=0;ilen;i++){ - Data_Get_Struct(RARRAY(layouts)->ptr[i], igraph_matrix_t, coord); + for(i=0;ilen; - ncols = RARRAY(RARRAY(rows)->ptr[0])->len; + nrows = RARRAY_LEN(rows); + ncols = RARRAY_LEN(RARRAY_PTR(rows)[0]); igraph_matrix_resize(m, nrows, ncols); //Loop through rows for (i=0; iptr[i])->ptr[j]); + MATRIX(*m,i,j) = NUM2DBL(RARRAY_PTR(RARRAY_PTR(rows)[i])[j]); } } diff --git a/ext/cIGraph_min_cuts.c b/ext/cIGraph_min_cuts.c index af01d10..8468038 100644 --- a/ext/cIGraph_min_cuts.c +++ b/ext/cIGraph_min_cuts.c @@ -29,8 +29,8 @@ VALUE cIGraph_maxflow_value(VALUE self, VALUE source, VALUE target, VALUE capaci igraph_vector_t capacity_v; igraph_vector_init(&capacity_v, 0); - for(i=0;ilen;i++){ - igraph_vector_push_back(&capacity_v,NUM2DBL(RARRAY(capacity)->ptr[i])); + for(i=0;ilen;i++){ - igraph_vector_push_back(&capacity_v,NUM2DBL(RARRAY(capacity)->ptr[i])); + for(i=0;ilen;i++){ - igraph_vector_push_back(&capacity_v,NUM2DBL(RARRAY(capacity)->ptr[i])); + for(i=0;ilen;i++){ - igraph_vector_push_back(&capacity_v,NUM2DBL(RARRAY(capacity)->ptr[i])); + for(i=0;ilen;i++){ - igraph_vector_push_back(&cutsv,NUM2DBL(RARRAY(cuts)->ptr[i])); + for(i=0;ilen;i++){ - igraph_vector_push_back(&cutsv,NUM2DBL(RARRAY(cuts)->ptr[i])); + for(i=0;ilen;i++){ - igraph_vector_push_back(&cutsv,NUM2DBL(RARRAY(cuts)->ptr[i])); + for(i=0;ilen; + n_paths = RARRAY_LEN(to); //vector to hold the results of the calculations igraph_vector_ptr_init(&res,0); diff --git a/ext/cIGraph_spanning.c b/ext/cIGraph_spanning.c index dfd170d..f885787 100644 --- a/ext/cIGraph_spanning.c +++ b/ext/cIGraph_spanning.c @@ -59,12 +59,12 @@ VALUE cIGraph_minimum_spanning_tree_prim(VALUE self, VALUE weights){ igraph_vector_t weights_vec; int i; - igraph_vector_init(&weights_vec,RARRAY(weights)->len); + igraph_vector_init(&weights_vec,RARRAY_LEN(weights)); Data_Get_Struct(self, igraph_t, graph); - for(i=0;ilen;i++){ - VECTOR(weights_vec)[i] = NUM2DBL(RARRAY(weights)->ptr[i]); + for(i=0;ilen; i++) { - vertex = RARRAY(va)->ptr[i]; + for (i=0; i