numo-narray 0.9.0.4 → 0.9.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -8
- data/Rakefile +9 -0
- data/ext/numo/narray/array.c +178 -47
- data/ext/numo/narray/data.c +105 -97
- data/ext/numo/narray/depend.erb +6 -7
- data/ext/numo/narray/gen/cogen.rb +30 -7
- data/ext/numo/narray/gen/def/bit.rb +17 -14
- data/ext/numo/narray/gen/def/dcomplex.rb +19 -15
- data/ext/numo/narray/gen/def/dfloat.rb +17 -13
- data/ext/numo/narray/gen/def/int16.rb +16 -12
- data/ext/numo/narray/gen/def/int32.rb +16 -12
- data/ext/numo/narray/gen/def/int64.rb +16 -12
- data/ext/numo/narray/gen/def/int8.rb +16 -12
- data/ext/numo/narray/gen/def/robject.rb +18 -14
- data/ext/numo/narray/gen/def/scomplex.rb +19 -15
- data/ext/numo/narray/gen/def/sfloat.rb +17 -13
- data/ext/numo/narray/gen/def/uint16.rb +16 -12
- data/ext/numo/narray/gen/def/uint32.rb +16 -12
- data/ext/numo/narray/gen/def/uint64.rb +16 -12
- data/ext/numo/narray/gen/def/uint8.rb +16 -12
- data/ext/numo/narray/gen/erbpp2.rb +324 -0
- data/ext/numo/narray/gen/narray_def.rb +252 -0
- data/ext/numo/narray/gen/spec.rb +141 -71
- data/ext/numo/narray/gen/tmpl/accum.c +22 -9
- data/ext/numo/narray/gen/tmpl/accum_binary.c +29 -13
- data/ext/numo/narray/gen/tmpl/accum_index.c +38 -16
- data/ext/numo/narray/gen/tmpl/alloc_func.c +107 -0
- data/ext/numo/narray/gen/tmpl/allocate.c +1 -1
- data/ext/numo/narray/gen/tmpl/aref.c +1 -1
- data/ext/numo/narray/gen/tmpl/aset.c +4 -2
- data/ext/numo/narray/gen/tmpl/binary.c +4 -4
- data/ext/numo/narray/gen/tmpl/binary2.c +5 -5
- data/ext/numo/narray/gen/tmpl/binary_s.c +5 -5
- data/ext/numo/narray/gen/tmpl/bincount.c +4 -4
- data/ext/numo/narray/gen/tmpl/cast.c +9 -6
- data/ext/numo/narray/gen/tmpl/cast_array.c +4 -9
- data/ext/numo/narray/gen/tmpl/class.c +9 -0
- data/ext/numo/narray/gen/tmpl/clip.c +118 -0
- data/ext/numo/narray/gen/tmpl/coerce_cast.c +4 -2
- data/ext/numo/narray/gen/tmpl/cond_binary.c +5 -5
- data/ext/numo/narray/gen/tmpl/cond_unary.c +6 -6
- data/ext/numo/narray/gen/tmpl/cum.c +18 -9
- data/ext/numo/narray/gen/tmpl/each.c +2 -2
- data/ext/numo/narray/gen/tmpl/each_with_index.c +2 -2
- data/ext/numo/narray/gen/tmpl/extract.c +2 -2
- data/ext/numo/narray/gen/tmpl/extract_data.c +48 -0
- data/ext/numo/narray/gen/tmpl/eye.c +3 -3
- data/ext/numo/narray/gen/tmpl/fill.c +2 -2
- data/ext/numo/narray/gen/tmpl/format.c +5 -5
- data/ext/numo/narray/gen/tmpl/format_to_a.c +4 -4
- data/ext/numo/narray/gen/tmpl/frexp.c +37 -0
- data/ext/numo/narray/gen/tmpl/init_class.c +20 -0
- data/ext/numo/narray/gen/tmpl/init_module.c +12 -0
- data/ext/numo/narray/gen/tmpl/inspect.c +2 -2
- data/ext/numo/narray/gen/tmpl/lib.c +45 -0
- data/ext/numo/narray/gen/tmpl/logseq.c +1 -1
- data/ext/numo/narray/gen/tmpl/map_with_index.c +2 -2
- data/ext/numo/narray/gen/tmpl/median.c +31 -8
- data/ext/numo/narray/gen/tmpl/minmax.c +24 -24
- data/ext/numo/narray/gen/tmpl/module.c +9 -0
- data/ext/numo/narray/gen/tmpl/new_dim0.c +12 -0
- data/ext/numo/narray/gen/tmpl/poly.c +3 -3
- data/ext/numo/narray/gen/tmpl/pow.c +1 -1
- data/ext/numo/narray/gen/tmpl/powint.c +1 -1
- data/ext/numo/narray/gen/tmpl/qsort.c +10 -3
- data/ext/numo/narray/gen/tmpl/rand.c +1 -1
- data/ext/numo/narray/gen/tmpl/rand_norm.c +1 -1
- data/ext/numo/narray/gen/tmpl/seq.c +1 -1
- data/ext/numo/narray/gen/tmpl/set2.c +5 -5
- data/ext/numo/narray/gen/tmpl/sort.c +29 -14
- data/ext/numo/narray/gen/tmpl/sort_index.c +41 -20
- data/ext/numo/narray/gen/tmpl/store.c +11 -5
- data/ext/numo/narray/gen/tmpl/store_array.c +1 -1
- data/ext/numo/narray/gen/tmpl/store_bit.c +1 -1
- data/ext/numo/narray/gen/tmpl/store_from.c +1 -1
- data/ext/numo/narray/gen/tmpl/store_numeric.c +3 -16
- data/ext/numo/narray/gen/tmpl/to_a.c +2 -2
- data/ext/numo/narray/gen/tmpl/unary.c +7 -7
- data/ext/numo/narray/gen/tmpl/unary2.c +8 -8
- data/ext/numo/narray/gen/tmpl/unary_ret2.c +33 -0
- data/ext/numo/narray/gen/tmpl/unary_s.c +8 -8
- data/ext/numo/narray/gen/tmpl_bit/allocate.c +1 -5
- data/ext/numo/narray/gen/tmpl_bit/aref.c +1 -1
- data/ext/numo/narray/gen/tmpl_bit/aset.c +2 -2
- data/ext/numo/narray/gen/tmpl_bit/binary.c +8 -8
- data/ext/numo/narray/gen/tmpl_bit/bit_count.c +8 -8
- data/ext/numo/narray/gen/tmpl_bit/bit_reduce.c +6 -6
- data/ext/numo/narray/gen/tmpl_bit/each.c +2 -2
- data/ext/numo/narray/gen/tmpl_bit/each_with_index.c +2 -2
- data/ext/numo/narray/gen/tmpl_bit/extract.c +1 -1
- data/ext/numo/narray/gen/tmpl_bit/fill.c +2 -2
- data/ext/numo/narray/gen/tmpl_bit/format.c +5 -5
- data/ext/numo/narray/gen/tmpl_bit/format_to_a.c +2 -2
- data/ext/numo/narray/gen/tmpl_bit/inspect.c +2 -2
- data/ext/numo/narray/gen/tmpl_bit/mask.c +5 -5
- data/ext/numo/narray/gen/tmpl_bit/none_p.c +4 -4
- data/ext/numo/narray/gen/tmpl_bit/store_array.c +2 -2
- data/ext/numo/narray/gen/tmpl_bit/store_bit.c +1 -1
- data/ext/numo/narray/gen/tmpl_bit/store_from.c +1 -1
- data/ext/numo/narray/gen/tmpl_bit/to_a.c +2 -2
- data/ext/numo/narray/gen/tmpl_bit/unary.c +9 -9
- data/ext/numo/narray/gen/tmpl_bit/where.c +6 -6
- data/ext/numo/narray/gen/tmpl_bit/where2.c +8 -8
- data/ext/numo/narray/index.c +46 -30
- data/ext/numo/narray/math.c +12 -6
- data/ext/numo/narray/narray.c +242 -218
- data/ext/numo/narray/ndloop.c +17 -24
- data/ext/numo/narray/numo/intern.h +63 -67
- data/ext/numo/narray/numo/narray.h +38 -13
- data/ext/numo/narray/numo/ndloop.h +1 -1
- data/ext/numo/narray/numo/template.h +1 -1
- data/ext/numo/narray/numo/types/complex.h +8 -4
- data/ext/numo/narray/numo/types/complex_macro.h +118 -1
- data/ext/numo/narray/numo/types/float_macro.h +283 -6
- data/ext/numo/narray/numo/types/robj_macro.h +261 -9
- data/ext/numo/narray/numo/types/xint_macro.h +35 -0
- data/ext/numo/narray/struct.c +34 -15
- data/lib/erbpp.rb +5 -1
- data/lib/erbpp/line_number.rb +10 -3
- data/lib/erbpp/narray_def.rb +55 -25
- data/lib/numo/narray/extra.rb +638 -219
- data/numo-narray.gemspec +1 -0
- data/spec/narray_spec.rb +2 -2
- metadata +17 -14
- data/ext/numo/narray/gen/dtype.erb.c +0 -82
- data/ext/numo/narray/gen/tmpl/cast_numeric.c +0 -22
- data/ext/numo/narray/gen/tmpl/robj_allocate.c +0 -32
- data/ext/numo/narray/gen/tmpl_bit/cast.c +0 -37
- data/ext/numo/narray/gen/tmpl_bit/cast_array.c +0 -18
- data/ext/numo/narray/gen/tmpl_bit/cast_numeric.c +0 -22
- data/ext/numo/narray/gen/tmpl_bit/coerce_cast.c +0 -8
- data/ext/numo/narray/gen/tmpl_bit/map_with_index.c +0 -94
- data/ext/numo/narray/gen/tmpl_bit/store.c +0 -32
- data/ext/numo/narray/gen/tmpl_bit/store_numeric.c +0 -22
data/numo-narray.gemspec
CHANGED
@@ -20,6 +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/narray"
|
22
22
|
spec.license = "MIT"
|
23
|
+
spec.required_ruby_version = '~> 2.1'
|
23
24
|
|
24
25
|
spec.files = `git ls-files Gemfile README.md Rakefile lib ext numo-narray.gemspec spec`.split($/)
|
25
26
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
data/spec/narray_spec.rb
CHANGED
@@ -76,7 +76,7 @@ types.each do |dtype|
|
|
76
76
|
it{expect(@a.stddev).to eq 3.710345895825168}
|
77
77
|
it{expect(@a.rms).to eq 5.901977069875258}
|
78
78
|
end
|
79
|
-
it{expect(@a.
|
79
|
+
it{expect(@a.dup.fill(12)).to eq [12]*6}
|
80
80
|
it{expect((@a + 1)).to eq [2,3,4,6,8,12]}
|
81
81
|
it{expect((@a - 1)).to eq [0,1,2,4,6,10]}
|
82
82
|
it{expect((@a * 3)).to eq [3,6,9,15,21,33]}
|
@@ -183,7 +183,7 @@ types.each do |dtype|
|
|
183
183
|
it{expect(@a.sort).to eq @src}
|
184
184
|
it{expect(@a.sort_index).to eq [[0,1,2],[3,4,5]]}
|
185
185
|
end
|
186
|
-
it{expect(@a.
|
186
|
+
it{expect(@a.dup.fill(12)).to eq [[12]*3]*2}
|
187
187
|
it{expect((@a + 1)).to eq [[2,3,4],[6,8,12]]}
|
188
188
|
it{expect((@a + [1,2,3])).to eq [[2,4,6],[6,9,14]]}
|
189
189
|
it{expect((@a - 1)).to eq [[0,1,2],[4,6,10]]}
|
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.0.
|
4
|
+
version: 0.9.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masahiro TANAKA
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -120,11 +120,13 @@ files:
|
|
120
120
|
- ext/numo/narray/gen/def/uint32.rb
|
121
121
|
- ext/numo/narray/gen/def/uint64.rb
|
122
122
|
- ext/numo/narray/gen/def/uint8.rb
|
123
|
-
- ext/numo/narray/gen/
|
123
|
+
- ext/numo/narray/gen/erbpp2.rb
|
124
|
+
- ext/numo/narray/gen/narray_def.rb
|
124
125
|
- ext/numo/narray/gen/spec.rb
|
125
126
|
- ext/numo/narray/gen/tmpl/accum.c
|
126
127
|
- ext/numo/narray/gen/tmpl/accum_binary.c
|
127
128
|
- ext/numo/narray/gen/tmpl/accum_index.c
|
129
|
+
- ext/numo/narray/gen/tmpl/alloc_func.c
|
128
130
|
- ext/numo/narray/gen/tmpl/allocate.c
|
129
131
|
- ext/numo/narray/gen/tmpl/aref.c
|
130
132
|
- ext/numo/narray/gen/tmpl/aset.c
|
@@ -134,7 +136,8 @@ files:
|
|
134
136
|
- ext/numo/narray/gen/tmpl/bincount.c
|
135
137
|
- ext/numo/narray/gen/tmpl/cast.c
|
136
138
|
- ext/numo/narray/gen/tmpl/cast_array.c
|
137
|
-
- ext/numo/narray/gen/tmpl/
|
139
|
+
- ext/numo/narray/gen/tmpl/class.c
|
140
|
+
- ext/numo/narray/gen/tmpl/clip.c
|
138
141
|
- ext/numo/narray/gen/tmpl/coerce_cast.c
|
139
142
|
- ext/numo/narray/gen/tmpl/cond_binary.c
|
140
143
|
- ext/numo/narray/gen/tmpl/cond_unary.c
|
@@ -142,22 +145,28 @@ files:
|
|
142
145
|
- ext/numo/narray/gen/tmpl/each.c
|
143
146
|
- ext/numo/narray/gen/tmpl/each_with_index.c
|
144
147
|
- ext/numo/narray/gen/tmpl/extract.c
|
148
|
+
- ext/numo/narray/gen/tmpl/extract_data.c
|
145
149
|
- ext/numo/narray/gen/tmpl/eye.c
|
146
150
|
- ext/numo/narray/gen/tmpl/fill.c
|
147
151
|
- ext/numo/narray/gen/tmpl/format.c
|
148
152
|
- ext/numo/narray/gen/tmpl/format_to_a.c
|
153
|
+
- ext/numo/narray/gen/tmpl/frexp.c
|
154
|
+
- ext/numo/narray/gen/tmpl/init_class.c
|
155
|
+
- ext/numo/narray/gen/tmpl/init_module.c
|
149
156
|
- ext/numo/narray/gen/tmpl/inspect.c
|
157
|
+
- ext/numo/narray/gen/tmpl/lib.c
|
150
158
|
- ext/numo/narray/gen/tmpl/logseq.c
|
151
159
|
- ext/numo/narray/gen/tmpl/map_with_index.c
|
152
160
|
- ext/numo/narray/gen/tmpl/median.c
|
153
161
|
- ext/numo/narray/gen/tmpl/minmax.c
|
162
|
+
- ext/numo/narray/gen/tmpl/module.c
|
163
|
+
- ext/numo/narray/gen/tmpl/new_dim0.c
|
154
164
|
- ext/numo/narray/gen/tmpl/poly.c
|
155
165
|
- ext/numo/narray/gen/tmpl/pow.c
|
156
166
|
- ext/numo/narray/gen/tmpl/powint.c
|
157
167
|
- ext/numo/narray/gen/tmpl/qsort.c
|
158
168
|
- ext/numo/narray/gen/tmpl/rand.c
|
159
169
|
- ext/numo/narray/gen/tmpl/rand_norm.c
|
160
|
-
- ext/numo/narray/gen/tmpl/robj_allocate.c
|
161
170
|
- ext/numo/narray/gen/tmpl/seq.c
|
162
171
|
- ext/numo/narray/gen/tmpl/set2.c
|
163
172
|
- ext/numo/narray/gen/tmpl/sort.c
|
@@ -170,6 +179,7 @@ files:
|
|
170
179
|
- ext/numo/narray/gen/tmpl/to_a.c
|
171
180
|
- ext/numo/narray/gen/tmpl/unary.c
|
172
181
|
- ext/numo/narray/gen/tmpl/unary2.c
|
182
|
+
- ext/numo/narray/gen/tmpl/unary_ret2.c
|
173
183
|
- ext/numo/narray/gen/tmpl/unary_s.c
|
174
184
|
- ext/numo/narray/gen/tmpl_bit/allocate.c
|
175
185
|
- ext/numo/narray/gen/tmpl_bit/aref.c
|
@@ -177,10 +187,6 @@ files:
|
|
177
187
|
- ext/numo/narray/gen/tmpl_bit/binary.c
|
178
188
|
- ext/numo/narray/gen/tmpl_bit/bit_count.c
|
179
189
|
- ext/numo/narray/gen/tmpl_bit/bit_reduce.c
|
180
|
-
- ext/numo/narray/gen/tmpl_bit/cast.c
|
181
|
-
- ext/numo/narray/gen/tmpl_bit/cast_array.c
|
182
|
-
- ext/numo/narray/gen/tmpl_bit/cast_numeric.c
|
183
|
-
- ext/numo/narray/gen/tmpl_bit/coerce_cast.c
|
184
190
|
- ext/numo/narray/gen/tmpl_bit/each.c
|
185
191
|
- ext/numo/narray/gen/tmpl_bit/each_with_index.c
|
186
192
|
- ext/numo/narray/gen/tmpl_bit/extract.c
|
@@ -188,14 +194,11 @@ files:
|
|
188
194
|
- ext/numo/narray/gen/tmpl_bit/format.c
|
189
195
|
- ext/numo/narray/gen/tmpl_bit/format_to_a.c
|
190
196
|
- ext/numo/narray/gen/tmpl_bit/inspect.c
|
191
|
-
- ext/numo/narray/gen/tmpl_bit/map_with_index.c
|
192
197
|
- ext/numo/narray/gen/tmpl_bit/mask.c
|
193
198
|
- ext/numo/narray/gen/tmpl_bit/none_p.c
|
194
|
-
- ext/numo/narray/gen/tmpl_bit/store.c
|
195
199
|
- ext/numo/narray/gen/tmpl_bit/store_array.c
|
196
200
|
- ext/numo/narray/gen/tmpl_bit/store_bit.c
|
197
201
|
- ext/numo/narray/gen/tmpl_bit/store_from.c
|
198
|
-
- ext/numo/narray/gen/tmpl_bit/store_numeric.c
|
199
202
|
- ext/numo/narray/gen/tmpl_bit/to_a.c
|
200
203
|
- ext/numo/narray/gen/tmpl_bit/unary.c
|
201
204
|
- ext/numo/narray/gen/tmpl_bit/where.c
|
@@ -253,9 +256,9 @@ require_paths:
|
|
253
256
|
- lib
|
254
257
|
required_ruby_version: !ruby/object:Gem::Requirement
|
255
258
|
requirements:
|
256
|
-
- - "
|
259
|
+
- - "~>"
|
257
260
|
- !ruby/object:Gem::Version
|
258
|
-
version: '
|
261
|
+
version: '2.1'
|
259
262
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
260
263
|
requirements:
|
261
264
|
- - ">="
|
@@ -1,82 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
<%=type_name%>.c
|
3
|
-
Numerical Array Extension for Ruby
|
4
|
-
(C) Copyright 1999-2011,2013-2016 by Masahiro TANAKA
|
5
|
-
*/
|
6
|
-
|
7
|
-
#include <ruby.h>
|
8
|
-
#include <math.h>
|
9
|
-
#include "numo/narray.h"
|
10
|
-
#include "numo/template.h"
|
11
|
-
#include "SFMT.h"
|
12
|
-
|
13
|
-
#define m_map(x) m_num_to_data(rb_yield(m_data_to_num(x)))
|
14
|
-
|
15
|
-
<%
|
16
|
-
eval open(File.join(File.dirname(__FILE__),"spec.rb")).read
|
17
|
-
|
18
|
-
IdVar.declaration.each do |x| %>
|
19
|
-
<%= x %><%
|
20
|
-
end
|
21
|
-
%>
|
22
|
-
|
23
|
-
#include "numo/types/<%=type_name%>.h"
|
24
|
-
|
25
|
-
VALUE cT;
|
26
|
-
extern VALUE cRT;
|
27
|
-
#ifdef mTM
|
28
|
-
VALUE mTM;
|
29
|
-
#endif
|
30
|
-
|
31
|
-
static VALUE <%= find_tmpl('store').c_func %>(VALUE,VALUE);
|
32
|
-
<%
|
33
|
-
Function.codes.each do |x| %>
|
34
|
-
<%= x %>
|
35
|
-
<% end %>
|
36
|
-
|
37
|
-
void
|
38
|
-
Init_nary_<%=tp%>()
|
39
|
-
{
|
40
|
-
volatile VALUE hCast;
|
41
|
-
|
42
|
-
cT = rb_define_class_under(mNumo, "<%=class_name%>", cNArray);
|
43
|
-
<% for x in class_alias %>
|
44
|
-
// alias of <%=class_name%>
|
45
|
-
rb_define_const(mNumo, "<%=x%>", <%=type_var%>);
|
46
|
-
<% end %>
|
47
|
-
<% if has_math %>
|
48
|
-
mTM = rb_define_module_under(cT, "Math"); <% end %>
|
49
|
-
|
50
|
-
<% if is_bit %>
|
51
|
-
rb_define_const(cT, "ELEMENT_BIT_SIZE", INT2FIX(1));
|
52
|
-
rb_define_const(cT, "ELEMENT_BYTE_SIZE", rb_float_new(1.0/8));
|
53
|
-
rb_define_const(cT, "CONTIGUOUS_STRIDE", INT2FIX(1));
|
54
|
-
<% else %>
|
55
|
-
rb_define_const(cT, ELEMENT_BIT_SIZE, INT2FIX(sizeof(dtype)*8));
|
56
|
-
rb_define_const(cT, ELEMENT_BYTE_SIZE, INT2FIX(sizeof(dtype)));
|
57
|
-
rb_define_const(cT, CONTIGUOUS_STRIDE, INT2FIX(sizeof(dtype)));
|
58
|
-
<% end %>
|
59
|
-
|
60
|
-
rb_define_singleton_method(cT, "[]", <%=cast_func%>, -2);
|
61
|
-
|
62
|
-
<% if is_object %>
|
63
|
-
rb_undef_method(rb_singleton_class(cT),"from_binary");
|
64
|
-
rb_undef_method(cT,"to_binary");
|
65
|
-
rb_undef_method(cT,"swap_byte");
|
66
|
-
rb_undef_method(cT,"to_network");
|
67
|
-
rb_undef_method(cT,"to_vacs");
|
68
|
-
rb_undef_method(cT,"to_host");
|
69
|
-
rb_undef_method(cT,"to_swapped");
|
70
|
-
<% end %>
|
71
|
-
|
72
|
-
<% Function.definitions.each do |x| %>
|
73
|
-
<%= x %><% end %>
|
74
|
-
<% IdVar.assignment.each do |x| %>
|
75
|
-
<%= x %><% end %>
|
76
|
-
|
77
|
-
hCast = rb_hash_new();
|
78
|
-
rb_define_const(cT, "UPCAST", hCast);
|
79
|
-
rb_hash_aset(hCast, rb_cArray, cT);
|
80
|
-
<% for x in upcast %>
|
81
|
-
<%= x %><% end %>
|
82
|
-
}
|
@@ -1,22 +0,0 @@
|
|
1
|
-
static VALUE
|
2
|
-
numo_<%=tp%>_new_dim0(dtype x)
|
3
|
-
{
|
4
|
-
narray_t *na;
|
5
|
-
VALUE v;
|
6
|
-
dtype *ptr;
|
7
|
-
|
8
|
-
v = rb_narray_new(cT, 0, NULL);
|
9
|
-
GetNArray(v,na);
|
10
|
-
ptr = (dtype*)(char*)na_get_pointer_for_write(v);
|
11
|
-
*ptr = x;
|
12
|
-
na_release_lock(v);
|
13
|
-
return v;
|
14
|
-
}
|
15
|
-
|
16
|
-
static VALUE
|
17
|
-
<%=c_func%>(VALUE x)
|
18
|
-
{
|
19
|
-
dtype y;
|
20
|
-
y = m_num_to_data(x);
|
21
|
-
return numo_<%=tp%>_new_dim0(y);
|
22
|
-
}
|
@@ -1,32 +0,0 @@
|
|
1
|
-
static void
|
2
|
-
na_gc_mark_robj(narray_data_t* na)
|
3
|
-
{
|
4
|
-
size_t n, i;
|
5
|
-
VALUE *a;
|
6
|
-
|
7
|
-
if (na->ptr) {
|
8
|
-
a = (VALUE*)(na->ptr);
|
9
|
-
n = na->base.size;
|
10
|
-
for (i=0; i<n; i++) {
|
11
|
-
rb_gc_mark(a[i]);
|
12
|
-
}
|
13
|
-
}
|
14
|
-
}
|
15
|
-
|
16
|
-
void na_free(narray_data_t* na);
|
17
|
-
|
18
|
-
VALUE
|
19
|
-
<%=c_func%>(VALUE klass)
|
20
|
-
{
|
21
|
-
narray_data_t *na = ALLOC(narray_data_t);
|
22
|
-
|
23
|
-
na->base.ndim = 0;
|
24
|
-
na->base.type = NARRAY_DATA_T;
|
25
|
-
na->base.flag[0] = 0;
|
26
|
-
na->base.flag[1] = 0;
|
27
|
-
na->base.size = 0;
|
28
|
-
na->base.shape = NULL;
|
29
|
-
na->base.reduce = INT2FIX(0);
|
30
|
-
na->ptr = NULL;
|
31
|
-
return Data_Wrap_Struct(klass, na_gc_mark_robj, na_free, na);
|
32
|
-
}
|
@@ -1,37 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
Cast object to Numo::<%=class_name%>.
|
3
|
-
@overload [](elements)
|
4
|
-
@overload <%=method%>(array)
|
5
|
-
@param [Numeric,Array] elements
|
6
|
-
@param [Array] array
|
7
|
-
@return [Numo::<%=class_name%>]
|
8
|
-
*/
|
9
|
-
static VALUE
|
10
|
-
<%=c_func%>(VALUE type, VALUE obj)
|
11
|
-
{
|
12
|
-
VALUE v;
|
13
|
-
narray_t *na;
|
14
|
-
dtype x;
|
15
|
-
|
16
|
-
if (CLASS_OF(obj)==cT) {
|
17
|
-
return obj;
|
18
|
-
}
|
19
|
-
if (RTEST(rb_obj_is_kind_of(obj,rb_cNumeric))) {
|
20
|
-
x = m_num_to_data(obj);
|
21
|
-
return numo_<%=tp%>_new_dim0(x);
|
22
|
-
}
|
23
|
-
if (RTEST(rb_obj_is_kind_of(obj,rb_cArray))) {
|
24
|
-
return <%=find_tmpl("cast_array").c_func%>(obj);
|
25
|
-
}
|
26
|
-
if (IsNArray(obj)) {
|
27
|
-
GetNArray(obj,na);
|
28
|
-
v = rb_narray_new(cT, NA_NDIM(na), NA_SHAPE(na));
|
29
|
-
if (NA_SIZE(na) > 0) {
|
30
|
-
<%=find_tmpl("allocate").c_func%>(v);
|
31
|
-
<%=find_tmpl("store").c_func%>(v,obj);
|
32
|
-
}
|
33
|
-
return v;
|
34
|
-
}
|
35
|
-
rb_raise(nary_eCastError,"cannot cast to %s",rb_class2name(type));
|
36
|
-
return Qnil;
|
37
|
-
}
|
@@ -1,18 +0,0 @@
|
|
1
|
-
static VALUE
|
2
|
-
<%=c_func%>(VALUE rary)
|
3
|
-
{
|
4
|
-
VALUE vnc, nary;
|
5
|
-
narray_t *na;
|
6
|
-
na_compose_t *nc;
|
7
|
-
|
8
|
-
vnc = na_ary_composition(rary);
|
9
|
-
Data_Get_Struct(vnc, na_compose_t, nc);
|
10
|
-
nary = rb_narray_new(cT, nc->ndim, nc->shape);
|
11
|
-
RB_GC_GUARD(vnc);
|
12
|
-
GetNArray(nary,na);
|
13
|
-
if (na->size > 0) {
|
14
|
-
<%=find_tmpl("allocate").c_func%>(nary);
|
15
|
-
<%=find_tmpl("store_array").c_func%>(nary, rary);
|
16
|
-
}
|
17
|
-
return nary;
|
18
|
-
}
|
@@ -1,22 +0,0 @@
|
|
1
|
-
static VALUE
|
2
|
-
numo_<%=tp%>_new_dim0(dtype x)
|
3
|
-
{
|
4
|
-
narray_t *na;
|
5
|
-
VALUE v;
|
6
|
-
dtype *ptr;
|
7
|
-
|
8
|
-
v = rb_narray_new(cT, 0, NULL);
|
9
|
-
GetNArray(v,na);
|
10
|
-
ptr = (dtype*)(char*)na_get_pointer_for_write(v);
|
11
|
-
*ptr = x;
|
12
|
-
na_release_lock(v);
|
13
|
-
return v;
|
14
|
-
}
|
15
|
-
|
16
|
-
static VALUE
|
17
|
-
<%=c_func%>(VALUE x)
|
18
|
-
{
|
19
|
-
dtype y;
|
20
|
-
y = m_num_to_data(x);
|
21
|
-
return numo_<%=tp%>_new_dim0(y);
|
22
|
-
}
|
@@ -1,94 +0,0 @@
|
|
1
|
-
static inline dtype
|
2
|
-
yield_map_with_index(dtype x, size_t *c, VALUE *a, int nd, int md)
|
3
|
-
{
|
4
|
-
int j;
|
5
|
-
VALUE y;
|
6
|
-
|
7
|
-
a[0] = m_data_to_num(x);
|
8
|
-
for (j=0; j<=nd; j++) {
|
9
|
-
a[j+1] = SIZET2NUM(c[j]);
|
10
|
-
}
|
11
|
-
y = rb_yield(rb_ary_new4(md,a));
|
12
|
-
return m_num_to_data(y);
|
13
|
-
}
|
14
|
-
|
15
|
-
void
|
16
|
-
<%=c_iter%>(na_loop_t *const lp)
|
17
|
-
{
|
18
|
-
size_t i;
|
19
|
-
char *p1, *p2;
|
20
|
-
ssize_t s1, s2;
|
21
|
-
size_t *idx1, *idx2;
|
22
|
-
dtype x;
|
23
|
-
VALUE *a;
|
24
|
-
size_t *c;
|
25
|
-
int nd, md;
|
26
|
-
|
27
|
-
c = (size_t*)(lp->opt_ptr);
|
28
|
-
nd = lp->ndim - 1;
|
29
|
-
md = lp->ndim + 1;
|
30
|
-
a = ALLOCA_N(VALUE,md);
|
31
|
-
|
32
|
-
INIT_COUNTER(lp, i);
|
33
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
34
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
35
|
-
|
36
|
-
c[nd] = 0;
|
37
|
-
if (idx1) {
|
38
|
-
if (idx2) {
|
39
|
-
for (; i--;) {
|
40
|
-
GET_DATA_INDEX(p1,idx1,dtype,x);
|
41
|
-
x = yield_map_with_index(x,c,a,nd,md);
|
42
|
-
SET_DATA_INDEX(p2,idx2,dtype,x);
|
43
|
-
c[nd]++;
|
44
|
-
}
|
45
|
-
} else {
|
46
|
-
for (; i--;) {
|
47
|
-
GET_DATA_INDEX(p1,idx1,dtype,x);
|
48
|
-
x = yield_map_with_index(x,c,a,nd,md);
|
49
|
-
SET_DATA_STRIDE(p2,s2,dtype,x);
|
50
|
-
c[nd]++;
|
51
|
-
}
|
52
|
-
}
|
53
|
-
} else {
|
54
|
-
if (idx2) {
|
55
|
-
for (; i--;) {
|
56
|
-
GET_DATA_STRIDE(p1,s1,dtype,x);
|
57
|
-
x = yield_map_with_index(x,c,a,nd,md);
|
58
|
-
SET_DATA_INDEX(p2,idx2,dtype,x);
|
59
|
-
c[nd]++;
|
60
|
-
}
|
61
|
-
} else {
|
62
|
-
for (; i--;) {
|
63
|
-
GET_DATA_STRIDE(p1,s1,dtype,x);
|
64
|
-
x = yield_map_with_index(x,c,a,nd,md);
|
65
|
-
SET_DATA_STRIDE(p2,s2,dtype,x);
|
66
|
-
c[nd]++;
|
67
|
-
}
|
68
|
-
}
|
69
|
-
}
|
70
|
-
}
|
71
|
-
|
72
|
-
/*
|
73
|
-
Invokes the given block once for each element of self,
|
74
|
-
passing that element and indices along each axis as parameters.
|
75
|
-
Creates a new NArray containing the values returned by the block.
|
76
|
-
Inplace option is allowed, i.e., `nary.inplace.map` overwrites `nary`.
|
77
|
-
|
78
|
-
@overload <%=method%>
|
79
|
-
|
80
|
-
For a block {|x,i,j,...| ... }
|
81
|
-
@yield [x,i,j,...] x is an element, i,j,... are multidimensional indices.
|
82
|
-
|
83
|
-
@return [Numo::NArray] mapped array
|
84
|
-
|
85
|
-
*/
|
86
|
-
static VALUE
|
87
|
-
<%=c_func%>(VALUE self)
|
88
|
-
{
|
89
|
-
ndfunc_arg_in_t ain[1] = {{Qnil,0}};
|
90
|
-
ndfunc_arg_out_t aout[1] = {{cT,0}};
|
91
|
-
ndfunc_t ndf = {<%=c_iter%>, FULL_LOOP, 1,1, ain,aout};
|
92
|
-
|
93
|
-
return na_ndloop_with_index(&ndf, 1, self);
|
94
|
-
}
|