red-arrow-numo-narray 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/doc/text/news.md +11 -0
- data/lib/arrow-numo-narray/to-narray.rb +16 -0
- data/lib/arrow-numo-narray/version.rb +1 -1
- data/test/test-to-narray.rb +101 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a484511f7152fa12df7cc0b356f775c70462b977e0783e5c9d4552f2a1beda7
|
4
|
+
data.tar.gz: d569a6d94ba32eb1893d9bc465a2f386ffbc91b7edff0a945bb9bcb2ddf786d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc715d39ee68ffc7e68ffed95b0b89badc85b83bb37ae7586443d6cd4896c5b823b89bdf5f9128253dc1a65b306db947fb80a0fbddd501b92bc1a3319e339679
|
7
|
+
data.tar.gz: 94cf907a219e1623314b48463ea70676995b1661a9f301bc6362970e214f0fd519cf2f2c2dc1d85258b13a5b42a3d102c33db24a0ea817a73a68c2ed51307240
|
data/doc/text/news.md
CHANGED
@@ -85,6 +85,22 @@ module Arrow
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
+
class ChunkedArray
|
89
|
+
def to_narray
|
90
|
+
unless n_nulls.zero?
|
91
|
+
message = "can't convert #{self.class} that has null values to NArray"
|
92
|
+
raise ArrowNumoNArray::UnconvertibleError, message
|
93
|
+
end
|
94
|
+
narray = value_data_type.narray_class.new(length)
|
95
|
+
data = ""
|
96
|
+
chunks.each do |chunk|
|
97
|
+
data << chunk.buffer.data.to_s
|
98
|
+
end
|
99
|
+
narray.store_binary(data)
|
100
|
+
narray
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
88
104
|
class Tensor
|
89
105
|
def to_narray
|
90
106
|
narray = value_data_type.narray_class.new(shape)
|
data/test/test-to-narray.rb
CHANGED
@@ -83,6 +83,107 @@ class ToNAarrayTest < Test::Unit::TestCase
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
+
sub_test_case("ChunkedArray") do
|
87
|
+
test("with NULL") do
|
88
|
+
chunked_array = Arrow::ChunkedArray.new([Arrow::Int8Array.new([0, nil])])
|
89
|
+
message =
|
90
|
+
"can't convert #{chunked_array.class} that has null values to NArray"
|
91
|
+
assert_raise(ArrowNumoNArray::UnconvertibleError.new(message)) do
|
92
|
+
chunked_array.to_narray
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
test("Int8") do
|
97
|
+
arrays = [
|
98
|
+
Arrow::Int8Array.new([-(2 ** 7), 0]),
|
99
|
+
Arrow::Int8Array.new([2 ** 7 - 1]),
|
100
|
+
]
|
101
|
+
assert_equal(Numo::Int8[-(2 ** 7), 0, 2 ** 7 - 1],
|
102
|
+
Arrow::ChunkedArray.new(arrays).to_narray)
|
103
|
+
end
|
104
|
+
|
105
|
+
test("Int16") do
|
106
|
+
arrays = [
|
107
|
+
Arrow::Int16Array.new([-(2 ** 15), 0]),
|
108
|
+
Arrow::Int16Array.new([2 ** 15 - 1]),
|
109
|
+
]
|
110
|
+
assert_equal(Numo::Int16[-(2 ** 15), 0, 2 ** 15 - 1],
|
111
|
+
Arrow::ChunkedArray.new(arrays).to_narray)
|
112
|
+
end
|
113
|
+
|
114
|
+
test("Int32") do
|
115
|
+
arrays = [
|
116
|
+
Arrow::Int32Array.new([-(2 ** 31), 0]),
|
117
|
+
Arrow::Int32Array.new([2 ** 31 - 1]),
|
118
|
+
]
|
119
|
+
assert_equal(Numo::Int32[-(2 ** 31), 0, 2 ** 31 - 1],
|
120
|
+
Arrow::ChunkedArray.new(arrays).to_narray)
|
121
|
+
end
|
122
|
+
|
123
|
+
test("Int64") do
|
124
|
+
arrays = [
|
125
|
+
Arrow::Int64Array.new([-(2 ** 63), 0]),
|
126
|
+
Arrow::Int64Array.new([2 ** 63 - 1]),
|
127
|
+
]
|
128
|
+
assert_equal(Numo::Int64[-(2 ** 63), 0, 2 ** 63 - 1],
|
129
|
+
Arrow::ChunkedArray.new(arrays).to_narray)
|
130
|
+
end
|
131
|
+
|
132
|
+
test("UInt8") do
|
133
|
+
arrays = [
|
134
|
+
Arrow::UInt8Array.new([0]),
|
135
|
+
Arrow::UInt8Array.new([2 ** 8 - 1]),
|
136
|
+
]
|
137
|
+
assert_equal(Numo::UInt8[0, 2 ** 8 - 1],
|
138
|
+
Arrow::ChunkedArray.new(arrays).to_narray)
|
139
|
+
end
|
140
|
+
|
141
|
+
test("UInt16") do
|
142
|
+
arrays = [
|
143
|
+
Arrow::UInt16Array.new([0]),
|
144
|
+
Arrow::UInt16Array.new([2 ** 16 - 1]),
|
145
|
+
]
|
146
|
+
assert_equal(Numo::UInt16[0, 2 ** 16 - 1],
|
147
|
+
Arrow::ChunkedArray.new(arrays).to_narray)
|
148
|
+
end
|
149
|
+
|
150
|
+
test("UInt32") do
|
151
|
+
arrays = [
|
152
|
+
Arrow::UInt32Array.new([0]),
|
153
|
+
Arrow::UInt32Array.new([2 ** 32 - 1]),
|
154
|
+
]
|
155
|
+
assert_equal(Numo::UInt32[0, 2 ** 32 - 1],
|
156
|
+
Arrow::ChunkedArray.new(arrays).to_narray)
|
157
|
+
end
|
158
|
+
|
159
|
+
test("UInt64") do
|
160
|
+
arrays = [
|
161
|
+
Arrow::UInt64Array.new([0]),
|
162
|
+
Arrow::UInt64Array.new([2 ** 64 - 1]),
|
163
|
+
]
|
164
|
+
assert_equal(Numo::UInt64[0, 2 ** 64 - 1],
|
165
|
+
Arrow::ChunkedArray.new(arrays).to_narray)
|
166
|
+
end
|
167
|
+
|
168
|
+
test("Float") do
|
169
|
+
arrays = [
|
170
|
+
Arrow::FloatArray.new([-1.1, 0]),
|
171
|
+
Arrow::FloatArray.new([1.1]),
|
172
|
+
]
|
173
|
+
assert_equal(Numo::SFloat[-1.1, 0, 1.1],
|
174
|
+
Arrow::ChunkedArray.new(arrays).to_narray)
|
175
|
+
end
|
176
|
+
|
177
|
+
test("Double") do
|
178
|
+
arrays = [
|
179
|
+
Arrow::DoubleArray.new([-1.1, 0]),
|
180
|
+
Arrow::DoubleArray.new([1.1]),
|
181
|
+
]
|
182
|
+
assert_equal(Numo::DFloat[-1.1, 0, 1.1],
|
183
|
+
Arrow::ChunkedArray.new(arrays).to_narray)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
86
187
|
sub_test_case("Tensor") do
|
87
188
|
test("Int8") do
|
88
189
|
data = [
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kouhei Sutou
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: red-arrow
|