1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 04:52:26 -05:00

Compare commits

...

3 commits

Author SHA1 Message Date
Kenta Moriuchi
d3771e0585
Merge bbf6ce54e4 into 9aa02769c8 2025-01-19 20:51:16 +00:00
Kenta Moriuchi
bbf6ce54e4
lint 2024-11-20 03:44:30 +09:00
Kenta Moriuchi
3d7e71c59c
feat(type): make Float16Array generic 2024-11-20 03:06:16 +09:00

View file

@ -3110,7 +3110,7 @@ declare namespace Intl {
* @category Platform
* @experimental
*/
interface Float16Array {
interface Float16Array<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike> {
/**
* The size in bytes of each element in the array.
*/
@ -3119,7 +3119,7 @@ interface Float16Array {
/**
* The ArrayBuffer instance referenced by the array.
*/
readonly buffer: ArrayBufferLike;
readonly buffer: TArrayBuffer;
/**
* The length in bytes of the array.
@ -3131,6 +3131,12 @@ interface Float16Array {
*/
readonly byteOffset: number;
/**
* Returns the item located at the specified index.
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
*/
at(index: number): number | undefined;
/**
* Returns the this object after copying a section of the array identified by start and end
* to the same array starting at position target
@ -3151,7 +3157,7 @@ interface Float16Array {
* If thisArg is omitted, undefined is used as the this value.
*/
every(
predicate: (value: number, index: number, array: Float16Array) => unknown,
predicate: (value: number, index: number, array: this) => unknown,
thisArg?: any,
): boolean;
@ -3173,9 +3179,9 @@ interface Float16Array {
* If thisArg is omitted, undefined is used as the this value.
*/
filter(
predicate: (value: number, index: number, array: Float16Array) => any,
predicate: (value: number, index: number, array: this) => any,
thisArg?: any,
): Float16Array;
): Float16Array<ArrayBuffer>;
/**
* Returns the value of the first element in the array where predicate is true, and undefined
@ -3187,7 +3193,7 @@ interface Float16Array {
* predicate. If it is not provided, undefined is used instead.
*/
find(
predicate: (value: number, index: number, obj: Float16Array) => boolean,
predicate: (value: number, index: number, obj: this) => boolean,
thisArg?: any,
): number | undefined;
@ -3201,7 +3207,51 @@ interface Float16Array {
* predicate. If it is not provided, undefined is used instead.
*/
findIndex(
predicate: (value: number, index: number, obj: Float16Array) => boolean,
predicate: (value: number, index: number, obj: this) => boolean,
thisArg?: any,
): number;
/**
* Returns the value of the last element in the array where predicate is true, and undefined
* otherwise.
* @param predicate findLast calls predicate once for each element of the array, in descending
* order, until it finds one where predicate returns true. If such an element is found, findLast
* immediately returns that element value. Otherwise, findLast returns undefined.
* @param thisArg If provided, it will be used as the this value for each invocation of
* predicate. If it is not provided, undefined is used instead.
*/
findLast<S extends number>(
predicate: (
value: number,
index: number,
array: this,
) => value is S,
thisArg?: any,
): S | undefined;
findLast(
predicate: (
value: number,
index: number,
array: this,
) => unknown,
thisArg?: any,
): number | undefined;
/**
* Returns the index of the last element in the array where predicate is true, and -1
* otherwise.
* @param predicate findLastIndex calls predicate once for each element of the array, in descending
* order, until it finds one where predicate returns true. If such an element is found,
* findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
* @param thisArg If provided, it will be used as the this value for each invocation of
* predicate. If it is not provided, undefined is used instead.
*/
findLastIndex(
predicate: (
value: number,
index: number,
array: this,
) => unknown,
thisArg?: any,
): number;
@ -3213,10 +3263,17 @@ interface Float16Array {
* If thisArg is omitted, undefined is used as the this value.
*/
forEach(
callbackfn: (value: number, index: number, array: Float16Array) => void,
callbackfn: (value: number, index: number, array: this) => void,
thisArg?: any,
): void;
/**
* Determines whether an array includes a certain element, returning true or false as appropriate.
* @param searchElement The element to search for.
* @param fromIndex The position in this array at which to begin searching for searchElement.
*/
includes(searchElement: number, fromIndex?: number): boolean;
/**
* Returns the index of the first occurrence of a value in an array.
* @param searchElement The value to locate in the array.
@ -3254,9 +3311,9 @@ interface Float16Array {
* If thisArg is omitted, undefined is used as the this value.
*/
map(
callbackfn: (value: number, index: number, array: Float16Array) => number,
callbackfn: (value: number, index: number, array: this) => number,
thisArg?: any,
): Float16Array;
): Float16Array<ArrayBuffer>;
/**
* Calls the specified callback function for all the elements in an array. The return value of
@ -3273,7 +3330,7 @@ interface Float16Array {
previousValue: number,
currentValue: number,
currentIndex: number,
array: Float16Array,
array: this,
) => number,
): number;
reduce(
@ -3281,7 +3338,7 @@ interface Float16Array {
previousValue: number,
currentValue: number,
currentIndex: number,
array: Float16Array,
array: this,
) => number,
initialValue: number,
): number;
@ -3301,7 +3358,7 @@ interface Float16Array {
previousValue: U,
currentValue: number,
currentIndex: number,
array: Float16Array,
array: this,
) => U,
initialValue: U,
): U;
@ -3321,7 +3378,7 @@ interface Float16Array {
previousValue: number,
currentValue: number,
currentIndex: number,
array: Float16Array,
array: this,
) => number,
): number;
reduceRight(
@ -3329,7 +3386,7 @@ interface Float16Array {
previousValue: number,
currentValue: number,
currentIndex: number,
array: Float16Array,
array: this,
) => number,
initialValue: number,
): number;
@ -3349,7 +3406,7 @@ interface Float16Array {
previousValue: U,
currentValue: number,
currentIndex: number,
array: Float16Array,
array: this,
) => U,
initialValue: U,
): U;
@ -3357,7 +3414,7 @@ interface Float16Array {
/**
* Reverses the elements in an Array.
*/
reverse(): Float16Array;
reverse(): this;
/**
* Sets a value or an array of values.
@ -3371,7 +3428,7 @@ interface Float16Array {
* @param start The beginning of the specified portion of the array.
* @param end The end of the specified portion of the array. This is exclusive of the element at the index 'end'.
*/
slice(start?: number, end?: number): Float16Array;
slice(start?: number, end?: number): Float16Array<ArrayBuffer>;
/**
* Determines whether the specified callback function returns true for any element of an array.
@ -3382,7 +3439,7 @@ interface Float16Array {
* If thisArg is omitted, undefined is used as the this value.
*/
some(
predicate: (value: number, index: number, array: Float16Array) => unknown,
predicate: (value: number, index: number, array: this) => unknown,
thisArg?: any,
): boolean;
@ -3403,12 +3460,34 @@ interface Float16Array {
* @param begin The index of the beginning of the array.
* @param end The index of the end of the array.
*/
subarray(begin?: number, end?: number): Float16Array;
subarray(begin?: number, end?: number): Float16Array<TArrayBuffer>;
/**
* Converts a number to a string by using the current locale.
*/
toLocaleString(): string;
toLocaleString(
locales?: string | string[],
options?: Intl.NumberFormatOptions,
): string;
/**
* Copies the array and returns the copy with the elements in reverse order.
*/
toReversed(): Float16Array<ArrayBuffer>;
/**
* Copies and sorts the array.
* @param compareFn Function used to determine the order of the elements. It is expected to return
* a negative value if the first argument is less than the second argument, zero if they're equal, and a positive
* value otherwise. If omitted, the elements are sorted in ascending order.
* ```ts
* const myNums = Float16Array<Buffer>.from([11.25, 2, -22.5, 1]);
* myNums.toSorted((a, b) => a - b) // Float16Array<Buffer>(4) [-22.5, 1, 2, 11.5]
* ```
*/
toSorted(
compareFn?: (a: number, b: number) => number,
): Float16Array<ArrayBuffer>;
/**
* Returns a string representation of an array.
@ -3416,9 +3495,37 @@ interface Float16Array {
toString(): string;
/** Returns the primitive value of the specified object. */
valueOf(): Float16Array;
valueOf(): this;
/**
* Copies the array and inserts the given number at the provided index.
* @param index The index of the value to overwrite. If the index is
* negative, then it replaces from the end of the array.
* @param value The value to insert into the copied array.
* @returns A copy of the original array with the inserted value.
*/
with(index: number, value: number): Float16Array<ArrayBuffer>;
[index: number]: number;
[Symbol.iterator](): ArrayIterator<number>;
/**
* Returns an array of key, value pairs for every entry in the array
*/
entries(): ArrayIterator<[number, number]>;
/**
* Returns an list of keys in the array
*/
keys(): ArrayIterator<number>;
/**
* Returns an list of values in the array
*/
values(): ArrayIterator<number>;
readonly [Symbol.toStringTag]: "Float16Array";
}
/**
@ -3426,14 +3533,14 @@ interface Float16Array {
* @experimental
*/
interface Float16ArrayConstructor {
readonly prototype: Float16Array;
new (length: number): Float16Array;
new (array: ArrayLike<number> | ArrayBufferLike): Float16Array;
new (
buffer: ArrayBufferLike,
readonly prototype: Float16Array<ArrayBufferLike>;
new (length?: number): Float16Array<ArrayBuffer>;
new (array: ArrayLike<number> | Iterable<number>): Float16Array<ArrayBuffer>;
new <TArrayBuffer extends ArrayBufferLike = ArrayBuffer>(
buffer: TArrayBuffer,
byteOffset?: number,
length?: number,
): Float16Array;
): Float16Array<TArrayBuffer>;
/**
* The size in bytes of each element in the array.
@ -3444,17 +3551,17 @@ interface Float16ArrayConstructor {
* Returns a new array from a set of elements.
* @param items A set of elements to include in the new array object.
*/
of(...items: number[]): Float16Array;
of(...items: number[]): Float16Array<ArrayBuffer>;
/**
* Creates an array from an array-like or iterable object.
* @param arrayLike An array-like or iterable object to convert to an array.
* @param arrayLike An array-like object to convert to an array.
*/
from(arrayLike: ArrayLike<number>): Float16Array;
from(arrayLike: ArrayLike<number>): Float16Array<ArrayBuffer>;
/**
* Creates an array from an array-like or iterable object.
* @param arrayLike An array-like or iterable object to convert to an array.
* @param arrayLike An array-like object to convert to an array.
* @param mapfn A mapping function to call on every element of the array.
* @param thisArg Value of 'this' used to invoke the mapfn.
*/
@ -3462,8 +3569,27 @@ interface Float16ArrayConstructor {
arrayLike: ArrayLike<T>,
mapfn: (v: T, k: number) => number,
thisArg?: any,
): Float16Array;
): Float16Array<ArrayBuffer>;
/**
* Creates an array from an array-like or iterable object.
* @param elements An iterable object to convert to an array.
*/
from(elements: Iterable<number>): Float16Array<ArrayBuffer>;
/**
* Creates an array from an array-like or iterable object.
* @param elements An iterable object to convert to an array.
* @param mapfn A mapping function to call on every element of the array.
* @param thisArg Value of 'this' used to invoke the mapfn.
*/
from<T>(
elements: Iterable<T>,
mapfn?: (v: T, k: number) => number,
thisArg?: any,
): Float16Array<ArrayBuffer>;
}
/**
* @category Platform
* @experimental
@ -3474,169 +3600,30 @@ declare var Float16Array: Float16ArrayConstructor;
* @category Platform
* @experimental
*/
interface Float16Array {
[Symbol.iterator](): IterableIterator<number>;
interface Math {
/**
* Returns an array of key, value pairs for every entry in the array
* Returns the nearest half precision float representation of a number.
* @param x A numeric expression.
*
* @category Platform
* @experimental
*/
entries(): IterableIterator<[number, number]>;
/**
* Returns an list of keys in the array
*/
keys(): IterableIterator<number>;
/**
* Returns an list of values in the array
*/
values(): IterableIterator<number>;
f16round(x: number): number;
}
/**
* @category Platform
* @experimental
*/
interface Float16Constructor {
new (elements: Iterable<number>): Float16Array;
/**
* Creates an array from an array-like or iterable object.
* @param arrayLike An array-like or iterable object to convert to an array.
* @param mapfn A mapping function to call on every element of the array.
* @param thisArg Value of 'this' used to invoke the mapfn.
*/
from(
arrayLike: Iterable<number>,
mapfn?: (v: number, k: number) => number,
thisArg?: any,
): Float16Array;
}
/**
* @category Platform
* @experimental
*/
interface Float16Array {
readonly [Symbol.toStringTag]: "Float16Array";
}
/**
* @category Platform
* @experimental
*/
interface Float16Array {
/**
* Determines whether an array includes a certain element, returning true or false as appropriate.
* @param searchElement The element to search for.
* @param fromIndex The position in this array at which to begin searching for searchElement.
*/
includes(searchElement: number, fromIndex?: number): boolean;
}
/**
* @category Platform
* @experimental
*/
interface Float16ArrayConstructor {
new (): Float16Array;
}
/**
* @category Platform
* @experimental
*/
interface Float16Array {
/**
* Returns the item located at the specified index.
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
*/
at(index: number): number | undefined;
}
/**
* @category Platform
* @experimental
*/
interface Float16Array {
/**
* Returns the value of the last element in the array where predicate is true, and undefined
* otherwise.
* @param predicate findLast calls predicate once for each element of the array, in descending
* order, until it finds one where predicate returns true. If such an element is found, findLast
* immediately returns that element value. Otherwise, findLast returns undefined.
* @param thisArg If provided, it will be used as the this value for each invocation of
* predicate. If it is not provided, undefined is used instead.
*/
findLast<S extends number>(
predicate: (
value: number,
index: number,
array: Float16Array,
) => value is S,
thisArg?: any,
): S | undefined;
findLast(
predicate: (
value: number,
index: number,
array: Float16Array,
) => unknown,
thisArg?: any,
): number | undefined;
/**
* Returns the index of the last element in the array where predicate is true, and -1
* otherwise.
* @param predicate findLastIndex calls predicate once for each element of the array, in descending
* order, until it finds one where predicate returns true. If such an element is found,
* findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
* @param thisArg If provided, it will be used as the this value for each invocation of
* predicate. If it is not provided, undefined is used instead.
*/
findLastIndex(
predicate: (
value: number,
index: number,
array: Float16Array,
) => unknown,
thisArg?: any,
): number;
/**
* Copies the array and returns the copy with the elements in reverse order.
*/
toReversed(): Float16Array;
/**
* Copies and sorts the array.
* @param compareFn Function used to determine the order of the elements. It is expected to return
* a negative value if the first argument is less than the second argument, zero if they're equal, and a positive
* value otherwise. If omitted, the elements are sorted in ascending order.
* ```ts
* const myNums = Float16Array.from([11.25, 2, -22.5, 1]);
* myNums.toSorted((a, b) => a - b) // Float16Array(4) [-22.5, 1, 2, 11.5]
* ```
*/
toSorted(compareFn?: (a: number, b: number) => number): Float16Array;
/**
* Copies the array and inserts the given number at the provided index.
* @param index The index of the value to overwrite. If the index is
* negative, then it replaces from the end of the array.
* @param value The value to insert into the copied array.
* @returns A copy of the original array with the inserted value.
*/
with(index: number, value: number): Float16Array;
}
/**
* @category Platform
* @experimental
*/
interface DataView {
interface DataView<TArrayBuffer extends ArrayBufferLike> {
/**
* Gets the Float16 value at the specified byte offset from the start of the view. There is
* no alignment constraint; multi-byte values may be fetched from any offset.
* @param byteOffset The place in the buffer at which the value should be retrieved.
* @param littleEndian If false or undefined, a big-endian value should be read.
*
* @category Platform
* @experimental
*/
getFloat16(byteOffset: number, littleEndian?: boolean): number;
@ -3645,6 +3632,9 @@ interface DataView {
* @param byteOffset The place in the buffer at which the value should be set.
* @param value The value to set.
* @param littleEndian If false or undefined, a big-endian value should be written.
*
* @category Platform
* @experimental
*/
setFloat16(byteOffset: number, value: number, littleEndian?: boolean): void;
}