Module: NDAV::Numo::NArray::FromNDAV

Defined in:
lib/ndav/numo/narray.rb

Instance Method Summary collapse

Instance Method Details

#from_ndav(ndav) ⇒ Object

Raises:

  • (ArgumentError)


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/ndav/numo/narray.rb', line 78

def from_ndav(ndav)
  format = ndav.format
  cls = FORMAT_TO_CLASS[format]
  raise ArgumentError, "unsupported format: #{format}, currently supported: #{FORMAT_TO_CLASS.keys}" unless cls

  shape = ndav.shape
  if ndav.row_major_contiguous?
    cls.from_binary(ndav.to_s, shape)
  elsif ndav.column_major_contiguous?
    cls.from_binary(ndav.to_s, shape.reverse).transpose
  else
    # TODO: Allocate enough memory, know that size, pass binary to from_binary, and reshape and restrides
    raise "Currently, non-contiguous NDAV not supported"
  end
end