Module: NDAV::OrtValue

Defined in:
lib/ndav/ort_value.rb

Defined Under Namespace

Modules: Converter, FromNDAV, MemoryViewable

Constant Summary collapse

TYPE_TO_FORMAT =
{
  int8: "c",
  uint8: "C",
  int16: "s",
  uint16: "S",
  int32: "l",
  uint32: "L",
  int64: "q",
  uint64: "Q",
  float: "f",
  double: "d"
}
FORMAT_TO_TYPE =
::NDAV::ITEM_SIZES.to_h {|format, size|
  suffix = size * 8
  type = case format
         when "s!", "c", "s", "l", "q", "i", "i!", "l!", "q!"
           :"int#{suffix}"
         when "S!", "C", "S", "L", "Q", "I", "I!", "L!", "Q!"
           :"uint#{suffix}"
         when "f"
           :float
         when "d"
           :double
         else
           case IO::Buffer::HOST_ENDIAN
           when IO::Buffer::LITTLE_ENDIAN
             case format
             when "v"
               :uint16
             when "V"
               :uint32
             when "e"
               :float
             when "E"
               :double
             end
           when IO::Buffer::BIG_ENDIAN
             case format
             when "n"
               :uint16
             when "N"
               :uint32
             when "g"
               :float
             when "G"
               :double
             end
           end
         end
  [format, type]
}
TYPE_SIZES =
TYPE_TO_FORMAT.transform_values {|format| ::NDAV::ITEM_SIZES[format]}