numpy-ts 0.2.0 → 0.4.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 +50 -126
- package/dist/numpy-ts.browser.js +1 -1364
- package/dist/numpy-ts.esm.js +1 -1364
- package/dist/numpy-ts.node.cjs +1 -1365
- package/dist/types/core/broadcasting.d.ts +16 -13
- package/dist/types/core/ndarray.d.ts +270 -52
- package/dist/types/core/storage.d.ts +25 -18
- package/dist/types/index.d.ts +1 -1
- package/dist/types/internal/compute.d.ts +9 -0
- package/dist/types/ops/linalg.d.ts +79 -0
- package/package.json +7 -7
|
@@ -5,12 +5,91 @@
|
|
|
5
5
|
* @module ops/linalg
|
|
6
6
|
*/
|
|
7
7
|
import { ArrayStorage } from '../core/storage';
|
|
8
|
+
/**
|
|
9
|
+
* Dot product of two arrays (fully NumPy-compatible)
|
|
10
|
+
*
|
|
11
|
+
* Behavior depends on input dimensions:
|
|
12
|
+
* - 0D · 0D: Multiply scalars → scalar
|
|
13
|
+
* - 0D · ND or ND · 0D: Element-wise multiply → ND
|
|
14
|
+
* - 1D · 1D: Inner product → scalar
|
|
15
|
+
* - 2D · 2D: Matrix multiplication → 2D
|
|
16
|
+
* - 2D · 1D: Matrix-vector product → 1D
|
|
17
|
+
* - 1D · 2D: Vector-matrix product → 1D
|
|
18
|
+
* - ND · 1D (N≥2): Sum product over last axis of a → (N-1)D
|
|
19
|
+
* - 1D · ND (N≥2): Sum product over first axis of b → (N-1)D
|
|
20
|
+
* - ND · MD (N,M≥2): Sum product over last axis of a and second-to-last of b → (N+M-2)D
|
|
21
|
+
*
|
|
22
|
+
* For 2D·2D, prefer using matmul() instead.
|
|
23
|
+
*/
|
|
24
|
+
export declare function dot(a: ArrayStorage, b: ArrayStorage): ArrayStorage | number | bigint;
|
|
8
25
|
/**
|
|
9
26
|
* Matrix multiplication
|
|
10
27
|
* Requires 2D arrays with compatible shapes
|
|
11
28
|
*
|
|
29
|
+
* Automatically detects transposed/non-contiguous arrays via strides
|
|
30
|
+
* and uses appropriate DGEMM transpose parameters.
|
|
31
|
+
*
|
|
12
32
|
* Note: Currently uses float64 precision for all operations.
|
|
13
33
|
* Integer inputs are promoted to float64 (matching NumPy behavior).
|
|
14
34
|
*/
|
|
15
35
|
export declare function matmul(a: ArrayStorage, b: ArrayStorage): ArrayStorage;
|
|
36
|
+
/**
|
|
37
|
+
* Sum along the diagonal of a 2D array
|
|
38
|
+
*
|
|
39
|
+
* Computes the trace (sum of diagonal elements) of a matrix.
|
|
40
|
+
* For non-square matrices, sums along the diagonal up to min(rows, cols).
|
|
41
|
+
*
|
|
42
|
+
* @param a - Input 2D array
|
|
43
|
+
* @returns Sum of diagonal elements
|
|
44
|
+
*/
|
|
45
|
+
export declare function trace(a: ArrayStorage): number | bigint;
|
|
46
|
+
/**
|
|
47
|
+
* Permute the dimensions of an array
|
|
48
|
+
*
|
|
49
|
+
* Standalone version of NDArray.transpose() method.
|
|
50
|
+
* Returns a view with axes permuted.
|
|
51
|
+
*
|
|
52
|
+
* @param a - Input array
|
|
53
|
+
* @param axes - Optional permutation of axes (defaults to reverse order)
|
|
54
|
+
* @returns Transposed view
|
|
55
|
+
*/
|
|
56
|
+
export declare function transpose(a: ArrayStorage, axes?: number[]): ArrayStorage;
|
|
57
|
+
/**
|
|
58
|
+
* Inner product of two arrays
|
|
59
|
+
*
|
|
60
|
+
* Computes sum product over the LAST axes of both a and b.
|
|
61
|
+
* - 1D · 1D: Same as dot (ordinary inner product) → scalar
|
|
62
|
+
* - ND · MD: Contracts last dimension of each → (*a.shape[:-1], *b.shape[:-1])
|
|
63
|
+
*
|
|
64
|
+
* Different from dot: always uses last axis of BOTH arrays.
|
|
65
|
+
*
|
|
66
|
+
* @param a - First array
|
|
67
|
+
* @param b - Second array
|
|
68
|
+
* @returns Inner product result
|
|
69
|
+
*/
|
|
70
|
+
export declare function inner(a: ArrayStorage, b: ArrayStorage): ArrayStorage | number | bigint;
|
|
71
|
+
/**
|
|
72
|
+
* Outer product of two vectors
|
|
73
|
+
*
|
|
74
|
+
* Computes out[i, j] = a[i] * b[j]
|
|
75
|
+
* Input arrays are flattened if not 1D.
|
|
76
|
+
*
|
|
77
|
+
* @param a - First input (flattened to 1D)
|
|
78
|
+
* @param b - Second input (flattened to 1D)
|
|
79
|
+
* @returns 2D array of shape (a.size, b.size)
|
|
80
|
+
*/
|
|
81
|
+
export declare function outer(a: ArrayStorage, b: ArrayStorage): ArrayStorage;
|
|
82
|
+
/**
|
|
83
|
+
* Tensor dot product along specified axes
|
|
84
|
+
*
|
|
85
|
+
* Computes sum product over specified axes.
|
|
86
|
+
*
|
|
87
|
+
* @param a - First array
|
|
88
|
+
* @param b - Second array
|
|
89
|
+
* @param axes - Axes to contract:
|
|
90
|
+
* - Integer N: Contract last N axes of a with first N of b
|
|
91
|
+
* - [a_axes, b_axes]: Contract specified axes
|
|
92
|
+
* @returns Tensor dot product
|
|
93
|
+
*/
|
|
94
|
+
export declare function tensordot(a: ArrayStorage, b: ArrayStorage, axes: number | [number[], number[]]): ArrayStorage | number | bigint;
|
|
16
95
|
//# sourceMappingURL=linalg.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "numpy-ts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.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
|
"bench:build": "esbuild benchmarks/src/index.ts --bundle --platform=node --format=cjs --outfile=benchmarks/dist/bench.cjs",
|
|
55
55
|
"bench": "npm run bench:build && node benchmarks/dist/bench.cjs",
|
|
56
56
|
"bench:quick": "npm run bench:build && node benchmarks/dist/bench.cjs --quick",
|
|
57
|
+
"bench:large": "npm run bench:build && node benchmarks/dist/bench.cjs --large",
|
|
57
58
|
"bench:category": "npm run bench:build && node benchmarks/dist/bench.cjs --category",
|
|
58
|
-
"bench:view": "open benchmarks/results/plots/latest.html || xdg-open benchmarks/results/plots/latest.html"
|
|
59
|
+
"bench:view": "open benchmarks/results/plots/latest.html || xdg-open benchmarks/results/plots/latest.html",
|
|
60
|
+
"bench:large:view": "open benchmarks/results/plots/latest-large.html || xdg-open benchmarks/results/plots/latest-large.html"
|
|
59
61
|
},
|
|
60
62
|
"keywords": [
|
|
61
63
|
"numpy",
|
|
@@ -81,7 +83,6 @@
|
|
|
81
83
|
},
|
|
82
84
|
"homepage": "https://github.com/dupontcyborg/numpy-ts#readme",
|
|
83
85
|
"devDependencies": {
|
|
84
|
-
"@stdlib/types": "^0.4.3",
|
|
85
86
|
"@types/node": "^24.9.1",
|
|
86
87
|
"@typescript-eslint/eslint-plugin": "^8.46.2",
|
|
87
88
|
"@typescript-eslint/parser": "^8.46.2",
|
|
@@ -103,13 +104,12 @@
|
|
|
103
104
|
"typescript": "^5.3.3",
|
|
104
105
|
"vitest": "^4.0.3"
|
|
105
106
|
},
|
|
106
|
-
"dependencies": {
|
|
107
|
-
"@stdlib/blas": "^0.3.3",
|
|
108
|
-
"@stdlib/ndarray": "^0.3.3"
|
|
109
|
-
},
|
|
110
107
|
"engines": {
|
|
111
108
|
"node": ">=18.0.0"
|
|
112
109
|
},
|
|
110
|
+
"overrides": {
|
|
111
|
+
"js-yaml": ">=4.1.1"
|
|
112
|
+
},
|
|
113
113
|
"lint-staged": {
|
|
114
114
|
"*.ts": [
|
|
115
115
|
"eslint --fix",
|