numpy-ts 0.4.0 → 0.6.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 +200 -294
- 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/broadcasting.d.ts +18 -0
- package/dist/types/core/ndarray.d.ts +1109 -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 +40 -0
- package/dist/types/ops/arithmetic.d.ts +54 -0
- package/dist/types/ops/comparison.d.ts +12 -0
- package/dist/types/ops/hyperbolic.d.ts +59 -0
- package/dist/types/ops/linalg.d.ts +51 -0
- package/dist/types/ops/reduction.d.ts +76 -0
- package/dist/types/ops/shape.d.ts +105 -0
- package/dist/types/ops/trig.d.ts +110 -0
- package/package.json +22 -9
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, asanyarray, ascontiguousarray, asfortranarray, diag, diagflat, frombuffer, fromfile, fromfunction, fromiter, fromstring, meshgrid, tri, tril, triu, vander, sqrt, power, absolute, negative, sign, mod, floor_divide, positive, reciprocal, cbrt, fabs, divmod, square, remainder, heaviside, dot, trace, diagonal, kron, transpose, inner, outer, tensordot, einsum, sin, cos, tan, arcsin, arccos, arctan, arctan2, hypot, degrees, radians, deg2rad, rad2deg, sinh, cosh, tanh, arcsinh, arccosh, arctanh, swapaxes, moveaxis, concatenate, stack, vstack, hstack, dstack, split, array_split, vsplit, hsplit, tile, repeat, ravel, reshape, squeeze, expand_dims, flip, fliplr, flipud, rot90, roll, rollaxis, atleast_1d, atleast_2d, atleast_3d, dsplit, column_stack, row_stack, resize, append, delete_ as delete, insert, pad, broadcast_to, broadcast_arrays, broadcast_shapes, take, put, choose, array_equal, array_equiv, cumsum, cumprod, ptp, median, percentile, quantile, average, nansum, nanprod, nanmean, nanvar, nanstd, nanmin, nanmax, nanargmin, nanargmax, nancumsum, nancumprod, nanmedian, } 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
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal ZIP file reading and writing
|
|
3
|
+
*/
|
|
4
|
+
export { readZip, readZipSync } from './reader';
|
|
5
|
+
export { writeZip, writeZipSync, type ZipWriteOptions } from './writer';
|
|
6
|
+
export { crc32, ZIP_STORED, ZIP_DEFLATED } from './types';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal ZIP file reader
|
|
3
|
+
*
|
|
4
|
+
* Reads ZIP files with STORED or DEFLATE compression.
|
|
5
|
+
* Uses the Compression Streams API (built into modern browsers and Node.js 18+).
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Read a ZIP file and return its entries
|
|
9
|
+
*
|
|
10
|
+
* @param buffer - ZIP file contents
|
|
11
|
+
* @returns Map of file names to their uncompressed data
|
|
12
|
+
*/
|
|
13
|
+
export declare function readZip(buffer: ArrayBuffer | Uint8Array): Promise<Map<string, Uint8Array>>;
|
|
14
|
+
/**
|
|
15
|
+
* Synchronously read a ZIP file (only works for STORED entries)
|
|
16
|
+
*
|
|
17
|
+
* @param buffer - ZIP file contents
|
|
18
|
+
* @returns Map of file names to their uncompressed data
|
|
19
|
+
* @throws Error if any entry uses compression
|
|
20
|
+
*/
|
|
21
|
+
export declare function readZipSync(buffer: ArrayBuffer | Uint8Array): Map<string, Uint8Array>;
|
|
22
|
+
//# sourceMappingURL=reader.d.ts.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ZIP file format types and constants
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* ZIP local file header signature
|
|
6
|
+
*/
|
|
7
|
+
export declare const ZIP_LOCAL_SIGNATURE = 67324752;
|
|
8
|
+
/**
|
|
9
|
+
* ZIP central directory header signature
|
|
10
|
+
*/
|
|
11
|
+
export declare const ZIP_CENTRAL_SIGNATURE = 33639248;
|
|
12
|
+
/**
|
|
13
|
+
* ZIP end of central directory signature
|
|
14
|
+
*/
|
|
15
|
+
export declare const ZIP_END_SIGNATURE = 101010256;
|
|
16
|
+
/**
|
|
17
|
+
* Compression methods
|
|
18
|
+
*/
|
|
19
|
+
export declare const ZIP_STORED = 0;
|
|
20
|
+
export declare const ZIP_DEFLATED = 8;
|
|
21
|
+
/**
|
|
22
|
+
* Entry in a ZIP file
|
|
23
|
+
*/
|
|
24
|
+
export interface ZipEntry {
|
|
25
|
+
/** File name */
|
|
26
|
+
name: string;
|
|
27
|
+
/** Uncompressed data */
|
|
28
|
+
data: Uint8Array;
|
|
29
|
+
/** Compression method used */
|
|
30
|
+
compressionMethod: number;
|
|
31
|
+
/** CRC-32 checksum */
|
|
32
|
+
crc32: number;
|
|
33
|
+
/** Compressed size */
|
|
34
|
+
compressedSize: number;
|
|
35
|
+
/** Uncompressed size */
|
|
36
|
+
uncompressedSize: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Raw entry as read from ZIP (before decompression)
|
|
40
|
+
*/
|
|
41
|
+
export interface RawZipEntry {
|
|
42
|
+
/** File name */
|
|
43
|
+
name: string;
|
|
44
|
+
/** Compressed data */
|
|
45
|
+
compressedData: Uint8Array;
|
|
46
|
+
/** Compression method */
|
|
47
|
+
compressionMethod: number;
|
|
48
|
+
/** CRC-32 checksum */
|
|
49
|
+
crc32: number;
|
|
50
|
+
/** Compressed size */
|
|
51
|
+
compressedSize: number;
|
|
52
|
+
/** Uncompressed size */
|
|
53
|
+
uncompressedSize: number;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Calculate CRC-32 checksum
|
|
57
|
+
*/
|
|
58
|
+
export declare function crc32(data: Uint8Array): number;
|
|
59
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal ZIP file writer
|
|
3
|
+
*
|
|
4
|
+
* Creates ZIP files with optional DEFLATE compression.
|
|
5
|
+
* Uses the Compression Streams API (built into modern browsers and Node.js 18+).
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Options for writing a ZIP file
|
|
9
|
+
*/
|
|
10
|
+
export interface ZipWriteOptions {
|
|
11
|
+
/** Whether to compress files (default: false for NPZ compatibility) */
|
|
12
|
+
compress?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create a ZIP file from a map of file names to data
|
|
16
|
+
*
|
|
17
|
+
* @param files - Map of file names to their data
|
|
18
|
+
* @param options - Write options
|
|
19
|
+
* @returns ZIP file as Uint8Array
|
|
20
|
+
*/
|
|
21
|
+
export declare function writeZip(files: Map<string, Uint8Array>, options?: ZipWriteOptions): Promise<Uint8Array>;
|
|
22
|
+
/**
|
|
23
|
+
* Create a ZIP file synchronously (no compression)
|
|
24
|
+
*
|
|
25
|
+
* @param files - Map of file names to their data
|
|
26
|
+
* @returns ZIP file as Uint8Array
|
|
27
|
+
*/
|
|
28
|
+
export declare function writeZipSync(files: Map<string, Uint8Array>): Uint8Array;
|
|
29
|
+
//# sourceMappingURL=writer.d.ts.map
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js-specific entry point for numpy-ts
|
|
3
|
+
*
|
|
4
|
+
* This module provides file system operations for saving and loading NPY/NPZ files,
|
|
5
|
+
* plus all core numpy-ts functionality in a single import.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* import * as np from 'numpy-ts/node';
|
|
9
|
+
* // Has everything from numpy-ts + file I/O
|
|
10
|
+
* const arr = await np.loadNpy('data.npy');
|
|
11
|
+
* await np.saveNpz('output.npz', { x: arr });
|
|
12
|
+
*
|
|
13
|
+
* For browser usage, use the main entry point (no file I/O).
|
|
14
|
+
*/
|
|
15
|
+
import { NDArray } from './core/ndarray';
|
|
16
|
+
import { type NpzParseOptions, type NpzParseResult } from './io/npz/parser';
|
|
17
|
+
import { type NpzSerializeOptions, type NpzArraysInput } from './io/npz/serializer';
|
|
18
|
+
export * from './index';
|
|
19
|
+
export * from './io';
|
|
20
|
+
/**
|
|
21
|
+
* Options for loading NPY/NPZ files
|
|
22
|
+
*/
|
|
23
|
+
export interface LoadOptions extends NpzParseOptions {
|
|
24
|
+
/**
|
|
25
|
+
* If true, allow loading .npy files.
|
|
26
|
+
* Default: true
|
|
27
|
+
*/
|
|
28
|
+
allowNpy?: boolean;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Options for saving NPZ files
|
|
32
|
+
*/
|
|
33
|
+
export interface SaveNpzOptions extends NpzSerializeOptions {
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Load an NDArray from a .npy file
|
|
37
|
+
*
|
|
38
|
+
* @param path - Path to the .npy file
|
|
39
|
+
* @returns The loaded NDArray
|
|
40
|
+
*/
|
|
41
|
+
export declare function loadNpy(path: string): Promise<NDArray>;
|
|
42
|
+
/**
|
|
43
|
+
* Synchronously load an NDArray from a .npy file
|
|
44
|
+
*
|
|
45
|
+
* @param path - Path to the .npy file
|
|
46
|
+
* @returns The loaded NDArray
|
|
47
|
+
*/
|
|
48
|
+
export declare function loadNpySync(path: string): NDArray;
|
|
49
|
+
/**
|
|
50
|
+
* Save an NDArray to a .npy file
|
|
51
|
+
*
|
|
52
|
+
* @param path - Path to save the .npy file
|
|
53
|
+
* @param arr - The NDArray to save
|
|
54
|
+
*/
|
|
55
|
+
export declare function saveNpy(path: string, arr: NDArray): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Synchronously save an NDArray to a .npy file
|
|
58
|
+
*
|
|
59
|
+
* @param path - Path to save the .npy file
|
|
60
|
+
* @param arr - The NDArray to save
|
|
61
|
+
*/
|
|
62
|
+
export declare function saveNpySync(path: string, arr: NDArray): void;
|
|
63
|
+
/**
|
|
64
|
+
* Load arrays from a .npz file
|
|
65
|
+
*
|
|
66
|
+
* @param path - Path to the .npz file
|
|
67
|
+
* @param options - Load options
|
|
68
|
+
* @returns Object with array names as keys
|
|
69
|
+
*/
|
|
70
|
+
export declare function loadNpzFile(path: string, options?: NpzParseOptions): Promise<NpzParseResult>;
|
|
71
|
+
/**
|
|
72
|
+
* Synchronously load arrays from a .npz file
|
|
73
|
+
*
|
|
74
|
+
* Note: Only works if the NPZ file is not DEFLATE compressed.
|
|
75
|
+
*
|
|
76
|
+
* @param path - Path to the .npz file
|
|
77
|
+
* @param options - Load options
|
|
78
|
+
* @returns Object with array names as keys
|
|
79
|
+
*/
|
|
80
|
+
export declare function loadNpzFileSync(path: string, options?: NpzParseOptions): NpzParseResult;
|
|
81
|
+
/**
|
|
82
|
+
* Save arrays to a .npz file
|
|
83
|
+
*
|
|
84
|
+
* @param path - Path to save the .npz file
|
|
85
|
+
* @param arrays - Arrays to save:
|
|
86
|
+
* - Array of NDArrays (positional, named arr_0, arr_1, etc.)
|
|
87
|
+
* - Map of names to NDArrays
|
|
88
|
+
* - Object with names as keys
|
|
89
|
+
* @param options - Save options
|
|
90
|
+
*/
|
|
91
|
+
export declare function saveNpz(path: string, arrays: NpzArraysInput, options?: SaveNpzOptions): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Synchronously save arrays to a .npz file (no compression)
|
|
94
|
+
*
|
|
95
|
+
* @param path - Path to save the .npz file
|
|
96
|
+
* @param arrays - Arrays to save (same types as saveNpz)
|
|
97
|
+
*/
|
|
98
|
+
export declare function saveNpzSync(path: string, arrays: NpzArraysInput): void;
|
|
99
|
+
/**
|
|
100
|
+
* Load an array or arrays from a .npy or .npz file
|
|
101
|
+
*
|
|
102
|
+
* This is a convenience function that auto-detects the file format based on extension.
|
|
103
|
+
*
|
|
104
|
+
* @param path - Path to the file
|
|
105
|
+
* @param options - Load options
|
|
106
|
+
* @returns NDArray for .npy files, or NpzParseResult for .npz files
|
|
107
|
+
*/
|
|
108
|
+
export declare function load(path: string, options?: LoadOptions): Promise<NDArray | NpzParseResult>;
|
|
109
|
+
/**
|
|
110
|
+
* Synchronously load an array or arrays from a .npy or .npz file
|
|
111
|
+
*
|
|
112
|
+
* @param path - Path to the file
|
|
113
|
+
* @param options - Load options
|
|
114
|
+
* @returns NDArray for .npy files, or NpzParseResult for .npz files
|
|
115
|
+
*/
|
|
116
|
+
export declare function loadSync(path: string, options?: LoadOptions): NDArray | NpzParseResult;
|
|
117
|
+
/**
|
|
118
|
+
* Save an array to a .npy file
|
|
119
|
+
*
|
|
120
|
+
* @param path - Path to save the file (should end with .npy)
|
|
121
|
+
* @param arr - The NDArray to save
|
|
122
|
+
*/
|
|
123
|
+
export declare function save(path: string, arr: NDArray): Promise<void>;
|
|
124
|
+
/**
|
|
125
|
+
* Synchronously save an array to a .npy file
|
|
126
|
+
*
|
|
127
|
+
* @param path - Path to save the file (should end with .npy)
|
|
128
|
+
* @param arr - The NDArray to save
|
|
129
|
+
*/
|
|
130
|
+
export declare function saveSync(path: string, arr: NDArray): void;
|
|
131
|
+
/**
|
|
132
|
+
* Save multiple arrays to a .npz file (like np.savez)
|
|
133
|
+
*
|
|
134
|
+
* @param path - Path to save the .npz file
|
|
135
|
+
* @param arrays - Arrays to save:
|
|
136
|
+
* - Array of NDArrays: named arr_0, arr_1, etc. (like np.savez positional args)
|
|
137
|
+
* - Object/Map with names as keys (like np.savez keyword args)
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* // Positional arrays
|
|
141
|
+
* await savez('data.npz', [arr1, arr2]) // saved as arr_0, arr_1
|
|
142
|
+
*
|
|
143
|
+
* // Named arrays
|
|
144
|
+
* await savez('data.npz', { x: arr1, y: arr2 })
|
|
145
|
+
*/
|
|
146
|
+
export declare function savez(path: string, arrays: NpzArraysInput): Promise<void>;
|
|
147
|
+
/**
|
|
148
|
+
* Save multiple arrays to a compressed .npz file (like np.savez_compressed)
|
|
149
|
+
*
|
|
150
|
+
* @param path - Path to save the .npz file
|
|
151
|
+
* @param arrays - Arrays to save (same input types as savez)
|
|
152
|
+
*/
|
|
153
|
+
export declare function savez_compressed(path: string, arrays: NpzArraysInput): Promise<void>;
|
|
154
|
+
//# sourceMappingURL=node.d.ts.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Advanced array operations
|
|
3
|
+
*
|
|
4
|
+
* Broadcasting, indexing, and comparison functions.
|
|
5
|
+
* @module ops/advanced
|
|
6
|
+
*/
|
|
7
|
+
import { ArrayStorage } from '../core/storage';
|
|
8
|
+
import { broadcastShapes } from '../core/broadcasting';
|
|
9
|
+
/**
|
|
10
|
+
* Broadcast an array to a given shape
|
|
11
|
+
* Returns a read-only view on the original array
|
|
12
|
+
*/
|
|
13
|
+
export declare function broadcast_to(storage: ArrayStorage, targetShape: number[]): ArrayStorage;
|
|
14
|
+
/**
|
|
15
|
+
* Broadcast multiple arrays to a common shape
|
|
16
|
+
* Returns views on the original arrays
|
|
17
|
+
*/
|
|
18
|
+
export declare function broadcast_arrays(storages: ArrayStorage[]): ArrayStorage[];
|
|
19
|
+
/**
|
|
20
|
+
* Compute the broadcast shape for multiple shapes
|
|
21
|
+
* Re-export from core/broadcasting for convenience
|
|
22
|
+
*/
|
|
23
|
+
export { broadcastShapes as broadcast_shapes };
|
|
24
|
+
/**
|
|
25
|
+
* Take elements from an array along an axis
|
|
26
|
+
*/
|
|
27
|
+
export declare function take(storage: ArrayStorage, indices: number[], axis?: number): ArrayStorage;
|
|
28
|
+
/**
|
|
29
|
+
* Put values at specified indices (modifies array in-place)
|
|
30
|
+
*/
|
|
31
|
+
export declare function put(storage: ArrayStorage, indices: number[], values: ArrayStorage | number | bigint): void;
|
|
32
|
+
/**
|
|
33
|
+
* Construct array from index array and choices
|
|
34
|
+
*/
|
|
35
|
+
export declare function choose(indexStorage: ArrayStorage, choices: ArrayStorage[]): ArrayStorage;
|
|
36
|
+
/**
|
|
37
|
+
* Check if two arrays are element-wise equal
|
|
38
|
+
*/
|
|
39
|
+
export declare function array_equal(a: ArrayStorage, b: ArrayStorage, equal_nan?: boolean): boolean;
|
|
40
|
+
//# sourceMappingURL=advanced.d.ts.map
|
|
@@ -105,4 +105,58 @@ export declare function positive(a: ArrayStorage): ArrayStorage;
|
|
|
105
105
|
* @returns Result storage with reciprocal values
|
|
106
106
|
*/
|
|
107
107
|
export declare function reciprocal(a: ArrayStorage): ArrayStorage;
|
|
108
|
+
/**
|
|
109
|
+
* Cube root of each element
|
|
110
|
+
* NumPy behavior: Promotes integer types to float64
|
|
111
|
+
*
|
|
112
|
+
* @param a - Input array storage
|
|
113
|
+
* @returns Result storage with cube root values
|
|
114
|
+
*/
|
|
115
|
+
export declare function cbrt(a: ArrayStorage): ArrayStorage;
|
|
116
|
+
/**
|
|
117
|
+
* Absolute value of each element, returning float
|
|
118
|
+
* NumPy behavior: fabs always returns floating point
|
|
119
|
+
*
|
|
120
|
+
* @param a - Input array storage
|
|
121
|
+
* @returns Result storage with absolute values as float
|
|
122
|
+
*/
|
|
123
|
+
export declare function fabs(a: ArrayStorage): ArrayStorage;
|
|
124
|
+
/**
|
|
125
|
+
* Returns both quotient and remainder (floor divide and modulo)
|
|
126
|
+
* NumPy behavior: divmod(a, b) = (floor_divide(a, b), mod(a, b))
|
|
127
|
+
*
|
|
128
|
+
* @param a - Dividend array storage
|
|
129
|
+
* @param b - Divisor (array storage or scalar)
|
|
130
|
+
* @returns Tuple of [quotient, remainder] storages
|
|
131
|
+
*/
|
|
132
|
+
export declare function divmod(a: ArrayStorage, b: ArrayStorage | number): [ArrayStorage, ArrayStorage];
|
|
133
|
+
/**
|
|
134
|
+
* Element-wise square of each element
|
|
135
|
+
* NumPy behavior: x**2
|
|
136
|
+
*
|
|
137
|
+
* @param a - Input array storage
|
|
138
|
+
* @returns Result storage with squared values
|
|
139
|
+
*/
|
|
140
|
+
export declare function square(a: ArrayStorage): ArrayStorage;
|
|
141
|
+
/**
|
|
142
|
+
* Remainder of division (same as mod)
|
|
143
|
+
* NumPy behavior: Same as mod, alias for compatibility
|
|
144
|
+
*
|
|
145
|
+
* @param a - Dividend array storage
|
|
146
|
+
* @param b - Divisor (array storage or scalar)
|
|
147
|
+
* @returns Result storage with remainder values
|
|
148
|
+
*/
|
|
149
|
+
export declare function remainder(a: ArrayStorage, b: ArrayStorage | number): ArrayStorage;
|
|
150
|
+
/**
|
|
151
|
+
* Heaviside step function
|
|
152
|
+
* NumPy behavior:
|
|
153
|
+
* heaviside(x1, x2) = 0 if x1 < 0
|
|
154
|
+
* = x2 if x1 == 0
|
|
155
|
+
* = 1 if x1 > 0
|
|
156
|
+
*
|
|
157
|
+
* @param x1 - Input array storage
|
|
158
|
+
* @param x2 - Value to use when x1 == 0 (array storage or scalar)
|
|
159
|
+
* @returns Result storage with heaviside values
|
|
160
|
+
*/
|
|
161
|
+
export declare function heaviside(x1: ArrayStorage, x2: ArrayStorage | number): ArrayStorage;
|
|
108
162
|
//# sourceMappingURL=arithmetic.d.ts.map
|