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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a2232329c5ed735d60a1b661d6a0db1b9522cc9cad8f98eb8fc1c6db9026b2cb
4
- data.tar.gz: ef322c74597e29f8e10c62887feceedc400bbadaa6858ffe80f60949ca31f56d
3
+ metadata.gz: 13fa1238cfb0a52ebd9c7f067e43660316027ecf0c9f03c387f0022c0ba4dace
4
+ data.tar.gz: bc4bbdb7664ae87f1be7ed302dcae63d852f09ed05dcd5a30a8f6e8368bdd2de
5
5
  SHA512:
6
- metadata.gz: 9a745b45d333641210bd942a39609b32df1a18638fdbe03c50fd884c5b31c186816019e2a02532ed23b719b24869054434ea227c0a0a9254155d0dc4d9fd1be4
7
- data.tar.gz: 288ea51ef740d909a6f66f5506de47112071d7d6fb7fe6e9bf6e2c04f470ac397cfc3b1edd8da1fd1228ffc5b3ef31eecc6f7265867ec51d03f40ebe88c2d35d
6
+ metadata.gz: bd834ddb4e45505e61d6bf81b7d4b8147228d12c3321d9fb3cc2fc8a3f51fe40e885010fc59e0a44b1f0d4b11780b2744f2b36236446dab178f91a1fb633d096
7
+ data.tar.gz: 0d75394f0ce6c63329de7c8549644fa8c3c5d5ada1883a8f48175c6683cb573b507006302b64ca31e4c12d58577f1a47ff9ca3ae4237e72dac76d52be4f3d1d8
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Numo::NArray - New NArray class library for Ruby/Numo (NUmerical MOdule)
1
+ # Numo::NArray
2
2
 
3
3
  [![Binder](http://mybinder.org/badge.svg)](http://mybinder.org/repo/ruby-numo/numo-narray)
4
4
  [![Build Status](https://travis-ci.org/ruby-numo/numo-narray.svg?branch=master)](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%E6%A6%82%E8%A6%81) (in Japanese)
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
 
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  array.c
3
3
  Ruby/Numo::NArray - Numerical Array class for Ruby
4
- Copyright (C) 1999-2019 Masahiro TANAKA
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
- v = rb_funcall(v,id_abs,0);
59
- if (RTEST(rb_funcall(v,id_le,1,int32_max))) {
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<0) x=-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
- v = rb_funcall(v,id_abs,0);
90
- if (RTEST(rb_funcall(v,id_le,1,int32_max))) {
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
  }
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  data.c
3
3
  Ruby/Numo::NArray - Numerical Array class for Ruby
4
- Copyright (C) 1999-2019 Masahiro TANAKA
4
+ Copyright (C) 1999-2020 Masahiro TANAKA
5
5
  */
6
6
 
7
7
  #include <ruby.h>
@@ -66,7 +66,7 @@ code = DefLib.new do
66
66
  end.result
67
67
 
68
68
  if $output
69
- open($output,"w").write(code)
69
+ File.write($output, code)
70
70
  else
71
71
  $stdout.write(code)
72
72
  end
@@ -3,6 +3,7 @@ def_id "eq"
3
3
  def_id "ne"
4
4
  def_id "pow"
5
5
  def_id "mulsum"
6
+ def_id "to_a"
6
7
  if is_complex
7
8
  def_id "real"
8
9
  def_id "imag"
@@ -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 %>
@@ -3,7 +3,7 @@
3
3
  Ruby/Numo::NArray - Numerical Array class for Ruby
4
4
 
5
5
  created on: 2017-03-11
6
- Copyright (C) 2017-2019 Masahiro Tanaka
6
+ Copyright (C) 2017-2020 Masahiro Tanaka
7
7
  */
8
8
 
9
9
  #include <ruby.h>
@@ -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 %>
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  index.c
3
3
  Ruby/Numo::NArray - Numerical Array class for Ruby
4
- Copyright (C) 1999-2019 Masahiro TANAKA
4
+ Copyright (C) 1999-2020 Masahiro TANAKA
5
5
  */
6
6
  //#define NARRAY_C
7
7
 
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  math.c
3
3
  Ruby/Numo::NArray - Numerical Array class for Ruby
4
- Copyright (C) 1999-2019 Masahiro TANAKA
4
+ Copyright (C) 1999-2020 Masahiro TANAKA
5
5
  */
6
6
  #include <ruby.h>
7
7
  #include "numo/narray.h"
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  narray.c
3
3
  Ruby/Numo::NArray - Numerical Array class for Ruby
4
- Copyright (C) 1999-2019 Masahiro TANAKA
4
+ Copyright (C) 1999-2020 Masahiro TANAKA
5
5
  */
6
6
  #define NARRAY_C
7
7
  #include <ruby.h>
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  ndloop.c
3
3
  Ruby/Numo::NArray - Numerical Array class for Ruby
4
- Copyright (C) 1999-2019 Masahiro TANAKA
4
+ Copyright (C) 1999-2020 Masahiro TANAKA
5
5
  */
6
6
 
7
7
  #include <ruby.h>
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  intern.h
3
3
  Ruby/Numo::NArray - Numerical Array class for Ruby
4
- Copyright (C) 1999-2019 Masahiro TANAKA
4
+ Copyright (C) 1999-2020 Masahiro TANAKA
5
5
  */
6
6
  #ifndef INTERN_H
7
7
  #define INTERN_H
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  narray.h
3
3
  Ruby/Numo::NArray - Numerical Array class for Ruby
4
- Copyright (C) 1999-2019 Masahiro TANAKA
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.6"
17
- #define NARRAY_VERSION_CODE 916
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"
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  ndloop.h
3
3
  Ruby/Numo::NArray - Numerical Array class for Ruby
4
- Copyright (C) 1999-2019 Masahiro TANAKA
4
+ Copyright (C) 1999-2020 Masahiro TANAKA
5
5
  */
6
6
  #ifndef NDLOOP_H
7
7
  #define NDLOOP_H
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  template.h
3
3
  Ruby/Numo::NArray - Numerical Array class for Ruby
4
- Copyright (C) 1999-2019 Masahiro TANAKA
4
+ Copyright (C) 1999-2020 Masahiro TANAKA
5
5
  */
6
6
  #ifndef TEMPLATE_H
7
7
  #define TEMPLATE_H
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  complex.h
3
3
  Ruby/Numo::NArray - Numerical Array class for Ruby
4
- Copyright (C) 1999-2019 Masahiro TANAKA
4
+ Copyright (C) 1999-2020 Masahiro TANAKA
5
5
  */
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  step.c
3
3
  Ruby/Numo::NArray - Numerical Array class for Ruby
4
- Copyright (C) 2007-2019 Masahiro TANAKA
4
+ Copyright (C) 2007-2020 Masahiro TANAKA
5
5
  */
6
6
  #include <ruby.h>
7
7
  #include <math.h>
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  strut.c
3
3
  Ruby/Numo::NArray - Numerical Array class for Ruby
4
- Copyright (C) 1999-2019 Masahiro TANAKA
4
+ Copyright (C) 1999-2020 Masahiro TANAKA
5
5
  */
6
6
  #include <ruby.h>
7
7
  #include "numo/narray.h"
@@ -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, ...]
@@ -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.1'
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
- if RUBY_VERSION < '2.2' # Ruby 2.1.x
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.6
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: 2019-12-30 00:00:00.000000000 Z
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: '10.0'
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: '10.0'
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.1'
227
+ version: '2.2'
228
228
  required_rubygems_version: !ruby/object:Gem::Requirement
229
229
  requirements:
230
230
  - - ">="