pickle

package
v0.0.0-...-25d19a7 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseClass

func ParseClass(entity PythonClass, obj interface{}) (err error)

ParseClass calls PythonClass's Reduce and Build methods

Types

type Build

type Build struct {
	Object interface{}
	// Args are usually represented like Tuple (arguments for custom __setstate__) or Dict (class members)
	Args interface{}
}

Build is result of BUILD pickle command (usually class __setstate__ call)

type Decoder

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

Decoder implements decoding pickle file from `reader`. It reads op byte (pickle command), do command, push result in `machine` object. Main method is `Decode`

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder creates decoder from io.Reader

func (*Decoder) Decode

func (d *Decoder) Decode() (interface{}, error)

Decode reads pickle commands in loop and return top most result object on the machine's stack

type Dict

type Dict map[string]interface{}

Dict represents python's dict. For our purpose it's sufficient to have only string keys

type Global

type Global struct {
	Module string
	Name   string
}

Global is result of GLOBAL pickle command (usually class full name)

type List

type List []interface{}

List is python list

type None

type None struct{}

None is python None

type NumpyArrayRaw

type NumpyArrayRaw struct {
	Type  NumpyDType
	Shape []int
	// For plain data objects array data are stored in NumpyRawBytes
	Data NumpyRawBytes
	// But in case when data objects are python objects, they are parsed to []interface{}
	DataList []interface{}
}

NumpyArrayRaw represent numpy ndarray parsed from pickle

func (*NumpyArrayRaw) Build

func (a *NumpyArrayRaw) Build(build Build) (err error)

func (*NumpyArrayRaw) Reduce

func (a *NumpyArrayRaw) Reduce(reduce Reduce) (err error)

type NumpyDType

type NumpyDType struct {
	LittleEndinan bool
	Type          string
}

func (*NumpyDType) Build

func (d *NumpyDType) Build(build Build) error

func (*NumpyDType) Reduce

func (d *NumpyDType) Reduce(reduce Reduce) error

type NumpyElementFunc

type NumpyElementFunc func([]byte) error

type NumpyRawBytes

type NumpyRawBytes []byte

func (*NumpyRawBytes) Build

func (b *NumpyRawBytes) Build(build Build) (err error)

func (*NumpyRawBytes) Iterate

func (b *NumpyRawBytes) Iterate(length int, parse NumpyElementFunc) (err error)

Iterate iterates over bytes chunks of length `length` and call `parse` function on each

func (*NumpyRawBytes) Reduce

func (b *NumpyRawBytes) Reduce(reduce Reduce) (err error)

type NumpyScalarRaw

type NumpyScalarRaw struct {
	Type NumpyDType
	Data NumpyRawBytes
}

func (*NumpyScalarRaw) Build

func (s *NumpyScalarRaw) Build(build Build) (err error)

func (*NumpyScalarRaw) Reduce

func (s *NumpyScalarRaw) Reduce(reduce Reduce) (err error)

type PythonClass

type PythonClass interface {
	Reduce(reduce Reduce) error
	Build(build Build) error
}

PythonClass is interface to restore python class representation in Go struct. Pickle restore python classes in two steps: 1. REDUCE (like __init__ call). 2. BUILD (like __setstate__ call)

type Reduce

type Reduce struct {
	Callable interface{}
	Args     Tuple
}

Reduce is result of REDUCE pickle command (usually class __init__ call)

type SKlearnInitEstimator

type SKlearnInitEstimator struct {
	Name  string
	Prior []float64
}

func (*SKlearnInitEstimator) Build

func (e *SKlearnInitEstimator) Build(build Build) (err error)

func (*SKlearnInitEstimator) Reduce

func (e *SKlearnInitEstimator) Reduce(reduce Reduce) (err error)

type SklearnDecisionTreeRegressor

type SklearnDecisionTreeRegressor struct {
	Tree        SklearnTree
	NClasses    int
	MaxFeatures int
	NOutputs    int
}

func (*SklearnDecisionTreeRegressor) Build

func (t *SklearnDecisionTreeRegressor) Build(build Build) (err error)

func (*SklearnDecisionTreeRegressor) Reduce

func (t *SklearnDecisionTreeRegressor) Reduce(reduce Reduce) (err error)

type SklearnGradientBoosting

type SklearnGradientBoosting struct {
	NClasses      int
	Classes       []int
	NEstimators   int
	MaxFeatures   int
	Estimators    []SklearnDecisionTreeRegressor
	LearningRate  float64
	InitEstimator SKlearnInitEstimator
}

func (*SklearnGradientBoosting) Build

func (t *SklearnGradientBoosting) Build(build Build) (err error)

func (*SklearnGradientBoosting) Reduce

func (t *SklearnGradientBoosting) Reduce(reduce Reduce) (err error)

type SklearnNode

type SklearnNode struct {
	LeftChild            int
	RightChild           int
	Feature              int
	Threshold            float64
	Impurity             float64
	NNodeSamples         int
	WeightedNNodeSamples float64
}

SklearnNode represents tree node data structure

func SklearnNodeFromBytes

func SklearnNodeFromBytes(bytes []byte) SklearnNode

SklearnNodeFromBytes converts 56 raw bytes into SklearnNode struct The rule described in https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/tree/_tree.pyx#L70 (NODE_DTYPE) 'names': ['left_child', 'right_child', 'feature', 'threshold', 'impurity', 'n_node_samples', 'weighted_n_node_samples'], 'formats': [np.intp, np.intp, np.intp, np.float64, np.float64, np.intp, np.float64]

type SklearnTree

type SklearnTree struct {
	NOutputs int
	Classes  []int
	NNodes   int
	Nodes    []SklearnNode
	Values   []float64
}

SklearnTree represents parsed tree struct

func (*SklearnTree) Build

func (t *SklearnTree) Build(build Build) (err error)

func (*SklearnTree) Reduce

func (t *SklearnTree) Reduce(reduce Reduce) (err error)

type Tuple

type Tuple []interface{}

Tuple is python tuple

type Unicode

type Unicode []byte

Unicode represents strings in raw bytes format

Jump to

Keyboard shortcuts

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