numpy-ts 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +199 -293
- package/dist/numpy-ts.browser.js +2 -2
- package/dist/numpy-ts.esm.js +2 -2
- package/dist/numpy-ts.node-io.cjs +3 -0
- package/dist/numpy-ts.node-io.cjs.map +7 -0
- package/dist/numpy-ts.node-io.mjs +3 -0
- package/dist/numpy-ts.node-io.mjs.map +7 -0
- package/dist/numpy-ts.node.cjs +2 -1
- package/dist/numpy-ts.node.cjs.map +7 -0
- package/dist/types/core/ndarray.d.ts +383 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/io/index.d.ts +17 -0
- package/dist/types/io/npy/format.d.ts +91 -0
- package/dist/types/io/npy/index.d.ts +7 -0
- package/dist/types/io/npy/parser.d.ts +28 -0
- package/dist/types/io/npy/serializer.d.ts +17 -0
- package/dist/types/io/npz/index.d.ts +6 -0
- package/dist/types/io/npz/parser.d.ts +57 -0
- package/dist/types/io/npz/serializer.d.ts +49 -0
- package/dist/types/io/zip/index.d.ts +7 -0
- package/dist/types/io/zip/reader.d.ts +22 -0
- package/dist/types/io/zip/types.d.ts +59 -0
- package/dist/types/io/zip/writer.d.ts +29 -0
- package/dist/types/node.d.ts +154 -0
- package/dist/types/ops/advanced.d.ts +34 -0
- package/dist/types/ops/hyperbolic.d.ts +59 -0
- package/dist/types/ops/shape.d.ts +61 -0
- package/dist/types/ops/trig.d.ts +94 -0
- package/package.json +18 -6
|
@@ -135,6 +135,101 @@ export declare class NDArray {
|
|
|
135
135
|
* @returns New array with signs
|
|
136
136
|
*/
|
|
137
137
|
sign(): NDArray;
|
|
138
|
+
/**
|
|
139
|
+
* Sine of each element (in radians)
|
|
140
|
+
* Promotes integer types to float64
|
|
141
|
+
* @returns New array with sine values
|
|
142
|
+
*/
|
|
143
|
+
sin(): NDArray;
|
|
144
|
+
/**
|
|
145
|
+
* Cosine of each element (in radians)
|
|
146
|
+
* Promotes integer types to float64
|
|
147
|
+
* @returns New array with cosine values
|
|
148
|
+
*/
|
|
149
|
+
cos(): NDArray;
|
|
150
|
+
/**
|
|
151
|
+
* Tangent of each element (in radians)
|
|
152
|
+
* Promotes integer types to float64
|
|
153
|
+
* @returns New array with tangent values
|
|
154
|
+
*/
|
|
155
|
+
tan(): NDArray;
|
|
156
|
+
/**
|
|
157
|
+
* Inverse sine of each element
|
|
158
|
+
* Promotes integer types to float64
|
|
159
|
+
* @returns New array with arcsin values (radians)
|
|
160
|
+
*/
|
|
161
|
+
arcsin(): NDArray;
|
|
162
|
+
/**
|
|
163
|
+
* Inverse cosine of each element
|
|
164
|
+
* Promotes integer types to float64
|
|
165
|
+
* @returns New array with arccos values (radians)
|
|
166
|
+
*/
|
|
167
|
+
arccos(): NDArray;
|
|
168
|
+
/**
|
|
169
|
+
* Inverse tangent of each element
|
|
170
|
+
* Promotes integer types to float64
|
|
171
|
+
* @returns New array with arctan values (radians)
|
|
172
|
+
*/
|
|
173
|
+
arctan(): NDArray;
|
|
174
|
+
/**
|
|
175
|
+
* Element-wise arc tangent of this/other choosing the quadrant correctly
|
|
176
|
+
* @param other - x-coordinates (array or scalar)
|
|
177
|
+
* @returns Angle in radians between -π and π
|
|
178
|
+
*/
|
|
179
|
+
arctan2(other: NDArray | number): NDArray;
|
|
180
|
+
/**
|
|
181
|
+
* Given the "legs" of a right triangle, return its hypotenuse
|
|
182
|
+
* Equivalent to sqrt(this**2 + other**2), element-wise
|
|
183
|
+
* @param other - Second leg (array or scalar)
|
|
184
|
+
* @returns Hypotenuse values
|
|
185
|
+
*/
|
|
186
|
+
hypot(other: NDArray | number): NDArray;
|
|
187
|
+
/**
|
|
188
|
+
* Convert angles from radians to degrees
|
|
189
|
+
* @returns New array with angles in degrees
|
|
190
|
+
*/
|
|
191
|
+
degrees(): NDArray;
|
|
192
|
+
/**
|
|
193
|
+
* Convert angles from degrees to radians
|
|
194
|
+
* @returns New array with angles in radians
|
|
195
|
+
*/
|
|
196
|
+
radians(): NDArray;
|
|
197
|
+
/**
|
|
198
|
+
* Hyperbolic sine of each element
|
|
199
|
+
* Promotes integer types to float64
|
|
200
|
+
* @returns New array with sinh values
|
|
201
|
+
*/
|
|
202
|
+
sinh(): NDArray;
|
|
203
|
+
/**
|
|
204
|
+
* Hyperbolic cosine of each element
|
|
205
|
+
* Promotes integer types to float64
|
|
206
|
+
* @returns New array with cosh values
|
|
207
|
+
*/
|
|
208
|
+
cosh(): NDArray;
|
|
209
|
+
/**
|
|
210
|
+
* Hyperbolic tangent of each element
|
|
211
|
+
* Promotes integer types to float64
|
|
212
|
+
* @returns New array with tanh values
|
|
213
|
+
*/
|
|
214
|
+
tanh(): NDArray;
|
|
215
|
+
/**
|
|
216
|
+
* Inverse hyperbolic sine of each element
|
|
217
|
+
* Promotes integer types to float64
|
|
218
|
+
* @returns New array with arcsinh values
|
|
219
|
+
*/
|
|
220
|
+
arcsinh(): NDArray;
|
|
221
|
+
/**
|
|
222
|
+
* Inverse hyperbolic cosine of each element
|
|
223
|
+
* Promotes integer types to float64
|
|
224
|
+
* @returns New array with arccosh values
|
|
225
|
+
*/
|
|
226
|
+
arccosh(): NDArray;
|
|
227
|
+
/**
|
|
228
|
+
* Inverse hyperbolic tangent of each element
|
|
229
|
+
* Promotes integer types to float64
|
|
230
|
+
* @returns New array with arctanh values
|
|
231
|
+
*/
|
|
232
|
+
arctanh(): NDArray;
|
|
138
233
|
/**
|
|
139
234
|
* Element-wise greater than comparison
|
|
140
235
|
* @param other - Value or array to compare with
|
|
@@ -303,6 +398,40 @@ export declare class NDArray {
|
|
|
303
398
|
* @returns Array with additional dimension (always a view)
|
|
304
399
|
*/
|
|
305
400
|
expand_dims(axis: number): NDArray;
|
|
401
|
+
/**
|
|
402
|
+
* Swap two axes of an array
|
|
403
|
+
* @param axis1 - First axis
|
|
404
|
+
* @param axis2 - Second axis
|
|
405
|
+
* @returns Array with swapped axes (always a view)
|
|
406
|
+
*/
|
|
407
|
+
swapaxes(axis1: number, axis2: number): NDArray;
|
|
408
|
+
/**
|
|
409
|
+
* Move axes to new positions
|
|
410
|
+
* @param source - Original positions of axes to move
|
|
411
|
+
* @param destination - New positions for axes
|
|
412
|
+
* @returns Array with moved axes (always a view)
|
|
413
|
+
*/
|
|
414
|
+
moveaxis(source: number | number[], destination: number | number[]): NDArray;
|
|
415
|
+
/**
|
|
416
|
+
* Repeat elements of an array
|
|
417
|
+
* @param repeats - Number of repetitions for each element
|
|
418
|
+
* @param axis - Axis along which to repeat (if undefined, flattens first)
|
|
419
|
+
* @returns New array with repeated elements
|
|
420
|
+
*/
|
|
421
|
+
repeat(repeats: number | number[], axis?: number): NDArray;
|
|
422
|
+
/**
|
|
423
|
+
* Take elements from array along an axis
|
|
424
|
+
* @param indices - Indices of elements to take
|
|
425
|
+
* @param axis - Axis along which to take (if undefined, flattens first)
|
|
426
|
+
* @returns New array with selected elements
|
|
427
|
+
*/
|
|
428
|
+
take(indices: number[], axis?: number): NDArray;
|
|
429
|
+
/**
|
|
430
|
+
* Put values at specified indices (modifies array in-place)
|
|
431
|
+
* @param indices - Indices at which to place values
|
|
432
|
+
* @param values - Values to put
|
|
433
|
+
*/
|
|
434
|
+
put(indices: number[], values: NDArray | number | bigint): void;
|
|
306
435
|
/**
|
|
307
436
|
* Matrix multiplication
|
|
308
437
|
* @param other - Array to multiply with
|
|
@@ -639,4 +768,258 @@ export declare function outer(a: NDArray, b: NDArray): NDArray;
|
|
|
639
768
|
* @returns Tensor dot product
|
|
640
769
|
*/
|
|
641
770
|
export declare function tensordot(a: NDArray, b: NDArray, axes?: number | [number[], number[]]): NDArray | number | bigint;
|
|
771
|
+
/**
|
|
772
|
+
* Element-wise sine
|
|
773
|
+
* @param x - Input array (angles in radians)
|
|
774
|
+
* @returns Array of sine values
|
|
775
|
+
*/
|
|
776
|
+
export declare function sin(x: NDArray): NDArray;
|
|
777
|
+
/**
|
|
778
|
+
* Element-wise cosine
|
|
779
|
+
* @param x - Input array (angles in radians)
|
|
780
|
+
* @returns Array of cosine values
|
|
781
|
+
*/
|
|
782
|
+
export declare function cos(x: NDArray): NDArray;
|
|
783
|
+
/**
|
|
784
|
+
* Element-wise tangent
|
|
785
|
+
* @param x - Input array (angles in radians)
|
|
786
|
+
* @returns Array of tangent values
|
|
787
|
+
*/
|
|
788
|
+
export declare function tan(x: NDArray): NDArray;
|
|
789
|
+
/**
|
|
790
|
+
* Element-wise inverse sine
|
|
791
|
+
* @param x - Input array (values in range [-1, 1])
|
|
792
|
+
* @returns Array of angles in radians
|
|
793
|
+
*/
|
|
794
|
+
export declare function arcsin(x: NDArray): NDArray;
|
|
795
|
+
/**
|
|
796
|
+
* Element-wise inverse cosine
|
|
797
|
+
* @param x - Input array (values in range [-1, 1])
|
|
798
|
+
* @returns Array of angles in radians
|
|
799
|
+
*/
|
|
800
|
+
export declare function arccos(x: NDArray): NDArray;
|
|
801
|
+
/**
|
|
802
|
+
* Element-wise inverse tangent
|
|
803
|
+
* @param x - Input array
|
|
804
|
+
* @returns Array of angles in radians
|
|
805
|
+
*/
|
|
806
|
+
export declare function arctan(x: NDArray): NDArray;
|
|
807
|
+
/**
|
|
808
|
+
* Element-wise arc tangent of x1/x2 choosing the quadrant correctly
|
|
809
|
+
* @param x1 - y-coordinates
|
|
810
|
+
* @param x2 - x-coordinates (array or scalar)
|
|
811
|
+
* @returns Angles in radians between -π and π
|
|
812
|
+
*/
|
|
813
|
+
export declare function arctan2(x1: NDArray, x2: NDArray | number): NDArray;
|
|
814
|
+
/**
|
|
815
|
+
* Given the "legs" of a right triangle, return its hypotenuse
|
|
816
|
+
* Equivalent to sqrt(x1**2 + x2**2), element-wise
|
|
817
|
+
* @param x1 - First leg
|
|
818
|
+
* @param x2 - Second leg (array or scalar)
|
|
819
|
+
* @returns Hypotenuse values
|
|
820
|
+
*/
|
|
821
|
+
export declare function hypot(x1: NDArray, x2: NDArray | number): NDArray;
|
|
822
|
+
/**
|
|
823
|
+
* Convert angles from radians to degrees
|
|
824
|
+
* @param x - Input array (angles in radians)
|
|
825
|
+
* @returns Angles in degrees
|
|
826
|
+
*/
|
|
827
|
+
export declare function degrees(x: NDArray): NDArray;
|
|
828
|
+
/**
|
|
829
|
+
* Convert angles from degrees to radians
|
|
830
|
+
* @param x - Input array (angles in degrees)
|
|
831
|
+
* @returns Angles in radians
|
|
832
|
+
*/
|
|
833
|
+
export declare function radians(x: NDArray): NDArray;
|
|
834
|
+
/**
|
|
835
|
+
* Element-wise hyperbolic sine
|
|
836
|
+
* @param x - Input array
|
|
837
|
+
* @returns Array of sinh values
|
|
838
|
+
*/
|
|
839
|
+
export declare function sinh(x: NDArray): NDArray;
|
|
840
|
+
/**
|
|
841
|
+
* Element-wise hyperbolic cosine
|
|
842
|
+
* @param x - Input array
|
|
843
|
+
* @returns Array of cosh values
|
|
844
|
+
*/
|
|
845
|
+
export declare function cosh(x: NDArray): NDArray;
|
|
846
|
+
/**
|
|
847
|
+
* Element-wise hyperbolic tangent
|
|
848
|
+
* @param x - Input array
|
|
849
|
+
* @returns Array of tanh values
|
|
850
|
+
*/
|
|
851
|
+
export declare function tanh(x: NDArray): NDArray;
|
|
852
|
+
/**
|
|
853
|
+
* Element-wise inverse hyperbolic sine
|
|
854
|
+
* @param x - Input array
|
|
855
|
+
* @returns Array of arcsinh values
|
|
856
|
+
*/
|
|
857
|
+
export declare function arcsinh(x: NDArray): NDArray;
|
|
858
|
+
/**
|
|
859
|
+
* Element-wise inverse hyperbolic cosine
|
|
860
|
+
* @param x - Input array (values >= 1)
|
|
861
|
+
* @returns Array of arccosh values
|
|
862
|
+
*/
|
|
863
|
+
export declare function arccosh(x: NDArray): NDArray;
|
|
864
|
+
/**
|
|
865
|
+
* Element-wise inverse hyperbolic tangent
|
|
866
|
+
* @param x - Input array (values in range (-1, 1))
|
|
867
|
+
* @returns Array of arctanh values
|
|
868
|
+
*/
|
|
869
|
+
export declare function arctanh(x: NDArray): NDArray;
|
|
870
|
+
/**
|
|
871
|
+
* Swap two axes of an array
|
|
872
|
+
*
|
|
873
|
+
* @param a - Input array
|
|
874
|
+
* @param axis1 - First axis
|
|
875
|
+
* @param axis2 - Second axis
|
|
876
|
+
* @returns View with axes swapped
|
|
877
|
+
*/
|
|
878
|
+
export declare function swapaxes(a: NDArray, axis1: number, axis2: number): NDArray;
|
|
879
|
+
/**
|
|
880
|
+
* Move axes to new positions
|
|
881
|
+
*
|
|
882
|
+
* @param a - Input array
|
|
883
|
+
* @param source - Original positions of axes to move
|
|
884
|
+
* @param destination - New positions for axes
|
|
885
|
+
* @returns View with axes moved
|
|
886
|
+
*/
|
|
887
|
+
export declare function moveaxis(a: NDArray, source: number | number[], destination: number | number[]): NDArray;
|
|
888
|
+
/**
|
|
889
|
+
* Concatenate arrays along an existing axis
|
|
890
|
+
*
|
|
891
|
+
* @param arrays - Arrays to concatenate
|
|
892
|
+
* @param axis - Axis along which to concatenate (default: 0)
|
|
893
|
+
* @returns Concatenated array
|
|
894
|
+
*/
|
|
895
|
+
export declare function concatenate(arrays: NDArray[], axis?: number): NDArray;
|
|
896
|
+
/**
|
|
897
|
+
* Stack arrays along a new axis
|
|
898
|
+
*
|
|
899
|
+
* @param arrays - Arrays to stack (must have same shape)
|
|
900
|
+
* @param axis - Axis in the result array along which to stack (default: 0)
|
|
901
|
+
* @returns Stacked array
|
|
902
|
+
*/
|
|
903
|
+
export declare function stack(arrays: NDArray[], axis?: number): NDArray;
|
|
904
|
+
/**
|
|
905
|
+
* Stack arrays vertically (row-wise)
|
|
906
|
+
*
|
|
907
|
+
* @param arrays - Arrays to stack
|
|
908
|
+
* @returns Vertically stacked array
|
|
909
|
+
*/
|
|
910
|
+
export declare function vstack(arrays: NDArray[]): NDArray;
|
|
911
|
+
/**
|
|
912
|
+
* Stack arrays horizontally (column-wise)
|
|
913
|
+
*
|
|
914
|
+
* @param arrays - Arrays to stack
|
|
915
|
+
* @returns Horizontally stacked array
|
|
916
|
+
*/
|
|
917
|
+
export declare function hstack(arrays: NDArray[]): NDArray;
|
|
918
|
+
/**
|
|
919
|
+
* Stack arrays depth-wise (along third axis)
|
|
920
|
+
*
|
|
921
|
+
* @param arrays - Arrays to stack
|
|
922
|
+
* @returns Depth-stacked array
|
|
923
|
+
*/
|
|
924
|
+
export declare function dstack(arrays: NDArray[]): NDArray;
|
|
925
|
+
/**
|
|
926
|
+
* Split array into multiple sub-arrays
|
|
927
|
+
*
|
|
928
|
+
* @param a - Array to split
|
|
929
|
+
* @param indicesOrSections - Number of equal sections or indices where to split
|
|
930
|
+
* @param axis - Axis along which to split (default: 0)
|
|
931
|
+
* @returns List of sub-arrays
|
|
932
|
+
*/
|
|
933
|
+
export declare function split(a: NDArray, indicesOrSections: number | number[], axis?: number): NDArray[];
|
|
934
|
+
/**
|
|
935
|
+
* Split array into multiple sub-arrays (allows unequal splits)
|
|
936
|
+
*
|
|
937
|
+
* @param a - Array to split
|
|
938
|
+
* @param indicesOrSections - Number of sections or indices where to split
|
|
939
|
+
* @param axis - Axis along which to split (default: 0)
|
|
940
|
+
* @returns List of sub-arrays
|
|
941
|
+
*/
|
|
942
|
+
export declare function array_split(a: NDArray, indicesOrSections: number | number[], axis?: number): NDArray[];
|
|
943
|
+
/**
|
|
944
|
+
* Split array vertically (row-wise)
|
|
945
|
+
*
|
|
946
|
+
* @param a - Array to split
|
|
947
|
+
* @param indicesOrSections - Number of sections or indices where to split
|
|
948
|
+
* @returns List of sub-arrays
|
|
949
|
+
*/
|
|
950
|
+
export declare function vsplit(a: NDArray, indicesOrSections: number | number[]): NDArray[];
|
|
951
|
+
/**
|
|
952
|
+
* Split array horizontally (column-wise)
|
|
953
|
+
*
|
|
954
|
+
* @param a - Array to split
|
|
955
|
+
* @param indicesOrSections - Number of sections or indices where to split
|
|
956
|
+
* @returns List of sub-arrays
|
|
957
|
+
*/
|
|
958
|
+
export declare function hsplit(a: NDArray, indicesOrSections: number | number[]): NDArray[];
|
|
959
|
+
/**
|
|
960
|
+
* Tile array by repeating along each axis
|
|
961
|
+
*
|
|
962
|
+
* @param a - Input array
|
|
963
|
+
* @param reps - Number of repetitions along each axis
|
|
964
|
+
* @returns Tiled array
|
|
965
|
+
*/
|
|
966
|
+
export declare function tile(a: NDArray, reps: number | number[]): NDArray;
|
|
967
|
+
/**
|
|
968
|
+
* Repeat elements of an array
|
|
969
|
+
*
|
|
970
|
+
* @param a - Input array
|
|
971
|
+
* @param repeats - Number of repetitions for each element
|
|
972
|
+
* @param axis - Axis along which to repeat (if undefined, flattens first)
|
|
973
|
+
* @returns Array with repeated elements
|
|
974
|
+
*/
|
|
975
|
+
export declare function repeat(a: NDArray, repeats: number | number[], axis?: number): NDArray;
|
|
976
|
+
/**
|
|
977
|
+
* Broadcast an array to a given shape
|
|
978
|
+
*
|
|
979
|
+
* @param a - Input array
|
|
980
|
+
* @param shape - Target shape
|
|
981
|
+
* @returns View broadcast to target shape
|
|
982
|
+
*/
|
|
983
|
+
export declare function broadcast_to(a: NDArray, shape: number[]): NDArray;
|
|
984
|
+
/**
|
|
985
|
+
* Broadcast arrays to a common shape
|
|
986
|
+
*
|
|
987
|
+
* @param arrays - Arrays to broadcast
|
|
988
|
+
* @returns Arrays broadcast to common shape
|
|
989
|
+
*/
|
|
990
|
+
export declare function broadcast_arrays(...arrays: NDArray[]): NDArray[];
|
|
991
|
+
/**
|
|
992
|
+
* Take elements from an array along an axis
|
|
993
|
+
*
|
|
994
|
+
* @param a - Input array
|
|
995
|
+
* @param indices - Indices of elements to take
|
|
996
|
+
* @param axis - Axis along which to take (if undefined, flattens first)
|
|
997
|
+
* @returns Array with selected elements
|
|
998
|
+
*/
|
|
999
|
+
export declare function take(a: NDArray, indices: number[], axis?: number): NDArray;
|
|
1000
|
+
/**
|
|
1001
|
+
* Put values at specified indices (modifies array in-place)
|
|
1002
|
+
*
|
|
1003
|
+
* @param a - Target array
|
|
1004
|
+
* @param indices - Indices at which to place values
|
|
1005
|
+
* @param values - Values to put
|
|
1006
|
+
*/
|
|
1007
|
+
export declare function put(a: NDArray, indices: number[], values: NDArray | number | bigint): void;
|
|
1008
|
+
/**
|
|
1009
|
+
* Construct array from index array and choices
|
|
1010
|
+
*
|
|
1011
|
+
* @param a - Index array (integer indices into choices)
|
|
1012
|
+
* @param choices - Arrays to choose from
|
|
1013
|
+
* @returns Array constructed from choices
|
|
1014
|
+
*/
|
|
1015
|
+
export declare function choose(a: NDArray, choices: NDArray[]): NDArray;
|
|
1016
|
+
/**
|
|
1017
|
+
* Check if two arrays are element-wise equal
|
|
1018
|
+
*
|
|
1019
|
+
* @param a - First array
|
|
1020
|
+
* @param b - Second array
|
|
1021
|
+
* @param equal_nan - Whether to consider NaN equal to NaN (default: false)
|
|
1022
|
+
* @returns True if arrays are equal element-wise
|
|
1023
|
+
*/
|
|
1024
|
+
export declare function array_equal(a: NDArray, b: NDArray, equal_nan?: boolean): boolean;
|
|
642
1025
|
//# sourceMappingURL=ndarray.d.ts.map
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module numpy-ts
|
|
5
5
|
*/
|
|
6
|
-
export { NDArray, zeros, ones, array, arange, linspace, logspace, geomspace, eye, empty, full, identity, asarray, copy, zeros_like, ones_like, empty_like, full_like, sqrt, power, absolute, negative, sign, mod, floor_divide, positive, reciprocal, dot, trace, transpose, inner, outer, tensordot, } from './core/ndarray';
|
|
6
|
+
export { NDArray, zeros, ones, array, arange, linspace, logspace, geomspace, eye, empty, full, identity, asarray, copy, zeros_like, ones_like, empty_like, full_like, sqrt, power, absolute, negative, sign, mod, floor_divide, positive, reciprocal, dot, trace, transpose, inner, outer, tensordot, sin, cos, tan, arcsin, arccos, arctan, arctan2, hypot, degrees, radians, sinh, cosh, tanh, arcsinh, arccosh, arctanh, swapaxes, moveaxis, concatenate, stack, vstack, hstack, dstack, split, array_split, vsplit, hsplit, tile, repeat, broadcast_to, broadcast_arrays, take, put, choose, array_equal, } from './core/ndarray';
|
|
7
|
+
export { parseNpy, serializeNpy, parseNpyHeader, parseNpyData, UnsupportedDTypeError, InvalidNpyError, SUPPORTED_DTYPES, DTYPE_TO_DESCR, type NpyHeader, type NpyMetadata, type NpyVersion, parseNpz, parseNpzSync, loadNpz, loadNpzSync, serializeNpz, serializeNpzSync, type NpzParseOptions, type NpzParseResult, type NpzSerializeOptions, } from './io';
|
|
7
8
|
export declare const __version__: string;
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IO module for numpy-ts
|
|
3
|
+
*
|
|
4
|
+
* This module provides parsing and serialization for NPY and NPZ formats.
|
|
5
|
+
* These functions work with bytes (Uint8Array/ArrayBuffer) and are environment-agnostic.
|
|
6
|
+
*
|
|
7
|
+
* For file system operations (save/load), use the Node.js-specific entry point:
|
|
8
|
+
* import { save, load } from 'numpy-ts/node';
|
|
9
|
+
*
|
|
10
|
+
* For browser usage, use fetch or FileReader to get the bytes, then use these functions.
|
|
11
|
+
*/
|
|
12
|
+
export { parseNpy, parseNpyHeader, parseNpyData } from './npy/parser';
|
|
13
|
+
export { serializeNpy } from './npy/serializer';
|
|
14
|
+
export { UnsupportedDTypeError, InvalidNpyError, SUPPORTED_DTYPES, DTYPE_TO_DESCR, type NpyHeader, type NpyMetadata, type NpyVersion, } from './npy/format';
|
|
15
|
+
export { parseNpz, parseNpzSync, loadNpz, loadNpzSync, type NpzParseOptions, type NpzParseResult, } from './npz/parser';
|
|
16
|
+
export { serializeNpz, serializeNpzSync, type NpzSerializeOptions } from './npz/serializer';
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NPY file format constants and type definitions
|
|
3
|
+
*
|
|
4
|
+
* NPY is NumPy's native binary format for storing arrays.
|
|
5
|
+
* Spec: https://numpy.org/doc/stable/reference/generated/numpy.lib.format.html
|
|
6
|
+
*/
|
|
7
|
+
import type { DType } from '../../core/dtype';
|
|
8
|
+
/**
|
|
9
|
+
* NPY magic number: \x93NUMPY (6 bytes)
|
|
10
|
+
*/
|
|
11
|
+
export declare const NPY_MAGIC: Uint8Array<ArrayBuffer>;
|
|
12
|
+
/**
|
|
13
|
+
* Supported NPY format versions
|
|
14
|
+
* - v1.0: 2-byte header length (max 65535 bytes)
|
|
15
|
+
* - v2.0: 4-byte header length (max 4GB)
|
|
16
|
+
* - v3.0: allows UTF-8 in description (same as v2 otherwise)
|
|
17
|
+
*
|
|
18
|
+
* We read v1, v2, and v3; we write v2 only
|
|
19
|
+
*/
|
|
20
|
+
export interface NpyVersion {
|
|
21
|
+
major: number;
|
|
22
|
+
minor: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* NPY header information
|
|
26
|
+
*/
|
|
27
|
+
export interface NpyHeader {
|
|
28
|
+
/** Data type descriptor (e.g., '<f8', '>i4') */
|
|
29
|
+
descr: string;
|
|
30
|
+
/** Whether array is Fortran-contiguous (column-major) */
|
|
31
|
+
fortran_order: boolean;
|
|
32
|
+
/** Array shape */
|
|
33
|
+
shape: number[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Parsed NPY metadata including version
|
|
37
|
+
*/
|
|
38
|
+
export interface NpyMetadata {
|
|
39
|
+
version: NpyVersion;
|
|
40
|
+
header: NpyHeader;
|
|
41
|
+
/** Byte offset where data starts */
|
|
42
|
+
dataOffset: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Result of parsing an NPY header descriptor to our DType
|
|
46
|
+
*/
|
|
47
|
+
export interface DTypeParseResult {
|
|
48
|
+
dtype: DType;
|
|
49
|
+
/** Whether the data needs byte swapping (big-endian on little-endian or vice versa) */
|
|
50
|
+
needsByteSwap: boolean;
|
|
51
|
+
/** Element size in bytes */
|
|
52
|
+
itemsize: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* All dtypes we support
|
|
56
|
+
*/
|
|
57
|
+
export declare const SUPPORTED_DTYPES: DType[];
|
|
58
|
+
/**
|
|
59
|
+
* Detect system endianness
|
|
60
|
+
*/
|
|
61
|
+
export declare function isSystemLittleEndian(): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* DType to NPY descriptor mapping (for serialization)
|
|
64
|
+
* We always write little-endian
|
|
65
|
+
*/
|
|
66
|
+
export declare const DTYPE_TO_DESCR: Record<DType, string>;
|
|
67
|
+
/**
|
|
68
|
+
* Unsupported dtype types (for error messages)
|
|
69
|
+
*/
|
|
70
|
+
export declare const UNSUPPORTED_DTYPE_PATTERNS: Record<string, string>;
|
|
71
|
+
/**
|
|
72
|
+
* Parse a NumPy dtype descriptor string to our DType
|
|
73
|
+
*
|
|
74
|
+
* @param descr - NumPy descriptor like '<f8', '>i4', '|b1'
|
|
75
|
+
* @returns Parsed result with dtype and byte order info
|
|
76
|
+
* @throws Error if dtype is not supported
|
|
77
|
+
*/
|
|
78
|
+
export declare function parseDescriptor(descr: string): DTypeParseResult;
|
|
79
|
+
/**
|
|
80
|
+
* Custom error for unsupported dtypes
|
|
81
|
+
*/
|
|
82
|
+
export declare class UnsupportedDTypeError extends Error {
|
|
83
|
+
constructor(message: string);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Custom error for invalid NPY format
|
|
87
|
+
*/
|
|
88
|
+
export declare class InvalidNpyError extends Error {
|
|
89
|
+
constructor(message: string);
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NPY format reading and writing
|
|
3
|
+
*/
|
|
4
|
+
export { parseNpy, parseNpyHeader, parseNpyData } from './parser';
|
|
5
|
+
export { serializeNpy } from './serializer';
|
|
6
|
+
export { NPY_MAGIC, DTYPE_TO_DESCR, SUPPORTED_DTYPES, parseDescriptor, isSystemLittleEndian, UnsupportedDTypeError, InvalidNpyError, type NpyVersion, type NpyHeader, type NpyMetadata, type DTypeParseResult, } from './format';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NPY file parser
|
|
3
|
+
*
|
|
4
|
+
* Parses NumPy .npy files (both v1 and v2/v3 formats) into NDArray objects.
|
|
5
|
+
*/
|
|
6
|
+
import { NDArray } from '../../core/ndarray';
|
|
7
|
+
import { type NpyMetadata } from './format';
|
|
8
|
+
/**
|
|
9
|
+
* Parse an NPY file from a Uint8Array or ArrayBuffer
|
|
10
|
+
*
|
|
11
|
+
* @param buffer - The NPY file contents
|
|
12
|
+
* @returns An NDArray containing the parsed data
|
|
13
|
+
* @throws InvalidNpyError if the file format is invalid
|
|
14
|
+
* @throws UnsupportedDTypeError if the dtype is not supported
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseNpy(buffer: ArrayBuffer | Uint8Array): NDArray;
|
|
17
|
+
/**
|
|
18
|
+
* Parse just the NPY header without reading the data
|
|
19
|
+
*
|
|
20
|
+
* @param bytes - The NPY file bytes
|
|
21
|
+
* @returns Parsed metadata including version, header, and data offset
|
|
22
|
+
*/
|
|
23
|
+
export declare function parseNpyHeader(bytes: Uint8Array): NpyMetadata;
|
|
24
|
+
/**
|
|
25
|
+
* Parse the data section of an NPY file given parsed metadata
|
|
26
|
+
*/
|
|
27
|
+
export declare function parseNpyData(bytes: Uint8Array, metadata: NpyMetadata): NDArray;
|
|
28
|
+
//# sourceMappingURL=parser.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NPY file serializer
|
|
3
|
+
*
|
|
4
|
+
* Serializes NDArray objects to NumPy .npy format (v3.0).
|
|
5
|
+
* Always writes in little-endian, C-contiguous order.
|
|
6
|
+
*
|
|
7
|
+
* v3.0 is identical to v2.0 but allows UTF-8 in dtype descriptions.
|
|
8
|
+
*/
|
|
9
|
+
import { NDArray } from '../../core/ndarray';
|
|
10
|
+
/**
|
|
11
|
+
* Serialize an NDArray to NPY format (v3.0)
|
|
12
|
+
*
|
|
13
|
+
* @param arr - The NDArray to serialize
|
|
14
|
+
* @returns A Uint8Array containing the NPY file data
|
|
15
|
+
*/
|
|
16
|
+
export declare function serializeNpy(arr: NDArray): Uint8Array;
|
|
17
|
+
//# sourceMappingURL=serializer.d.ts.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NPZ format reading and writing
|
|
3
|
+
*/
|
|
4
|
+
export { parseNpz, parseNpzSync, loadNpz, loadNpzSync, type NpzParseOptions, type NpzParseResult, } from './parser';
|
|
5
|
+
export { serializeNpz, serializeNpzSync, type NpzSerializeOptions, type NpzArraysInput, } from './serializer';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NPZ file parser
|
|
3
|
+
*
|
|
4
|
+
* NPZ is a ZIP archive containing multiple .npy files.
|
|
5
|
+
*/
|
|
6
|
+
import { NDArray } from '../../core/ndarray';
|
|
7
|
+
/**
|
|
8
|
+
* Options for parsing NPZ files
|
|
9
|
+
*/
|
|
10
|
+
export interface NpzParseOptions {
|
|
11
|
+
/**
|
|
12
|
+
* If true, skip arrays with unsupported dtypes instead of throwing an error.
|
|
13
|
+
* Skipped arrays will not be included in the result.
|
|
14
|
+
* Default: false
|
|
15
|
+
*/
|
|
16
|
+
force?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Result of parsing an NPZ file
|
|
20
|
+
*/
|
|
21
|
+
export interface NpzParseResult {
|
|
22
|
+
/** Successfully parsed arrays */
|
|
23
|
+
arrays: Map<string, NDArray>;
|
|
24
|
+
/** Names of arrays that were skipped due to unsupported dtypes (only when force=true) */
|
|
25
|
+
skipped: string[];
|
|
26
|
+
/** Error messages for skipped arrays */
|
|
27
|
+
errors: Map<string, string>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Parse an NPZ file from bytes
|
|
31
|
+
*
|
|
32
|
+
* @param buffer - The NPZ file contents
|
|
33
|
+
* @param options - Parse options
|
|
34
|
+
* @returns Promise resolving to parsed arrays
|
|
35
|
+
*/
|
|
36
|
+
export declare function parseNpz(buffer: ArrayBuffer | Uint8Array, options?: NpzParseOptions): Promise<NpzParseResult>;
|
|
37
|
+
/**
|
|
38
|
+
* Synchronously parse an NPZ file (only works if not DEFLATE compressed)
|
|
39
|
+
*
|
|
40
|
+
* @param buffer - The NPZ file contents
|
|
41
|
+
* @param options - Parse options
|
|
42
|
+
* @returns Parsed arrays
|
|
43
|
+
*/
|
|
44
|
+
export declare function parseNpzSync(buffer: ArrayBuffer | Uint8Array, options?: NpzParseOptions): NpzParseResult;
|
|
45
|
+
/**
|
|
46
|
+
* Convenience function to get arrays as a plain object
|
|
47
|
+
*
|
|
48
|
+
* @param buffer - The NPZ file contents
|
|
49
|
+
* @param options - Parse options
|
|
50
|
+
* @returns Promise resolving to object with array names as keys
|
|
51
|
+
*/
|
|
52
|
+
export declare function loadNpz(buffer: ArrayBuffer | Uint8Array, options?: NpzParseOptions): Promise<Record<string, NDArray>>;
|
|
53
|
+
/**
|
|
54
|
+
* Synchronous version of loadNpz
|
|
55
|
+
*/
|
|
56
|
+
export declare function loadNpzSync(buffer: ArrayBuffer | Uint8Array, options?: NpzParseOptions): Record<string, NDArray>;
|
|
57
|
+
//# sourceMappingURL=parser.d.ts.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NPZ file serializer
|
|
3
|
+
*
|
|
4
|
+
* Serializes multiple NDArrays to NPZ format (ZIP archive of .npy files).
|
|
5
|
+
*/
|
|
6
|
+
import { NDArray } from '../../core/ndarray';
|
|
7
|
+
/**
|
|
8
|
+
* Input type for arrays - supports:
|
|
9
|
+
* - Array of NDArrays (positional, named arr_0, arr_1, etc.)
|
|
10
|
+
* - Map of names to NDArrays
|
|
11
|
+
* - Object with names as keys
|
|
12
|
+
*/
|
|
13
|
+
export type NpzArraysInput = NDArray[] | Map<string, NDArray> | Record<string, NDArray>;
|
|
14
|
+
/**
|
|
15
|
+
* Options for serializing NPZ files
|
|
16
|
+
*/
|
|
17
|
+
export interface NpzSerializeOptions {
|
|
18
|
+
/**
|
|
19
|
+
* Whether to compress the NPZ file using DEFLATE.
|
|
20
|
+
* Default: false (matches np.savez behavior; use true for np.savez_compressed behavior)
|
|
21
|
+
*/
|
|
22
|
+
compress?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Serialize multiple arrays to NPZ format
|
|
26
|
+
*
|
|
27
|
+
* @param arrays - Arrays to save. Can be:
|
|
28
|
+
* - An array of NDArrays (named arr_0, arr_1, etc. like np.savez positional args)
|
|
29
|
+
* - A Map of names to NDArrays
|
|
30
|
+
* - An object with names as keys (like np.savez keyword args)
|
|
31
|
+
* @param options - Serialization options
|
|
32
|
+
* @returns Promise resolving to NPZ file as Uint8Array
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* // Positional arrays (named arr_0, arr_1)
|
|
36
|
+
* await serializeNpz([arr1, arr2])
|
|
37
|
+
*
|
|
38
|
+
* // Named arrays
|
|
39
|
+
* await serializeNpz({ x: arr1, y: arr2 })
|
|
40
|
+
*/
|
|
41
|
+
export declare function serializeNpz(arrays: NpzArraysInput, options?: NpzSerializeOptions): Promise<Uint8Array>;
|
|
42
|
+
/**
|
|
43
|
+
* Synchronously serialize multiple arrays to NPZ format (no compression)
|
|
44
|
+
*
|
|
45
|
+
* @param arrays - Arrays to save (same input types as serializeNpz)
|
|
46
|
+
* @returns NPZ file as Uint8Array
|
|
47
|
+
*/
|
|
48
|
+
export declare function serializeNpzSync(arrays: NpzArraysInput): Uint8Array;
|
|
49
|
+
//# sourceMappingURL=serializer.d.ts.map
|