numo-narray 0.9.1.0 → 0.9.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f25d67eb3b5fbf2fbfb211acc0b839a58500954c64224a7fb605f0516e506297
4
- data.tar.gz: f7a1c70751bcbb89db48a7be3bfb9b519494445bb39e4e8a9b37af57441578eb
3
+ metadata.gz: 2e9851b8d675467f0aa278a6600a631ba1d5a86e5a478ff5f51a6835ba1777d4
4
+ data.tar.gz: c0966fbbe3878466b39cee78282b7c5476f40529db98d86a57ccd0814fbe14fb
5
5
  SHA512:
6
- metadata.gz: 202b2db2d9e89bf17933b8d972c418a6c82bc15df08ff7bb81804575efd1e4ba7fc307b1df73f30dd4ea7ff404699a04646860c2bb09630cb1f8c4729c944f86
7
- data.tar.gz: c512052952cbb874207d22dbd0bcc9eb59b59b5137283dcd322b5dcb33fbc9c8c8f518aa3f768288ea80d0799285b546dc488446179cebbb8a61ee3f04c99584
6
+ metadata.gz: e04617bfa3066a4b021636582bbd7476f0c68ff3b262904679e1922b830d9ea8e3e90873c9a47d05052575afd4828c41f66d9d093ba812ca7891a24e1812f47a
7
+ data.tar.gz: 0662567f04b57c0e62a30d36841a17441c92aec4e36cff5a9027561a255263ac73125efb96eb97e18f4f90bc3ce452f24e303c9492f878bffdf89652f0e4748e
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # Numo::NArray - New NArray class library for Ruby/Numo (NUmerical MOdule)
2
2
 
3
- [![Binder](http://mybinder.org/badge.svg)](http://mybinder.org/repo/ruby-numo/narray)
4
- [![Build Status](https://travis-ci.org/ruby-numo/narray.svg?branch=master)](https://travis-ci.org/ruby-numo/narray)
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)
5
5
 
6
- [GitHub](https://github.com/ruby-numo/narray)
6
+ [GitHub](https://github.com/ruby-numo/numo-narray)
7
7
  | [RubyGems](https://rubygems.org/gems/numo-narray)
8
8
 
9
9
  Numo::NArray is an Numerical N-dimensional Array class
@@ -17,15 +17,16 @@ under development
17
17
  All documents are primitive.
18
18
 
19
19
  * [Numo::NArray API Doc](http://ruby-numo.github.io/narray/narray/frames.html)
20
- * [Numo::NArray vs numpy](https://github.com/ruby-numo/narray/wiki/Numo-vs-numpy)
21
- * [Numo::NArray vs ndarray](https://github.com/ruby-numo/narray/wiki/Numo-vs-ndarray)
22
- * [Numo::NArray Overview](https://github.com/ruby-numo/narray/wiki/Numo::NArray%E6%A6%82%E8%A6%81) (in Japanese)
20
+ * [Numo::NArray vs numpy](https://github.com/ruby-numo/numo-narray/wiki/Numo-vs-numpy)
21
+ * [Numo::NArray vs ndarray](https://github.com/ruby-numo/numo-narray/wiki/Numo-vs-ndarray)
22
+ * [Numo::NArray Overview](https://github.com/ruby-numo/numo-narray/wiki/Numo::NArray%E6%A6%82%E8%A6%81) (in Japanese)
23
23
 
24
24
  ## Related Projects
25
- * [Numo::Linalg](https://github.com/ruby-numo/linalg) - Linear Algebra library with [LAPACK](http://www.netlib.org/lapack/).
26
- * [Numo::GSL](https://github.com/ruby-numo/gsl) - Ruby interface for [GSL (GNU Scientific Library)](http://www.gnu.org/software/gsl/).
27
- * [Numo::FFTE](https://github.com/ruby-numo/ffte) - Ruby interface for [FFTE (A Fast Fourier Transform library with radix-2,3,5)](http://www.ffte.jp/).
28
- * [Numo::Gnuplot](https://github.com/ruby-numo/gnuplot) - Simple and easy-to-use Gnuplot interface.
25
+ * [Numo::Linalg](https://github.com/ruby-numo/numo-linalg) - Linear Algebra library with [LAPACK](http://www.netlib.org/lapack/).
26
+ * [Numo::GSL](https://github.com/ruby-numo/numo-gsl) - Ruby interface for [GSL (GNU Scientific Library)](http://www.gnu.org/software/gsl/).
27
+ * [Numo::FFTW](https://github.com/ruby-numo/numo-fftw) - Ruby/Numo interface to [FFTW (A Discrete Fourier Transform library](http://www.fftw.org/).
28
+ * [Numo::FFTE](https://github.com/ruby-numo/numo-ffte) - Ruby interface for [FFTE (A Fast Fourier Transform library with radix-2,3,5)](http://www.ffte.jp/).
29
+ * [Numo::Gnuplot](https://github.com/ruby-numo/numo-gnuplot) - Simple and easy-to-use Gnuplot interface.
29
30
 
30
31
  ## Installation
31
32
  ### Requirement
@@ -35,7 +36,7 @@ Ruby ver 2.1 and later.
35
36
  ```shell
36
37
  apt install -y git ruby gcc ruby-dev rake make
37
38
  gem install specific_install
38
- gem specific_install https://github.com/ruby-numo/narray.git
39
+ gem specific_install https://github.com/ruby-numo/numo-narray.git
39
40
  ```
40
41
 
41
42
  ## Quick start
@@ -57,4 +58,25 @@ An example
57
58
  [6] pry(main)> a.size
58
59
  => 15
59
60
  ```
60
- For more examples, check out this [narray version of 100 numpy exercises](https://github.com/ruby-numo/narray/wiki/100-narray-exercises) (and the [IRuby Notebook](https://github.com/ruby-numo/narray/blob/master/100-narray-exercises.ipynb)).
61
+ For more examples, check out this [narray version of 100 numpy exercises](https://github.com/ruby-numo/numo-narray/wiki/100-narray-exercises) (and the [IRuby Notebook](https://github.com/ruby-numo/numo-narray/blob/master/100-narray-exercises.ipynb)).
62
+
63
+ ## Development
64
+
65
+ ### Build
66
+
67
+ ```shell
68
+ ruby setup.rb
69
+ ```
70
+
71
+ ### Run tests
72
+
73
+ ```shell
74
+ bundle install
75
+ bundle exec rake test
76
+ ```
77
+
78
+ Tips: You may run tests defined in a specified line as:
79
+
80
+ ```shell
81
+ bundle exec ruby test/bit_test.rb --location 27
82
+ ```
data/Rakefile CHANGED
@@ -62,5 +62,13 @@ namespace :release do
62
62
  end
63
63
  end
64
64
 
65
+ require 'rake/testtask'
66
+ Rake::TestTask.new(:test) do |t|
67
+ t.libs << "test"
68
+ t.libs << "lib"
69
+ t.verbose = true
70
+ t.test_files = FileList['test/**/*_test.rb']
71
+ end
72
+
65
73
  rescue LoadError
66
74
  end
@@ -435,7 +435,8 @@ na_composition3(VALUE obj, VALUE *ptype, VALUE *pshape, VALUE *pnary)
435
435
  *pnary = nary_new(dtype, ndim, na->shape);
436
436
  }
437
437
  } else {
438
- rb_bug("invalid type for md-array: %s", rb_class2name(CLASS_OF(obj)));
438
+ rb_raise(rb_eTypeError,"invalid type for NArray: %s",
439
+ rb_class2name(CLASS_OF(obj)));
439
440
  }
440
441
  }
441
442
 
@@ -4,11 +4,13 @@ thisdir = File.dirname(__FILE__)
4
4
  libpath = File.absolute_path(File.dirname(__FILE__))+"/../../../../lib"
5
5
  $LOAD_PATH.unshift libpath
6
6
 
7
- require_relative "./narray_def"
7
+ require_relative "narray_def"
8
+
9
+ $line_number = false
8
10
 
9
11
  while true
10
12
  if ARGV[0] == "-l"
11
- require "erbpp/line_number"
13
+ $line_number = true
12
14
  ARGV.shift
13
15
  elsif ARGV[0] == "-o"
14
16
  ARGV.shift
@@ -33,6 +35,7 @@ erb_dir.unshift("tmpl_bit") if (type_name == "bit")
33
35
  erb_dir.map!{|d| File.join(thisdir,d)}
34
36
 
35
37
  code = DefLib.new do
38
+ set line_number: $line_number
36
39
  set erb_dir: erb_dir
37
40
  set erb_suffix: ".c"
38
41
  set ns_var: "mNumo"
@@ -0,0 +1,132 @@
1
+ require 'erb'
2
+
3
+ class ErbPP
4
+
5
+ class CountLnString < String
6
+
7
+ def initialize(filename)
8
+ @filename = filename
9
+ @lnchar = "\n"
10
+ @buf = ""
11
+ @str = ""
12
+ @countln = 1
13
+ @current = 1
14
+ super("\n"+report_line)
15
+ end
16
+
17
+ def report_line
18
+ "#line #{@current} \"#{@filename}\"\n"
19
+ end
20
+
21
+ def concat0(s)
22
+ ln(caller[0])
23
+ @buf.concat(s)
24
+ @str.concat(s)
25
+ end
26
+
27
+ def concat1(s)
28
+ ln(caller[0])
29
+ @buf.concat(s)
30
+ end
31
+
32
+ def ln(status=nil)
33
+ case status
34
+ when /:(\d+):/
35
+ n = $1.to_i
36
+ else
37
+ n = status.to_i
38
+ end
39
+ return if n == @current
40
+ if @current != @countln || @postpone
41
+ if /\A\s*\z/ =~ @str || /\A#line / =~ @buf
42
+ @postpone = true
43
+ elsif @in_comment
44
+ @postpone = false
45
+ else
46
+ if self[-1] != "\n"
47
+ concat("\n")
48
+ end
49
+ concat(report_line)
50
+ @postpone = false
51
+ end
52
+ end
53
+ concat(@buf)
54
+
55
+ b = @buf.gsub(/".*?(?<!\\)"/,'""')
56
+ /^.*(\/\*)(.*?)$/ =~ b
57
+ x = $2
58
+ /^.*(\*\/)(.*?)$/ =~ b
59
+ y = $2
60
+ if x
61
+ if y
62
+ if x.size < y.size
63
+ #:in_comment
64
+ @in_comment = true
65
+ else
66
+ #:out_comment
67
+ @in_comment = false
68
+ end
69
+ else
70
+ #:in_comment
71
+ @in_comment = true
72
+ end
73
+ else
74
+ if y
75
+ #:out_comment
76
+ @in_comment = false
77
+ else
78
+ #:keep
79
+ end
80
+ end
81
+
82
+ @countln = @current + @buf.count(@lnchar)
83
+ @current = n
84
+ @buf = ""
85
+ @str = ""
86
+ end
87
+
88
+ def d(s)
89
+ p [s, [x,y], r]
90
+ r
91
+ end
92
+
93
+ def final
94
+ ln(caller[0])
95
+ concat(@buf)
96
+ end
97
+
98
+ end
99
+
100
+ class ERBLN
101
+
102
+ def initialize(str, filename, trim_mode=nil, eoutvar='_erbout')
103
+ @filename = filename
104
+ compiler = ERB::Compiler.new(trim_mode)
105
+ set_eoutvar(compiler, eoutvar)
106
+ @src, @enc = *compiler.compile(str)
107
+ end
108
+
109
+ def set_eoutvar(compiler, eoutvar = '_erbout')
110
+ compiler.put_cmd = "#{eoutvar}.concat0"
111
+ compiler.insert_cmd = "#{eoutvar}.concat1"
112
+ compiler.pre_cmd = ["#{eoutvar} = CountLnString.new(#{@filename.inspect})"]
113
+ compiler.post_cmd = ["#{eoutvar}.final"]
114
+ end
115
+
116
+ def run(b)
117
+ print self.result(b)
118
+ end
119
+
120
+ def result(b)
121
+ #open("tmpout","a") do |f|
122
+ # f.puts "\n#file:#{@filename}"
123
+ # f.puts @src
124
+ #end
125
+ eval(@src, b, (@filename || '(erb)'), 0)
126
+ end
127
+
128
+ #require "fileutils"
129
+ #FileUtils.rm_f("tmpout")
130
+ end
131
+
132
+ end
@@ -1,4 +1,5 @@
1
1
  require "erb"
2
+ require_relative "erbln"
2
3
 
3
4
  class ErbPP
4
5
 
@@ -66,8 +67,12 @@ class ErbPP
66
67
  Dir.glob(x).each do |dir|
67
68
  path = File.join(dir,file)
68
69
  if File.exist?(path)
69
- erb = ERB.new(File.read(path), safe_level, trim_mode)
70
- erb.filename = path
70
+ if get(:line_number)
71
+ erb = ERBLN.new(File.read(path), path, trim_mode)
72
+ else
73
+ erb = ERB.new(File.read(path), safe_level, trim_mode)
74
+ erb.filename = path
75
+ end
71
76
  return erb
72
77
  end
73
78
  end
@@ -304,6 +309,20 @@ class DefConst < ErbPP
304
309
  end
305
310
  end
306
311
 
312
+ class DefError < ErbPP
313
+ def initialize(parent, name, sup_var, **opts, &block)
314
+ super(parent, error_name:name, error_var:"e"+name, super_var:sup_var,
315
+ **opts, &block)
316
+ end
317
+ def result
318
+ "static VALUE #{error_var};"
319
+ end
320
+ def init_def
321
+ "/*#{description}*/
322
+ #{error_var} = rb_define_class_under(#{ns_var},\"#{error_name}\",#{super_var});"
323
+ end
324
+ end
325
+
307
326
  class DefStruct < ErbPP
308
327
  def method_code
309
328
  "static VALUE #{class_var};"
@@ -1,4 +1,4 @@
1
- require_relative './erbpp2'
1
+ require_relative 'erbpp2'
2
2
 
3
3
  module NArrayMethod
4
4
 
@@ -23,6 +23,9 @@ if is_comparable && !is_object
23
23
  def_id "lt"
24
24
  def_id "le"
25
25
  end
26
+ if is_comparable
27
+ def_id "nan"
28
+ end
26
29
  if is_object
27
30
  def_id "bit_and"
28
31
  def_id "bit_or"
@@ -290,6 +293,8 @@ if is_comparable
290
293
  accum_index "max_index"
291
294
  accum_index "min_index"
292
295
  def_method "minmax"
296
+ def_module_function "maximum", "ewcomp", n_arg:2
297
+ def_module_function "minimum", "ewcomp", n_arg:2
293
298
  end
294
299
 
295
300
  if is_int && !is_object
@@ -23,8 +23,9 @@ void
23
23
  int nd, md;
24
24
 
25
25
  c = (size_t*)(lp->opt_ptr);
26
- nd = lp->ndim - 1;
27
- md = lp->ndim + 1;
26
+ nd = lp->ndim;
27
+ if (nd > 0) {nd--;}
28
+ md = nd + 2;
28
29
  a = ALLOCA_N(VALUE,md);
29
30
 
30
31
  INIT_COUNTER(lp, i);
@@ -0,0 +1,64 @@
1
+ /*
2
+ Element-wise <%=name%> of two arrays.
3
+
4
+ <% if is_float %>
5
+ @overload <%=name%>(a1, a2, nan:false)
6
+ @param [Numo::NArray,Numeric] a1 The array to be compared.
7
+ @param [Numo::NArray,Numeric] a2 The array to be compared.
8
+ @param [TrueClass] nan If true, apply NaN-aware algorithm (return NaN if exist).
9
+ <% else %>
10
+ @overload <%=name%>(a1, a2)
11
+ @param [Numo::NArray,Numeric] a1,a2 The arrays holding the elements to be compared.
12
+ <% end %>
13
+ @return [Numo::<%=class_name%>]
14
+ */
15
+
16
+ <% (is_float ? ["","_nan"] : [""]).each do |j| %>
17
+ static void
18
+ <%=c_iter%><%=j%>(na_loop_t *const lp)
19
+ {
20
+ size_t i, n;
21
+ char *p1, *p2, *p3;
22
+ ssize_t s1, s2, s3;
23
+
24
+ INIT_COUNTER(lp, n);
25
+ INIT_PTR(lp, 0, p1, s1);
26
+ INIT_PTR(lp, 1, p2, s2);
27
+ INIT_PTR(lp, 2, p3, s3);
28
+
29
+ for (i=0; i<n; i++) {
30
+ dtype x, y, z;
31
+ GET_DATA_STRIDE(p1,s1,dtype,x);
32
+ GET_DATA_STRIDE(p2,s2,dtype,y);
33
+ GET_DATA(p3,dtype,z);
34
+ z = f_<%=name%><%=j%>(x,y);
35
+ SET_DATA_STRIDE(p3,s3,dtype,z);
36
+ }
37
+ }
38
+ <% end %>
39
+
40
+ static VALUE
41
+ <%=c_func(-1)%>(int argc, VALUE *argv, VALUE mod)
42
+ {
43
+ VALUE a1 = Qnil;
44
+ VALUE a2 = Qnil;
45
+ ndfunc_arg_in_t ain[2] = {{cT,0},{cT,0}};
46
+ ndfunc_arg_out_t aout[1] = {{cT,0}};
47
+ ndfunc_t ndf = { <%=c_iter%>, STRIDE_LOOP_NIP, 2, 1, ain, aout };
48
+
49
+ <% if is_float %>
50
+ VALUE kw_hash = Qnil;
51
+ ID kw_table[1] = {id_nan};
52
+ VALUE opts[1] = {Qundef};
53
+
54
+ rb_scan_args(argc, argv, "20:", &a1, &a2, &kw_hash);
55
+ rb_get_kwargs(kw_hash, kw_table, 0, 1, opts);
56
+ if (opts[0] != Qundef) {
57
+ ndf.func = <%=c_iter%>_nan;
58
+ }
59
+ <% else %>
60
+ rb_scan_args(argc, argv, "20", &a1, &a2);
61
+ <% end %>
62
+
63
+ return na_ndloop(&ndf, 2, a1, a2);
64
+ }
@@ -25,8 +25,9 @@ void
25
25
  int nd, md;
26
26
 
27
27
  c = (size_t*)(lp->opt_ptr);
28
- nd = lp->ndim - 1;
29
- md = lp->ndim + 1;
28
+ nd = lp->ndim;
29
+ if (nd > 0) {nd--;}
30
+ md = nd + 2;
30
31
  a = ALLOCA_N(VALUE,md);
31
32
 
32
33
  INIT_COUNTER(lp, i);
@@ -1284,10 +1284,10 @@ ndloop_run(VALUE vlp)
1284
1284
  if (lp->loop_func == loop_narray) {
1285
1285
  loop_spec = ndloop_func_loop_spec(nf, lp->user.ndim);
1286
1286
  ndfunc_set_bufcp(lp, loop_spec);
1287
- if (na_debug_flag) {
1288
- printf("-- ndfunc_set_bufcp --\n");
1289
- print_ndloop(lp);
1290
- }
1287
+ }
1288
+ if (na_debug_flag) {
1289
+ printf("-- ndfunc_set_bufcp --\n");
1290
+ print_ndloop(lp);
1291
1291
  }
1292
1292
 
1293
1293
  // loop
@@ -1879,17 +1879,11 @@ loop_narray_with_index(ndfunc_t *nf, na_md_loop_t *lp)
1879
1879
  int i,j;
1880
1880
  int nd = lp->ndim;
1881
1881
 
1882
- // for zero-dimensional narray
1883
- if (nd==0) {
1884
- switch (lp->n[0]) {
1885
- case 0:
1886
- return;
1887
- case 1:
1888
- nd = 1;
1889
- break;
1890
- default:
1891
- rb_fatal("invalid narray");
1892
- }
1882
+ if (nd < 0) {
1883
+ rb_bug("bug? lp->ndim = %d\n", lp->ndim);
1884
+ }
1885
+ if (lp->n[0] == 0) { // empty array
1886
+ return;
1893
1887
  }
1894
1888
 
1895
1889
  // pass total ndim to iterator