@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/select.d.ts ADDED
@@ -0,0 +1,91 @@
1
+ import type { Fn, Predicate2 } from "@thi.ng/api";
2
+ import type { ITensor } from "./api.js";
3
+ import type { Tensor1, Tensor2, Tensor3 } from "./tensor.js";
4
+ /**
5
+ * Result type of {@link select}.
6
+ */
7
+ export type SelectResult<T> = {
8
+ arg: number[];
9
+ value: T;
10
+ };
11
+ /**
12
+ * Same as {@link select} for 1D tensors.
13
+ *
14
+ * @param a
15
+ * @param xform
16
+ * @param pred
17
+ * @param initial
18
+ */
19
+ export declare const select1: <T>(a: Tensor1<T>, xform: Fn<T, T>, pred: Predicate2<T>, initial: T) => SelectResult<T>;
20
+ /**
21
+ * Same as {@link select} for 2D tensors.
22
+ *
23
+ * @param a
24
+ * @param xform
25
+ * @param pred
26
+ * @param initial
27
+ */
28
+ export declare const select2: <T>(a: Tensor2<T>, xform: Fn<T, T>, pred: Predicate2<T>, initial: T) => SelectResult<T>;
29
+ /**
30
+ * Same as {@link select} for 3D tensors.
31
+ *
32
+ * @param a
33
+ * @param xform
34
+ * @param pred
35
+ * @param initial
36
+ */
37
+ export declare const select3: <T>(a: Tensor3<T>, xform: Fn<T, T>, pred: Predicate2<T>, initial: T) => SelectResult<T>;
38
+ /**
39
+ * Same as {@link select} for 4D tensors.
40
+ *
41
+ * @param a
42
+ * @param xform
43
+ * @param pred
44
+ * @param initial
45
+ */
46
+ export declare const select4: <T>(a: Tensor3<T>, xform: Fn<T, T>, pred: Predicate2<T>, initial: T) => SelectResult<T>;
47
+ /**
48
+ * Uses given value transform `xform` and predicate `pred` to select a specific
49
+ * component value and its position in the tensor. The `initial` value is used
50
+ * to seed the search.
51
+ *
52
+ * @remarks
53
+ * This function is a generalization of {@link argMin}/{@link argMax}-like
54
+ * functionality and customizable via arbitrary predicates.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * import { select, tensor } from "@thi.ng/tensors";
59
+ *
60
+ * const a = tensor("i8", [2, 2], { data: [1, -2, -3, 4] });
61
+ *
62
+ * // select smallest value
63
+ * console.log(select(a, (x) => x, (a,b) => a < b, Infinity));
64
+ * // { arg: [1, 0], value: -3 }
65
+ *
66
+ * // select smallest absolute value
67
+ * console.log(select(a, Math.abs, (a,b) => a < b, Infinity));
68
+ * // { arg: [0, 0], value: 1 }
69
+ * ```
70
+ *
71
+ * @param a
72
+ * @param xform
73
+ * @param pred
74
+ * @param initial
75
+ */
76
+ export declare const select: <T>(a: ITensor<T>, xform: Fn<T, T>, pred: Predicate2<T>, initial: T) => SelectResult<T>;
77
+ /**
78
+ * Syntax sugar for {@link select} to find the minimum component value and its
79
+ * position in a tensor.
80
+ *
81
+ * @param a
82
+ */
83
+ export declare const argMin: (a: ITensor) => SelectResult<number>;
84
+ /**
85
+ * Syntax sugar for {@link select} to find the maximum component value and its
86
+ * position in a tensor.
87
+ *
88
+ * @param a
89
+ */
90
+ export declare const argMax: (a: ITensor) => SelectResult<number>;
91
+ //# sourceMappingURL=select.d.ts.map
package/select.js ADDED
@@ -0,0 +1,111 @@
1
+ import { identity } from "@thi.ng/api/fn";
2
+ import { top } from "./top.js";
3
+ const select1 = (a, xform, pred, initial) => {
4
+ const {
5
+ data,
6
+ offset,
7
+ shape: [sx],
8
+ stride: [tx]
9
+ } = a;
10
+ const arg = [-1];
11
+ let value = initial;
12
+ for (let x = 0; x < sx; x++) {
13
+ const v = xform(data[offset + x * tx]);
14
+ if (pred(v, value)) {
15
+ value = v;
16
+ arg[0] = x;
17
+ }
18
+ }
19
+ return { arg, value };
20
+ };
21
+ const select2 = (a, xform, pred, initial) => {
22
+ const {
23
+ data,
24
+ offset,
25
+ shape: [sx, sy],
26
+ stride: [tx, ty]
27
+ } = a;
28
+ const arg = [-1, -1];
29
+ let value = initial;
30
+ for (let x = 0; x < sx; x++) {
31
+ const ox = offset + x * tx;
32
+ for (let y = 0; y < sy; y++) {
33
+ const v = xform(data[ox + y * ty]);
34
+ if (pred(v, value)) {
35
+ value = v;
36
+ arg[0] = x;
37
+ arg[1] = y;
38
+ }
39
+ }
40
+ }
41
+ return { arg, value };
42
+ };
43
+ const select3 = (a, xform, pred, initial) => {
44
+ const {
45
+ data,
46
+ offset,
47
+ shape: [sx, sy, sz],
48
+ stride: [tx, ty, tz]
49
+ } = a;
50
+ const arg = [-1, -1, -1];
51
+ let value = initial;
52
+ for (let x = 0; x < sx; x++) {
53
+ const ox = offset + x * tx;
54
+ for (let y = 0; y < sy; y++) {
55
+ const oy = ox + y * ty;
56
+ for (let z = 0; z < sz; z++) {
57
+ const v = xform(data[oy + z * tz]);
58
+ if (pred(v, value)) {
59
+ value = v;
60
+ arg[0] = x;
61
+ arg[1] = y;
62
+ arg[2] = z;
63
+ }
64
+ }
65
+ }
66
+ }
67
+ return { arg, value };
68
+ };
69
+ const select4 = (a, xform, pred, initial) => {
70
+ const {
71
+ data,
72
+ offset,
73
+ shape: [sx, sy, sz, sw],
74
+ stride: [tx, ty, tz, tw]
75
+ } = a;
76
+ const arg = [-1, -1, -1, -1];
77
+ let value = initial;
78
+ for (let x = 0; x < sx; x++) {
79
+ const ox = offset + x * tx;
80
+ for (let y = 0; y < sy; y++) {
81
+ const oy = ox + y * ty;
82
+ for (let z = 0; z < sz; z++) {
83
+ const oz = oy + z * tz;
84
+ for (let w = 0; w < sw; w++) {
85
+ const v = xform(data[oz + w * tw]);
86
+ if (pred(v, value)) {
87
+ value = v;
88
+ arg[0] = x;
89
+ arg[1] = y;
90
+ arg[2] = z;
91
+ arg[3] = w;
92
+ }
93
+ }
94
+ }
95
+ }
96
+ }
97
+ return { arg, value };
98
+ };
99
+ const __select = top(0, void 0, select1, select2, select3, select4);
100
+ const select = (a, xform, pred, initial) => __select(a, xform, pred, initial);
101
+ const argMin = (a) => __select(a, identity, (a2, b) => a2 < b, Infinity);
102
+ const argMax = (a) => __select(a, identity, (a2, b) => a2 > b, -Infinity);
103
+ export {
104
+ argMax,
105
+ argMin,
106
+ select,
107
+ select1,
108
+ select2,
109
+ select3,
110
+ select4
111
+ };
package/set.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import type { ITensor } from "./api.js";
2
+ import type { Tensor1, Tensor2, Tensor3, Tensor4 } from "./tensor.js";
3
+ export declare const set: <T>(out: ITensor<T>, src: ITensor<T>) => ITensor<any>;
4
+ export declare const set1: <T>(out: Tensor1<T>, src: Tensor1<T>) => Tensor1<any>;
5
+ export declare const set2: <T>(out: Tensor2<T>, src: Tensor2<T>) => Tensor2<any>;
6
+ export declare const set3: <T>(out: Tensor3<T>, src: Tensor3<T>) => Tensor3<any>;
7
+ export declare const set4: <T>(out: Tensor4<T>, src: Tensor4<T>) => Tensor4<any>;
8
+ //# sourceMappingURL=set.d.ts.map
package/set.js ADDED
@@ -0,0 +1,14 @@
1
+ import { defOpT } from "./defopt.js";
2
+ const [a, b, c, d, e] = defOpT((x) => x);
3
+ const set = (out, src) => a(out, src);
4
+ const set1 = (out, src) => b(out, src);
5
+ const set2 = (out, src) => c(out, src);
6
+ const set3 = (out, src) => d(out, src);
7
+ const set4 = (out, src) => e(out, src);
8
+ export {
9
+ set,
10
+ set1,
11
+ set2,
12
+ set3,
13
+ set4
14
+ };
package/setn.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import type { ITensor } from "./api.js";
2
+ import type { Tensor1, Tensor2, Tensor3, Tensor4 } from "./tensor.js";
3
+ export declare const setN: <T>(out: ITensor<T>, n: T) => ITensor<any>;
4
+ export declare const setN1: <T>(out: Tensor1<T>, n: T) => Tensor1<any>;
5
+ export declare const setN2: <T>(out: Tensor2<T>, n: T) => Tensor2<any>;
6
+ export declare const setN3: <T>(out: Tensor3<T>, n: T) => Tensor3<any>;
7
+ export declare const setN4: <T>(out: Tensor4<T>, n: T) => Tensor4<any>;
8
+ //# sourceMappingURL=setn.d.ts.map
package/setn.js ADDED
@@ -0,0 +1,14 @@
1
+ import { defOpN } from "./defopn.js";
2
+ const [a, b, c, d, e] = defOpN((x) => x);
3
+ const setN = (out, n) => a(out, n);
4
+ const setN1 = (out, n) => b(out, n);
5
+ const setN2 = (out, n) => c(out, n);
6
+ const setN3 = (out, n) => d(out, n);
7
+ const setN4 = (out, n) => e(out, n);
8
+ export {
9
+ setN,
10
+ setN1,
11
+ setN2,
12
+ setN3,
13
+ setN4
14
+ };
package/sigmoid.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Componentwise computes Sigmoid activation of given nD tensor. Writes result
3
+ * to `out`. If `out` is null, mutates original. Multi-method.
4
+ *
5
+ * Reference: https://en.wikipedia.org/wiki/Sigmoid_function
6
+ *
7
+ * @param out - output tensor
8
+ * @param a - input tensor
9
+ */
10
+ export declare const sigmoid: import("./api.js").MultiTensorOpT<number>;
11
+ /**
12
+ * Same as {@link sigmoid} for 1D tensors.
13
+ *
14
+ * @param out - output tensor
15
+ * @param a - input tensor
16
+ */
17
+ export declare const sigmoid1: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor1<number>, import("./tensor.js").Tensor1<number>>;
18
+ /**
19
+ * Same as {@link sigmoid} for 2D tensors.
20
+ *
21
+ * @param out - output tensor
22
+ * @param a - input tensor
23
+ */
24
+ export declare const sigmoid2: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor2<number>, import("./tensor.js").Tensor2<number>>;
25
+ /**
26
+ * Same as {@link sigmoid} for 3D tensors.
27
+ *
28
+ * @param out - output tensor
29
+ * @param a - input tensor
30
+ */
31
+ export declare const sigmoid3: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor3<number>, import("./tensor.js").Tensor3<number>>;
32
+ /**
33
+ * Same as {@link sigmoid} for 4D tensors.
34
+ *
35
+ * @param out - output tensor
36
+ * @param a - input tensor
37
+ */
38
+ export declare const sigmoid4: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor4<number>, import("./tensor.js").Tensor4<number>>;
39
+ //# sourceMappingURL=sigmoid.d.ts.map
package/sigmoid.js ADDED
@@ -0,0 +1,15 @@
1
+ import { defOpT } from "./defopt.js";
2
+ const { exp } = Math;
3
+ const [a, b, c, d, e] = defOpT((x) => 1 / (1 + exp(-x)));
4
+ const sigmoid = a;
5
+ const sigmoid1 = b;
6
+ const sigmoid2 = c;
7
+ const sigmoid3 = d;
8
+ const sigmoid4 = e;
9
+ export {
10
+ sigmoid,
11
+ sigmoid1,
12
+ sigmoid2,
13
+ sigmoid3,
14
+ sigmoid4
15
+ };
package/sin.d.ts ADDED
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Componentwise computes `Math.sin` 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 sin: import("./api.js").MultiTensorOpT<number>;
9
+ /**
10
+ * Same as {@link sin} for 1D tensors.
11
+ *
12
+ * @param out - output tensor
13
+ * @param a - input tensor
14
+ */
15
+ export declare const sin1: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor1<number>, import("./tensor.js").Tensor1<number>>;
16
+ /**
17
+ * Same as {@link sin} for 2D tensors.
18
+ *
19
+ * @param out - output tensor
20
+ * @param a - input tensor
21
+ */
22
+ export declare const sin2: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor2<number>, import("./tensor.js").Tensor2<number>>;
23
+ /**
24
+ * Same as {@link sin} for 3D tensors.
25
+ *
26
+ * @param out - output tensor
27
+ * @param a - input tensor
28
+ */
29
+ export declare const sin3: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor3<number>, import("./tensor.js").Tensor3<number>>;
30
+ /**
31
+ * Same as {@link sin} for 4D tensors.
32
+ *
33
+ * @param out - output tensor
34
+ * @param a - input tensor
35
+ */
36
+ export declare const sin4: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor4<number>, import("./tensor.js").Tensor4<number>>;
37
+ //# sourceMappingURL=sin.d.ts.map
package/sin.js ADDED
@@ -0,0 +1,14 @@
1
+ import { defOpT } from "./defopt.js";
2
+ const [a, b, c, d, e] = defOpT(Math.sin);
3
+ const sin = a;
4
+ const sin1 = b;
5
+ const sin2 = c;
6
+ const sin3 = d;
7
+ const sin4 = e;
8
+ export {
9
+ sin,
10
+ sin1,
11
+ sin2,
12
+ sin3,
13
+ sin4
14
+ };
package/softmax.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ import type { ITensor } from "./api.js";
2
+ /**
3
+ * Computes softmax (aka normalized {@link exp}) of input tensor `src` and
4
+ * writes results to `out` (or if null, back into `src`). The optional
5
+ * `temperature` (should be >= 1) can be used to adjust the emphasis/scaling of
6
+ * normalized values: Higher temperatures reduce the contrast ratio between
7
+ * min/max components.
8
+ *
9
+ * @remarks
10
+ * Computes: `smax = exp(src / temp) / sum(exp(src / temp))`. The result
11
+ * vector's components will all be in the [0,1] range and sum to 1.0.
12
+ *
13
+ * This function is often used as the last activation function in a neural
14
+ * network to normalize the output to a probability distribution over predicted
15
+ * output classes.
16
+ *
17
+ * References:
18
+ *
19
+ * - https://en.wikipedia.org/wiki/Softmax_function
20
+ * - https://victorzhou.com/blog/softmax/
21
+ *
22
+ * @param out -
23
+ * @param src -
24
+ * @param temperature -
25
+ */
26
+ export declare const softMax: (out: ITensor | null, src: ITensor, temperature?: number) => ITensor<number>;
27
+ //# sourceMappingURL=softmax.d.ts.map
package/softmax.js ADDED
@@ -0,0 +1,10 @@
1
+ import { divN } from "./divn.js";
2
+ import { exp } from "./exp.js";
3
+ import { sum } from "./sum.js";
4
+ const softMax = (out, src, temperature) => {
5
+ const e = temperature !== void 0 ? exp(null, divN(src.empty(), src, temperature)) : exp(src.empty(), src);
6
+ return divN(out || src, e, sum(e));
7
+ };
8
+ export {
9
+ softMax
10
+ };
package/softplus.d.ts ADDED
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Componentwise computes Softplus activation of given nD tensor with given `k`
3
+ * (sharpness param, should be >= 1). Writes result to `out`. If `out` is null,
4
+ * mutates original. Multi-method.
5
+ *
6
+ * @remarks
7
+ *
8
+ * - Reference: https://en.wikipedia.org/wiki/Softplus
9
+ * - Interactive calculator: https://www.desmos.com/calculator/54pfflbsbv
10
+ *
11
+ * @param out - output tensor
12
+ * @param a - input tensor
13
+ * @param n - sharpness
14
+ */
15
+ export declare const softPlus: import("./api.js").MultiTensorOpTN<number>;
16
+ /**
17
+ * Same as {@link softPlus} for 1D tensors.
18
+ *
19
+ * @param out - output tensor
20
+ * @param a - input tensor
21
+ * @param n - sharpness
22
+ */
23
+ export declare const softPlus1: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor1<number>, import("./tensor.js").Tensor1<number>>;
24
+ /**
25
+ * Same as {@link softPlus} for 2D tensors.
26
+ *
27
+ * @param out - output tensor
28
+ * @param a - input tensor
29
+ * @param n - sharpness
30
+ */
31
+ export declare const softPlus2: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor2<number>, import("./tensor.js").Tensor2<number>>;
32
+ /**
33
+ * Same as {@link softPlus} for 3D tensors.
34
+ *
35
+ * @param out - output tensor
36
+ * @param a - input tensor
37
+ * @param n - sharpness
38
+ */
39
+ export declare const softPlus3: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor3<number>, import("./tensor.js").Tensor3<number>>;
40
+ /**
41
+ * Same as {@link softPlus} for 4D tensors.
42
+ *
43
+ * @param out - output tensor
44
+ * @param a - input tensor
45
+ * @param n - sharpness
46
+ */
47
+ export declare const softPlus4: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor4<number>, import("./tensor.js").Tensor4<number>>;
48
+ //# sourceMappingURL=softplus.d.ts.map
package/softplus.js ADDED
@@ -0,0 +1,15 @@
1
+ import { defOpTN } from "./defoptn.js";
2
+ const { exp, log } = Math;
3
+ const [a, b, c, d, e] = defOpTN((x, k) => log(1 + exp(x * k)) / k);
4
+ const softPlus = a;
5
+ const softPlus1 = b;
6
+ const softPlus2 = c;
7
+ const softPlus3 = d;
8
+ const softPlus4 = e;
9
+ export {
10
+ softPlus,
11
+ softPlus1,
12
+ softPlus2,
13
+ softPlus3,
14
+ softPlus4
15
+ };
package/sqrt.d.ts ADDED
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Componentwise computes `Math.sqrt` 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 sqrt: import("./api.js").MultiTensorOpT<number>;
9
+ /**
10
+ * Same as {@link sqrt} for 1D tensors.
11
+ *
12
+ * @param out - output tensor
13
+ * @param a - input tensor
14
+ */
15
+ export declare const sqrt1: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor1<number>, import("./tensor.js").Tensor1<number>>;
16
+ /**
17
+ * Same as {@link sqrt} for 2D tensors.
18
+ *
19
+ * @param out - output tensor
20
+ * @param a - input tensor
21
+ */
22
+ export declare const sqrt2: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor2<number>, import("./tensor.js").Tensor2<number>>;
23
+ /**
24
+ * Same as {@link sqrt} for 3D tensors.
25
+ *
26
+ * @param out - output tensor
27
+ * @param a - input tensor
28
+ */
29
+ export declare const sqrt3: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor3<number>, import("./tensor.js").Tensor3<number>>;
30
+ /**
31
+ * Same as {@link sqrt} for 4D tensors.
32
+ *
33
+ * @param out - output tensor
34
+ * @param a - input tensor
35
+ */
36
+ export declare const sqrt4: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor4<number>, import("./tensor.js").Tensor4<number>>;
37
+ //# sourceMappingURL=sqrt.d.ts.map
package/sqrt.js ADDED
@@ -0,0 +1,14 @@
1
+ import { defOpT } from "./defopt.js";
2
+ const [a, b, c, d, e] = defOpT(Math.sqrt);
3
+ const sqrt = a;
4
+ const sqrt1 = b;
5
+ const sqrt2 = c;
6
+ const sqrt3 = d;
7
+ const sqrt4 = e;
8
+ export {
9
+ sqrt,
10
+ sqrt1,
11
+ sqrt2,
12
+ sqrt3,
13
+ sqrt4
14
+ };
package/step.d.ts ADDED
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Componentwise computes step function for given nD tensor and uniform scalar
3
+ * threshold `n`. Writes result to `out`. If `out` is null, mutates `a`.
4
+ * Multi-method.
5
+ *
6
+ * @remarks
7
+ * Same logic as GLSL `step()` (but with different order of arguments). If
8
+ * `n=0`, the op becomes the Heaviside function:
9
+ * https://en.wikipedia.org/wiki/Heaviside_step_function
10
+ *
11
+ * @param out - output tensor
12
+ * @param a - input tensor
13
+ * @param n - scalar
14
+ */
15
+ export declare const stepN: import("./api.js").MultiTensorOpTN<number>;
16
+ /**
17
+ * Same as {@link stepN} for 1D tensors.
18
+ *
19
+ * @param out - output tensor
20
+ * @param a - input tensor
21
+ * @param n - scalar
22
+ */
23
+ export declare const stepN1: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor1<number>, import("./tensor.js").Tensor1<number>>;
24
+ /**
25
+ * Same as {@link stepN} for 2D tensors.
26
+ *
27
+ * @param out - output tensor
28
+ * @param a - input tensor
29
+ * @param n - scalar
30
+ */
31
+ export declare const stepN2: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor2<number>, import("./tensor.js").Tensor2<number>>;
32
+ /**
33
+ * Same as {@link stepN} for 3D tensors.
34
+ *
35
+ * @param out - output tensor
36
+ * @param a - input tensor
37
+ * @param n - scalar
38
+ */
39
+ export declare const stepN3: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor3<number>, import("./tensor.js").Tensor3<number>>;
40
+ /**
41
+ * Same as {@link stepN} for 4D tensors.
42
+ *
43
+ * @param out - output tensor
44
+ * @param a - input tensor
45
+ * @param n - scalar
46
+ */
47
+ export declare const stepN4: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor4<number>, import("./tensor.js").Tensor4<number>>;
48
+ //# sourceMappingURL=step.d.ts.map
package/step.js ADDED
@@ -0,0 +1,14 @@
1
+ import { defOpTN } from "./defoptn.js";
2
+ const [a, b, c, d, e] = defOpTN((a2, b2) => a2 >= b2 ? 1 : 0);
3
+ const stepN = a;
4
+ const stepN1 = b;
5
+ const stepN2 = c;
6
+ const stepN3 = d;
7
+ const stepN4 = e;
8
+ export {
9
+ stepN,
10
+ stepN1,
11
+ stepN2,
12
+ stepN3,
13
+ stepN4
14
+ };
package/storage.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import type { StorageRegistry } from "./api.js";
2
+ export declare const STORAGE: StorageRegistry;
3
+ //# sourceMappingURL=storage.d.ts.map
package/storage.js ADDED
@@ -0,0 +1,32 @@
1
+ import {} from "@thi.ng/api";
2
+ import { always } from "@thi.ng/api/fn";
3
+ import { typedArray, TYPEDARRAY_CTORS } from "@thi.ng/api/typedarray";
4
+ const impl = (type) => ({
5
+ alloc: (size) => typedArray(type, size),
6
+ from: (iter) => TYPEDARRAY_CTORS[type].from(iter),
7
+ release: always
8
+ });
9
+ const STORAGE = {
10
+ u8: impl("u8"),
11
+ u8c: impl("u8c"),
12
+ i8: impl("i8"),
13
+ u16: impl("u16"),
14
+ i16: impl("i16"),
15
+ u32: impl("u32"),
16
+ i32: impl("i32"),
17
+ f32: impl("f32"),
18
+ f64: impl("f64"),
19
+ num: {
20
+ alloc: (size) => new Array(size).fill(0),
21
+ from: (iter) => [...iter],
22
+ release: always
23
+ },
24
+ str: {
25
+ alloc: (size) => new Array(size).fill(""),
26
+ from: (iter) => [...iter],
27
+ release: always
28
+ }
29
+ };
30
+ export {
31
+ STORAGE
32
+ };
package/sub.d.ts ADDED
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Componentwise nD tensor subtraction. 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 sub: import("./api.js").MultiTensorOpTT<number>;
10
+ /**
11
+ * Same as {@link sub} for 1D tensors.
12
+ *
13
+ * @param out - output tensor
14
+ * @param a - input tensor
15
+ * @param n - scalar
16
+ */
17
+ export declare const sub1: import("./api.js").TensorOpTT<number, number, import("./tensor.js").Tensor1<number>, import("./tensor.js").Tensor1<number>>;
18
+ /**
19
+ * Same as {@link sub} for 2D tensors.
20
+ *
21
+ * @param out - output tensor
22
+ * @param a - input tensor
23
+ * @param n - scalar
24
+ */
25
+ export declare const sub2: import("./api.js").TensorOpTT<number, number, import("./tensor.js").Tensor2<number>, import("./tensor.js").Tensor2<number>>;
26
+ /**
27
+ * Same as {@link sub} for 3D tensors.
28
+ *
29
+ * @param out - output tensor
30
+ * @param a - input tensor
31
+ * @param n - scalar
32
+ */
33
+ export declare const sub3: import("./api.js").TensorOpTT<number, number, import("./tensor.js").Tensor3<number>, import("./tensor.js").Tensor3<number>>;
34
+ /**
35
+ * Same as {@link sub} for 4D tensors.
36
+ *
37
+ * @param out - output tensor
38
+ * @param a - input tensor
39
+ * @param n - scalar
40
+ */
41
+ export declare const sub4: import("./api.js").TensorOpTT<number, number, import("./tensor.js").Tensor4<number>, import("./tensor.js").Tensor4<number>>;
42
+ //# sourceMappingURL=sub.d.ts.map
package/sub.js ADDED
@@ -0,0 +1,15 @@
1
+ import { $sub } from "@thi.ng/vectors/ops";
2
+ import { defOpTT } from "./defoptt.js";
3
+ const [a, b, c, d, e] = defOpTT($sub);
4
+ const sub = a;
5
+ const sub1 = b;
6
+ const sub2 = c;
7
+ const sub3 = d;
8
+ const sub4 = e;
9
+ export {
10
+ sub,
11
+ sub1,
12
+ sub2,
13
+ sub3,
14
+ sub4
15
+ };