Class: Numo::GSL::Histogram2DPdf

Inherits:
Object
  • Object
show all
Defined in:
ext/numo/gsl/histogram/gsl_histogram.c

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(nx, ny) ⇒ Object

allocate instance of Histogram2DPdf class.

This function allocates memory for a two-dimensional probability distribution of size nx-by-ny and returns a pointer to a newly initialized gsl_histogram2d_pdf struct. If insufficient memory is available a null pointer is returned and the error handler is invoked with an error code of GSL_ENOMEM.

Parameters:

  • nx (Integer)

    parameter

  • ny (Integer)

    parameter



2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
# File 'ext/numo/gsl/histogram/gsl_histogram.c', line 2294

static VALUE
histogram2d_pdf_s_new(VALUE klass, VALUE v1, VALUE v2)
{
    gsl_histogram2d_pdf *w;
    w = gsl_histogram2d_pdf_alloc(NUM2SIZET(v1), NUM2SIZET(v2));
    if (!w) {
        rb_raise(rb_eNoMemError,"fail to allocate struct");
    }
    return TypedData_Wrap_Struct(cHistogram2DPdf, &histogram2d_pdf_data_type, (void*)w);
}

Instance Method Details

#init(h) ⇒ Bool

This function initializes the two-dimensional probability distribution calculated p from the histogram h. If any of the bins of h are negative then the error handler is invoked with an error code of GSL_EDOM because a probability distribution cannot contain negative values.

Parameters:

Returns:

  • (Bool)


2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
# File 'ext/numo/gsl/histogram/gsl_histogram.c', line 2319

static VALUE
histogram2d_pdf_init(VALUE self, VALUE v1)
{
    int stat;
    gsl_histogram2d_pdf *w;
    gsl_histogram2d *w1;

    TypedData_Get_Struct(self, gsl_histogram2d_pdf, &histogram2d_pdf_data_type, w);
    TypedData_Get_Struct(v1, gsl_histogram2d, &histogram2d_data_type, w1);

    stat = gsl_histogram2d_pdf_init(w, w1);
    return (stat) ? Qtrue: Qfalse;
}

#nxInteger

returns nx field in gsl_histogram2d_pdf struct.

Returns:

  • (Integer)


2156
2157
2158
2159
2160
2161
2162
2163
2164
# File 'ext/numo/gsl/histogram/gsl_histogram.c', line 2156

static VALUE
histogram2d_pdf_nx(VALUE self)
{
    gsl_histogram2d_pdf *w;

    TypedData_Get_Struct(self, gsl_histogram2d_pdf, &histogram2d_pdf_data_type, w);

    return SIZET2NUM(w->nx);
}

#nyInteger

returns ny field in gsl_histogram2d_pdf struct.

Returns:

  • (Integer)


2174
2175
2176
2177
2178
2179
2180
2181
2182
# File 'ext/numo/gsl/histogram/gsl_histogram.c', line 2174

static VALUE
histogram2d_pdf_ny(VALUE self)
{
    gsl_histogram2d_pdf *w;

    TypedData_Get_Struct(self, gsl_histogram2d_pdf, &histogram2d_pdf_data_type, w);

    return SIZET2NUM(w->ny);
}

#sample(r1, r2) ⇒ Array

This function uses two uniform random numbers between zero and one, r1 and r2, to compute a single random sample from the two-dimensional probability distribution p.

Parameters:

  • r1 (DFloat)
  • r2 (DFloat)

Returns:

  • (Array)

    array of [[DFloat] x, [DFloat] y]



2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
# File 'ext/numo/gsl/histogram/gsl_histogram.c', line 2370

static VALUE
histogram2d_pdf_sample(VALUE self, VALUE v1, VALUE v2)
{
    gsl_histogram2d_pdf *w;
    ndfunc_arg_in_t ain[2] = {{cDF,0},{cDF,0}};
    ndfunc_arg_out_t aout[2] = {{cDF,0},{cDF,0}};
    ndfunc_t ndf = {iter_histogram2d_pdf_sample, STRIDE_LOOP|NDF_EXTRACT, 2,2, ain,aout};

    TypedData_Get_Struct(self, gsl_histogram2d_pdf, &histogram2d_pdf_data_type, w);

    return na_ndloop3(&ndf, w, 2, v1, v2);
}

#sumDFloat

returns sum field in gsl_histogram2d_pdf struct.

Returns:

  • (DFloat)

    narray of sum field in gsl_histogram2d_pdf.



2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
# File 'ext/numo/gsl/histogram/gsl_histogram.c', line 2255

static VALUE
histogram2d_pdf_sum(VALUE self)
{
    gsl_histogram2d_pdf *w;
    double *d;
    VALUE v;
    size_t n, i, shape[2];

    TypedData_Get_Struct(self, gsl_histogram2d_pdf, &histogram2d_pdf_data_type, w);

    
    n = w->nx * w->ny;
    shape[0] = w->nx;
    shape[1] = w->ny;
    

    v = rb_narray_new(cDF, 2, shape);
    d = (double*)na_get_pointer_for_write(v);
    for (i=0; i<n; i++) {
        d[i] = w->sum[i];
    }
    return v;
}

#xrangeDFloat

returns xrange field in gsl_histogram2d_pdf struct.

Returns:

  • (DFloat)

    narray of xrange field in gsl_histogram2d_pdf.



2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
# File 'ext/numo/gsl/histogram/gsl_histogram.c', line 2193

static VALUE
histogram2d_pdf_xrange(VALUE self)
{
    gsl_histogram2d_pdf *w;
    double *d;
    VALUE v;
    size_t n, i, shape[2];

    TypedData_Get_Struct(self, gsl_histogram2d_pdf, &histogram2d_pdf_data_type, w);

    
    shape[0] = n = w->nx+1;
    

    v = rb_narray_new(cDF, 2, shape);
    d = (double*)na_get_pointer_for_write(v);
    for (i=0; i<n; i++) {
        d[i] = w->xrange[i];
    }
    return v;
}

#yrangeDFloat

returns yrange field in gsl_histogram2d_pdf struct.

Returns:

  • (DFloat)

    narray of yrange field in gsl_histogram2d_pdf.



2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
# File 'ext/numo/gsl/histogram/gsl_histogram.c', line 2224

static VALUE
histogram2d_pdf_yrange(VALUE self)
{
    gsl_histogram2d_pdf *w;
    double *d;
    VALUE v;
    size_t n, i, shape[2];

    TypedData_Get_Struct(self, gsl_histogram2d_pdf, &histogram2d_pdf_data_type, w);

    
    shape[0] = n = w->ny+1;
    

    v = rb_narray_new(cDF, 2, shape);
    d = (double*)na_get_pointer_for_write(v);
    for (i=0; i<n; i++) {
        d[i] = w->yrange[i];
    }
    return v;
}