numpy-ts 0.9.0 → 0.11.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 +45 -26
- package/dist/numpy-ts.browser.js +2 -2
- package/dist/numpy-ts.esm.js +2 -2
- package/dist/numpy-ts.node-io.cjs +3 -3
- package/dist/numpy-ts.node-io.cjs.map +4 -4
- package/dist/numpy-ts.node-io.mjs +3 -3
- 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/complex.d.ts +94 -0
- package/dist/types/core/dtype.d.ts +62 -3
- package/dist/types/core/ndarray.d.ts +663 -37
- package/dist/types/core/storage.d.ts +15 -4
- package/dist/types/index.d.ts +41 -1
- package/dist/types/ops/advanced.d.ts +7 -0
- package/dist/types/ops/arithmetic.d.ts +53 -0
- package/dist/types/ops/comparison.d.ts +6 -0
- package/dist/types/ops/complex.d.ts +65 -0
- package/dist/types/ops/exponential.d.ts +9 -0
- package/dist/types/ops/hyperbolic.d.ts +6 -0
- package/dist/types/ops/linalg.d.ts +6 -5
- package/dist/types/ops/logic.d.ts +219 -0
- package/dist/types/ops/random.d.ts +136 -0
- package/dist/types/ops/reduction.d.ts +26 -18
- package/dist/types/ops/rounding.d.ts +3 -0
- package/dist/types/ops/sorting.d.ts +8 -0
- package/dist/types/ops/statistics.d.ts +108 -0
- package/dist/types/ops/trig.d.ts +6 -0
- package/package.json +2 -2
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* @internal - This is not part of the public API
|
|
7
7
|
*/
|
|
8
8
|
import { type DType, type TypedArray } from './dtype';
|
|
9
|
+
import { Complex } from './complex';
|
|
9
10
|
/**
|
|
10
11
|
* Internal storage for NDArray data
|
|
11
12
|
* Manages the underlying TypedArray and metadata
|
|
@@ -55,20 +56,30 @@ export declare class ArrayStorage {
|
|
|
55
56
|
get isFContiguous(): boolean;
|
|
56
57
|
/**
|
|
57
58
|
* Get element at linear index (respects strides and offset)
|
|
59
|
+
* For complex dtypes, returns a Complex object.
|
|
58
60
|
*/
|
|
59
|
-
iget(linearIndex: number): number | bigint;
|
|
61
|
+
iget(linearIndex: number): number | bigint | Complex;
|
|
60
62
|
/**
|
|
61
63
|
* Set element at linear index (respects strides and offset)
|
|
64
|
+
* For complex dtypes, value can be a Complex object, {re, im} object, or number.
|
|
62
65
|
*/
|
|
63
|
-
iset(linearIndex: number, value: number | bigint
|
|
66
|
+
iset(linearIndex: number, value: number | bigint | Complex | {
|
|
67
|
+
re: number;
|
|
68
|
+
im: number;
|
|
69
|
+
}): void;
|
|
64
70
|
/**
|
|
65
71
|
* Get element at multi-index position
|
|
72
|
+
* For complex dtypes, returns a Complex object.
|
|
66
73
|
*/
|
|
67
|
-
get(...indices: number[]): number | bigint;
|
|
74
|
+
get(...indices: number[]): number | bigint | Complex;
|
|
68
75
|
/**
|
|
69
76
|
* Set element at multi-index position
|
|
77
|
+
* For complex dtypes, value can be a Complex object, {re, im} object, or number.
|
|
70
78
|
*/
|
|
71
|
-
set(indices: number[], value: number | bigint
|
|
79
|
+
set(indices: number[], value: number | bigint | Complex | {
|
|
80
|
+
re: number;
|
|
81
|
+
im: number;
|
|
82
|
+
}): void;
|
|
72
83
|
/**
|
|
73
84
|
* Create a deep copy of this storage
|
|
74
85
|
*/
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,7 +3,47 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module numpy-ts
|
|
5
5
|
*/
|
|
6
|
-
export {
|
|
6
|
+
export { Complex, type ComplexInput } from './core/complex';
|
|
7
|
+
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, pow, // alias for power
|
|
8
|
+
exp, exp2, expm1, log, log2, log10, log1p, logaddexp, logaddexp2, absolute, abs, // alias for absolute
|
|
9
|
+
negative, sign, mod, divide, true_divide, // alias for divide
|
|
10
|
+
floor_divide, positive, reciprocal, cbrt, fabs, divmod, square, remainder, heaviside, float_power, fmod, frexp, gcd, lcm, ldexp, modf, dot, trace, diagonal, kron, transpose, inner, outer, tensordot, einsum, linalg, sin, cos, tan, arcsin, asin, // alias for arcsin
|
|
11
|
+
arccos, acos, // alias for arccos
|
|
12
|
+
arctan, atan, // alias for arctan
|
|
13
|
+
arctan2, atan2, // alias for arctan2
|
|
14
|
+
hypot, degrees, radians, deg2rad, rad2deg, sinh, cosh, tanh, arcsinh, asinh, // alias for arcsinh
|
|
15
|
+
arccosh, acosh, // alias for arccosh
|
|
16
|
+
arctanh, atanh, // alias for arctanh
|
|
17
|
+
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, iindex, bindex, copyto, choose, array_equal, array_equiv, take_along_axis, put_along_axis, putmask, compress, select, place, fill_diagonal, 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, cumulative_sum, // alias for cumsum
|
|
18
|
+
cumprod, cumulative_prod, // alias for cumprod
|
|
19
|
+
max, amax, // alias for max
|
|
20
|
+
min, amin, // alias for min
|
|
21
|
+
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, logical_and, logical_or, logical_not, logical_xor, isfinite, isinf, isnan, isnat, iscomplex, iscomplexobj, isreal, isrealobj, real, imag, conj, conjugate, angle, isneginf, isposinf, isfortran, real_if_close, isscalar, iterable, isdtype, promote_types, copysign, signbit, nextafter, spacing, sort, argsort, lexsort, partition, argpartition, sort_complex, nonzero, argwhere, flatnonzero, where, searchsorted, extract, count_nonzero, around, round_, // alias for around
|
|
22
|
+
ceil, fix, floor, rint, round, trunc, unique, in1d, intersect1d, isin, setdiff1d, setxor1d, union1d, diff, ediff1d, gradient, cross, bincount, digitize, histogram, histogram2d, histogramdd, correlate, convolve, cov, corrcoef, } from './core/ndarray';
|
|
7
23
|
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';
|
|
24
|
+
import * as randomOps from './ops/random';
|
|
25
|
+
import { ArrayStorage } from './core/storage';
|
|
26
|
+
import { NDArray as NDArrayClass } from './core/ndarray';
|
|
27
|
+
import { DType } from './core/dtype';
|
|
28
|
+
export declare const random: {
|
|
29
|
+
seed: typeof randomOps.seed;
|
|
30
|
+
random: (size?: number | number[]) => number | ArrayStorage | NDArrayClass;
|
|
31
|
+
rand: (...shape: number[]) => number | ArrayStorage | NDArrayClass;
|
|
32
|
+
randn: (...shape: number[]) => number | ArrayStorage | NDArrayClass;
|
|
33
|
+
randint: (low: number, high?: number | null, size?: number | number[], dtype?: DType) => number | ArrayStorage | NDArrayClass;
|
|
34
|
+
uniform: (low?: number, high?: number, size?: number | number[]) => number | ArrayStorage | NDArrayClass;
|
|
35
|
+
normal: (loc?: number, scale?: number, size?: number | number[]) => number | ArrayStorage | NDArrayClass;
|
|
36
|
+
standard_normal: (size?: number | number[]) => number | ArrayStorage | NDArrayClass;
|
|
37
|
+
exponential: (scale?: number, size?: number | number[]) => number | ArrayStorage | NDArrayClass;
|
|
38
|
+
poisson: (lam?: number, size?: number | number[]) => number | ArrayStorage | NDArrayClass;
|
|
39
|
+
binomial: (n: number, p: number, size?: number | number[]) => number | ArrayStorage | NDArrayClass;
|
|
40
|
+
choice: (a: number | ArrayStorage, size?: number | number[], replace?: boolean, p?: ArrayStorage | number[]) => number | ArrayStorage | NDArrayClass;
|
|
41
|
+
permutation: (x: number | ArrayStorage) => ArrayStorage | NDArrayClass;
|
|
42
|
+
shuffle: typeof randomOps.shuffle;
|
|
43
|
+
get_state: typeof randomOps.get_state;
|
|
44
|
+
set_state: typeof randomOps.set_state;
|
|
45
|
+
default_rng: typeof randomOps.default_rng;
|
|
46
|
+
Generator: typeof randomOps.Generator;
|
|
47
|
+
};
|
|
8
48
|
export declare const __version__: string;
|
|
9
49
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -105,4 +105,11 @@ export declare function ravel_multi_index(multi_index: ArrayStorage[], dims: num
|
|
|
105
105
|
* Convert flat index array to tuple of coordinate arrays
|
|
106
106
|
*/
|
|
107
107
|
export declare function unravel_index(indices: ArrayStorage | number, shape: number[], order?: 'C' | 'F'): ArrayStorage[];
|
|
108
|
+
/**
|
|
109
|
+
* Fill the main diagonal of a given array (modifies in-place)
|
|
110
|
+
* @param a - Array storage (at least 2D)
|
|
111
|
+
* @param val - Value or array of values to fill diagonal with
|
|
112
|
+
* @param wrap - Whether to wrap for tall matrices
|
|
113
|
+
*/
|
|
114
|
+
export declare function fill_diagonal(a: ArrayStorage, val: ArrayStorage | number, wrap?: boolean): void;
|
|
108
115
|
//# sourceMappingURL=advanced.d.ts.map
|
|
@@ -37,6 +37,8 @@ export declare function multiply(a: ArrayStorage, b: ArrayStorage | number): Arr
|
|
|
37
37
|
*
|
|
38
38
|
* NumPy behavior: Integer division always promotes to float
|
|
39
39
|
* Type promotion rules:
|
|
40
|
+
* - complex128 + anything → complex128
|
|
41
|
+
* - complex64 + float32/int → complex64
|
|
40
42
|
* - float64 + anything → float64
|
|
41
43
|
* - float32 + integer → float32
|
|
42
44
|
* - integer + integer → float64
|
|
@@ -100,6 +102,7 @@ export declare function positive(a: ArrayStorage): ArrayStorage;
|
|
|
100
102
|
/**
|
|
101
103
|
* Reciprocal (1/x) of each element
|
|
102
104
|
* NumPy behavior: Always promotes to float64 for integer types
|
|
105
|
+
* For complex: 1/z = z̄/|z|² = (re - i*im) / (re² + im²)
|
|
103
106
|
*
|
|
104
107
|
* @param a - Input array storage
|
|
105
108
|
* @returns Result storage with reciprocal values
|
|
@@ -133,6 +136,7 @@ export declare function divmod(a: ArrayStorage, b: ArrayStorage | number): [Arra
|
|
|
133
136
|
/**
|
|
134
137
|
* Element-wise square of each element
|
|
135
138
|
* NumPy behavior: x**2
|
|
139
|
+
* For complex: z² = (re + i*im)² = (re² - im²) + i*(2*re*im)
|
|
136
140
|
*
|
|
137
141
|
* @param a - Input array storage
|
|
138
142
|
* @returns Result storage with squared values
|
|
@@ -159,4 +163,53 @@ export declare function remainder(a: ArrayStorage, b: ArrayStorage | number): Ar
|
|
|
159
163
|
* @returns Result storage with heaviside values
|
|
160
164
|
*/
|
|
161
165
|
export declare function heaviside(x1: ArrayStorage, x2: ArrayStorage | number): ArrayStorage;
|
|
166
|
+
/**
|
|
167
|
+
* First array raised to power of second, always promoting to float
|
|
168
|
+
* @param x1 - Base values
|
|
169
|
+
* @param x2 - Exponent values
|
|
170
|
+
* @returns Result in float64
|
|
171
|
+
*/
|
|
172
|
+
export declare function float_power(x1: ArrayStorage, x2: ArrayStorage | number): ArrayStorage;
|
|
173
|
+
/**
|
|
174
|
+
* Element-wise remainder of division (fmod)
|
|
175
|
+
* Unlike mod/remainder, fmod matches C fmod behavior
|
|
176
|
+
* @param x1 - Dividend
|
|
177
|
+
* @param x2 - Divisor
|
|
178
|
+
* @returns Remainder
|
|
179
|
+
*/
|
|
180
|
+
export declare function fmod(x1: ArrayStorage, x2: ArrayStorage | number): ArrayStorage;
|
|
181
|
+
/**
|
|
182
|
+
* Decompose floating point numbers into mantissa and exponent
|
|
183
|
+
* Returns [mantissa, exponent] where x = mantissa * 2^exponent
|
|
184
|
+
* @param x - Input array
|
|
185
|
+
* @returns Tuple of [mantissa, exponent] arrays
|
|
186
|
+
*/
|
|
187
|
+
export declare function frexp(x: ArrayStorage): [ArrayStorage, ArrayStorage];
|
|
188
|
+
/**
|
|
189
|
+
* Greatest common divisor
|
|
190
|
+
* @param x1 - First array
|
|
191
|
+
* @param x2 - Second array or scalar
|
|
192
|
+
* @returns GCD
|
|
193
|
+
*/
|
|
194
|
+
export declare function gcd(x1: ArrayStorage, x2: ArrayStorage | number): ArrayStorage;
|
|
195
|
+
/**
|
|
196
|
+
* Least common multiple
|
|
197
|
+
* @param x1 - First array
|
|
198
|
+
* @param x2 - Second array or scalar
|
|
199
|
+
* @returns LCM
|
|
200
|
+
*/
|
|
201
|
+
export declare function lcm(x1: ArrayStorage, x2: ArrayStorage | number): ArrayStorage;
|
|
202
|
+
/**
|
|
203
|
+
* Returns x1 * 2^x2, element-wise
|
|
204
|
+
* @param x1 - Mantissa
|
|
205
|
+
* @param x2 - Exponent
|
|
206
|
+
* @returns Result
|
|
207
|
+
*/
|
|
208
|
+
export declare function ldexp(x1: ArrayStorage, x2: ArrayStorage | number): ArrayStorage;
|
|
209
|
+
/**
|
|
210
|
+
* Return fractional and integral parts of array
|
|
211
|
+
* @param x - Input array
|
|
212
|
+
* @returns Tuple of [fractional, integral] arrays
|
|
213
|
+
*/
|
|
214
|
+
export declare function modf(x: ArrayStorage): [ArrayStorage, ArrayStorage];
|
|
162
215
|
//# sourceMappingURL=arithmetic.d.ts.map
|
|
@@ -8,26 +8,32 @@
|
|
|
8
8
|
import { ArrayStorage } from '../core/storage';
|
|
9
9
|
/**
|
|
10
10
|
* Element-wise greater than comparison (a > b)
|
|
11
|
+
* For complex: uses lexicographic ordering (real first, then imaginary)
|
|
11
12
|
*/
|
|
12
13
|
export declare function greater(a: ArrayStorage, b: ArrayStorage | number): ArrayStorage;
|
|
13
14
|
/**
|
|
14
15
|
* Element-wise greater than or equal comparison (a >= b)
|
|
16
|
+
* For complex: uses lexicographic ordering (real first, then imaginary)
|
|
15
17
|
*/
|
|
16
18
|
export declare function greaterEqual(a: ArrayStorage, b: ArrayStorage | number): ArrayStorage;
|
|
17
19
|
/**
|
|
18
20
|
* Element-wise less than comparison (a < b)
|
|
21
|
+
* For complex: uses lexicographic ordering (real first, then imaginary)
|
|
19
22
|
*/
|
|
20
23
|
export declare function less(a: ArrayStorage, b: ArrayStorage | number): ArrayStorage;
|
|
21
24
|
/**
|
|
22
25
|
* Element-wise less than or equal comparison (a <= b)
|
|
26
|
+
* For complex: uses lexicographic ordering (real first, then imaginary)
|
|
23
27
|
*/
|
|
24
28
|
export declare function lessEqual(a: ArrayStorage, b: ArrayStorage | number): ArrayStorage;
|
|
25
29
|
/**
|
|
26
30
|
* Element-wise equality comparison (a == b)
|
|
31
|
+
* For complex: both real and imaginary parts must be equal
|
|
27
32
|
*/
|
|
28
33
|
export declare function equal(a: ArrayStorage, b: ArrayStorage | number): ArrayStorage;
|
|
29
34
|
/**
|
|
30
35
|
* Element-wise inequality comparison (a != b)
|
|
36
|
+
* For complex: either real or imaginary parts must differ
|
|
31
37
|
*/
|
|
32
38
|
export declare function notEqual(a: ArrayStorage, b: ArrayStorage | number): ArrayStorage;
|
|
33
39
|
/**
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Complex number operations
|
|
3
|
+
*
|
|
4
|
+
* Pure functions for complex array operations:
|
|
5
|
+
* real, imag, conj, angle
|
|
6
|
+
*
|
|
7
|
+
* @module ops/complex
|
|
8
|
+
*/
|
|
9
|
+
import { ArrayStorage } from '../core/storage';
|
|
10
|
+
/**
|
|
11
|
+
* Return the real part of complex argument.
|
|
12
|
+
*
|
|
13
|
+
* For complex arrays, returns the real components.
|
|
14
|
+
* For real arrays, returns a copy of the input.
|
|
15
|
+
*
|
|
16
|
+
* @param a - Input array storage
|
|
17
|
+
* @returns Array with real parts (float64 or float32 for complex, same dtype for real)
|
|
18
|
+
*/
|
|
19
|
+
export declare function real(a: ArrayStorage): ArrayStorage;
|
|
20
|
+
/**
|
|
21
|
+
* Return the imaginary part of complex argument.
|
|
22
|
+
*
|
|
23
|
+
* For complex arrays, returns the imaginary components.
|
|
24
|
+
* For real arrays, returns zeros.
|
|
25
|
+
*
|
|
26
|
+
* @param a - Input array storage
|
|
27
|
+
* @returns Array with imaginary parts
|
|
28
|
+
*/
|
|
29
|
+
export declare function imag(a: ArrayStorage): ArrayStorage;
|
|
30
|
+
/**
|
|
31
|
+
* Return the complex conjugate.
|
|
32
|
+
*
|
|
33
|
+
* For complex arrays, negates the imaginary part: (a + bi) -> (a - bi)
|
|
34
|
+
* For real arrays, returns a copy of the input.
|
|
35
|
+
*
|
|
36
|
+
* @param a - Input array storage
|
|
37
|
+
* @returns Complex conjugate array
|
|
38
|
+
*/
|
|
39
|
+
export declare function conj(a: ArrayStorage): ArrayStorage;
|
|
40
|
+
export declare const conjugate: typeof conj;
|
|
41
|
+
/**
|
|
42
|
+
* Return the angle (phase) of complex argument.
|
|
43
|
+
*
|
|
44
|
+
* angle(z) = arctan2(imag(z), real(z))
|
|
45
|
+
*
|
|
46
|
+
* For real arrays, returns 0 for positive, pi for negative.
|
|
47
|
+
*
|
|
48
|
+
* @param a - Input array storage
|
|
49
|
+
* @param deg - Return angle in degrees if true (default: false, returns radians)
|
|
50
|
+
* @returns Array with angles in radians (or degrees)
|
|
51
|
+
*/
|
|
52
|
+
export declare function angle(a: ArrayStorage, deg?: boolean): ArrayStorage;
|
|
53
|
+
/**
|
|
54
|
+
* Return the absolute value (magnitude) for complex arrays.
|
|
55
|
+
*
|
|
56
|
+
* For complex: |z| = sqrt(re² + im²)
|
|
57
|
+
* For real: |x| = abs(x)
|
|
58
|
+
*
|
|
59
|
+
* This is a helper that can be called from arithmetic.absolute
|
|
60
|
+
*
|
|
61
|
+
* @param a - Input array storage
|
|
62
|
+
* @returns Array with magnitudes
|
|
63
|
+
*/
|
|
64
|
+
export declare function complexAbs(a: ArrayStorage): ArrayStorage;
|
|
65
|
+
//# sourceMappingURL=complex.d.ts.map
|
|
@@ -11,6 +11,7 @@ import { ArrayStorage } from '../core/storage';
|
|
|
11
11
|
/**
|
|
12
12
|
* Square root of each element
|
|
13
13
|
* NumPy behavior: Always promotes to float64 for integer types
|
|
14
|
+
* For complex: sqrt(a+bi) = sqrt((|z|+a)/2) + sign(b)*i*sqrt((|z|-a)/2)
|
|
14
15
|
*
|
|
15
16
|
* @param a - Input array storage
|
|
16
17
|
* @returns Result storage with sqrt applied
|
|
@@ -19,6 +20,7 @@ export declare function sqrt(a: ArrayStorage): ArrayStorage;
|
|
|
19
20
|
/**
|
|
20
21
|
* Raise elements to power
|
|
21
22
|
* NumPy behavior: Promotes to float64 for integer types with non-integer exponents
|
|
23
|
+
* For complex: z^n = |z|^n * (cos(n*θ) + i*sin(n*θ)) where θ = atan2(im, re)
|
|
22
24
|
*
|
|
23
25
|
* @param a - Base array storage
|
|
24
26
|
* @param b - Exponent (array storage or scalar)
|
|
@@ -28,6 +30,7 @@ export declare function power(a: ArrayStorage, b: ArrayStorage | number): ArrayS
|
|
|
28
30
|
/**
|
|
29
31
|
* Natural exponential function (e^x) for each element
|
|
30
32
|
* NumPy behavior: Always promotes to float64 for integer types
|
|
33
|
+
* For complex: exp(a+bi) = e^a * (cos(b) + i*sin(b))
|
|
31
34
|
*
|
|
32
35
|
* @param a - Input array storage
|
|
33
36
|
* @returns Result storage with exp applied
|
|
@@ -36,6 +39,7 @@ export declare function exp(a: ArrayStorage): ArrayStorage;
|
|
|
36
39
|
/**
|
|
37
40
|
* Base-2 exponential function (2^x) for each element
|
|
38
41
|
* NumPy behavior: Always promotes to float64 for integer types
|
|
42
|
+
* For complex: 2^z = exp(z * ln(2))
|
|
39
43
|
*
|
|
40
44
|
* @param a - Input array storage
|
|
41
45
|
* @returns Result storage with 2^x applied
|
|
@@ -45,6 +49,7 @@ export declare function exp2(a: ArrayStorage): ArrayStorage;
|
|
|
45
49
|
* Exponential minus one (e^x - 1) for each element
|
|
46
50
|
* More accurate than exp(x) - 1 for small x
|
|
47
51
|
* NumPy behavior: Always promotes to float64 for integer types
|
|
52
|
+
* For complex: expm1(z) = exp(z) - 1
|
|
48
53
|
*
|
|
49
54
|
* @param a - Input array storage
|
|
50
55
|
* @returns Result storage with expm1 applied
|
|
@@ -53,6 +58,7 @@ export declare function expm1(a: ArrayStorage): ArrayStorage;
|
|
|
53
58
|
/**
|
|
54
59
|
* Natural logarithm (ln) for each element
|
|
55
60
|
* NumPy behavior: Always promotes to float64 for integer types
|
|
61
|
+
* For complex: log(a+bi) = ln|z| + i*arg(z) = ln(sqrt(a²+b²)) + i*atan2(b,a)
|
|
56
62
|
*
|
|
57
63
|
* @param a - Input array storage
|
|
58
64
|
* @returns Result storage with log applied
|
|
@@ -61,6 +67,7 @@ export declare function log(a: ArrayStorage): ArrayStorage;
|
|
|
61
67
|
/**
|
|
62
68
|
* Base-2 logarithm for each element
|
|
63
69
|
* NumPy behavior: Always promotes to float64 for integer types
|
|
70
|
+
* For complex: log2(z) = log(z) / ln(2)
|
|
64
71
|
*
|
|
65
72
|
* @param a - Input array storage
|
|
66
73
|
* @returns Result storage with log2 applied
|
|
@@ -69,6 +76,7 @@ export declare function log2(a: ArrayStorage): ArrayStorage;
|
|
|
69
76
|
/**
|
|
70
77
|
* Base-10 logarithm for each element
|
|
71
78
|
* NumPy behavior: Always promotes to float64 for integer types
|
|
79
|
+
* For complex: log10(z) = log(z) / ln(10)
|
|
72
80
|
*
|
|
73
81
|
* @param a - Input array storage
|
|
74
82
|
* @returns Result storage with log10 applied
|
|
@@ -78,6 +86,7 @@ export declare function log10(a: ArrayStorage): ArrayStorage;
|
|
|
78
86
|
* Natural logarithm of (1 + x) for each element
|
|
79
87
|
* More accurate than log(1 + x) for small x
|
|
80
88
|
* NumPy behavior: Always promotes to float64 for integer types
|
|
89
|
+
* For complex: log1p(z) = log(1 + z)
|
|
81
90
|
*
|
|
82
91
|
* @param a - Input array storage
|
|
83
92
|
* @returns Result storage with log1p applied
|
|
@@ -11,6 +11,7 @@ import { ArrayStorage } from '../core/storage';
|
|
|
11
11
|
/**
|
|
12
12
|
* Hyperbolic sine of each element (element-wise)
|
|
13
13
|
* NumPy behavior: Always promotes to float64 for integer types
|
|
14
|
+
* For complex: sinh(a+bi) = sinh(a)cos(b) + i*cosh(a)sin(b)
|
|
14
15
|
*
|
|
15
16
|
* @param a - Input array storage
|
|
16
17
|
* @returns Result storage with sinh applied
|
|
@@ -19,6 +20,7 @@ export declare function sinh(a: ArrayStorage): ArrayStorage;
|
|
|
19
20
|
/**
|
|
20
21
|
* Hyperbolic cosine of each element (element-wise)
|
|
21
22
|
* NumPy behavior: Always promotes to float64 for integer types
|
|
23
|
+
* For complex: cosh(a+bi) = cosh(a)cos(b) + i*sinh(a)sin(b)
|
|
22
24
|
*
|
|
23
25
|
* @param a - Input array storage
|
|
24
26
|
* @returns Result storage with cosh applied
|
|
@@ -27,6 +29,7 @@ export declare function cosh(a: ArrayStorage): ArrayStorage;
|
|
|
27
29
|
/**
|
|
28
30
|
* Hyperbolic tangent of each element (element-wise)
|
|
29
31
|
* NumPy behavior: Always promotes to float64 for integer types
|
|
32
|
+
* For complex: tanh(z) = (sinh(2a) + i*sin(2b)) / (cosh(2a) + cos(2b))
|
|
30
33
|
*
|
|
31
34
|
* @param a - Input array storage
|
|
32
35
|
* @returns Result storage with tanh applied
|
|
@@ -35,6 +38,7 @@ export declare function tanh(a: ArrayStorage): ArrayStorage;
|
|
|
35
38
|
/**
|
|
36
39
|
* Inverse hyperbolic sine of each element (element-wise)
|
|
37
40
|
* NumPy behavior: Always promotes to float64 for integer types
|
|
41
|
+
* For complex: arcsinh(z) = log(z + sqrt(z² + 1))
|
|
38
42
|
*
|
|
39
43
|
* @param a - Input array storage
|
|
40
44
|
* @returns Result storage with arcsinh applied
|
|
@@ -43,6 +47,7 @@ export declare function arcsinh(a: ArrayStorage): ArrayStorage;
|
|
|
43
47
|
/**
|
|
44
48
|
* Inverse hyperbolic cosine of each element (element-wise)
|
|
45
49
|
* NumPy behavior: Always promotes to float64 for integer types
|
|
50
|
+
* For complex: arccosh(z) = log(z + sqrt(z - 1) * sqrt(z + 1))
|
|
46
51
|
*
|
|
47
52
|
* @param a - Input array storage (values >= 1)
|
|
48
53
|
* @returns Result storage with arccosh applied
|
|
@@ -51,6 +56,7 @@ export declare function arccosh(a: ArrayStorage): ArrayStorage;
|
|
|
51
56
|
/**
|
|
52
57
|
* Inverse hyperbolic tangent of each element (element-wise)
|
|
53
58
|
* NumPy behavior: Always promotes to float64 for integer types
|
|
59
|
+
* For complex: arctanh(z) = (1/2) * log((1+z)/(1-z))
|
|
54
60
|
*
|
|
55
61
|
* @param a - Input array storage (values in range (-1, 1))
|
|
56
62
|
* @returns Result storage with arctanh applied
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* @module ops/linalg
|
|
6
6
|
*/
|
|
7
7
|
import { ArrayStorage } from '../core/storage';
|
|
8
|
+
import { Complex } from '../core/complex';
|
|
8
9
|
/**
|
|
9
10
|
* Dot product of two arrays (fully NumPy-compatible)
|
|
10
11
|
*
|
|
@@ -21,7 +22,7 @@ import { ArrayStorage } from '../core/storage';
|
|
|
21
22
|
*
|
|
22
23
|
* For 2D·2D, prefer using matmul() instead.
|
|
23
24
|
*/
|
|
24
|
-
export declare function dot(a: ArrayStorage, b: ArrayStorage): ArrayStorage | number | bigint;
|
|
25
|
+
export declare function dot(a: ArrayStorage, b: ArrayStorage): ArrayStorage | number | bigint | Complex;
|
|
25
26
|
/**
|
|
26
27
|
* Matrix multiplication
|
|
27
28
|
* Requires 2D arrays with compatible shapes
|
|
@@ -42,7 +43,7 @@ export declare function matmul(a: ArrayStorage, b: ArrayStorage): ArrayStorage;
|
|
|
42
43
|
* @param a - Input 2D array
|
|
43
44
|
* @returns Sum of diagonal elements
|
|
44
45
|
*/
|
|
45
|
-
export declare function trace(a: ArrayStorage): number | bigint;
|
|
46
|
+
export declare function trace(a: ArrayStorage): number | bigint | Complex;
|
|
46
47
|
/**
|
|
47
48
|
* Permute the dimensions of an array
|
|
48
49
|
*
|
|
@@ -67,7 +68,7 @@ export declare function transpose(a: ArrayStorage, axes?: number[]): ArrayStorag
|
|
|
67
68
|
* @param b - Second array
|
|
68
69
|
* @returns Inner product result
|
|
69
70
|
*/
|
|
70
|
-
export declare function inner(a: ArrayStorage, b: ArrayStorage): ArrayStorage | number | bigint;
|
|
71
|
+
export declare function inner(a: ArrayStorage, b: ArrayStorage): ArrayStorage | number | bigint | Complex;
|
|
71
72
|
/**
|
|
72
73
|
* Outer product of two vectors
|
|
73
74
|
*
|
|
@@ -91,7 +92,7 @@ export declare function outer(a: ArrayStorage, b: ArrayStorage): ArrayStorage;
|
|
|
91
92
|
* - [a_axes, b_axes]: Contract specified axes
|
|
92
93
|
* @returns Tensor dot product
|
|
93
94
|
*/
|
|
94
|
-
export declare function tensordot(a: ArrayStorage, b: ArrayStorage, axes: number | [number[], number[]]): ArrayStorage | number | bigint;
|
|
95
|
+
export declare function tensordot(a: ArrayStorage, b: ArrayStorage, axes: number | [number[], number[]]): ArrayStorage | number | bigint | Complex;
|
|
95
96
|
/**
|
|
96
97
|
* Extract a diagonal or construct a diagonal array.
|
|
97
98
|
*
|
|
@@ -126,7 +127,7 @@ export declare function diagonal(a: ArrayStorage, offset?: number, axis1?: numbe
|
|
|
126
127
|
* @param operands - Input arrays
|
|
127
128
|
* @returns Result of the Einstein summation
|
|
128
129
|
*/
|
|
129
|
-
export declare function einsum(subscripts: string, ...operands: ArrayStorage[]): ArrayStorage | number | bigint;
|
|
130
|
+
export declare function einsum(subscripts: string, ...operands: ArrayStorage[]): ArrayStorage | number | bigint | Complex;
|
|
130
131
|
/**
|
|
131
132
|
* Kronecker product of two arrays.
|
|
132
133
|
*
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logic operations
|
|
3
|
+
*
|
|
4
|
+
* Pure functions for element-wise logical operations:
|
|
5
|
+
* logical_and, logical_or, logical_not, logical_xor,
|
|
6
|
+
* isfinite, isinf, isnan, isnat, copysign, signbit, nextafter, spacing
|
|
7
|
+
*
|
|
8
|
+
* These operations convert values to boolean (non-zero = true, zero = false)
|
|
9
|
+
* and return boolean arrays (dtype: 'bool').
|
|
10
|
+
*/
|
|
11
|
+
import { ArrayStorage } from '../core/storage';
|
|
12
|
+
import { type DType } from '../core/dtype';
|
|
13
|
+
/**
|
|
14
|
+
* Logical AND of two arrays or array and scalar
|
|
15
|
+
*
|
|
16
|
+
* Returns a boolean array where each element is the logical AND
|
|
17
|
+
* of corresponding elements (non-zero = true, zero = false).
|
|
18
|
+
*
|
|
19
|
+
* @param a - First array storage
|
|
20
|
+
* @param b - Second array storage or scalar
|
|
21
|
+
* @returns Boolean result storage
|
|
22
|
+
*/
|
|
23
|
+
export declare function logical_and(a: ArrayStorage, b: ArrayStorage | number): ArrayStorage;
|
|
24
|
+
/**
|
|
25
|
+
* Logical OR of two arrays or array and scalar
|
|
26
|
+
*
|
|
27
|
+
* Returns a boolean array where each element is the logical OR
|
|
28
|
+
* of corresponding elements (non-zero = true, zero = false).
|
|
29
|
+
*
|
|
30
|
+
* @param a - First array storage
|
|
31
|
+
* @param b - Second array storage or scalar
|
|
32
|
+
* @returns Boolean result storage
|
|
33
|
+
*/
|
|
34
|
+
export declare function logical_or(a: ArrayStorage, b: ArrayStorage | number): ArrayStorage;
|
|
35
|
+
/**
|
|
36
|
+
* Logical NOT of an array
|
|
37
|
+
*
|
|
38
|
+
* Returns a boolean array where each element is the logical NOT
|
|
39
|
+
* of the input (non-zero = false, zero = true).
|
|
40
|
+
*
|
|
41
|
+
* @param a - Input array storage
|
|
42
|
+
* @returns Boolean result storage
|
|
43
|
+
*/
|
|
44
|
+
export declare function logical_not(a: ArrayStorage): ArrayStorage;
|
|
45
|
+
/**
|
|
46
|
+
* Logical XOR of two arrays or array and scalar
|
|
47
|
+
*
|
|
48
|
+
* Returns a boolean array where each element is the logical XOR
|
|
49
|
+
* of corresponding elements (non-zero = true, zero = false).
|
|
50
|
+
*
|
|
51
|
+
* @param a - First array storage
|
|
52
|
+
* @param b - Second array storage or scalar
|
|
53
|
+
* @returns Boolean result storage
|
|
54
|
+
*/
|
|
55
|
+
export declare function logical_xor(a: ArrayStorage, b: ArrayStorage | number): ArrayStorage;
|
|
56
|
+
/**
|
|
57
|
+
* Test element-wise for finiteness (not infinity and not NaN)
|
|
58
|
+
*
|
|
59
|
+
* For complex numbers: True if both real and imaginary parts are finite.
|
|
60
|
+
*
|
|
61
|
+
* @param a - Input array storage
|
|
62
|
+
* @returns Boolean result storage
|
|
63
|
+
*/
|
|
64
|
+
export declare function isfinite(a: ArrayStorage): ArrayStorage;
|
|
65
|
+
/**
|
|
66
|
+
* Test element-wise for positive or negative infinity
|
|
67
|
+
*
|
|
68
|
+
* For complex numbers: True if either real or imaginary part is infinite.
|
|
69
|
+
*
|
|
70
|
+
* @param a - Input array storage
|
|
71
|
+
* @returns Boolean result storage
|
|
72
|
+
*/
|
|
73
|
+
export declare function isinf(a: ArrayStorage): ArrayStorage;
|
|
74
|
+
/**
|
|
75
|
+
* Test element-wise for NaN (Not a Number)
|
|
76
|
+
*
|
|
77
|
+
* For complex numbers: True if either real or imaginary part is NaN.
|
|
78
|
+
*
|
|
79
|
+
* @param a - Input array storage
|
|
80
|
+
* @returns Boolean result storage
|
|
81
|
+
*/
|
|
82
|
+
export declare function isnan(a: ArrayStorage): ArrayStorage;
|
|
83
|
+
/**
|
|
84
|
+
* Test element-wise for NaT (Not a Time)
|
|
85
|
+
*
|
|
86
|
+
* In NumPy, NaT is the datetime equivalent of NaN.
|
|
87
|
+
* Since we don't have datetime support, this always returns false.
|
|
88
|
+
*
|
|
89
|
+
* @param a - Input array storage
|
|
90
|
+
* @returns Boolean result storage (all false)
|
|
91
|
+
*/
|
|
92
|
+
export declare function isnat(a: ArrayStorage): ArrayStorage;
|
|
93
|
+
/**
|
|
94
|
+
* Change the sign of x1 to that of x2, element-wise
|
|
95
|
+
*
|
|
96
|
+
* Returns a value with the magnitude of x1 and the sign of x2.
|
|
97
|
+
*
|
|
98
|
+
* @param x1 - Values to change sign of (magnitude source)
|
|
99
|
+
* @param x2 - Values whose sign is used (sign source)
|
|
100
|
+
* @returns Array with magnitude from x1 and sign from x2
|
|
101
|
+
*/
|
|
102
|
+
export declare function copysign(x1: ArrayStorage, x2: ArrayStorage | number): ArrayStorage;
|
|
103
|
+
/**
|
|
104
|
+
* Returns element-wise True where signbit is set (less than zero)
|
|
105
|
+
*
|
|
106
|
+
* @param a - Input array storage
|
|
107
|
+
* @returns Boolean result storage
|
|
108
|
+
*/
|
|
109
|
+
export declare function signbit(a: ArrayStorage): ArrayStorage;
|
|
110
|
+
/**
|
|
111
|
+
* Return the next floating-point value after x1 towards x2, element-wise
|
|
112
|
+
*
|
|
113
|
+
* @param x1 - Values to find the next representable value of
|
|
114
|
+
* @param x2 - Direction to look in for the next representable value
|
|
115
|
+
* @returns Array of next representable values
|
|
116
|
+
*/
|
|
117
|
+
export declare function nextafter(x1: ArrayStorage, x2: ArrayStorage | number): ArrayStorage;
|
|
118
|
+
/**
|
|
119
|
+
* Return the distance between x and the nearest adjacent number
|
|
120
|
+
*
|
|
121
|
+
* This is the difference between x and the next representable floating-point value.
|
|
122
|
+
*
|
|
123
|
+
* @param a - Input array storage
|
|
124
|
+
* @returns Array of spacing values
|
|
125
|
+
*/
|
|
126
|
+
export declare function spacing(a: ArrayStorage): ArrayStorage;
|
|
127
|
+
/**
|
|
128
|
+
* Test element-wise for complex number.
|
|
129
|
+
*
|
|
130
|
+
* For complex arrays, returns true for elements with non-zero imaginary part.
|
|
131
|
+
* For real arrays, always returns false.
|
|
132
|
+
*
|
|
133
|
+
* @param a - Input array storage
|
|
134
|
+
* @returns Boolean array
|
|
135
|
+
*/
|
|
136
|
+
export declare function iscomplex(a: ArrayStorage): ArrayStorage;
|
|
137
|
+
/**
|
|
138
|
+
* Check whether object is complex type array.
|
|
139
|
+
*
|
|
140
|
+
* @param a - Input array storage
|
|
141
|
+
* @returns true if dtype is complex64 or complex128
|
|
142
|
+
*/
|
|
143
|
+
export declare function iscomplexobj(a: ArrayStorage): boolean;
|
|
144
|
+
/**
|
|
145
|
+
* Test element-wise for real number (not complex).
|
|
146
|
+
*
|
|
147
|
+
* For complex arrays, returns true for elements with zero imaginary part.
|
|
148
|
+
* For real arrays, always returns true.
|
|
149
|
+
*
|
|
150
|
+
* @param a - Input array storage
|
|
151
|
+
* @returns Boolean array
|
|
152
|
+
*/
|
|
153
|
+
export declare function isreal(a: ArrayStorage): ArrayStorage;
|
|
154
|
+
/**
|
|
155
|
+
* Check whether object is real type array (not complex).
|
|
156
|
+
*
|
|
157
|
+
* @param a - Input array storage
|
|
158
|
+
* @returns true if dtype is NOT complex64 or complex128
|
|
159
|
+
*/
|
|
160
|
+
export declare function isrealobj(a: ArrayStorage): boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Test element-wise for negative infinity
|
|
163
|
+
*
|
|
164
|
+
* For complex numbers: True if either real or imaginary part is -Infinity.
|
|
165
|
+
*
|
|
166
|
+
* @param a - Input array storage
|
|
167
|
+
* @returns Boolean array
|
|
168
|
+
*/
|
|
169
|
+
export declare function isneginf(a: ArrayStorage): ArrayStorage;
|
|
170
|
+
/**
|
|
171
|
+
* Test element-wise for positive infinity
|
|
172
|
+
*
|
|
173
|
+
* For complex numbers: True if either real or imaginary part is +Infinity.
|
|
174
|
+
*
|
|
175
|
+
* @param a - Input array storage
|
|
176
|
+
* @returns Boolean array
|
|
177
|
+
*/
|
|
178
|
+
export declare function isposinf(a: ArrayStorage): ArrayStorage;
|
|
179
|
+
/**
|
|
180
|
+
* Check if array is Fortran contiguous (column-major order)
|
|
181
|
+
* @param a - Input array storage
|
|
182
|
+
* @returns true if F-contiguous
|
|
183
|
+
*/
|
|
184
|
+
export declare function isfortran(a: ArrayStorage): boolean;
|
|
185
|
+
/**
|
|
186
|
+
* Returns complex array with complex parts close to zero set to real
|
|
187
|
+
* Since numpy-ts doesn't support complex numbers, returns copy
|
|
188
|
+
* @param a - Input array storage
|
|
189
|
+
* @param _tol - Tolerance (unused, for API compatibility)
|
|
190
|
+
* @returns Copy of input array
|
|
191
|
+
*/
|
|
192
|
+
export declare function real_if_close(a: ArrayStorage, tol?: number): ArrayStorage;
|
|
193
|
+
/**
|
|
194
|
+
* Check if element is a scalar type
|
|
195
|
+
* @param val - Value to check
|
|
196
|
+
* @returns true if scalar
|
|
197
|
+
*/
|
|
198
|
+
export declare function isscalar(val: unknown): boolean;
|
|
199
|
+
/**
|
|
200
|
+
* Check if object is iterable
|
|
201
|
+
* @param obj - Object to check
|
|
202
|
+
* @returns true if iterable
|
|
203
|
+
*/
|
|
204
|
+
export declare function iterable(obj: unknown): boolean;
|
|
205
|
+
/**
|
|
206
|
+
* Check if dtype meets specified criteria
|
|
207
|
+
* @param dtype - Dtype to check
|
|
208
|
+
* @param kind - Kind of dtype ('b' bool, 'i' int, 'u' uint, 'f' float)
|
|
209
|
+
* @returns true if dtype matches kind
|
|
210
|
+
*/
|
|
211
|
+
export declare function isdtype(dtype: DType, kind: string): boolean;
|
|
212
|
+
/**
|
|
213
|
+
* Find the dtype that can represent both input dtypes
|
|
214
|
+
* @param dtype1 - First dtype
|
|
215
|
+
* @param dtype2 - Second dtype
|
|
216
|
+
* @returns Promoted dtype
|
|
217
|
+
*/
|
|
218
|
+
export declare function promote_types(dtype1: DType, dtype2: DType): DType;
|
|
219
|
+
//# sourceMappingURL=logic.d.ts.map
|