-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support TypeScript 5.6 and 5.7 (#241)
TypeScript 5.7 made TypeArray objects generic over an `ArrayBufferLike` source. We only use `ArrayBuffer` internally, so isdeally we would be explicit about the generic parameter in our return types. However, older versions of TS will fail with an explicit generic parameter (i.e., `Uint8Array<ArrayBuffer>`). The biggest issue is a mismatch between `ndarray` types and our own. This change vendors the types for `ndarray`, to align them with our own.
- Loading branch information
Showing
8 changed files
with
124 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
declare module "ndarray" { | ||
declare function ndarray<D extends ndarray.Data = ndarray.Data<number>>( | ||
data: D, | ||
shape?: number[], | ||
stride?: number[], | ||
offset?: number, | ||
): ndarray.NdArray<D>; | ||
|
||
declare namespace ndarray { | ||
interface NdArray<D extends Data = Data<number>> { | ||
data: D; | ||
shape: number[]; | ||
stride: number[]; | ||
offset: number; | ||
dtype: DataType<D>; | ||
size: number; | ||
order: number[]; | ||
dimension: number; | ||
get(...args: number[]): Value<D>; | ||
set(...args: number[]): Value<D>; | ||
index(...args: number[]): Value<D>; | ||
lo(...args: number[]): NdArray<D>; | ||
hi(...args: number[]): NdArray<D>; | ||
step(...args: number[]): NdArray<D>; | ||
transpose(...args: number[]): NdArray<D>; | ||
pick(...args: Array<number | null>): NdArray<D>; | ||
T: NdArray<D>; | ||
} | ||
|
||
interface GenericArray<T> { | ||
get(idx: number): T; | ||
set(idx: number, value: T): void; | ||
length: number; | ||
} | ||
|
||
// biome-ignore lint/suspicious/noExplicitAny: not our library | ||
type Data<T = any> = T extends number | ||
? GenericArray<T> | T[] | TypedArray | ||
: T extends bigint | ||
? GenericArray<T> | T[] | BigInt64Array | BigUint64Array | ||
: GenericArray<T> | T[]; | ||
|
||
type TypedArray = | ||
| Int8Array | ||
| Int16Array | ||
| Int32Array | ||
| Uint8Array | ||
| Uint8ClampedArray | ||
| Uint16Array | ||
| Uint32Array | ||
| Float32Array | ||
| Float64Array; | ||
|
||
type Value<D extends Data> = D extends | ||
| GenericArray<infer T> | ||
// biome-ignore lint/suspicious/noRedeclare: not our library | ||
| Record<number, infer T> | ||
? T | ||
: never; | ||
|
||
type DataType<D extends Data = Data> = D extends Int8Array | ||
? "int8" | ||
: D extends Int16Array | ||
? "int16" | ||
: D extends Int32Array | ||
? "int32" | ||
: D extends Uint8Array | ||
? "uint8" | ||
: D extends Uint8ClampedArray | ||
? "uint8_clamped" | ||
: D extends Uint16Array | ||
? "uint16" | ||
: D extends Uint32Array | ||
? "uint32" | ||
: D extends Float32Array | ||
? "float32" | ||
: D extends Float64Array | ||
? "float64" | ||
: D extends BigInt64Array | ||
? "bigint64" | ||
: D extends BigUint64Array | ||
? "biguint64" | ||
: D extends GenericArray<unknown> | ||
? "generic" | ||
: "array"; | ||
} | ||
|
||
export = ndarray; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.