numo-narray 0.9.1.0 → 0.9.1.1
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 +34 -12
- data/Rakefile +8 -0
- data/ext/numo/narray/array.c +2 -1
- data/ext/numo/narray/gen/cogen.rb +5 -2
- data/ext/numo/narray/gen/erbln.rb +132 -0
- data/ext/numo/narray/gen/erbpp2.rb +21 -2
- data/ext/numo/narray/gen/narray_def.rb +1 -1
- data/ext/numo/narray/gen/spec.rb +5 -0
- data/ext/numo/narray/gen/tmpl/each_with_index.c +3 -2
- data/ext/numo/narray/gen/tmpl/ewcomp.c +64 -0
- data/ext/numo/narray/gen/tmpl/map_with_index.c +3 -2
- data/ext/numo/narray/ndloop.c +9 -15
- data/ext/numo/narray/numo/narray.h +2 -2
- data/ext/numo/narray/numo/types/real_accum.h +45 -0
- data/ext/numo/narray/numo/types/xint_macro.h +16 -0
- data/numo-narray.gemspec +2 -2
- metadata +11 -16
- data/lib/erbpp.rb +0 -294
- data/lib/erbpp/line_number.rb +0 -133
- data/lib/erbpp/narray_def.rb +0 -381
- data/spec/bit_spec.rb +0 -93
- data/spec/narray_spec.rb +0 -252
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e9851b8d675467f0aa278a6600a631ba1d5a86e5a478ff5f51a6835ba1777d4
|
4
|
+
data.tar.gz: c0966fbbe3878466b39cee78282b7c5476f40529db98d86a57ccd0814fbe14fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
[](http://mybinder.org/repo/ruby-numo/narray)
|
4
|
-
[](https://travis-ci.org/ruby-numo/narray)
|
3
|
+
[](http://mybinder.org/repo/ruby-numo/numo-narray)
|
4
|
+
[](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::
|
28
|
-
* [Numo::
|
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
data/ext/numo/narray/array.c
CHANGED
@@ -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
|
-
|
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 "
|
7
|
+
require_relative "narray_def"
|
8
|
+
|
9
|
+
$line_number = false
|
8
10
|
|
9
11
|
while true
|
10
12
|
if ARGV[0] == "-l"
|
11
|
-
|
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
|
-
|
70
|
-
|
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};"
|
data/ext/numo/narray/gen/spec.rb
CHANGED
@@ -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
|
@@ -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
|
+
}
|
data/ext/numo/narray/ndloop.c
CHANGED
@@ -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
|
-
|
1288
|
-
|
1289
|
-
|
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
|
-
|
1883
|
-
|
1884
|
-
|
1885
|
-
|
1886
|
-
|
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
|