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
|
@@ -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,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Advanced array operations
|
|
3
|
+
*
|
|
4
|
+
* Broadcasting, indexing, and comparison functions.
|
|
5
|
+
* @module ops/advanced
|
|
6
|
+
*/
|
|
7
|
+
import { ArrayStorage } from '../core/storage';
|
|
8
|
+
/**
|
|
9
|
+
* Broadcast an array to a given shape
|
|
10
|
+
* Returns a read-only view on the original array
|
|
11
|
+
*/
|
|
12
|
+
export declare function broadcast_to(storage: ArrayStorage, targetShape: number[]): ArrayStorage;
|
|
13
|
+
/**
|
|
14
|
+
* Broadcast multiple arrays to a common shape
|
|
15
|
+
* Returns views on the original arrays
|
|
16
|
+
*/
|
|
17
|
+
export declare function broadcast_arrays(storages: ArrayStorage[]): ArrayStorage[];
|
|
18
|
+
/**
|
|
19
|
+
* Take elements from an array along an axis
|
|
20
|
+
*/
|
|
21
|
+
export declare function take(storage: ArrayStorage, indices: number[], axis?: number): ArrayStorage;
|
|
22
|
+
/**
|
|
23
|
+
* Put values at specified indices (modifies array in-place)
|
|
24
|
+
*/
|
|
25
|
+
export declare function put(storage: ArrayStorage, indices: number[], values: ArrayStorage | number | bigint): void;
|
|
26
|
+
/**
|
|
27
|
+
* Construct array from index array and choices
|
|
28
|
+
*/
|
|
29
|
+
export declare function choose(indexStorage: ArrayStorage, choices: ArrayStorage[]): ArrayStorage;
|
|
30
|
+
/**
|
|
31
|
+
* Check if two arrays are element-wise equal
|
|
32
|
+
*/
|
|
33
|
+
export declare function array_equal(a: ArrayStorage, b: ArrayStorage, equal_nan?: boolean): boolean;
|
|
34
|
+
//# sourceMappingURL=advanced.d.ts.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hyperbolic operations
|
|
3
|
+
*
|
|
4
|
+
* Pure functions for element-wise hyperbolic operations:
|
|
5
|
+
* sinh, cosh, tanh, arcsinh, arccosh, arctanh
|
|
6
|
+
*
|
|
7
|
+
* These functions are used by NDArray methods but are separated
|
|
8
|
+
* to keep the codebase modular and testable.
|
|
9
|
+
*/
|
|
10
|
+
import { ArrayStorage } from '../core/storage';
|
|
11
|
+
/**
|
|
12
|
+
* Hyperbolic sine of each element (element-wise)
|
|
13
|
+
* NumPy behavior: Always promotes to float64 for integer types
|
|
14
|
+
*
|
|
15
|
+
* @param a - Input array storage
|
|
16
|
+
* @returns Result storage with sinh applied
|
|
17
|
+
*/
|
|
18
|
+
export declare function sinh(a: ArrayStorage): ArrayStorage;
|
|
19
|
+
/**
|
|
20
|
+
* Hyperbolic cosine of each element (element-wise)
|
|
21
|
+
* NumPy behavior: Always promotes to float64 for integer types
|
|
22
|
+
*
|
|
23
|
+
* @param a - Input array storage
|
|
24
|
+
* @returns Result storage with cosh applied
|
|
25
|
+
*/
|
|
26
|
+
export declare function cosh(a: ArrayStorage): ArrayStorage;
|
|
27
|
+
/**
|
|
28
|
+
* Hyperbolic tangent of each element (element-wise)
|
|
29
|
+
* NumPy behavior: Always promotes to float64 for integer types
|
|
30
|
+
*
|
|
31
|
+
* @param a - Input array storage
|
|
32
|
+
* @returns Result storage with tanh applied
|
|
33
|
+
*/
|
|
34
|
+
export declare function tanh(a: ArrayStorage): ArrayStorage;
|
|
35
|
+
/**
|
|
36
|
+
* Inverse hyperbolic sine of each element (element-wise)
|
|
37
|
+
* NumPy behavior: Always promotes to float64 for integer types
|
|
38
|
+
*
|
|
39
|
+
* @param a - Input array storage
|
|
40
|
+
* @returns Result storage with arcsinh applied
|
|
41
|
+
*/
|
|
42
|
+
export declare function arcsinh(a: ArrayStorage): ArrayStorage;
|
|
43
|
+
/**
|
|
44
|
+
* Inverse hyperbolic cosine of each element (element-wise)
|
|
45
|
+
* NumPy behavior: Always promotes to float64 for integer types
|
|
46
|
+
*
|
|
47
|
+
* @param a - Input array storage (values >= 1)
|
|
48
|
+
* @returns Result storage with arccosh applied
|
|
49
|
+
*/
|
|
50
|
+
export declare function arccosh(a: ArrayStorage): ArrayStorage;
|
|
51
|
+
/**
|
|
52
|
+
* Inverse hyperbolic tangent of each element (element-wise)
|
|
53
|
+
* NumPy behavior: Always promotes to float64 for integer types
|
|
54
|
+
*
|
|
55
|
+
* @param a - Input array storage (values in range (-1, 1))
|
|
56
|
+
* @returns Result storage with arctanh applied
|
|
57
|
+
*/
|
|
58
|
+
export declare function arctanh(a: ArrayStorage): ArrayStorage;
|
|
59
|
+
//# sourceMappingURL=hyperbolic.d.ts.map
|
|
@@ -36,4 +36,65 @@ export declare function squeeze(storage: ArrayStorage, axis?: number): ArrayStor
|
|
|
36
36
|
* Returns a view with additional dimension
|
|
37
37
|
*/
|
|
38
38
|
export declare function expandDims(storage: ArrayStorage, axis: number): ArrayStorage;
|
|
39
|
+
/**
|
|
40
|
+
* Swap two axes of an array
|
|
41
|
+
* Returns a view with axes swapped
|
|
42
|
+
*/
|
|
43
|
+
export declare function swapaxes(storage: ArrayStorage, axis1: number, axis2: number): ArrayStorage;
|
|
44
|
+
/**
|
|
45
|
+
* Move axes to new positions
|
|
46
|
+
* Returns a view with axes moved
|
|
47
|
+
*/
|
|
48
|
+
export declare function moveaxis(storage: ArrayStorage, source: number | number[], destination: number | number[]): ArrayStorage;
|
|
49
|
+
/**
|
|
50
|
+
* Concatenate arrays along an axis
|
|
51
|
+
*/
|
|
52
|
+
export declare function concatenate(storages: ArrayStorage[], axis?: number): ArrayStorage;
|
|
53
|
+
/**
|
|
54
|
+
* Stack arrays along a new axis
|
|
55
|
+
*/
|
|
56
|
+
export declare function stack(storages: ArrayStorage[], axis?: number): ArrayStorage;
|
|
57
|
+
/**
|
|
58
|
+
* Stack arrays vertically (row-wise)
|
|
59
|
+
* vstack is equivalent to concatenation along the first axis after
|
|
60
|
+
* 1-D arrays of shape (N,) have been reshaped to (1,N)
|
|
61
|
+
*/
|
|
62
|
+
export declare function vstack(storages: ArrayStorage[]): ArrayStorage;
|
|
63
|
+
/**
|
|
64
|
+
* Stack arrays horizontally (column-wise)
|
|
65
|
+
* hstack is equivalent to concatenation along the second axis,
|
|
66
|
+
* except for 1-D arrays where it concatenates along the first axis
|
|
67
|
+
*/
|
|
68
|
+
export declare function hstack(storages: ArrayStorage[]): ArrayStorage;
|
|
69
|
+
/**
|
|
70
|
+
* Stack arrays depth-wise (along third axis)
|
|
71
|
+
* dstack is equivalent to concatenation along the third axis after
|
|
72
|
+
* 2-D arrays of shape (M,N) have been reshaped to (M,N,1) and
|
|
73
|
+
* 1-D arrays of shape (N,) have been reshaped to (1,N,1)
|
|
74
|
+
*/
|
|
75
|
+
export declare function dstack(storages: ArrayStorage[]): ArrayStorage;
|
|
76
|
+
/**
|
|
77
|
+
* Split array into sub-arrays
|
|
78
|
+
*/
|
|
79
|
+
export declare function split(storage: ArrayStorage, indicesOrSections: number | number[], axis?: number): ArrayStorage[];
|
|
80
|
+
/**
|
|
81
|
+
* Split array into sub-arrays (allows unequal splits)
|
|
82
|
+
*/
|
|
83
|
+
export declare function arraySplit(storage: ArrayStorage, indicesOrSections: number | number[], axis?: number): ArrayStorage[];
|
|
84
|
+
/**
|
|
85
|
+
* Split array vertically (row-wise)
|
|
86
|
+
*/
|
|
87
|
+
export declare function vsplit(storage: ArrayStorage, indicesOrSections: number | number[]): ArrayStorage[];
|
|
88
|
+
/**
|
|
89
|
+
* Split array horizontally (column-wise)
|
|
90
|
+
*/
|
|
91
|
+
export declare function hsplit(storage: ArrayStorage, indicesOrSections: number | number[]): ArrayStorage[];
|
|
92
|
+
/**
|
|
93
|
+
* Tile array by repeating along each axis
|
|
94
|
+
*/
|
|
95
|
+
export declare function tile(storage: ArrayStorage, reps: number | number[]): ArrayStorage;
|
|
96
|
+
/**
|
|
97
|
+
* Repeat elements of an array
|
|
98
|
+
*/
|
|
99
|
+
export declare function repeat(storage: ArrayStorage, repeats: number | number[], axis?: number): ArrayStorage;
|
|
39
100
|
//# sourceMappingURL=shape.d.ts.map
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trigonometric operations
|
|
3
|
+
*
|
|
4
|
+
* Pure functions for element-wise trigonometric operations:
|
|
5
|
+
* sin, cos, tan, arcsin, arccos, arctan, arctan2, hypot, degrees, radians
|
|
6
|
+
*
|
|
7
|
+
* These functions are used by NDArray methods but are separated
|
|
8
|
+
* to keep the codebase modular and testable.
|
|
9
|
+
*/
|
|
10
|
+
import { ArrayStorage } from '../core/storage';
|
|
11
|
+
/**
|
|
12
|
+
* Sine of each element (element-wise)
|
|
13
|
+
* NumPy behavior: Always promotes to float64 for integer types
|
|
14
|
+
*
|
|
15
|
+
* @param a - Input array storage (angles in radians)
|
|
16
|
+
* @returns Result storage with sin applied
|
|
17
|
+
*/
|
|
18
|
+
export declare function sin(a: ArrayStorage): ArrayStorage;
|
|
19
|
+
/**
|
|
20
|
+
* Cosine of each element (element-wise)
|
|
21
|
+
* NumPy behavior: Always promotes to float64 for integer types
|
|
22
|
+
*
|
|
23
|
+
* @param a - Input array storage (angles in radians)
|
|
24
|
+
* @returns Result storage with cos applied
|
|
25
|
+
*/
|
|
26
|
+
export declare function cos(a: ArrayStorage): ArrayStorage;
|
|
27
|
+
/**
|
|
28
|
+
* Tangent of each element (element-wise)
|
|
29
|
+
* NumPy behavior: Always promotes to float64 for integer types
|
|
30
|
+
*
|
|
31
|
+
* @param a - Input array storage (angles in radians)
|
|
32
|
+
* @returns Result storage with tan applied
|
|
33
|
+
*/
|
|
34
|
+
export declare function tan(a: ArrayStorage): ArrayStorage;
|
|
35
|
+
/**
|
|
36
|
+
* Inverse sine of each element (element-wise)
|
|
37
|
+
* NumPy behavior: Always promotes to float64 for integer types
|
|
38
|
+
*
|
|
39
|
+
* @param a - Input array storage (values in range [-1, 1])
|
|
40
|
+
* @returns Result storage with arcsin applied (radians)
|
|
41
|
+
*/
|
|
42
|
+
export declare function arcsin(a: ArrayStorage): ArrayStorage;
|
|
43
|
+
/**
|
|
44
|
+
* Inverse cosine of each element (element-wise)
|
|
45
|
+
* NumPy behavior: Always promotes to float64 for integer types
|
|
46
|
+
*
|
|
47
|
+
* @param a - Input array storage (values in range [-1, 1])
|
|
48
|
+
* @returns Result storage with arccos applied (radians)
|
|
49
|
+
*/
|
|
50
|
+
export declare function arccos(a: ArrayStorage): ArrayStorage;
|
|
51
|
+
/**
|
|
52
|
+
* Inverse tangent of each element (element-wise)
|
|
53
|
+
* NumPy behavior: Always promotes to float64 for integer types
|
|
54
|
+
*
|
|
55
|
+
* @param a - Input array storage
|
|
56
|
+
* @returns Result storage with arctan applied (radians)
|
|
57
|
+
*/
|
|
58
|
+
export declare function arctan(a: ArrayStorage): ArrayStorage;
|
|
59
|
+
/**
|
|
60
|
+
* Element-wise arc tangent of x1/x2 choosing the quadrant correctly.
|
|
61
|
+
* NumPy behavior: Always promotes to float64 for integer types
|
|
62
|
+
*
|
|
63
|
+
* @param x1 - y-coordinates
|
|
64
|
+
* @param x2 - x-coordinates (array storage or scalar)
|
|
65
|
+
* @returns Angle in radians between -π and π
|
|
66
|
+
*/
|
|
67
|
+
export declare function arctan2(x1: ArrayStorage, x2: ArrayStorage | number): ArrayStorage;
|
|
68
|
+
/**
|
|
69
|
+
* Given the "legs" of a right triangle, return its hypotenuse.
|
|
70
|
+
* Equivalent to sqrt(x1**2 + x2**2), element-wise.
|
|
71
|
+
* NumPy behavior: Always promotes to float64 for integer types
|
|
72
|
+
*
|
|
73
|
+
* @param x1 - First leg
|
|
74
|
+
* @param x2 - Second leg (array storage or scalar)
|
|
75
|
+
* @returns Hypotenuse
|
|
76
|
+
*/
|
|
77
|
+
export declare function hypot(x1: ArrayStorage, x2: ArrayStorage | number): ArrayStorage;
|
|
78
|
+
/**
|
|
79
|
+
* Convert angles from radians to degrees.
|
|
80
|
+
* NumPy behavior: Always promotes to float64 for integer types
|
|
81
|
+
*
|
|
82
|
+
* @param a - Input array storage (angles in radians)
|
|
83
|
+
* @returns Angles in degrees
|
|
84
|
+
*/
|
|
85
|
+
export declare function degrees(a: ArrayStorage): ArrayStorage;
|
|
86
|
+
/**
|
|
87
|
+
* Convert angles from degrees to radians.
|
|
88
|
+
* NumPy behavior: Always promotes to float64 for integer types
|
|
89
|
+
*
|
|
90
|
+
* @param a - Input array storage (angles in degrees)
|
|
91
|
+
* @returns Angles in radians
|
|
92
|
+
*/
|
|
93
|
+
export declare function radians(a: ArrayStorage): ArrayStorage;
|
|
94
|
+
//# sourceMappingURL=trig.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "numpy-ts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Complete NumPy implementation for TypeScript and JavaScript (under construction)",
|
|
5
5
|
"main": "dist/numpy-ts.node.cjs",
|
|
6
6
|
"browser": "dist/numpy-ts.browser.js",
|
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
"files": [
|
|
11
11
|
"dist/**/*.js",
|
|
12
12
|
"dist/**/*.cjs",
|
|
13
|
+
"dist/**/*.mjs",
|
|
14
|
+
"dist/**/*.cjs.map",
|
|
15
|
+
"dist/**/*.mjs.map",
|
|
13
16
|
"dist/types/**/*.d.ts",
|
|
14
17
|
"README.md",
|
|
15
18
|
"LICENSE"
|
|
@@ -23,10 +26,18 @@
|
|
|
23
26
|
},
|
|
24
27
|
"./node": {
|
|
25
28
|
"types": "./dist/types/node.d.ts",
|
|
26
|
-
"
|
|
29
|
+
"import": "./dist/numpy-ts.node-io.mjs",
|
|
30
|
+
"require": "./dist/numpy-ts.node-io.cjs",
|
|
31
|
+
"default": "./dist/numpy-ts.node-io.cjs"
|
|
32
|
+
},
|
|
33
|
+
"./io": {
|
|
34
|
+
"types": "./dist/types/io/index.d.ts",
|
|
35
|
+
"node": "./dist/numpy-ts.node.cjs",
|
|
36
|
+
"browser": "./dist/numpy-ts.browser.js",
|
|
37
|
+
"default": "./dist/numpy-ts.esm.js"
|
|
27
38
|
},
|
|
28
39
|
"./browser": {
|
|
29
|
-
"types": "./dist/types/
|
|
40
|
+
"types": "./dist/types/index.d.ts",
|
|
30
41
|
"default": "./dist/numpy-ts.browser.js"
|
|
31
42
|
}
|
|
32
43
|
},
|
|
@@ -57,7 +68,8 @@
|
|
|
57
68
|
"bench:large": "npm run bench:build && node benchmarks/dist/bench.cjs --large",
|
|
58
69
|
"bench:category": "npm run bench:build && node benchmarks/dist/bench.cjs --category",
|
|
59
70
|
"bench:view": "open benchmarks/results/plots/latest.html || xdg-open benchmarks/results/plots/latest.html",
|
|
60
|
-
"bench:large:view": "open benchmarks/results/plots/latest-large.html || xdg-open benchmarks/results/plots/latest-large.html"
|
|
71
|
+
"bench:large:view": "open benchmarks/results/plots/latest-large.html || xdg-open benchmarks/results/plots/latest-large.html",
|
|
72
|
+
"compare-api": "python3 scripts/compare-api-coverage.py"
|
|
61
73
|
},
|
|
62
74
|
"keywords": [
|
|
63
75
|
"numpy",
|
|
@@ -81,7 +93,7 @@
|
|
|
81
93
|
"bugs": {
|
|
82
94
|
"url": "https://github.com/dupontcyborg/numpy-ts/issues"
|
|
83
95
|
},
|
|
84
|
-
"homepage": "https://github.com/dupontcyborg/numpy-ts
|
|
96
|
+
"homepage": "https://github.com/dupontcyborg/numpy-ts",
|
|
85
97
|
"devDependencies": {
|
|
86
98
|
"@types/node": "^24.9.1",
|
|
87
99
|
"@typescript-eslint/eslint-plugin": "^8.46.2",
|
|
@@ -105,7 +117,7 @@
|
|
|
105
117
|
"vitest": "^4.0.3"
|
|
106
118
|
},
|
|
107
119
|
"engines": {
|
|
108
|
-
"node": ">=
|
|
120
|
+
"node": ">=20.1.0"
|
|
109
121
|
},
|
|
110
122
|
"overrides": {
|
|
111
123
|
"js-yaml": ">=4.1.1"
|