numpy-ts 0.6.0 → 0.8.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.
@@ -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
@@ -37,4 +37,72 @@ export declare function choose(indexStorage: ArrayStorage, choices: ArrayStorage
37
37
  * Check if two arrays are element-wise equal
38
38
  */
39
39
  export declare function array_equal(a: ArrayStorage, b: ArrayStorage, equal_nan?: boolean): boolean;
40
+ /**
41
+ * Take values along an axis using 1D index array
42
+ */
43
+ export declare function take_along_axis(storage: ArrayStorage, indices: ArrayStorage, axis: number): ArrayStorage;
44
+ /**
45
+ * Put values into array along an axis using 1D index array
46
+ */
47
+ export declare function put_along_axis(storage: ArrayStorage, indices: ArrayStorage, values: ArrayStorage, axis: number): void;
48
+ /**
49
+ * Change elements of array based on conditional mask
50
+ */
51
+ export declare function putmask(storage: ArrayStorage, mask: ArrayStorage, values: ArrayStorage | number | bigint): void;
52
+ /**
53
+ * Return selected slices along given axis based on condition
54
+ */
55
+ export declare function compress(condition: ArrayStorage, storage: ArrayStorage, axis?: number): ArrayStorage;
56
+ /**
57
+ * Return array drawn from elements in choicelist, depending on conditions
58
+ */
59
+ export declare function select(condlist: ArrayStorage[], choicelist: ArrayStorage[], defaultValue?: number | bigint): ArrayStorage;
60
+ /**
61
+ * Change elements of array based on conditional and input values
62
+ */
63
+ export declare function place(storage: ArrayStorage, mask: ArrayStorage, vals: ArrayStorage): void;
64
+ /**
65
+ * Return indices to access main diagonal of array
66
+ */
67
+ export declare function diag_indices(n: number, ndim?: number): ArrayStorage[];
68
+ /**
69
+ * Return indices to access main diagonal of array from given array
70
+ */
71
+ export declare function diag_indices_from(storage: ArrayStorage): ArrayStorage[];
72
+ /**
73
+ * Return indices for lower-triangle of an (n, m) array
74
+ */
75
+ export declare function tril_indices(n: number, k?: number, m?: number): ArrayStorage[];
76
+ /**
77
+ * Return indices for lower-triangle of given array
78
+ */
79
+ export declare function tril_indices_from(storage: ArrayStorage, k?: number): ArrayStorage[];
80
+ /**
81
+ * Return indices for upper-triangle of an (n, m) array
82
+ */
83
+ export declare function triu_indices(n: number, k?: number, m?: number): ArrayStorage[];
84
+ /**
85
+ * Return indices for upper-triangle of given array
86
+ */
87
+ export declare function triu_indices_from(storage: ArrayStorage, k?: number): ArrayStorage[];
88
+ /**
89
+ * Return indices to access elements using mask function
90
+ */
91
+ export declare function mask_indices(n: number, mask_func: (n: number, k: number) => ArrayStorage, k?: number): ArrayStorage[];
92
+ /**
93
+ * Return array representing indices of a grid
94
+ */
95
+ export declare function indices(dimensions: number[], dtype?: 'int32' | 'int64' | 'float64'): ArrayStorage;
96
+ /**
97
+ * Construct open mesh from multiple sequences
98
+ */
99
+ export declare function ix_(...args: ArrayStorage[]): ArrayStorage[];
100
+ /**
101
+ * Convert multi-dimensional index arrays to flat index array
102
+ */
103
+ export declare function ravel_multi_index(multi_index: ArrayStorage[], dims: number[], mode?: 'raise' | 'wrap' | 'clip'): ArrayStorage;
104
+ /**
105
+ * Convert flat index array to tuple of coordinate arrays
106
+ */
107
+ export declare function unravel_index(indices: ArrayStorage | number, shape: number[], order?: 'C' | 'F'): ArrayStorage[];
40
108
  //# sourceMappingURL=advanced.d.ts.map
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Bitwise operations
3
+ *
4
+ * Pure functions for element-wise bitwise operations:
5
+ * bitwise_and, bitwise_or, bitwise_xor, bitwise_not, invert,
6
+ * left_shift, right_shift, packbits, unpackbits
7
+ *
8
+ * These operations only work on integer types.
9
+ */
10
+ import { ArrayStorage } from '../core/storage';
11
+ /**
12
+ * Bitwise AND of two arrays or array and scalar
13
+ *
14
+ * @param a - First array storage (must be integer type)
15
+ * @param b - Second array storage or scalar (must be integer type)
16
+ * @returns Result storage
17
+ */
18
+ export declare function bitwise_and(a: ArrayStorage, b: ArrayStorage | number): ArrayStorage;
19
+ /**
20
+ * Bitwise OR of two arrays or array and scalar
21
+ *
22
+ * @param a - First array storage (must be integer type)
23
+ * @param b - Second array storage or scalar (must be integer type)
24
+ * @returns Result storage
25
+ */
26
+ export declare function bitwise_or(a: ArrayStorage, b: ArrayStorage | number): ArrayStorage;
27
+ /**
28
+ * Bitwise XOR of two arrays or array and scalar
29
+ *
30
+ * @param a - First array storage (must be integer type)
31
+ * @param b - Second array storage or scalar (must be integer type)
32
+ * @returns Result storage
33
+ */
34
+ export declare function bitwise_xor(a: ArrayStorage, b: ArrayStorage | number): ArrayStorage;
35
+ /**
36
+ * Bitwise NOT (invert) of each element
37
+ *
38
+ * @param a - Input array storage (must be integer type)
39
+ * @returns Result storage with bitwise NOT values
40
+ */
41
+ export declare function bitwise_not(a: ArrayStorage): ArrayStorage;
42
+ /**
43
+ * Invert (bitwise NOT) - alias for bitwise_not
44
+ *
45
+ * @param a - Input array storage (must be integer type)
46
+ * @returns Result storage with inverted values
47
+ */
48
+ export declare function invert(a: ArrayStorage): ArrayStorage;
49
+ /**
50
+ * Left shift of array elements
51
+ *
52
+ * @param a - Input array storage (must be integer type)
53
+ * @param b - Shift amount (array storage or scalar)
54
+ * @returns Result storage with left-shifted values
55
+ */
56
+ export declare function left_shift(a: ArrayStorage, b: ArrayStorage | number): ArrayStorage;
57
+ /**
58
+ * Right shift of array elements
59
+ *
60
+ * @param a - Input array storage (must be integer type)
61
+ * @param b - Shift amount (array storage or scalar)
62
+ * @returns Result storage with right-shifted values
63
+ */
64
+ export declare function right_shift(a: ArrayStorage, b: ArrayStorage | number): ArrayStorage;
65
+ /**
66
+ * Pack binary values into uint8 array
67
+ *
68
+ * Packs the elements of a binary-valued array into bits in a uint8 array.
69
+ * The result has the same shape as the input, except for the specified axis
70
+ * which is divided by 8 (rounded up).
71
+ *
72
+ * @param a - Input array (values are interpreted as binary: 0 or non-zero)
73
+ * @param axis - The dimension over which bit-packing is done (default: -1, meaning the last axis)
74
+ * @param bitorder - The order of bits within each packed byte. 'big' means the most significant bit is first. (default: 'big')
75
+ * @returns Packed uint8 array
76
+ */
77
+ export declare function packbits(a: ArrayStorage, axis?: number, bitorder?: 'big' | 'little'): ArrayStorage;
78
+ /**
79
+ * Unpack uint8 array into binary values
80
+ *
81
+ * Unpacks elements of a uint8 array into a binary-valued output array.
82
+ * Each element of the input array is unpacked into 8 binary values.
83
+ *
84
+ * @param a - Input uint8 array
85
+ * @param axis - The dimension over which bit-unpacking is done (default: -1, meaning the last axis)
86
+ * @param count - The number of elements to unpack along axis, or -1 for all (default: -1)
87
+ * @param bitorder - The order of bits within each packed byte. 'big' means the most significant bit is first. (default: 'big')
88
+ * @returns Unpacked uint8 array of 0s and 1s
89
+ */
90
+ export declare function unpackbits(a: ArrayStorage, axis?: number, count?: number, bitorder?: 'big' | 'little'): ArrayStorage;
91
+ //# sourceMappingURL=bitwise.d.ts.map
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Sorting and searching operations
3
+ *
4
+ * Functions for sorting arrays, finding sorted indices, and searching.
5
+ * @module ops/sorting
6
+ */
7
+ import { ArrayStorage } from '../core/storage';
8
+ /**
9
+ * Return a sorted copy of an array
10
+ * @param storage - Input array storage
11
+ * @param axis - Axis along which to sort. Default is -1 (last axis)
12
+ * @returns Sorted array
13
+ */
14
+ export declare function sort(storage: ArrayStorage, axis?: number): ArrayStorage;
15
+ /**
16
+ * Returns the indices that would sort an array
17
+ * @param storage - Input array storage
18
+ * @param axis - Axis along which to sort. Default is -1 (last axis)
19
+ * @returns Array of indices that sort the input array
20
+ */
21
+ export declare function argsort(storage: ArrayStorage, axis?: number): ArrayStorage;
22
+ /**
23
+ * Perform an indirect stable sort using a sequence of keys
24
+ * @param keys - Array of ArrayStorage, the last key is the primary sort key
25
+ * @returns Array of indices that would sort the keys
26
+ */
27
+ export declare function lexsort(keys: ArrayStorage[]): ArrayStorage;
28
+ /**
29
+ * Partially sort an array
30
+ * Returns array with element at kth position in sorted position,
31
+ * all smaller elements before it, all larger after it (not fully sorted)
32
+ * @param storage - Input array storage
33
+ * @param kth - Element index to partition by
34
+ * @param axis - Axis along which to sort. Default is -1 (last axis)
35
+ * @returns Partitioned array
36
+ */
37
+ export declare function partition(storage: ArrayStorage, kth: number, axis?: number): ArrayStorage;
38
+ /**
39
+ * Returns indices that would partition an array
40
+ * @param storage - Input array storage
41
+ * @param kth - Element index to partition by
42
+ * @param axis - Axis along which to sort. Default is -1 (last axis)
43
+ * @returns Array of indices
44
+ */
45
+ export declare function argpartition(storage: ArrayStorage, kth: number, axis?: number): ArrayStorage;
46
+ /**
47
+ * Sort a complex array using the real part first, then the imaginary part
48
+ * For real arrays, this is equivalent to sort
49
+ * @param storage - Input array storage
50
+ * @returns Sorted array
51
+ */
52
+ export declare function sort_complex(storage: ArrayStorage): ArrayStorage;
53
+ /**
54
+ * Return the indices of the elements that are non-zero
55
+ * @param storage - Input array storage
56
+ * @returns Tuple of arrays, one for each dimension
57
+ */
58
+ export declare function nonzero(storage: ArrayStorage): ArrayStorage[];
59
+ /**
60
+ * Return indices of non-zero elements in flattened array
61
+ * @param storage - Input array storage
62
+ * @returns Array of indices
63
+ */
64
+ export declare function flatnonzero(storage: ArrayStorage): ArrayStorage;
65
+ /**
66
+ * Return elements from x or y depending on condition
67
+ * @param condition - Boolean array or condition
68
+ * @param x - Values where condition is true
69
+ * @param y - Values where condition is false
70
+ * @returns Array with elements chosen from x or y based on condition
71
+ */
72
+ export declare function where(condition: ArrayStorage, x?: ArrayStorage, y?: ArrayStorage): ArrayStorage | ArrayStorage[];
73
+ /**
74
+ * Find indices where elements should be inserted to maintain order
75
+ * @param storage - Input array (must be sorted in ascending order)
76
+ * @param values - Values to insert
77
+ * @param side - 'left' or 'right' side to insert
78
+ * @returns Indices where values should be inserted
79
+ */
80
+ export declare function searchsorted(storage: ArrayStorage, values: ArrayStorage, side?: 'left' | 'right'): ArrayStorage;
81
+ /**
82
+ * Return the elements of an array that satisfy some condition
83
+ * @param condition - Boolean array
84
+ * @param storage - Input array storage
85
+ * @returns 1D array of elements where condition is true
86
+ */
87
+ export declare function extract(condition: ArrayStorage, storage: ArrayStorage): ArrayStorage;
88
+ /**
89
+ * Count number of non-zero values in the array
90
+ * @param storage - Input array storage
91
+ * @param axis - Axis along which to count (optional)
92
+ * @returns Count of non-zero values
93
+ */
94
+ export declare function count_nonzero(storage: ArrayStorage, axis?: number): ArrayStorage | number;
95
+ //# sourceMappingURL=sorting.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "numpy-ts",
3
- "version": "0.6.0",
3
+ "version": "0.8.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",