• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ rb_float_new函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中rb_float_new函数的典型用法代码示例。如果您正苦于以下问题:C++ rb_float_new函数的具体用法?C++ rb_float_new怎么用?C++ rb_float_new使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了rb_float_new函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: rb_gsl_function_graph

static VALUE rb_gsl_function_graph(int argc, VALUE *argv, VALUE obj)
{
#ifdef HAVE_GNU_GRAPH
  gsl_function *F = NULL;
  gsl_vector *v = NULL;
  double x, y;
  char opt[256] = "", command[1024];
  size_t i, n;
  int flag = 0;
  FILE *fp = NULL;
  VALUE ary, params, proc;
  switch (argc) {
  case 2:
    Check_Type(argv[1], T_STRING);
    strcpy(opt, STR2CSTR(argv[1]));
    /* no break, do next */
  case 1:
    if (CLASS_OF(argv[0]) == rb_cRange) argv[0] = rb_gsl_range2ary(argv[0]);
    if (TYPE(argv[0]) == T_ARRAY) {
      n = RARRAY(argv[0])->len;
      v = gsl_vector_alloc(n);
      flag = 1;
      for (i = 0; i < n; i++) 
	gsl_vector_set(v, i, NUM2DBL(rb_ary_entry(argv[0], i)));
    } else if (rb_obj_is_kind_of(argv[0], cgsl_vector)) {
      Data_Get_Struct(argv[0], gsl_vector, v);
      n = v->size;
      flag = 0;
    } else {
      rb_raise(rb_eTypeError, 
	       "wrong argument type %s (Array or GSL::Vector expected)", 
	       rb_class2name(CLASS_OF(argv[0])));
    }
    break;
  default:
    rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
    break;
  }
  Data_Get_Struct(obj, gsl_function, F);
  ary = (VALUE) F->params;
  proc = rb_ary_entry(ary, 0);
  params = rb_ary_entry(ary, 1);
  sprintf(command, "graph -T X -g 3 %s", opt);
  fp = popen(command, "w");
  if (fp == NULL)
    rb_raise(rb_eIOError, "GNU graph not found.");
  for (i = 0; i < n; i++) {
    x = gsl_vector_get(v, i);
    if (NIL_P(params)) y = NUM2DBL(rb_funcall(proc, RBGSL_ID_call, 1, rb_float_new(x)));
    else y = NUM2DBL(rb_funcall(proc, RBGSL_ID_call, 2, rb_float_new(x), params));
    fprintf(fp, "%e %e\n", x, y);
  }
  fflush(fp);
 pclose(fp);
  fp = NULL;
  if (flag == 1) gsl_vector_free(v);
  return Qtrue;
#else
  rb_raise(rb_eNoMethodError, "not implemented");
  return Qfalse;
#endif
}
开发者ID:davidrichards,项目名称:rb-gsl,代码行数:62,代码来源:function.c


示例2: rb_ool_conmin_minimizer_size

static VALUE rb_ool_conmin_minimizer_size(VALUE obj)
{
	ool_conmin_minimizer *m;
	Data_Get_Struct(obj, ool_conmin_minimizer, m);
	return rb_float_new(ool_conmin_minimizer_size(m));
}
开发者ID:engineyard,项目名称:rb-gsl,代码行数:6,代码来源:ool.c


示例3: Nokogiri_marshal_xpath_funcall_and_return_values

void Nokogiri_marshal_xpath_funcall_and_return_values(xmlXPathParserContextPtr ctx, int nargs, VALUE handler, const char* function_name)
{
  int i;
  VALUE result, doc;
  VALUE *argv;
  VALUE node_set = Qnil;
  xmlNodeSetPtr xml_node_set = NULL;
  xmlXPathObjectPtr obj;
  nokogiriNodeSetTuple *node_set_tuple;

  assert(ctx->context->doc);
  assert(DOC_RUBY_OBJECT_TEST(ctx->context->doc));

  argv = (VALUE *)calloc((size_t)nargs, sizeof(VALUE));
  for (i = 0 ; i < nargs ; ++i) {
    rb_gc_register_address(&argv[i]);
  }

  doc = DOC_RUBY_OBJECT(ctx->context->doc);

  if (nargs > 0) {
    i = nargs - 1;
    do {
      obj = valuePop(ctx);
      switch(obj->type) {
        case XPATH_STRING:
          argv[i] = NOKOGIRI_STR_NEW2(obj->stringval);
          break;
        case XPATH_BOOLEAN:
          argv[i] = obj->boolval == 1 ? Qtrue : Qfalse;
          break;
        case XPATH_NUMBER:
          argv[i] = rb_float_new(obj->floatval);
          break;
        case XPATH_NODESET:
          argv[i] = Nokogiri_wrap_xml_node_set(obj->nodesetval, doc);
          break;
        default:
          argv[i] = NOKOGIRI_STR_NEW2(xmlXPathCastToString(obj));
      }
      xmlXPathFreeNodeSetList(obj);
    } while(i-- > 0);
  }

  result = rb_funcall2(handler, rb_intern((const char*)function_name), nargs, argv);

  for (i = 0 ; i < nargs ; ++i) {
    rb_gc_unregister_address(&argv[i]);
  }
  free(argv);

  switch(TYPE(result)) {
    case T_FLOAT:
    case T_BIGNUM:
    case T_FIXNUM:
      xmlXPathReturnNumber(ctx, NUM2DBL(result));
      break;
    case T_STRING:
      xmlXPathReturnString(
          ctx,
          xmlCharStrdup(StringValuePtr(result))
      );
      break;
    case T_TRUE:
      xmlXPathReturnTrue(ctx);
      break;
    case T_FALSE:
      xmlXPathReturnFalse(ctx);
      break;
    case T_NIL:
      break;
    case T_ARRAY:
      {
        VALUE args[2];
	args[0] = doc;
	args[1] = result;
        node_set = rb_class_new_instance(2, args, cNokogiriXmlNodeSet);
        Data_Get_Struct(node_set, nokogiriNodeSetTuple, node_set_tuple);
	xml_node_set = node_set_tuple->node_set;
        xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, xml_node_set));
      }
      break;
    case T_DATA:
      if(rb_obj_is_kind_of(result, cNokogiriXmlNodeSet)) {
        Data_Get_Struct(result, nokogiriNodeSetTuple, node_set_tuple);
	xml_node_set = node_set_tuple->node_set;
        /* Copy the node set, otherwise it will get GC'd. */
        xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, xml_node_set));
        break;
      }
    default:
      rb_raise(rb_eRuntimeError, "Invalid return type");
  }
}
开发者ID:00zl00,项目名称:AlfredWorkflow.com,代码行数:94,代码来源:xml_xpath_context.c


示例4: prof_call_info_total_time

/* call-seq:
   total_time -> float

Returns the total amount of time spent in this method and its children. */
static VALUE
prof_call_info_total_time(VALUE self)
{
    prof_call_info_t *result = prof_get_call_info(self);
    return rb_float_new(result->total_time);
}
开发者ID:skyandsy,项目名称:CoinPost,代码行数:10,代码来源:rp_call_info.c


示例5: rb_io_convert_time

/*
 * Converts a D time metric to a Ruby float in ms
*/
static VALUE
rb_io_convert_time(uint64_t t)
{
    return rb_float_new((double) t / 1000000);
}
开发者ID:methodmissing,项目名称:io-trace,代码行数:8,代码来源:trace.c


示例6: Music_GetDuration

/* call-seq:
 *   music.getDuration()	-> float
 *
 * Get the total duration of the music. 
 */
static VALUE Music_GetDuration( VALUE self )
{
	sf::Music *object = NULL;
	Data_Get_Struct( self, sf::Music, object );
	return rb_float_new( object->GetDuration() );
}
开发者ID:vidjogamer,项目名称:ProjectTemplate,代码行数:11,代码来源:Music.cpp


示例7: t_to_mel

static VALUE t_to_mel(VALUE self, VALUE m) {
  return rb_float_new(mel(NUM2DBL(m)));
}
开发者ID:hmoody87,项目名称:noyes,代码行数:3,代码来源:mel_filter.c


示例8: rb_cqpminimizer_gap

static VALUE rb_cqpminimizer_gap(VALUE obj)
{
  gsl_cqpminimizer *m;
  Data_Get_Struct(obj, gsl_cqpminimizer, m);
  return rb_float_new(gsl_cqpminimizer_gap(m));
}
开发者ID:AbhimanyuAryan,项目名称:rb-gsl,代码行数:6,代码来源:cqp.c


示例9: rb_cqpminimizer_residuals_norm

static VALUE rb_cqpminimizer_residuals_norm(VALUE obj)
{
  gsl_cqpminimizer *m;
  Data_Get_Struct(obj, gsl_cqpminimizer, m);
  return rb_float_new(gsl_cqpminimizer_residuals_norm(m));
}
开发者ID:AbhimanyuAryan,项目名称:rb-gsl,代码行数:6,代码来源:cqp.c


示例10: pg_text_dec_float

/*
 * Document-class: PG::TextDecoder::Float < PG::SimpleDecoder
 *
 * This is a decoder class for conversion of PostgreSQL float4 and float8 types
 * to Ruby Float objects.
 *
 */
static VALUE
pg_text_dec_float(t_pg_coder *conv, char *val, int len, int tuple, int field, int enc_idx)
{
	return rb_float_new(strtod(val, NULL));
}
开发者ID:RapsIn4,项目名称:pg,代码行数:12,代码来源:pg_text_decoder.c


示例11: rb_cpBBGetT

static VALUE
rb_cpBBGetT(VALUE self) {
  return rb_float_new(BBGET(self)->t);
}
开发者ID:Anaxim,项目名称:chipmunk,代码行数:4,代码来源:rb_cpBB.c


示例12: Init_carray_numeric

void
Init_carray_numeric ()
{
  /* hack Fixnum and Bignum's "|", "&", "^", "<<", ">>" */

  id___or__ = rb_intern("__or__");
  id___and__ = rb_intern("__and__");
  id___xor__ = rb_intern("__xor__");
  id___rshift__ = rb_intern("__rshift__");
  id___lshift__ = rb_intern("__lshift__");

  CA_NAN = rb_float_new(0.0/0.0);
  CA_INF = rb_float_new(1.0/0.0);
  rb_define_const(rb_cObject, "CA_NAN", CA_NAN);
  rb_define_const(rb_cObject, "CA_INF", CA_INF);
  rb_define_global_function("nan", rb_num_nan, 0);
  rb_define_global_function("inf", rb_num_inf, 0);

  rb_define_alias(rb_cTrueClass, "__or__", "|");
  rb_define_alias(rb_cTrueClass, "__and__", "&");
  rb_define_alias(rb_cTrueClass, "__xor__", "^");

  rb_define_alias(rb_cFalseClass, "__or__", "|");
  rb_define_alias(rb_cFalseClass, "__and__", "&");
  rb_define_alias(rb_cFalseClass, "__xor__", "^");

  rb_define_alias(rb_cFixnum, "__or__", "|");
  rb_define_alias(rb_cFixnum, "__and__", "&");
  rb_define_alias(rb_cFixnum, "__xor__", "^");
  rb_define_alias(rb_cFixnum, "__lshift__", "<<");
  rb_define_alias(rb_cFixnum, "__rshift__", ">>");

  rb_define_alias(rb_cBignum, "__or__", "|");
  rb_define_alias(rb_cBignum, "__and__", "&");
  rb_define_alias(rb_cBignum, "__xor__", "^");
  rb_define_alias(rb_cBignum, "__lshift__", "<<");
  rb_define_alias(rb_cBignum, "__rshift__", ">>");

  rb_define_method(rb_cTrueClass, "|", rb_hack_or, 1);
  rb_define_method(rb_cTrueClass, "&", rb_hack_and, 1);
  rb_define_method(rb_cTrueClass, "^", rb_hack_xor, 1);
  rb_define_method(rb_cTrueClass, "*", rb_hack_star, 1);

  rb_define_method(rb_cFalseClass, "|", rb_hack_or, 1);
  rb_define_method(rb_cFalseClass, "&", rb_hack_and, 1);
  rb_define_method(rb_cFalseClass, "^", rb_hack_xor, 1);
  rb_define_method(rb_cFalseClass, "*", rb_hack_star, 1);

  rb_define_method(rb_cFixnum, "|", rb_hack_or, 1);
  rb_define_method(rb_cFixnum, "&", rb_hack_and, 1);
  rb_define_method(rb_cFixnum, "^", rb_hack_xor, 1);
  rb_define_method(rb_cFixnum, "<<", rb_hack_lshift, 1);
  rb_define_method(rb_cFixnum, ">>", rb_hack_rshift, 1);

  rb_define_method(rb_cBignum, "|", rb_hack_or, 1);
  rb_define_method(rb_cBignum, "&", rb_hack_and, 1);
  rb_define_method(rb_cBignum, "^", rb_hack_xor, 1);
  rb_define_method(rb_cBignum, "<<", rb_hack_lshift, 1);
  rb_define_method(rb_cBignum, ">>", rb_hack_rshift, 1);

#ifdef HAVE_COMPLEX_H
  rb_define_method(rb_cCArray, "arg", rb_ca_arg, 0);
#endif

}
开发者ID:himotoyoshi,项目名称:carray,代码行数:65,代码来源:carray_numeric.c


示例13: callback

void
callback(ffi_cif *cif, void *resp, void **args, void *ctx)
{
    VALUE self      = (VALUE)ctx;
    VALUE rbargs    = rb_iv_get(self, "@args");
    VALUE ctype     = rb_iv_get(self, "@ctype");
    int argc        = RARRAY_LENINT(rbargs);
    VALUE *params   = xcalloc(argc, sizeof(VALUE *));
    VALUE ret;
    VALUE cPointer;
    int i, type;

    cPointer = rb_const_get(mFiddle, rb_intern("Pointer"));

    for (i = 0; i < argc; i++) {
        type = NUM2INT(RARRAY_PTR(rbargs)[i]);
        switch (type) {
	  case TYPE_VOID:
	    argc = 0;
	    break;
	  case TYPE_INT:
	    params[i] = INT2NUM(*(int *)args[i]);
	    break;
	  case TYPE_VOIDP:
            params[i] = rb_funcall(cPointer, rb_intern("[]"), 1,
              PTR2NUM(*(void **)args[i]));
	    break;
	  case TYPE_LONG:
	    params[i] = LONG2NUM(*(long *)args[i]);
	    break;
	  case TYPE_CHAR:
	    params[i] = INT2NUM(*(char *)args[i]);
	    break;
	  case TYPE_DOUBLE:
	    params[i] = rb_float_new(*(double *)args[i]);
	    break;
	  case TYPE_FLOAT:
	    params[i] = rb_float_new(*(float *)args[i]);
	    break;
#if HAVE_LONG_LONG
	  case TYPE_LONG_LONG:
	    params[i] = rb_ull2inum(*(unsigned LONG_LONG *)args[i]);
	    break;
#endif
	  default:
	    rb_raise(rb_eRuntimeError, "closure args: %d", type);
        }
    }

    ret = rb_funcall2(self, rb_intern("call"), argc, params);

    type = NUM2INT(ctype);
    switch (type) {
      case TYPE_VOID:
	break;
      case TYPE_LONG:
	*(long *)resp = NUM2LONG(ret);
	break;
      case TYPE_CHAR:
	*(char *)resp = NUM2INT(ret);
	break;
      case TYPE_VOIDP:
	*(void **)resp = NUM2PTR(ret);
	break;
      case TYPE_INT:
	*(int *)resp = NUM2INT(ret);
	break;
      case TYPE_DOUBLE:
	*(double *)resp = NUM2DBL(ret);
	break;
      case TYPE_FLOAT:
	*(float *)resp = (float)NUM2DBL(ret);
	break;
#if HAVE_LONG_LONG
      case TYPE_LONG_LONG:
	*(unsigned LONG_LONG *)resp = rb_big2ull(ret);
	break;
#endif
      default:
	rb_raise(rb_eRuntimeError, "closure retval: %d", type);
    }
    xfree(params);
}
开发者ID:2220142,项目名称:ruby,代码行数:83,代码来源:closure.c


示例14: ruby_funcall

static void ruby_funcall(xmlXPathParserContextPtr ctx, int nargs)
{
  VALUE xpath_handler = Qnil;
  VALUE result;
  VALUE *argv;
  VALUE doc;
  VALUE node_set = Qnil;
  xmlNodeSetPtr xml_node_set = NULL;
  xmlXPathObjectPtr obj;
  int i;

  assert(ctx);
  assert(ctx->context);
  assert(ctx->context->userData);
  assert(ctx->context->doc);
  assert(DOC_RUBY_OBJECT_TEST(ctx->context->doc));

  xpath_handler = (VALUE)(ctx->context->userData);

  argv = (VALUE *)calloc((unsigned int)nargs, sizeof(VALUE));
  doc = DOC_RUBY_OBJECT(ctx->context->doc);

  i = nargs - 1;
  do {
    obj = valuePop(ctx);
    switch(obj->type) {
      case XPATH_STRING:
        argv[i] = NOKOGIRI_STR_NEW2(obj->stringval);
        break;
      case XPATH_BOOLEAN:
        argv[i] = obj->boolval == 1 ? Qtrue : Qfalse;
        break;
      case XPATH_NUMBER:
        argv[i] = rb_float_new(obj->floatval);
        break;
      case XPATH_NODESET:
        argv[i] = Nokogiri_wrap_xml_node_set(obj->nodesetval, doc);
        break;
      default:
        argv[i] = NOKOGIRI_STR_NEW2(xmlXPathCastToString(obj));
    }
    xmlXPathFreeNodeSetList(obj);
  } while(i-- > 0);

  result = rb_funcall2(
      xpath_handler,
      rb_intern((const char *)ctx->context->function),
      nargs,
      argv
  );
  free(argv);

  switch(TYPE(result)) {
    case T_FLOAT:
    case T_BIGNUM:
    case T_FIXNUM:
      xmlXPathReturnNumber(ctx, NUM2DBL(result));
      break;
    case T_STRING:
      xmlXPathReturnString(
          ctx,
          (xmlChar *)xmlXPathWrapCString(StringValuePtr(result))
      );
      break;
    case T_TRUE:
      xmlXPathReturnTrue(ctx);
      break;
    case T_FALSE:
      xmlXPathReturnFalse(ctx);
      break;
    case T_NIL:
      break;
    case T_ARRAY:
      {
        VALUE args[2];
	args[0] = doc;
	args[1] = result;
        node_set = rb_class_new_instance(2, args, cNokogiriXmlNodeSet);
        Data_Get_Struct(node_set, xmlNodeSet, xml_node_set);
        xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, xml_node_set));
      }
      break;
    case T_DATA:
      if(rb_obj_is_kind_of(result, cNokogiriXmlNodeSet)) {
        Data_Get_Struct(result, xmlNodeSet, xml_node_set);
        /* Copy the node set, otherwise it will get GC'd. */
        xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, xml_node_set));
        break;
      }
    default:
      rb_raise(rb_eRuntimeError, "Invalid return type");
  }
}
开发者ID:glebm,项目名称:glebm-nokogiri,代码行数:93,代码来源:xml_xpath_context.c


示例15: rb_read_number

STATIC VALUE rb_read_number(ramf0_load_context_t* context)
{
  return rb_float_new(c_read_number(context));
}
开发者ID:mrhenry,项目名称:ramf,代码行数:4,代码来源:ramf_AMF0Deserializer.c


示例16: rb_grn_bulk_to_ruby_object_by_range_type

static VALUE
rb_grn_bulk_to_ruby_object_by_range_type (grn_ctx *context, grn_obj *bulk,
					  grn_obj *range, grn_id range_id,
					  VALUE related_object, VALUE *rb_value)
{
    rb_grn_boolean success = RB_GRN_TRUE;

    if (!range && range_id != GRN_ID_NIL) {
	range = grn_ctx_at(context, range_id);
    }

    if (!range)
	return RB_GRN_FALSE;

    switch (range->header.type) {
      case GRN_TABLE_HASH_KEY:
      case GRN_TABLE_PAT_KEY:
      case GRN_TABLE_NO_KEY:
	{
	    grn_id id;

	    id = *((grn_id *)GRN_BULK_HEAD(bulk));
	    if (id == GRN_ID_NIL) {
		*rb_value = Qnil;
	    } else {
		VALUE rb_range;

		rb_range = GRNOBJECT2RVAL(Qnil, context, range, RB_GRN_FALSE);
		*rb_value = rb_grn_record_new(rb_range, id, Qnil);
	    }
	}
	break;
      case GRN_TYPE:
	if (range->header.flags & GRN_OBJ_KEY_VAR_SIZE) {
	    *rb_value = rb_grn_context_rb_string_new(context,
						     GRN_BULK_HEAD(bulk),
						     GRN_BULK_VSIZE(bulk));
	} else {
	    switch (range->header.flags & GRN_OBJ_KEY_MASK) {
	      case GRN_OBJ_KEY_UINT:
		*rb_value = INT2NUM(GRN_UINT32_VALUE(bulk));
		break;
	      case GRN_OBJ_KEY_INT:
		*rb_value = INT2NUM(GRN_INT32_VALUE(bulk));
		break;
	      case GRN_OBJ_KEY_FLOAT:
		*rb_value = rb_float_new(GRN_FLOAT_VALUE(bulk));
		break;
	      default:
		success = RB_GRN_FALSE;
	    }
	    break;
	}
	break;
      default:
	success = RB_GRN_FALSE;
	break;
    }

    return success;
}
开发者ID:nobu,项目名称:rroonga,代码行数:61,代码来源:rb-grn-utils.c


示例17: icu4r_cal_now

/**
 * call-seq:
 *     UCalendar.now
 *
 * Get the current date and time. in millis
 *
 *       UCalendar.now # => 1137934561000.0
 *
 */
VALUE icu4r_cal_now(VALUE obj){
	return rb_float_new(ucal_getNow());
}
开发者ID:noahdiewald,项目名称:icu4r,代码行数:12,代码来源:calendar.c


示例18: t_to_linear

static VALUE t_to_linear(VALUE self, VALUE f) {
  return rb_float_new(melinv(NUM2DBL(f)));
}
开发者ID:hmoody87,项目名称:noyes,代码行数:3,代码来源:mel_filter.c


示例19: cIGraph_community_spinglass

VALUE cIGraph_community_spinglass(VALUE self, VALUE weights, VALUE spins, VALUE parupdate, VALUE starttemp, VALUE stoptemp, VALUE coolfact, VALUE update_rule, VALUE gamma){

  igraph_t *graph;

  igraph_vector_t weights_vec;
  igraph_vector_t membership;
  igraph_real_t temperature;
  igraph_real_t modularity;
  igraph_bool_t parupdate_b;

  VALUE group;
  VALUE groups;
  VALUE res;

  VALUE str;

  int i,groupid,max_groupid;

  if(parupdate)
    parupdate_b = 1;

  Data_Get_Struct(self, igraph_t, graph);

  igraph_vector_init(&membership,0);

  igraph_vector_init(&weights_vec,RARRAY_LEN(weights));
  for(i=0;i<RARRAY_LEN(weights);i++){
    VECTOR(weights_vec)[i] = NUM2DBL(RARRAY_PTR(weights)[i]);
  }

  igraph_community_spinglass(graph,
			     igraph_vector_size(&weights_vec) > 0 ? &weights_vec : NULL,
			     &modularity,&temperature,
			     &membership,NULL,NUM2INT(spins),parupdate_b,
			     NUM2DBL(starttemp),NUM2DBL(stoptemp),
			     NUM2DBL(coolfact),NUM2INT(update_rule),
			     NUM2DBL(gamma));
  
  max_groupid = 0;
  for(i=0;i<igraph_vector_size(&membership);i++){
    if(VECTOR(membership)[i] > max_groupid)
      max_groupid = VECTOR(membership)[i];
  }
    
  groups = rb_ary_new();
  for(i=0;i<max_groupid+1;i++){
    rb_ary_push(groups,rb_ary_new());
  }

  for(i=0;i<igraph_vector_size(&membership);i++){

    groupid = VECTOR(membership)[i];

    if(groupid == -1)
      groupid = 0;

    group = RARRAY_PTR(groups)[groupid];
    rb_ary_push(group,cIGraph_get_vertex_object(self, i));
  }

  res = rb_ary_new3(3,groups,
		    rb_float_new(modularity),
		    rb_float_new(temperature));

  igraph_vector_destroy(&membership);
  igraph_vector_destroy(&weights_vec);

  return res;

}
开发者ID:jimmyharris,项目名称:igraph,代码行数:70,代码来源:cIGraph_community.c


示例20: cIGraph_community_leading_eigenvector_step

VALUE cIGraph_community_leading_eigenvector_step(VALUE self, VALUE membership, VALUE community){

  igraph_t *graph;

  igraph_vector_t membership_vec;
  igraph_vector_t eigenvector;
  igraph_real_t eigenvalue;
  igraph_bool_t split;

  int i,j,groupid,max_groupid,vid;

igraph_arpack_options_t arpack_opt;
igraph_arpack_options_init(&arpack_opt);

  VALUE groups, group, res, eigenvector_a, obj;

  Data_Get_Struct(self, igraph_t, graph);

  igraph_vector_init(&membership_vec,igraph_vcount(graph));
  igraph_vector_init(&eigenvector,0);

  for(i=0;i<RARRAY_LEN(membership);i++){
    group = RARRAY_PTR(membership)[i];

    for(j=0;j<RARRAY_LEN(group);j++){

      obj = RARRAY_PTR(group)[j];
      vid = cIGraph_get_vertex_id(self,obj);

      VECTOR(membership_vec)[vid] = i;

    }
  }

  igraph_community_leading_eigenvector_step(graph,&membership_vec,
					    NUM2INT(community),
					    &split,&eigenvector,&eigenvalue,&arpack_opt,NULL);

  max_groupid = 0;
  for(i=0;i<igraph_vector_size(&membership_vec);i++){
    if(VECTOR(membership_vec)[i] > max_groupid)
      max_groupid = VECTOR(membership_vec)[i];
  }

  groups = rb_ary_new();
  for(i=0;i<max_groupid+1;i++){
    rb_ary_push(groups,rb_ary_new());
  }

  for(i=0;i<igraph_vector_size(&membership_vec);i++){

    groupid = VECTOR(membership_vec)[i];

    if(groupid == -1)
      groupid = 0;

    group = RARRAY_PTR(groups)[groupid];
    rb_ary_push(group,cIGraph_get_vertex_object(self, i));
  }

  eigenvector_a = rb_ary_new();
  for(i=0;i<igraph_vector_size(&eigenvector);i++){
    rb_ary_push(eigenvector_a,rb_float_new(VECTOR(eigenvector)[i]));
  }

  res = rb_ary_new3(4,groups,split==0 ? Qfalse : Qtrue,
		    eigenvector_a,rb_float_new(eigenvalue));


  igraph_vector_destroy(&membership_vec);
  igraph_vector_destroy(&eigenvector);

  return res;

}
开发者ID:jimmyharris,项目名称:igraph,代码行数:75,代码来源:cIGraph_community.c



注:本文中的rb_float_new函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ rb_free函数代码示例发布时间:2022-05-30
下一篇:
C++ rb_first函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap