numpy-ts 0.7.0 → 0.9.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 +15 -15
- package/dist/numpy-ts.browser.js +2 -2
- package/dist/numpy-ts.esm.js +2 -2
- package/dist/numpy-ts.node-io.cjs +3 -2
- package/dist/numpy-ts.node-io.cjs.map +4 -4
- package/dist/numpy-ts.node-io.mjs +3 -2
- package/dist/numpy-ts.node-io.mjs.map +4 -4
- package/dist/numpy-ts.node.cjs +2 -2
- package/dist/numpy-ts.node.cjs.map +4 -4
- package/dist/types/core/ndarray.d.ts +526 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/io/index.d.ts +5 -4
- package/dist/types/io/txt/index.d.ts +12 -0
- package/dist/types/io/txt/parser.d.ts +109 -0
- package/dist/types/io/txt/serializer.d.ts +67 -0
- package/dist/types/node.d.ts +122 -0
- package/dist/types/ops/exponential.d.ts +79 -1
- package/dist/types/ops/gradient.d.ts +57 -0
- package/dist/types/ops/linalg.d.ts +220 -0
- package/dist/types/ops/rounding.d.ts +36 -0
- package/dist/types/ops/sets.d.ts +38 -0
- package/dist/types/ops/sorting.d.ts +95 -0
- package/package.json +1 -1
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text file parsing for numpy-ts
|
|
3
|
+
*
|
|
4
|
+
* Provides NumPy-compatible loadtxt/genfromtxt functionality.
|
|
5
|
+
* These functions work with strings and are environment-agnostic.
|
|
6
|
+
*/
|
|
7
|
+
import { NDArray } from '../../core/ndarray';
|
|
8
|
+
import type { DType } from '../../core/dtype';
|
|
9
|
+
/**
|
|
10
|
+
* Options for parsing text data
|
|
11
|
+
*/
|
|
12
|
+
export interface ParseTxtOptions {
|
|
13
|
+
/**
|
|
14
|
+
* The string used to separate values.
|
|
15
|
+
* By default, any consecutive whitespace acts as delimiter.
|
|
16
|
+
* If specified, the exact delimiter is used.
|
|
17
|
+
*/
|
|
18
|
+
delimiter?: string;
|
|
19
|
+
/**
|
|
20
|
+
* The character used to indicate the start of a comment.
|
|
21
|
+
* Lines beginning with this character (after stripping whitespace) will be skipped.
|
|
22
|
+
* Default: '#'
|
|
23
|
+
*/
|
|
24
|
+
comments?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Skip the first `skiprows` lines.
|
|
27
|
+
* Default: 0
|
|
28
|
+
*/
|
|
29
|
+
skiprows?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Which columns to read, with 0 being the first.
|
|
32
|
+
* If not specified, all columns are read.
|
|
33
|
+
*/
|
|
34
|
+
usecols?: number | number[];
|
|
35
|
+
/**
|
|
36
|
+
* Read only the first `max_rows` lines of content after `skiprows`.
|
|
37
|
+
* Default: read all rows
|
|
38
|
+
*/
|
|
39
|
+
max_rows?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Data type of the resulting array.
|
|
42
|
+
* Default: 'float64'
|
|
43
|
+
*/
|
|
44
|
+
dtype?: DType;
|
|
45
|
+
/**
|
|
46
|
+
* What encoding to use when reading the file.
|
|
47
|
+
* Only relevant for Node.js file operations.
|
|
48
|
+
* Default: 'utf-8'
|
|
49
|
+
*/
|
|
50
|
+
encoding?: string;
|
|
51
|
+
/**
|
|
52
|
+
* The string representation of a missing value.
|
|
53
|
+
* Used by genfromtxt. When encountered, the value is replaced with `filling_values`.
|
|
54
|
+
*/
|
|
55
|
+
missing_values?: string | string[];
|
|
56
|
+
/**
|
|
57
|
+
* The value to use for missing values.
|
|
58
|
+
* Default: NaN for floating point, 0 for integers
|
|
59
|
+
*/
|
|
60
|
+
filling_values?: number;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Parse text data into an NDArray.
|
|
64
|
+
*
|
|
65
|
+
* This is the browser-compatible core function. For file operations in Node.js,
|
|
66
|
+
* use `loadtxt` from 'numpy-ts/node'.
|
|
67
|
+
*
|
|
68
|
+
* @param text - The text content to parse
|
|
69
|
+
* @param options - Parsing options
|
|
70
|
+
* @returns NDArray with the parsed data
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const text = "1 2 3\n4 5 6\n7 8 9";
|
|
75
|
+
* const arr = parseTxt(text);
|
|
76
|
+
* // arr.shape = [3, 3]
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare function parseTxt(text: string, options?: ParseTxtOptions): NDArray;
|
|
80
|
+
/**
|
|
81
|
+
* Parse text data into an NDArray with more flexible handling.
|
|
82
|
+
*
|
|
83
|
+
* Similar to parseTxt but handles missing values more gracefully.
|
|
84
|
+
* This is the browser-compatible version.
|
|
85
|
+
*
|
|
86
|
+
* @param text - The text content to parse
|
|
87
|
+
* @param options - Parsing options
|
|
88
|
+
* @returns NDArray with the parsed data
|
|
89
|
+
*/
|
|
90
|
+
export declare function genfromtxt(text: string, options?: ParseTxtOptions): NDArray;
|
|
91
|
+
/**
|
|
92
|
+
* Parse text data using a regular expression.
|
|
93
|
+
*
|
|
94
|
+
* Extract data from each line using regex groups.
|
|
95
|
+
*
|
|
96
|
+
* @param text - The text content to parse
|
|
97
|
+
* @param regexp - Regular expression with groups to extract values
|
|
98
|
+
* @param dtype - Data type of the resulting array (default: 'float64')
|
|
99
|
+
* @returns NDArray with the parsed data
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* const text = "x=1.0, y=2.0\nx=3.0, y=4.0";
|
|
104
|
+
* const arr = fromregex(text, /x=([\d.]+), y=([\d.]+)/);
|
|
105
|
+
* // arr = [[1.0, 2.0], [3.0, 4.0]]
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export declare function fromregex(text: string, regexp: RegExp | string, dtype?: DType): NDArray;
|
|
109
|
+
//# sourceMappingURL=parser.d.ts.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text file serialization for numpy-ts
|
|
3
|
+
*
|
|
4
|
+
* Provides NumPy-compatible savetxt functionality.
|
|
5
|
+
* These functions work with strings and are environment-agnostic.
|
|
6
|
+
*/
|
|
7
|
+
import { NDArray } from '../../core/ndarray';
|
|
8
|
+
/**
|
|
9
|
+
* Options for serializing array to text
|
|
10
|
+
*/
|
|
11
|
+
export interface SerializeTxtOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Format string for a single value.
|
|
14
|
+
* Uses a simplified printf-style format:
|
|
15
|
+
* - '%.6f' - 6 decimal places (default for floats)
|
|
16
|
+
* - '%.2e' - scientific notation with 2 decimal places
|
|
17
|
+
* - '%d' - integer
|
|
18
|
+
* - '%s' - string representation
|
|
19
|
+
*
|
|
20
|
+
* Default: '%.18e' (NumPy default for full precision)
|
|
21
|
+
*/
|
|
22
|
+
fmt?: string;
|
|
23
|
+
/**
|
|
24
|
+
* String or character separating columns.
|
|
25
|
+
* Default: ' ' (single space)
|
|
26
|
+
*/
|
|
27
|
+
delimiter?: string;
|
|
28
|
+
/**
|
|
29
|
+
* String that will be written at the end of each row.
|
|
30
|
+
* Default: '\n'
|
|
31
|
+
*/
|
|
32
|
+
newline?: string;
|
|
33
|
+
/**
|
|
34
|
+
* String that will be written at the beginning of the file.
|
|
35
|
+
* Will be prepended with the comment character if it doesn't start with one.
|
|
36
|
+
*/
|
|
37
|
+
header?: string;
|
|
38
|
+
/**
|
|
39
|
+
* String that will be written at the end of the file.
|
|
40
|
+
*/
|
|
41
|
+
footer?: string;
|
|
42
|
+
/**
|
|
43
|
+
* String that will be prepended to the header and footer strings,
|
|
44
|
+
* to mark them as comments.
|
|
45
|
+
* Default: '# '
|
|
46
|
+
*/
|
|
47
|
+
comments?: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Serialize an NDArray to text format.
|
|
51
|
+
*
|
|
52
|
+
* This is the browser-compatible core function. For file operations in Node.js,
|
|
53
|
+
* use `savetxt` from 'numpy-ts/node'.
|
|
54
|
+
*
|
|
55
|
+
* @param arr - The array to serialize (must be 1D or 2D)
|
|
56
|
+
* @param options - Serialization options
|
|
57
|
+
* @returns String representation of the array
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const arr = np.array([[1, 2, 3], [4, 5, 6]]);
|
|
62
|
+
* const text = serializeTxt(arr, { delimiter: ',' });
|
|
63
|
+
* // "1.000000000000000000e+00,2.000000000000000000e+00,3.000000000000000000e+00\n4.000000000000000000e+00,5.000000000000000000e+00,6.000000000000000000e+00\n"
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export declare function serializeTxt(arr: NDArray, options?: SerializeTxtOptions): string;
|
|
67
|
+
//# sourceMappingURL=serializer.d.ts.map
|
package/dist/types/node.d.ts
CHANGED
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
import { NDArray } from './core/ndarray';
|
|
16
16
|
import { type NpzParseOptions, type NpzParseResult } from './io/npz/parser';
|
|
17
17
|
import { type NpzSerializeOptions, type NpzArraysInput } from './io/npz/serializer';
|
|
18
|
+
import { type ParseTxtOptions, type SerializeTxtOptions } from './io/txt';
|
|
19
|
+
import type { DType } from './core/dtype';
|
|
18
20
|
export * from './index';
|
|
19
21
|
export * from './io';
|
|
20
22
|
/**
|
|
@@ -151,4 +153,124 @@ export declare function savez(path: string, arrays: NpzArraysInput): Promise<voi
|
|
|
151
153
|
* @param arrays - Arrays to save (same input types as savez)
|
|
152
154
|
*/
|
|
153
155
|
export declare function savez_compressed(path: string, arrays: NpzArraysInput): Promise<void>;
|
|
156
|
+
/**
|
|
157
|
+
* Options for loadtxt
|
|
158
|
+
*/
|
|
159
|
+
export interface LoadTxtOptions extends ParseTxtOptions {
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Options for savetxt
|
|
163
|
+
*/
|
|
164
|
+
export interface SaveTxtOptions extends SerializeTxtOptions {
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Load data from a text file.
|
|
168
|
+
*
|
|
169
|
+
* Each row in the text file must have the same number of values.
|
|
170
|
+
*
|
|
171
|
+
* @param path - Path to the text file
|
|
172
|
+
* @param options - Load options
|
|
173
|
+
* @returns NDArray with the loaded data
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* // Load a CSV file
|
|
178
|
+
* const arr = await loadtxt('data.csv', { delimiter: ',' });
|
|
179
|
+
*
|
|
180
|
+
* // Load with specific columns
|
|
181
|
+
* const arr = await loadtxt('data.txt', { usecols: [0, 2] });
|
|
182
|
+
*
|
|
183
|
+
* // Skip header rows
|
|
184
|
+
* const arr = await loadtxt('data.txt', { skiprows: 1 });
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
export declare function loadtxt(path: string, options?: LoadTxtOptions): Promise<NDArray>;
|
|
188
|
+
/**
|
|
189
|
+
* Synchronously load data from a text file.
|
|
190
|
+
*
|
|
191
|
+
* @param path - Path to the text file
|
|
192
|
+
* @param options - Load options
|
|
193
|
+
* @returns NDArray with the loaded data
|
|
194
|
+
*/
|
|
195
|
+
export declare function loadtxtSync(path: string, options?: LoadTxtOptions): NDArray;
|
|
196
|
+
/**
|
|
197
|
+
* Save an array to a text file.
|
|
198
|
+
*
|
|
199
|
+
* @param path - Path to save the text file
|
|
200
|
+
* @param arr - The array to save (must be 1D or 2D)
|
|
201
|
+
* @param options - Save options
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```typescript
|
|
205
|
+
* // Save as CSV
|
|
206
|
+
* await savetxt('data.csv', arr, { delimiter: ',' });
|
|
207
|
+
*
|
|
208
|
+
* // Save with custom format
|
|
209
|
+
* await savetxt('data.txt', arr, { fmt: '%.2f', delimiter: '\t' });
|
|
210
|
+
*
|
|
211
|
+
* // Save with header
|
|
212
|
+
* await savetxt('data.txt', arr, { header: 'x y z' });
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
export declare function savetxt(path: string, arr: NDArray, options?: SaveTxtOptions): Promise<void>;
|
|
216
|
+
/**
|
|
217
|
+
* Synchronously save an array to a text file.
|
|
218
|
+
*
|
|
219
|
+
* @param path - Path to save the text file
|
|
220
|
+
* @param arr - The array to save (must be 1D or 2D)
|
|
221
|
+
* @param options - Save options
|
|
222
|
+
*/
|
|
223
|
+
export declare function savetxtSync(path: string, arr: NDArray, options?: SaveTxtOptions): void;
|
|
224
|
+
/**
|
|
225
|
+
* Load data from a text file with more flexible handling.
|
|
226
|
+
*
|
|
227
|
+
* Similar to loadtxt but handles missing values more gracefully.
|
|
228
|
+
*
|
|
229
|
+
* @param path - Path to the text file
|
|
230
|
+
* @param options - Load options
|
|
231
|
+
* @returns NDArray with the loaded data
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* // Load file with missing values
|
|
236
|
+
* const arr = await genfromtxt('data.csv', {
|
|
237
|
+
* delimiter: ',',
|
|
238
|
+
* missing_values: ['NA', ''],
|
|
239
|
+
* filling_values: 0
|
|
240
|
+
* });
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
export declare function genfromtxt(path: string, options?: LoadTxtOptions): Promise<NDArray>;
|
|
244
|
+
/**
|
|
245
|
+
* Synchronously load data from a text file with more flexible handling.
|
|
246
|
+
*
|
|
247
|
+
* @param path - Path to the text file
|
|
248
|
+
* @param options - Load options
|
|
249
|
+
* @returns NDArray with the loaded data
|
|
250
|
+
*/
|
|
251
|
+
export declare function genfromtxtSync(path: string, options?: LoadTxtOptions): NDArray;
|
|
252
|
+
/**
|
|
253
|
+
* Load data from a text file using regular expressions.
|
|
254
|
+
*
|
|
255
|
+
* @param path - Path to the text file
|
|
256
|
+
* @param regexp - Regular expression with capture groups for extracting values
|
|
257
|
+
* @param dtype - Data type of the resulting array (default: 'float64')
|
|
258
|
+
* @returns NDArray with the extracted data
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```typescript
|
|
262
|
+
* // Extract x,y pairs from "Point: x=1.0, y=2.0" format
|
|
263
|
+
* const arr = await fromregex('points.txt', /x=([\d.]+), y=([\d.]+)/);
|
|
264
|
+
* ```
|
|
265
|
+
*/
|
|
266
|
+
export declare function fromregex(path: string, regexp: RegExp | string, dtype?: DType): Promise<NDArray>;
|
|
267
|
+
/**
|
|
268
|
+
* Synchronously load data from a text file using regular expressions.
|
|
269
|
+
*
|
|
270
|
+
* @param path - Path to the text file
|
|
271
|
+
* @param regexp - Regular expression with capture groups for extracting values
|
|
272
|
+
* @param dtype - Data type of the resulting array (default: 'float64')
|
|
273
|
+
* @returns NDArray with the extracted data
|
|
274
|
+
*/
|
|
275
|
+
export declare function fromregexSync(path: string, regexp: RegExp | string, dtype?: DType): NDArray;
|
|
154
276
|
//# sourceMappingURL=node.d.ts.map
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Exponential, logarithmic, and power operations
|
|
3
3
|
*
|
|
4
4
|
* Pure functions for element-wise exponential operations:
|
|
5
|
-
* exp, log, sqrt, power
|
|
5
|
+
* exp, exp2, expm1, log, log2, log10, log1p, logaddexp, logaddexp2, sqrt, power
|
|
6
6
|
*
|
|
7
7
|
* These functions are used by NDArray methods but are separated
|
|
8
8
|
* to keep the codebase modular and testable.
|
|
@@ -25,4 +25,82 @@ export declare function sqrt(a: ArrayStorage): ArrayStorage;
|
|
|
25
25
|
* @returns Result storage with power applied
|
|
26
26
|
*/
|
|
27
27
|
export declare function power(a: ArrayStorage, b: ArrayStorage | number): ArrayStorage;
|
|
28
|
+
/**
|
|
29
|
+
* Natural exponential function (e^x) for each element
|
|
30
|
+
* NumPy behavior: Always promotes to float64 for integer types
|
|
31
|
+
*
|
|
32
|
+
* @param a - Input array storage
|
|
33
|
+
* @returns Result storage with exp applied
|
|
34
|
+
*/
|
|
35
|
+
export declare function exp(a: ArrayStorage): ArrayStorage;
|
|
36
|
+
/**
|
|
37
|
+
* Base-2 exponential function (2^x) for each element
|
|
38
|
+
* NumPy behavior: Always promotes to float64 for integer types
|
|
39
|
+
*
|
|
40
|
+
* @param a - Input array storage
|
|
41
|
+
* @returns Result storage with 2^x applied
|
|
42
|
+
*/
|
|
43
|
+
export declare function exp2(a: ArrayStorage): ArrayStorage;
|
|
44
|
+
/**
|
|
45
|
+
* Exponential minus one (e^x - 1) for each element
|
|
46
|
+
* More accurate than exp(x) - 1 for small x
|
|
47
|
+
* NumPy behavior: Always promotes to float64 for integer types
|
|
48
|
+
*
|
|
49
|
+
* @param a - Input array storage
|
|
50
|
+
* @returns Result storage with expm1 applied
|
|
51
|
+
*/
|
|
52
|
+
export declare function expm1(a: ArrayStorage): ArrayStorage;
|
|
53
|
+
/**
|
|
54
|
+
* Natural logarithm (ln) for each element
|
|
55
|
+
* NumPy behavior: Always promotes to float64 for integer types
|
|
56
|
+
*
|
|
57
|
+
* @param a - Input array storage
|
|
58
|
+
* @returns Result storage with log applied
|
|
59
|
+
*/
|
|
60
|
+
export declare function log(a: ArrayStorage): ArrayStorage;
|
|
61
|
+
/**
|
|
62
|
+
* Base-2 logarithm for each element
|
|
63
|
+
* NumPy behavior: Always promotes to float64 for integer types
|
|
64
|
+
*
|
|
65
|
+
* @param a - Input array storage
|
|
66
|
+
* @returns Result storage with log2 applied
|
|
67
|
+
*/
|
|
68
|
+
export declare function log2(a: ArrayStorage): ArrayStorage;
|
|
69
|
+
/**
|
|
70
|
+
* Base-10 logarithm for each element
|
|
71
|
+
* NumPy behavior: Always promotes to float64 for integer types
|
|
72
|
+
*
|
|
73
|
+
* @param a - Input array storage
|
|
74
|
+
* @returns Result storage with log10 applied
|
|
75
|
+
*/
|
|
76
|
+
export declare function log10(a: ArrayStorage): ArrayStorage;
|
|
77
|
+
/**
|
|
78
|
+
* Natural logarithm of (1 + x) for each element
|
|
79
|
+
* More accurate than log(1 + x) for small x
|
|
80
|
+
* NumPy behavior: Always promotes to float64 for integer types
|
|
81
|
+
*
|
|
82
|
+
* @param a - Input array storage
|
|
83
|
+
* @returns Result storage with log1p applied
|
|
84
|
+
*/
|
|
85
|
+
export declare function log1p(a: ArrayStorage): ArrayStorage;
|
|
86
|
+
/**
|
|
87
|
+
* Logarithm of the sum of exponentials: log(exp(x1) + exp(x2))
|
|
88
|
+
* More numerically stable than computing the expression directly
|
|
89
|
+
* NumPy behavior: Always promotes to float64 for integer types
|
|
90
|
+
*
|
|
91
|
+
* @param x1 - First input array storage
|
|
92
|
+
* @param x2 - Second input array storage (or scalar)
|
|
93
|
+
* @returns Result storage with logaddexp applied
|
|
94
|
+
*/
|
|
95
|
+
export declare function logaddexp(x1: ArrayStorage, x2: ArrayStorage | number): ArrayStorage;
|
|
96
|
+
/**
|
|
97
|
+
* Logarithm base 2 of the sum of exponentials: log2(2^x1 + 2^x2)
|
|
98
|
+
* More numerically stable than computing the expression directly
|
|
99
|
+
* NumPy behavior: Always promotes to float64 for integer types
|
|
100
|
+
*
|
|
101
|
+
* @param x1 - First input array storage
|
|
102
|
+
* @param x2 - Second input array storage (or scalar)
|
|
103
|
+
* @returns Result storage with logaddexp2 applied
|
|
104
|
+
*/
|
|
105
|
+
export declare function logaddexp2(x1: ArrayStorage, x2: ArrayStorage | number): ArrayStorage;
|
|
28
106
|
//# sourceMappingURL=exponential.d.ts.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gradient and difference operations
|
|
3
|
+
*
|
|
4
|
+
* Pure functions for computing gradients and differences:
|
|
5
|
+
* gradient, diff, ediff1d, cross
|
|
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
|
+
* Calculate the n-th discrete difference along the given axis.
|
|
13
|
+
*
|
|
14
|
+
* The first difference is given by out[i] = a[i+1] - a[i] along the given axis.
|
|
15
|
+
* Higher differences are calculated by using diff recursively.
|
|
16
|
+
*
|
|
17
|
+
* @param a - Input array storage
|
|
18
|
+
* @param n - Number of times values are differenced (default: 1)
|
|
19
|
+
* @param axis - Axis along which to compute difference (default: -1, last axis)
|
|
20
|
+
* @returns Result storage with differences
|
|
21
|
+
*/
|
|
22
|
+
export declare function diff(a: ArrayStorage, n?: number, axis?: number): ArrayStorage;
|
|
23
|
+
/**
|
|
24
|
+
* The differences between consecutive elements of a flattened array.
|
|
25
|
+
*
|
|
26
|
+
* @param ary - Input array storage
|
|
27
|
+
* @param to_end - Number(s) to append at the end of the returned differences
|
|
28
|
+
* @param to_begin - Number(s) to prepend at the beginning of the returned differences
|
|
29
|
+
* @returns Array of differences with optional prepend/append values
|
|
30
|
+
*/
|
|
31
|
+
export declare function ediff1d(ary: ArrayStorage, to_end?: number[] | null, to_begin?: number[] | null): ArrayStorage;
|
|
32
|
+
/**
|
|
33
|
+
* Return the gradient of an N-dimensional array.
|
|
34
|
+
*
|
|
35
|
+
* The gradient is computed using second order accurate central differences in the interior
|
|
36
|
+
* and first order accurate one-sided (forward or backwards) differences at the boundaries.
|
|
37
|
+
*
|
|
38
|
+
* @param f - Input array storage
|
|
39
|
+
* @param varargs - Spacing between values (scalar or array per dimension)
|
|
40
|
+
* @param axis - Axis or axes along which to compute gradient (default: all axes)
|
|
41
|
+
* @returns Array of gradients (one per axis) or single gradient if one axis
|
|
42
|
+
*/
|
|
43
|
+
export declare function gradient(f: ArrayStorage, varargs?: number | number[], axis?: number | number[] | null): ArrayStorage | ArrayStorage[];
|
|
44
|
+
/**
|
|
45
|
+
* Return the cross product of two (arrays of) vectors.
|
|
46
|
+
*
|
|
47
|
+
* The cross product of a and b in R^3 is a vector perpendicular to both a and b.
|
|
48
|
+
*
|
|
49
|
+
* @param a - First input array (components of first vector(s))
|
|
50
|
+
* @param b - Second input array (components of second vector(s))
|
|
51
|
+
* @param axisa - Axis of a that defines the vector(s) (default: -1)
|
|
52
|
+
* @param axisb - Axis of b that defines the vector(s) (default: -1)
|
|
53
|
+
* @param axisc - Axis of c containing the cross product vector(s) (default: -1)
|
|
54
|
+
* @returns Cross product array
|
|
55
|
+
*/
|
|
56
|
+
export declare function cross(a: ArrayStorage, b: ArrayStorage, axisa?: number, axisb?: number, _axisc?: number): ArrayStorage;
|
|
57
|
+
//# sourceMappingURL=gradient.d.ts.map
|
|
@@ -143,4 +143,224 @@ export declare function einsum(subscripts: string, ...operands: ArrayStorage[]):
|
|
|
143
143
|
* @returns Kronecker product of a and b
|
|
144
144
|
*/
|
|
145
145
|
export declare function kron(a: ArrayStorage, b: ArrayStorage): ArrayStorage;
|
|
146
|
+
/**
|
|
147
|
+
* Cross product of two vectors.
|
|
148
|
+
*
|
|
149
|
+
* For 3D vectors: returns the cross product vector
|
|
150
|
+
* For 2D vectors: returns the scalar z-component of the cross product
|
|
151
|
+
*
|
|
152
|
+
* @param a - First input array
|
|
153
|
+
* @param b - Second input array
|
|
154
|
+
* @param axisa - Axis of a that defines the vectors (default: -1)
|
|
155
|
+
* @param axisb - Axis of b that defines the vectors (default: -1)
|
|
156
|
+
* @param axisc - Axis of c containing the cross product vectors (default: -1)
|
|
157
|
+
* @param axis - If defined, the axis of a, b and c that defines the vectors
|
|
158
|
+
* @returns Cross product of a and b
|
|
159
|
+
*/
|
|
160
|
+
export declare function cross(a: ArrayStorage, b: ArrayStorage, axisa?: number, axisb?: number, axisc?: number, axis?: number): ArrayStorage | number;
|
|
161
|
+
/**
|
|
162
|
+
* Vector norm.
|
|
163
|
+
*
|
|
164
|
+
* @param x - Input vector or array
|
|
165
|
+
* @param ord - Order of the norm (default: 2)
|
|
166
|
+
* - Infinity: max(abs(x))
|
|
167
|
+
* - -Infinity: min(abs(x))
|
|
168
|
+
* - 0: sum(x != 0)
|
|
169
|
+
* - Other: sum(abs(x)^ord)^(1/ord)
|
|
170
|
+
* @param axis - Axis along which to compute (flattened if not specified)
|
|
171
|
+
* @param keepdims - Keep reduced dimensions
|
|
172
|
+
* @returns Vector norm
|
|
173
|
+
*/
|
|
174
|
+
export declare function vector_norm(x: ArrayStorage, ord?: number | 'fro' | 'nuc', axis?: number | null, keepdims?: boolean): ArrayStorage | number;
|
|
175
|
+
/**
|
|
176
|
+
* Matrix norm.
|
|
177
|
+
*
|
|
178
|
+
* @param x - Input 2D array
|
|
179
|
+
* @param ord - Order of the norm:
|
|
180
|
+
* - 'fro': Frobenius norm (default)
|
|
181
|
+
* - 'nuc': Nuclear norm (sum of singular values)
|
|
182
|
+
* - 1: Max column sum (max(sum(abs(x), axis=0)))
|
|
183
|
+
* - -1: Min column sum (min(sum(abs(x), axis=0)))
|
|
184
|
+
* - 2: Largest singular value
|
|
185
|
+
* - -2: Smallest singular value
|
|
186
|
+
* - Infinity: Max row sum (max(sum(abs(x), axis=1)))
|
|
187
|
+
* - -Infinity: Min row sum (min(sum(abs(x), axis=1)))
|
|
188
|
+
* @param keepdims - Keep reduced dimensions
|
|
189
|
+
* @returns Matrix norm
|
|
190
|
+
*/
|
|
191
|
+
export declare function matrix_norm(x: ArrayStorage, ord?: number | 'fro' | 'nuc', keepdims?: boolean): ArrayStorage | number;
|
|
192
|
+
/**
|
|
193
|
+
* General norm function (for both vectors and matrices).
|
|
194
|
+
*
|
|
195
|
+
* @param x - Input array
|
|
196
|
+
* @param ord - Order of the norm (default: 'fro' for 2D, 2 for 1D)
|
|
197
|
+
* @param axis - Axis or axes along which to compute
|
|
198
|
+
* @param keepdims - Keep reduced dimensions
|
|
199
|
+
* @returns Norm
|
|
200
|
+
*/
|
|
201
|
+
export declare function norm(x: ArrayStorage, ord?: number | 'fro' | 'nuc' | null, axis?: number | [number, number] | null, keepdims?: boolean): ArrayStorage | number;
|
|
202
|
+
/**
|
|
203
|
+
* QR decomposition using Householder reflections.
|
|
204
|
+
*
|
|
205
|
+
* @param a - Input matrix (m x n)
|
|
206
|
+
* @param mode - 'reduced' (default), 'complete', 'r', or 'raw'
|
|
207
|
+
* @returns { q, r } where A = Q @ R
|
|
208
|
+
*/
|
|
209
|
+
export declare function qr(a: ArrayStorage, mode?: 'reduced' | 'complete' | 'r' | 'raw'): {
|
|
210
|
+
q: ArrayStorage;
|
|
211
|
+
r: ArrayStorage;
|
|
212
|
+
} | ArrayStorage | {
|
|
213
|
+
h: ArrayStorage;
|
|
214
|
+
tau: ArrayStorage;
|
|
215
|
+
};
|
|
216
|
+
/**
|
|
217
|
+
* Cholesky decomposition.
|
|
218
|
+
*
|
|
219
|
+
* Returns the lower triangular matrix L such that A = L @ L^T
|
|
220
|
+
* for a symmetric positive-definite matrix A.
|
|
221
|
+
*
|
|
222
|
+
* @param a - Symmetric positive-definite matrix
|
|
223
|
+
* @param upper - If true, return upper triangular U such that A = U^T @ U
|
|
224
|
+
* @returns Lower (or upper) triangular Cholesky factor
|
|
225
|
+
*/
|
|
226
|
+
export declare function cholesky(a: ArrayStorage, upper?: boolean): ArrayStorage;
|
|
227
|
+
/**
|
|
228
|
+
* Singular Value Decomposition.
|
|
229
|
+
*
|
|
230
|
+
* @param a - Input matrix (m x n)
|
|
231
|
+
* @param full_matrices - If true, return full U and V^T, otherwise reduced
|
|
232
|
+
* @param compute_uv - If true, return U, S, V^T; if false, return only S
|
|
233
|
+
* @returns { u, s, vt } or just s depending on compute_uv
|
|
234
|
+
*/
|
|
235
|
+
export declare function svd(a: ArrayStorage, full_matrices?: boolean, compute_uv?: boolean): {
|
|
236
|
+
u: ArrayStorage;
|
|
237
|
+
s: ArrayStorage;
|
|
238
|
+
vt: ArrayStorage;
|
|
239
|
+
} | ArrayStorage;
|
|
240
|
+
/**
|
|
241
|
+
* Compute the determinant of a square matrix.
|
|
242
|
+
*
|
|
243
|
+
* Uses LU decomposition for numerical stability.
|
|
244
|
+
*
|
|
245
|
+
* @param a - Square matrix
|
|
246
|
+
* @returns Determinant
|
|
247
|
+
*/
|
|
248
|
+
export declare function det(a: ArrayStorage): number;
|
|
249
|
+
/**
|
|
250
|
+
* Compute the matrix inverse - optimized to do LU decomposition once.
|
|
251
|
+
*
|
|
252
|
+
* @param a - Square matrix
|
|
253
|
+
* @returns Inverse matrix
|
|
254
|
+
*/
|
|
255
|
+
export declare function inv(a: ArrayStorage): ArrayStorage;
|
|
256
|
+
/**
|
|
257
|
+
* Solve a linear system A @ x = b.
|
|
258
|
+
*
|
|
259
|
+
* @param a - Coefficient matrix (n x n)
|
|
260
|
+
* @param b - Right-hand side (n,) or (n, k)
|
|
261
|
+
* @returns Solution x with same shape as b
|
|
262
|
+
*/
|
|
263
|
+
export declare function solve(a: ArrayStorage, b: ArrayStorage): ArrayStorage;
|
|
264
|
+
/**
|
|
265
|
+
* Compute the least-squares solution to a linear matrix equation.
|
|
266
|
+
*
|
|
267
|
+
* @param a - Coefficient matrix (m x n)
|
|
268
|
+
* @param b - Right-hand side (m,) or (m, k)
|
|
269
|
+
* @param rcond - Cutoff for small singular values (default: machine precision * max(m, n))
|
|
270
|
+
* @returns { x, residuals, rank, s } - Solution, residuals, effective rank, singular values
|
|
271
|
+
*/
|
|
272
|
+
export declare function lstsq(a: ArrayStorage, b: ArrayStorage, rcond?: number | null): {
|
|
273
|
+
x: ArrayStorage;
|
|
274
|
+
residuals: ArrayStorage;
|
|
275
|
+
rank: number;
|
|
276
|
+
s: ArrayStorage;
|
|
277
|
+
};
|
|
278
|
+
/**
|
|
279
|
+
* Compute the condition number of a matrix.
|
|
280
|
+
*
|
|
281
|
+
* @param a - Input matrix
|
|
282
|
+
* @param p - Order of the norm (default: 2, -2, 'fro', or inf)
|
|
283
|
+
* @returns Condition number
|
|
284
|
+
*/
|
|
285
|
+
export declare function cond(a: ArrayStorage, p?: number | 'fro' | 'nuc'): number;
|
|
286
|
+
/**
|
|
287
|
+
* Compute the rank of a matrix using SVD.
|
|
288
|
+
*
|
|
289
|
+
* @param a - Input matrix
|
|
290
|
+
* @param tol - Threshold below which singular values are considered zero
|
|
291
|
+
* @returns Matrix rank
|
|
292
|
+
*/
|
|
293
|
+
export declare function matrix_rank(a: ArrayStorage, tol?: number): number;
|
|
294
|
+
/**
|
|
295
|
+
* Raise a square matrix to an integer power.
|
|
296
|
+
*
|
|
297
|
+
* @param a - Input square matrix
|
|
298
|
+
* @param n - Integer power (can be negative)
|
|
299
|
+
* @returns Matrix raised to power n
|
|
300
|
+
*/
|
|
301
|
+
export declare function matrix_power(a: ArrayStorage, n: number): ArrayStorage;
|
|
302
|
+
/**
|
|
303
|
+
* Compute the Moore-Penrose pseudo-inverse using SVD.
|
|
304
|
+
*
|
|
305
|
+
* @param a - Input matrix
|
|
306
|
+
* @param rcond - Cutoff for small singular values
|
|
307
|
+
* @returns Pseudo-inverse of a
|
|
308
|
+
*/
|
|
309
|
+
export declare function pinv(a: ArrayStorage, rcond?: number): ArrayStorage;
|
|
310
|
+
/**
|
|
311
|
+
* Compute eigenvalues and right eigenvectors of a square matrix.
|
|
312
|
+
*
|
|
313
|
+
* For general matrices, uses iterative methods.
|
|
314
|
+
* For symmetric matrices, use eigh for better performance.
|
|
315
|
+
*
|
|
316
|
+
* **Limitation**: Complex eigenvalues are not supported. For non-symmetric matrices,
|
|
317
|
+
* this function returns only the real parts of eigenvalues. If your matrix has
|
|
318
|
+
* complex eigenvalues (e.g., rotation matrices), results will be incorrect.
|
|
319
|
+
* Use eigh() for symmetric matrices where eigenvalues are guaranteed to be real.
|
|
320
|
+
*
|
|
321
|
+
* @param a - Input square matrix
|
|
322
|
+
* @returns { w, v } - Eigenvalues (real only) and eigenvector matrix
|
|
323
|
+
*/
|
|
324
|
+
export declare function eig(a: ArrayStorage): {
|
|
325
|
+
w: ArrayStorage;
|
|
326
|
+
v: ArrayStorage;
|
|
327
|
+
};
|
|
328
|
+
/**
|
|
329
|
+
* Compute eigenvalues and eigenvectors of a real symmetric matrix.
|
|
330
|
+
*
|
|
331
|
+
* Note: Named "Hermitian" for NumPy compatibility, but only real symmetric
|
|
332
|
+
* matrices are supported (complex Hermitian matrices require complex dtype support).
|
|
333
|
+
* Symmetric matrices always have real eigenvalues, so results are exact.
|
|
334
|
+
*
|
|
335
|
+
* @param a - Real symmetric matrix
|
|
336
|
+
* @param UPLO - 'L' or 'U' to use lower or upper triangle (default: 'L')
|
|
337
|
+
* @returns { w, v } - Eigenvalues (sorted ascending) and eigenvector matrix
|
|
338
|
+
*/
|
|
339
|
+
export declare function eigh(a: ArrayStorage, UPLO?: 'L' | 'U'): {
|
|
340
|
+
w: ArrayStorage;
|
|
341
|
+
v: ArrayStorage;
|
|
342
|
+
};
|
|
343
|
+
/**
|
|
344
|
+
* Compute eigenvalues of a general square matrix.
|
|
345
|
+
*
|
|
346
|
+
* **Limitation**: Complex eigenvalues are not supported. For non-symmetric matrices,
|
|
347
|
+
* this function returns only real approximations. Use eigvalsh() for symmetric
|
|
348
|
+
* matrices where eigenvalues are guaranteed to be real.
|
|
349
|
+
*
|
|
350
|
+
* @param a - Input square matrix
|
|
351
|
+
* @returns Array of eigenvalues (real only)
|
|
352
|
+
*/
|
|
353
|
+
export declare function eigvals(a: ArrayStorage): ArrayStorage;
|
|
354
|
+
/**
|
|
355
|
+
* Compute eigenvalues of a real symmetric matrix.
|
|
356
|
+
*
|
|
357
|
+
* Note: Named "Hermitian" for NumPy compatibility, but only real symmetric
|
|
358
|
+
* matrices are supported (complex Hermitian matrices require complex dtype support).
|
|
359
|
+
* Symmetric matrices always have real eigenvalues, so results are exact.
|
|
360
|
+
*
|
|
361
|
+
* @param a - Real symmetric matrix
|
|
362
|
+
* @param UPLO - 'L' or 'U' to use lower or upper triangle
|
|
363
|
+
* @returns Array of eigenvalues (sorted ascending)
|
|
364
|
+
*/
|
|
365
|
+
export declare function eigvalsh(a: ArrayStorage, UPLO?: 'L' | 'U'): ArrayStorage;
|
|
146
366
|
//# sourceMappingURL=linalg.d.ts.map
|