enumerable-statistics 2.0.0 → 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 +4 -4
- data/.github/workflows/ci.yml +47 -0
- data/CHANGELOG.md +27 -1
- data/Rakefile +9 -0
- data/enumerable-statistics.gemspec +2 -1
- data/ext/enumerable/statistics/extension/array_ext.c +60 -0
- data/ext/enumerable/statistics/extension/statistics.c +126 -42
- data/lib/enumerable_statistics.rb +1 -0
- data/lib/enumerable_statistics/array_ext.rb +37 -0
- data/lib/enumerable_statistics/histogram.rb +2 -1
- data/lib/enumerable_statistics/version.rb +1 -1
- metadata +22 -8
- data/.travis.yml +0 -32
- data/ext/-bench-/extconf.rb +0 -3
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
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
- push
|
|
5
|
+
|
|
6
|
+
jobs:
|
|
7
|
+
cruby:
|
|
8
|
+
name: Test
|
|
9
|
+
runs-on: ${{ matrix.os }}
|
|
10
|
+
|
|
11
|
+
strategy:
|
|
12
|
+
fail-fast: false
|
|
13
|
+
matrix:
|
|
14
|
+
os:
|
|
15
|
+
- ubuntu-latest
|
|
16
|
+
- macos-latest
|
|
17
|
+
- windows-latest
|
|
18
|
+
ruby:
|
|
19
|
+
- 3.0
|
|
20
|
+
- 2.7
|
|
21
|
+
- 2.6
|
|
22
|
+
- 2.5
|
|
23
|
+
- 2.4
|
|
24
|
+
- debug
|
|
25
|
+
exclude:
|
|
26
|
+
- os: windows-latest
|
|
27
|
+
ruby: 3.0
|
|
28
|
+
- os: windows-latest
|
|
29
|
+
ruby: debug
|
|
30
|
+
|
|
31
|
+
steps:
|
|
32
|
+
- uses: actions/checkout@v2
|
|
33
|
+
|
|
34
|
+
- name: Setup Ruby
|
|
35
|
+
uses: ruby/setup-ruby@v1
|
|
36
|
+
with:
|
|
37
|
+
ruby-version: ${{ matrix.ruby }}
|
|
38
|
+
|
|
39
|
+
- run: gem install bundler
|
|
40
|
+
- run: bundle install
|
|
41
|
+
|
|
42
|
+
- run: rake --trace compile
|
|
43
|
+
|
|
44
|
+
- run: rake build
|
|
45
|
+
- run: gem install pkg/*gem
|
|
46
|
+
|
|
47
|
+
- run: rake
|
data/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,30 @@
|
|
|
1
|
-
# 2.0.
|
|
1
|
+
# 2.0.6
|
|
2
|
+
|
|
3
|
+
- Add edges parameter in histogram
|
|
4
|
+
- Rename parameter in histogram to fix typo: `weight` to `weights`
|
|
5
|
+
|
|
6
|
+
# 2.0.5
|
|
7
|
+
|
|
8
|
+
- Add weighted histogram support
|
|
9
|
+
|
|
10
|
+
# 2.0.4
|
|
11
|
+
|
|
12
|
+
- Add `find_min`, `find_max`, `argmin`, `argmax` methods
|
|
13
|
+
- Fix `nbin=:auto` case in `histogram` method
|
|
14
|
+
|
|
15
|
+
# 2.0.3
|
|
16
|
+
|
|
17
|
+
- Ractor-safe version
|
|
18
|
+
|
|
19
|
+
# 2.0.2
|
|
20
|
+
|
|
21
|
+
- Support Ruby 3.0
|
|
22
|
+
|
|
23
|
+
# 2.0.1
|
|
24
|
+
|
|
25
|
+
- Fix a bug of `histogram` (#9)
|
|
26
|
+
|
|
27
|
+
# 2.0.0
|
|
2
28
|
|
|
3
29
|
- Add `value_counts` method in Array, Hash, and Enumerable
|
|
4
30
|
- Add `median` method in Array
|
data/Rakefile
CHANGED
|
@@ -8,7 +8,14 @@ Rake::ExtensionTask.new('enumerable/statistics/extension')
|
|
|
8
8
|
|
|
9
9
|
directory 'lib/enumerable/statistics'
|
|
10
10
|
|
|
11
|
+
desc "Run test"
|
|
12
|
+
task :test do
|
|
13
|
+
ruby("test/run-test.rb")
|
|
14
|
+
end
|
|
15
|
+
task :test => :compile
|
|
16
|
+
|
|
11
17
|
RSpec::Core::RakeTask.new(:spec)
|
|
18
|
+
task :spec => :compile
|
|
12
19
|
|
|
13
20
|
task :bench do
|
|
14
21
|
puts "# sum\n"
|
|
@@ -20,3 +27,5 @@ task :bench do
|
|
|
20
27
|
puts "# variance\n"
|
|
21
28
|
system('benchmark-driver bench/variance.yml')
|
|
22
29
|
end
|
|
30
|
+
|
|
31
|
+
task default: [:test, :spec]
|
|
@@ -27,10 +27,11 @@ Gem::Specification.new do |spec|
|
|
|
27
27
|
|
|
28
28
|
spec.required_ruby_version = '>= 2.4'
|
|
29
29
|
|
|
30
|
-
spec.add_development_dependency "bundler"
|
|
30
|
+
spec.add_development_dependency "bundler"
|
|
31
31
|
spec.add_development_dependency "rake"
|
|
32
32
|
spec.add_development_dependency "rake-compiler", ">= 0.9.8"
|
|
33
33
|
spec.add_development_dependency "rspec", ">= 3.4"
|
|
34
|
+
spec.add_development_dependency "test-unit"
|
|
34
35
|
spec.add_development_dependency "fuubar"
|
|
35
36
|
spec.add_development_dependency "yard"
|
|
36
37
|
spec.add_development_dependency "benchmark-driver"
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#include <ruby/ruby.h>
|
|
2
|
+
|
|
3
|
+
static VALUE
|
|
4
|
+
ary_find_max(VALUE ary)
|
|
5
|
+
{
|
|
6
|
+
const long n = RARRAY_LEN(ary);
|
|
7
|
+
if (n == 0) {
|
|
8
|
+
return Qnil;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
long imax = 0;
|
|
12
|
+
VALUE max = RARRAY_AREF(ary, imax);
|
|
13
|
+
|
|
14
|
+
long i;
|
|
15
|
+
for (i = 1; i < n; ++i) {
|
|
16
|
+
VALUE v = RARRAY_AREF(ary, i);
|
|
17
|
+
if (RTEST(rb_funcall(v, '>', 1, max))) {
|
|
18
|
+
imax = i;
|
|
19
|
+
max = v;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return rb_assoc_new(max, LONG2NUM(imax));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static VALUE
|
|
27
|
+
ary_find_min(VALUE ary)
|
|
28
|
+
{
|
|
29
|
+
const long n = RARRAY_LEN(ary);
|
|
30
|
+
if (n == 0) {
|
|
31
|
+
return Qnil;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
long imin = 0;
|
|
35
|
+
VALUE min = RARRAY_AREF(ary, imin);
|
|
36
|
+
|
|
37
|
+
long i;
|
|
38
|
+
for (i = 1; i < n; ++i) {
|
|
39
|
+
VALUE v = RARRAY_AREF(ary, i);
|
|
40
|
+
if (RTEST(rb_funcall(v, '<', 1, min))) {
|
|
41
|
+
imin = i;
|
|
42
|
+
min = v;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return rb_assoc_new(min, LONG2NUM(imin));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
void
|
|
50
|
+
Init_array_extension(void)
|
|
51
|
+
{
|
|
52
|
+
VALUE mEnumerableStatistics = rb_const_get_at(rb_cObject, rb_intern("EnumerableStatistics"));
|
|
53
|
+
VALUE mArrayExtension = rb_const_get_at(mEnumerableStatistics, rb_intern("ArrayExtension"));
|
|
54
|
+
|
|
55
|
+
rb_undef_method(mArrayExtension, "find_max");
|
|
56
|
+
rb_define_method(mArrayExtension, "find_max", ary_find_max, 0);
|
|
57
|
+
|
|
58
|
+
rb_undef_method(mArrayExtension, "find_min");
|
|
59
|
+
rb_define_method(mArrayExtension, "find_min", ary_find_min, 0);
|
|
60
|
+
}
|
|
@@ -44,7 +44,7 @@ struct RRational {
|
|
|
44
44
|
#endif
|
|
45
45
|
|
|
46
46
|
#ifndef RRATIONAL
|
|
47
|
-
# define RRATIONAL(obj) (
|
|
47
|
+
# define RRATIONAL(obj) ((struct RRational *)(obj))
|
|
48
48
|
#endif
|
|
49
49
|
|
|
50
50
|
#ifndef RRATIONAL_SET_NUM
|
|
@@ -64,7 +64,7 @@ struct RComplex {
|
|
|
64
64
|
#endif
|
|
65
65
|
|
|
66
66
|
#ifndef RCOMPLEX
|
|
67
|
-
# define RCOMPLEX(obj) (
|
|
67
|
+
# define RCOMPLEX(obj) ((struct RComplex *)(obj))
|
|
68
68
|
#endif
|
|
69
69
|
|
|
70
70
|
#ifndef RCOMPLEX_SET_REAL
|
|
@@ -97,7 +97,7 @@ static ID idPow, idPLUS, idMINUS, idSTAR, idDIV, idGE;
|
|
|
97
97
|
static ID id_eqeq_p, id_idiv, id_negate, id_to_f, id_cmp, id_nan_p;
|
|
98
98
|
static ID id_each, id_real_p, id_sum, id_population, id_closed, id_edge;
|
|
99
99
|
|
|
100
|
-
static VALUE sym_left, sym_right;
|
|
100
|
+
static VALUE sym_auto, sym_left, sym_right;
|
|
101
101
|
|
|
102
102
|
static VALUE cHistogram;
|
|
103
103
|
|
|
@@ -2102,50 +2102,61 @@ histogram_edge_bin_index(VALUE edge, VALUE rb_x, int left_p)
|
|
|
2102
2102
|
}
|
|
2103
2103
|
|
|
2104
2104
|
static void
|
|
2105
|
-
histogram_weights_push_values(VALUE
|
|
2105
|
+
histogram_weights_push_values(VALUE bin_weights, VALUE edge, VALUE values, VALUE weight_array, int left_p)
|
|
2106
2106
|
{
|
|
2107
2107
|
VALUE x, cur;
|
|
2108
|
-
long i, n, bi;
|
|
2108
|
+
long i, n, bi, one, weighted = 0;
|
|
2109
2109
|
|
|
2110
2110
|
n = RARRAY_LEN(values);
|
|
2111
|
+
|
|
2112
|
+
if (! NIL_P(weight_array)) {
|
|
2113
|
+
assert(RB_TYPE_P(weight_array, T_ARRAY));
|
|
2114
|
+
assert(RARRAY_LEN(weight_array) == n);
|
|
2115
|
+
weighted = 1;
|
|
2116
|
+
}
|
|
2117
|
+
|
|
2118
|
+
one = INT2FIX(1);
|
|
2111
2119
|
for (i = 0; i < n; ++i) {
|
|
2112
2120
|
x = RARRAY_AREF(values, i);
|
|
2113
2121
|
|
|
2122
|
+
VALUE w;
|
|
2123
|
+
if (weighted) {
|
|
2124
|
+
w = RARRAY_AREF(weight_array, i);
|
|
2125
|
+
if (RB_TYPE_P(w, T_COMPLEX)) {
|
|
2126
|
+
VALUE imag = RCOMPLEX(w)->imag;
|
|
2127
|
+
if (! RTEST(f_zero_p(imag))) {
|
|
2128
|
+
goto type_error;
|
|
2129
|
+
}
|
|
2130
|
+
}
|
|
2131
|
+
else if (rb_obj_is_kind_of(w, rb_cNumeric)) {
|
|
2132
|
+
if (!RTEST(f_real_p(w))) {
|
|
2133
|
+
goto type_error;
|
|
2134
|
+
}
|
|
2135
|
+
}
|
|
2136
|
+
else {
|
|
2137
|
+
goto type_error;
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
else {
|
|
2141
|
+
w = one;
|
|
2142
|
+
}
|
|
2143
|
+
|
|
2114
2144
|
bi = histogram_edge_bin_index(edge, x, left_p);
|
|
2115
2145
|
|
|
2116
|
-
cur = rb_ary_entry(
|
|
2146
|
+
cur = rb_ary_entry(bin_weights, bi);
|
|
2117
2147
|
if (NIL_P(cur)) {
|
|
2118
|
-
cur =
|
|
2148
|
+
cur = w;
|
|
2119
2149
|
}
|
|
2120
2150
|
else {
|
|
2121
|
-
cur = rb_funcall(cur, idPLUS, 1,
|
|
2151
|
+
cur = rb_funcall(cur, idPLUS, 1, w);
|
|
2122
2152
|
}
|
|
2123
2153
|
|
|
2124
|
-
rb_ary_store(
|
|
2154
|
+
rb_ary_store(bin_weights, bi, cur);
|
|
2125
2155
|
}
|
|
2126
|
-
|
|
2156
|
+
return;
|
|
2127
2157
|
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
{
|
|
2131
|
-
int left_p = 1;
|
|
2132
|
-
|
|
2133
|
-
if (!NIL_P(opts)) {
|
|
2134
|
-
VALUE closed;
|
|
2135
|
-
#ifdef HAVE_RB_GET_KWARGS
|
|
2136
|
-
ID kwargs = id_closed;
|
|
2137
|
-
rb_get_kwargs(opts, &kwargs, 0, 1, &closed);
|
|
2138
|
-
#else
|
|
2139
|
-
closed = rb_hash_lookup2(opts, ID2SYM(id_closed), sym_left);
|
|
2140
|
-
#endif
|
|
2141
|
-
left_p = (closed != sym_right);
|
|
2142
|
-
if (left_p && closed != sym_left) {
|
|
2143
|
-
rb_raise(rb_eArgError, "invalid value for :closed keyword "
|
|
2144
|
-
"(%"PRIsVALUE" for :left or :right)", closed);
|
|
2145
|
-
}
|
|
2146
|
-
}
|
|
2147
|
-
|
|
2148
|
-
return left_p;
|
|
2158
|
+
type_error:
|
|
2159
|
+
rb_raise(rb_eTypeError, "weight array must have only real numbers");
|
|
2149
2160
|
}
|
|
2150
2161
|
|
|
2151
2162
|
static inline long
|
|
@@ -2269,10 +2280,47 @@ ary_histogram_calculate_edge(VALUE ary, const long nbins, const int left_p)
|
|
|
2269
2280
|
return edge;
|
|
2270
2281
|
}
|
|
2271
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
|
+
|
|
2272
2314
|
/* call-seq:
|
|
2273
|
-
* ary.histogram(nbins=:auto, closed: :left)
|
|
2315
|
+
* ary.histogram(nbins=:auto, weight: nil, closed: :left)
|
|
2274
2316
|
*
|
|
2275
2317
|
* @param [Integer] nbins The approximate number of bins
|
|
2318
|
+
* @params [Array<Numeric>] weights
|
|
2319
|
+
* An optional weight array, that has the same length as the receiver.
|
|
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.
|
|
2276
2324
|
* @param [:left, :right] closed
|
|
2277
2325
|
* If :left (the default), the bin interval are left-closed.
|
|
2278
2326
|
* If :right, the bin interval are right-closed.
|
|
@@ -2282,24 +2330,52 @@ ary_histogram_calculate_edge(VALUE ary, const long nbins, const int left_p)
|
|
|
2282
2330
|
static VALUE
|
|
2283
2331
|
ary_histogram(int argc, VALUE *argv, VALUE ary)
|
|
2284
2332
|
{
|
|
2285
|
-
VALUE arg0,
|
|
2286
|
-
|
|
2287
|
-
long nbins;
|
|
2333
|
+
VALUE arg0, kwargs, bin_weights;
|
|
2334
|
+
long nbins, n_bin_weights, i;
|
|
2288
2335
|
|
|
2289
|
-
|
|
2290
|
-
|
|
2336
|
+
VALUE weight_array = Qnil;
|
|
2337
|
+
VALUE edges = Qnil;
|
|
2338
|
+
int left_p = 1;
|
|
2339
|
+
|
|
2340
|
+
rb_scan_args(argc, argv, "01:", &arg0, &kwargs);
|
|
2341
|
+
if (NIL_P(arg0) || arg0 == sym_auto) {
|
|
2291
2342
|
nbins = sturges(RARRAY_LEN(ary));
|
|
2292
2343
|
}
|
|
2293
2344
|
else {
|
|
2294
2345
|
nbins = NUM2LONG(arg0);
|
|
2295
2346
|
}
|
|
2296
|
-
left_p = opt_closed_left_p(opts);
|
|
2297
2347
|
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2348
|
+
if (!NIL_P(kwargs)) {
|
|
2349
|
+
enum { kw_weights, kw_edges, kw_closed };
|
|
2350
|
+
static ID kwarg_keys[3];
|
|
2351
|
+
VALUE kwarg_vals[3];
|
|
2301
2352
|
|
|
2302
|
-
|
|
2353
|
+
if (!kwarg_keys[0]) {
|
|
2354
|
+
kwarg_keys[kw_weights] = rb_intern("weights");
|
|
2355
|
+
kwarg_keys[kw_edges] = rb_intern("edges");
|
|
2356
|
+
kwarg_keys[kw_closed] = rb_intern("closed");
|
|
2357
|
+
}
|
|
2358
|
+
|
|
2359
|
+
rb_get_kwargs(kwargs, kwarg_keys, 0, 3, kwarg_vals);
|
|
2360
|
+
|
|
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]);
|
|
2364
|
+
}
|
|
2365
|
+
|
|
2366
|
+
if (NIL_P(edges)) {
|
|
2367
|
+
edges = ary_histogram_calculate_edge(ary, nbins, left_p);
|
|
2368
|
+
}
|
|
2369
|
+
|
|
2370
|
+
n_bin_weights = RARRAY_LEN(edges) - 1;
|
|
2371
|
+
bin_weights = rb_ary_new_capa(n_bin_weights);
|
|
2372
|
+
for (i = 0; i < n_bin_weights; ++i) {
|
|
2373
|
+
rb_ary_store(bin_weights, i, INT2FIX(0));
|
|
2374
|
+
}
|
|
2375
|
+
|
|
2376
|
+
histogram_weights_push_values(bin_weights, edges, ary, weight_array, left_p);
|
|
2377
|
+
|
|
2378
|
+
return rb_struct_new(cHistogram, edges, bin_weights,
|
|
2303
2379
|
left_p ? sym_left : sym_right,
|
|
2304
2380
|
Qfalse);
|
|
2305
2381
|
}
|
|
@@ -2309,6 +2385,10 @@ Init_extension(void)
|
|
|
2309
2385
|
{
|
|
2310
2386
|
VALUE mEnumerableStatistics;
|
|
2311
2387
|
|
|
2388
|
+
#ifdef HAVE_RB_EXT_RACTOR_SAFE
|
|
2389
|
+
rb_ext_ractor_safe(true);
|
|
2390
|
+
#endif
|
|
2391
|
+
|
|
2312
2392
|
#ifndef HAVE_ENUM_SUM
|
|
2313
2393
|
rb_define_method(rb_mEnumerable, "sum", enum_sum, -1);
|
|
2314
2394
|
#endif
|
|
@@ -2342,6 +2422,9 @@ Init_extension(void)
|
|
|
2342
2422
|
|
|
2343
2423
|
rb_define_method(rb_cArray, "histogram", ary_histogram, -1);
|
|
2344
2424
|
|
|
2425
|
+
void Init_array_extension(void);
|
|
2426
|
+
Init_array_extension();
|
|
2427
|
+
|
|
2345
2428
|
idPLUS = '+';
|
|
2346
2429
|
idMINUS = '-';
|
|
2347
2430
|
idSTAR = '*';
|
|
@@ -2361,6 +2444,7 @@ Init_extension(void)
|
|
|
2361
2444
|
id_closed = rb_intern("closed");
|
|
2362
2445
|
id_edge = rb_intern("edge");
|
|
2363
2446
|
|
|
2447
|
+
sym_auto = ID2SYM(rb_intern("auto"));
|
|
2364
2448
|
sym_left = ID2SYM(rb_intern("left"));
|
|
2365
2449
|
sym_right = ID2SYM(rb_intern("right"));
|
|
2366
2450
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module EnumerableStatistics
|
|
2
|
+
module ArrayExtension
|
|
3
|
+
def find_max
|
|
4
|
+
n = size
|
|
5
|
+
return nil if n == 0
|
|
6
|
+
|
|
7
|
+
imax, i = 0, 1
|
|
8
|
+
while i < n
|
|
9
|
+
imax = i if self[i] > self[imax]
|
|
10
|
+
i += 1
|
|
11
|
+
end
|
|
12
|
+
[self[imax], imax]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def argmax
|
|
16
|
+
find_max[1]
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def find_min
|
|
20
|
+
n = size
|
|
21
|
+
return nil if n == 0
|
|
22
|
+
|
|
23
|
+
imin, i = 0, 1
|
|
24
|
+
while i < n
|
|
25
|
+
imin = i if self[i] < self[imax]
|
|
26
|
+
i += 1
|
|
27
|
+
end
|
|
28
|
+
[self[imin], imin]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def argmin
|
|
32
|
+
find_min[1]
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
Array.include ArrayExtension
|
|
37
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: enumerable-statistics
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.
|
|
4
|
+
version: 2.0.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kenta Murata
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-06-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version:
|
|
19
|
+
version: '0'
|
|
20
20
|
type: :development
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version:
|
|
26
|
+
version: '0'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: rake
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -66,6 +66,20 @@ dependencies:
|
|
|
66
66
|
- - ">="
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
68
|
version: '3.4'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: test-unit
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
69
83
|
- !ruby/object:Gem::Dependency
|
|
70
84
|
name: fuubar
|
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -114,12 +128,11 @@ email:
|
|
|
114
128
|
executables: []
|
|
115
129
|
extensions:
|
|
116
130
|
- ext/enumerable/statistics/extension/extconf.rb
|
|
117
|
-
- ext/-bench-/extconf.rb
|
|
118
131
|
extra_rdoc_files: []
|
|
119
132
|
files:
|
|
133
|
+
- ".github/workflows/ci.yml"
|
|
120
134
|
- ".gitignore"
|
|
121
135
|
- ".rspec"
|
|
122
|
-
- ".travis.yml"
|
|
123
136
|
- ".yardopts"
|
|
124
137
|
- CHANGELOG.md
|
|
125
138
|
- Gemfile
|
|
@@ -136,12 +149,13 @@ files:
|
|
|
136
149
|
- bin/rspec
|
|
137
150
|
- bin/setup
|
|
138
151
|
- enumerable-statistics.gemspec
|
|
139
|
-
- ext
|
|
152
|
+
- ext/enumerable/statistics/extension/array_ext.c
|
|
140
153
|
- ext/enumerable/statistics/extension/extconf.rb
|
|
141
154
|
- ext/enumerable/statistics/extension/statistics.c
|
|
142
155
|
- images/benchmark.png
|
|
143
156
|
- lib/enumerable/statistics.rb
|
|
144
157
|
- lib/enumerable_statistics.rb
|
|
158
|
+
- lib/enumerable_statistics/array_ext.rb
|
|
145
159
|
- lib/enumerable_statistics/histogram.rb
|
|
146
160
|
- lib/enumerable_statistics/version.rb
|
|
147
161
|
- templates/default/layout/html/headers.erb
|
|
@@ -275,7 +289,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
275
289
|
- !ruby/object:Gem::Version
|
|
276
290
|
version: '0'
|
|
277
291
|
requirements: []
|
|
278
|
-
rubygems_version: 3.
|
|
292
|
+
rubygems_version: 3.2.3
|
|
279
293
|
signing_key:
|
|
280
294
|
specification_version: 4
|
|
281
295
|
summary: Statistics features for Enumerable
|
data/.travis.yml
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
notification:
|
|
3
|
-
email:
|
|
4
|
-
- mrkn@ruby-lang.org
|
|
5
|
-
|
|
6
|
-
language: ruby
|
|
7
|
-
|
|
8
|
-
before_install:
|
|
9
|
-
- yes | gem update --system
|
|
10
|
-
- gem install bundler
|
|
11
|
-
|
|
12
|
-
install:
|
|
13
|
-
- bundle install
|
|
14
|
-
|
|
15
|
-
script:
|
|
16
|
-
- bundle exec rake --trace clobber compile
|
|
17
|
-
- bundle exec rake spec
|
|
18
|
-
|
|
19
|
-
matrix:
|
|
20
|
-
include:
|
|
21
|
-
- name: "2.3"
|
|
22
|
-
rvm: 2.3
|
|
23
|
-
- name: "2.4"
|
|
24
|
-
rvm: 2.4.5
|
|
25
|
-
- name: "2.5"
|
|
26
|
-
rvm: 2.5.2
|
|
27
|
-
- name: "2.6"
|
|
28
|
-
rvm: 2.6
|
|
29
|
-
- name: "trunk"
|
|
30
|
-
rvm: ruby-head
|
|
31
|
-
allow_failures:
|
|
32
|
-
- rvm: 2.3
|
data/ext/-bench-/extconf.rb
DELETED