class Arrow::Tensor

Public Instance Methods

to_pixbuf() click to toggle source
# File lib/arrow-gdk-pixbuf/to-pixbuf.rb, line 17
def to_pixbuf
  unless value_data_type.is_a?(UInt8DataType)
    message = "Arrow::UInt8DataType tensor is only convertable "
    message << "to GdkPixbuf::Pixbuf: #{value_data_type.inspect}"
    raise Error::Invalid.new(message)
  end
  if n_dimensions != 3
    message = "[height, width, n_channels] shape tensor is only convertable "
    message << "to GdkPixbuf::Pixbuf: #{shapes.inspect}"
    raise Error::Invalid.new(message)
  end
  height, width, n_channels = shape
  if n_channels != 3 and n_channels != 4
    message = "3 (RGB) or 4 (RGBA) channels tensor is only convertable "
    message << "to GdkPixbuf::Pixbuf: #{n_channels}"
    raise Error::Invalid.new(message)
  end
  if column_major?
    message = "Row major tensor is only  convertable "
    message << "to GdkPixbuf::Pixbuf for now"
    raise Error::NotImplemented.new(message)
  end
  data = buffer.data
  GdkPixbuf::Pixbuf.new(bytes: data,
                        width: width,
                        height: height,
                        has_alpha: n_channels == 4,
                        row_stride: data.size / height)
end