index.d.ts 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. /**
  2. * A typed array of 16-bit float values. The contents are initialized to 0. If the requested number
  3. * of bytes could not be allocated an exception is raised.
  4. */
  5. export interface Float16Array {
  6. /**
  7. * The size in bytes of each element in the array.
  8. */
  9. readonly BYTES_PER_ELEMENT: number;
  10. /**
  11. * The ArrayBuffer instance referenced by the array.
  12. */
  13. readonly buffer: ArrayBufferLike;
  14. /**
  15. * The length in bytes of the array.
  16. */
  17. readonly byteLength: number;
  18. /**
  19. * The offset in bytes of the array.
  20. */
  21. readonly byteOffset: number;
  22. [Symbol.iterator](): IterableIterator<number>;
  23. /**
  24. * Returns an array of key, value pairs for every entry in the array
  25. */
  26. entries(): IterableIterator<[number, number]>;
  27. /**
  28. * Returns an list of keys in the array
  29. */
  30. keys(): IterableIterator<number>;
  31. /**
  32. * Returns an list of values in the array
  33. */
  34. values(): IterableIterator<number>;
  35. /**
  36. * Returns the item located at the specified index.
  37. * @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
  38. */
  39. at(index: number): number | undefined;
  40. /**
  41. * Returns the this object after copying a section of the array identified by start and end
  42. * to the same array starting at position target
  43. * @param target If target is negative, it is treated as length+target where length is the
  44. * length of the array.
  45. * @param start If start is negative, it is treated as length+start. If end is negative, it
  46. * is treated as length+end.
  47. * @param end If not specified, length of the this object is used as its default value.
  48. */
  49. copyWithin(target: number, start: number, end?: number): this;
  50. /**
  51. * Determines whether all the members of an array satisfy the specified test.
  52. * @param callbackfn A function that accepts up to three arguments. The every method calls
  53. * the callbackfn function for each element in the array until the callbackfn returns a value
  54. * which is coercible to the Boolean value false, or until the end of the array.
  55. * @param thisArg An object to which the this keyword can refer in the callbackfn function.
  56. * If thisArg is omitted, undefined is used as the this value.
  57. */
  58. every(
  59. callbackfn: (value: number, index: number, array: Float16Array) => unknown,
  60. thisArg?: any,
  61. ): boolean;
  62. /**
  63. * Returns the this object after filling the section identified by start and end with value
  64. * @param value value to fill array section with
  65. * @param start index to start filling the array at. If start is negative, it is treated as
  66. * length+start where length is the length of the array.
  67. * @param end index to stop filling the array at. If end is negative, it is treated as
  68. * length+end.
  69. */
  70. fill(value: number, start?: number, end?: number): this;
  71. /**
  72. * Returns the elements of an array that meet the condition specified in a callback function.
  73. * @param predicate A function that accepts up to three arguments. The filter method calls
  74. * the predicate function one time for each element in the array.
  75. * @param thisArg An object to which the this keyword can refer in the predicate function.
  76. * If thisArg is omitted, undefined is used as the this value.
  77. */
  78. filter(
  79. predicate: (value: number, index: number, array: Float16Array) => any,
  80. thisArg?: any,
  81. ): Float16Array;
  82. /**
  83. * Returns the value of the first element in the array where predicate is true, and undefined
  84. * otherwise.
  85. * @param predicate find calls predicate once for each element of the array, in ascending
  86. * order, until it finds one where predicate returns true. If such an element is found, find
  87. * immediately returns that element value. Otherwise, find returns undefined.
  88. * @param thisArg If provided, it will be used as the this value for each invocation of
  89. * predicate. If it is not provided, undefined is used instead.
  90. */
  91. find(
  92. predicate: (value: number, index: number, obj: Float16Array) => boolean,
  93. thisArg?: any,
  94. ): number | undefined;
  95. /**
  96. * Returns the index of the first element in the array where predicate is true, and -1
  97. * otherwise.
  98. * @param predicate find calls predicate once for each element of the array, in ascending
  99. * order, until it finds one where predicate returns true. If such an element is found,
  100. * findIndex immediately returns that element index. Otherwise, findIndex returns -1.
  101. * @param thisArg If provided, it will be used as the this value for each invocation of
  102. * predicate. If it is not provided, undefined is used instead.
  103. */
  104. findIndex(
  105. predicate: (value: number, index: number, obj: Float16Array) => boolean,
  106. thisArg?: any,
  107. ): number;
  108. /**
  109. * Returns the value of the last element in the array where predicate is true, and undefined
  110. * otherwise.
  111. * @param predicate find calls predicate once for each element of the array, in descending
  112. * order, until it finds one where predicate returns true. If such an element is found, findLast
  113. * immediately returns that element value. Otherwise, findLast returns undefined.
  114. * @param thisArg If provided, it will be used as the this value for each invocation of
  115. * predicate. If it is not provided, undefined is used instead.
  116. */
  117. findLast(
  118. predicate: (value: number, index: number, obj: Float16Array) => boolean,
  119. thisArg?: any,
  120. ): number | undefined;
  121. /**
  122. * Returns the index of the last element in the array where predicate is true, and -1
  123. * otherwise.
  124. * @param predicate find calls predicate once for each element of the array, in descending
  125. * order, until it finds one where predicate returns true. If such an element is found,
  126. * findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
  127. * @param thisArg If provided, it will be used as the this value for each invocation of
  128. * predicate. If it is not provided, undefined is used instead.
  129. */
  130. findLastIndex(
  131. predicate: (value: number, index: number, obj: Float16Array) => boolean,
  132. thisArg?: any,
  133. ): number;
  134. /**
  135. * Performs the specified action for each element in an array.
  136. * @param callbackfn A function that accepts up to three arguments. forEach calls the
  137. * callbackfn function one time for each element in the array.
  138. * @param thisArg An object to which the this keyword can refer in the callbackfn function.
  139. * If thisArg is omitted, undefined is used as the this value.
  140. */
  141. forEach(
  142. callbackfn: (value: number, index: number, array: Float16Array) => void,
  143. thisArg?: any,
  144. ): void;
  145. /**
  146. * Determines whether an array includes a certain element, returning true or false as appropriate.
  147. * @param searchElement The element to search for.
  148. * @param fromIndex The position in this array at which to begin searching for searchElement.
  149. */
  150. includes(searchElement: number, fromIndex?: number): boolean;
  151. /**
  152. * Returns the index of the first occurrence of a value in an array.
  153. * @param searchElement The value to locate in the array.
  154. * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the
  155. * search starts at index 0.
  156. */
  157. indexOf(searchElement: number, fromIndex?: number): number;
  158. /**
  159. * Adds all the elements of an array separated by the specified separator string.
  160. * @param separator A string used to separate one element of an array from the next in the
  161. * resulting String. If omitted, the array elements are separated with a comma.
  162. */
  163. join(separator?: string): string;
  164. /**
  165. * Returns the index of the last occurrence of a value in an array.
  166. * @param searchElement The value to locate in the array.
  167. * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the
  168. * search starts at index 0.
  169. */
  170. lastIndexOf(searchElement: number, fromIndex?: number): number;
  171. /**
  172. * The length of the array.
  173. */
  174. readonly length: number;
  175. /**
  176. * Calls a defined callback function on each element of an array, and returns an array that
  177. * contains the results.
  178. * @param callbackfn A function that accepts up to three arguments. The map method calls the
  179. * callbackfn function one time for each element in the array.
  180. * @param thisArg An object to which the this keyword can refer in the callbackfn function.
  181. * If thisArg is omitted, undefined is used as the this value.
  182. */
  183. map(
  184. callbackfn: (value: number, index: number, array: Float16Array) => number,
  185. thisArg?: any,
  186. ): Float16Array;
  187. /**
  188. * Calls the specified callback function for all the elements in an array. The return value of
  189. * the callback function is the accumulated result, and is provided as an argument in the next
  190. * call to the callback function.
  191. * @param callbackfn A function that accepts up to four arguments. The reduce method calls the
  192. * callbackfn function one time for each element in the array.
  193. * @param initialValue If initialValue is specified, it is used as the initial value to start
  194. * the accumulation. The first call to the callbackfn function provides this value as an argument
  195. * instead of an array value.
  196. */
  197. reduce(
  198. callbackfn: (
  199. previousValue: number,
  200. currentValue: number,
  201. currentIndex: number,
  202. array: Float16Array,
  203. ) => number,
  204. ): number;
  205. reduce(
  206. callbackfn: (
  207. previousValue: number,
  208. currentValue: number,
  209. currentIndex: number,
  210. array: Float16Array,
  211. ) => number,
  212. initialValue: number,
  213. ): number;
  214. reduce<U>(
  215. callbackfn: (
  216. previousValue: U,
  217. currentValue: number,
  218. currentIndex: number,
  219. array: Float16Array,
  220. ) => U,
  221. initialValue: U,
  222. ): U;
  223. /**
  224. * Calls the specified callback function for all the elements in an array, in descending order.
  225. * The return value of the callback function is the accumulated result, and is provided as an
  226. * argument in the next call to the callback function.
  227. * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls
  228. * the callbackfn function one time for each element in the array.
  229. * @param initialValue If initialValue is specified, it is used as the initial value to start
  230. * the accumulation. The first call to the callbackfn function provides this value as an
  231. * argument instead of an array value.
  232. */
  233. reduceRight(
  234. callbackfn: (
  235. previousValue: number,
  236. currentValue: number,
  237. currentIndex: number,
  238. array: Float16Array,
  239. ) => number,
  240. ): number;
  241. reduceRight(
  242. callbackfn: (
  243. previousValue: number,
  244. currentValue: number,
  245. currentIndex: number,
  246. array: Float16Array,
  247. ) => number,
  248. initialValue: number,
  249. ): number;
  250. reduceRight<U>(
  251. callbackfn: (
  252. previousValue: U,
  253. currentValue: number,
  254. currentIndex: number,
  255. array: Float16Array,
  256. ) => U,
  257. initialValue: U,
  258. ): U;
  259. /**
  260. * Reverses the elements in an Array.
  261. */
  262. reverse(): this;
  263. /**
  264. * Sets a value or an array of values.
  265. * @param array A typed or untyped array of values to set.
  266. * @param offset The index in the current array at which the values are to be written.
  267. */
  268. set(array: ArrayLike<number>, offset?: number): void;
  269. /**
  270. * Returns a section of an array.
  271. * @param start The beginning of the specified portion of the array.
  272. * @param end The end of the specified portion of the array. This is exclusive of the element at the index 'end'.
  273. */
  274. slice(start?: number, end?: number): Float16Array;
  275. /**
  276. * Determines whether the specified callback function returns true for any element of an array.
  277. * @param callbackfn A function that accepts up to three arguments. The some method calls
  278. * the callbackfn function for each element in the array until the callbackfn returns a value
  279. * which is coercible to the Boolean value true, or until the end of the array.
  280. * @param thisArg An object to which the this keyword can refer in the callbackfn function.
  281. * If thisArg is omitted, undefined is used as the this value.
  282. */
  283. some(
  284. callbackfn: (value: number, index: number, array: Float16Array) => unknown,
  285. thisArg?: any,
  286. ): boolean;
  287. /**
  288. * Sorts an array.
  289. * @param compareFn Function used to determine the order of the elements. It is expected to return
  290. * a negative value if first argument is less than second argument, zero if they're equal and a positive
  291. * value otherwise. If omitted, the elements are sorted in ascending.
  292. */
  293. sort(compareFn?: (a: number, b: number) => number): this;
  294. /**
  295. * Gets a new Float16Array view of the ArrayBuffer store for this array, referencing the elements
  296. * at begin, inclusive, up to end, exclusive.
  297. * @param begin The index of the beginning of the array.
  298. * @param end The index of the end of the array.
  299. */
  300. subarray(begin?: number, end?: number): Float16Array;
  301. /**
  302. * Copies the array and returns the copy with the elements in reverse order.
  303. */
  304. toReversed(): Float16Array;
  305. /**
  306. * Copies and sorts the array.
  307. * @param compareFn Function used to determine the order of the elements. It is expected to return
  308. * a negative value if first argument is less than second argument, zero if they're equal and a positive
  309. * value otherwise. If omitted, the elements are sorted in ascending.
  310. */
  311. toSorted(compareFn?: (a: number, b: number) => number): Float16Array;
  312. /**
  313. * Copies the array and replaces the element at the given index with the provided value.
  314. * @param index The zero-based location in the array for which to replace an element.
  315. * @param value Element to insert into the array in place of the replaced element.
  316. */
  317. with(index: number, value: number): Float16Array;
  318. /**
  319. * Converts a number to a string by using the current locale.
  320. */
  321. toLocaleString(): string;
  322. /**
  323. * Returns a string representation of an array.
  324. */
  325. toString(): string;
  326. /**
  327. * Returns the primitive value of the specified object.
  328. */
  329. valueOf(): Float16Array;
  330. readonly [Symbol.toStringTag]: "Float16Array";
  331. [index: number]: number;
  332. }
  333. export interface Float16ArrayConstructor {
  334. readonly prototype: Float16Array;
  335. new (): Float16Array;
  336. new (length: number): Float16Array;
  337. new (elements: Iterable<number>): Float16Array;
  338. new (array: ArrayLike<number> | ArrayBufferLike): Float16Array;
  339. new (
  340. buffer: ArrayBufferLike,
  341. byteOffset: number,
  342. length?: number,
  343. ): Float16Array;
  344. /**
  345. * The size in bytes of each element in the array.
  346. */
  347. readonly BYTES_PER_ELEMENT: number;
  348. /**
  349. * Returns a new array from a set of elements.
  350. * @param items A set of elements to include in the new array object.
  351. */
  352. of(...items: number[]): Float16Array;
  353. /**
  354. * Creates an array from an array-like or iterable object.
  355. * @param elements An iterable object to convert to an array.
  356. */
  357. from(elements: Iterable<number>): Float16Array;
  358. /**
  359. * Creates an array from an array-like or iterable object.
  360. * @param elements An iterable object to convert to an array.
  361. * @param mapfn A mapping function to call on every element of the array.
  362. * @param thisArg Value of 'this' used to invoke the mapfn.
  363. */
  364. from<T>(
  365. elements: Iterable<T>,
  366. mapfn: (v: T, k: number) => number,
  367. thisArg?: any,
  368. ): Float16Array;
  369. /**
  370. * Creates an array from an array-like or iterable object.
  371. * @param arrayLike An array-like object to convert to an array.
  372. */
  373. from(arrayLike: ArrayLike<number>): Float16Array;
  374. /**
  375. * Creates an array from an array-like or iterable object.
  376. * @param arrayLike An array-like object to convert to an array.
  377. * @param mapfn A mapping function to call on every element of the array.
  378. * @param thisArg Value of 'this' used to invoke the mapfn.
  379. */
  380. from<T>(
  381. arrayLike: ArrayLike<T>,
  382. mapfn: (v: T, k: number) => number,
  383. thisArg?: any,
  384. ): Float16Array;
  385. }
  386. export declare const Float16Array: Float16ArrayConstructor;
  387. /**
  388. * Returns `true` if the value is a Float16Array instance.
  389. * @since v3.4.0
  390. */
  391. export declare function isFloat16Array(value: unknown): value is Float16Array;
  392. /**
  393. * Returns `true` if the value is a type of TypedArray instance that contains Float16Array.
  394. * @since v3.6.0
  395. */
  396. export declare function isTypedArray(
  397. value: unknown,
  398. ): value is
  399. | Uint8Array
  400. | Uint8ClampedArray
  401. | Uint16Array
  402. | Uint32Array
  403. | Int8Array
  404. | Int16Array
  405. | Int32Array
  406. | Float16Array
  407. | Float32Array
  408. | Float64Array
  409. | BigUint64Array
  410. | BigInt64Array;
  411. /**
  412. * Gets the Float16 value at the specified byte offset from the start of the view. There is
  413. * no alignment constraint; multi-byte values may be fetched from any offset.
  414. * @param byteOffset The place in the buffer at which the value should be retrieved.
  415. * @param littleEndian If false or undefined, a big-endian value should be read,
  416. * otherwise a little-endian value should be read.
  417. */
  418. export declare function getFloat16(
  419. dataView: DataView,
  420. byteOffset: number,
  421. littleEndian?: boolean,
  422. ): number;
  423. /**
  424. * Stores an Float16 value at the specified byte offset from the start of the view.
  425. * @param byteOffset The place in the buffer at which the value should be set.
  426. * @param value The value to set.
  427. * @param littleEndian If false or undefined, a big-endian value should be written,
  428. * otherwise a little-endian value should be written.
  429. */
  430. export declare function setFloat16(
  431. dataView: DataView,
  432. byteOffset: number,
  433. value: number,
  434. littleEndian?: boolean,
  435. ): void;
  436. /**
  437. * Returns the nearest half-precision float representation of a number.
  438. * @param x A numeric expression.
  439. */
  440. export declare function f16round(x: number): number;
  441. /**
  442. * Returns the nearest half-precision float representation of a number.
  443. * @alias f16round
  444. * @param x A numeric expression.
  445. */
  446. export declare function hfround(x: number): number;