-
Notifications
You must be signed in to change notification settings - Fork 3.6k
TypeScript: Allow constructing float16 tensors using Float16Array #26742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
7018775
143e63e
fd6c809
c6c72e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,10 @@ import { Tensor as TensorImpl } from './tensor-impl.js'; | |
| import { TypedTensorUtils } from './tensor-utils.js'; | ||
| import { TryGetGlobalType } from './type-helper.js'; | ||
|
|
||
| // Helper type: resolves to the instance type of `Float16Array` if it exists in the global scope, | ||
| // or `never` otherwise. Uses the shared TryGetGlobalType helper. | ||
| export type GlobalFloat16Array = TryGetGlobalType<'Float16Array', never>; | ||
|
|
||
| /* eslint-disable @typescript-eslint/no-redeclare */ | ||
|
|
||
| /** | ||
|
|
@@ -240,6 +244,19 @@ export interface TensorConstructor extends TensorFactory { | |
| dims?: readonly number[], | ||
| ): TypedTensor<T>; | ||
|
|
||
| /** | ||
| * Construct a new float16 tensor object from the given type, data and dims. | ||
| * | ||
| * @param type - Specify the element type. | ||
| * @param data - Specify the CPU tensor data. | ||
| * @param dims - Specify the dimension of the tensor. If omitted, a 1-D tensor is assumed. | ||
| */ | ||
| new ( | ||
| type: 'float16', | ||
| data: Tensor.DataTypeMap['float16'] | GlobalFloat16Array | readonly number[], | ||
|
||
| dims?: readonly number[], | ||
| ): TypedTensor<'float16'>; | ||
|
|
||
| /** | ||
| * Construct a new numeric tensor object from the given type, data and dims. | ||
| * | ||
|
|
@@ -264,6 +281,14 @@ export interface TensorConstructor extends TensorFactory { | |
| */ | ||
| new (data: Float32Array, dims?: readonly number[]): TypedTensor<'float32'>; | ||
|
|
||
| /** | ||
| * Construct a new float16 tensor object from the given data and dims. | ||
| * | ||
| * @param data - Specify the CPU tensor data. | ||
| * @param dims - Specify the dimension of the tensor. If omitted, a 1-D tensor is assumed. | ||
| */ | ||
| new (data: GlobalFloat16Array, dims?: readonly number[]): TypedTensor<'float16'>; | ||
|
|
||
| /** | ||
| * Construct a new int8 tensor object from the given data and dims. | ||
| * | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it needs to be exported / part of the public API, just a local helper.