dtype

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2025 License: Apache-2.0 Imports: 5 Imported by: 16

Documentation

Overview

Package dtype defines data types that can be supported by a platform.

Index

Constants

View Source
const (
	BoolSize     = 1
	Int32Size    = 4
	Int64Size    = 8
	Uint32Size   = 4
	Uint64Size   = 8
	Bfloat16Size = 2
	Float32Size  = 4
	Float64Size  = 8
)

Sizes of data type (in bytes).

Variables

This section is empty.

Functions

func IsAlgebra

func IsAlgebra(d DataType) bool

IsAlgebra returns true if the data type is an algebra type.

func IsFloat

func IsFloat(d DataType) bool

IsFloat returns true if the data type is a float.

func IsInteger

func IsInteger(d DataType) bool

IsInteger returns true if the data type is an integer.

func IsNonAlgebra

func IsNonAlgebra(d DataType) bool

IsNonAlgebra returns true if the data type is a non algebra data type.

func IsSigned

func IsSigned(d DataType) bool

IsSigned returns true if the data type is a signed integer.

func IsUnsigned

func IsUnsigned(d DataType) bool

IsUnsigned returns true if the data type is a unsigned integer.

func Sizeof

func Sizeof(dt DataType) int

Sizeof returns the size of an atomic value of a data type.

func ToSlice

func ToSlice[T any](data []byte) []T

ToSlice converts a []byte buffer into a slice of a given Go type.

Types

type AlgebraType

type AlgebraType interface {
	Float | IntegerType | Bfloat16T
}

AlgebraType are types on which common algebra operations between integers and floats are supported.

type Bfloat16T

type Bfloat16T uint16

Bfloat16T is a shortened (16-bit) version of the 32-bit IEEE 754 single-precision floating-point format (binary32). This implementation only supports conversion to/from other formats, but no arithmetic.

Based on the implementation in https://github.com/gomlx/gopjrt, which is in turn derived from https://github.com/x448/float16.

func BFloat16FromFloat32

func BFloat16FromFloat32(x float32) Bfloat16T

BFloat16FromFloat32 converts a float32 to a BFloat16.

func BFloat16FromFloat64

func BFloat16FromFloat64(x float64) Bfloat16T

BFloat16FromFloat64 converts a float32 to a BFloat16.

func (Bfloat16T) Bits

func (f Bfloat16T) Bits() uint16

Bits convert BFloat16 to an uint16.

func (Bfloat16T) Float32

func (f Bfloat16T) Float32() float32

Float32 returns a BFloat16 value in float32 format.

func (Bfloat16T) String

func (f Bfloat16T) String() string

String implements fmt.Stringer, and prints a float representation of a BFloat16.

type DataType

type DataType uint32

DataType is the type of an atomic value or type of the data stored in an array.

const (
	Invalid DataType = iota

	Bool
	Int
	Int32
	Int64
	Uint32
	Uint64
	Bfloat16
	Float32
	Float64

	MaxDataType = 1 << 16 // Maximum value for a datatype.
)

All supported types

func Generic

func Generic[T GoDataType]() DataType

Generic returns a dtype from a Go type.

func (DataType) String

func (dt DataType) String() string

String returns a string representation of a kind.

type Float

type Float interface {
	~float32 | ~float64
}

Float is a constraint supporting floating-point type.

type GoDataType

type GoDataType interface {
	AlgebraType | NonAlgebraType
}

GoDataType that can be stored in an array.

type IntegerType

type IntegerType interface {
	Signed | Unsigned
}

IntegerType are types on which integer algebra operations are supported.

type NonAlgebraType

type NonAlgebraType interface {
	~bool
}

NonAlgebraType are types on which common algebra operations are NOT supported.

type Signed

type Signed interface {
	~int32 | ~int64
}

Signed is a constraint supporting signed integer type.

type Unsigned

type Unsigned interface {
	~uint32 | ~uint64
}

Unsigned is a constraint supporting unsigned integer type.

Jump to

Keyboard shortcuts

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