numo-narray 0.9.1.6 → 0.9.1.7
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/README.md +2 -2
- data/ext/numo/narray/array.c +13 -12
- data/ext/numo/narray/data.c +1 -1
- data/ext/numo/narray/gen/cogen.rb +1 -1
- data/ext/numo/narray/gen/spec.rb +1 -0
- data/ext/numo/narray/gen/tmpl/cast.c +7 -0
- data/ext/numo/narray/gen/tmpl/lib.c +1 -1
- data/ext/numo/narray/gen/tmpl/store.c +9 -0
- data/ext/numo/narray/index.c +1 -1
- data/ext/numo/narray/math.c +1 -1
- data/ext/numo/narray/narray.c +1 -1
- data/ext/numo/narray/ndloop.c +1 -1
- data/ext/numo/narray/numo/intern.h +1 -1
- data/ext/numo/narray/numo/narray.h +3 -3
- data/ext/numo/narray/numo/ndloop.h +1 -1
- data/ext/numo/narray/numo/template.h +1 -1
- data/ext/numo/narray/numo/types/complex.h +1 -1
- data/ext/numo/narray/step.c +1 -1
- data/ext/numo/narray/struct.c +1 -1
- data/lib/numo/narray/extra.rb +29 -0
- data/numo-narray.gemspec +2 -6
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13fa1238cfb0a52ebd9c7f067e43660316027ecf0c9f03c387f0022c0ba4dace
|
4
|
+
data.tar.gz: bc4bbdb7664ae87f1be7ed302dcae63d852f09ed05dcd5a30a8f6e8368bdd2de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd834ddb4e45505e61d6bf81b7d4b8147228d12c3321d9fb3cc2fc8a3f51fe40e885010fc59e0a44b1f0d4b11780b2744f2b36236446dab178f91a1fb633d096
|
7
|
+
data.tar.gz: 0d75394f0ce6c63329de7c8549644fa8c3c5d5ada1883a8f48175c6683cb573b507006302b64ca31e4c12d58577f1a47ff9ca3ae4237e72dac76d52be4f3d1d8
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Numo::NArray
|
1
|
+
# Numo::NArray
|
2
2
|
|
3
3
|
[](http://mybinder.org/repo/ruby-numo/numo-narray)
|
4
4
|
[](https://travis-ci.org/ruby-numo/numo-narray)
|
@@ -18,7 +18,7 @@ All documents are primitive.
|
|
18
18
|
* [Numo::NArray API Doc](http://ruby-numo.github.io/numo-narray/yard/index.html)
|
19
19
|
* [Numo::NArray vs numpy](https://github.com/ruby-numo/numo-narray/wiki/Numo-vs-numpy)
|
20
20
|
* [Numo::NArray vs ndarray](https://github.com/ruby-numo/numo-narray/wiki/Numo-vs-ndarray)
|
21
|
-
* [Numo::NArray Overview](https://github.com/ruby-numo/numo-narray/wiki/Numo::NArray
|
21
|
+
* [Numo::NArray Overview](https://github.com/ruby-numo/numo-narray/wiki/Numo::NArray-Overview-(Japanese)) (in Japanese)
|
22
22
|
|
23
23
|
## Related Projects
|
24
24
|
|
data/ext/numo/narray/array.c
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
array.c
|
3
3
|
Ruby/Numo::NArray - Numerical Array class for Ruby
|
4
|
-
Copyright (C) 1999-
|
4
|
+
Copyright (C) 1999-2020 Masahiro TANAKA
|
5
5
|
*/
|
6
6
|
#include <ruby.h>
|
7
7
|
#include "numo/narray.h"
|
@@ -31,15 +31,12 @@ static ID id_abs;
|
|
31
31
|
static ID id_cast;
|
32
32
|
static ID id_le;
|
33
33
|
static ID id_Complex;
|
34
|
-
|
34
|
+
static VALUE int32_max = Qnil;
|
35
|
+
static VALUE int32_min = Qnil;
|
35
36
|
|
36
37
|
static VALUE
|
37
38
|
na_object_type(int type, VALUE v)
|
38
39
|
{
|
39
|
-
static VALUE int32_max = Qnil;
|
40
|
-
if (NIL_P(int32_max))
|
41
|
-
int32_max = ULONG2NUM(2147483647);
|
42
|
-
|
43
40
|
switch(TYPE(v)) {
|
44
41
|
|
45
42
|
case T_TRUE:
|
@@ -55,8 +52,8 @@ static VALUE
|
|
55
52
|
return type;
|
56
53
|
case T_BIGNUM:
|
57
54
|
if (type<NA_INT64) {
|
58
|
-
|
59
|
-
|
55
|
+
if (RTEST(rb_funcall(v,id_le,1,int32_max)) &&
|
56
|
+
RTEST(rb_funcall(v,id_ge,1,int32_min))) {
|
60
57
|
if (type<NA_INT32)
|
61
58
|
return NA_INT32;
|
62
59
|
} else {
|
@@ -69,8 +66,7 @@ static VALUE
|
|
69
66
|
case T_FIXNUM:
|
70
67
|
if (type<NA_INT64) {
|
71
68
|
long x = NUM2LONG(v);
|
72
|
-
if (x
|
73
|
-
if (x<=2147483647) {
|
69
|
+
if (x<=2147483647 && x>=-2147483648) {
|
74
70
|
if (type<NA_INT32)
|
75
71
|
return NA_INT32;
|
76
72
|
} else {
|
@@ -86,8 +82,8 @@ static VALUE
|
|
86
82
|
case T_FIXNUM:
|
87
83
|
case T_BIGNUM:
|
88
84
|
if (type<NA_INT64) {
|
89
|
-
|
90
|
-
|
85
|
+
if (RTEST(rb_funcall(v,id_le,1,int32_max)) &&
|
86
|
+
RTEST(rb_funcall(v,id_ge,1,int32_min))) {
|
91
87
|
if (type<NA_INT32)
|
92
88
|
return NA_INT32;
|
93
89
|
} else {
|
@@ -650,4 +646,9 @@ Init_nary_array()
|
|
650
646
|
id_abs = rb_intern("abs");
|
651
647
|
id_le = rb_intern("<=");
|
652
648
|
id_Complex = rb_intern("Complex");
|
649
|
+
|
650
|
+
rb_global_variable(&int32_max);
|
651
|
+
int32_max = INT2NUM(2147483647);
|
652
|
+
rb_global_variable(&int32_min);
|
653
|
+
int32_min = INT2NUM(-2147483648);
|
653
654
|
}
|
data/ext/numo/narray/data.c
CHANGED
data/ext/numo/narray/gen/spec.rb
CHANGED
@@ -35,6 +35,13 @@ static VALUE
|
|
35
35
|
}
|
36
36
|
return v;
|
37
37
|
}
|
38
|
+
if (rb_respond_to(obj,id_to_a)) {
|
39
|
+
obj = rb_funcall(obj,id_to_a,0);
|
40
|
+
if (TYPE(obj)!=T_ARRAY) {
|
41
|
+
rb_raise(rb_eTypeError, "`to_a' did not return Array");
|
42
|
+
}
|
43
|
+
return <%=find_tmpl("cast_array").c_func%>(obj);
|
44
|
+
}
|
38
45
|
<% if is_object %>
|
39
46
|
return robject_new_dim0(obj);
|
40
47
|
<% else %>
|
@@ -30,6 +30,15 @@ static VALUE
|
|
30
30
|
}
|
31
31
|
}
|
32
32
|
|
33
|
+
if (rb_respond_to(obj,id_to_a)) {
|
34
|
+
obj = rb_funcall(obj,id_to_a,0);
|
35
|
+
if (TYPE(obj)!=T_ARRAY) {
|
36
|
+
rb_raise(rb_eTypeError, "`to_a' did not return Array");
|
37
|
+
}
|
38
|
+
<%=store_array.c_func%>(self,obj);
|
39
|
+
return self;
|
40
|
+
}
|
41
|
+
|
33
42
|
<% if is_object %>
|
34
43
|
robject_store_numeric(self,obj);
|
35
44
|
<% else %>
|
data/ext/numo/narray/index.c
CHANGED
data/ext/numo/narray/math.c
CHANGED
data/ext/numo/narray/narray.c
CHANGED
data/ext/numo/narray/ndloop.c
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
narray.h
|
3
3
|
Ruby/Numo::NArray - Numerical Array class for Ruby
|
4
|
-
Copyright (C) 1999-
|
4
|
+
Copyright (C) 1999-2020 Masahiro TANAKA
|
5
5
|
*/
|
6
6
|
#ifndef NARRAY_H
|
7
7
|
#define NARRAY_H
|
@@ -13,8 +13,8 @@ extern "C" {
|
|
13
13
|
#endif
|
14
14
|
#endif
|
15
15
|
|
16
|
-
#define NARRAY_VERSION "0.9.1.
|
17
|
-
#define NARRAY_VERSION_CODE
|
16
|
+
#define NARRAY_VERSION "0.9.1.7"
|
17
|
+
#define NARRAY_VERSION_CODE 917
|
18
18
|
|
19
19
|
#include <math.h>
|
20
20
|
#include "numo/compat.h"
|
data/ext/numo/narray/step.c
CHANGED
data/ext/numo/narray/struct.c
CHANGED
data/lib/numo/narray/extra.rb
CHANGED
@@ -1171,6 +1171,35 @@ module Numo
|
|
1171
1171
|
end
|
1172
1172
|
end
|
1173
1173
|
|
1174
|
+
# Percentile
|
1175
|
+
#
|
1176
|
+
# @param q [Numo::NArray]
|
1177
|
+
# @param axis [Integer] applied axis
|
1178
|
+
# @return [Numo::NArray] return percentile
|
1179
|
+
def percentile(q, axis: nil)
|
1180
|
+
raise ArgumentError, "q is out of range" if q < 0 || q > 100
|
1181
|
+
|
1182
|
+
x = self
|
1183
|
+
unless axis
|
1184
|
+
axis = 0
|
1185
|
+
x = x.flatten
|
1186
|
+
end
|
1187
|
+
|
1188
|
+
sorted = x.sort(axis: axis)
|
1189
|
+
x = q / 100.0 * (sorted.shape[axis] - 1)
|
1190
|
+
r = x % 1
|
1191
|
+
i = x.floor
|
1192
|
+
refs = [true] * sorted.ndim
|
1193
|
+
refs[axis] = i
|
1194
|
+
if i == sorted.shape[axis] - 1
|
1195
|
+
sorted[*refs]
|
1196
|
+
else
|
1197
|
+
refs_upper = refs.dup
|
1198
|
+
refs_upper[axis] = i + 1
|
1199
|
+
sorted[*refs] + r * (sorted[*refs_upper] - sorted[*refs])
|
1200
|
+
end
|
1201
|
+
end
|
1202
|
+
|
1174
1203
|
# Kronecker product of two arrays.
|
1175
1204
|
#
|
1176
1205
|
# kron(a,b)[k_0, k_1, ...] = a[i_0, i_1, ...] * b[j_0, j_1, ...]
|
data/numo-narray.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.summary = %q{alpha release of Numo::NArray - New NArray class library in Ruby/Numo (NUmerical MOdule)}
|
21
21
|
spec.homepage = "https://github.com/ruby-numo/numo-narray"
|
22
22
|
spec.license = "BSD-3-Clause"
|
23
|
-
spec.required_ruby_version = '~> 2.
|
23
|
+
spec.required_ruby_version = '~> 2.2'
|
24
24
|
|
25
25
|
spec.files = `git ls-files Gemfile README.md Rakefile lib ext numo-narray.gemspec spec`.split($/)
|
26
26
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
@@ -33,10 +33,6 @@ Gem::Specification.new do |spec|
|
|
33
33
|
else
|
34
34
|
spec.add_development_dependency "bundler", "~> 2.0"
|
35
35
|
end
|
36
|
-
|
37
|
-
spec.add_development_dependency "rake", "<= 10.5", ">=10.1.1"
|
38
|
-
else
|
39
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
40
|
-
end
|
36
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
41
37
|
spec.add_development_dependency "test-unit", "~> 3.0"
|
42
38
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: numo-narray
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.1.
|
4
|
+
version: 0.9.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masahiro TANAKA
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 12.3.3
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 12.3.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: test-unit
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -224,7 +224,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
224
224
|
requirements:
|
225
225
|
- - "~>"
|
226
226
|
- !ruby/object:Gem::Version
|
227
|
-
version: '2.
|
227
|
+
version: '2.2'
|
228
228
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
229
229
|
requirements:
|
230
230
|
- - ">="
|