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.
@@ -284,6 +284,46 @@ export declare class NDArray {
284
284
  * @returns Boolean array (represented as uint8: 1=true, 0=false)
285
285
  */
286
286
  allclose(other: NDArray | number, rtol?: number, atol?: number): boolean;
287
+ /**
288
+ * Bitwise AND element-wise
289
+ * @param other - Array or scalar for AND operation (must be integer type)
290
+ * @returns Result of bitwise AND
291
+ */
292
+ bitwise_and(other: NDArray | number): NDArray;
293
+ /**
294
+ * Bitwise OR element-wise
295
+ * @param other - Array or scalar for OR operation (must be integer type)
296
+ * @returns Result of bitwise OR
297
+ */
298
+ bitwise_or(other: NDArray | number): NDArray;
299
+ /**
300
+ * Bitwise XOR element-wise
301
+ * @param other - Array or scalar for XOR operation (must be integer type)
302
+ * @returns Result of bitwise XOR
303
+ */
304
+ bitwise_xor(other: NDArray | number): NDArray;
305
+ /**
306
+ * Bitwise NOT (inversion) element-wise
307
+ * @returns Result of bitwise NOT
308
+ */
309
+ bitwise_not(): NDArray;
310
+ /**
311
+ * Invert (bitwise NOT) element-wise - alias for bitwise_not
312
+ * @returns Result of bitwise inversion
313
+ */
314
+ invert(): NDArray;
315
+ /**
316
+ * Left shift elements by positions
317
+ * @param shift - Shift amount (array or scalar)
318
+ * @returns Result of left shift
319
+ */
320
+ left_shift(shift: NDArray | number): NDArray;
321
+ /**
322
+ * Right shift elements by positions
323
+ * @param shift - Shift amount (array or scalar)
324
+ * @returns Result of right shift
325
+ */
326
+ right_shift(shift: NDArray | number): NDArray;
287
327
  /**
288
328
  * Sum array elements over a given axis
289
329
  * @param axis - Axis along which to sum. If undefined, sum all elements
@@ -494,6 +534,44 @@ export declare class NDArray {
494
534
  * @returns Median of array elements ignoring NaNs
495
535
  */
496
536
  nanmedian(axis?: number, keepdims?: boolean): NDArray | number;
537
+ /**
538
+ * Return a sorted copy of the array
539
+ * @param axis - Axis along which to sort. Default is -1 (last axis)
540
+ * @returns Sorted array
541
+ */
542
+ sort(axis?: number): NDArray;
543
+ /**
544
+ * Returns the indices that would sort this array
545
+ * @param axis - Axis along which to sort. Default is -1 (last axis)
546
+ * @returns Array of indices that sort the array
547
+ */
548
+ argsort(axis?: number): NDArray;
549
+ /**
550
+ * Partially sort the array
551
+ * @param kth - Element index to partition by
552
+ * @param axis - Axis along which to sort. Default is -1 (last axis)
553
+ * @returns Partitioned array
554
+ */
555
+ partition(kth: number, axis?: number): NDArray;
556
+ /**
557
+ * Returns indices that would partition the array
558
+ * @param kth - Element index to partition by
559
+ * @param axis - Axis along which to sort. Default is -1 (last axis)
560
+ * @returns Array of indices
561
+ */
562
+ argpartition(kth: number, axis?: number): NDArray;
563
+ /**
564
+ * Return the indices of non-zero elements
565
+ * @returns Tuple of arrays, one for each dimension
566
+ */
567
+ nonzero(): NDArray[];
568
+ /**
569
+ * Find indices where elements should be inserted to maintain order
570
+ * @param v - Values to insert
571
+ * @param side - 'left' or 'right' side to insert
572
+ * @returns Indices where values should be inserted
573
+ */
574
+ searchsorted(v: NDArray, side?: 'left' | 'right'): NDArray;
497
575
  /**
498
576
  * Reshape array to a new shape
499
577
  * Returns a new array with the specified shape
@@ -1726,6 +1804,84 @@ export declare function remainder(x: NDArray, y: NDArray | number): NDArray;
1726
1804
  * @returns Array with heaviside values (0 if x1 < 0, x2 if x1 == 0, 1 if x1 > 0)
1727
1805
  */
1728
1806
  export declare function heaviside(x1: NDArray, x2: NDArray | number): NDArray;
1807
+ /**
1808
+ * Bitwise AND element-wise
1809
+ *
1810
+ * @param x1 - First input array (must be integer type)
1811
+ * @param x2 - Second input array or scalar (must be integer type)
1812
+ * @returns Result of bitwise AND
1813
+ */
1814
+ export declare function bitwise_and(x1: NDArray, x2: NDArray | number): NDArray;
1815
+ /**
1816
+ * Bitwise OR element-wise
1817
+ *
1818
+ * @param x1 - First input array (must be integer type)
1819
+ * @param x2 - Second input array or scalar (must be integer type)
1820
+ * @returns Result of bitwise OR
1821
+ */
1822
+ export declare function bitwise_or(x1: NDArray, x2: NDArray | number): NDArray;
1823
+ /**
1824
+ * Bitwise XOR element-wise
1825
+ *
1826
+ * @param x1 - First input array (must be integer type)
1827
+ * @param x2 - Second input array or scalar (must be integer type)
1828
+ * @returns Result of bitwise XOR
1829
+ */
1830
+ export declare function bitwise_xor(x1: NDArray, x2: NDArray | number): NDArray;
1831
+ /**
1832
+ * Bitwise NOT (inversion) element-wise
1833
+ *
1834
+ * @param x - Input array (must be integer type)
1835
+ * @returns Result of bitwise NOT
1836
+ */
1837
+ export declare function bitwise_not(x: NDArray): NDArray;
1838
+ /**
1839
+ * Invert (bitwise NOT) element-wise
1840
+ * Alias for bitwise_not
1841
+ *
1842
+ * @param x - Input array (must be integer type)
1843
+ * @returns Result of bitwise inversion
1844
+ */
1845
+ export declare function invert(x: NDArray): NDArray;
1846
+ /**
1847
+ * Left shift elements by positions
1848
+ *
1849
+ * @param x1 - Input array (must be integer type)
1850
+ * @param x2 - Shift amount (array or scalar)
1851
+ * @returns Result of left shift
1852
+ */
1853
+ export declare function left_shift(x1: NDArray, x2: NDArray | number): NDArray;
1854
+ /**
1855
+ * Right shift elements by positions
1856
+ *
1857
+ * @param x1 - Input array (must be integer type)
1858
+ * @param x2 - Shift amount (array or scalar)
1859
+ * @returns Result of right shift
1860
+ */
1861
+ export declare function right_shift(x1: NDArray, x2: NDArray | number): NDArray;
1862
+ /**
1863
+ * Pack binary values into uint8 array
1864
+ *
1865
+ * Packs the elements of a binary-valued array into bits in a uint8 array.
1866
+ *
1867
+ * @param a - Input array (values are interpreted as binary: 0 or non-zero)
1868
+ * @param axis - The dimension over which bit-packing is done (default: -1)
1869
+ * @param bitorder - Order of bits: 'big' or 'little' (default: 'big')
1870
+ * @returns Packed uint8 array
1871
+ */
1872
+ export declare function packbits(a: NDArray, axis?: number, bitorder?: 'big' | 'little'): NDArray;
1873
+ /**
1874
+ * Unpack uint8 array into binary values
1875
+ *
1876
+ * Unpacks elements of a uint8 array into a binary-valued output array.
1877
+ *
1878
+ * @param a - Input uint8 array
1879
+ * @param axis - The dimension over which bit-unpacking is done (default: -1)
1880
+ * @param count - Number of elements to unpack, or -1 for all (default: -1)
1881
+ * @param bitorder - Order of bits: 'big' or 'little' (default: 'big')
1882
+ * @returns Unpacked uint8 array of 0s and 1s
1883
+ */
1884
+ export declare function unpackbits(a: NDArray, axis?: number, count?: number, bitorder?: 'big' | 'little'): NDArray;
1729
1885
  /**
1730
1886
  * Einstein summation convention
1731
1887
  *
@@ -1748,4 +1904,235 @@ export declare function heaviside(x1: NDArray, x2: NDArray | number): NDArray;
1748
1904
  * einsum('ii->', a)
1749
1905
  */
1750
1906
  export declare function einsum(subscripts: string, ...operands: NDArray[]): NDArray | number | bigint;
1907
+ /**
1908
+ * Take values from the input array by matching 1d index and data slices along axis.
1909
+ *
1910
+ * @param arr - Input array
1911
+ * @param indices - Index array with same ndim as arr
1912
+ * @param axis - The axis along which to select values
1913
+ * @returns Array of values taken along the axis
1914
+ */
1915
+ export declare function take_along_axis(arr: NDArray, indices: NDArray, axis: number): NDArray;
1916
+ /**
1917
+ * Put values into the destination array using 1d index and data slices along axis.
1918
+ *
1919
+ * @param arr - Destination array (modified in-place)
1920
+ * @param indices - Index array with same ndim as arr
1921
+ * @param values - Values to put
1922
+ * @param axis - The axis along which to put values
1923
+ */
1924
+ export declare function put_along_axis(arr: NDArray, indices: NDArray, values: NDArray, axis: number): void;
1925
+ /**
1926
+ * Change elements of array based on conditional mask.
1927
+ *
1928
+ * @param a - Array to modify (in-place)
1929
+ * @param mask - Boolean mask array
1930
+ * @param values - Values to put where mask is True
1931
+ */
1932
+ export declare function putmask(a: NDArray, mask: NDArray, values: NDArray | number | bigint): void;
1933
+ /**
1934
+ * Return selected slices of array along given axis.
1935
+ *
1936
+ * @param condition - Boolean array for selecting
1937
+ * @param a - Array from which to select
1938
+ * @param axis - Axis along which to select (if undefined, works on flattened array)
1939
+ * @returns Compressed array
1940
+ */
1941
+ export declare function compress(condition: NDArray, a: NDArray, axis?: number): NDArray;
1942
+ /**
1943
+ * Return an array drawn from elements in choicelist, depending on conditions.
1944
+ *
1945
+ * @param condlist - List of boolean arrays (conditions)
1946
+ * @param choicelist - List of arrays to choose from
1947
+ * @param defaultVal - Default value when no condition is met (default 0)
1948
+ * @returns Array with selected values
1949
+ */
1950
+ export declare function select(condlist: NDArray[], choicelist: NDArray[], defaultVal?: number | bigint): NDArray;
1951
+ /**
1952
+ * Change elements of an array based on conditional and input values.
1953
+ *
1954
+ * @param arr - Array to modify (in-place)
1955
+ * @param mask - Boolean mask array
1956
+ * @param vals - Values to place where mask is True (cycles if shorter)
1957
+ */
1958
+ export declare function place(arr: NDArray, mask: NDArray, vals: NDArray): void;
1959
+ /**
1960
+ * Return the indices to access the main diagonal of an array.
1961
+ *
1962
+ * @param n - Size of arrays for which indices are returned
1963
+ * @param ndim - Number of dimensions (default 2)
1964
+ * @returns Tuple of index arrays
1965
+ */
1966
+ export declare function diag_indices(n: number, ndim?: number): NDArray[];
1967
+ /**
1968
+ * Return the indices to access the main diagonal of an n-dimensional array.
1969
+ *
1970
+ * @param arr - Input array (must have all equal dimensions)
1971
+ * @returns Tuple of index arrays
1972
+ */
1973
+ export declare function diag_indices_from(arr: NDArray): NDArray[];
1974
+ /**
1975
+ * Return the indices for the lower-triangle of an (n, m) array.
1976
+ *
1977
+ * @param n - Number of rows
1978
+ * @param k - Diagonal offset (0 = main, positive = above, negative = below)
1979
+ * @param m - Number of columns (default n)
1980
+ * @returns Tuple of row and column index arrays
1981
+ */
1982
+ export declare function tril_indices(n: number, k?: number, m?: number): NDArray[];
1983
+ /**
1984
+ * Return the indices for the lower-triangle of arr.
1985
+ *
1986
+ * @param arr - Input 2-D array
1987
+ * @param k - Diagonal offset (0 = main, positive = above, negative = below)
1988
+ * @returns Tuple of row and column index arrays
1989
+ */
1990
+ export declare function tril_indices_from(arr: NDArray, k?: number): NDArray[];
1991
+ /**
1992
+ * Return the indices for the upper-triangle of an (n, m) array.
1993
+ *
1994
+ * @param n - Number of rows
1995
+ * @param k - Diagonal offset (0 = main, positive = above, negative = below)
1996
+ * @param m - Number of columns (default n)
1997
+ * @returns Tuple of row and column index arrays
1998
+ */
1999
+ export declare function triu_indices(n: number, k?: number, m?: number): NDArray[];
2000
+ /**
2001
+ * Return the indices for the upper-triangle of arr.
2002
+ *
2003
+ * @param arr - Input 2-D array
2004
+ * @param k - Diagonal offset (0 = main, positive = above, negative = below)
2005
+ * @returns Tuple of row and column index arrays
2006
+ */
2007
+ export declare function triu_indices_from(arr: NDArray, k?: number): NDArray[];
2008
+ /**
2009
+ * Return the indices to access (n, n) arrays, given a masking function.
2010
+ *
2011
+ * @param n - The returned indices will be valid to access arrays of shape (n, n)
2012
+ * @param mask_func - A function that generates an (n, n) boolean mask
2013
+ * @param k - Optional diagonal offset passed to mask_func
2014
+ * @returns Tuple of row and column index arrays
2015
+ */
2016
+ export declare function mask_indices(n: number, mask_func: (n: number, k: number) => NDArray, k?: number): NDArray[];
2017
+ /**
2018
+ * Return an array representing the indices of a grid.
2019
+ *
2020
+ * @param dimensions - The shape of the grid
2021
+ * @param dtype - Data type of result (default 'int32')
2022
+ * @returns Array of shape (len(dimensions), *dimensions)
2023
+ */
2024
+ export declare function indices(dimensions: number[], dtype?: 'int32' | 'int64' | 'float64'): NDArray;
2025
+ /**
2026
+ * Construct an open mesh from multiple sequences.
2027
+ *
2028
+ * This function returns a list of arrays with shapes suitable for broadcasting.
2029
+ *
2030
+ * @param args - 1-D sequences
2031
+ * @returns Tuple of arrays for open mesh
2032
+ */
2033
+ export declare function ix_(...args: NDArray[]): NDArray[];
2034
+ /**
2035
+ * Convert a tuple of index arrays into an array of flat indices.
2036
+ *
2037
+ * @param multi_index - Tuple of index arrays
2038
+ * @param dims - Shape of array into which indices apply
2039
+ * @param mode - How to handle out-of-bounds indices ('raise', 'wrap', 'clip')
2040
+ * @returns Flattened indices
2041
+ */
2042
+ export declare function ravel_multi_index(multi_index: NDArray[], dims: number[], mode?: 'raise' | 'wrap' | 'clip'): NDArray;
2043
+ /**
2044
+ * Convert a flat index or array of flat indices into a tuple of coordinate arrays.
2045
+ *
2046
+ * @param indices - Array of indices or single index
2047
+ * @param shape - Shape of the array to index into
2048
+ * @param order - Row-major ('C') or column-major ('F') order
2049
+ * @returns Tuple of coordinate arrays
2050
+ */
2051
+ export declare function unravel_index(indices: NDArray | number, shape: number[], order?: 'C' | 'F'): NDArray[];
2052
+ /**
2053
+ * Return a sorted copy of an array
2054
+ * @param a - Input array
2055
+ * @param axis - Axis along which to sort. Default is -1 (last axis)
2056
+ * @returns Sorted array
2057
+ */
2058
+ export declare function sort(a: NDArray, axis?: number): NDArray;
2059
+ /**
2060
+ * Returns the indices that would sort an array
2061
+ * @param a - Input array
2062
+ * @param axis - Axis along which to sort. Default is -1 (last axis)
2063
+ * @returns Array of indices that sort the input array
2064
+ */
2065
+ export declare function argsort(a: NDArray, axis?: number): NDArray;
2066
+ /**
2067
+ * Perform an indirect stable sort using a sequence of keys
2068
+ * @param keys - Array of NDArrays, the last key is the primary sort key
2069
+ * @returns Array of indices that would sort the keys
2070
+ */
2071
+ export declare function lexsort(keys: NDArray[]): NDArray;
2072
+ /**
2073
+ * Partially sort an array
2074
+ * @param a - Input array
2075
+ * @param kth - Element index to partition by
2076
+ * @param axis - Axis along which to sort. Default is -1 (last axis)
2077
+ * @returns Partitioned array
2078
+ */
2079
+ export declare function partition(a: NDArray, kth: number, axis?: number): NDArray;
2080
+ /**
2081
+ * Returns indices that would partition an array
2082
+ * @param a - Input array
2083
+ * @param kth - Element index to partition by
2084
+ * @param axis - Axis along which to sort. Default is -1 (last axis)
2085
+ * @returns Array of indices
2086
+ */
2087
+ export declare function argpartition(a: NDArray, kth: number, axis?: number): NDArray;
2088
+ /**
2089
+ * Sort a complex array using the real part first, then the imaginary part
2090
+ * For real arrays, returns a sorted 1D array
2091
+ * @param a - Input array
2092
+ * @returns Sorted 1D array
2093
+ */
2094
+ export declare function sort_complex(a: NDArray): NDArray;
2095
+ /**
2096
+ * Return the indices of the elements that are non-zero
2097
+ * @param a - Input array
2098
+ * @returns Tuple of arrays, one for each dimension
2099
+ */
2100
+ export declare function nonzero(a: NDArray): NDArray[];
2101
+ /**
2102
+ * Return indices of non-zero elements in flattened array
2103
+ * @param a - Input array
2104
+ * @returns Array of indices
2105
+ */
2106
+ export declare function flatnonzero(a: NDArray): NDArray;
2107
+ /**
2108
+ * Return elements from x or y depending on condition
2109
+ * If only condition is given, returns indices where condition is true (like nonzero)
2110
+ * @param condition - Boolean array or condition
2111
+ * @param x - Values where condition is true (optional)
2112
+ * @param y - Values where condition is false (optional)
2113
+ * @returns Array with elements chosen from x or y, or indices if only condition given
2114
+ */
2115
+ export declare function where(condition: NDArray, x?: NDArray, y?: NDArray): NDArray | NDArray[];
2116
+ /**
2117
+ * Find indices where elements should be inserted to maintain order
2118
+ * @param a - Input array (must be sorted in ascending order)
2119
+ * @param v - Values to insert
2120
+ * @param side - 'left' or 'right' side to insert
2121
+ * @returns Indices where values should be inserted
2122
+ */
2123
+ export declare function searchsorted(a: NDArray, v: NDArray, side?: 'left' | 'right'): NDArray;
2124
+ /**
2125
+ * Return the elements of an array that satisfy some condition
2126
+ * @param condition - Boolean array
2127
+ * @param a - Input array
2128
+ * @returns 1D array of elements where condition is true
2129
+ */
2130
+ export declare function extract(condition: NDArray, a: NDArray): NDArray;
2131
+ /**
2132
+ * Count number of non-zero values in the array
2133
+ * @param a - Input array
2134
+ * @param axis - Axis along which to count (optional)
2135
+ * @returns Count of non-zero values
2136
+ */
2137
+ export declare function count_nonzero(a: NDArray, axis?: number): NDArray | number;
1751
2138
  //# sourceMappingURL=ndarray.d.ts.map
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @module numpy-ts
5
5
  */
6
- export { NDArray, zeros, ones, array, arange, linspace, logspace, geomspace, eye, empty, full, identity, asarray, copy, zeros_like, ones_like, empty_like, full_like, asanyarray, ascontiguousarray, asfortranarray, diag, diagflat, frombuffer, fromfile, fromfunction, fromiter, fromstring, meshgrid, tri, tril, triu, vander, sqrt, power, absolute, negative, sign, mod, floor_divide, positive, reciprocal, cbrt, fabs, divmod, square, remainder, heaviside, dot, trace, diagonal, kron, transpose, inner, outer, tensordot, einsum, sin, cos, tan, arcsin, arccos, arctan, arctan2, hypot, degrees, radians, deg2rad, rad2deg, sinh, cosh, tanh, arcsinh, arccosh, arctanh, swapaxes, moveaxis, concatenate, stack, vstack, hstack, dstack, split, array_split, vsplit, hsplit, tile, repeat, ravel, reshape, squeeze, expand_dims, flip, fliplr, flipud, rot90, roll, rollaxis, atleast_1d, atleast_2d, atleast_3d, dsplit, column_stack, row_stack, resize, append, delete_ as delete, insert, pad, broadcast_to, broadcast_arrays, broadcast_shapes, take, put, choose, array_equal, array_equiv, cumsum, cumprod, ptp, median, percentile, quantile, average, nansum, nanprod, nanmean, nanvar, nanstd, nanmin, nanmax, nanargmin, nanargmax, nancumsum, nancumprod, nanmedian, } from './core/ndarray';
6
+ export { NDArray, zeros, ones, array, arange, linspace, logspace, geomspace, eye, empty, full, identity, asarray, copy, zeros_like, ones_like, empty_like, full_like, asanyarray, ascontiguousarray, asfortranarray, diag, diagflat, frombuffer, fromfile, fromfunction, fromiter, fromstring, meshgrid, tri, tril, triu, vander, sqrt, power, absolute, negative, sign, mod, floor_divide, positive, reciprocal, cbrt, fabs, divmod, square, remainder, heaviside, dot, trace, diagonal, kron, transpose, inner, outer, tensordot, einsum, sin, cos, tan, arcsin, arccos, arctan, arctan2, hypot, degrees, radians, deg2rad, rad2deg, sinh, cosh, tanh, arcsinh, arccosh, arctanh, swapaxes, moveaxis, concatenate, stack, vstack, hstack, dstack, split, array_split, vsplit, hsplit, tile, repeat, ravel, reshape, squeeze, expand_dims, flip, fliplr, flipud, rot90, roll, rollaxis, atleast_1d, atleast_2d, atleast_3d, dsplit, column_stack, row_stack, resize, append, delete_ as delete, insert, pad, broadcast_to, broadcast_arrays, broadcast_shapes, take, put, choose, array_equal, array_equiv, take_along_axis, put_along_axis, putmask, compress, select, place, diag_indices, diag_indices_from, tril_indices, tril_indices_from, triu_indices, triu_indices_from, mask_indices, indices, ix_, ravel_multi_index, unravel_index, cumsum, cumprod, ptp, median, percentile, quantile, average, nansum, nanprod, nanmean, nanvar, nanstd, nanmin, nanmax, nanargmin, nanargmax, nancumsum, nancumprod, nanmedian, bitwise_and, bitwise_or, bitwise_xor, bitwise_not, invert, left_shift, right_shift, packbits, unpackbits, sort, argsort, lexsort, partition, argpartition, sort_complex, nonzero, flatnonzero, where, searchsorted, extract, count_nonzero, } from './core/ndarray';
7
7
  export { parseNpy, serializeNpy, parseNpyHeader, parseNpyData, UnsupportedDTypeError, InvalidNpyError, SUPPORTED_DTYPES, DTYPE_TO_DESCR, type NpyHeader, type NpyMetadata, type NpyVersion, parseNpz, parseNpzSync, loadNpz, loadNpzSync, serializeNpz, serializeNpzSync, type NpzParseOptions, type NpzParseResult, type NpzSerializeOptions, } from './io';
8
8
  export declare const __version__: string;
9
9
  //# sourceMappingURL=index.d.ts.map
@@ -1,17 +1,18 @@
1
1
  /**
2
2
  * IO module for numpy-ts
3
3
  *
4
- * This module provides parsing and serialization for NPY and NPZ formats.
5
- * These functions work with bytes (Uint8Array/ArrayBuffer) and are environment-agnostic.
4
+ * This module provides parsing and serialization for NPY, NPZ, and text formats.
5
+ * These functions work with bytes/strings and are environment-agnostic.
6
6
  *
7
7
  * For file system operations (save/load), use the Node.js-specific entry point:
8
- * import { save, load } from 'numpy-ts/node';
8
+ * import { save, load, loadtxt, savetxt } from 'numpy-ts/node';
9
9
  *
10
- * For browser usage, use fetch or FileReader to get the bytes, then use these functions.
10
+ * For browser usage, use fetch or FileReader to get the bytes/text, then use these functions.
11
11
  */
12
12
  export { parseNpy, parseNpyHeader, parseNpyData } from './npy/parser';
13
13
  export { serializeNpy } from './npy/serializer';
14
14
  export { UnsupportedDTypeError, InvalidNpyError, SUPPORTED_DTYPES, DTYPE_TO_DESCR, type NpyHeader, type NpyMetadata, type NpyVersion, } from './npy/format';
15
15
  export { parseNpz, parseNpzSync, loadNpz, loadNpzSync, type NpzParseOptions, type NpzParseResult, } from './npz/parser';
16
16
  export { serializeNpz, serializeNpzSync, type NpzSerializeOptions } from './npz/serializer';
17
+ export { parseTxt, genfromtxt, fromregex, serializeTxt, type ParseTxtOptions, type SerializeTxtOptions, } from './txt';
17
18
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Text I/O module for numpy-ts
3
+ *
4
+ * Provides parsing and serialization for delimited text formats (CSV, TSV, etc.).
5
+ * These functions work with strings and are environment-agnostic.
6
+ *
7
+ * For file system operations, use the Node.js-specific entry point:
8
+ * import { loadtxt, savetxt } from 'numpy-ts/node';
9
+ */
10
+ export { parseTxt, genfromtxt, fromregex, type ParseTxtOptions } from './parser';
11
+ export { serializeTxt, type SerializeTxtOptions } from './serializer';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -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