@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.
Files changed (124) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/LICENSE +201 -0
  3. package/README.md +307 -0
  4. package/abs.d.ts +37 -0
  5. package/abs.js +14 -0
  6. package/add.d.ts +42 -0
  7. package/add.js +15 -0
  8. package/addn.d.ts +42 -0
  9. package/addn.js +15 -0
  10. package/api.d.ts +137 -0
  11. package/api.js +0 -0
  12. package/clamp.d.ts +47 -0
  13. package/clamp.js +15 -0
  14. package/clampn.d.ts +47 -0
  15. package/clampn.js +15 -0
  16. package/cos.d.ts +37 -0
  17. package/cos.js +14 -0
  18. package/defopn.d.ts +13 -0
  19. package/defopn.js +65 -0
  20. package/defoprt.d.ts +14 -0
  21. package/defoprt.js +77 -0
  22. package/defoprtt.d.ts +14 -0
  23. package/defoprtt.js +113 -0
  24. package/defopt.d.ts +13 -0
  25. package/defopt.js +109 -0
  26. package/defoptn.d.ts +13 -0
  27. package/defoptn.js +109 -0
  28. package/defoptnn.d.ts +13 -0
  29. package/defoptnn.js +109 -0
  30. package/defoptt.d.ts +13 -0
  31. package/defoptt.js +144 -0
  32. package/defopttt.d.ts +13 -0
  33. package/defopttt.js +177 -0
  34. package/div.d.ts +42 -0
  35. package/div.js +15 -0
  36. package/divn.d.ts +42 -0
  37. package/divn.js +15 -0
  38. package/dot.d.ts +31 -0
  39. package/dot.js +17 -0
  40. package/errors.d.ts +15 -0
  41. package/errors.js +9 -0
  42. package/exp.d.ts +37 -0
  43. package/exp.js +14 -0
  44. package/exp2.d.ts +37 -0
  45. package/exp2.js +14 -0
  46. package/format.d.ts +14 -0
  47. package/format.js +37 -0
  48. package/identity.d.ts +4 -0
  49. package/identity.js +11 -0
  50. package/index.d.ts +60 -0
  51. package/index.js +59 -0
  52. package/log.d.ts +37 -0
  53. package/log.js +14 -0
  54. package/log2.d.ts +37 -0
  55. package/log2.js +14 -0
  56. package/mag.d.ts +3 -0
  57. package/mag.js +5 -0
  58. package/magsq.d.ts +31 -0
  59. package/magsq.js +17 -0
  60. package/max.d.ts +37 -0
  61. package/max.js +14 -0
  62. package/maxn.d.ts +42 -0
  63. package/maxn.js +14 -0
  64. package/min.d.ts +37 -0
  65. package/min.js +14 -0
  66. package/minn.d.ts +42 -0
  67. package/minn.js +14 -0
  68. package/mul.d.ts +42 -0
  69. package/mul.js +15 -0
  70. package/mulm.d.ts +12 -0
  71. package/mulm.js +49 -0
  72. package/muln.d.ts +42 -0
  73. package/muln.js +15 -0
  74. package/mulv.d.ts +11 -0
  75. package/mulv.js +39 -0
  76. package/normalize.d.ts +3 -0
  77. package/normalize.js +11 -0
  78. package/package.json +261 -0
  79. package/pow.d.ts +37 -0
  80. package/pow.js +14 -0
  81. package/pown.d.ts +42 -0
  82. package/pown.js +14 -0
  83. package/product.d.ts +31 -0
  84. package/product.js +15 -0
  85. package/rand-distrib.d.ts +49 -0
  86. package/rand-distrib.js +52 -0
  87. package/relu.d.ts +37 -0
  88. package/relu.js +14 -0
  89. package/relun.d.ts +43 -0
  90. package/relun.js +14 -0
  91. package/select.d.ts +91 -0
  92. package/select.js +111 -0
  93. package/set.d.ts +8 -0
  94. package/set.js +14 -0
  95. package/setn.d.ts +8 -0
  96. package/setn.js +14 -0
  97. package/sigmoid.d.ts +39 -0
  98. package/sigmoid.js +15 -0
  99. package/sin.d.ts +37 -0
  100. package/sin.js +14 -0
  101. package/softmax.d.ts +27 -0
  102. package/softmax.js +10 -0
  103. package/softplus.d.ts +48 -0
  104. package/softplus.js +15 -0
  105. package/sqrt.d.ts +37 -0
  106. package/sqrt.js +14 -0
  107. package/step.d.ts +48 -0
  108. package/step.js +14 -0
  109. package/storage.d.ts +3 -0
  110. package/storage.js +32 -0
  111. package/sub.d.ts +42 -0
  112. package/sub.js +15 -0
  113. package/subn.d.ts +42 -0
  114. package/subn.js +15 -0
  115. package/sum.d.ts +31 -0
  116. package/sum.js +15 -0
  117. package/tan.d.ts +37 -0
  118. package/tan.js +14 -0
  119. package/tanh.d.ts +37 -0
  120. package/tanh.js +14 -0
  121. package/tensor.d.ts +127 -0
  122. package/tensor.js +517 -0
  123. package/top.d.ts +16 -0
  124. 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
@@ -0,0 +1,14 @@
1
+ import { defOpT } from "./defopt.js";
2
+ const [a, b, c, d, e] = defOpT(Math.log);
3
+ const log = a;
4
+ const log_1 = b;
5
+ const log_2 = c;
6
+ const log_3 = d;
7
+ const log_4 = e;
8
+ export {
9
+ log,
10
+ log_1,
11
+ log_2,
12
+ log_3,
13
+ log_4
14
+ };
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
@@ -0,0 +1,14 @@
1
+ import { defOpT } from "./defopt.js";
2
+ const [a, b, c, d, e] = defOpT(Math.log2);
3
+ const log2 = a;
4
+ const log2_1 = b;
5
+ const log2_2 = c;
6
+ const log2_3 = d;
7
+ const log2_4 = e;
8
+ export {
9
+ log2,
10
+ log2_1,
11
+ log2_2,
12
+ log2_3,
13
+ log2_4
14
+ };
package/mag.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import type { ITensor } from "./api.js";
2
+ export declare const mag: (a: ITensor) => number;
3
+ //# sourceMappingURL=mag.d.ts.map
package/mag.js ADDED
@@ -0,0 +1,5 @@
1
+ import { magSq } from "./magsq.js";
2
+ const mag = (a) => Math.sqrt(magSq(a));
3
+ export {
4
+ mag
5
+ };
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
@@ -0,0 +1,14 @@
1
+ import { defOpTT } from "./defoptt.js";
2
+ const [a, b, c, d, e] = defOpTT(Math.max);
3
+ const max = a;
4
+ const max1 = b;
5
+ const max2 = c;
6
+ const max3 = d;
7
+ const max4 = e;
8
+ export {
9
+ max,
10
+ max1,
11
+ max2,
12
+ max3,
13
+ max4
14
+ };
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
@@ -0,0 +1,14 @@
1
+ import { defOpTN } from "./defoptn.js";
2
+ const [a, b, c, d, e] = defOpTN(Math.max);
3
+ const maxN = a;
4
+ const maxN1 = b;
5
+ const maxN2 = c;
6
+ const maxN3 = d;
7
+ const maxN4 = e;
8
+ export {
9
+ maxN,
10
+ maxN1,
11
+ maxN2,
12
+ maxN3,
13
+ maxN4
14
+ };
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
@@ -0,0 +1,14 @@
1
+ import { defOpTT } from "./defoptt.js";
2
+ const [a, b, c, d, e] = defOpTT(Math.min);
3
+ const min = a;
4
+ const min1 = b;
5
+ const min2 = c;
6
+ const min3 = d;
7
+ const min4 = e;
8
+ export {
9
+ min,
10
+ min1,
11
+ min2,
12
+ min3,
13
+ min4
14
+ };
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
@@ -0,0 +1,14 @@
1
+ import { defOpTN } from "./defoptn.js";
2
+ const [a, b, c, d, e] = defOpTN(Math.min);
3
+ const minN = a;
4
+ const minN1 = b;
5
+ const minN2 = c;
6
+ const minN3 = d;
7
+ const minN4 = e;
8
+ export {
9
+ minN,
10
+ minN1,
11
+ minN2,
12
+ minN3,
13
+ minN4
14
+ };
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
@@ -0,0 +1,3 @@
1
+ import type { ITensor } from "./api.js";
2
+ export declare const normalize: (out: ITensor | null, a: ITensor, n?: number) => ITensor<any>;
3
+ //# sourceMappingURL=normalize.d.ts.map
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
+ };