values

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2025 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Overview

Package values implements all values that GX can represent.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToAtom

func ToAtom[T dtype.GoDataType](a *HostArray) (T, error)

ToAtom converts an array on the host into a Go atom value.

func ToElements added in v0.3.0

func ToElements(vals []Value) []ir.Element

ToElements converts a slice of values into a slice of elements.

Types

type Array

type Array interface {
	Value

	// Handle to the data.
	Handle() platform.Handle

	// Type returns the GX type of the array.
	Type() ir.Type

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

	// ToDevice transfers the array to a device.
	// It is a no-op if the data is already on the device.
	ToDevice(dev platform.Device) (*DeviceArray, error)

	// ToHostArray transfers the array on the host if it is not already.
	// Use the Go allocator.
	ToHostArray(alloc platform.Allocator) (*HostArray, error)
}

Array is an array value (also includes atomic).

func AtomNumberFloat

func AtomNumberFloat(x *big.Float, typ ir.Type) (Array, error)

AtomNumberFloat evaluates a big integer number into a GX array value.

type DeviceArray

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

DeviceArray managed by GX where the data is on a device.

func NewDeviceArray

func NewDeviceArray(typ ir.Type, handle platform.DeviceHandle) (*DeviceArray, error)

NewDeviceArray returns a new array managed by GX.

func (*DeviceArray) DeviceHandle

func (a *DeviceArray) DeviceHandle() platform.DeviceHandle

DeviceHandle returns the handle pointing to the data on the device.

func (*DeviceArray) Handle

func (a *DeviceArray) Handle() platform.Handle

Handle to the data.

func (*DeviceArray) Shape

func (a *DeviceArray) Shape() *shape.Shape

Shape of the array.

func (*DeviceArray) String

func (a *DeviceArray) String() string

String representation of the array.

func (*DeviceArray) ToDevice

func (a *DeviceArray) ToDevice(dev platform.Device) (*DeviceArray, error)

ToDevice transfers the data to a device. It is a no-op if the data is already on the device.

func (*DeviceArray) ToHost

func (a *DeviceArray) ToHost(alloc platform.Allocator) (Value, error)

ToHost transfers the value to the host.

func (*DeviceArray) ToHostArray

func (a *DeviceArray) ToHostArray(alloc platform.Allocator) (*HostArray, error)

ToHostArray transfers the array to the host using the Go allocator.

func (*DeviceArray) Type

func (a *DeviceArray) Type() ir.Type

Type of the array.

type FuncInputs added in v0.3.0

type FuncInputs struct {
	// Receiver on which the function call was done.
	// Can be nil.
	Receiver ir.Element

	// Args returns list of arguments passed to the interpreter at call time.
	Args []ir.Element
}

FuncInputs are GX values passed to the function call.

type HostArray

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

HostArray managed by GX where the data is on a device.

func ArrayBfloat16Value

func ArrayBfloat16Value(typ ir.Type, vals []dtype.Bfloat16T, dims []int) (*HostArray, error)

ArrayBfloat16Value returns an array GX value given a Go value.

func ArrayBoolValue

func ArrayBoolValue(typ ir.Type, vals []bool, dims []int) (*HostArray, error)

ArrayBoolValue returns an array GX value given a boolean value.

func ArrayFloatValue

func ArrayFloatValue[T dtype.Float](typ ir.Type, vals []T, dims []int) (*HostArray, error)

ArrayFloatValue returns an array GX value given a Go value.

func ArrayIntegerValue

func ArrayIntegerValue[T dtype.IntegerType](typ ir.Type, vals []T, dims []int) (*HostArray, error)

ArrayIntegerValue returns an array GX value given a Go value.

func AtomBfloat16Value

func AtomBfloat16Value(typ ir.Type, val dtype.Bfloat16T) (*HostArray, error)

AtomBfloat16Value returns an array GX value given a Go value.

func AtomBoolValue

func AtomBoolValue(typ ir.Type, val bool) (*HostArray, error)

AtomBoolValue returns an array GX value given a boolean value.

func AtomFloatValue

func AtomFloatValue[T dtype.Float](typ ir.Type, val T) (*HostArray, error)

AtomFloatValue returns an array GX value given a Go value.

func AtomIntegerValue

func AtomIntegerValue[T dtype.IntegerType](typ ir.Type, val T) (*HostArray, error)

AtomIntegerValue returns an array GX value given a Go value.

func AtomNumberInt

func AtomNumberInt(x *big.Int, typ ir.Type) (*HostArray, error)

AtomNumberInt evaluates a big integer number into a GX array value.

func NewHostArray

func NewHostArray(typ ir.Type, handle platform.HostBuffer) (*HostArray, error)

NewHostArray returns a new array managed by GX.

func (*HostArray) Buffer

func (a *HostArray) Buffer() platform.HostBuffer

Buffer returns the buffer holding the array data.

func (*HostArray) Handle

func (a *HostArray) Handle() platform.Handle

Handle to the data.

func (*HostArray) Shape

func (a *HostArray) Shape() *shape.Shape

Shape of the array.

func (*HostArray) String

func (a *HostArray) String() string

String representation of the array.

func (*HostArray) ToAtom

func (a *HostArray) ToAtom() (any, error)

ToAtom returns the value as an atomic value. An error is returned if the array contains more than one value.

func (*HostArray) ToDevice

func (a *HostArray) ToDevice(dev platform.Device) (*DeviceArray, error)

ToDevice transfers the data to a device. It is a no-op if the data is already on the device.

func (*HostArray) ToFloatNumber

func (a *HostArray) ToFloatNumber() (*big.Float, error)

ToFloatNumber returns the value as a float number. An error is returned if the array contains more than one value.

func (*HostArray) ToHost

func (a *HostArray) ToHost(platform.Allocator) (Value, error)

ToHost returns receiver. The allocator is ignored.

func (*HostArray) ToHostArray

func (a *HostArray) ToHostArray(platform.Allocator) (*HostArray, error)

ToHostArray returns the receiver.

func (*HostArray) Type

func (a *HostArray) Type() ir.Type

Type of the array.

type IRNode

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

IRNode is a GX string value.

func NewIRNode

func NewIRNode(node ir.Node) (*IRNode, error)

NewIRNode returns a GX string value from its type and its Go value.

func (*IRNode) String

func (s *IRNode) String() string

IR representation of the value. The returned string is a string reported to the user.

func (*IRNode) ToHost

func (s *IRNode) ToHost(platform.Allocator) (Value, error)

ToHost transfers the value to host given an allocator.

func (*IRNode) Type

func (s *IRNode) Type() ir.Type

Type returns the type of the value.

type NamedType

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

NamedType is the GX runtime value of a named type.

func NewNamedType

func NewNamedType(val Value, typ *ir.NamedType) *NamedType

NewNamedType returns a new named type from a GX runtime value and a named type.

func (*NamedType) NamedType

func (n *NamedType) NamedType() *ir.NamedType

NamedType returns the IR named type of the value.

func (*NamedType) Select added in v0.3.0

func (n *NamedType) Select(expr *ir.SelectorExpr) (ir.Element, error)

Select a field in the structure.

func (*NamedType) String

func (n *NamedType) String() string

String representation of the value. The returned string is a string reported to the user.

func (*NamedType) ToHost

func (n *NamedType) ToHost(alloc platform.Allocator) (Value, error)

ToHost transfers the value to host given an allocator.

func (*NamedType) Type

func (n *NamedType) Type() ir.Type

Type returns the type of the value.

func (*NamedType) Under added in v0.3.0

func (n *NamedType) Under() ir.Element

Under returns the element stored by this type.

func (*NamedType) Underlying

func (n *NamedType) Underlying() Value

Underlying returns the underlying value.

type Slice

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

Slice of GX values.

func NewSlice

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

NewSlice returns a new slice of GX values. vals can be nil when the slice will be allocated and constructed later.

func (*Slice) Allocate

func (s *Slice) Allocate(size int)

Allocate a slice of GX values given a size.

func (*Slice) Element

func (s *Slice) Element(i int) Value

Element at the ith position.

func (*Slice) Elements added in v0.3.0

func (s *Slice) Elements() []ir.Element

Elements returns all the element of the slice

func (*Slice) Len added in v0.3.0

func (s *Slice) Len() int

Len returns the size of the slice.

func (*Slice) Set

func (s *Slice) Set(i int, val Value)

Set the ith element of the slice.

func (*Slice) SliceType

func (s *Slice) SliceType() *ir.SliceType

SliceType returns the type of the slice.

func (*Slice) String

func (s *Slice) String() string

String representation of the slice.

func (*Slice) ToHost

func (s *Slice) ToHost(alloc platform.Allocator) (Value, error)

ToHost transfers all the elements of the slice to the host.

func (*Slice) Type

func (s *Slice) Type() ir.Type

Type of the slice.

type String

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

String is a GX string value.

func NewString

func NewString(typ ir.Type, str string) (*String, error)

NewString returns a GX string value from its type and its Go value.

func (*String) String

func (s *String) String() string

String representation of the value. The returned string is a string reported to the user.

func (*String) ToHost

func (s *String) ToHost(platform.Allocator) (Value, error)

ToHost transfers the value to host given an allocator.

func (*String) Type

func (s *String) Type() ir.Type

Type returns the type of the value.

type Struct

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

Struct stores the GX values of a structure.

func NewStruct

func NewStruct(typ ir.Type, vals []Value) (*Struct, error)

NewStruct returns a new structure given a set of values.

func (*Struct) FieldValue

func (vs *Struct) FieldValue(name string) Value

FieldValue returns the value of the ith field.

func (*Struct) Select added in v0.3.0

func (vs *Struct) Select(expr *ir.SelectorExpr) (ir.Element, error)

Select a field in the structure.

func (*Struct) SetField

func (vs *Struct) SetField(name string, val Value)

SetField sets a field value.

func (*Struct) String

func (vs *Struct) String() string

String representation of the structure.

func (*Struct) StructType

func (vs *Struct) StructType() *ir.StructType

StructType returns the structure type of the structure.

func (*Struct) ToHost

func (vs *Struct) ToHost(alloc platform.Allocator) (Value, error)

ToHost transfers all the elements of the slice to the host.

func (*Struct) Type

func (vs *Struct) Type() ir.Type

Type of the structure.

type Value

type Value interface {

	// Type returns the type of the value.
	Type() ir.Type

	// ToHost transfers the value to host given an allocator.
	ToHost(platform.Allocator) (Value, error)

	// String representation of the value.
	// The returned string is a string reported to the user.
	String() string
	// contains filtered or unexported methods
}

Value is a GX value.

func ToHost

func ToHost(alloc platform.Allocator, vals []Value) ([]Value, error)

ToHost transfers all values recursively to the host.

func Underlying

func Underlying(val Value) Value

Underlying returns the underlying element.

func Zero

func Zero(typ ir.Type) (Value, error)

Zero returns a zero value given a GX type.

type Valuer

type Valuer interface {
	GXValue() Value
}

Valuer is an instance able to produce a GX value.

Jump to

Keyboard shortcuts

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