torch_internal

package
v0.0.0-...-8e0162c Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FlattenSlice

func FlattenSlice(slc interface{}, kind reflect.Kind) unsafe.Pointer

Flatten a slice of the given kind to a 1-dimensional buffer of contiguous data. The input is expected to be an n-dimensional slice of data and the output is the `Data` buffer of the flattened representation of the input.

https://medium.com/@the1mills/flattening-arrays-slices-with-golang-c796905debbe provides a way to flatten any recursive slices into []interface{}. However, we cannot reuse this solution here, because libtorch wants []float32/float64/..., instead of []interface{}. Without type template as that in C++, we have to write the following Go switch over types.

func GetSizesAndKindOfSlice

func GetSizesAndKindOfSlice(data interface{}) ([]int64, reflect.Kind)

Extract the shape and data-type of a slice. Returns a tuple of the shape of the tensor-like data structure, and the kind of the elements contained by the tensor-like structure.

func MockCException

func MockCException(message string) unsafe.Pointer

Create a mock C error with a message. We intentionally do not defer the freeing of the C-string to mock the functionality of the C interface that will transfer ownership of non-nil pointer returns to the caller.

func NewTorchError

func NewTorchError(err unsafe.Pointer) error

@brief Create a new error from a verified char*. @param err The char* that is guaranteed to not be nil. @returns The formatted error structure. @details The input `err` is expected to be a valid char* that is managed by the Golang context. When the string is copied, it will be freed using Cgo.

func PanicOnCException

func PanicOnCException(err unsafe.Pointer)

Panic if a system error is caught in the error buffer. @param error A *C.Char to an error string that may be nil.

Types

This section is empty.

Jump to

Keyboard shortcuts

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