dtype

package module
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2021 License: MIT Imports: 6 Imported by: 0

README

dtype

Package dtype provides a definition of a Dtype, which is a part of the type system that Gorgonia uses.

The main type that this package provides is Dtype{}. Dtype is used within the Gorgonia family of libraries in its type system.

Further, this package also provides some definitions for type classes. These type classes are also used in the Gorgonia family of libraries.

Type Classes

What is a type class? A type class is a set of types that all have a particular feature.

Consider for example, a string and an int. Both these types allow a notion of "addition" - e.g.

// string "addition".
s := "hello"
s += "world"

// int addition.
i := 1
i += 1

So they are to be found in a type class called Addable.

Note that this library DOES NOT enforce the features. Instead, think of this library as holding a collection of known types that does a particular thing.

The list of type classes are:

Type Class What It Does/For
All A collection of known types in Gorgonia's type system.
Specialized A collection of types that receives specialized support/operations within Gorgonia's engines.
Addable Types whose values can be "added" together.
Number Types whose values are numbers.
Ord Types whose values can be sorted in order.
Eq Types whose values can be compared for equality.
Unsigned Types whose values are unsigned numbers.
Signed Types whose values are signed numbers.
SignedNonComplex Types whose values are signed numbers, and are not complex numbers.
Floats Types whose values are represented by floating point numbers.
Complexes Types whose values are represented by floating point complex numbers.
FloatComplex Types whose values are floating point numbers or complex numbers made up of floating point numbers.
NonComplexNumber Types whose values are not complex numbers.
Generatable Types whose values are generatable by a random number generator (strings are also generatable)

Documentation

Overview

Package dtype provides a definition of a Dtype, which is a part of the type system that Gorgonia uses.

Index

Constants

This section is empty.

Variables

View Source
var (
	Bool       = Dtype{reflect.TypeOf(true)}
	Int        = Dtype{reflect.TypeOf(int(1))}
	Int8       = Dtype{reflect.TypeOf(int8(1))}
	Int16      = Dtype{reflect.TypeOf(int16(1))}
	Int32      = Dtype{reflect.TypeOf(int32(1))}
	Int64      = Dtype{reflect.TypeOf(int64(1))}
	Uint       = Dtype{reflect.TypeOf(uint(1))}
	Uint8      = Dtype{reflect.TypeOf(uint8(1))}
	Uint16     = Dtype{reflect.TypeOf(uint16(1))}
	Uint32     = Dtype{reflect.TypeOf(uint32(1))}
	Uint64     = Dtype{reflect.TypeOf(uint64(1))}
	Float32    = Dtype{reflect.TypeOf(float32(1))}
	Float64    = Dtype{reflect.TypeOf(float64(1))}
	Complex64  = Dtype{reflect.TypeOf(complex64(1))}
	Complex128 = Dtype{reflect.TypeOf(complex128(1))}
	String     = Dtype{reflect.TypeOf("")}

	// aliases
	Byte = Uint8

	// extras
	Uintptr       = Dtype{reflect.TypeOf(uintptr(0))}
	UnsafePointer = Dtype{reflect.TypeOf(unsafe.Pointer(&Uintptr))}
)

oh how nice it'd be if I could make them immutable

Functions

func ID

func ID(a Dtype) int

ID returns the ID of the Dtype in the registry.

func Register

func Register(a Dtype)

Register registers a new Dtype into the registry.

func RegisterEq

func RegisterEq(a Dtype)

RegisterEq registers a dtype as a type whose values can be compared for equality.

func RegisterFloat

func RegisterFloat(a Dtype)

RegisterFloat registers a dtype as a type whose values are floating points. This implies that NaN, +Inf and -Inf are also well as values in this type.

func RegisterNumber

func RegisterNumber(a Dtype)

RegisterNumber is a function required to register a new numerical Dtype. This package provides the following Dtype:

Int
Int8
Int16
Int32
Int64
Uint
Uint8
Uint16
Uint32
Uint64
Float32
Float64
Complex64
Complex128

If a Dtype that is registered already exists on the list, it will not be added to the list.

func RegisterOrd

func RegisterOrd(a Dtype)

RegisterOrd registers a dtype as a type whose values can be ordered.

func TypeClassCheck

func TypeClassCheck(a Dtype, in TypeClass) error

TypeClassCheck checks if a given Dtype is in the given type class. It returns nil if it is in the given type class.

Types

type Dtype

type Dtype struct {
	reflect.Type
}

Dtype represents a data type of a Tensor. Concretely it's implemented as an embedded reflect.Type which allows for easy reflection operations. It also implements hm.Type, for type inference in Gorgonia

func FindByName

func FindByName(name string) (Dtype, error)

FindByName finds a given type by its name.

func FromNumpyDtype

func FromNumpyDtype(t string) (Dtype, error)

FromNumpyDtype returns a Dtype given a string that matches Numpy's Dtype.

func (Dtype) Apply

func (dt Dtype) Apply(hm.Subs) hm.Substitutable

func (Dtype) Eq

func (dt Dtype) Eq(other hm.Type) bool

func (Dtype) Format

func (dt Dtype) Format(s fmt.State, c rune)

func (Dtype) FreeTypeVar

func (dt Dtype) FreeTypeVar() hm.TypeVarSet

func (Dtype) Normalize

func (dt Dtype) Normalize(k, v hm.TypeVarSet) (hm.Type, error)

func (Dtype) NumpyDtype

func (dt Dtype) NumpyDtype() (string, error)

NumpyDtype returns the Numpy's Dtype equivalent. This is predominantly used in converting a Tensor to a Numpy ndarray, however, not all Dtypes are supported

func (Dtype) Types

func (dt Dtype) Types() hm.Types

type TypeClass

type TypeClass int
const (
	All TypeClass = iota
	Specialized
	Addable
	Number
	Ord
	Eq
	Unsigned
	Signed
	SignedNonComplex
	Floats
	Complexes
	FloatComplex
	NonComplexNumber
	Generatable
)

Jump to

Keyboard shortcuts

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