@@ -14,6 +14,7 @@ import (
1414 "unsafe"
1515
1616 "github.com/gomlx/compute/dtypes"
17+ "github.com/gomlx/compute/dtypes/gotype"
1718 "github.com/gomlx/go-xla/internal/shapeinference"
1819 "github.com/gomlx/go-xla/types/shapes"
1920 "github.com/pkg/errors"
@@ -222,7 +223,7 @@ func (b *Buffer) Client() *Client {
222223}
223224
224225// ScalarToRaw generates the raw values needed by BufferFromHostConfig.FromRawData to feed a simple scalar value.
225- func ScalarToRaw [T dtypes .Supported ](value T ) ([]byte , dtypes.DType , []int ) {
226+ func ScalarToRaw [T gotype .Supported ](value T ) ([]byte , dtypes.DType , []int ) {
226227 dtype := dtypes .FromGenericsType [T ]()
227228 rawSlice := unsafe .Slice ((* byte )(unsafe .Pointer (& value )), int (unsafe .Sizeof (value )))
228229 return rawSlice , dtype , nil // empty dimensions for scalar
@@ -252,7 +253,7 @@ func (b *Buffer) Size() (int, error) {
252253}
253254
254255// BufferToScalar is a generic function that transfer a Buffer back to host as a scalar of the given type.
255- func BufferToScalar [T dtypes .Supported ](b * Buffer ) (value T , err error ) {
256+ func BufferToScalar [T gotype .Supported ](b * Buffer ) (value T , err error ) {
256257 dst := unsafe .Slice ((* byte )(unsafe .Pointer (& value )), unsafe .Sizeof (value ))
257258 err = b .ToHost (dst )
258259 return
@@ -262,7 +263,7 @@ func BufferToScalar[T dtypes.Supported](b *Buffer) (value T, err error) {
262263//
263264// It is a shortcut to Client.BufferFromHost call with default parameters.
264265// If you need more control where the value will be used you'll have to use Client.BufferFromHost instead.
265- func ScalarToBuffer [T dtypes .Supported ](client * Client , value T ) (b * Buffer , err error ) {
266+ func ScalarToBuffer [T gotype .Supported ](client * Client , value T ) (b * Buffer , err error ) {
266267 dtype := dtypes .FromGenericsType [T ]()
267268 src := unsafe .Slice ((* byte )(unsafe .Pointer (& value )), unsafe .Sizeof (value ))
268269 return client .BufferFromHost ().FromRawData (src , dtype , nil ).Done ()
@@ -272,7 +273,7 @@ func ScalarToBuffer[T dtypes.Supported](client *Client, value T) (b *Buffer, err
272273//
273274// It is a shortcut to Client.BufferFromHost call with default parameters.
274275// If you need more control where the value will be used you'll have to use Client.BufferFromHost instead.
275- func ScalarToBufferOnDeviceNum [T dtypes .Supported ](client * Client , deviceNum int , value T ) (b * Buffer , err error ) {
276+ func ScalarToBufferOnDeviceNum [T gotype .Supported ](client * Client , deviceNum int , value T ) (b * Buffer , err error ) {
276277 dtype := dtypes .FromGenericsType [T ]()
277278 src := unsafe .Slice ((* byte )(unsafe .Pointer (& value )), unsafe .Sizeof (value ))
278279 return client .BufferFromHost ().FromRawData (src , dtype , nil ).ToDeviceNum (deviceNum ).Done ()
@@ -283,15 +284,15 @@ func ScalarToBufferOnDeviceNum[T dtypes.Supported](client *Client, deviceNum int
283284//
284285// It is a shortcut to Client.BufferFromHost call with default parameters.
285286// If you need more control where the value will be used you'll have to use Client.BufferFromHost instead.
286- func ArrayToBuffer [T dtypes .Supported ](client * Client , flatValues []T , dimensions ... int ) (b * Buffer , err error ) {
287+ func ArrayToBuffer [T gotype .Supported ](client * Client , flatValues []T , dimensions ... int ) (b * Buffer , err error ) {
287288 if len (dimensions ) == 0 && len (flatValues ) != 1 {
288289 return nil , errors .Errorf ("ArrayToBuffer not given any dimensions (indicating a scalar), but len(flatValues) == %d" , len (flatValues ))
289290 }
290291 return client .BufferFromHost ().FromFlatDataWithDimensions (flatValues , dimensions ).Done ()
291292}
292293
293294// BufferToArray transfers the buffer to an array defined by a slice with its flat values, and returns also its underlying dimensions.
294- func BufferToArray [T dtypes .Supported ](buffer * Buffer ) (flatValues []T , dimensions []int , err error ) {
295+ func BufferToArray [T gotype .Supported ](buffer * Buffer ) (flatValues []T , dimensions []int , err error ) {
295296 if err = buffer .Check (); err != nil {
296297 return
297298 }
0 commit comments