Module: NDAV::Torch::Tensor

Defined in:
lib/ndav/torch/tensor.rb

Defined Under Namespace

Modules: Converter, MemoryViewable

Constant Summary collapse

TYPE_TO_FORMAT =
{
  int8: "c",
  uint8: "C",
  int16: "s",
  uint16: "S",
  int32: "l",
  uint32: "L",
  int64: "q",
  uint64: "Q",
  float32: "f",
  float64: "d"
}
FORMAT_TO_TYPE =
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", "d"
           :"float#{suffix}"
         else
           case IO::Buffer::HOST_ENDIAN
           when IO::Buffer::LITTLE_ENDIAN
             if ["v", "V", "e", "E"].include? format
               :"float#{suffix}"
             end
           when IO::Buffer::BIG_ENDIAN
             if ["n", "N", "g", "G"].include? format
               :"float#{suffix}"
             end
           end
         end
  [format, type]
}
TYPE_SIZES =
TYPE_TO_FORMAT.transform_values {|format| ITEM_SIZES[format]}