15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/dnn/numo2numpy.rb', line 15
def self.from_na(narray)
bin = narray.to_binary
bin.force_encoding("ASCII-8BIT")
case
when narray.is_a?(Numo::Int8)
Numpy.frombuffer(bin, dtype: "int8").reshape(*narray.shape)
when narray.is_a?(Numo::UInt8)
Numpy.frombuffer(bin, dtype: "uint8").reshape(*narray.shape)
when narray.is_a?(Numo::Int16)
Numpy.frombuffer(bin, dtype: "int16").reshape(*narray.shape)
when narray.is_a?(Numo::UInt16)
Numpy.frombuffer(bin, dtype: "uint16").reshape(*narray.shape)
when narray.is_a?(Numo::Int32)
Numpy.frombuffer(bin, dtype: "int32").reshape(*narray.shape)
when narray.is_a?(Numo::UInt32)
Numpy.frombuffer(bin, dtype: "uint32").reshape(*narray.shape)
when narray.is_a?(Numo::Int64)
Numpy.frombuffer(bin, dtype: "int64").reshape(*narray.shape)
when narray.is_a?(Numo::UInt64)
Numpy.frombuffer(bin, dtype: "uint64").reshape(*narray.shape)
when narray.is_a?(Numo::SFloat)
Numpy.frombuffer(bin, dtype: "float32").reshape(*narray.shape)
when narray.is_a?(Numo::DFloat)
Numpy.frombuffer(bin, dtype: "float64").reshape(*narray.shape)
else
raise NumpyToNumoError.new("#{narray.class.name} is not support convert.")
end
end
|