enumerable-statistics 2.0.5 → 2.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ca7750e402868e65da3619203a19ad1b7bd86348aee8ca2168c35db6fe6f262
|
4
|
+
data.tar.gz: 425bd2623655dd3f189ee50f12b0d44d3c25bed86194d2f31eb530431cab1090
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37a9f4e270fee3e34852bccd0adc18d288514c1d8363807b2db16877ada2174aea7c1f8c8ef7cea94cb3274bb5716c35ee689ecde95a5a71cb7724e1afd2a164
|
7
|
+
data.tar.gz: 5426b9ff42ce8033cf403be706da8a3dea94c88056a7a621218c0bc9aabe676571f868c263bef55266175759c95cc7f54267108f86cb483b0adacd11ce844968
|
data/CHANGELOG.md
CHANGED
@@ -2280,13 +2280,47 @@ ary_histogram_calculate_edge(VALUE ary, const long nbins, const int left_p)
|
|
2280
2280
|
return edge;
|
2281
2281
|
}
|
2282
2282
|
|
2283
|
+
static VALUE
|
2284
|
+
check_histogram_weight_array(VALUE weight_array, const long ary_len)
|
2285
|
+
{
|
2286
|
+
if (weight_array == Qundef) return Qnil;
|
2287
|
+
|
2288
|
+
weight_array = rb_check_convert_type(weight_array, T_ARRAY, "Array", "to_ary");
|
2289
|
+
if (RARRAY_LEN(weight_array) != ary_len) {
|
2290
|
+
rb_raise(rb_eArgError, "weight array must have the same number of items as the receiver array");
|
2291
|
+
}
|
2292
|
+
|
2293
|
+
return weight_array;
|
2294
|
+
}
|
2295
|
+
|
2296
|
+
static VALUE
|
2297
|
+
check_histogram_edges(VALUE edges)
|
2298
|
+
{
|
2299
|
+
if (edges == Qundef) return Qnil;
|
2300
|
+
return rb_check_convert_type(edges, T_ARRAY, "Array", "to_ary");
|
2301
|
+
}
|
2302
|
+
|
2303
|
+
static int
|
2304
|
+
check_histogram_left_p(VALUE closed)
|
2305
|
+
{
|
2306
|
+
int left_p = (closed != sym_right);
|
2307
|
+
if (left_p && closed != Qundef && closed != sym_left) {
|
2308
|
+
rb_raise(rb_eArgError, "invalid value for :closed keyword "
|
2309
|
+
"(%"PRIsVALUE" for :left or :right)", closed);
|
2310
|
+
}
|
2311
|
+
return left_p;
|
2312
|
+
}
|
2313
|
+
|
2283
2314
|
/* call-seq:
|
2284
2315
|
* ary.histogram(nbins=:auto, weight: nil, closed: :left)
|
2285
2316
|
*
|
2286
2317
|
* @param [Integer] nbins The approximate number of bins
|
2287
|
-
* @params [Array<Numeric>]
|
2318
|
+
* @params [Array<Numeric>] weights
|
2288
2319
|
* An optional weight array, that has the same length as the receiver.
|
2289
2320
|
* `weight[i]` means the weight value of the i-th element in the receiver.
|
2321
|
+
* @params [Array<Numeric>] edges
|
2322
|
+
* An optional edge array, that specify the bin edges.
|
2323
|
+
* This array must be sorted.
|
2290
2324
|
* @param [:left, :right] closed
|
2291
2325
|
* If :left (the default), the bin interval are left-closed.
|
2292
2326
|
* If :right, the bin interval are right-closed.
|
@@ -2296,10 +2330,11 @@ ary_histogram_calculate_edge(VALUE ary, const long nbins, const int left_p)
|
|
2296
2330
|
static VALUE
|
2297
2331
|
ary_histogram(int argc, VALUE *argv, VALUE ary)
|
2298
2332
|
{
|
2299
|
-
VALUE arg0, kwargs,
|
2333
|
+
VALUE arg0, kwargs, bin_weights;
|
2300
2334
|
long nbins, n_bin_weights, i;
|
2301
2335
|
|
2302
2336
|
VALUE weight_array = Qnil;
|
2337
|
+
VALUE edges = Qnil;
|
2303
2338
|
int left_p = 1;
|
2304
2339
|
|
2305
2340
|
rb_scan_args(argc, argv, "01:", &arg0, &kwargs);
|
@@ -2311,48 +2346,36 @@ ary_histogram(int argc, VALUE *argv, VALUE ary)
|
|
2311
2346
|
}
|
2312
2347
|
|
2313
2348
|
if (!NIL_P(kwargs)) {
|
2314
|
-
enum {
|
2315
|
-
static ID kwarg_keys[
|
2316
|
-
VALUE kwarg_vals[
|
2317
|
-
VALUE closed;
|
2349
|
+
enum { kw_weights, kw_edges, kw_closed };
|
2350
|
+
static ID kwarg_keys[3];
|
2351
|
+
VALUE kwarg_vals[3];
|
2318
2352
|
|
2319
2353
|
if (!kwarg_keys[0]) {
|
2320
|
-
kwarg_keys[
|
2354
|
+
kwarg_keys[kw_weights] = rb_intern("weights");
|
2355
|
+
kwarg_keys[kw_edges] = rb_intern("edges");
|
2321
2356
|
kwarg_keys[kw_closed] = rb_intern("closed");
|
2322
2357
|
}
|
2323
2358
|
|
2324
|
-
rb_get_kwargs(kwargs, kwarg_keys, 0,
|
2359
|
+
rb_get_kwargs(kwargs, kwarg_keys, 0, 3, kwarg_vals);
|
2325
2360
|
|
2326
|
-
weight_array = kwarg_vals[
|
2327
|
-
|
2328
|
-
|
2329
|
-
if (RARRAY_LEN(weight_array) != RARRAY_LEN(ary)) {
|
2330
|
-
rb_raise(rb_eArgError, "weight array must have the same number of items as the receiver array");
|
2331
|
-
}
|
2332
|
-
}
|
2333
|
-
else {
|
2334
|
-
weight_array = Qnil;
|
2335
|
-
}
|
2336
|
-
|
2337
|
-
closed = kwarg_vals[kw_closed];
|
2338
|
-
left_p = (closed != sym_right);
|
2339
|
-
if (left_p && closed != Qundef && closed != sym_left) {
|
2340
|
-
rb_raise(rb_eArgError, "invalid value for :closed keyword "
|
2341
|
-
"(%"PRIsVALUE" for :left or :right)", closed);
|
2342
|
-
}
|
2361
|
+
weight_array = check_histogram_weight_array(kwarg_vals[kw_weights], RARRAY_LEN(ary));
|
2362
|
+
edges = check_histogram_edges(kwarg_vals[kw_edges]);
|
2363
|
+
left_p = check_histogram_left_p(kwarg_vals[kw_closed]);
|
2343
2364
|
}
|
2344
2365
|
|
2345
|
-
|
2366
|
+
if (NIL_P(edges)) {
|
2367
|
+
edges = ary_histogram_calculate_edge(ary, nbins, left_p);
|
2368
|
+
}
|
2346
2369
|
|
2347
|
-
n_bin_weights = RARRAY_LEN(
|
2370
|
+
n_bin_weights = RARRAY_LEN(edges) - 1;
|
2348
2371
|
bin_weights = rb_ary_new_capa(n_bin_weights);
|
2349
2372
|
for (i = 0; i < n_bin_weights; ++i) {
|
2350
2373
|
rb_ary_store(bin_weights, i, INT2FIX(0));
|
2351
2374
|
}
|
2352
2375
|
|
2353
|
-
histogram_weights_push_values(bin_weights,
|
2376
|
+
histogram_weights_push_values(bin_weights, edges, ary, weight_array, left_p);
|
2354
2377
|
|
2355
|
-
return rb_struct_new(cHistogram,
|
2378
|
+
return rb_struct_new(cHistogram, edges, bin_weights,
|
2356
2379
|
left_p ? sym_left : sym_right,
|
2357
2380
|
Qfalse);
|
2358
2381
|
}
|