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

C++ RARRAY函数代码示例

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

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



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

示例1: rb2GimpParamDefs

GimpParamDef *
rb2GimpParamDefs (VALUE rbparamdefs,
                  gint  *count)
{
  if (rbparamdefs == Qnil)
    {
      *count = 0;
      return NULL;
    }
  else
    {
        Check_Type(rbparamdefs, T_ARRAY);

      int num = RARRAY_LEN(RARRAY(rbparamdefs));
      VALUE *arr = RARRAY_PTR(RARRAY(rbparamdefs));

      GimpParamDef *gimpparamdefs = g_new(GimpParamDef, num);

      int i;
      for(i=0; i<num; i++)
        gimpparamdefs[i] = rb2GimpParamDef(arr[i]);

      *count = (gint)num;
      return gimpparamdefs;
    }
}
开发者ID:antono,项目名称:gimp-ruby,代码行数:26,代码来源:conversion.c


示例2: mrb_ary_cmp

/*
 *  call-seq:
 *     ary <=> other_ary   ->  -1, 0, +1 or nil
 *
 *  Comparison---Returns an integer (-1, 0, or +1)
 *  if this array is less than, equal to, or greater than <i>other_ary</i>.
 *  Each object in each array is compared (using <=>). If any value isn't
 *  equal, then that inequality is the return value. If all the
 *  values found are equal, then the return is based on a
 *  comparison of the array lengths.  Thus, two arrays are
 *  ``equal'' according to <code>Array#<=></code> if and only if they have
 *  the same length and the value of each element is equal to the
 *  value of the corresponding element in the other array.
 *
 *     [ "a", "a", "c" ]    <=> [ "a", "b", "c" ]   #=> -1
 *     [ 1, 2, 3, 4, 5, 6 ] <=> [ 1, 2 ]            #=> +1
 *
 */
mrb_value
mrb_ary_cmp(mrb_state *mrb, mrb_value ary1)
{
  mrb_value ary2;
  struct RArray *a1, *a2;
  mrb_value r = mrb_nil_value();
  int i, len;

  mrb_get_args(mrb, "o", &ary2);
  if (mrb_type(ary2) != MRB_TT_ARRAY) return mrb_nil_value();
  a1 = RARRAY(ary1); a2 = RARRAY(ary2);
  if (a1->len == a2->len && a1->ptr == a2->ptr) return mrb_fixnum_value(0);
  else {
    len = RARRAY_LEN(ary1);
    if (len > RARRAY_LEN(ary2)) {
      len = RARRAY_LEN(ary2);
    }
    for (i=0; i<len; i++) {
      r = mrb_funcall(mrb, ary_elt(ary1, i), "<=>", 1, ary_elt(ary2, i));
      if (mrb_type(r) != MRB_TT_FIXNUM || mrb_fixnum(r) != 0) return r;
    }
  }
  len = a1->len - a2->len;
  return mrb_fixnum_value((len == 0)? 0: (len > 0)? 1: -1);
}
开发者ID:galois17,项目名称:mruby,代码行数:43,代码来源:array.c


示例3: ossl_x509crl_set_extensions

/*
 * Sets X509_EXTENSIONs
 */
static VALUE 
ossl_x509crl_set_extensions(VALUE self, VALUE ary)
{
    X509_CRL *crl;
    X509_EXTENSION *ext;
    int i;
	
    Check_Type(ary, T_ARRAY);
    /* All ary members should be X509 Extensions */
    for (i=0; i<RARRAY(ary)->len; i++) {
	OSSL_Check_Kind(RARRAY(ary)->ptr[i], cX509Ext);
    }
    GetX509CRL(self, crl);
    sk_X509_EXTENSION_pop_free(crl->crl->extensions, X509_EXTENSION_free);
    crl->crl->extensions = NULL;
    for (i=0; i<RARRAY(ary)->len; i++) {
	ext = DupX509ExtPtr(RARRAY(ary)->ptr[i]);
	if(!X509_CRL_add_ext(crl, ext, -1)) { /* DUPs ext - FREE it */
	    X509_EXTENSION_free(ext);
	    ossl_raise(eX509CRLError, NULL);
	}
	X509_EXTENSION_free(ext);
    }

    return ary;
}
开发者ID:FooBarWidget,项目名称:rubyenterpriseedition,代码行数:29,代码来源:ossl_x509crl.c


示例4: rbosa_elementlist_new

static VALUE
rbosa_elementlist_new (int argc, VALUE *argv, VALUE self)
{
    OSErr           error;
    AEDescList      list;
    VALUE           ary;
    int             i;

    rb_scan_args (argc, argv, "01", &ary);

    if (!NIL_P (ary))
        Check_Type (ary, T_ARRAY);

    error = AECreateList (NULL, 0, false, &list);
    if (error != noErr) 
        rb_raise (rb_eRuntimeError, "Cannot create Apple Event descriptor list : %s (%d)", 
                  error_code_to_string (error), error);

    if (!NIL_P (ary)) {
        for (i = 0; i < RARRAY (ary)->len; i++)
            __rbosa_elementlist_add (&list, RARRAY (ary)->ptr[i], i + 1); 
    }
    
    return rbosa_element_make (self, &list, Qnil);
}
开发者ID:bmorton,项目名称:rubyosa,代码行数:25,代码来源:rbosa.c


示例5: ossl_x509crl_set_revoked

static VALUE 
ossl_x509crl_set_revoked(VALUE self, VALUE ary)
{
    X509_CRL *crl;
    X509_REVOKED *rev;
    int i;

    Check_Type(ary, T_ARRAY);
    /* All ary members should be X509 Revoked */
    for (i=0; i<RARRAY(ary)->len; i++) {
	OSSL_Check_Kind(RARRAY(ary)->ptr[i], cX509Rev);
    }
    GetX509CRL(self, crl);
    sk_X509_REVOKED_pop_free(crl->crl->revoked, X509_REVOKED_free);
    crl->crl->revoked = NULL;
    for (i=0; i<RARRAY(ary)->len; i++) {
	rev = DupX509RevokedPtr(RARRAY(ary)->ptr[i]);
	if (!X509_CRL_add0_revoked(crl, rev)) { /* NO DUP - don't free! */
	    ossl_raise(eX509CRLError, NULL);
	}
    }
    X509_CRL_sort(crl);

    return ary;
}
开发者ID:FooBarWidget,项目名称:rubyenterpriseedition,代码行数:25,代码来源:ossl_x509crl.c


示例6: munge_xpath_namespace

VALUE munge_xpath_namespace( VALUE orig_expr, xmlChar *root_ns )
{
	VALUE path_bits = rb_str_split( orig_expr, "/" );
	VALUE ns_prefix = rb_str_new2( (const char*)root_ns );
	VALUE ns_indic = rb_str_new2( ":" );
	VALUE slash = rb_str_new2( "/" );
	VALUE path_bit, str_idx;
	VALUE ret_ary = rb_ary_new();
	long i;
	
	rb_str_append( ns_prefix, ns_indic );
    for (i=0; i<RARRAY(path_bits)->len; i++) {
        path_bit = RARRAY(path_bits)->ptr[i];
		
		if (RSTRING_LEN(path_bit) > 0) {
			str_idx = rb_funcall( path_bit, rb_intern( "index" ), 1, ns_indic );
			if (str_idx == Qnil || str_idx == Qfalse) // didn't find the :, so it looks like we don't have a namespace
				path_bit = rb_str_plus( ns_prefix, path_bit );
		}	
		
		rb_ary_push( ret_ary, path_bit );
    }
	
	return rb_ary_join( ret_ary, slash );
}
开发者ID:segfault,项目名称:fastxml,代码行数:25,代码来源:fastxml.c


示例7: rb_gsl_blas_drotm2

static VALUE rb_gsl_blas_drotm2(VALUE obj, VALUE xx, VALUE yy, VALUE PP)
{
  gsl_vector *x = NULL, *y = NULL, *p = NULL, *xnew = NULL, *ynew = NULL;
  int flag = 0, i;
  CHECK_VECTOR(xx);
  CHECK_VECTOR(yy);
  Data_Get_Struct(xx, gsl_vector, x);
  Data_Get_Struct(yy, gsl_vector, y);
  if (rb_obj_is_kind_of(PP, cgsl_vector)) {
    Data_Get_Struct(PP, gsl_vector, p);
  } else {
    if (TYPE(PP) != T_ARRAY) rb_raise(rb_eTypeError, "wrong argument type %s (Array of Vector expected", rb_class2name(CLASS_OF(PP)));
    p = gsl_vector_alloc(RARRAY(PP)->len);
    for (i = 0; i < RARRAY(PP)->len; i++) {
      gsl_vector_set(p, i, rb_ary_entry(PP, i));
    }
    flag = 1;
  }
  xnew = gsl_vector_alloc(x->size);
  ynew = gsl_vector_alloc(y->size);
  gsl_vector_memcpy(xnew, x);
  gsl_vector_memcpy(ynew, y);
  gsl_blas_drotm(xnew, ynew, p->data);
  if (flag == 1) gsl_vector_free(p);
  return rb_ary_new3(2, Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, xnew),
		     Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, ynew));
}
开发者ID:davidrichards,项目名称:rb-gsl,代码行数:27,代码来源:blas1.c


示例8: dnssd_tr_encode

static VALUE
dnssd_tr_encode(VALUE self)
{
	long i;
	VALUE buf;
	/* Declare ary volatile to prevent it from being reclaimed when:
	 * buf is allocated later, key/values are converted to strings */
	volatile VALUE ary = rb_funcall2(self, rb_intern("to_a"), 0, 0);
	/* array of key, value pairs */
	VALUE *ptr = RARRAY(ary)->ptr;
	
	buf = rb_str_buf_new(dnssd_tr_convert_pairs(ary));
	for(i=0; i<RARRAY(ary)->len; i++) {
		uint8_t len;
		VALUE key = RARRAY(ptr[i])->ptr[0];
		VALUE value = RARRAY(ptr[i])->ptr[1];
		if (!NIL_P(value)) {
			len = (uint8_t)(RSTRING(key)->len + RSTRING(value)->len + 1);
			rb_str_buf_cat(buf, &len, 1);
			rb_str_buf_append(buf, key);
			rb_str_buf_cat(buf, "=", 1);
			rb_str_buf_append(buf, value);	
		} else {
			len = (uint8_t)RSTRING(key)->len;
			rb_str_buf_cat(buf, &len, 1);
			rb_str_buf_append(buf, key);
		}
	}
	return buf;
}
开发者ID:lachie,项目名称:zeroconf,代码行数:30,代码来源:rdnssd_tr.c


示例9: og_oniguruma_match_offset

/*
 * Document-method: offset
 *
 * call-seq:
 *    mtch.offset(n)      => array
 *    mtch.offset         => array
 *    mtch.offset(symbol) => array
 *
 * Returns a two-element array containing the beginning and ending offsets of
 * the <em>n</em>th match.
 *
 *    m = ORegexp.new( '(.)(.)(\d+)(\d)' ).match("THX1138.")
 *    m.offset(0)   #=> [1, 7]
 *    m.offset(4)   #=> [6, 7]
 *
 * If no arguments are given, the offsets of the entire
 * sequence are returned.
 *
 *    m = ORegexp.new( '(.)(.)(\d+)(\d)' ).match("THX1138.")
 *    m.offset      #=> [1, 7]
 *
 * If the argument is a symbol, then the offsets of the
 * corresponding named group are returned, or <code>nil</code>
 * if the group does not exist.
 *
 *    m = ORegexp.new( '(?<begin>^.*?)(?<middle>\d)(?<end>.*)' ).match("THX1138")
 *    m.end(:middle) #=> [3, 4]
 */
static VALUE
og_oniguruma_match_offset(int argc, VALUE *argv, VALUE self)
{
  VALUE idx, first, k, nargv[2];
  
  rb_scan_args(argc, argv, "0*", &idx);
  
  first = rb_ary_entry(idx, 0);
  if (SYMBOL_P(first)) {
    k = og_oniguruma_match_to_index(self, first);
    if (!NIL_P(k)) {
      nargv[0] = k;
      nargv[1] = (VALUE)NULL;
      
      return rb_funcall3(self, rb_intern("offset_without_oniguruma"), 1, nargv);
    } else
      return Qnil;
  } else if (RARRAY(idx)->len == 0) {
    nargv[0] = INT2FIX(0);
    nargv[1] = (VALUE)NULL;
    
    return rb_funcall3(self, rb_intern("offset_without_oniguruma"), 1, nargv);
  }
  
  return rb_funcall3(self, rb_intern("offset_without_oniguruma"), RARRAY(idx)->len, RARRAY(idx)->ptr);
}
开发者ID:Smily1984,项目名称:oniguruma,代码行数:54,代码来源:rb_oniguruma_ext_match.c


示例10: ruby_to_value

static value_t* ruby_to_value(VALUE v)
{
  switch (TYPE(v)) {
    case T_NIL:
      return value_new_void();
    case T_BIGNUM:
    case T_FIXNUM:
      return value_new_int32(NUM2INT(v));
    case T_TRUE:
      return value_new_boolean(true);
    case T_FALSE:
      return value_new_boolean(false);
    case T_FLOAT:
      return value_new_float32(NUM2DBL(v));
    case T_SYMBOL:
      return value_new_string(rb_id2name(SYM2ID(v)));
    case T_STRING:
      return value_new_string(StringValuePtr(v));
    case T_ARRAY: {
      /* process Array */
      value_t*array = array_new();
      int len = RARRAY(v)->len;
      int i;
      for(i=0;i<len;i++) {
          volatile VALUE item = RARRAY(v)->ptr[i];
          array_append(array, ruby_to_value(item));
      }
      return array;
    }
    default:
      /* raise exception */
      rb_raise(rb_eTypeError, "not valid value");
  }
}
开发者ID:luiseduardohdbackup,项目名称:cagekeeper,代码行数:34,代码来源:language_rb.c


示例11: compare_arrays

static VALUE compare_arrays(VALUE a, VALUE b, fun_array_cmp cmp) {
  struct array_comparison result = { 0, 0, RARRAY(a)->len, RARRAY(b)->len };
  long * long_a;
  long * long_b;
  int i, j;
  
  result.union_size = result.a_size + result.b_size;
  
  if((result.a_size > 0) && (result.b_size > 0))
  {
    COPYRUBYHASHARRAY(a, long_a);
    COPYRUBYHASHARRAY(b, long_b);
    
    for(i = 0; i < result.a_size; ++i)
    {
      for(j = 0; j < result.b_size; ++j)
      {
        if(long_a[i] == long_b[j])
        {
          result.intersection_size++;
        }
      }
    }
    
  }
  
  return rb_float_new((*cmp)(result));
}
开发者ID:codahale,项目名称:ruby-gsl,代码行数:28,代码来源:Similarity.c


示例12: parse

static void
parse(pairmatcher_t *pm, VALUE tokenizer, VALUE reporter)
{
  VALUE token_info;
  while ((token_info = get_token(tokenizer)) != Qnil) {
    VALUE token_type, token_text, token_lineno, token_byteno;
    VALUE token;
    Check_Type(token_info, T_ARRAY);
    if (RARRAY(token_info)->len != 8) {
      rb_raise(rb_eArgError, "unexpected token");
    }
    token_type = RARRAY(token_info)->ptr[0];
    token_text = RARRAY(token_info)->ptr[1];
    token_lineno = RARRAY(token_info)->ptr[2];
    token_byteno = RARRAY(token_info)->ptr[4];
    token = rb_funcall(Fragment, id_new, 4, token_type, token_text, token_lineno, token_byteno);
    if (intertoken_p(pm, token_type)) {
      rb_funcall(reporter, id_call, 1, token);
    }
    else {
      put_token(pm, token, reporter);
    }
  }
  finish(pm, reporter);
}
开发者ID:sonsongithub,项目名称:sonson,代码行数:25,代码来源:pairmatcher.c


示例13: coverage_increase_counter_uncached

static struct cov_array * coverage_increase_counter_uncached(char *sourcefile, unsigned int sourceline, char mark_only) {
  struct cov_array *carray = NULL;
 
  if(sourcefile == NULL) {
    /* "can't happen", just ignore and avoid segfault */
    return NULL;
  } 
  else if(!st_lookup(coverinfo, (st_data_t)sourcefile, (st_data_t*)&carray)) {
    VALUE arr;
    
    arr = rb_hash_aref(oSCRIPT_LINES__, rb_str_new2(sourcefile));
    if(NIL_P(arr)) 
      return 0;
    rb_check_type(arr, T_ARRAY);
    carray = calloc(1, sizeof(struct cov_array));
    carray->ptr = calloc(RARRAY(arr)->len, sizeof(unsigned int));
    carray->len = RARRAY(arr)->len;
    st_insert(coverinfo, (st_data_t)strdup(sourcefile), (st_data_t) carray);
  } 
  else {
    /* recovered carray, sanity check */
    assert(carray && "failed to create valid carray");
  }

  if(mark_only) {
    if(!carray->ptr[sourceline])
      carray->ptr[sourceline] = 1;
  } else {
    if (carray && carray->len > sourceline) {
      carray->ptr[sourceline]++;
    }
  }

  return carray;
}
开发者ID:CoralineAda,项目名称:rcov,代码行数:35,代码来源:rcovrt.c


示例14: rb_iv_get

octave_value OR_StructMatrix::to_octave()
{
  int i, row_index, column_index;
  VALUE row, cell;
  VALUE cells = rb_iv_get(ruby_val, "@cells");
  VALUE names = rb_iv_get(ruby_val, "@names");
  int number_of_keys = RARRAY(names)->len;
  int number_of_rows = FIX2INT(rb_iv_get(ruby_val, "@m"));
  int number_of_columns = FIX2INT(rb_iv_get(ruby_val, "@n"));

  string_vector keys = string_vector();
  for (i = 0; i < number_of_keys; i++) {
    keys.append(std::string(RSTRING(RARRAY(names)->ptr[i])->ptr));
  }
  
  Octave_map struct_matrix = Octave_map(dim_vector(number_of_rows, number_of_columns), Cell(keys));
  for (row_index = 0; row_index < number_of_rows; row_index++) {
    row = RARRAY(cells)->ptr[row_index];
  
    for (column_index = 0; column_index < number_of_columns; column_index++) {
      cell = RARRAY(row)->ptr[column_index];
      
      for (i = 0; i < number_of_keys; i++) {
        struct_matrix.contents(std::string(RSTRING(RARRAY(names)->ptr[i])->ptr))(row_index, column_index) = OR_Variable(rb_hash_aref(cell, rb_str_new2(RSTRING(RARRAY(names)->ptr[i])->ptr))).to_octave();
      }
    }
  }
  
  return struct_matrix;
}
开发者ID:apohllo,项目名称:octave-ruby,代码行数:30,代码来源:or-struct_matrix.cpp


示例15: union_list

/**
@method union_list( array_of_rects )
Returns a new array representing a rectangle covering all rectangles
in @array_of_rects.
*/
static VALUE rb_array_union_list(VALUE self, VALUE other_rects)
{
	int i;
	double left;
	double right;
	double top;
	double bottom;
	double l,r,t,b;
	VALUE rect;

	if(RARRAY(other_rects)->len==0){
		return Qnil;
	}

	rect=rb_ary_entry(other_rects, 0);
	left=array_get_x(rect);
	right=array_get_w(rect)+left;
	top=array_get_y(rect);
	bottom=array_get_h(rect)+top;

	for(i=1; i<RARRAY(other_rects)->len; i++){
		rect=rb_ary_entry(other_rects, i);
		l=array_get_x(rect);
		r=array_get_w(rect)+l;
		t=array_get_y(rect);
		b=array_get_h(rect)+t;
		left=RUDL_MIN(left, l);
		right=RUDL_MAX(right, r);
		top=RUDL_MIN(top, t);
		bottom=RUDL_MAX(bottom, b);
	}

	return new_rect(left, top, right-left, bottom-top);
}
开发者ID:matozoid,项目名称:rudl,代码行数:39,代码来源:rudl_video_rect.c


示例16: rb_dataset_set_params

/* call-seq: _set_params(pars,vars,set_derivs)
 *
 * Sets <tt>@params</tt> using MINUIT parameters _pars_ and kinematic
 * variables _vars_ (if <tt>:dcs</tt>). If _set_derivs_ is <tt>true</tt>, then
 * <tt>@dparams</tt> is set also.
 */
VALUE rb_dataset_set_params(VALUE __self,VALUE __pars,VALUE __vars,
          VALUE __set_derivs){
  static ID set_pars_id = rb_intern("set_pars");
  static ID value_id = rb_intern("value");
  static ID deriv_id = rb_intern("deriv");
  VALUE amps = rb_iv_get(__self,"@amps"); 
  VectorDbl2D *params 
    = get_cpp_ptr(rb_iv_get(__self,"@params"),__VectorDbl2D__);
  VectorDbl3D *dparams 
    = get_cpp_ptr(rb_iv_get(__self,"@dparams"),__VectorDbl3D__);
  int num_ic = RARRAY(amps)->len,num_pars = RARRAY(__pars)->len;
  for(int ic = 0; ic < num_ic; ic++){ // loop over incoherent wavesets
    VALUE ic_amps = rb_ary_entry(amps,ic);
    int num_amps = RARRAY(ic_amps)->len;
    for(int a = 0; a < num_amps; a++){ // loop over amps in this waveset
      VALUE amp = rb_ary_entry(ic_amps,a); // current amp
      if(rb_iv_get(amp,"@use") == Qfalse){
  (*params)[ic][a] = 0.0;
  for(int par = 0; par < num_pars; par++) (*dparams)[ic][a][par] = 0.;
  continue;
      }
      rb_funcall(amp,set_pars_id,1,__pars); // call Amp#set_pars on it
      (*params)[ic][a] = CPP_COMPLEX(float,rb_funcall(amp,value_id,1,__vars));
      if(__set_derivs == Qfalse) continue;
      for(int par = 0; par < num_pars; par++){ // loop over parameters
  if(rb_ary_entry(__pars,par) == Qnil) continue; // amp doesn't use par
  (*dparams)[ic][a][par] 
    = CPP_COMPLEX(double,rb_funcall(amp,deriv_id,2,INT2NUM(par),__vars));
      }
    }
  }
  return __self;
}
开发者ID:diorahman,项目名称:ruby-pwa,代码行数:39,代码来源:dcs.cpp


示例17: frt_get_fields

static HashSet *
frt_get_fields(VALUE rfields)
{
    VALUE rval;
    HashSet *fields;
    char *s, *p, *str;

    if (rfields == Qnil) return NULL;

    fields = hs_new_str(&free);
    if (TYPE(rfields) == T_ARRAY) {
        int i;
        for (i = 0; i < RARRAY(rfields)->len; i++) {
            rval = rb_obj_as_string(RARRAY(rfields)->ptr[i]);
            hs_add(fields, estrdup(RSTRING(rval)->ptr));
        }
    } else {
        rval = rb_obj_as_string(rfields);
        if (strcmp("*", RSTRING(rval)->ptr) == 0) {
            hs_destroy(fields);
            fields = NULL;
        } else {
            s = str = estrdup(RSTRING(rval)->ptr);
            while ((p = strchr(s, '|')) != '\0') {
                *p = '\0';
                hs_add(fields, estrdup(s));
                s = p + 1;
            }
            hs_add(fields, estrdup(s));
            free(str);
        }
    }
    return fields;
}
开发者ID:BusProject,项目名称:theballot,代码行数:34,代码来源:r_qparser.c


示例18: io_close

// Used to close io handle
static VALUE io_close(VALUE val) {
    int i;
    for(i=0;i<3;i++) {
    	 if(rb_funcall(RARRAY(val)->ptr[i], rb_intern("closed?"),0)==Qfalse)
    	 	rb_funcall(RARRAY(val)->ptr[i], rb_intern("close"),0);
    }
    return Qnil;
}
开发者ID:shairontoledo,项目名称:popen4,代码行数:9,代码来源:open3.c


示例19: array_spec_RARRAY_ptr_assign

static VALUE array_spec_RARRAY_ptr_assign(VALUE self, VALUE ary, VALUE content, VALUE length) {
  int i;
  for (i = 0; i < NUM2INT(length); i++) {
    RARRAY(ary)->ptr[i] = content;
  }
  RARRAY(ary)->len = i;
  return ary;
}
开发者ID:DanielVartanov,项目名称:rubinius,代码行数:8,代码来源:array_spec.c


示例20: rb_dcs_fcn_val

/* call-seq: fcn_val(flag,pars,derivs) -> chi2
 *
 * Calculates chi2 given MINUIT parameters _pars_. If _flag_ is 2, derivatives
 * are calculated and set in _derivs_.
 */
static VALUE rb_dcs_fcn_val(VALUE __self,VALUE __flag,VALUE __pars,
			    VALUE __derivs){
  static ID cs_id = rb_intern("cs");
  static ID cs_err_id = rb_intern("cs_err");
  static ID vars_id = rb_intern("vars");  
  int num_pars = RARRAY(__pars)->len; // length of MINUIT parameter array
  double chi2 = 0.0;
  double phsp = NUM2DBL(rb_iv_get(__self,"@phsp_factor"));  
  VALUE dcs_pts = rb_iv_get(__self,"@dcs_pts");
  VALUE do_derivs = (NUM2INT(__flag) == 2) ? Qtrue : Qfalse;
  int num_pts = RARRAY(dcs_pts)->len;
  VectorFlt3D *amp_vals 
    = get_cpp_ptr(rb_iv_get(__self,"@amp_vals"),__VectorFlt3D__);
  VectorDbl2D *params 
    = get_cpp_ptr(rb_iv_get(__self,"@params"),__VectorDbl2D__);
  VectorDbl3D *dparams 
    = get_cpp_ptr(rb_iv_get(__self,"@dparams"),__VectorDbl3D__);
  double dchi2dpar[num_pars];
  for(int p = 0; p < num_pars; p++) dchi2dpar[p] = 0.;
  for(int pt = 0; pt < num_pts; pt++){ // loop over dsigma pts
    VALUE dcs_pt = rb_ary_entry(dcs_pts,pt);
    double cs = NUM2DBL(rb_funcall(dcs_pt,cs_id,0));
    double cs_err = NUM2DBL(rb_funcall(dcs_pt,cs_err_id,0));
    rb_dataset_set_params(__self,__pars,rb_funcall(dcs_pt,vars_id,0),
			  do_derivs);
    int num_ic = (int)(*amp_vals)[pt].size();
    double intensity = 0.0; 
    complex<double> dcsdpar[num_pars];
    for(int p = 0; p < num_pars; p++) dcsdpar[p] = 0.;
    for(int ic = 0; ic < num_ic; ic++){ // loop over incoherent wavesets
      complex<double> amp_tot 
	= get_amp_total((*amp_vals)[pt][ic],(*params)[ic]);
      intensity += (amp_tot*conj(amp_tot)).real();
      if(do_derivs == Qfalse) continue;
      int num_amps = (int)(*amp_vals)[pt][ic].size();
      for(int a = 0; a < num_amps; a++){ // loop over amps in this waveset
	complex<double> amp_prod = (*amp_vals)[pt][ic][a]*conj(amp_tot);
	for(int p = 0; p < num_pars; p++) 
	  dcsdpar[p] += (*dparams)[ic][a][p]*amp_prod;
      }
    }
    double cs_calc = phsp*intensity;
    double diff = cs - cs_calc;
    chi2 += diff*diff/(cs_err*cs_err); // add this pt's chi^2 to total
    if(do_derivs == Qtrue){
      for(int p = 1; p < num_pars; p++){
	complex<double> dsdp = dcsdpar[p]*phsp;
	dchi2dpar[p] += 2*((2/(cs_err*cs_err))*(cs_calc - cs)*dsdp).real();
      }
      for(int p = 1; p < num_pars; p++){ // set the derivatives
	if(rb_ary_entry(__derivs,p) != Qnil){
	  rb_ary_store(__derivs,p,rb_float_new(dchi2dpar[p]));
	}
      }
    }
  }
  return rb_float_new(chi2);
}
开发者ID:diorahman,项目名称:ruby-pwa,代码行数:63,代码来源:dcs.cpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ RARRAY_AREF函数代码示例发布时间:2022-05-30
下一篇:
C++ RARCH_WARN函数代码示例发布时间: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