static VALUE rb_gsl_vector_int_coerce(VALUE obj, VALUE other) { gsl_vector_int *v = NULL, *vnew = NULL; VALUE vv; Data_Get_Struct(obj, gsl_vector_int, v); switch (TYPE(other)) { case T_FIXNUM: vnew = gsl_vector_int_alloc(v->size); if (vnew == NULL) rb_raise(rb_eNoMemError, "gsl_vector_int_alloc failed"); gsl_vector_int_set_all(vnew, FIX2INT(other)); vv = Data_Wrap_Struct(VECTOR_INT_ROW_COL(obj), 0, gsl_vector_int_free, vnew); return rb_ary_new3(2, vv, obj); break; default: return rb_ary_new3(2, other, rb_gsl_vector_int_to_f(obj)); } // return rb_ary_new3(2, other, rb_gsl_vector_int_to_f(obj)); }
int DPMHC_init(struct str_DPMHC *ptr_DPMHC_data, int i_draws){ int j; int i_T = (ptr_DPMHC_data->vi_S)->size; if (i_T == 0){ fprintf(stderr,"Error in DPMHC_init(): DPMHC_alloc() has not been called.\n"); exit(1); } int i_K; gsl_matrix *m_DPtheta = ptr_DPMHC_data->m_DPtheta; ptr_DPMHC_data->m_DPmcmc = gsl_matrix_alloc(i_draws, 2); // for draw of i_K and d_DPalpha // initialize slice truction to K = 4 and one alive cluster, i_m = 1 i_K = ptr_DPMHC_data->i_K = 4; ptr_DPMHC_data->i_m = 1; gsl_vector_int_set_all(ptr_DPMHC_data->vi_S,0); vset_int(ptr_DPMHC_data->vi_n,0,i_T); // draw DP precision parameter d_DPalpha ~ Gamma(a,b) double d_DPalpha; d_DPalpha = ran_gamma(rng, ptr_DPMHC_data->d_a, ptr_DPMHC_data->d_b); ptr_DPMHC_data->d_DPalpha = d_DPalpha; // Draw initial mixture locations for K clusters for(j = 0; j < i_K; j++){ mset(m_DPtheta, j, 0, ptr_DPMHC_data->d_m0 + gsl_ran_gaussian_ziggurat(rng, sqrt(ptr_DPMHC_data->d_s2m))); mset(m_DPtheta, j, 1, gsl_ran_gaussian_ziggurat(rng, ptr_DPMHC_data->d_A)); mset(m_DPtheta, j, 2, gsl_ran_gamma(rng, 0.5, 0.5) ); } return 0; }