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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2723cec3e04deedc561c54a0d4f6af799dd93fc8a32079d06a074f00f07f466c
4
- data.tar.gz: 5548cfa23b0ac7227b62ab8edd00ba040805c0563befeb32591179dc090eff66
3
+ metadata.gz: 5a1e49e2dfd16c57254defdd6ccf5548d676f5c7238341fca70f841d14931e30
4
+ data.tar.gz: c2bdd3b1131d58ab462d1259ccdbff2664040c5cacd4f5ef2fcc314046a78bd2
5
5
  SHA512:
6
- metadata.gz: 19a91712b943da6f57f2cda4fa178adcb5a0c845c2b0ce8190f46c5c1a0d83a331fd32d71e9b2b85c960222f4a01940926bacba63eb882ea1b27aebb7a09c7a3
7
- data.tar.gz: 4ee3a88369439ccf964fd23358a84530973c5355d4c71b35eda516bd655966ce127d494159c942bf0a82045b3f05a6be7ed16f4d9d30b96916df651c9a5ec0cb
6
+ metadata.gz: 6906c6bff6eac4969dc653c17bbe6cfc7eaffd3415c65e56e2f09bd6575b18f5495eedf2f4baf3062e6501a9b177b88d900aec8c49bdd060495975342b951344
7
+ data.tar.gz: ae33fa09e06cedc0032c6689e3e8da4a53991deb0c04e8019aeee30c58617af7bd356f916464eb0ece80ea8063ce575e71facc50b1e06108bb45579e5d4e8891
data/README.md CHANGED
@@ -1,7 +1,7 @@
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
- [![Build Status](https://travis-ci.org/ruby-numo/numo-narray.svg?branch=master)](https://travis-ci.org/ruby-numo/numo-narray)
4
+ [![Build Status](https://github.com/ruby-numo/numo-narray/workflows/build/badge.svg)](https://github.com/ruby-numo/numo-narray/actions)
5
5
 
6
6
  [GitHub](https://github.com/ruby-numo/numo-narray)
7
7
  | [RubyGems](https://rubygems.org/gems/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
 
@@ -71,13 +71,15 @@ For more examples, check out this [narray version of 100 numpy exercises](https:
71
71
  ### Build
72
72
 
73
73
  ```shell
74
- ruby setup.rb
74
+ git clone https://github.com/ruby-numo/numo-narray
75
+ cd numo-narray
76
+ bundle install
77
+ bundle exec rake compile
75
78
  ```
76
79
 
77
80
  ### Run tests
78
81
 
79
82
  ```shell
80
- bundle install
81
83
  bundle exec rake test
82
84
  ```
83
85
 
data/Rakefile CHANGED
@@ -1,76 +1,14 @@
1
1
  require "bundler/gem_tasks"
2
- begin
3
2
 
4
3
  task :doc do
5
4
  dir = "ext/numo/narray"
6
5
  src = %w[array.c data.c index.c math.c narray.c rand.c struct.c].
7
6
  map{|s| File.join(dir,s)} +
8
- [File.join(dir,"types/*.c"), "lib/numo/narray/extra.rb"]
7
+ [File.join(dir,"t_*.c"), "lib/numo/narray/extra.rb"]
9
8
  sh "cd ext/numo/narray; ruby extconf.rb; make src"
10
9
  sh "rm -rf yard .yardoc; yard doc -o yard -m markdown -r README.md #{src.join(' ')}"
11
10
  end
12
11
 
13
- require "rake/extensiontask"
14
- require "rake_compiler_dock"
15
- require "shellwords"
16
-
17
- spec = Bundler::GemHelper.gemspec
18
-
19
- cross_platforms = ["x86-mingw32", "x64-mingw32"]
20
- Rake::ExtensionTask.new("numo/narray", spec) do |ext|
21
- ext.cross_compile = true
22
- ext.cross_platform = cross_platforms
23
- end
24
-
25
- pkg_dir = "pkg"
26
- windows_gem_paths = cross_platforms.collect do |platform|
27
- File.join(pkg_dir, "#{spec.full_name}-#{platform}.gem")
28
- end
29
-
30
- namespace :build do
31
- directory pkg_dir
32
-
33
- desc "Build gems for Windows into the pkg directory"
34
- task :windows => pkg_dir do
35
- build_dir = "tmp/windows"
36
- rm_rf build_dir
37
- mkdir_p build_dir
38
-
39
- commands = [
40
- ["git", "clone", "file://#{Dir.pwd}/.git", build_dir],
41
- ["cd", build_dir],
42
- ["bundle"],
43
- [
44
- "rake",
45
- "RUBY_CC_VERSION=2.5.0:2.4.0:2.3.0:2.2.2:2.1.6",
46
- "cross",
47
- "native",
48
- "gem",
49
- ],
50
- ]
51
- raw_commands = commands.collect do |command|
52
- Shellwords.join(command)
53
- end
54
- raw_command_line = raw_commands.join(" && ")
55
-
56
- RakeCompilerDock.sh(raw_command_line)
57
-
58
- cp(Dir.glob("#{build_dir}/#{pkg_dir}/*.gem"),
59
- "#{pkg_dir}/")
60
- end
61
- end
62
-
63
- namespace :release do
64
- task :windows => "build:windows" do
65
- windows_gem_paths.each do |path|
66
- ruby("-S", "gem", "push", path)
67
- end
68
- end
69
- end
70
-
71
- rescue LoadError
72
- end
73
-
74
12
  require 'rake/testtask'
75
13
  Rake::TestTask.new(:test) do |t|
76
14
  t.libs << "test"
@@ -79,3 +17,6 @@ Rake::TestTask.new(:test) do |t|
79
17
  t.warning = false
80
18
  t.test_files = FileList['test/**/*_test.rb']
81
19
  end
20
+
21
+ require 'rake/extensiontask'
22
+ Rake::ExtensionTask.new('numo/narray')
@@ -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"
@@ -30,16 +30,16 @@ static ID id_step;
30
30
  static ID id_abs;
31
31
  static ID id_cast;
32
32
  static ID id_le;
33
+ #if SIZEOF_LONG <= 4
34
+ static ID id_ge;
35
+ #endif
33
36
  static ID id_Complex;
34
-
37
+ static VALUE int32_max = Qnil;
38
+ static VALUE int32_min = Qnil;
35
39
 
36
40
  static VALUE
37
41
  na_object_type(int type, VALUE v)
38
42
  {
39
- static VALUE int32_max = Qnil;
40
- if (NIL_P(int32_max))
41
- int32_max = ULONG2NUM(2147483647);
42
-
43
43
  switch(TYPE(v)) {
44
44
 
45
45
  case T_TRUE:
@@ -48,15 +48,15 @@ static VALUE
48
48
  return NA_BIT;
49
49
  return type;
50
50
 
51
- #if SIZEOF_LONG == 4
51
+ #if SIZEOF_LONG <= 4
52
52
  case T_FIXNUM:
53
53
  if (type<NA_INT32)
54
54
  return NA_INT32;
55
55
  return type;
56
56
  case T_BIGNUM:
57
57
  if (type<NA_INT64) {
58
- v = rb_funcall(v,id_abs,0);
59
- if (RTEST(rb_funcall(v,id_le,1,int32_max))) {
58
+ if (RTEST(rb_funcall(v,id_le,1,int32_max)) &&
59
+ RTEST(rb_funcall(v,id_ge,1,int32_min))) {
60
60
  if (type<NA_INT32)
61
61
  return NA_INT32;
62
62
  } else {
@@ -64,13 +64,11 @@ static VALUE
64
64
  }
65
65
  }
66
66
  return type;
67
-
68
- #elif SIZEOF_LONG == 8
67
+ #else
69
68
  case T_FIXNUM:
70
69
  if (type<NA_INT64) {
71
70
  long x = NUM2LONG(v);
72
- if (x<0) x=-x;
73
- if (x<=2147483647) {
71
+ if (x<=2147483647L && x>=-2147483648L) {
74
72
  if (type<NA_INT32)
75
73
  return NA_INT32;
76
74
  } else {
@@ -82,19 +80,6 @@ static VALUE
82
80
  if (type<NA_INT64)
83
81
  return NA_INT64;
84
82
  return type;
85
- #else
86
- case T_FIXNUM:
87
- case T_BIGNUM:
88
- if (type<NA_INT64) {
89
- v = rb_funcall(v,id_abs,0);
90
- if (RTEST(rb_funcall(v,id_le,1,int32_max))) {
91
- if (type<NA_INT32)
92
- return NA_INT32;
93
- } else {
94
- return NA_INT64;
95
- }
96
- }
97
- return type;
98
83
  #endif
99
84
 
100
85
  case T_FLOAT:
@@ -649,5 +634,13 @@ Init_nary_array()
649
634
  id_cast = rb_intern("cast");
650
635
  id_abs = rb_intern("abs");
651
636
  id_le = rb_intern("<=");
637
+ #if SIZEOF_LONG <= 4
638
+ id_ge = rb_intern(">=");
639
+ #endif
652
640
  id_Complex = rb_intern("Complex");
641
+
642
+ rb_global_variable(&int32_max);
643
+ int32_max = INT2NUM(2147483647);
644
+ rb_global_variable(&int32_min);
645
+ int32_min = INT2NUM(-2147483648);
653
646
  }
@@ -1,16 +1,14 @@
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>
8
8
  #include "numo/narray.h"
9
9
  #include "numo/template.h"
10
10
 
11
- static VALUE sym_mulsum;
12
11
  static ID id_mulsum;
13
- static ID id_respond_to_p;
14
12
  static ID id_store;
15
13
  static ID id_swap_byte;
16
14
 
@@ -921,12 +919,10 @@ na_new_dimension_for_dot(VALUE self, int pos, int len, bool transpose)
921
919
  static VALUE
922
920
  numo_na_dot(VALUE self, VALUE other)
923
921
  {
924
- VALUE test;
925
922
  volatile VALUE a1=self, a2=other;
926
923
  narray_t *na1, *na2;
927
924
 
928
- test = rb_funcall(a1, id_respond_to_p, 1, sym_mulsum);
929
- if (!RTEST(test)) {
925
+ if (!rb_respond_to(a1, id_mulsum)) {
930
926
  rb_raise(rb_eNoMethodError,"requires mulsum method for dot method");
931
927
  }
932
928
  GetNArray(a1,na1);
@@ -983,8 +979,6 @@ Init_nary_data()
983
979
  //rb_define_method(cNArray, "dot", numo_na_dot, 1);
984
980
 
985
981
  id_mulsum = rb_intern("mulsum");
986
- sym_mulsum = ID2SYM(id_mulsum);
987
- id_respond_to_p = rb_intern("respond_to?");
988
982
  id_store = rb_intern("store");
989
983
  id_swap_byte = rb_intern("swap_byte");
990
984
  }
@@ -1,17 +1,13 @@
1
1
  TAGSRC = \
2
- ../../ruby/include/ruby/*.h \
3
- ../../ruby/*.c \
4
- *.h \
5
- types/*.h \
6
- *.c \
7
- types/*.c
2
+ numo/types/*.h \
3
+ *.c
8
4
 
9
5
  tags : TAGS
10
6
  TAGS : $(TAGSRC)
11
7
  etags $(TAGSRC)
12
8
 
13
9
  doc :
14
- yard doc *.c types/*.c
10
+ yard doc *.c
15
11
 
16
12
  C_TMPL = <%=Dir.glob("#{__dir__}/gen/tmpl*/*.c").join(" ")%>
17
13
 
@@ -22,13 +18,13 @@ DEPENDS = $(C_TMPL) <%= __dir__ %>/gen/*.rb
22
18
  type_c = []
23
19
  type_rb = Dir.glob("#{__dir__}/gen/def/*.rb")
24
20
  type_rb.each do |s|
25
- type_c << c = "types/"+File.basename(s,".rb")+".c"
21
+ type_c << c = "t_"+File.basename(s,".rb")+".c"
26
22
  %>
27
23
  <%=c%>: <%=s%> $(DEPENDS)
28
- $(MAKEDIRS) $(@D) types
29
24
  ruby $(COGEN) -l -o $@ <%=s%>
30
25
  <% end %>
31
26
 
32
27
  src : <%= type_c.join(" ") %>
33
28
 
34
- CLEANOBJS = *.o */*.o *.bak types/*.c
29
+ CLEANOBJS = *.o t_*.c *.bak
30
+ DISTCLEANFILES = depend TAGS
@@ -7,7 +7,11 @@ if RUBY_VERSION < "2.1.0"
7
7
  exit(1)
8
8
  end
9
9
 
10
- rm_f 'numo/extconf.h'
10
+ def d(file)
11
+ File.join(__dir__,file)
12
+ end
13
+
14
+ rm_f d('numo/extconf.h')
11
15
 
12
16
  #$CFLAGS="-g3 -O0 -Wall"
13
17
  #$CFLAGS=" $(cflags) -O3 -m64 -msse2 -funroll-loops"
@@ -28,20 +32,20 @@ step
28
32
  index
29
33
  ndloop
30
34
  data
31
- types/bit
32
- types/int8
33
- types/int16
34
- types/int32
35
- types/int64
36
- types/uint8
37
- types/uint16
38
- types/uint32
39
- types/uint64
40
- types/sfloat
41
- types/dfloat
42
- types/scomplex
43
- types/dcomplex
44
- types/robject
35
+ t_bit
36
+ t_int8
37
+ t_int16
38
+ t_int32
39
+ t_int64
40
+ t_uint8
41
+ t_uint16
42
+ t_uint32
43
+ t_uint64
44
+ t_sfloat
45
+ t_dfloat
46
+ t_scomplex
47
+ t_dcomplex
48
+ t_robject
45
49
  math
46
50
  SFMT
47
51
  struct
@@ -89,14 +93,12 @@ have_var("rb_cComplex")
89
93
 
90
94
  $objs = srcs.collect{|i| i+".o"}
91
95
 
92
- create_header('numo/extconf.h')
96
+ create_header d('numo/extconf.h')
93
97
 
94
- depend_path = File.join(__dir__, "depend")
95
- File.open(depend_path, "w") do |depend|
96
- depend_erb_path = File.join(__dir__, "depend.erb")
97
- File.open(depend_erb_path, "r") do |depend_erb|
98
+ File.open(d('depend'), "w") do |depend|
99
+ File.open(d('depend.erb'), "r") do |depend_erb|
98
100
  erb = ERB.new(depend_erb.read)
99
- erb.filename = depend_erb_path
101
+ erb.filename = d('depend.erb')
100
102
  depend.print(erb.result)
101
103
  end
102
104
  end
@@ -50,7 +50,7 @@ code = DefLib.new do
50
50
  set file_name: $output||""
51
51
  set include_files: ["numo/types/#{type_name}.h"]
52
52
  set lib_name: "numo_"+type_name
53
-
53
+
54
54
  if (::RbConfig::CONFIG['target_cpu'] == 'x86_64') or (::RbConfig::CONFIG['target_cpu'] == 'x64')
55
55
  set is_simd: true
56
56
  else
@@ -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
@@ -27,7 +27,7 @@ module NArrayMethod
27
27
 
28
28
  def set2(meth, dtype, result_class)
29
29
  h = {dtype:dtype, result_class:result_class}
30
- def_method(meth, "set2", h)
30
+ def_method(meth, "set2", **h)
31
31
  end
32
32
 
33
33
  def cond_binary(meth,op=nil)
@@ -1,8 +1,6 @@
1
1
  def_id "cast"
2
- def_id "eq"
3
- def_id "ne"
4
- def_id "pow"
5
2
  def_id "mulsum"
3
+ def_id "to_a"
6
4
  if is_complex
7
5
  def_id "real"
8
6
  def_id "imag"
@@ -32,7 +30,6 @@ if is_object
32
30
  def_id "bit_xor"
33
31
  def_id "bit_not"
34
32
  def_id "abs"
35
- def_id "minus"
36
33
  def_id "reciprocal"
37
34
  def_id "square"
38
35
  def_id "floor"
@@ -42,6 +39,7 @@ if is_object
42
39
  def_id "nan?"
43
40
  def_id "infinite?"
44
41
  def_id "finite?"
42
+ def_id "-@","minus"
45
43
  def_id "==","eq"
46
44
  def_id "!=","ne"
47
45
  def_id ">" ,"gt"
@@ -49,6 +47,9 @@ if is_object
49
47
  def_id "<" ,"lt"
50
48
  def_id "<=","le"
51
49
  def_id "<=>","ufo"
50
+ else
51
+ def_id "eq"
52
+ def_id "ne"
52
53
  end
53
54
 
54
55
  if is_int && !is_object
@@ -179,7 +180,12 @@ if !is_complex
179
180
  binary2 "divmod"
180
181
  end
181
182
 
182
- pow
183
+
184
+ if !is_bit
185
+ pow
186
+ def_id "**","pow"
187
+ def_alias "pow","**"
188
+ end
183
189
 
184
190
  unary "minus", "-@"
185
191
  unary "reciprocal"
@@ -273,7 +279,7 @@ if is_float
273
279
  cond_unary "isfinite"
274
280
  end
275
281
 
276
- if is_int
282
+ if is_int && !is_object
277
283
  if is_unsigned
278
284
  accum "sum","u_int64_t","numo_cUInt64"
279
285
  accum "prod","u_int64_t","numo_cUInt64"