red-arrow-numo-narray 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +2 -2
- data/doc/text/news.md +11 -0
- data/lib/arrow-numo-narray.rb +2 -0
- data/lib/arrow-numo-narray/error.rb +21 -0
- data/lib/arrow-numo-narray/to-narray.rb +13 -1
- data/lib/arrow-numo-narray/version.rb +1 -1
- data/test/test-to-narray.rb +303 -239
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d3548b4dd13c4472bf84d6a46593328972efd81c81f71fd9c022f7823734ed9c
|
4
|
+
data.tar.gz: 3e6c02abf4ba9827db4ba6f6dc8421a805a20df7c81d2bd050226e6888a768e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c6d433d0e3f6738f0e6d8b77b97760d36ac775faa4992ff1f4992f21179cc0439c2aa383cc3044090d54f82e37c968920f3b4ec638a65edb1a73e62c8220cab
|
7
|
+
data.tar.gz: 78f28f991402fd5b3ac96b901e7b7ef230d6459d55f08b3b1f3644a599cd2995aca020615c5f0ea2cc11a039b8529e3ec3e167db619e366f936630aaa58b6aea
|
data/README.md
CHANGED
@@ -21,8 +21,8 @@ Red Arrow Numo::NArray adds `Arrow::Tensor#to_narray` and `#to_arrow` to `Numo::
|
|
21
21
|
```ruby
|
22
22
|
require "arrow-numo-narray"
|
23
23
|
|
24
|
-
tensor.to_narray # ->
|
25
|
-
narray.to_arrow # -> An Arrow::Tensor
|
24
|
+
tensor.to_narray # -> An object of Numo::NArray's numeric subclass such as Numo::Int8
|
25
|
+
narray.to_arrow # -> An object of Arrow::Tensor
|
26
26
|
```
|
27
27
|
|
28
28
|
## Dependencies
|
data/doc/text/news.md
CHANGED
data/lib/arrow-numo-narray.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Copyright 2019 Sutou Kouhei <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module ArrowNumoNArray
|
16
|
+
class Error < StandardError
|
17
|
+
end
|
18
|
+
|
19
|
+
class UncovertableError < Error
|
20
|
+
end
|
21
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright 2017 Kouhei
|
1
|
+
# Copyright 2017-2019 Sutou Kouhei <kou@clear-code.com>
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -73,6 +73,18 @@ module Arrow
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
+
class Array
|
77
|
+
def to_narray
|
78
|
+
unless n_nulls.zero?
|
79
|
+
message = "can't convert #{self.class} that has null values to NArray"
|
80
|
+
raise UnconvertableError, message
|
81
|
+
end
|
82
|
+
narray = value_data_type.narray_class.new(length)
|
83
|
+
narray.store_binary(buffer.data.to_s)
|
84
|
+
narray
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
76
88
|
class Tensor
|
77
89
|
def to_narray
|
78
90
|
narray = value_data_type.narray_class.new(shape)
|
data/test/test-to-narray.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright 2017 Kouhei
|
1
|
+
# Copyright 2017-2019 Sutou Kouhei <kou@clear-code.com>
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -13,253 +13,317 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
class ToNAarrayTest < Test::Unit::TestCase
|
16
|
-
|
17
|
-
|
18
|
-
[
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
[
|
23
|
-
[9, 10, 11, 12],
|
24
|
-
[-1, -2, -3, -4],
|
25
|
-
],
|
26
|
-
[
|
27
|
-
[-5, -6, -7, -8],
|
28
|
-
[-9, -10, -11, -12],
|
29
|
-
],
|
30
|
-
]
|
31
|
-
shape = [3, 2, 4]
|
32
|
-
tensor = Arrow::Tensor.new(Arrow::UInt8DataType.new,
|
33
|
-
Arrow::Buffer.new(data.flatten.pack("c*")),
|
34
|
-
shape,
|
35
|
-
nil,
|
36
|
-
nil)
|
37
|
-
assert_equal(Numo::Int8.new(shape).store(data),
|
38
|
-
tensor.to_narray)
|
39
|
-
end
|
16
|
+
sub_test_case("Array") do
|
17
|
+
test("Int8") do
|
18
|
+
array = Arrow::Int8Array.new([-(2 ** 7), 0, 2 ** 7 - 1])
|
19
|
+
assert_equal(Numo::Int8[-(2 ** 7), 0, 2 ** 7 - 1],
|
20
|
+
array.to_narray)
|
21
|
+
end
|
40
22
|
|
41
|
-
|
42
|
-
|
43
|
-
[
|
44
|
-
|
45
|
-
|
46
|
-
],
|
47
|
-
[
|
48
|
-
[9, 10, 11, 12],
|
49
|
-
[-1, -2, -3, -4],
|
50
|
-
],
|
51
|
-
[
|
52
|
-
[-5, -6, -7, -8],
|
53
|
-
[-9, -10, -11, -12],
|
54
|
-
],
|
55
|
-
]
|
56
|
-
shape = [3, 2, 4]
|
57
|
-
tensor = Arrow::Tensor.new(Arrow::UInt16DataType.new,
|
58
|
-
Arrow::Buffer.new(data.flatten.pack("s*")),
|
59
|
-
shape,
|
60
|
-
nil,
|
61
|
-
nil)
|
62
|
-
assert_equal(Numo::Int16.new(shape).store(data),
|
63
|
-
tensor.to_narray)
|
64
|
-
end
|
23
|
+
test("Int16") do
|
24
|
+
array = Arrow::Int16Array.new([-(2 ** 15), 0, 2 ** 15 - 1])
|
25
|
+
assert_equal(Numo::Int16[-(2 ** 15), 0, 2 ** 15 - 1],
|
26
|
+
array.to_narray)
|
27
|
+
end
|
65
28
|
|
66
|
-
|
67
|
-
|
68
|
-
[
|
69
|
-
|
70
|
-
|
71
|
-
],
|
72
|
-
[
|
73
|
-
[9, 10, 11, 12],
|
74
|
-
[-1, -2, -3, -4],
|
75
|
-
],
|
76
|
-
[
|
77
|
-
[-5, -6, -7, -8],
|
78
|
-
[-9, -10, -11, -12],
|
79
|
-
],
|
80
|
-
]
|
81
|
-
shape = [3, 2, 4]
|
82
|
-
tensor = Arrow::Tensor.new(Arrow::UInt32DataType.new,
|
83
|
-
Arrow::Buffer.new(data.flatten.pack("l*")),
|
84
|
-
shape,
|
85
|
-
nil,
|
86
|
-
nil)
|
87
|
-
assert_equal(Numo::Int32.new(shape).store(data),
|
88
|
-
tensor.to_narray)
|
89
|
-
end
|
29
|
+
test("Int32") do
|
30
|
+
array = Arrow::Int32Array.new([-(2 ** 31), 0, 2 ** 31 - 1])
|
31
|
+
assert_equal(Numo::Int32[-(2 ** 31), 0, 2 ** 31 - 1],
|
32
|
+
array.to_narray)
|
33
|
+
end
|
90
34
|
|
91
|
-
|
92
|
-
|
93
|
-
[
|
94
|
-
|
95
|
-
|
96
|
-
],
|
97
|
-
[
|
98
|
-
[9, 10, 11, 12],
|
99
|
-
[-1, -2, -3, -4],
|
100
|
-
],
|
101
|
-
[
|
102
|
-
[-5, -6, -7, -8],
|
103
|
-
[-9, -10, -11, -12],
|
104
|
-
],
|
105
|
-
]
|
106
|
-
shape = [3, 2, 4]
|
107
|
-
tensor = Arrow::Tensor.new(Arrow::UInt64DataType.new,
|
108
|
-
Arrow::Buffer.new(data.flatten.pack("q*")),
|
109
|
-
shape,
|
110
|
-
nil,
|
111
|
-
nil)
|
112
|
-
assert_equal(Numo::Int64.new(shape).store(data),
|
113
|
-
tensor.to_narray)
|
114
|
-
end
|
35
|
+
test("Int64") do
|
36
|
+
array = Arrow::Int64Array.new([-(2 ** 63), 0, 2 ** 63 - 1])
|
37
|
+
assert_equal(Numo::Int64[-(2 ** 63), 0, 2 ** 63 - 1],
|
38
|
+
array.to_narray)
|
39
|
+
end
|
115
40
|
|
116
|
-
|
117
|
-
|
118
|
-
[
|
119
|
-
|
120
|
-
|
121
|
-
],
|
122
|
-
[
|
123
|
-
[9, 10, 11, 12],
|
124
|
-
[13, 14, 15, 16],
|
125
|
-
],
|
126
|
-
[
|
127
|
-
[17, 18, 19, 20],
|
128
|
-
[21, 22, 23, 24],
|
129
|
-
],
|
130
|
-
]
|
131
|
-
shape = [3, 2, 4]
|
132
|
-
tensor = Arrow::Tensor.new(Arrow::UInt8DataType.new,
|
133
|
-
Arrow::Buffer.new(data.flatten.pack("C*")),
|
134
|
-
shape,
|
135
|
-
nil,
|
136
|
-
nil)
|
137
|
-
assert_equal(Numo::UInt8.new(shape).store(data),
|
138
|
-
tensor.to_narray)
|
139
|
-
end
|
41
|
+
test("UInt8") do
|
42
|
+
array = Arrow::UInt8Array.new([0, 2 ** 8 - 1])
|
43
|
+
assert_equal(Numo::UInt8[0, 2 ** 8 - 1],
|
44
|
+
array.to_narray)
|
45
|
+
end
|
140
46
|
|
141
|
-
|
142
|
-
|
143
|
-
[
|
144
|
-
|
145
|
-
|
146
|
-
],
|
147
|
-
[
|
148
|
-
[9, 10, 11, 12],
|
149
|
-
[13, 14, 15, 16],
|
150
|
-
],
|
151
|
-
[
|
152
|
-
[17, 18, 19, 20],
|
153
|
-
[21, 22, 23, 24],
|
154
|
-
],
|
155
|
-
]
|
156
|
-
shape = [3, 2, 4]
|
157
|
-
tensor = Arrow::Tensor.new(Arrow::UInt16DataType.new,
|
158
|
-
Arrow::Buffer.new(data.flatten.pack("S*")),
|
159
|
-
shape,
|
160
|
-
nil,
|
161
|
-
nil)
|
162
|
-
assert_equal(Numo::UInt16.new(shape).store(data),
|
163
|
-
tensor.to_narray)
|
164
|
-
end
|
47
|
+
test("UInt16") do
|
48
|
+
array = Arrow::UInt16Array.new([0, 2 ** 16 - 1])
|
49
|
+
assert_equal(Numo::UInt16[0, 2 ** 16 - 1],
|
50
|
+
array.to_narray)
|
51
|
+
end
|
165
52
|
|
166
|
-
|
167
|
-
|
168
|
-
[
|
169
|
-
|
170
|
-
|
171
|
-
],
|
172
|
-
[
|
173
|
-
[9, 10, 11, 12],
|
174
|
-
[13, 14, 15, 16],
|
175
|
-
],
|
176
|
-
[
|
177
|
-
[17, 18, 19, 20],
|
178
|
-
[21, 22, 23, 24],
|
179
|
-
],
|
180
|
-
]
|
181
|
-
shape = [3, 2, 4]
|
182
|
-
tensor = Arrow::Tensor.new(Arrow::UInt32DataType.new,
|
183
|
-
Arrow::Buffer.new(data.flatten.pack("L*")),
|
184
|
-
shape,
|
185
|
-
nil,
|
186
|
-
nil)
|
187
|
-
assert_equal(Numo::UInt32.new(shape).store(data),
|
188
|
-
tensor.to_narray)
|
189
|
-
end
|
53
|
+
test("UInt32") do
|
54
|
+
array = Arrow::UInt32Array.new([0, 2 ** 32 - 1])
|
55
|
+
assert_equal(Numo::UInt32[0, 2 ** 32 - 1],
|
56
|
+
array.to_narray)
|
57
|
+
end
|
190
58
|
|
191
|
-
|
192
|
-
|
193
|
-
[
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
[17, 18, 19, 20],
|
203
|
-
[21, 22, 23, 24],
|
204
|
-
],
|
205
|
-
]
|
206
|
-
shape = [3, 2, 4]
|
207
|
-
tensor = Arrow::Tensor.new(Arrow::UInt64DataType.new,
|
208
|
-
Arrow::Buffer.new(data.flatten.pack("Q*")),
|
209
|
-
shape,
|
210
|
-
nil,
|
211
|
-
nil)
|
212
|
-
assert_equal(Numo::UInt64.new(shape).store(data),
|
213
|
-
tensor.to_narray)
|
214
|
-
end
|
59
|
+
test("UInt64") do
|
60
|
+
array = Arrow::UInt64Array.new([0, 2 ** 64 - 1])
|
61
|
+
assert_equal(Numo::UInt64[0, 2 ** 64 - 1],
|
62
|
+
array.to_narray)
|
63
|
+
end
|
64
|
+
|
65
|
+
test("Float") do
|
66
|
+
array = Arrow::FloatArray.new([-1.1, 0, 1.1])
|
67
|
+
assert_equal(Numo::SFloat[-1.1, 0, 1.1],
|
68
|
+
array.to_narray)
|
69
|
+
end
|
215
70
|
|
216
|
-
|
217
|
-
|
218
|
-
[
|
219
|
-
|
220
|
-
|
221
|
-
],
|
222
|
-
[
|
223
|
-
[9.0, 10.0, 11.0, 12.0],
|
224
|
-
[13.0, 14.0, 15.0, 16.0],
|
225
|
-
],
|
226
|
-
[
|
227
|
-
[17.0, 18.0, 19.0, 20.0],
|
228
|
-
[21.0, 22.0, 23.0, 24.0],
|
229
|
-
],
|
230
|
-
]
|
231
|
-
shape = [3, 2, 4]
|
232
|
-
tensor = Arrow::Tensor.new(Arrow::FloatDataType.new,
|
233
|
-
Arrow::Buffer.new(data.flatten.pack("f*")),
|
234
|
-
shape,
|
235
|
-
nil,
|
236
|
-
nil)
|
237
|
-
assert_equal(Numo::SFloat.new(shape).store(data),
|
238
|
-
tensor.to_narray)
|
71
|
+
test("Double") do
|
72
|
+
array = Arrow::DoubleArray.new([-1.1, 0, 1.1])
|
73
|
+
assert_equal(Numo::DFloat[-1.1, 0, 1.1],
|
74
|
+
array.to_narray)
|
75
|
+
end
|
239
76
|
end
|
240
77
|
|
241
|
-
|
242
|
-
|
243
|
-
[
|
244
|
-
[
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
[
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
[
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
78
|
+
sub_test_case("Tensor") do
|
79
|
+
test("Int8") do
|
80
|
+
data = [
|
81
|
+
[
|
82
|
+
[1, 2, 3, 4],
|
83
|
+
[5, 6, 7, 8],
|
84
|
+
],
|
85
|
+
[
|
86
|
+
[9, 10, 11, 12],
|
87
|
+
[-1, -2, -3, -4],
|
88
|
+
],
|
89
|
+
[
|
90
|
+
[-5, -6, -7, -8],
|
91
|
+
[-9, -10, -11, -12],
|
92
|
+
],
|
93
|
+
]
|
94
|
+
shape = [3, 2, 4]
|
95
|
+
tensor = Arrow::Tensor.new(Arrow::Int8DataType.new,
|
96
|
+
Arrow::Buffer.new(data.flatten.pack("c*")),
|
97
|
+
shape,
|
98
|
+
nil,
|
99
|
+
nil)
|
100
|
+
assert_equal(Numo::Int8.new(shape).store(data),
|
101
|
+
tensor.to_narray)
|
102
|
+
end
|
103
|
+
|
104
|
+
test("Int16") do
|
105
|
+
data = [
|
106
|
+
[
|
107
|
+
[1, 2, 3, 4],
|
108
|
+
[5, 6, 7, 8],
|
109
|
+
],
|
110
|
+
[
|
111
|
+
[9, 10, 11, 12],
|
112
|
+
[-1, -2, -3, -4],
|
113
|
+
],
|
114
|
+
[
|
115
|
+
[-5, -6, -7, -8],
|
116
|
+
[-9, -10, -11, -12],
|
117
|
+
],
|
118
|
+
]
|
119
|
+
shape = [3, 2, 4]
|
120
|
+
tensor = Arrow::Tensor.new(Arrow::Int16DataType.new,
|
121
|
+
Arrow::Buffer.new(data.flatten.pack("s*")),
|
122
|
+
shape,
|
123
|
+
nil,
|
124
|
+
nil)
|
125
|
+
assert_equal(Numo::Int16.new(shape).store(data),
|
126
|
+
tensor.to_narray)
|
127
|
+
end
|
128
|
+
|
129
|
+
test("Int32") do
|
130
|
+
data = [
|
131
|
+
[
|
132
|
+
[1, 2, 3, 4],
|
133
|
+
[5, 6, 7, 8],
|
134
|
+
],
|
135
|
+
[
|
136
|
+
[9, 10, 11, 12],
|
137
|
+
[-1, -2, -3, -4],
|
138
|
+
],
|
139
|
+
[
|
140
|
+
[-5, -6, -7, -8],
|
141
|
+
[-9, -10, -11, -12],
|
142
|
+
],
|
143
|
+
]
|
144
|
+
shape = [3, 2, 4]
|
145
|
+
tensor = Arrow::Tensor.new(Arrow::Int32DataType.new,
|
146
|
+
Arrow::Buffer.new(data.flatten.pack("l*")),
|
147
|
+
shape,
|
148
|
+
nil,
|
149
|
+
nil)
|
150
|
+
assert_equal(Numo::Int32.new(shape).store(data),
|
151
|
+
tensor.to_narray)
|
152
|
+
end
|
153
|
+
|
154
|
+
test("Int64") do
|
155
|
+
data = [
|
156
|
+
[
|
157
|
+
[1, 2, 3, 4],
|
158
|
+
[5, 6, 7, 8],
|
159
|
+
],
|
160
|
+
[
|
161
|
+
[9, 10, 11, 12],
|
162
|
+
[-1, -2, -3, -4],
|
163
|
+
],
|
164
|
+
[
|
165
|
+
[-5, -6, -7, -8],
|
166
|
+
[-9, -10, -11, -12],
|
167
|
+
],
|
168
|
+
]
|
169
|
+
shape = [3, 2, 4]
|
170
|
+
tensor = Arrow::Tensor.new(Arrow::Int64DataType.new,
|
171
|
+
Arrow::Buffer.new(data.flatten.pack("q*")),
|
172
|
+
shape,
|
173
|
+
nil,
|
174
|
+
nil)
|
175
|
+
assert_equal(Numo::Int64.new(shape).store(data),
|
176
|
+
tensor.to_narray)
|
177
|
+
end
|
178
|
+
|
179
|
+
test("UInt8") do
|
180
|
+
data = [
|
181
|
+
[
|
182
|
+
[1, 2, 3, 4],
|
183
|
+
[5, 6, 7, 8],
|
184
|
+
],
|
185
|
+
[
|
186
|
+
[9, 10, 11, 12],
|
187
|
+
[13, 14, 15, 16],
|
188
|
+
],
|
189
|
+
[
|
190
|
+
[17, 18, 19, 20],
|
191
|
+
[21, 22, 23, 24],
|
192
|
+
],
|
193
|
+
]
|
194
|
+
shape = [3, 2, 4]
|
195
|
+
tensor = Arrow::Tensor.new(Arrow::UInt8DataType.new,
|
196
|
+
Arrow::Buffer.new(data.flatten.pack("C*")),
|
197
|
+
shape,
|
198
|
+
nil,
|
199
|
+
nil)
|
200
|
+
assert_equal(Numo::UInt8.new(shape).store(data),
|
201
|
+
tensor.to_narray)
|
202
|
+
end
|
203
|
+
|
204
|
+
test("UInt16") do
|
205
|
+
data = [
|
206
|
+
[
|
207
|
+
[1, 2, 3, 4],
|
208
|
+
[5, 6, 7, 8],
|
209
|
+
],
|
210
|
+
[
|
211
|
+
[9, 10, 11, 12],
|
212
|
+
[13, 14, 15, 16],
|
213
|
+
],
|
214
|
+
[
|
215
|
+
[17, 18, 19, 20],
|
216
|
+
[21, 22, 23, 24],
|
217
|
+
],
|
218
|
+
]
|
219
|
+
shape = [3, 2, 4]
|
220
|
+
tensor = Arrow::Tensor.new(Arrow::UInt16DataType.new,
|
221
|
+
Arrow::Buffer.new(data.flatten.pack("S*")),
|
222
|
+
shape,
|
223
|
+
nil,
|
224
|
+
nil)
|
225
|
+
assert_equal(Numo::UInt16.new(shape).store(data),
|
226
|
+
tensor.to_narray)
|
227
|
+
end
|
228
|
+
|
229
|
+
test("UInt32") do
|
230
|
+
data = [
|
231
|
+
[
|
232
|
+
[1, 2, 3, 4],
|
233
|
+
[5, 6, 7, 8],
|
234
|
+
],
|
235
|
+
[
|
236
|
+
[9, 10, 11, 12],
|
237
|
+
[13, 14, 15, 16],
|
238
|
+
],
|
239
|
+
[
|
240
|
+
[17, 18, 19, 20],
|
241
|
+
[21, 22, 23, 24],
|
242
|
+
],
|
243
|
+
]
|
244
|
+
shape = [3, 2, 4]
|
245
|
+
tensor = Arrow::Tensor.new(Arrow::UInt32DataType.new,
|
246
|
+
Arrow::Buffer.new(data.flatten.pack("L*")),
|
247
|
+
shape,
|
248
|
+
nil,
|
249
|
+
nil)
|
250
|
+
assert_equal(Numo::UInt32.new(shape).store(data),
|
251
|
+
tensor.to_narray)
|
252
|
+
end
|
253
|
+
|
254
|
+
test("UInt64") do
|
255
|
+
data = [
|
256
|
+
[
|
257
|
+
[1, 2, 3, 4],
|
258
|
+
[5, 6, 7, 8],
|
259
|
+
],
|
260
|
+
[
|
261
|
+
[9, 10, 11, 12],
|
262
|
+
[13, 14, 15, 16],
|
263
|
+
],
|
264
|
+
[
|
265
|
+
[17, 18, 19, 20],
|
266
|
+
[21, 22, 23, 24],
|
267
|
+
],
|
268
|
+
]
|
269
|
+
shape = [3, 2, 4]
|
270
|
+
tensor = Arrow::Tensor.new(Arrow::UInt64DataType.new,
|
271
|
+
Arrow::Buffer.new(data.flatten.pack("Q*")),
|
272
|
+
shape,
|
273
|
+
nil,
|
274
|
+
nil)
|
275
|
+
assert_equal(Numo::UInt64.new(shape).store(data),
|
276
|
+
tensor.to_narray)
|
277
|
+
end
|
278
|
+
|
279
|
+
test("Float") do
|
280
|
+
data = [
|
281
|
+
[
|
282
|
+
[1.0, 2.0, 3.0, 4.0],
|
283
|
+
[5.0, 6.0, 7.0, 8.0],
|
284
|
+
],
|
285
|
+
[
|
286
|
+
[9.0, 10.0, 11.0, 12.0],
|
287
|
+
[13.0, 14.0, 15.0, 16.0],
|
288
|
+
],
|
289
|
+
[
|
290
|
+
[17.0, 18.0, 19.0, 20.0],
|
291
|
+
[21.0, 22.0, 23.0, 24.0],
|
292
|
+
],
|
293
|
+
]
|
294
|
+
shape = [3, 2, 4]
|
295
|
+
tensor = Arrow::Tensor.new(Arrow::FloatDataType.new,
|
296
|
+
Arrow::Buffer.new(data.flatten.pack("f*")),
|
297
|
+
shape,
|
298
|
+
nil,
|
299
|
+
nil)
|
300
|
+
assert_equal(Numo::SFloat.new(shape).store(data),
|
301
|
+
tensor.to_narray)
|
302
|
+
end
|
303
|
+
|
304
|
+
test("Double") do
|
305
|
+
data = [
|
306
|
+
[
|
307
|
+
[1.0, 2.0, 3.0, 4.0],
|
308
|
+
[5.0, 6.0, 7.0, 8.0],
|
309
|
+
],
|
310
|
+
[
|
311
|
+
[9.0, 10.0, 11.0, 12.0],
|
312
|
+
[13.0, 14.0, 15.0, 16.0],
|
313
|
+
],
|
314
|
+
[
|
315
|
+
[17.0, 18.0, 19.0, 20.0],
|
316
|
+
[21.0, 22.0, 23.0, 24.0],
|
317
|
+
],
|
318
|
+
]
|
319
|
+
shape = [3, 2, 4]
|
320
|
+
tensor = Arrow::Tensor.new(Arrow::DoubleDataType.new,
|
321
|
+
Arrow::Buffer.new(data.flatten.pack("d*")),
|
322
|
+
shape,
|
323
|
+
nil,
|
324
|
+
nil)
|
325
|
+
assert_equal(Numo::DFloat.new(shape).store(data),
|
326
|
+
tensor.to_narray)
|
327
|
+
end
|
264
328
|
end
|
265
329
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: red-arrow-numo-narray
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kouhei Sutou
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: red-arrow
|
@@ -127,6 +127,7 @@ files:
|
|
127
127
|
- doc/text/apache-2.0.txt
|
128
128
|
- doc/text/news.md
|
129
129
|
- lib/arrow-numo-narray.rb
|
130
|
+
- lib/arrow-numo-narray/error.rb
|
130
131
|
- lib/arrow-numo-narray/to-arrow.rb
|
131
132
|
- lib/arrow-numo-narray/to-narray.rb
|
132
133
|
- lib/arrow-numo-narray/version.rb
|
@@ -155,13 +156,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
156
|
version: '0'
|
156
157
|
requirements: []
|
157
158
|
rubyforge_project:
|
158
|
-
rubygems_version: 2.
|
159
|
+
rubygems_version: 2.7.6.2
|
159
160
|
signing_key:
|
160
161
|
specification_version: 4
|
161
162
|
summary: Red Arrow Numo::NArray is a library that provides converters between Apache
|
162
163
|
Arrow's tensor data (`Arrow::Tensor`) and Numo::NArray data.
|
163
164
|
test_files:
|
164
|
-
- test/test-to-narray.rb
|
165
|
-
- test/test-to-arrow.rb
|
166
165
|
- test/helper.rb
|
167
166
|
- test/run-test.rb
|
167
|
+
- test/test-to-arrow.rb
|
168
|
+
- test/test-to-narray.rb
|