types

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package types defines types used in the Go bindings.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AtomFromHost

func AtomFromHost[T dtype.GoDataType](hostValue *values.HostArray) T

AtomFromHost returns an atom from a value stored on the host.

Types

type Array

type Array[T dtype.GoDataType] interface {
	Bridger

	Fetch() (*HostArray[T], error)

	Shape() *shape.Shape
}

Array managed by GX.

func NewArray

func NewArray[T dtype.GoDataType](arr values.Array) Array[T]

NewArray returns a new Go array bridge given a GX value of the same data type.

type ArrayBridge

type ArrayBridge interface {
	Bridge

	// Shape returns the shape of the array.
	Shape() *shape.Shape

	// ToDevice transfers the array to a device.
	ToDevice(*api.Device) (ArrayBridge, error)
}

ArrayBridge is a bridge value representing an array (or an atomic value).

type Atom

type Atom[T dtype.GoDataType] interface {
	Bridger

	// Fetch the value from the device to the host and returns a handle to the host value.
	Fetch() (*HostAtom[T], error)

	// FetchValue fetches the atom value from the device.
	FetchValue() (T, error)
}

Atom managed by GX.

func NewAtom

func NewAtom[T dtype.GoDataType](arr values.Array) Atom[T]

NewAtom returns a new Go atom bridge given a GX value of the same data type.

type Bridge

type Bridge interface {
	values.Valuer

	// Bridger returns the Go object owning the GX value.
	Bridger() Bridger
}

Bridge is implemented by all types used by the Go bindings. It provides the bridge between the Go instance and the GX value.

type Bridger

type Bridger interface {
	Bridge() Bridge
}

Bridger is able to return a Go-GX value bridge.

type DeviceArray

type DeviceArray[T dtype.GoDataType] struct {
	// contains filtered or unexported fields
}

DeviceArray is an array stored on a device.

func NewDeviceArray

func NewDeviceArray[T dtype.GoDataType](val *values.DeviceArray) *DeviceArray[T]

NewDeviceArray returns a new Go array given a device value managed by GX.

func (*DeviceArray) Bridge

func (bb *DeviceArray) Bridge() Bridge

Bridge between the Go value and the GX value.

func (*DeviceArray) Bridger

func (bb *DeviceArray) Bridger() Bridger

Bridger returns the Go value of the object.

func (*DeviceArray[T]) Fetch

func (array *DeviceArray[T]) Fetch() (*HostArray[T], error)

Fetch the value from the device.

func (*DeviceArray[T]) FetchWithAlloc

func (array *DeviceArray[T]) FetchWithAlloc(alloc platform.Allocator) (*HostArray[T], error)

FetchWithAlloc the value from the device given a specific allocator.

func (*DeviceArray) GXValue

func (bb *DeviceArray) GXValue() values.Value

GXValue returns the GX value storing the array data.

func (*DeviceArray[T]) Shape

func (array *DeviceArray[T]) Shape() *shape.Shape

Shape of the array.

func (*DeviceArray[T]) String

func (array *DeviceArray[T]) String() string

func (*DeviceArray) ToDevice

func (bb *DeviceArray) ToDevice(dev *api.Device) (ArrayBridge, error)

ToDevice transfers the array to a device.

type DeviceAtom

type DeviceAtom[T dtype.GoDataType] struct {
	// contains filtered or unexported fields
}

DeviceAtom is an array stored on a device.

func NewDeviceAtom

func NewDeviceAtom[T dtype.GoDataType](val *values.DeviceArray) *DeviceAtom[T]

NewDeviceAtom returns a new Go array given a device value managed by GX.

func (*DeviceAtom) Bridge

func (bb *DeviceAtom) Bridge() Bridge

Bridge between the Go value and the GX value.

func (*DeviceAtom) Bridger

func (bb *DeviceAtom) Bridger() Bridger

Bridger returns the Go value of the object.

func (*DeviceAtom[T]) Fetch

func (atom *DeviceAtom[T]) Fetch() (*HostAtom[T], error)

Fetch the value from the device.

func (*DeviceAtom[T]) FetchValue

func (atom *DeviceAtom[T]) FetchValue() (val T, err error)

FetchValue returns the atom value from the device.

func (*DeviceAtom[T]) FetchWithAlloc

func (atom *DeviceAtom[T]) FetchWithAlloc(alloc platform.Allocator) (*HostAtom[T], error)

FetchWithAlloc the value from the device given a specific allocator.

func (*DeviceAtom) GXValue

func (bb *DeviceAtom) GXValue() values.Value

GXValue returns the GX value storing the array data.

func (*DeviceAtom) Shape

func (bb *DeviceAtom) Shape() *shape.Shape

Shape of the array.

func (*DeviceAtom[T]) String

func (atom *DeviceAtom[T]) String() string

func (*DeviceAtom) ToDevice

func (bb *DeviceAtom) ToDevice(dev *api.Device) (ArrayBridge, error)

ToDevice transfers the array to a device.

type Factory

type Factory interface {
	New(ir.Type) (Bridge, error)
}

Factory creates instances given a type. Numerical types (atoms or arrays) are not supported.

type HostArray

type HostArray[T dtype.GoDataType] struct {
	// contains filtered or unexported fields
}

HostArray is an array stored on a host.

func ArrayBool

func ArrayBool(vals []bool, dims ...int) *HostArray[bool]

ArrayBool returns a new Go host array of bool.

func ArrayFloat32

func ArrayFloat32(vals []float32, dims ...int) *HostArray[float32]

ArrayFloat32 returns a new Go host array of float32.

func ArrayFloat64

func ArrayFloat64(vals []float64, dims ...int) *HostArray[float64]

ArrayFloat64 returns a new Go host array of float64.

func ArrayInt32

func ArrayInt32(vals []int32, dims ...int) *HostArray[int32]

ArrayInt32 returns a new Go host array of int32.

func ArrayInt64

func ArrayInt64(vals []int64, dims ...int) *HostArray[int64]

ArrayInt64 returns a new Go host array of int64.

func ArrayUint32

func ArrayUint32(vals []uint32, dims ...int) *HostArray[uint32]

ArrayUint32 returns a new Go host array of uint32.

func ArrayUint64

func ArrayUint64(vals []uint64, dims ...int) *HostArray[uint64]

ArrayUint64 returns a new Go host array of uint64.

func NewHostArray

func NewHostArray[T dtype.GoDataType](val *values.HostArray) *HostArray[T]

NewHostArray returns a new Go array given a device value managed by GX.

func (*HostArray) Bridge

func (bb *HostArray) Bridge() Bridge

Bridge between the Go value and the GX value.

func (*HostArray) Bridger

func (bb *HostArray) Bridger() Bridger

Bridger returns the Go value of the object.

func (*HostArray[T]) CopyFlat

func (array *HostArray[T]) CopyFlat() []T

CopyFlat makes a copy of the data and returns it as a flat representation of an array.

func (*HostArray[T]) Fetch

func (array *HostArray[T]) Fetch() (*HostArray[T], error)

Fetch the value to the host.

func (*HostArray) GXValue

func (bb *HostArray) GXValue() values.Value

GXValue returns the GX value storing the array data.

func (*HostArray[T]) Shape

func (array *HostArray[T]) Shape() *shape.Shape

Shape of the array.

func (*HostArray[T]) String

func (array *HostArray[T]) String() string

func (*HostArray) ToDevice

func (bb *HostArray) ToDevice(dev *api.Device) (ArrayBridge, error)

ToDevice transfers the array to a device.

type HostAtom

type HostAtom[T dtype.GoDataType] struct {
	// contains filtered or unexported fields
}

HostAtom is an array stored on a host.

func Bool

func Bool(val bool) *HostAtom[bool]

Bool returns a new Go host atom of bool.

func DefaultInt

func DefaultInt(val ir.Int) *HostAtom[ir.Int]

DefaultInt returns a new Go host atom of int32.

func Float32

func Float32(val float32) *HostAtom[float32]

Float32 returns a new Go host atom of float32.

func Float64

func Float64(val float64) *HostAtom[float64]

Float64 returns a new Go host atom of float64.

func Int32

func Int32(val int32) *HostAtom[int32]

Int32 returns a new Go host atom of int32.

func Int64

func Int64(val int64) *HostAtom[int64]

Int64 returns a new Go host atom of int64.

func NewHostAtom

func NewHostAtom[T dtype.GoDataType](val *values.HostArray) *HostAtom[T]

NewHostAtom returns a new Go array given a device value managed by GX.

func Uint32

func Uint32(val uint32) *HostAtom[uint32]

Uint32 returns a new Go host atom of uint32.

func Uint64

func Uint64(val uint64) *HostAtom[uint64]

Uint64 returns a new Go host atom of uint64.

func (*HostAtom) Bridge

func (bb *HostAtom) Bridge() Bridge

Bridge between the Go value and the GX value.

func (*HostAtom) Bridger

func (bb *HostAtom) Bridger() Bridger

Bridger returns the Go value of the object.

func (*HostAtom[T]) Fetch

func (atom *HostAtom[T]) Fetch() (*HostAtom[T], error)

Fetch the value to the host.

func (*HostAtom[T]) FetchValue

func (atom *HostAtom[T]) FetchValue() (val T, err error)

FetchValue returns the atom value from the device.

func (*HostAtom) GXValue

func (bb *HostAtom) GXValue() values.Value

GXValue returns the GX value storing the array data.

func (*HostAtom[T]) SendTo

func (atom *HostAtom[T]) SendTo(dev *api.Device) (*DeviceAtom[T], error)

SendTo sends the value to a device.

func (*HostAtom) Shape

func (bb *HostAtom) Shape() *shape.Shape

Shape of the array.

func (*HostAtom[T]) String

func (atom *HostAtom[T]) String() string

func (*HostAtom) ToDevice

func (bb *HostAtom) ToDevice(dev *api.Device) (ArrayBridge, error)

ToDevice transfers the array to a device.

func (*HostAtom[T]) Value

func (atom *HostAtom[T]) Value() T

Value of the atom.

type Slice

type Slice[T Bridger] struct {
	// contains filtered or unexported fields
}

Slice of Go instances.

func NewEmptySlice

func NewEmptySlice[T Bridger](typ ir.Type, factory func() (Bridge, error)) (*Slice[T], error)

NewEmptySlice creates an empty slice that will be allocated later.

func NewSlice

func NewSlice[T Bridger](typ ir.Type, vals []T) (*Slice[T], error)

NewSlice returns a new slice storing data on a device.

func (*Slice[T]) At

func (s *Slice[T]) At(i int) T

At returns the element at the ith position.

func (*Slice[T]) Bridge

func (s *Slice[T]) Bridge() Bridge

Bridge returns the bridge of the slice.

func (*Slice[T]) Size

func (s *Slice[T]) Size() int

Size of the slice.

func (*Slice[T]) String

func (s *Slice[T]) String() string

type SliceBridge

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

SliceBridge is the bridge between Go and GX values for a slice.

func (*SliceBridge) Allocate

func (b *SliceBridge) Allocate(size int)

Allocate the slice to a given number of elements.

func (*SliceBridge) Bridger

func (b *SliceBridge) Bridger() Bridger

Bridger returns the Go value of the slice.

func (*SliceBridge) DType

func (b *SliceBridge) DType() ir.Type

DType returns the data type of the slice.

func (*SliceBridge) GXValue

func (b *SliceBridge) GXValue() values.Value

GXValue returns the underlying GX value.

func (*SliceBridge) Get

func (b *SliceBridge) Get(i int) Bridge

Get returns the value of the ith position.

func (*SliceBridge) Set

func (b *SliceBridge) Set(i int, el Bridge) error

Set an element in the slice. The slice needs to have been pre-allocated before.

type StructBridge

type StructBridge interface {
	Bridge

	// StructValue returns the GX value of the structure.
	StructValue() *values.Struct

	// NewFromField returns a new instance of the type defined by the field of the structure.
	// An error is returned if the field does not belong to the structure.
	NewFromField(field *ir.Field) (Bridge, error)

	// SetField sets a field with a value.
	// An error is returns if the value cannot be casted to the field type.
	SetField(field *ir.Field, val Bridge) error
}

StructBridge is a bridge for a structure.

Jump to

Keyboard shortcuts

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