pickle

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const HighestProtocol byte = 5 // The highest protocol number pickle currently knows how to read

Variables

View Source
var (
	MARK            rune = '(' // push special markobject on stack
	STOP            rune = '.' // every pickle ends with STOP
	POP             rune = '0' // discard topmost stack item
	POP_MARK        rune = '1' // discard stack top through topmost markobject
	DUP             rune = '2' // duplicate top stack item
	FLOAT           rune = 'F' // push float object; decimal string argument
	INT             rune = 'I' // push integer or bool; decimal string argument
	BININT          rune = 'J' // push four-byte signed int
	BININT1         rune = 'K' // push 1-byte unsigned int
	LONG            rune = 'L' // push long; decimal string argument
	BININT2         rune = 'M' // push 2-byte unsigned int
	NONE            rune = 'N' // push None
	PERSID          rune = 'P' // push persistent object; id is taken from string arg
	BINPERSID       rune = 'Q' //  "       "         "  ;  "  "   "     "  stack
	REDUCE          rune = 'R' // apply callable to argtuple, both on stack
	STRING          rune = 'S' // push string; NL-terminated string argument
	BINSTRING       rune = 'T' // push string; counted binary string argument
	SHORT_BINSTRING rune = 'U' //  "     "   ;    "      "       "      " < 256 bytes
	UNICODE         rune = 'V' // push Unicode string; raw-unicode-escaped'd argument
	BINUNICODE      rune = 'X' //   "     "       "  ; counted UTF-8 string argument
	APPEND          rune = 'a' // append stack top to list below it
	BUILD           rune = 'b' // call __setstate__ or __dict__.update()
	GLOBAL          rune = 'c' // push self.find_class(modname, name); 2 string args
	DICT            rune = 'd' // build a dict from stack items
	EMPTY_DICT      rune = '}' // push empty dict
	APPENDS         rune = 'e' // extend list on stack by topmost stack slice
	GET             rune = 'g' // push item from memo on stack; index is string arg
	BINGET          rune = 'h' //   "    "    "    "   "   "  ;   "    " 1-byte arg
	INST            rune = 'i' // build & push class instance
	LONG_BINGET     rune = 'j' // push item from memo on stack; index is 4-byte arg
	LIST            rune = 'l' // build list from topmost stack items
	EMPTY_LIST      rune = ']' // push empty list
	OBJ             rune = 'o' // build & push class instance
	PUT             rune = 'p' // store stack top in memo; index is string arg
	BINPUT          rune = 'q' //   "     "    "   "   " ;   "    " 1-byte arg
	LONG_BINPUT     rune = 'r' //   "     "    "   "   " ;   "    " 4-byte arg
	SETITEM         rune = 's' // add key+value pair to dict
	TUPLE           rune = 't' // build tuple from topmost stack items
	EMPTY_TUPLE     rune = ')' // push empty tuple
	SETITEMS        rune = 'u' // modify dict by adding topmost key+value pairs
	BINFLOAT        rune = 'G' // push float; arg is 8-byte float encoding

	PROTO    rune = '\x80' // identify pickle protocol
	NEWOBJ   rune = '\x81' // build object by applying cls.__new__ to argtuple
	EXT1     rune = '\x82' // push object from extension registry; 1-byte index
	EXT2     rune = '\x83' // ditto, but 2-byte index
	EXT4     rune = '\x84' // ditto, but 4-byte index
	TUPLE1   rune = '\x85' // build 1-tuple from stack top
	TUPLE2   rune = '\x86' // build 2-tuple from two topmost stack items
	TUPLE3   rune = '\x87' // build 3-tuple from three topmost stack items
	NEWTRUE  rune = '\x88' // push True
	NEWFALSE rune = '\x89' // push False
	LONG1    rune = '\x8a' // push long from < 256 bytes
	LONG4    rune = '\x8b' // push really big long

	BINBYTES       rune = 'B' // push bytes; counted binary string argument
	SHORT_BINBYTES rune = 'C' //  "     "   ;    "      "       "      " < 256 bytes

	SHORT_BINUNICODE rune = '\x8c' // push short string; UTF-8 length < 256 bytes
	BINUNICODE8      rune = '\x8d' // push very long string
	BINBYTES8        rune = '\x8e' // push very long bytes string
	EMPTY_SET        rune = '\x8f' // push empty set on the stack
	ADDITEMS         rune = '\x90' // modify set by adding topmost stack items
	FROZENSET        rune = '\x91' // build frozenset from topmost stack items
	NEWOBJ_EX        rune = '\x92' // like NEWOBJ but work with keyword only arguments
	STACK_GLOBAL     rune = '\x93' // same as GLOBAL but using names on the stacks
	MEMOIZE          rune = '\x94' // store top of the stack in memo
	FRAME            rune = '\x95' // indicate the beginning of a new frame

	BYTEARRAY8      rune = '\x96' // push bytearray
	NEXT_BUFFER     rune = '\x97' // push next out-of-band buffer
	READONLY_BUFFER rune = '\x98' // make top of stack readonly
)
View Source
var DefaultProtocol byte = 4 // The protocol pickle currently used to write by default.
View Source
var ErrInvalidMagicNumber = errors.New("invalid pytorch magic number")
View Source
var ErrInvalidProtocolVersion = errors.New("invalid pytorch protocol version")

Functions

func Decode

func Decode(filename string) (map[string]*ts.Tensor, error)

Decode decodes pickled data created by 'torch.save()' with Python Pytorch and rebuilds named tensor weights.

func Encode

func Encode(model ts.Module, outputFile string) error

Encode encodes model using pickling machinery. Output pickled model can be loads with Python Pytorch as `torch.load("pytorch_model.bin")`

TODO. implement pickling part so that model can be exported and load with Python Pytorch. See https://github.com/python/cpython/blob/b0de6299a840a397d4fe3e6c98159d9f258d3295/Lib/pickle.py#L407

func FloatBits16to32

func FloatBits16to32(u16 uint16) uint32

Converts the bits representation of a Half Float (16 bits) number to an IEEE 754 float representation (32 bits) From http://www.fox-toolkit.org/ftp/fasthalffloatconversion.pdf

func GetFunctionName

func GetFunctionName(i interface{}) string

func Load

func Load(filename string) (interface{}, error)

Load unpickles a pickled file.

func LoadAll

func LoadAll(vs *nn.VarStore, modelFile string) error

LoadAll finds and loads all weights from varstore. It will throw err if one of weights from varstore cannot find from loaded pretrained model.

func LoadPartial

func LoadPartial(vs *nn.VarStore, modelFile string) ([]string, error)

LoadPartial finds and loads weights for varstore. It returns list of unfound weight names.

func LoadWithUnpickler

func LoadWithUnpickler(filename string, newUnpickler func(r io.Reader) Unpickler) (interface{}, error)

LoadWithUnpickler is like Load, but it accepts a newUnpickler function which is used to create new customized pickle.Unpickler instances.

func Loads

func Loads(s string) (interface{}, error)

Loads unpicles a string.

Types

type BFloat16Storage

type BFloat16Storage struct {
	BaseStorage
	Data []half.BFloat16
}

func (*BFloat16Storage) DType

func (s *BFloat16Storage) DType() gotch.DType

func (*BFloat16Storage) Device

func (s *BFloat16Storage) Device() gotch.Device

func (*BFloat16Storage) GetData

func (s *BFloat16Storage) GetData() interface{}

func (*BFloat16Storage) SetFromFile

func (s *BFloat16Storage) SetFromFile(r io.Reader) error

func (*BFloat16Storage) SetFromFileWithSize

func (s *BFloat16Storage) SetFromFileWithSize(r io.Reader, size int) error

type BFloat16StorageClass

type BFloat16StorageClass struct{}

BFloat16Storage: ================

func (*BFloat16StorageClass) New

func (s *BFloat16StorageClass) New(size int, location string) Storage

type BaseStorage

type BaseStorage struct {
	Size     int
	Location string
}

BaseStorage represents a base storage.

type BoolStorage

type BoolStorage struct {
	BaseStorage
	Data []bool
}

func (*BoolStorage) DType

func (s *BoolStorage) DType() gotch.DType

func (*BoolStorage) Device

func (s *BoolStorage) Device() gotch.Device

func (*BoolStorage) GetData

func (s *BoolStorage) GetData() interface{}

func (*BoolStorage) SetFromFile

func (s *BoolStorage) SetFromFile(r io.Reader) error

func (*BoolStorage) SetFromFileWithSize

func (s *BoolStorage) SetFromFileWithSize(r io.Reader, size int) error

type BoolStorageClass

type BoolStorageClass struct{}

func (*BoolStorageClass) New

func (s *BoolStorageClass) New(size int, location string) Storage

type ByteArray

type ByteArray []byte

ByteArray simulates Python bytearray.

func NewByteArray

func NewByteArray() *ByteArray

func NewByteArrayFromSlice

func NewByteArrayFromSlice(slice []byte) *ByteArray

func (*ByteArray) Get

func (a *ByteArray) Get(i int) byte

func (*ByteArray) Len

func (a *ByteArray) Len() int

type ByteStorage

type ByteStorage struct {
	BaseStorage
	Data []uint8
}

func (*ByteStorage) DType

func (s *ByteStorage) DType() gotch.DType

func (*ByteStorage) Device

func (s *ByteStorage) Device() gotch.Device

func (*ByteStorage) GetData

func (s *ByteStorage) GetData() interface{}

func (*ByteStorage) SetFromFile

func (s *ByteStorage) SetFromFile(r io.Reader) error

func (*ByteStorage) SetFromFileWithSize

func (s *ByteStorage) SetFromFileWithSize(r io.Reader, size int) error

type ByteStorageClass

type ByteStorageClass struct{}

func (*ByteStorageClass) New

func (s *ByteStorageClass) New(size int, location string) Storage

type Callable

type Callable interface {
	// Call mimics a direct invocation on a Python value, such as a function
	// or class (constructor).
	Call(args ...interface{}) (interface{}, error)
}

Callable is implemented by any value that can be directly called to get a new value.

It is usually implemented by Python-like functions (returning a value given some arguments), or classes (typically returning an instance given some constructor arguments).

type CharStorage

type CharStorage struct {
	BaseStorage
	Data []int8
}

func (*CharStorage) DType

func (s *CharStorage) DType() gotch.DType

func (*CharStorage) Device

func (s *CharStorage) Device() gotch.Device

func (*CharStorage) GetData

func (s *CharStorage) GetData() interface{}

func (*CharStorage) SetFromFile

func (s *CharStorage) SetFromFile(r io.Reader) error

func (*CharStorage) SetFromFileWithSize

func (s *CharStorage) SetFromFileWithSize(r io.Reader, size int) error

type CharStorageClass

type CharStorageClass struct{}

func (*CharStorageClass) New

func (s *CharStorageClass) New(size int, location string) Storage

type Dict

type Dict []*DictEntry

Dict represents a Python "dict" (builtin type).

It is implemented as a slice, instead of a map, because in Go not all types can be map's keys (e.g. slices).

func NewDict

func NewDict() *Dict

NewDict makes and returns a new empty Dict.

func (*Dict) Get

func (d *Dict) Get(key interface{}) (interface{}, bool)

Get returns the value associated with the given key (if any), and whether the key is present or not.

func (*Dict) Len

func (d *Dict) Len() int

Len returns the length of the Dict, that is, the amount of key/value pairs contained by the Dict.

func (*Dict) MustGet

func (d *Dict) MustGet(key interface{}) interface{}

MustGet returns the value associated with the given key, if if it exists, otherwise it panics.

func (*Dict) Set

func (d *Dict) Set(key, value interface{})

Set sets into the Dict the given key/value pair.

type DictEntry

type DictEntry struct {
	Key   interface{}
	Value interface{}
}

type DictSetter

type DictSetter interface {
	Set(key, value interface{})
}

DictSetter is implemented by any value that exhibits a dict-like behaviour, allowing arbitrary key/value pairs to be set.

type DoubleStorage

type DoubleStorage struct {
	BaseStorage
	Data []float64
}

func (*DoubleStorage) DType

func (s *DoubleStorage) DType() gotch.DType

func (*DoubleStorage) Device

func (s *DoubleStorage) Device() gotch.Device

func (*DoubleStorage) GetData

func (s *DoubleStorage) GetData() interface{}

func (*DoubleStorage) SetFromFile

func (s *DoubleStorage) SetFromFile(r io.Reader) error

func (*DoubleStorage) SetFromFileWithSize

func (s *DoubleStorage) SetFromFileWithSize(r io.Reader, size int) error

type DoubleStorageClass

type DoubleStorageClass struct{}

func (*DoubleStorageClass) New

func (s *DoubleStorageClass) New(size int, location string) Storage

type FloatStorage

type FloatStorage struct {
	BaseStorage
	Data []float32
}

func (*FloatStorage) DType

func (s *FloatStorage) DType() gotch.DType

func (*FloatStorage) Device

func (s *FloatStorage) Device() gotch.Device

func (*FloatStorage) GetData

func (s *FloatStorage) GetData() interface{}

func (*FloatStorage) SetFromFile

func (s *FloatStorage) SetFromFile(r io.Reader) error

func (*FloatStorage) SetFromFileWithSize

func (s *FloatStorage) SetFromFileWithSize(r io.Reader, size int) error

type FloatStorageClass

type FloatStorageClass struct{}

func (*FloatStorageClass) New

func (s *FloatStorageClass) New(size int, location string) Storage

type FrozenSet

type FrozenSet map[interface{}]frozenSetEmptyStruct

FrozenSet represents a Python "frozenset" (builtin type).

It is implemented in Go as a map with empty struct values; the actual set of generic "interface{}" items is thus represented by all the keys.

func NewFrozenSetFromSlice

func NewFrozenSetFromSlice(slice []interface{}) *FrozenSet

NewFrozenSetFromSlice makes and returns a new FrozenSet initialized with the elements of the given slice.

func (*FrozenSet) Has

func (f *FrozenSet) Has(v interface{}) bool

Has returns whether the given value is present in the FrozenSet (true) or not (false).

func (*FrozenSet) Len

func (f *FrozenSet) Len() int

Len returns the length of the FrozenSet.

type GenericClass

type GenericClass struct {
	Module string
	Name   string
}

func NewGenericClass

func NewGenericClass(module, name string) *GenericClass

func (*GenericClass) PyNew

func (g *GenericClass) PyNew(args ...interface{}) (interface{}, error)

type GenericObject

type GenericObject struct {
	Class           *GenericClass
	ConstructorArgs []interface{}
}

type HalfStorage

type HalfStorage struct {
	BaseStorage
	// Data []float32
	Data []half.Float16
}

func (*HalfStorage) DType

func (s *HalfStorage) DType() gotch.DType

func (*HalfStorage) Device

func (s *HalfStorage) Device() gotch.Device

func (*HalfStorage) GetData

func (s *HalfStorage) GetData() interface{}

func (*HalfStorage) SetFromFile

func (s *HalfStorage) SetFromFile(r io.Reader) error

func (*HalfStorage) SetFromFileWithSize

func (s *HalfStorage) SetFromFileWithSize(r io.Reader, size int) error

type HalfStorageClass

type HalfStorageClass struct{}

func (*HalfStorageClass) New

func (s *HalfStorageClass) New(size int, location string) Storage

type IntStorage

type IntStorage struct {
	BaseStorage
	Data []int32
}

func (*IntStorage) DType

func (s *IntStorage) DType() gotch.DType

func (*IntStorage) Device

func (s *IntStorage) Device() gotch.Device

func (*IntStorage) GetData

func (s *IntStorage) GetData() interface{}

func (*IntStorage) SetFromFile

func (s *IntStorage) SetFromFile(r io.Reader) error

func (*IntStorage) SetFromFileWithSize

func (s *IntStorage) SetFromFileWithSize(r io.Reader, size int) error

type IntStorageClass

type IntStorageClass struct{}

func (*IntStorageClass) New

func (s *IntStorageClass) New(size int, location string) Storage

type LimitedBufferReader

type LimitedBufferReader struct {
	// contains filtered or unexported fields
}

func NewLimitedBufferReader

func NewLimitedBufferReader(
	r io.Reader,
	dataSize, scalarSize, bufferSize int,
) *LimitedBufferReader

func (*LimitedBufferReader) HasNext

func (br *LimitedBufferReader) HasNext() bool

func (*LimitedBufferReader) ReadNext

func (br *LimitedBufferReader) ReadNext() ([]byte, error)

type List

type List []interface{}

List represents a Python "list" (builtin type).

func NewList

func NewList() *List

NewList makes and returns a new empty List.

func NewListFromSlice

func NewListFromSlice(slice []interface{}) *List

NewListFromSlice makes and returns a new List initialized with the elements of the given slice.

The new List is a simple type cast of the input slice; the slice is _not_ copied.

func (*List) Append

func (l *List) Append(v interface{})

Append appends one element to the end of the List.

func (*List) Get

func (l *List) Get(i int) interface{}

Get returns the element of the List at the given index.

It panics if the index is out of range.

func (*List) Len

func (l *List) Len() int

Len returns the length of the List.

type ListAppender

type ListAppender interface {
	Append(v interface{})
}

ListAppender is implemented by any value that exhibits a list-like behaviour, allowing arbitrary values to be appended.

type LongStorage

type LongStorage struct {
	BaseStorage
	Data []int64
}

func (*LongStorage) DType

func (s *LongStorage) DType() gotch.DType

func (*LongStorage) Device

func (s *LongStorage) Device() gotch.Device

func (*LongStorage) GetData

func (s *LongStorage) GetData() interface{}

func (*LongStorage) SetFromFile

func (s *LongStorage) SetFromFile(r io.Reader) error

func (*LongStorage) SetFromFileWithSize

func (s *LongStorage) SetFromFileWithSize(r io.Reader, size int) error

type LongStorageClass

type LongStorageClass struct{}

func (*LongStorageClass) New

func (s *LongStorageClass) New(size int, location string) Storage

type ModelInfor

type ModelInfor struct {
	// contains filtered or unexported fields
}

func LoadModelInfo

func LoadModelInfo(modelFile string) (*ModelInfor, error)

LoadInfo loads pretrained weights and prints out name and shape of weights.

func NewModelInfor

func NewModelInfor(weights map[string][]int64, dtype gotch.DType) *ModelInfor

func (*ModelInfor) DType

func (m *ModelInfor) DType() gotch.DType

func (*ModelInfor) Parameters

func (m *ModelInfor) Parameters() int

func (*ModelInfor) String

func (m *ModelInfor) String() string

type ObjectClass

type ObjectClass struct{}

func (*ObjectClass) PyNew

func (o *ObjectClass) PyNew(args ...interface{}) (interface{}, error)

type OrderedDict

type OrderedDict struct {
	// Map associates a key of any type (interface{}) to OrderedDictEntry
	// pointer values. These values are shared with List.
	Map map[interface{}]*OrderedDictEntry
	// List is an ordered list of OrderedDictEntry pointers, which are
	// also shared with Map.
	List *list.List
	// PyDict represents Python "object.__dict__" dictionary of attributes.
	PyDict map[string]interface{}
}

OrderedDict is a minimal and trivial implementation of an ordered map, which represent a Python "collections.OrderedDict" object.

It is composed by a simple unordered Map, and a List to keep the order of the entries. The former is useful for direct key lookups, the latter for iteration.

func NewOrderedDict

func NewOrderedDict() *OrderedDict

NewOrderedDict makes and returns a new empty OrderedDict.

func (*OrderedDict) Get

func (o *OrderedDict) Get(k interface{}) (interface{}, bool)

Get returns the value associated with the given key (if any), and whether the key is present or not.

func (*OrderedDict) Len

func (o *OrderedDict) Len() int

Len returns the length of the OrderedDict, that is, the amount of key/value pairs contained by the OrderedDict.

func (*OrderedDict) MustGet

func (o *OrderedDict) MustGet(key interface{}) interface{}

MustGet returns the value associated with the given key, if if it exists, otherwise it panics.

func (*OrderedDict) PyDictSet

func (o *OrderedDict) PyDictSet(key, value interface{}) error

PyDictSet mimics the setting of a key/value pair on Python "__dict__" attribute of the OrderedDict.

func (*OrderedDict) Set

func (o *OrderedDict) Set(k, v interface{})

Set sets into the OrderedDict the given key/value pair. If the key does not exist yet, the new pair is positioned at the end (back) of the OrderedDict. If the key already exists, the existing associated value is replaced with the new one, and the original position is maintained.

type OrderedDictClass

type OrderedDictClass struct{}

OrderedDictClass represent Python "collections.OrderedDict" class.

This class allows the indirect creation of OrderedDict objects.

func (*OrderedDictClass) Call

func (*OrderedDictClass) Call(args ...interface{}) (interface{}, error)

Call returns a new empty OrderedDict. It is equivalent to Python constructor "collections.OrderedDict()".

No arguments are supported.

type OrderedDictEntry

type OrderedDictEntry struct {
	// Key of a single OrderedDict's entry.
	Key interface{}
	// Value of a single OrderedDict's entry.
	Value interface{}
	// ListElement is a pointer to the OrderedDict's List Element which
	// contains this very OrderedDictEntry.
	ListElement *list.Element
}

OrderedDictEntry is a single key/value pair stored in an OrderedDict.

A pointer to an OrderedDictEntry is always shared between OrderedDict's Map and List.

type PyAttrSettable

type PyAttrSettable interface {
	// PySetAttr mimics the setting of an arbitrary value to an object's
	// attribute.
	//
	// In Python this is done with "setattr" function, to which object,
	// attribute name, and value are passed. For an easy and clear
	// implementation, here instead we require this method to be implemented
	// on the "object" itself.
	//
	// See: https://docs.python.org/3/library/functions.html#setattr
	PySetAttr(key string, value interface{}) error
}

PyAttrSettable is implemented by any value on which an existing or new Python-like attribute can be set. In Python this is done with "setattr" builtin function.

type PyDictSettable

type PyDictSettable interface {
	// PyDictSet mimics the setting of a key/value pair on an object's
	//"__dict__" attribute.
	//
	// See: https://docs.python.org/3/library/stdtypes.html#object.__dict__
	PyDictSet(key, value interface{}) error
}

PyDictSettable is implemented by any value that can store dictionary-like key/value pairs. It reflects Python behavior of setting a key/value pair on an object's "__dict__" attribute.

type PyNewable

type PyNewable interface {
	// PyNew mimics Python invocation of the "__new__" method, usually
	// provided by classes.
	//
	// See: https://docs.python.org/3/reference/datamodel.html#object.__new__
	PyNew(args ...interface{}) (interface{}, error)
}

PyNewable is implemented by any value that has a Python-like "__new__" method.

It is usually implemented by values representing Python classes.

type PyStateSettable

type PyStateSettable interface {
	// PySetState mimics Python invocation of the "__setstate__" method.
	//
	// See: https://docs.python.org/3/library/pickle.html#object.__setstate__
	PySetState(state interface{}) error
}

PyStateSettable is implemented by any value that has a Python-like "__setstate__" method.

type RebuildDeviceTensorFromNumpy

type RebuildDeviceTensorFromNumpy struct{}

Rebuild Device Tensor From Numpy: ================================= Ref. https://github.com/pytorch/pytorch/blob/c2255c36ec121fdb998ce3db8deb7508c814b567/torch/_utils.py#L197

func (*RebuildDeviceTensorFromNumpy) Call

func (r *RebuildDeviceTensorFromNumpy) Call(args ...interface{}) (interface{}, error)

type RebuildMetaTensorNoStorage

type RebuildMetaTensorNoStorage struct{}

Rebuild Meta Tensor No Storage: =============================== Ref. https://github.com/pytorch/pytorch/blob/c2255c36ec121fdb998ce3db8deb7508c814b567/torch/_utils.py#L208

func (*RebuildMetaTensorNoStorage) Call

func (r *RebuildMetaTensorNoStorage) Call(args ...interface{}) (interface{}, error)

type RebuildParameter

type RebuildParameter struct{}

Rebuild Parameter: ================== RebuildTensor represents a struct to rebuild tensor back from pickle object. Ref. https://github.com/pytorch/pytorch/blob/c2255c36ec121fdb998ce3db8deb7508c814b567/torch/_utils.py#L240

func (*RebuildParameter) Call

func (r *RebuildParameter) Call(args ...interface{}) (interface{}, error)

type RebuildQtensor

type RebuildQtensor struct{}

Rebuild QTensor: ================ Ref. https://github.com/pytorch/pytorch/blob/c2255c36ec121fdb998ce3db8deb7508c814b567/torch/_utils.py#L214

func (*RebuildQtensor) Call

func (r *RebuildQtensor) Call(args ...interface{}) (interface{}, error)

type RebuildSparseCsrTensor

type RebuildSparseCsrTensor struct{}

Rebuild Sparse CSR Tensor: ========================== Ref. https://github.com/pytorch/pytorch/blob/c2255c36ec121fdb998ce3db8deb7508c814b567/torch/_utils.py#L187

func (*RebuildSparseCsrTensor) Call

func (r *RebuildSparseCsrTensor) Call(args ...interface{}) (interface{}, error)

type RebuildSparseTensor

type RebuildSparseTensor struct{}

Rebuild Sparse Tensor: ======================= ref. https://github.com/pytorch/pytorch/blob/c2255c36ec121fdb998ce3db8deb7508c814b567/torch/_utils.py#L178

func (*RebuildSparseTensor) Call

func (r *RebuildSparseTensor) Call(args ...interface{}) (interface{}, error)

type RebuildTensor

type RebuildTensor struct{}

func (*RebuildTensor) Call

func (r *RebuildTensor) Call(args ...interface{}) (interface{}, error)

type RebuildTensorV2

type RebuildTensorV2 struct{}

RebuildTensorV2 represents a struct to rebuild tensor back from pickle object.

func (*RebuildTensorV2) Call

func (r *RebuildTensorV2) Call(args ...interface{}) (interface{}, error)

type Reconstructor

type Reconstructor struct{}

func (*Reconstructor) Call

func (r *Reconstructor) Call(args ...interface{}) (interface{}, error)

type Set

type Set map[interface{}]setEmptyStruct

Set represents a Python "set" (builtin type).

It is implemented in Go as a map with empty struct values; the actual set of generic "interface{}" items is thus represented by all the keys.

func NewSet

func NewSet() *Set

NewSet makes and returns a new empty Set.

func NewSetFromSlice

func NewSetFromSlice(slice []interface{}) *Set

NewSetFromSlice makes and returns a new Set initialized with the elements of the given slice.

func (*Set) Add

func (s *Set) Add(v interface{})

Add adds one element to the Set.

func (*Set) Has

func (s *Set) Has(v interface{}) bool

Has returns whether the given value is present in the Set (true) or not (false).

func (*Set) Len

func (s *Set) Len() int

Len returns the length of the Set.

type SetAdder

type SetAdder interface {
	Add(v interface{})
}

SetAdder is implemented by any value that exhibits a set-like behaviour, allowing arbitrary values to be added.

type ShortStorage

type ShortStorage struct {
	BaseStorage
	Data []int16
}

func (*ShortStorage) DType

func (s *ShortStorage) DType() gotch.DType

func (*ShortStorage) Device

func (s *ShortStorage) Device() gotch.Device

func (*ShortStorage) GetData

func (s *ShortStorage) GetData() interface{}

func (*ShortStorage) SetFromFile

func (s *ShortStorage) SetFromFile(r io.Reader) error

func (*ShortStorage) SetFromFileWithSize

func (s *ShortStorage) SetFromFileWithSize(r io.Reader, size int) error

type ShortStorageClass

type ShortStorageClass struct{}

func (*ShortStorageClass) New

func (s *ShortStorageClass) New(size int, location string) Storage

type Stop

type Stop struct {
	// contains filtered or unexported fields
}

Stop implements error interface. It is raised by `Unpickler.LoadStop()` in response to the STOP opcode, passing the object that is the result of unpickling.

func (Stop) Error

func (s Stop) Error() string

type Storage

type Storage interface {
	SetFromFile(r io.Reader) error
	SetFromFileWithSize(r io.Reader, size int) error
	DType() gotch.DType
	GetData() interface{}
	Device() gotch.Device
}

Storage define Storage interface.

type StorageClass

type StorageClass interface {
	New(size int, location string) Storage
}

StorageClass defines interface for types to be used in Storage.

type StorageTensor

type StorageTensor struct {
	Source        Storage
	StorageOffset int64
	Size          []int64
	Stride        []int64
	RequiresGrad  bool
}

StorageTensor: ===============

type Tuple

type Tuple []interface{}

func NewTupleFromSlice

func NewTupleFromSlice(slice []interface{}) *Tuple

func (*Tuple) Get

func (t *Tuple) Get(i int) interface{}

func (*Tuple) Len

func (t *Tuple) Len() int

type Unpickler

type Unpickler struct {
	FindClass      func(module, name string) (interface{}, error) // function to determine data type
	PersistentLoad func(interface{}) (interface{}, error)         // function how to load pickled objects by its id.

	GetExtension     func(code int) (interface{}, error)
	NextBufferFunc   func() (interface{}, error)
	MakeReadOnlyFunc func(interface{}) (interface{}, error)
	// contains filtered or unexported fields
}

func NewUnpickler

func NewUnpickler(r io.Reader) Unpickler

NewUnpickler creates a new Unpickler.

func (*Unpickler) Load

func (up *Unpickler) Load() (interface{}, error)

Load decodes objects by loading through unpickling machinery.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL