index.d.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. type ValueOf<T> = T[keyof T];
  2. // Add constructor options type
  3. export interface NpyjsOptions {
  4. convertFloat16?: boolean;
  5. }
  6. export type Dtypes = {
  7. "<u1": {
  8. name: "uint8";
  9. size: 8;
  10. arrayConstructor: typeof Uint8Array;
  11. };
  12. "|u1": {
  13. name: "uint8";
  14. size: 8;
  15. arrayConstructor: typeof Uint8Array;
  16. };
  17. "<u2": {
  18. name: "uint16";
  19. size: 16;
  20. arrayConstructor: typeof Uint16Array;
  21. };
  22. "|i1": {
  23. name: "int8";
  24. size: 8;
  25. arrayConstructor: typeof Int8Array;
  26. };
  27. "<i2": {
  28. name: "int16";
  29. size: 16;
  30. arrayConstructor: typeof Int16Array;
  31. };
  32. "<u4": {
  33. name: "uint32";
  34. size: 32;
  35. arrayConstructor: typeof Int32Array;
  36. };
  37. "<i4": {
  38. name: "int32";
  39. size: 32;
  40. arrayConstructor: typeof Int32Array;
  41. };
  42. "<u8": {
  43. name: "uint64";
  44. size: 64;
  45. arrayConstructor: typeof BigUint64Array;
  46. };
  47. "<i8": {
  48. name: "int64";
  49. size: 64;
  50. arrayConstructor: typeof BigInt64Array;
  51. };
  52. "<f4": {
  53. name: "float32";
  54. size: 32;
  55. arrayConstructor: typeof Float32Array;
  56. };
  57. "<f8": {
  58. name: "float64";
  59. size: 64;
  60. arrayConstructor: typeof Float64Array;
  61. };
  62. "<f2": {
  63. name: "float16";
  64. size: 16;
  65. arrayConstructor: typeof Uint16Array;
  66. converter?: (array: Uint16Array) => Float32Array;
  67. };
  68. };
  69. export type Parsed = ValueOf<{
  70. [K in keyof Dtypes]: {
  71. dtype: Dtypes[K]["name"];
  72. data: K extends "<f2" ? Float32Array : InstanceType<Dtypes[K]["arrayConstructor"]>;
  73. shape: number[];
  74. fortranOrder: boolean;
  75. };
  76. }>;
  77. declare class npyjs {
  78. constructor(opts?: NpyjsOptions);
  79. dtypes: Dtypes;
  80. parse(arrayBufferContents: ArrayBuffer): Parsed;
  81. load(
  82. filename: RequestInfo | URL | ArrayBuffer,
  83. callback?: (result?: Parsed) => any,
  84. fetchArgs?: RequestInit
  85. ): Promise<Parsed>;
  86. float16ToFloat32Array(float16Array: Uint16Array): Float32Array;
  87. static float16ToFloat32(float16: number): number;
  88. }
  89. export default npyjs;