numpy-ts 0.5.0 → 0.6.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.
@@ -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, sqrt, power, absolute, negative, sign, mod, floor_divide, positive, reciprocal, dot, trace, transpose, inner, outer, tensordot, sin, cos, tan, arcsin, arccos, arctan, arctan2, hypot, degrees, radians, sinh, cosh, tanh, arcsinh, arccosh, arctanh, swapaxes, moveaxis, concatenate, stack, vstack, hstack, dstack, split, array_split, vsplit, hsplit, tile, repeat, broadcast_to, broadcast_arrays, take, put, choose, array_equal, } 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, cumsum, cumprod, ptp, median, percentile, quantile, average, nansum, nanprod, nanmean, nanvar, nanstd, nanmin, nanmax, nanargmin, nanargmax, nancumsum, nancumprod, nanmedian, } 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
@@ -5,6 +5,7 @@
5
5
  * @module ops/advanced
6
6
  */
7
7
  import { ArrayStorage } from '../core/storage';
8
+ import { broadcastShapes } from '../core/broadcasting';
8
9
  /**
9
10
  * Broadcast an array to a given shape
10
11
  * Returns a read-only view on the original array
@@ -15,6 +16,11 @@ export declare function broadcast_to(storage: ArrayStorage, targetShape: number[
15
16
  * Returns views on the original arrays
16
17
  */
17
18
  export declare function broadcast_arrays(storages: ArrayStorage[]): ArrayStorage[];
19
+ /**
20
+ * Compute the broadcast shape for multiple shapes
21
+ * Re-export from core/broadcasting for convenience
22
+ */
23
+ export { broadcastShapes as broadcast_shapes };
18
24
  /**
19
25
  * Take elements from an array along an axis
20
26
  */
@@ -105,4 +105,58 @@ export declare function positive(a: ArrayStorage): ArrayStorage;
105
105
  * @returns Result storage with reciprocal values
106
106
  */
107
107
  export declare function reciprocal(a: ArrayStorage): ArrayStorage;
108
+ /**
109
+ * Cube root of each element
110
+ * NumPy behavior: Promotes integer types to float64
111
+ *
112
+ * @param a - Input array storage
113
+ * @returns Result storage with cube root values
114
+ */
115
+ export declare function cbrt(a: ArrayStorage): ArrayStorage;
116
+ /**
117
+ * Absolute value of each element, returning float
118
+ * NumPy behavior: fabs always returns floating point
119
+ *
120
+ * @param a - Input array storage
121
+ * @returns Result storage with absolute values as float
122
+ */
123
+ export declare function fabs(a: ArrayStorage): ArrayStorage;
124
+ /**
125
+ * Returns both quotient and remainder (floor divide and modulo)
126
+ * NumPy behavior: divmod(a, b) = (floor_divide(a, b), mod(a, b))
127
+ *
128
+ * @param a - Dividend array storage
129
+ * @param b - Divisor (array storage or scalar)
130
+ * @returns Tuple of [quotient, remainder] storages
131
+ */
132
+ export declare function divmod(a: ArrayStorage, b: ArrayStorage | number): [ArrayStorage, ArrayStorage];
133
+ /**
134
+ * Element-wise square of each element
135
+ * NumPy behavior: x**2
136
+ *
137
+ * @param a - Input array storage
138
+ * @returns Result storage with squared values
139
+ */
140
+ export declare function square(a: ArrayStorage): ArrayStorage;
141
+ /**
142
+ * Remainder of division (same as mod)
143
+ * NumPy behavior: Same as mod, alias for compatibility
144
+ *
145
+ * @param a - Dividend array storage
146
+ * @param b - Divisor (array storage or scalar)
147
+ * @returns Result storage with remainder values
148
+ */
149
+ export declare function remainder(a: ArrayStorage, b: ArrayStorage | number): ArrayStorage;
150
+ /**
151
+ * Heaviside step function
152
+ * NumPy behavior:
153
+ * heaviside(x1, x2) = 0 if x1 < 0
154
+ * = x2 if x1 == 0
155
+ * = 1 if x1 > 0
156
+ *
157
+ * @param x1 - Input array storage
158
+ * @param x2 - Value to use when x1 == 0 (array storage or scalar)
159
+ * @returns Result storage with heaviside values
160
+ */
161
+ export declare function heaviside(x1: ArrayStorage, x2: ArrayStorage | number): ArrayStorage;
108
162
  //# sourceMappingURL=arithmetic.d.ts.map
@@ -40,4 +40,16 @@ export declare function isclose(a: ArrayStorage, b: ArrayStorage | number, rtol?
40
40
  * Returns true if all elements satisfy isclose condition
41
41
  */
42
42
  export declare function allclose(a: ArrayStorage, b: ArrayStorage | number, rtol?: number, atol?: number): boolean;
43
+ /**
44
+ * Returns True if two arrays are element-wise equal within a tolerance.
45
+ * Unlike array_equal, this function broadcasts the arrays before comparison.
46
+ *
47
+ * NumPy behavior: Broadcasts arrays before comparing, returns True if shapes
48
+ * are broadcast-compatible and all elements are equal.
49
+ *
50
+ * @param a1 - First input array
51
+ * @param a2 - Second input array
52
+ * @returns True if arrays are equivalent (after broadcasting), False otherwise
53
+ */
54
+ export declare function arrayEquiv(a1: ArrayStorage, a2: ArrayStorage): boolean;
43
55
  //# sourceMappingURL=comparison.d.ts.map
@@ -92,4 +92,55 @@ export declare function outer(a: ArrayStorage, b: ArrayStorage): ArrayStorage;
92
92
  * @returns Tensor dot product
93
93
  */
94
94
  export declare function tensordot(a: ArrayStorage, b: ArrayStorage, axes: number | [number[], number[]]): ArrayStorage | number | bigint;
95
+ /**
96
+ * Extract a diagonal or construct a diagonal array.
97
+ *
98
+ * NumPy behavior:
99
+ * - For 2D arrays: extract the k-th diagonal
100
+ * - For ND arrays (N >= 2): extract diagonal from the axes specified
101
+ * - Returns a view when possible, copy otherwise
102
+ *
103
+ * @param a - Input array (must be at least 2D)
104
+ * @param offset - Offset of the diagonal from the main diagonal (default: 0)
105
+ * - offset > 0: diagonal above main diagonal
106
+ * - offset < 0: diagonal below main diagonal
107
+ * @param axis1 - First axis for ND arrays (default: 0)
108
+ * @param axis2 - Second axis for ND arrays (default: 1)
109
+ * @returns Array containing the diagonal elements
110
+ */
111
+ export declare function diagonal(a: ArrayStorage, offset?: number, axis1?: number, axis2?: number): ArrayStorage;
112
+ /**
113
+ * Einstein summation convention
114
+ *
115
+ * Performs tensor contractions and reductions using Einstein summation notation.
116
+ *
117
+ * Examples:
118
+ * - 'ij,jk->ik': matrix multiplication
119
+ * - 'i,i->': dot product (inner product)
120
+ * - 'ij->ji': transpose
121
+ * - 'ii->': trace
122
+ * - 'ij->j': sum over first axis
123
+ * - 'ijk,ikl->ijl': batched matrix multiplication
124
+ *
125
+ * @param subscripts - Einstein summation subscripts (e.g., 'ij,jk->ik')
126
+ * @param operands - Input arrays
127
+ * @returns Result of the Einstein summation
128
+ */
129
+ export declare function einsum(subscripts: string, ...operands: ArrayStorage[]): ArrayStorage | number | bigint;
130
+ /**
131
+ * Kronecker product of two arrays.
132
+ *
133
+ * Computes the Kronecker product, a composite array made of blocks of the
134
+ * second array scaled by the elements of the first.
135
+ *
136
+ * NumPy behavior:
137
+ * - If both inputs are vectors (1D), output is also a vector
138
+ * - If both inputs are 2D matrices, output shape is (m1*m2, n1*n2)
139
+ * - General case: broadcasts shapes then computes block product
140
+ *
141
+ * @param a - First input array
142
+ * @param b - Second input array
143
+ * @returns Kronecker product of a and b
144
+ */
145
+ export declare function kron(a: ArrayStorage, b: ArrayStorage): ArrayStorage;
95
146
  //# sourceMappingURL=linalg.d.ts.map
@@ -58,4 +58,80 @@ export declare function all(storage: ArrayStorage, axis?: number, keepdims?: boo
58
58
  * Test whether any array elements along a given axis evaluate to True
59
59
  */
60
60
  export declare function any(storage: ArrayStorage, axis?: number, keepdims?: boolean): ArrayStorage | boolean;
61
+ /**
62
+ * Return cumulative sum of elements along a given axis
63
+ */
64
+ export declare function cumsum(storage: ArrayStorage, axis?: number): ArrayStorage;
65
+ /**
66
+ * Return cumulative product of elements along a given axis
67
+ */
68
+ export declare function cumprod(storage: ArrayStorage, axis?: number): ArrayStorage;
69
+ /**
70
+ * Peak to peak (maximum - minimum) value along a given axis
71
+ */
72
+ export declare function ptp(storage: ArrayStorage, axis?: number, keepdims?: boolean): ArrayStorage | number;
73
+ /**
74
+ * Compute the median along the specified axis
75
+ */
76
+ export declare function median(storage: ArrayStorage, axis?: number, keepdims?: boolean): ArrayStorage | number;
77
+ /**
78
+ * Compute the q-th percentile of data along specified axis
79
+ */
80
+ export declare function percentile(storage: ArrayStorage, q: number, axis?: number, keepdims?: boolean): ArrayStorage | number;
81
+ /**
82
+ * Compute the q-th quantile of data along specified axis
83
+ */
84
+ export declare function quantile(storage: ArrayStorage, q: number, axis?: number, keepdims?: boolean): ArrayStorage | number;
85
+ /**
86
+ * Compute the weighted average along the specified axis
87
+ */
88
+ export declare function average(storage: ArrayStorage, axis?: number, weights?: ArrayStorage, keepdims?: boolean): ArrayStorage | number;
89
+ /**
90
+ * Return sum of elements, treating NaNs as zero
91
+ */
92
+ export declare function nansum(storage: ArrayStorage, axis?: number, keepdims?: boolean): ArrayStorage | number;
93
+ /**
94
+ * Return product of elements, treating NaNs as one
95
+ */
96
+ export declare function nanprod(storage: ArrayStorage, axis?: number, keepdims?: boolean): ArrayStorage | number;
97
+ /**
98
+ * Compute mean ignoring NaN values
99
+ */
100
+ export declare function nanmean(storage: ArrayStorage, axis?: number, keepdims?: boolean): ArrayStorage | number;
101
+ /**
102
+ * Compute variance ignoring NaN values
103
+ */
104
+ export declare function nanvar(storage: ArrayStorage, axis?: number, ddof?: number, keepdims?: boolean): ArrayStorage | number;
105
+ /**
106
+ * Compute standard deviation ignoring NaN values
107
+ */
108
+ export declare function nanstd(storage: ArrayStorage, axis?: number, ddof?: number, keepdims?: boolean): ArrayStorage | number;
109
+ /**
110
+ * Return minimum ignoring NaN values
111
+ */
112
+ export declare function nanmin(storage: ArrayStorage, axis?: number, keepdims?: boolean): ArrayStorage | number;
113
+ /**
114
+ * Return maximum ignoring NaN values
115
+ */
116
+ export declare function nanmax(storage: ArrayStorage, axis?: number, keepdims?: boolean): ArrayStorage | number;
117
+ /**
118
+ * Return indices of minimum value, ignoring NaNs
119
+ */
120
+ export declare function nanargmin(storage: ArrayStorage, axis?: number): ArrayStorage | number;
121
+ /**
122
+ * Return indices of maximum value, ignoring NaNs
123
+ */
124
+ export declare function nanargmax(storage: ArrayStorage, axis?: number): ArrayStorage | number;
125
+ /**
126
+ * Return cumulative sum, treating NaNs as zero
127
+ */
128
+ export declare function nancumsum(storage: ArrayStorage, axis?: number): ArrayStorage;
129
+ /**
130
+ * Return cumulative product, treating NaNs as one
131
+ */
132
+ export declare function nancumprod(storage: ArrayStorage, axis?: number): ArrayStorage;
133
+ /**
134
+ * Compute median ignoring NaN values
135
+ */
136
+ export declare function nanmedian(storage: ArrayStorage, axis?: number, keepdims?: boolean): ArrayStorage | number;
61
137
  //# sourceMappingURL=reduction.d.ts.map
@@ -97,4 +97,48 @@ export declare function tile(storage: ArrayStorage, reps: number | number[]): Ar
97
97
  * Repeat elements of an array
98
98
  */
99
99
  export declare function repeat(storage: ArrayStorage, repeats: number | number[], axis?: number): ArrayStorage;
100
+ /**
101
+ * Reverse the order of elements in an array along given axis
102
+ */
103
+ export declare function flip(storage: ArrayStorage, axis?: number | number[]): ArrayStorage;
104
+ /**
105
+ * Rotate array by 90 degrees in the plane specified by axes
106
+ */
107
+ export declare function rot90(storage: ArrayStorage, k?: number, axes?: [number, number]): ArrayStorage;
108
+ /**
109
+ * Roll array elements along a given axis
110
+ */
111
+ export declare function roll(storage: ArrayStorage, shift: number | number[], axis?: number | number[]): ArrayStorage;
112
+ /**
113
+ * Roll the specified axis backwards until it lies in a given position
114
+ */
115
+ export declare function rollaxis(storage: ArrayStorage, axis: number, start?: number): ArrayStorage;
116
+ /**
117
+ * Split array along third axis (depth)
118
+ */
119
+ export declare function dsplit(storage: ArrayStorage, indicesOrSections: number | number[]): ArrayStorage[];
120
+ /**
121
+ * Stack 1-D arrays as columns into a 2-D array
122
+ */
123
+ export declare function columnStack(storages: ArrayStorage[]): ArrayStorage;
124
+ /**
125
+ * Stack arrays in sequence vertically (row_stack is an alias for vstack)
126
+ */
127
+ export declare const rowStack: typeof vstack;
128
+ /**
129
+ * Resize array to new shape (returns new array, may repeat or truncate)
130
+ */
131
+ export declare function resize(storage: ArrayStorage, newShape: number[]): ArrayStorage;
132
+ /**
133
+ * Convert arrays to at least 1D
134
+ */
135
+ export declare function atleast1d(storages: ArrayStorage[]): ArrayStorage[];
136
+ /**
137
+ * Convert arrays to at least 2D
138
+ */
139
+ export declare function atleast2d(storages: ArrayStorage[]): ArrayStorage[];
140
+ /**
141
+ * Convert arrays to at least 3D
142
+ */
143
+ export declare function atleast3d(storages: ArrayStorage[]): ArrayStorage[];
100
144
  //# sourceMappingURL=shape.d.ts.map
@@ -91,4 +91,20 @@ export declare function degrees(a: ArrayStorage): ArrayStorage;
91
91
  * @returns Angles in radians
92
92
  */
93
93
  export declare function radians(a: ArrayStorage): ArrayStorage;
94
+ /**
95
+ * Convert angles from degrees to radians (alias for radians).
96
+ * NumPy behavior: Always promotes to float64 for integer types
97
+ *
98
+ * @param a - Input array storage (angles in degrees)
99
+ * @returns Angles in radians
100
+ */
101
+ export declare function deg2rad(a: ArrayStorage): ArrayStorage;
102
+ /**
103
+ * Convert angles from radians to degrees (alias for degrees).
104
+ * NumPy behavior: Always promotes to float64 for integer types
105
+ *
106
+ * @param a - Input array storage (angles in radians)
107
+ * @returns Angles in degrees
108
+ */
109
+ export declare function rad2deg(a: ArrayStorage): ArrayStorage;
94
110
  //# sourceMappingURL=trig.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "numpy-ts",
3
- "version": "0.5.0",
3
+ "version": "0.6.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",
@@ -54,8 +54,10 @@
54
54
  "test:ci": "npm run lint && npm run typecheck && npm test && npm run test:bundles",
55
55
  "test:summary": "vitest run --reporter=tap | grep -E 'not ok|# tests'",
56
56
  "test:watch": "vitest watch",
57
- "test:coverage": "vitest run tests/unit --coverage",
58
- "test:coverage:view": "vitest run tests/unit --coverage; open coverage/index.html",
57
+ "test:coverage": "vitest run --project=unit --coverage",
58
+ "test:coverage:view": "vitest run --project=unit --coverage && open coverage/index.html",
59
+ "test:coverage:validation": "vitest run --project=validation-quick --coverage",
60
+ "test:coverage:validation:view": "vitest run --project=validation-quick --coverage && open coverage/index.html",
59
61
  "test:coverage:all": "vitest run --coverage",
60
62
  "lint": "eslint src tests --ext .ts",
61
63
  "lint:fix": "eslint src tests --ext .ts --fix",
@@ -111,7 +113,6 @@
111
113
  "lint-staged": "^16.2.6",
112
114
  "playwright": "^1.56.1",
113
115
  "prettier": "^3.1.1",
114
- "ts-node": "^10.9.2",
115
116
  "tsx": "^4.20.6",
116
117
  "typescript": "^5.3.3",
117
118
  "vitest": "^4.0.3"