numo-narray 0.9.1.5 → 0.9.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -5
  3. data/Rakefile +4 -63
  4. data/ext/numo/narray/array.c +19 -26
  5. data/ext/numo/narray/data.c +2 -8
  6. data/ext/numo/narray/depend.erb +6 -10
  7. data/ext/numo/narray/extconf.rb +23 -21
  8. data/ext/numo/narray/gen/cogen.rb +2 -2
  9. data/ext/numo/narray/gen/narray_def.rb +1 -1
  10. data/ext/numo/narray/gen/spec.rb +12 -6
  11. data/ext/numo/narray/gen/tmpl/accum_binary.c +4 -0
  12. data/ext/numo/narray/gen/tmpl/alloc_func.c +4 -1
  13. data/ext/numo/narray/gen/tmpl/allocate.c +1 -0
  14. data/ext/numo/narray/gen/tmpl/cast.c +7 -0
  15. data/ext/numo/narray/gen/tmpl/lib.c +1 -1
  16. data/ext/numo/narray/gen/tmpl_bit/allocate.c +1 -0
  17. data/ext/numo/narray/gen/tmpl_bit/binary.c +6 -0
  18. data/ext/numo/narray/gen/tmpl_bit/store_bit.c +6 -2
  19. data/ext/numo/narray/gen/tmpl_bit/unary.c +4 -0
  20. data/ext/numo/narray/index.c +5 -11
  21. data/ext/numo/narray/math.c +1 -1
  22. data/ext/numo/narray/narray.c +108 -11
  23. data/ext/numo/narray/ndloop.c +3 -3
  24. data/ext/numo/narray/numo/intern.h +1 -1
  25. data/ext/numo/narray/numo/narray.h +16 -12
  26. data/ext/numo/narray/numo/ndloop.h +1 -1
  27. data/ext/numo/narray/numo/template.h +8 -10
  28. data/ext/numo/narray/numo/types/complex.h +1 -1
  29. data/ext/numo/narray/numo/types/complex_macro.h +1 -1
  30. data/ext/numo/narray/numo/types/float_macro.h +1 -1
  31. data/ext/numo/narray/numo/types/int16.h +5 -2
  32. data/ext/numo/narray/numo/types/int32.h +0 -1
  33. data/ext/numo/narray/numo/types/int64.h +0 -1
  34. data/ext/numo/narray/numo/types/int8.h +1 -2
  35. data/ext/numo/narray/numo/types/uint16.h +5 -2
  36. data/ext/numo/narray/numo/types/uint32.h +0 -1
  37. data/ext/numo/narray/numo/types/uint64.h +0 -1
  38. data/ext/numo/narray/numo/types/uint8.h +1 -2
  39. data/ext/numo/narray/numo/types/xint_macro.h +2 -0
  40. data/ext/numo/narray/step.c +1 -1
  41. data/ext/numo/narray/struct.c +2 -2
  42. data/lib/numo/narray.rb +1 -7
  43. data/lib/numo/narray/extra.rb +42 -1
  44. data/numo-narray.gemspec +3 -8
  45. metadata +14 -34
@@ -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
@@ -36,19 +36,17 @@
36
36
 
37
37
  #define INIT_PTR_BIT( lp, i, ad, ps, st ) \
38
38
  { \
39
- ps = ((lp)->args[i].iter[0]).pos; \
40
- ad = (BIT_DIGIT*)(((lp)->args[i]).ptr) + ps/NB; \
41
- ps %= NB; \
42
- st = ((lp)->args[i].iter[0]).step; \
39
+ ps = ((lp)->args[i].iter[0]).pos; \
40
+ ad = (BIT_DIGIT*)(((lp)->args[i]).ptr); \
41
+ st = ((lp)->args[i].iter[0]).step; \
43
42
  }
44
43
 
45
44
  #define INIT_PTR_BIT_IDX( lp, i, ad, ps, st, id ) \
46
45
  { \
47
- ps = ((lp)->args[i].iter[0]).pos; \
48
- ad = (BIT_DIGIT*)(((lp)->args[i]).ptr) + ps/NB; \
49
- ps %= NB; \
50
- st = ((lp)->args[i].iter[0]).step; \
51
- id = ((lp)->args[i].iter[0]).idx; \
46
+ ps = ((lp)->args[i].iter[0]).pos; \
47
+ ad = (BIT_DIGIT*)(((lp)->args[i]).ptr); \
48
+ st = ((lp)->args[i].iter[0]).step; \
49
+ id = ((lp)->args[i].iter[0]).idx; \
52
50
  }
53
51
 
54
52
  #define GET_DATA( ptr, type, val ) \
@@ -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
 
@@ -117,7 +117,7 @@ static inline dtype c_from_dcomplex(dcomplex x) {
117
117
  #define m_acosh(x) c_acosh(x)
118
118
  #define m_atanh(x) c_atanh(x)
119
119
  #define m_hypot(x,y) c_hypot(x,y)
120
- #define m_sinc(x) c_div(c_sin(x),x)
120
+ #define m_sinc(x) ((REAL(x)==0 && IMAG(x)==0) ? (c_new(1,0)):(c_div(c_sin(x),x)))
121
121
 
122
122
  #define m_sum_init INT2FIX(0)
123
123
  #define m_mulsum_init INT2FIX(0)
@@ -110,7 +110,7 @@ extern double pow(double, double);
110
110
  #define m_atanh(x) atanh(x)
111
111
  #define m_atan2(x,y) atan2(x,y)
112
112
  #define m_hypot(x,y) hypot(x,y)
113
- #define m_sinc(x) (sin(x)/(x))
113
+ #define m_sinc(x) (((x)==0) ? 1.0:(sin(x)/(x)))
114
114
 
115
115
  #define m_erf(x) erf(x)
116
116
  #define m_erfc(x) erfc(x)
@@ -4,8 +4,11 @@ typedef int16_t rtype;
4
4
  #define cRT cT
5
5
 
6
6
  #define m_num_to_data(x) ((dtype)NUM2INT(x))
7
- #define m_data_to_num(x) INT2NUM((int)(x))
8
- #define m_extract(x) INT2NUM((int)*(dtype*)(x))
7
+ #if SIZEOF_INT > 2
8
+ #define m_data_to_num(x) INT2FIX(x)
9
+ #else
10
+ #define m_data_to_num(x) INT2NUM(x)
11
+ #endif
9
12
  #define m_sprintf(s,x) sprintf(s,"%d",(int)(x))
10
13
 
11
14
  #ifndef INT16_MIN
@@ -5,7 +5,6 @@ typedef int32_t rtype;
5
5
 
6
6
  #define m_num_to_data(x) ((dtype)NUM2INT32(x))
7
7
  #define m_data_to_num(x) INT322NUM((int32_t)(x))
8
- #define m_extract(x) INT322NUM((int32_t)*(dtype*)(x))
9
8
  #define m_sprintf(s,x) sprintf(s,"%"PRId32,(int32_t)(x))
10
9
 
11
10
  #ifndef INT32_MIN
@@ -5,7 +5,6 @@ typedef int64_t rtype;
5
5
 
6
6
  #define m_num_to_data(x) ((dtype)NUM2INT64(x))
7
7
  #define m_data_to_num(x) INT642NUM((int64_t)(x))
8
- #define m_extract(x) INT642NUM((int64_t)*(dtype*)(x))
9
8
  #define m_sprintf(s,x) sprintf(s,"%"PRId64,(int64_t)(x))
10
9
 
11
10
  #ifndef INT64_MIN
@@ -4,8 +4,7 @@ typedef int8_t rtype;
4
4
  #define cRT cT
5
5
 
6
6
  #define m_num_to_data(x) ((dtype)NUM2INT(x))
7
- #define m_data_to_num(x) INT2NUM((int)(x))
8
- #define m_extract(x) INT2NUM((int)*(dtype*)(x))
7
+ #define m_data_to_num(x) INT2FIX(x)
9
8
  #define m_sprintf(s,x) sprintf(s,"%d",(int)(x))
10
9
 
11
10
  #ifndef INT8_MIN
@@ -4,8 +4,11 @@ typedef u_int16_t rtype;
4
4
  #define cRT cT
5
5
 
6
6
  #define m_num_to_data(x) ((dtype)NUM2UINT(x))
7
- #define m_data_to_num(x) UINT2NUM((unsigned int)(x))
8
- #define m_extract(x) UINT2NUM((unsigned int)*(dtype*)(x))
7
+ #if SIZEOF_INT > 2
8
+ #define m_data_to_num(x) INT2FIX(x)
9
+ #else
10
+ #define m_data_to_num(x) UINT2NUM(x)
11
+ #endif
9
12
  #define m_sprintf(s,x) sprintf(s,"%u",(unsigned int)(x))
10
13
 
11
14
  #ifndef UINT16_MAX
@@ -5,7 +5,6 @@ typedef u_int32_t rtype;
5
5
 
6
6
  #define m_num_to_data(x) ((dtype)NUM2UINT32(x))
7
7
  #define m_data_to_num(x) UINT322NUM((u_int32_t)(x))
8
- #define m_extract(x) UINT322NUM((u_int32_t)*(dtype*)(x))
9
8
  #define m_sprintf(s,x) sprintf(s,"%"PRIu32,(u_int32_t)(x))
10
9
 
11
10
  #ifndef UINT32_MAX
@@ -5,7 +5,6 @@ typedef u_int64_t rtype;
5
5
 
6
6
  #define m_num_to_data(x) ((dtype)NUM2UINT64(x))
7
7
  #define m_data_to_num(x) UINT642NUM((u_int64_t)(x))
8
- #define m_extract(x) UINT642NUM((u_int64_t)*(dtype*)(x))
9
8
  #define m_sprintf(s,x) sprintf(s,"%"PRIu64,(u_int64_t)(x))
10
9
 
11
10
  #ifndef UINT64_MAX
@@ -4,8 +4,7 @@ typedef u_int8_t rtype;
4
4
  #define cRT cT
5
5
 
6
6
  #define m_num_to_data(x) ((dtype)NUM2UINT(x))
7
- #define m_data_to_num(x) UINT2NUM((unsigned int)(x))
8
- #define m_extract(x) UINT2NUM((unsigned int)*(dtype*)(x))
7
+ #define m_data_to_num(x) INT2FIX(x)
9
8
  #define m_sprintf(s,x) sprintf(s,"%u",(unsigned int)(x))
10
9
 
11
10
  #ifndef UINT8_MAX
@@ -1,6 +1,8 @@
1
1
  #define m_zero 0
2
2
  #define m_one 1
3
3
 
4
+ #define m_extract(x) m_data_to_num(*(dtype*)(x))
5
+
4
6
  #define m_from_double(x) (x)
5
7
  #define m_from_real(x) (x)
6
8
  #define m_from_sint(x) (x)
@@ -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"
@@ -813,7 +813,7 @@ nst_s_add_type(int argc, VALUE *argv, VALUE mod)
813
813
 
814
814
  #define NST_TYPEDEF(tpname,tpclass) \
815
815
  static VALUE \
816
- nst_s_##tpname(VALUE argc, VALUE *argv, VALUE mod) \
816
+ nst_s_##tpname(int argc, VALUE *argv, VALUE mod) \
817
817
  { nstruct_add_type(tpclass,argc,argv,mod); \
818
818
  return Qnil; \
819
819
  }
data/lib/numo/narray.rb CHANGED
@@ -1,8 +1,2 @@
1
- begin
2
- major, minor, _ = RUBY_VERSION.split(/\./)
3
- require "#{major}.#{minor}/numo/narray.so"
4
- rescue LoadError
5
- require "numo/narray.so"
6
- end
7
-
1
+ require "numo/narray.so"
8
2
  require "numo/narray/extra"
@@ -106,7 +106,19 @@ module Numo
106
106
 
107
107
  # Convert the argument to an narray if not an narray.
108
108
  def self.cast(a)
109
- a.kind_of?(NArray) ? a : NArray.array_type(a).cast(a)
109
+ case a
110
+ when NArray
111
+ a
112
+ when Array,Numeric
113
+ NArray.array_type(a).cast(a)
114
+ else
115
+ if a.respond_to?(:to_a)
116
+ a = a.to_a
117
+ NArray.array_type(a).cast(a)
118
+ else
119
+ raise TypeError,"invalid type for NArray"
120
+ end
121
+ end
110
122
  end
111
123
 
112
124
  def self.asarray(a)
@@ -1171,6 +1183,35 @@ module Numo
1171
1183
  end
1172
1184
  end
1173
1185
 
1186
+ # Percentile
1187
+ #
1188
+ # @param q [Numo::NArray]
1189
+ # @param axis [Integer] applied axis
1190
+ # @return [Numo::NArray] return percentile
1191
+ def percentile(q, axis: nil)
1192
+ raise ArgumentError, "q is out of range" if q < 0 || q > 100
1193
+
1194
+ x = self
1195
+ unless axis
1196
+ axis = 0
1197
+ x = x.flatten
1198
+ end
1199
+
1200
+ sorted = x.sort(axis: axis)
1201
+ x = q / 100.0 * (sorted.shape[axis] - 1)
1202
+ r = x % 1
1203
+ i = x.floor
1204
+ refs = [true] * sorted.ndim
1205
+ refs[axis] = i
1206
+ if i == sorted.shape[axis] - 1
1207
+ sorted[*refs]
1208
+ else
1209
+ refs_upper = refs.dup
1210
+ refs_upper[axis] = i + 1
1211
+ sorted[*refs] + r * (sorted[*refs_upper] - sorted[*refs])
1212
+ end
1213
+ end
1214
+
1174
1215
  # Kronecker product of two arrays.
1175
1216
  #
1176
1217
  # 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.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,12 +33,7 @@ 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"
37
+ spec.add_development_dependency "rake-compiler", "~> 1.1"
41
38
  spec.add_development_dependency "test-unit", "~> 3.0"
42
- spec.add_development_dependency 'rake-compiler', "~> 1.0", ">= 1.0.1"
43
- spec.add_development_dependency "rake-compiler-dock", "~> 0.0"
44
39
  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.5
4
+ version: 0.9.2.0
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-10-08 00:00:00.000000000 Z
11
+ date: 2021-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,64 +28,44 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '10.0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '10.0'
41
- - !ruby/object:Gem::Dependency
42
- name: test-unit
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
31
+ - - ">="
46
32
  - !ruby/object:Gem::Version
47
- version: '3.0'
33
+ version: 12.3.3
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - "~>"
38
+ - - ">="
53
39
  - !ruby/object:Gem::Version
54
- version: '3.0'
40
+ version: 12.3.3
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rake-compiler
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
45
  - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: '1.0'
62
- - - ">="
63
- - !ruby/object:Gem::Version
64
- version: 1.0.1
47
+ version: '1.1'
65
48
  type: :development
66
49
  prerelease: false
67
50
  version_requirements: !ruby/object:Gem::Requirement
68
51
  requirements:
69
52
  - - "~>"
70
53
  - !ruby/object:Gem::Version
71
- version: '1.0'
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- version: 1.0.1
54
+ version: '1.1'
75
55
  - !ruby/object:Gem::Dependency
76
- name: rake-compiler-dock
56
+ name: test-unit
77
57
  requirement: !ruby/object:Gem::Requirement
78
58
  requirements:
79
59
  - - "~>"
80
60
  - !ruby/object:Gem::Version
81
- version: '0.0'
61
+ version: '3.0'
82
62
  type: :development
83
63
  prerelease: false
84
64
  version_requirements: !ruby/object:Gem::Requirement
85
65
  requirements:
86
66
  - - "~>"
87
67
  - !ruby/object:Gem::Version
88
- version: '0.0'
68
+ version: '3.0'
89
69
  description: Numo::NArray - New NArray class library in Ruby/Numo.
90
70
  email:
91
71
  - masa16.tanaka@gmail.com
@@ -256,16 +236,16 @@ require_paths:
256
236
  - lib
257
237
  required_ruby_version: !ruby/object:Gem::Requirement
258
238
  requirements:
259
- - - "~>"
239
+ - - ">="
260
240
  - !ruby/object:Gem::Version
261
- version: '2.1'
241
+ version: '2.2'
262
242
  required_rubygems_version: !ruby/object:Gem::Requirement
263
243
  requirements:
264
244
  - - ">="
265
245
  - !ruby/object:Gem::Version
266
246
  version: '0'
267
247
  requirements: []
268
- rubygems_version: 3.0.3
248
+ rubygems_version: 3.2.3
269
249
  signing_key:
270
250
  specification_version: 4
271
251
  summary: alpha release of Numo::NArray - New NArray class library in Ruby/Numo (NUmerical