Method: Numpy.to_na

Defined in:
lib/dnn/numo2numpy.rb

.to_na(ndarray) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/dnn/numo2numpy.rb', line 44

def self.to_na(ndarray)
  shape = ndarray.shape
  bin = ndarray.flatten.tobytes
  case ndarray.dtype.to_s
  when "int8"
    Numo::Int8.from_binary(bin).reshape(*shape)
  when "uint8"
    Numo::UInt8.from_binary(bin).reshape(*shape)
  when "int16"
    Numo::Int16.from_binary(bin).reshape(*shape)
  when "uint16"
    Numo::UInt16.from_binary(bin).reshape(*shape)
  when "int32"
    Numo::Int32.from_binary(bin).reshape(*shape)
  when "uint32"
    Numo::UInt32.from_binary(bin).reshape(*shape)
  when "int64"
    Numo::Int64.from_binary(bin).reshape(*shape)
  when "uint64"
    Numo::UInt64.from_binary(bin).reshape(*shape)
  when "float32"
    Numo::SFloat.from_binary(bin).reshape(*shape)
  when "float64"
    Numo::DFloat.from_binary(bin).reshape(*shape)
  else
    raise NumpyToNumoError.new("#{ndarray.dtype} is not support convert.")
  end
end