numpy-ts 0.3.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 -297
- package/dist/numpy-ts.browser.js +2 -397
- package/dist/numpy-ts.esm.js +2 -397
- 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 -412
- package/dist/numpy-ts.node.cjs.map +7 -0
- package/dist/types/core/ndarray.d.ts +477 -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/linalg.d.ts +79 -0
- package/dist/types/ops/shape.d.ts +61 -0
- package/dist/types/ops/trig.d.ts +94 -0
- package/package.json +18 -10
|
@@ -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,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
|
|
@@ -5,12 +5,91 @@
|
|
|
5
5
|
* @module ops/linalg
|
|
6
6
|
*/
|
|
7
7
|
import { ArrayStorage } from '../core/storage';
|
|
8
|
+
/**
|
|
9
|
+
* Dot product of two arrays (fully NumPy-compatible)
|
|
10
|
+
*
|
|
11
|
+
* Behavior depends on input dimensions:
|
|
12
|
+
* - 0D · 0D: Multiply scalars → scalar
|
|
13
|
+
* - 0D · ND or ND · 0D: Element-wise multiply → ND
|
|
14
|
+
* - 1D · 1D: Inner product → scalar
|
|
15
|
+
* - 2D · 2D: Matrix multiplication → 2D
|
|
16
|
+
* - 2D · 1D: Matrix-vector product → 1D
|
|
17
|
+
* - 1D · 2D: Vector-matrix product → 1D
|
|
18
|
+
* - ND · 1D (N≥2): Sum product over last axis of a → (N-1)D
|
|
19
|
+
* - 1D · ND (N≥2): Sum product over first axis of b → (N-1)D
|
|
20
|
+
* - ND · MD (N,M≥2): Sum product over last axis of a and second-to-last of b → (N+M-2)D
|
|
21
|
+
*
|
|
22
|
+
* For 2D·2D, prefer using matmul() instead.
|
|
23
|
+
*/
|
|
24
|
+
export declare function dot(a: ArrayStorage, b: ArrayStorage): ArrayStorage | number | bigint;
|
|
8
25
|
/**
|
|
9
26
|
* Matrix multiplication
|
|
10
27
|
* Requires 2D arrays with compatible shapes
|
|
11
28
|
*
|
|
29
|
+
* Automatically detects transposed/non-contiguous arrays via strides
|
|
30
|
+
* and uses appropriate DGEMM transpose parameters.
|
|
31
|
+
*
|
|
12
32
|
* Note: Currently uses float64 precision for all operations.
|
|
13
33
|
* Integer inputs are promoted to float64 (matching NumPy behavior).
|
|
14
34
|
*/
|
|
15
35
|
export declare function matmul(a: ArrayStorage, b: ArrayStorage): ArrayStorage;
|
|
36
|
+
/**
|
|
37
|
+
* Sum along the diagonal of a 2D array
|
|
38
|
+
*
|
|
39
|
+
* Computes the trace (sum of diagonal elements) of a matrix.
|
|
40
|
+
* For non-square matrices, sums along the diagonal up to min(rows, cols).
|
|
41
|
+
*
|
|
42
|
+
* @param a - Input 2D array
|
|
43
|
+
* @returns Sum of diagonal elements
|
|
44
|
+
*/
|
|
45
|
+
export declare function trace(a: ArrayStorage): number | bigint;
|
|
46
|
+
/**
|
|
47
|
+
* Permute the dimensions of an array
|
|
48
|
+
*
|
|
49
|
+
* Standalone version of NDArray.transpose() method.
|
|
50
|
+
* Returns a view with axes permuted.
|
|
51
|
+
*
|
|
52
|
+
* @param a - Input array
|
|
53
|
+
* @param axes - Optional permutation of axes (defaults to reverse order)
|
|
54
|
+
* @returns Transposed view
|
|
55
|
+
*/
|
|
56
|
+
export declare function transpose(a: ArrayStorage, axes?: number[]): ArrayStorage;
|
|
57
|
+
/**
|
|
58
|
+
* Inner product of two arrays
|
|
59
|
+
*
|
|
60
|
+
* Computes sum product over the LAST axes of both a and b.
|
|
61
|
+
* - 1D · 1D: Same as dot (ordinary inner product) → scalar
|
|
62
|
+
* - ND · MD: Contracts last dimension of each → (*a.shape[:-1], *b.shape[:-1])
|
|
63
|
+
*
|
|
64
|
+
* Different from dot: always uses last axis of BOTH arrays.
|
|
65
|
+
*
|
|
66
|
+
* @param a - First array
|
|
67
|
+
* @param b - Second array
|
|
68
|
+
* @returns Inner product result
|
|
69
|
+
*/
|
|
70
|
+
export declare function inner(a: ArrayStorage, b: ArrayStorage): ArrayStorage | number | bigint;
|
|
71
|
+
/**
|
|
72
|
+
* Outer product of two vectors
|
|
73
|
+
*
|
|
74
|
+
* Computes out[i, j] = a[i] * b[j]
|
|
75
|
+
* Input arrays are flattened if not 1D.
|
|
76
|
+
*
|
|
77
|
+
* @param a - First input (flattened to 1D)
|
|
78
|
+
* @param b - Second input (flattened to 1D)
|
|
79
|
+
* @returns 2D array of shape (a.size, b.size)
|
|
80
|
+
*/
|
|
81
|
+
export declare function outer(a: ArrayStorage, b: ArrayStorage): ArrayStorage;
|
|
82
|
+
/**
|
|
83
|
+
* Tensor dot product along specified axes
|
|
84
|
+
*
|
|
85
|
+
* Computes sum product over specified axes.
|
|
86
|
+
*
|
|
87
|
+
* @param a - First array
|
|
88
|
+
* @param b - Second array
|
|
89
|
+
* @param axes - Axes to contract:
|
|
90
|
+
* - Integer N: Contract last N axes of a with first N of b
|
|
91
|
+
* - [a_axes, b_axes]: Contract specified axes
|
|
92
|
+
* @returns Tensor dot product
|
|
93
|
+
*/
|
|
94
|
+
export declare function tensordot(a: ArrayStorage, b: ArrayStorage, axes: number | [number[], number[]]): ArrayStorage | number | bigint;
|
|
16
95
|
//# sourceMappingURL=linalg.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
|