nimxla/shape

Source   Edit  

The shape module wraps the XLA Shape type which holds the information on the data layout for any host or device buffers.

Types

DataType = enum
  InvalidType, Bool, I8, I16, I32, I64, U8, U16, U32, U64, F16, F32, F64, Tuple,
  OpaqueType, C64, BF16, Token, C128
DataType lists all of the XLA data types. Source   Edit  
ElemType = float32 or float64 or int64 or int32 or uint8 or bool
Allowed types for native nim Tensors Source   Edit  
Opt2d = int or (int, int)
Source   Edit  
Opt3d = int or (int, int, int)
Source   Edit  
Padding = object
  lo*: int
  hi*: int
  same*: bool
Source   Edit  
Shape = object
  case kind*: ShapeKind
  of ArrayKind:
      dtype*: DataType
      dims*: seq[int]

  of TupleKind:
      elems*: seq[Shape]

  
A shape is gives the data type and dimensions either for a single tensor or for a tuple of tensors which might be returned from XLA. Source   Edit  
ShapeKind = enum
  ArrayKind, TupleKind
Source   Edit  

Consts

padSame: Padding = (lo: 0, hi: 0, same: true)
Padding such that output matches the input. Source   Edit  

Procs

proc `$`(p: Padding): string {....raises: [ValueError], tags: [], forbids: [].}
Source   Edit  
proc `$`(s: Shape): string {....raises: [Exception], tags: [RootEffect],
                             forbids: [].}
Pretty print shape info. Will recursively generate list of shapes for tuples. Source   Edit  
func `==`(s1, s2: Shape): bool {....raises: [Exception], tags: [RootEffect],
                                 forbids: [].}
Have same data type and dimensions? Source   Edit  
proc arrayShape(dtype: DataType; dims: varargs[int]): Shape {....raises: [],
    tags: [], forbids: [].}
Create a shape for an nd array. Source   Edit  
proc dtypeOf(T: typedesc[ElemType]): DataType
Map from supported tensor types to XLA element type enumeration. Source   Edit  
proc pad(lo, hi: int): Padding {....raises: [], tags: [], forbids: [].}
Padding with given low and high values. Source   Edit  
proc pad(val: int): Padding {....raises: [], tags: [], forbids: [].}
Padding with low and high values set to val. Source   Edit  
proc seq2(opt: Opt2d): seq[int]
Source   Edit  
proc seq2(opt: Pad2d): seq[Padding]
Source   Edit  
proc seq3(opt: Opt3d): seq[int]
Source   Edit  
proc seq3(opt: Pad3d): seq[Padding]
Source   Edit  
proc toShape(s: shape_t; topLevel = true): Shape {....raises: [], tags: [],
    forbids: [].}
Unpack the raw shape_t returned by the xla wrapper. Source   Edit