@thi.ng/tensors 0.1.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/CHANGELOG.md +46 -0
- package/LICENSE +201 -0
- package/README.md +307 -0
- package/abs.d.ts +37 -0
- package/abs.js +14 -0
- package/add.d.ts +42 -0
- package/add.js +15 -0
- package/addn.d.ts +42 -0
- package/addn.js +15 -0
- package/api.d.ts +137 -0
- package/api.js +0 -0
- package/clamp.d.ts +47 -0
- package/clamp.js +15 -0
- package/clampn.d.ts +47 -0
- package/clampn.js +15 -0
- package/cos.d.ts +37 -0
- package/cos.js +14 -0
- package/defopn.d.ts +13 -0
- package/defopn.js +65 -0
- package/defoprt.d.ts +14 -0
- package/defoprt.js +77 -0
- package/defoprtt.d.ts +14 -0
- package/defoprtt.js +113 -0
- package/defopt.d.ts +13 -0
- package/defopt.js +109 -0
- package/defoptn.d.ts +13 -0
- package/defoptn.js +109 -0
- package/defoptnn.d.ts +13 -0
- package/defoptnn.js +109 -0
- package/defoptt.d.ts +13 -0
- package/defoptt.js +144 -0
- package/defopttt.d.ts +13 -0
- package/defopttt.js +177 -0
- package/div.d.ts +42 -0
- package/div.js +15 -0
- package/divn.d.ts +42 -0
- package/divn.js +15 -0
- package/dot.d.ts +31 -0
- package/dot.js +17 -0
- package/errors.d.ts +15 -0
- package/errors.js +9 -0
- package/exp.d.ts +37 -0
- package/exp.js +14 -0
- package/exp2.d.ts +37 -0
- package/exp2.js +14 -0
- package/format.d.ts +14 -0
- package/format.js +37 -0
- package/identity.d.ts +4 -0
- package/identity.js +11 -0
- package/index.d.ts +60 -0
- package/index.js +59 -0
- package/log.d.ts +37 -0
- package/log.js +14 -0
- package/log2.d.ts +37 -0
- package/log2.js +14 -0
- package/mag.d.ts +3 -0
- package/mag.js +5 -0
- package/magsq.d.ts +31 -0
- package/magsq.js +17 -0
- package/max.d.ts +37 -0
- package/max.js +14 -0
- package/maxn.d.ts +42 -0
- package/maxn.js +14 -0
- package/min.d.ts +37 -0
- package/min.js +14 -0
- package/minn.d.ts +42 -0
- package/minn.js +14 -0
- package/mul.d.ts +42 -0
- package/mul.js +15 -0
- package/mulm.d.ts +12 -0
- package/mulm.js +49 -0
- package/muln.d.ts +42 -0
- package/muln.js +15 -0
- package/mulv.d.ts +11 -0
- package/mulv.js +39 -0
- package/normalize.d.ts +3 -0
- package/normalize.js +11 -0
- package/package.json +261 -0
- package/pow.d.ts +37 -0
- package/pow.js +14 -0
- package/pown.d.ts +42 -0
- package/pown.js +14 -0
- package/product.d.ts +31 -0
- package/product.js +15 -0
- package/rand-distrib.d.ts +49 -0
- package/rand-distrib.js +52 -0
- package/relu.d.ts +37 -0
- package/relu.js +14 -0
- package/relun.d.ts +43 -0
- package/relun.js +14 -0
- package/select.d.ts +91 -0
- package/select.js +111 -0
- package/set.d.ts +8 -0
- package/set.js +14 -0
- package/setn.d.ts +8 -0
- package/setn.js +14 -0
- package/sigmoid.d.ts +39 -0
- package/sigmoid.js +15 -0
- package/sin.d.ts +37 -0
- package/sin.js +14 -0
- package/softmax.d.ts +27 -0
- package/softmax.js +10 -0
- package/softplus.d.ts +48 -0
- package/softplus.js +15 -0
- package/sqrt.d.ts +37 -0
- package/sqrt.js +14 -0
- package/step.d.ts +48 -0
- package/step.js +14 -0
- package/storage.d.ts +3 -0
- package/storage.js +32 -0
- package/sub.d.ts +42 -0
- package/sub.js +15 -0
- package/subn.d.ts +42 -0
- package/subn.js +15 -0
- package/sum.d.ts +31 -0
- package/sum.js +15 -0
- package/tan.d.ts +37 -0
- package/tan.js +14 -0
- package/tanh.d.ts +37 -0
- package/tanh.js +14 -0
- package/tensor.d.ts +127 -0
- package/tensor.js +517 -0
- package/top.d.ts +16 -0
- package/top.js +15 -0
package/log.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Componentwise computes `Math.log` of given nD tensor and writes result to
|
|
3
|
+
* `out`. If `out` is null, mutates original. Multi-method.
|
|
4
|
+
*
|
|
5
|
+
* @param out - output tensor
|
|
6
|
+
* @param a - input tensor
|
|
7
|
+
*/
|
|
8
|
+
export declare const log: import("./api.js").MultiTensorOpT<number>;
|
|
9
|
+
/**
|
|
10
|
+
* Same as {@link log} for 1D tensors.
|
|
11
|
+
*
|
|
12
|
+
* @param out - output tensor
|
|
13
|
+
* @param a - input tensor
|
|
14
|
+
*/
|
|
15
|
+
export declare const log_1: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor1<number>, import("./tensor.js").Tensor1<number>>;
|
|
16
|
+
/**
|
|
17
|
+
* Same as {@link log} for 2D tensors.
|
|
18
|
+
*
|
|
19
|
+
* @param out - output tensor
|
|
20
|
+
* @param a - input tensor
|
|
21
|
+
*/
|
|
22
|
+
export declare const log_2: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor2<number>, import("./tensor.js").Tensor2<number>>;
|
|
23
|
+
/**
|
|
24
|
+
* Same as {@link log} for 3D tensors.
|
|
25
|
+
*
|
|
26
|
+
* @param out - output tensor
|
|
27
|
+
* @param a - input tensor
|
|
28
|
+
*/
|
|
29
|
+
export declare const log_3: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor3<number>, import("./tensor.js").Tensor3<number>>;
|
|
30
|
+
/**
|
|
31
|
+
* Same as {@link log} for 4D tensors.
|
|
32
|
+
*
|
|
33
|
+
* @param out - output tensor
|
|
34
|
+
* @param a - input tensor
|
|
35
|
+
*/
|
|
36
|
+
export declare const log_4: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor4<number>, import("./tensor.js").Tensor4<number>>;
|
|
37
|
+
//# sourceMappingURL=log.d.ts.map
|
package/log.js
ADDED
package/log2.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Componentwise computes `Math.log2` of given nD tensor and writes result to
|
|
3
|
+
* `out`. If `out` is null, mutates original. Multi-method.
|
|
4
|
+
*
|
|
5
|
+
* @param out - output tensor
|
|
6
|
+
* @param a - input tensor
|
|
7
|
+
*/
|
|
8
|
+
export declare const log2: import("./api.js").MultiTensorOpT<number>;
|
|
9
|
+
/**
|
|
10
|
+
* Same as {@link log2} for 1D tensors.
|
|
11
|
+
*
|
|
12
|
+
* @param out - output tensor
|
|
13
|
+
* @param a - input tensor
|
|
14
|
+
*/
|
|
15
|
+
export declare const log2_1: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor1<number>, import("./tensor.js").Tensor1<number>>;
|
|
16
|
+
/**
|
|
17
|
+
* Same as {@link log2} for 2D tensors.
|
|
18
|
+
*
|
|
19
|
+
* @param out - output tensor
|
|
20
|
+
* @param a - input tensor
|
|
21
|
+
*/
|
|
22
|
+
export declare const log2_2: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor2<number>, import("./tensor.js").Tensor2<number>>;
|
|
23
|
+
/**
|
|
24
|
+
* Same as {@link log2} for 3D tensors.
|
|
25
|
+
*
|
|
26
|
+
* @param out - output tensor
|
|
27
|
+
* @param a - input tensor
|
|
28
|
+
*/
|
|
29
|
+
export declare const log2_3: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor3<number>, import("./tensor.js").Tensor3<number>>;
|
|
30
|
+
/**
|
|
31
|
+
* Same as {@link log2} for 4D tensors.
|
|
32
|
+
*
|
|
33
|
+
* @param out - output tensor
|
|
34
|
+
* @param a - input tensor
|
|
35
|
+
*/
|
|
36
|
+
export declare const log2_4: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor4<number>, import("./tensor.js").Tensor4<number>>;
|
|
37
|
+
//# sourceMappingURL=log2.d.ts.map
|
package/log2.js
ADDED
package/mag.d.ts
ADDED
package/mag.js
ADDED
package/magsq.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Squared magnitude of given nD tensor. Multi-method.
|
|
3
|
+
*
|
|
4
|
+
* @param a - input tensor
|
|
5
|
+
*/
|
|
6
|
+
export declare const magSq: import("./api.js").MultiTensorOpRT<number, number>;
|
|
7
|
+
/**
|
|
8
|
+
* Squared magnitude of given 1D tensor.
|
|
9
|
+
*
|
|
10
|
+
* @param a - input tensor
|
|
11
|
+
*/
|
|
12
|
+
export declare const magSq1: import("./api.js").TensorOpRT<number, number, import("./tensor.js").Tensor1<number>>;
|
|
13
|
+
/**
|
|
14
|
+
* Squared magnitude of given 2D tensor.
|
|
15
|
+
*
|
|
16
|
+
* @param a - input tensor
|
|
17
|
+
*/
|
|
18
|
+
export declare const magSq2: import("./api.js").TensorOpRT<number, number, import("./tensor.js").Tensor2<number>>;
|
|
19
|
+
/**
|
|
20
|
+
* Squared magnitude of given 3D tensor.
|
|
21
|
+
*
|
|
22
|
+
* @param a - input tensor
|
|
23
|
+
*/
|
|
24
|
+
export declare const magSq3: import("./api.js").TensorOpRT<number, number, import("./tensor.js").Tensor3<number>>;
|
|
25
|
+
/**
|
|
26
|
+
* Squared magnitude of given 4D tensor.
|
|
27
|
+
*
|
|
28
|
+
* @param a - input tensor
|
|
29
|
+
*/
|
|
30
|
+
export declare const magSq4: import("./api.js").TensorOpRT<number, number, import("./tensor.js").Tensor4<number>>;
|
|
31
|
+
//# sourceMappingURL=magsq.d.ts.map
|
package/magsq.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defOpRT } from "./defoprt.js";
|
|
2
|
+
const [a, b, c, d, e] = defOpRT(
|
|
3
|
+
(acc, x) => acc + x * x,
|
|
4
|
+
() => 0
|
|
5
|
+
);
|
|
6
|
+
const magSq = a;
|
|
7
|
+
const magSq1 = b;
|
|
8
|
+
const magSq2 = c;
|
|
9
|
+
const magSq3 = d;
|
|
10
|
+
const magSq4 = e;
|
|
11
|
+
export {
|
|
12
|
+
magSq,
|
|
13
|
+
magSq1,
|
|
14
|
+
magSq2,
|
|
15
|
+
magSq3,
|
|
16
|
+
magSq4
|
|
17
|
+
};
|
package/max.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Componentwise computes `Math.max` of given nD tensors and writes result to
|
|
3
|
+
* `out`. If `out` is null, mutates original. Multi-method.
|
|
4
|
+
*
|
|
5
|
+
* @param out - output tensor
|
|
6
|
+
* @param a - input tensor
|
|
7
|
+
*/
|
|
8
|
+
export declare const max: import("./api.js").MultiTensorOpTT<number>;
|
|
9
|
+
/**
|
|
10
|
+
* Same as {@link max} for 1D tensors.
|
|
11
|
+
*
|
|
12
|
+
* @param out - output tensor
|
|
13
|
+
* @param a - input tensor
|
|
14
|
+
*/
|
|
15
|
+
export declare const max1: import("./api.js").TensorOpTT<number, number, import("./tensor.js").Tensor1<number>, import("./tensor.js").Tensor1<number>>;
|
|
16
|
+
/**
|
|
17
|
+
* Same as {@link max} for 2D tensors.
|
|
18
|
+
*
|
|
19
|
+
* @param out - output tensor
|
|
20
|
+
* @param a - input tensor
|
|
21
|
+
*/
|
|
22
|
+
export declare const max2: import("./api.js").TensorOpTT<number, number, import("./tensor.js").Tensor2<number>, import("./tensor.js").Tensor2<number>>;
|
|
23
|
+
/**
|
|
24
|
+
* Same as {@link max} for 3D tensors.
|
|
25
|
+
*
|
|
26
|
+
* @param out - output tensor
|
|
27
|
+
* @param a - input tensor
|
|
28
|
+
*/
|
|
29
|
+
export declare const max3: import("./api.js").TensorOpTT<number, number, import("./tensor.js").Tensor3<number>, import("./tensor.js").Tensor3<number>>;
|
|
30
|
+
/**
|
|
31
|
+
* Same as {@link max} for 4D tensors.
|
|
32
|
+
*
|
|
33
|
+
* @param out - output tensor
|
|
34
|
+
* @param a - input tensor
|
|
35
|
+
*/
|
|
36
|
+
export declare const max4: import("./api.js").TensorOpTT<number, number, import("./tensor.js").Tensor4<number>, import("./tensor.js").Tensor4<number>>;
|
|
37
|
+
//# sourceMappingURL=max.d.ts.map
|
package/max.js
ADDED
package/maxn.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Componentwise computes `Math.max` of given nD tensor and uniform scalar `n`.
|
|
3
|
+
* Writes result to `out`. If `out` is null, mutates original. Multi-method.
|
|
4
|
+
*
|
|
5
|
+
* @param out - output tensor
|
|
6
|
+
* @param a - input tensor
|
|
7
|
+
* @param n - scalar
|
|
8
|
+
*/
|
|
9
|
+
export declare const maxN: import("./api.js").MultiTensorOpTN<number>;
|
|
10
|
+
/**
|
|
11
|
+
* Same as {@link maxN} for 1D tensors.
|
|
12
|
+
*
|
|
13
|
+
* @param out - output tensor
|
|
14
|
+
* @param a - input tensor
|
|
15
|
+
* @param n - scalar
|
|
16
|
+
*/
|
|
17
|
+
export declare const maxN1: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor1<number>, import("./tensor.js").Tensor1<number>>;
|
|
18
|
+
/**
|
|
19
|
+
* Same as {@link maxN} for 2D tensors.
|
|
20
|
+
*
|
|
21
|
+
* @param out - output tensor
|
|
22
|
+
* @param a - input tensor
|
|
23
|
+
* @param n - scalar
|
|
24
|
+
*/
|
|
25
|
+
export declare const maxN2: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor2<number>, import("./tensor.js").Tensor2<number>>;
|
|
26
|
+
/**
|
|
27
|
+
* Same as {@link maxN} for 3D tensors.
|
|
28
|
+
*
|
|
29
|
+
* @param out - output tensor
|
|
30
|
+
* @param a - input tensor
|
|
31
|
+
* @param n - scalar
|
|
32
|
+
*/
|
|
33
|
+
export declare const maxN3: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor3<number>, import("./tensor.js").Tensor3<number>>;
|
|
34
|
+
/**
|
|
35
|
+
* Same as {@link maxN} for 4D tensors.
|
|
36
|
+
*
|
|
37
|
+
* @param out - output tensor
|
|
38
|
+
* @param a - input tensor
|
|
39
|
+
* @param n - scalar
|
|
40
|
+
*/
|
|
41
|
+
export declare const maxN4: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor4<number>, import("./tensor.js").Tensor4<number>>;
|
|
42
|
+
//# sourceMappingURL=maxn.d.ts.map
|
package/maxn.js
ADDED
package/min.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Componentwise computes `Math.min` of given nD tensors and writes result to
|
|
3
|
+
* `out`. If `out` is null, mutates original. Multi-method.
|
|
4
|
+
*
|
|
5
|
+
* @param out - output tensor
|
|
6
|
+
* @param a - input tensor
|
|
7
|
+
*/
|
|
8
|
+
export declare const min: import("./api.js").MultiTensorOpTT<number>;
|
|
9
|
+
/**
|
|
10
|
+
* Same as {@link min} for 1D tensors.
|
|
11
|
+
*
|
|
12
|
+
* @param out - output tensor
|
|
13
|
+
* @param a - input tensor
|
|
14
|
+
*/
|
|
15
|
+
export declare const min1: import("./api.js").TensorOpTT<number, number, import("./tensor.js").Tensor1<number>, import("./tensor.js").Tensor1<number>>;
|
|
16
|
+
/**
|
|
17
|
+
* Same as {@link min} for 2D tensors.
|
|
18
|
+
*
|
|
19
|
+
* @param out - output tensor
|
|
20
|
+
* @param a - input tensor
|
|
21
|
+
*/
|
|
22
|
+
export declare const min2: import("./api.js").TensorOpTT<number, number, import("./tensor.js").Tensor2<number>, import("./tensor.js").Tensor2<number>>;
|
|
23
|
+
/**
|
|
24
|
+
* Same as {@link min} for 3D tensors.
|
|
25
|
+
*
|
|
26
|
+
* @param out - output tensor
|
|
27
|
+
* @param a - input tensor
|
|
28
|
+
*/
|
|
29
|
+
export declare const min3: import("./api.js").TensorOpTT<number, number, import("./tensor.js").Tensor3<number>, import("./tensor.js").Tensor3<number>>;
|
|
30
|
+
/**
|
|
31
|
+
* Same as {@link min} for 4D tensors.
|
|
32
|
+
*
|
|
33
|
+
* @param out - output tensor
|
|
34
|
+
* @param a - input tensor
|
|
35
|
+
*/
|
|
36
|
+
export declare const min4: import("./api.js").TensorOpTT<number, number, import("./tensor.js").Tensor4<number>, import("./tensor.js").Tensor4<number>>;
|
|
37
|
+
//# sourceMappingURL=min.d.ts.map
|
package/min.js
ADDED
package/minn.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Componentwise computes `Math.min` of given nD tensor and uniform scalar `n`.
|
|
3
|
+
* Writes result to `out`. If `out` is null, mutates original. Multi-method.
|
|
4
|
+
*
|
|
5
|
+
* @param out - output tensor
|
|
6
|
+
* @param a - input tensor
|
|
7
|
+
* @param n - scalar
|
|
8
|
+
*/
|
|
9
|
+
export declare const minN: import("./api.js").MultiTensorOpTN<number>;
|
|
10
|
+
/**
|
|
11
|
+
* Same as {@link minN} for 1D tensors.
|
|
12
|
+
*
|
|
13
|
+
* @param out - output tensor
|
|
14
|
+
* @param a - input tensor
|
|
15
|
+
* @param n - scalar
|
|
16
|
+
*/
|
|
17
|
+
export declare const minN1: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor1<number>, import("./tensor.js").Tensor1<number>>;
|
|
18
|
+
/**
|
|
19
|
+
* Same as {@link minN} for 2D tensors.
|
|
20
|
+
*
|
|
21
|
+
* @param out - output tensor
|
|
22
|
+
* @param a - input tensor
|
|
23
|
+
* @param n - scalar
|
|
24
|
+
*/
|
|
25
|
+
export declare const minN2: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor2<number>, import("./tensor.js").Tensor2<number>>;
|
|
26
|
+
/**
|
|
27
|
+
* Same as {@link minN} for 3D tensors.
|
|
28
|
+
*
|
|
29
|
+
* @param out - output tensor
|
|
30
|
+
* @param a - input tensor
|
|
31
|
+
* @param n - scalar
|
|
32
|
+
*/
|
|
33
|
+
export declare const minN3: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor3<number>, import("./tensor.js").Tensor3<number>>;
|
|
34
|
+
/**
|
|
35
|
+
* Same as {@link minN} for 4D tensors.
|
|
36
|
+
*
|
|
37
|
+
* @param out - output tensor
|
|
38
|
+
* @param a - input tensor
|
|
39
|
+
* @param n - scalar
|
|
40
|
+
*/
|
|
41
|
+
export declare const minN4: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor4<number>, import("./tensor.js").Tensor4<number>>;
|
|
42
|
+
//# sourceMappingURL=minn.d.ts.map
|
package/minn.js
ADDED
package/mul.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Componentwise nD tensor multiplication. Writes result to `out`. If `out` is
|
|
3
|
+
* null, mutates `a`. Multi-method.
|
|
4
|
+
*
|
|
5
|
+
* @param out - output tensor
|
|
6
|
+
* @param a - input tensor
|
|
7
|
+
* @param n - scalar
|
|
8
|
+
*/
|
|
9
|
+
export declare const mul: import("./api.js").MultiTensorOpTT<number>;
|
|
10
|
+
/**
|
|
11
|
+
* Same as {@link mul} for 1D tensors.
|
|
12
|
+
*
|
|
13
|
+
* @param out - output tensor
|
|
14
|
+
* @param a - input tensor
|
|
15
|
+
* @param n - scalar
|
|
16
|
+
*/
|
|
17
|
+
export declare const mul1: import("./api.js").TensorOpTT<number, number, import("./tensor.js").Tensor1<number>, import("./tensor.js").Tensor1<number>>;
|
|
18
|
+
/**
|
|
19
|
+
* Same as {@link mul} for 2D tensors.
|
|
20
|
+
*
|
|
21
|
+
* @param out - output tensor
|
|
22
|
+
* @param a - input tensor
|
|
23
|
+
* @param n - scalar
|
|
24
|
+
*/
|
|
25
|
+
export declare const mul2: import("./api.js").TensorOpTT<number, number, import("./tensor.js").Tensor2<number>, import("./tensor.js").Tensor2<number>>;
|
|
26
|
+
/**
|
|
27
|
+
* Same as {@link mul} for 3D tensors.
|
|
28
|
+
*
|
|
29
|
+
* @param out - output tensor
|
|
30
|
+
* @param a - input tensor
|
|
31
|
+
* @param n - scalar
|
|
32
|
+
*/
|
|
33
|
+
export declare const mul3: import("./api.js").TensorOpTT<number, number, import("./tensor.js").Tensor3<number>, import("./tensor.js").Tensor3<number>>;
|
|
34
|
+
/**
|
|
35
|
+
* Same as {@link mul} for 4D tensors.
|
|
36
|
+
*
|
|
37
|
+
* @param out - output tensor
|
|
38
|
+
* @param a - input tensor
|
|
39
|
+
* @param n - scalar
|
|
40
|
+
*/
|
|
41
|
+
export declare const mul4: import("./api.js").TensorOpTT<number, number, import("./tensor.js").Tensor4<number>, import("./tensor.js").Tensor4<number>>;
|
|
42
|
+
//# sourceMappingURL=mul.d.ts.map
|
package/mul.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { $mul } from "@thi.ng/vectors/ops";
|
|
2
|
+
import { defOpTT } from "./defoptt.js";
|
|
3
|
+
const [a, b, c, d, e] = defOpTT($mul);
|
|
4
|
+
const mul = a;
|
|
5
|
+
const mul1 = b;
|
|
6
|
+
const mul2 = c;
|
|
7
|
+
const mul3 = d;
|
|
8
|
+
const mul4 = e;
|
|
9
|
+
export {
|
|
10
|
+
mul,
|
|
11
|
+
mul1,
|
|
12
|
+
mul2,
|
|
13
|
+
mul3,
|
|
14
|
+
mul4
|
|
15
|
+
};
|
package/mulm.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Tensor2 } from "./tensor.js";
|
|
2
|
+
/**
|
|
3
|
+
* Matrix-matrix multiplication between matrix `a` (MxN) and matrix `b` (PxQ).
|
|
4
|
+
* If `out` is given, it MUST be a MxQ tensor. If null then a new will be
|
|
5
|
+
* created, using `a`'s storage impl.
|
|
6
|
+
*
|
|
7
|
+
* @param out
|
|
8
|
+
* @param a
|
|
9
|
+
* @param b
|
|
10
|
+
*/
|
|
11
|
+
export declare const mulM: (out: Tensor2 | null, a: Tensor2, b: Tensor2) => Tensor2<number>;
|
|
12
|
+
//# sourceMappingURL=mulm.d.ts.map
|
package/mulm.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { assert } from "@thi.ng/errors/assert";
|
|
2
|
+
import { tensor } from "./tensor.js";
|
|
3
|
+
const mulM = (out, a, b) => {
|
|
4
|
+
const {
|
|
5
|
+
data: adata,
|
|
6
|
+
offset: offa,
|
|
7
|
+
shape: [rowa, cola],
|
|
8
|
+
stride: [txa, tya]
|
|
9
|
+
} = a;
|
|
10
|
+
const {
|
|
11
|
+
data: bdata,
|
|
12
|
+
offset: offb,
|
|
13
|
+
shape: [rowb, colb],
|
|
14
|
+
stride: [txb, tyb]
|
|
15
|
+
} = b;
|
|
16
|
+
assert(
|
|
17
|
+
cola === rowb,
|
|
18
|
+
`incompatible matrix shapes, matrix b requires ${cola} rows`
|
|
19
|
+
);
|
|
20
|
+
if (out == null) {
|
|
21
|
+
out = tensor(a.type, [rowa, colb], { storage: a.storage });
|
|
22
|
+
}
|
|
23
|
+
const {
|
|
24
|
+
data: odata,
|
|
25
|
+
offset: offo,
|
|
26
|
+
shape: [rowo, colo],
|
|
27
|
+
stride: [txo, tyo]
|
|
28
|
+
} = out;
|
|
29
|
+
assert(
|
|
30
|
+
rowo === rowa && colo === colb,
|
|
31
|
+
`incompatible output matrix shape, expected: [${rowa},${colb}]`
|
|
32
|
+
);
|
|
33
|
+
for (let i = 0; i < rowa; i++) {
|
|
34
|
+
const io = offo + i * txo;
|
|
35
|
+
const ia = offa + i * txa;
|
|
36
|
+
for (let j = 0; j < colb; j++) {
|
|
37
|
+
const ib = offb + j * tyb;
|
|
38
|
+
let dot = 0;
|
|
39
|
+
for (let j2 = 0; j2 < cola; j2++) {
|
|
40
|
+
dot += adata[ia + j2 * tya] * bdata[ib + j2 * txb];
|
|
41
|
+
}
|
|
42
|
+
odata[io + j * tyo] = dot;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return out;
|
|
46
|
+
};
|
|
47
|
+
export {
|
|
48
|
+
mulM
|
|
49
|
+
};
|
package/muln.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Componentwise nD tensor multiplication with uniform scalar `n`. Writes result
|
|
3
|
+
* to `out`. If `out` is null, mutates `a`. Multi-method.
|
|
4
|
+
*
|
|
5
|
+
* @param out - output tensor
|
|
6
|
+
* @param a - input tensor
|
|
7
|
+
* @param n - scalar
|
|
8
|
+
*/
|
|
9
|
+
export declare const mulN: import("./api.js").MultiTensorOpTN<number>;
|
|
10
|
+
/**
|
|
11
|
+
* Same as {@link mulN} for 1D tensors.
|
|
12
|
+
*
|
|
13
|
+
* @param out - output tensor
|
|
14
|
+
* @param a - input tensor
|
|
15
|
+
* @param n - scalar
|
|
16
|
+
*/
|
|
17
|
+
export declare const mulN1: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor1<number>, import("./tensor.js").Tensor1<number>>;
|
|
18
|
+
/**
|
|
19
|
+
* Same as {@link mulN} for 2D tensors.
|
|
20
|
+
*
|
|
21
|
+
* @param out - output tensor
|
|
22
|
+
* @param a - input tensor
|
|
23
|
+
* @param n - scalar
|
|
24
|
+
*/
|
|
25
|
+
export declare const mulN2: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor2<number>, import("./tensor.js").Tensor2<number>>;
|
|
26
|
+
/**
|
|
27
|
+
* Same as {@link mulN} for 3D tensors.
|
|
28
|
+
*
|
|
29
|
+
* @param out - output tensor
|
|
30
|
+
* @param a - input tensor
|
|
31
|
+
* @param n - scalar
|
|
32
|
+
*/
|
|
33
|
+
export declare const mulN3: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor3<number>, import("./tensor.js").Tensor3<number>>;
|
|
34
|
+
/**
|
|
35
|
+
* Same as {@link mulN} for 4D tensors.
|
|
36
|
+
*
|
|
37
|
+
* @param out - output tensor
|
|
38
|
+
* @param a - input tensor
|
|
39
|
+
* @param n - scalar
|
|
40
|
+
*/
|
|
41
|
+
export declare const mulN4: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor4<number>, import("./tensor.js").Tensor4<number>>;
|
|
42
|
+
//# sourceMappingURL=muln.d.ts.map
|
package/muln.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { $mul } from "@thi.ng/vectors/ops";
|
|
2
|
+
import { defOpTN } from "./defoptn.js";
|
|
3
|
+
const [a, b, c, d, e] = defOpTN($mul);
|
|
4
|
+
const mulN = a;
|
|
5
|
+
const mulN1 = b;
|
|
6
|
+
const mulN2 = c;
|
|
7
|
+
const mulN3 = d;
|
|
8
|
+
const mulN4 = e;
|
|
9
|
+
export {
|
|
10
|
+
mulN,
|
|
11
|
+
mulN1,
|
|
12
|
+
mulN2,
|
|
13
|
+
mulN3,
|
|
14
|
+
mulN4
|
|
15
|
+
};
|
package/mulv.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Tensor1, type Tensor2 } from "./tensor.js";
|
|
2
|
+
/**
|
|
3
|
+
* Matrix-vector multiplication. If `out` is null, a new 1D tensor will be
|
|
4
|
+
* created, using vector `b`'s storage impl.
|
|
5
|
+
*
|
|
6
|
+
* @param out
|
|
7
|
+
* @param a
|
|
8
|
+
* @param b
|
|
9
|
+
*/
|
|
10
|
+
export declare const mulV: (out: Tensor1 | null, a: Tensor2, b: Tensor1) => Tensor1<number>;
|
|
11
|
+
//# sourceMappingURL=mulv.d.ts.map
|
package/mulv.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { illegalShape } from "./errors.js";
|
|
2
|
+
import { tensor } from "./tensor.js";
|
|
3
|
+
const mulV = (out, a, b) => {
|
|
4
|
+
const {
|
|
5
|
+
data: adata,
|
|
6
|
+
offset: offa,
|
|
7
|
+
shape: [rowa, cola],
|
|
8
|
+
stride: [txa, tya]
|
|
9
|
+
} = a;
|
|
10
|
+
const {
|
|
11
|
+
data: bdata,
|
|
12
|
+
offset: offb,
|
|
13
|
+
shape: [rowb],
|
|
14
|
+
stride: [txb]
|
|
15
|
+
} = b;
|
|
16
|
+
if (cola !== rowb) illegalShape(b.shape);
|
|
17
|
+
if (out == null) {
|
|
18
|
+
out = tensor(b.type, [rowa], { storage: b.storage });
|
|
19
|
+
}
|
|
20
|
+
const {
|
|
21
|
+
data: odata,
|
|
22
|
+
offset: offo,
|
|
23
|
+
shape: [rowo],
|
|
24
|
+
stride: [txo]
|
|
25
|
+
} = out;
|
|
26
|
+
if (rowo !== rowa) illegalShape(out.shape);
|
|
27
|
+
for (let i = 0; i < rowa; i++) {
|
|
28
|
+
const ia = offa + i * txa;
|
|
29
|
+
let sum = 0;
|
|
30
|
+
for (let j = 0; j < cola; j++) {
|
|
31
|
+
sum += adata[ia + j * tya] * bdata[offb + j * txb];
|
|
32
|
+
}
|
|
33
|
+
odata[offo + i * txo] = sum;
|
|
34
|
+
}
|
|
35
|
+
return out;
|
|
36
|
+
};
|
|
37
|
+
export {
|
|
38
|
+
mulV
|
|
39
|
+
};
|
package/normalize.d.ts
ADDED
package/normalize.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { magSq } from "./magsq.js";
|
|
2
|
+
import { mulN } from "./muln.js";
|
|
3
|
+
import { set } from "./set.js";
|
|
4
|
+
const normalize = (out, a, n = 1) => {
|
|
5
|
+
!out && (out = a);
|
|
6
|
+
const m = Math.sqrt(magSq(a));
|
|
7
|
+
return m >= 1e-6 ? mulN(out || a, a, n / m) : out !== a ? set(out, a) : out;
|
|
8
|
+
};
|
|
9
|
+
export {
|
|
10
|
+
normalize
|
|
11
|
+
};
|