Module: NDAV::Numo::NArray::MemoryViewable

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

Instance Method Summary collapse

Instance Method Details

#ndav_descriptor(writable: false, column_major: false) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/ndav/numo/narray.rb', line 96

def ndav_descriptor(writable: false, column_major: false, **)
  format = CLASS_TO_FORMAT[self.class]
  unless format
    warn "unsupported class: #{self.class}, currently supported: #{CLASS_TO_FORMAT.keys}"
    return false
  end

  ptr = writable ? ::NDAV::Numo::NArray.pointer_for_write(self) :
                   ::NDAV::Numo::NArray.pointer_for_read(self)
  {
    data: ptr,
    shape:,
    strides: ::NDAV::Numo::NArray.strides(self) || ::NDAV.default_strides(shape:, item_size: ITEM_SIZES[format], row_major: !column_major),
    format:,
    byte_size:,
    readonly?: !writable,
    sub_offsets: nil
  }
end