numpy-ts 0.3.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 +0 -4
- package/dist/numpy-ts.browser.js +1 -396
- package/dist/numpy-ts.esm.js +1 -396
- package/dist/numpy-ts.node.cjs +1 -412
- package/dist/types/core/ndarray.d.ts +94 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/ops/linalg.d.ts +79 -0
- package/package.json +1 -5
|
@@ -309,6 +309,36 @@ export declare class NDArray {
|
|
|
309
309
|
* @returns Result of matrix multiplication
|
|
310
310
|
*/
|
|
311
311
|
matmul(other: NDArray): NDArray;
|
|
312
|
+
/**
|
|
313
|
+
* Dot product (matching NumPy behavior)
|
|
314
|
+
* @param other - Array to dot with
|
|
315
|
+
* @returns Result of dot product (scalar or array depending on dimensions)
|
|
316
|
+
*/
|
|
317
|
+
dot(other: NDArray): NDArray | number | bigint;
|
|
318
|
+
/**
|
|
319
|
+
* Sum of diagonal elements (trace)
|
|
320
|
+
* @returns Sum of diagonal elements
|
|
321
|
+
*/
|
|
322
|
+
trace(): number | bigint;
|
|
323
|
+
/**
|
|
324
|
+
* Inner product (contracts over last axes of both arrays)
|
|
325
|
+
* @param other - Array to compute inner product with
|
|
326
|
+
* @returns Inner product result
|
|
327
|
+
*/
|
|
328
|
+
inner(other: NDArray): NDArray | number | bigint;
|
|
329
|
+
/**
|
|
330
|
+
* Outer product (flattens inputs then computes a[i]*b[j])
|
|
331
|
+
* @param other - Array to compute outer product with
|
|
332
|
+
* @returns 2D outer product matrix
|
|
333
|
+
*/
|
|
334
|
+
outer(other: NDArray): NDArray;
|
|
335
|
+
/**
|
|
336
|
+
* Tensor dot product along specified axes
|
|
337
|
+
* @param other - Array to contract with
|
|
338
|
+
* @param axes - Axes to contract (integer or [a_axes, b_axes])
|
|
339
|
+
* @returns Tensor dot product result
|
|
340
|
+
*/
|
|
341
|
+
tensordot(other: NDArray, axes?: number | [number[], number[]]): NDArray | number | bigint;
|
|
312
342
|
/**
|
|
313
343
|
* Slice the array using NumPy-style string syntax
|
|
314
344
|
*
|
|
@@ -545,4 +575,68 @@ export declare function positive(x: NDArray): NDArray;
|
|
|
545
575
|
* @returns Array of reciprocals
|
|
546
576
|
*/
|
|
547
577
|
export declare function reciprocal(x: NDArray): NDArray;
|
|
578
|
+
/**
|
|
579
|
+
* Dot product of two arrays
|
|
580
|
+
*
|
|
581
|
+
* Fully NumPy-compatible. Behavior depends on input dimensions:
|
|
582
|
+
* - 0D · 0D: Multiply scalars → scalar
|
|
583
|
+
* - 0D · ND or ND · 0D: Element-wise multiply → ND
|
|
584
|
+
* - 1D · 1D: Inner product → scalar
|
|
585
|
+
* - 2D · 2D: Matrix multiplication → 2D
|
|
586
|
+
* - 2D · 1D: Matrix-vector product → 1D
|
|
587
|
+
* - 1D · 2D: Vector-matrix product → 1D
|
|
588
|
+
* - ND · 1D (N>2): Sum over last axis → (N-1)D
|
|
589
|
+
* - 1D · ND (N>2): Sum over first axis → (N-1)D
|
|
590
|
+
* - ND · MD (N,M≥2): Tensor contraction → (N+M-2)D
|
|
591
|
+
*
|
|
592
|
+
* @param a - First array
|
|
593
|
+
* @param b - Second array
|
|
594
|
+
* @returns Result of dot product
|
|
595
|
+
*/
|
|
596
|
+
export declare function dot(a: NDArray, b: NDArray): NDArray | number | bigint;
|
|
597
|
+
/**
|
|
598
|
+
* Sum of diagonal elements
|
|
599
|
+
*
|
|
600
|
+
* @param a - Input 2D array
|
|
601
|
+
* @returns Sum of diagonal elements
|
|
602
|
+
*/
|
|
603
|
+
export declare function trace(a: NDArray): number | bigint;
|
|
604
|
+
/**
|
|
605
|
+
* Permute array dimensions
|
|
606
|
+
*
|
|
607
|
+
* @param a - Input array
|
|
608
|
+
* @param axes - Optional permutation of axes (defaults to reverse order)
|
|
609
|
+
* @returns Transposed view
|
|
610
|
+
*/
|
|
611
|
+
export declare function transpose(a: NDArray, axes?: number[]): NDArray;
|
|
612
|
+
/**
|
|
613
|
+
* Inner product of two arrays
|
|
614
|
+
*
|
|
615
|
+
* Contracts over last axes of both arrays.
|
|
616
|
+
* Result shape: (*a.shape[:-1], *b.shape[:-1])
|
|
617
|
+
*
|
|
618
|
+
* @param a - First array
|
|
619
|
+
* @param b - Second array
|
|
620
|
+
* @returns Inner product result
|
|
621
|
+
*/
|
|
622
|
+
export declare function inner(a: NDArray, b: NDArray): NDArray | number | bigint;
|
|
623
|
+
/**
|
|
624
|
+
* Outer product of two arrays
|
|
625
|
+
*
|
|
626
|
+
* Flattens inputs then computes result[i,j] = a[i] * b[j]
|
|
627
|
+
*
|
|
628
|
+
* @param a - First array
|
|
629
|
+
* @param b - Second array
|
|
630
|
+
* @returns 2D outer product matrix
|
|
631
|
+
*/
|
|
632
|
+
export declare function outer(a: NDArray, b: NDArray): NDArray;
|
|
633
|
+
/**
|
|
634
|
+
* Tensor dot product along specified axes
|
|
635
|
+
*
|
|
636
|
+
* @param a - First array
|
|
637
|
+
* @param b - Second array
|
|
638
|
+
* @param axes - Axes to contract (integer or [a_axes, b_axes])
|
|
639
|
+
* @returns Tensor dot product
|
|
640
|
+
*/
|
|
641
|
+
export declare function tensordot(a: NDArray, b: NDArray, axes?: number | [number[], number[]]): NDArray | number | bigint;
|
|
548
642
|
//# sourceMappingURL=ndarray.d.ts.map
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
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, } 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, sqrt, power, absolute, negative, sign, mod, floor_divide, positive, reciprocal, dot, trace, transpose, inner, outer, tensordot, } from './core/ndarray';
|
|
7
7
|
export declare const __version__: string;
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -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",
|
|
@@ -83,7 +83,6 @@
|
|
|
83
83
|
},
|
|
84
84
|
"homepage": "https://github.com/dupontcyborg/numpy-ts#readme",
|
|
85
85
|
"devDependencies": {
|
|
86
|
-
"@stdlib/types": "^0.4.3",
|
|
87
86
|
"@types/node": "^24.9.1",
|
|
88
87
|
"@typescript-eslint/eslint-plugin": "^8.46.2",
|
|
89
88
|
"@typescript-eslint/parser": "^8.46.2",
|
|
@@ -105,9 +104,6 @@
|
|
|
105
104
|
"typescript": "^5.3.3",
|
|
106
105
|
"vitest": "^4.0.3"
|
|
107
106
|
},
|
|
108
|
-
"dependencies": {
|
|
109
|
-
"@stdlib/blas": "^0.3.3"
|
|
110
|
-
},
|
|
111
107
|
"engines": {
|
|
112
108
|
"node": ">=18.0.0"
|
|
113
109
|
},
|