@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/defopttt.js
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { top } from "./top.js";
|
|
2
|
+
const defOpTTT = (fn, dispatch = 1) => {
|
|
3
|
+
const f1 = (out, a, b, c) => {
|
|
4
|
+
!out && (out = a);
|
|
5
|
+
const {
|
|
6
|
+
data: odata,
|
|
7
|
+
offset: oo,
|
|
8
|
+
stride: [txo]
|
|
9
|
+
} = out;
|
|
10
|
+
const {
|
|
11
|
+
data: adata,
|
|
12
|
+
offset: oa,
|
|
13
|
+
shape: [sx],
|
|
14
|
+
stride: [txa]
|
|
15
|
+
} = a;
|
|
16
|
+
const {
|
|
17
|
+
data: bdata,
|
|
18
|
+
offset: ob,
|
|
19
|
+
stride: [txb]
|
|
20
|
+
} = b;
|
|
21
|
+
const {
|
|
22
|
+
data: cdata,
|
|
23
|
+
offset: oc,
|
|
24
|
+
stride: [txc]
|
|
25
|
+
} = c;
|
|
26
|
+
for (let x = 0; x < sx; x++) {
|
|
27
|
+
odata[oo + x * txo] = fn(
|
|
28
|
+
adata[oa + x * txa],
|
|
29
|
+
bdata[ob + x * txb],
|
|
30
|
+
cdata[oc + x * txc]
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
};
|
|
35
|
+
const f2 = (out, a, b, c) => {
|
|
36
|
+
!out && (out = a);
|
|
37
|
+
const {
|
|
38
|
+
data: odata,
|
|
39
|
+
offset: oo,
|
|
40
|
+
stride: [txo, tyo]
|
|
41
|
+
} = out;
|
|
42
|
+
const {
|
|
43
|
+
data: adata,
|
|
44
|
+
offset: oa,
|
|
45
|
+
shape: [sx, sy],
|
|
46
|
+
stride: [txa, tya]
|
|
47
|
+
} = a;
|
|
48
|
+
const {
|
|
49
|
+
data: bdata,
|
|
50
|
+
offset: ob,
|
|
51
|
+
stride: [txb, tyb]
|
|
52
|
+
} = b;
|
|
53
|
+
const {
|
|
54
|
+
data: cdata,
|
|
55
|
+
offset: oc,
|
|
56
|
+
stride: [txc, tyc]
|
|
57
|
+
} = c;
|
|
58
|
+
for (let x = 0; x < sx; x++) {
|
|
59
|
+
const oox = oo + x * txo;
|
|
60
|
+
const oax = oa + x * txa;
|
|
61
|
+
const obx = ob + x * txb;
|
|
62
|
+
const ocx = oc + x * txc;
|
|
63
|
+
for (let y = 0; y < sy; y++) {
|
|
64
|
+
odata[oox + y * tyo] = fn(
|
|
65
|
+
adata[oax + y * tya],
|
|
66
|
+
bdata[obx + y * tyb],
|
|
67
|
+
cdata[ocx + y * tyc]
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return out;
|
|
72
|
+
};
|
|
73
|
+
const f3 = (out, a, b, c) => {
|
|
74
|
+
!out && (out = a);
|
|
75
|
+
const {
|
|
76
|
+
data: odata,
|
|
77
|
+
offset: oo,
|
|
78
|
+
stride: [txo, tyo, tzo]
|
|
79
|
+
} = out;
|
|
80
|
+
const {
|
|
81
|
+
data: adata,
|
|
82
|
+
offset: oa,
|
|
83
|
+
shape: [sx, sy, sz],
|
|
84
|
+
stride: [txa, tya, tza]
|
|
85
|
+
} = a;
|
|
86
|
+
const {
|
|
87
|
+
data: bdata,
|
|
88
|
+
offset: ob,
|
|
89
|
+
stride: [txb, tyb, tzb]
|
|
90
|
+
} = b;
|
|
91
|
+
const {
|
|
92
|
+
data: cdata,
|
|
93
|
+
offset: oc,
|
|
94
|
+
stride: [txc, tyc, tzc]
|
|
95
|
+
} = c;
|
|
96
|
+
for (let x = 0; x < sx; x++) {
|
|
97
|
+
const oox = oo + x * txo;
|
|
98
|
+
const oax = oa + x * txa;
|
|
99
|
+
const obx = ob + x * txb;
|
|
100
|
+
const ocx = oc + x * txc;
|
|
101
|
+
for (let y = 0; y < sy; y++) {
|
|
102
|
+
const ooy = oox + y * tyo;
|
|
103
|
+
const oay = oax + y * tya;
|
|
104
|
+
const oby = obx + y * tyb;
|
|
105
|
+
const ocy = ocx + y * tyc;
|
|
106
|
+
for (let z = 0; z < sz; z++) {
|
|
107
|
+
odata[ooy + z * tzo] = fn(
|
|
108
|
+
adata[oay + z * tza],
|
|
109
|
+
bdata[oby + z * tzb],
|
|
110
|
+
cdata[ocy + z * tzc]
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return out;
|
|
116
|
+
};
|
|
117
|
+
const f4 = (out, a, b, c) => {
|
|
118
|
+
!out && (out = a);
|
|
119
|
+
const {
|
|
120
|
+
data: odata,
|
|
121
|
+
offset: oo,
|
|
122
|
+
stride: [txo, tyo, tzo, two]
|
|
123
|
+
} = out;
|
|
124
|
+
const {
|
|
125
|
+
data: adata,
|
|
126
|
+
offset: oa,
|
|
127
|
+
shape: [sx, sy, sz, sw],
|
|
128
|
+
stride: [txa, tya, tza, twa]
|
|
129
|
+
} = a;
|
|
130
|
+
const {
|
|
131
|
+
data: bdata,
|
|
132
|
+
offset: ob,
|
|
133
|
+
stride: [txb, tyb, tzb, twb]
|
|
134
|
+
} = b;
|
|
135
|
+
const {
|
|
136
|
+
data: cdata,
|
|
137
|
+
offset: oc,
|
|
138
|
+
stride: [txc, tyc, tzc, twc]
|
|
139
|
+
} = c;
|
|
140
|
+
for (let x = 0; x < sx; x++) {
|
|
141
|
+
const oox = oo + x * txo;
|
|
142
|
+
const oax = oa + x * txa;
|
|
143
|
+
const obx = ob + x * txb;
|
|
144
|
+
const ocx = oc + x * txc;
|
|
145
|
+
for (let y = 0; y < sy; y++) {
|
|
146
|
+
const ooy = oox + y * tyo;
|
|
147
|
+
const oay = oax + y * tya;
|
|
148
|
+
const oby = obx + y * tyb;
|
|
149
|
+
const ocy = ocx + y * tyc;
|
|
150
|
+
for (let z = 0; z < sz; z++) {
|
|
151
|
+
const ooz = ooy + z * tzo;
|
|
152
|
+
const oaz = oay + z * tza;
|
|
153
|
+
const obz = oby + z * tzb;
|
|
154
|
+
const ocz = ocy + z * tzc;
|
|
155
|
+
for (let w = 0; w < sw; w++) {
|
|
156
|
+
odata[ooz + w * two] = fn(
|
|
157
|
+
adata[oaz + w * twa],
|
|
158
|
+
bdata[obz + w * twb],
|
|
159
|
+
cdata[ocz + w * twc]
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return out;
|
|
166
|
+
};
|
|
167
|
+
return [
|
|
168
|
+
top(dispatch, void 0, f1, f2, f3, f4),
|
|
169
|
+
f1,
|
|
170
|
+
f2,
|
|
171
|
+
f3,
|
|
172
|
+
f4
|
|
173
|
+
];
|
|
174
|
+
};
|
|
175
|
+
export {
|
|
176
|
+
defOpTTT
|
|
177
|
+
};
|
package/div.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Componentwise nD tensor division. Writes result to `out`. If `out` is null,
|
|
3
|
+
* mutates `a`. Multi-method.
|
|
4
|
+
*
|
|
5
|
+
* @param out - output tensor
|
|
6
|
+
* @param a - input tensor
|
|
7
|
+
* @param n - scalar
|
|
8
|
+
*/
|
|
9
|
+
export declare const div: import("./api.js").MultiTensorOpTT<number>;
|
|
10
|
+
/**
|
|
11
|
+
* Same as {@link div} for 1D tensors.
|
|
12
|
+
*
|
|
13
|
+
* @param out - output tensor
|
|
14
|
+
* @param a - input tensor
|
|
15
|
+
* @param n - scalar
|
|
16
|
+
*/
|
|
17
|
+
export declare const div1: import("./api.js").TensorOpTT<number, number, import("./tensor.js").Tensor1<number>, import("./tensor.js").Tensor1<number>>;
|
|
18
|
+
/**
|
|
19
|
+
* Same as {@link div} for 2D tensors.
|
|
20
|
+
*
|
|
21
|
+
* @param out - output tensor
|
|
22
|
+
* @param a - input tensor
|
|
23
|
+
* @param n - scalar
|
|
24
|
+
*/
|
|
25
|
+
export declare const div2: import("./api.js").TensorOpTT<number, number, import("./tensor.js").Tensor2<number>, import("./tensor.js").Tensor2<number>>;
|
|
26
|
+
/**
|
|
27
|
+
* Same as {@link div} for 3D tensors.
|
|
28
|
+
*
|
|
29
|
+
* @param out - output tensor
|
|
30
|
+
* @param a - input tensor
|
|
31
|
+
* @param n - scalar
|
|
32
|
+
*/
|
|
33
|
+
export declare const div3: import("./api.js").TensorOpTT<number, number, import("./tensor.js").Tensor3<number>, import("./tensor.js").Tensor3<number>>;
|
|
34
|
+
/**
|
|
35
|
+
* Same as {@link div} for 4D tensors.
|
|
36
|
+
*
|
|
37
|
+
* @param out - output tensor
|
|
38
|
+
* @param a - input tensor
|
|
39
|
+
* @param n - scalar
|
|
40
|
+
*/
|
|
41
|
+
export declare const div4: import("./api.js").TensorOpTT<number, number, import("./tensor.js").Tensor4<number>, import("./tensor.js").Tensor4<number>>;
|
|
42
|
+
//# sourceMappingURL=div.d.ts.map
|
package/div.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { $div } from "@thi.ng/vectors/ops";
|
|
2
|
+
import { defOpTT } from "./defoptt.js";
|
|
3
|
+
const [a, b, c, d, e] = defOpTT($div);
|
|
4
|
+
const div = a;
|
|
5
|
+
const div1 = b;
|
|
6
|
+
const div2 = c;
|
|
7
|
+
const div3 = d;
|
|
8
|
+
const div4 = e;
|
|
9
|
+
export {
|
|
10
|
+
div,
|
|
11
|
+
div1,
|
|
12
|
+
div2,
|
|
13
|
+
div3,
|
|
14
|
+
div4
|
|
15
|
+
};
|
package/divn.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Componentwise nD tensor division with uniform scalar `n`. Writes result to
|
|
3
|
+
* `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 divN: import("./api.js").MultiTensorOpTN<number>;
|
|
10
|
+
/**
|
|
11
|
+
* Same as {@link divN} for 1D tensors.
|
|
12
|
+
*
|
|
13
|
+
* @param out - output tensor
|
|
14
|
+
* @param a - input tensor
|
|
15
|
+
* @param n - scalar
|
|
16
|
+
*/
|
|
17
|
+
export declare const divN1: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor1<number>, import("./tensor.js").Tensor1<number>>;
|
|
18
|
+
/**
|
|
19
|
+
* Same as {@link divN} for 2D tensors.
|
|
20
|
+
*
|
|
21
|
+
* @param out - output tensor
|
|
22
|
+
* @param a - input tensor
|
|
23
|
+
* @param n - scalar
|
|
24
|
+
*/
|
|
25
|
+
export declare const divN2: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor2<number>, import("./tensor.js").Tensor2<number>>;
|
|
26
|
+
/**
|
|
27
|
+
* Same as {@link divN} for 3D tensors.
|
|
28
|
+
*
|
|
29
|
+
* @param out - output tensor
|
|
30
|
+
* @param a - input tensor
|
|
31
|
+
* @param n - scalar
|
|
32
|
+
*/
|
|
33
|
+
export declare const divN3: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor3<number>, import("./tensor.js").Tensor3<number>>;
|
|
34
|
+
/**
|
|
35
|
+
* Same as {@link divN} for 4D tensors.
|
|
36
|
+
*
|
|
37
|
+
* @param out - output tensor
|
|
38
|
+
* @param a - input tensor
|
|
39
|
+
* @param n - scalar
|
|
40
|
+
*/
|
|
41
|
+
export declare const divN4: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor4<number>, import("./tensor.js").Tensor4<number>>;
|
|
42
|
+
//# sourceMappingURL=divn.d.ts.map
|
package/divn.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { $div } from "@thi.ng/vectors/ops";
|
|
2
|
+
import { defOpTN } from "./defoptn.js";
|
|
3
|
+
const [a, b, c, d, e] = defOpTN($div);
|
|
4
|
+
const divN = a;
|
|
5
|
+
const divN1 = b;
|
|
6
|
+
const divN2 = c;
|
|
7
|
+
const divN3 = d;
|
|
8
|
+
const divN4 = e;
|
|
9
|
+
export {
|
|
10
|
+
divN,
|
|
11
|
+
divN1,
|
|
12
|
+
divN2,
|
|
13
|
+
divN3,
|
|
14
|
+
divN4
|
|
15
|
+
};
|
package/dot.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dot product of given nD tensor. Multi-method.
|
|
3
|
+
*
|
|
4
|
+
* @param a - input tensor
|
|
5
|
+
*/
|
|
6
|
+
export declare const dot: import("./api.js").MultiTensorOpRTT<number, number>;
|
|
7
|
+
/**
|
|
8
|
+
* Dot product of given 1D tensor.
|
|
9
|
+
*
|
|
10
|
+
* @param a - input tensor
|
|
11
|
+
*/
|
|
12
|
+
export declare const dot1: import("./api.js").TensorOpRTT<number, number, import("./tensor.js").Tensor1<number>>;
|
|
13
|
+
/**
|
|
14
|
+
* Dot product of given 2D tensor.
|
|
15
|
+
*
|
|
16
|
+
* @param a - input tensor
|
|
17
|
+
*/
|
|
18
|
+
export declare const dot2: import("./api.js").TensorOpRTT<number, number, import("./tensor.js").Tensor2<number>>;
|
|
19
|
+
/**
|
|
20
|
+
* Dot product of given 3D tensor.
|
|
21
|
+
*
|
|
22
|
+
* @param a - input tensor
|
|
23
|
+
*/
|
|
24
|
+
export declare const dot3: import("./api.js").TensorOpRTT<number, number, import("./tensor.js").Tensor3<number>>;
|
|
25
|
+
/**
|
|
26
|
+
* Dot product of given 3D tensor.
|
|
27
|
+
*
|
|
28
|
+
* @param a - input tensor
|
|
29
|
+
*/
|
|
30
|
+
export declare const dot4: import("./api.js").TensorOpRTT<number, number, import("./tensor.js").Tensor4<number>>;
|
|
31
|
+
//# sourceMappingURL=dot.d.ts.map
|
package/dot.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defOpRTT } from "./defoprtt.js";
|
|
2
|
+
const [a, b, c, d, e] = defOpRTT(
|
|
3
|
+
(acc, x, y) => acc + x * y,
|
|
4
|
+
() => 0
|
|
5
|
+
);
|
|
6
|
+
const dot = a;
|
|
7
|
+
const dot1 = b;
|
|
8
|
+
const dot2 = c;
|
|
9
|
+
const dot3 = d;
|
|
10
|
+
const dot4 = e;
|
|
11
|
+
export {
|
|
12
|
+
dot,
|
|
13
|
+
dot1,
|
|
14
|
+
dot2,
|
|
15
|
+
dot3,
|
|
16
|
+
dot4
|
|
17
|
+
};
|
package/errors.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { NumericArray } from "@thi.ng/api";
|
|
2
|
+
export declare const IllegalShapeError: {
|
|
3
|
+
new (msg?: NumericArray | undefined): {
|
|
4
|
+
origMessage: string;
|
|
5
|
+
name: string;
|
|
6
|
+
message: string;
|
|
7
|
+
stack?: string;
|
|
8
|
+
cause?: unknown;
|
|
9
|
+
};
|
|
10
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
11
|
+
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
12
|
+
stackTraceLimit: number;
|
|
13
|
+
};
|
|
14
|
+
export declare const illegalShape: (shape: NumericArray) => never;
|
|
15
|
+
//# sourceMappingURL=errors.d.ts.map
|
package/errors.js
ADDED
package/exp.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Componentwise computes `Math.exp` 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 exp: import("./api.js").MultiTensorOpT<number>;
|
|
9
|
+
/**
|
|
10
|
+
* Same as {@link exp} for 1D tensors.
|
|
11
|
+
*
|
|
12
|
+
* @param out - output tensor
|
|
13
|
+
* @param a - input tensor
|
|
14
|
+
*/
|
|
15
|
+
export declare const exp_1: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor1<number>, import("./tensor.js").Tensor1<number>>;
|
|
16
|
+
/**
|
|
17
|
+
* Same as {@link exp} for 2D tensors.
|
|
18
|
+
*
|
|
19
|
+
* @param out - output tensor
|
|
20
|
+
* @param a - input tensor
|
|
21
|
+
*/
|
|
22
|
+
export declare const exp_2: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor2<number>, import("./tensor.js").Tensor2<number>>;
|
|
23
|
+
/**
|
|
24
|
+
* Same as {@link exp} for 3D tensors.
|
|
25
|
+
*
|
|
26
|
+
* @param out - output tensor
|
|
27
|
+
* @param a - input tensor
|
|
28
|
+
*/
|
|
29
|
+
export declare const exp_3: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor3<number>, import("./tensor.js").Tensor3<number>>;
|
|
30
|
+
/**
|
|
31
|
+
* Same as {@link exp} for 4D tensors.
|
|
32
|
+
*
|
|
33
|
+
* @param out - output tensor
|
|
34
|
+
* @param a - input tensor
|
|
35
|
+
*/
|
|
36
|
+
export declare const exp_4: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor4<number>, import("./tensor.js").Tensor4<number>>;
|
|
37
|
+
//# sourceMappingURL=exp.d.ts.map
|
package/exp.js
ADDED
package/exp2.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Componentwise computes `2^x` 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 exp2: import("./api.js").MultiTensorOpT<number>;
|
|
9
|
+
/**
|
|
10
|
+
* Same as {@link exp2} for 1D tensors.
|
|
11
|
+
*
|
|
12
|
+
* @param out - output tensor
|
|
13
|
+
* @param a - input tensor
|
|
14
|
+
*/
|
|
15
|
+
export declare const exp2_1: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor1<number>, import("./tensor.js").Tensor1<number>>;
|
|
16
|
+
/**
|
|
17
|
+
* Same as {@link exp2} for 2D tensors.
|
|
18
|
+
*
|
|
19
|
+
* @param out - output tensor
|
|
20
|
+
* @param a - input tensor
|
|
21
|
+
*/
|
|
22
|
+
export declare const exp2_2: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor2<number>, import("./tensor.js").Tensor2<number>>;
|
|
23
|
+
/**
|
|
24
|
+
* Same as {@link exp2} for 3D tensors.
|
|
25
|
+
*
|
|
26
|
+
* @param out - output tensor
|
|
27
|
+
* @param a - input tensor
|
|
28
|
+
*/
|
|
29
|
+
export declare const exp2_3: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor3<number>, import("./tensor.js").Tensor3<number>>;
|
|
30
|
+
/**
|
|
31
|
+
* Same as {@link exp2} for 4D tensors.
|
|
32
|
+
*
|
|
33
|
+
* @param out - output tensor
|
|
34
|
+
* @param a - input tensor
|
|
35
|
+
*/
|
|
36
|
+
export declare const exp2_4: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor4<number>, import("./tensor.js").Tensor4<number>>;
|
|
37
|
+
//# sourceMappingURL=exp2.d.ts.map
|
package/exp2.js
ADDED
package/format.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ITensor } from "./api.js";
|
|
2
|
+
export declare const format: (x: any) => string;
|
|
3
|
+
export declare const setFormat: (width: number, prec: number) => void;
|
|
4
|
+
export declare const debug: ({ data, shape, stride, offset }: ITensor<any>) => void;
|
|
5
|
+
/**
|
|
6
|
+
* Syntax sugar for: `console.log(a.toString())`.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Also see {@link debug} and {@link setFormat}.
|
|
10
|
+
*
|
|
11
|
+
* @param a - tensor
|
|
12
|
+
*/
|
|
13
|
+
export declare const print: (a: ITensor<any>) => void;
|
|
14
|
+
//# sourceMappingURL=format.d.ts.map
|
package/format.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { isNumber } from "@thi.ng/checks/is-number";
|
|
2
|
+
import { floatFixedWidth } from "@thi.ng/strings/float";
|
|
3
|
+
import { padLeft } from "@thi.ng/strings/pad-left";
|
|
4
|
+
import { truncate } from "@thi.ng/strings/truncate";
|
|
5
|
+
import { dot } from "@thi.ng/vectors/dot";
|
|
6
|
+
let formatNumber;
|
|
7
|
+
let pad;
|
|
8
|
+
let trunc;
|
|
9
|
+
const format = (x) => isNumber(x) ? formatNumber(x) : trunc(pad(x.toString()));
|
|
10
|
+
const setFormat = (width, prec) => {
|
|
11
|
+
formatNumber = floatFixedWidth(width, prec);
|
|
12
|
+
pad = padLeft(width);
|
|
13
|
+
trunc = truncate(width);
|
|
14
|
+
};
|
|
15
|
+
setFormat(9, 4);
|
|
16
|
+
const debug = ({ data, shape, stride, offset }) => {
|
|
17
|
+
let dim = shape.length;
|
|
18
|
+
const state = new Array(dim).fill(0);
|
|
19
|
+
dim--;
|
|
20
|
+
while (true) {
|
|
21
|
+
const idx = dot(state, stride) + offset;
|
|
22
|
+
console.log(state, idx, data[idx]);
|
|
23
|
+
if (++state[dim] >= shape[dim]) {
|
|
24
|
+
for (; dim-- > 0; ) if (++state[dim] < shape[dim]) break;
|
|
25
|
+
if (state[0] >= shape[0]) return;
|
|
26
|
+
state.fill(0, dim + 1);
|
|
27
|
+
dim = shape.length - 1;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const print = (a) => console.log(a.toString(), "\n");
|
|
32
|
+
export {
|
|
33
|
+
debug,
|
|
34
|
+
format,
|
|
35
|
+
print,
|
|
36
|
+
setFormat
|
|
37
|
+
};
|
package/identity.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { TensorOpts, Type } from "./api.js";
|
|
2
|
+
import { Tensor2 } from "./tensor.js";
|
|
3
|
+
export declare const identity: <T extends Exclude<Type, "str">>(type: T, size: number, opts?: Pick<TensorOpts<any, any>, "storage">) => Tensor2<number>;
|
|
4
|
+
//# sourceMappingURL=identity.d.ts.map
|
package/identity.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { STORAGE } from "./storage.js";
|
|
2
|
+
import { Tensor2 } from "./tensor.js";
|
|
3
|
+
const identity = (type, size, opts) => {
|
|
4
|
+
const storage = opts?.storage || STORAGE[type];
|
|
5
|
+
const data = storage.alloc(size * size);
|
|
6
|
+
for (let i = 0; i < data.length; i += size + 1) data[i] = 1;
|
|
7
|
+
return new Tensor2(type, storage, data, [size, size], [size, 1]);
|
|
8
|
+
};
|
|
9
|
+
export {
|
|
10
|
+
identity
|
|
11
|
+
};
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export * from "./abs.js";
|
|
2
|
+
export * from "./add.js";
|
|
3
|
+
export * from "./addn.js";
|
|
4
|
+
export * from "./api.js";
|
|
5
|
+
export * from "./clamp.js";
|
|
6
|
+
export * from "./clampn.js";
|
|
7
|
+
export * from "./cos.js";
|
|
8
|
+
export * from "./defopn.js";
|
|
9
|
+
export * from "./defoprt.js";
|
|
10
|
+
export * from "./defoprtt.js";
|
|
11
|
+
export * from "./defopt.js";
|
|
12
|
+
export * from "./defoptn.js";
|
|
13
|
+
export * from "./defoptnn.js";
|
|
14
|
+
export * from "./defoptt.js";
|
|
15
|
+
export * from "./defopttt.js";
|
|
16
|
+
export * from "./div.js";
|
|
17
|
+
export * from "./divn.js";
|
|
18
|
+
export * from "./dot.js";
|
|
19
|
+
export * from "./errors.js";
|
|
20
|
+
export * from "./exp.js";
|
|
21
|
+
export * from "./exp2.js";
|
|
22
|
+
export * from "./format.js";
|
|
23
|
+
export * from "./identity.js";
|
|
24
|
+
export * from "./log.js";
|
|
25
|
+
export * from "./log2.js";
|
|
26
|
+
export * from "./mag.js";
|
|
27
|
+
export * from "./magsq.js";
|
|
28
|
+
export * from "./max.js";
|
|
29
|
+
export * from "./maxn.js";
|
|
30
|
+
export * from "./min.js";
|
|
31
|
+
export * from "./minn.js";
|
|
32
|
+
export * from "./mul.js";
|
|
33
|
+
export * from "./mulm.js";
|
|
34
|
+
export * from "./muln.js";
|
|
35
|
+
export * from "./mulv.js";
|
|
36
|
+
export * from "./normalize.js";
|
|
37
|
+
export * from "./pow.js";
|
|
38
|
+
export * from "./pown.js";
|
|
39
|
+
export * from "./product.js";
|
|
40
|
+
export * from "./rand-distrib.js";
|
|
41
|
+
export * from "./relu.js";
|
|
42
|
+
export * from "./relun.js";
|
|
43
|
+
export * from "./select.js";
|
|
44
|
+
export * from "./set.js";
|
|
45
|
+
export * from "./setn.js";
|
|
46
|
+
export * from "./sigmoid.js";
|
|
47
|
+
export * from "./sin.js";
|
|
48
|
+
export * from "./softmax.js";
|
|
49
|
+
export * from "./softplus.js";
|
|
50
|
+
export * from "./sqrt.js";
|
|
51
|
+
export * from "./step.js";
|
|
52
|
+
export * from "./storage.js";
|
|
53
|
+
export * from "./sub.js";
|
|
54
|
+
export * from "./subn.js";
|
|
55
|
+
export * from "./sum.js";
|
|
56
|
+
export * from "./tan.js";
|
|
57
|
+
export * from "./tanh.js";
|
|
58
|
+
export * from "./tensor.js";
|
|
59
|
+
export * from "./top.js";
|
|
60
|
+
//# sourceMappingURL=index.d.ts.map
|
package/index.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export * from "./abs.js";
|
|
2
|
+
export * from "./add.js";
|
|
3
|
+
export * from "./addn.js";
|
|
4
|
+
export * from "./api.js";
|
|
5
|
+
export * from "./clamp.js";
|
|
6
|
+
export * from "./clampn.js";
|
|
7
|
+
export * from "./cos.js";
|
|
8
|
+
export * from "./defopn.js";
|
|
9
|
+
export * from "./defoprt.js";
|
|
10
|
+
export * from "./defoprtt.js";
|
|
11
|
+
export * from "./defopt.js";
|
|
12
|
+
export * from "./defoptn.js";
|
|
13
|
+
export * from "./defoptnn.js";
|
|
14
|
+
export * from "./defoptt.js";
|
|
15
|
+
export * from "./defopttt.js";
|
|
16
|
+
export * from "./div.js";
|
|
17
|
+
export * from "./divn.js";
|
|
18
|
+
export * from "./dot.js";
|
|
19
|
+
export * from "./errors.js";
|
|
20
|
+
export * from "./exp.js";
|
|
21
|
+
export * from "./exp2.js";
|
|
22
|
+
export * from "./format.js";
|
|
23
|
+
export * from "./identity.js";
|
|
24
|
+
export * from "./log.js";
|
|
25
|
+
export * from "./log2.js";
|
|
26
|
+
export * from "./mag.js";
|
|
27
|
+
export * from "./magsq.js";
|
|
28
|
+
export * from "./max.js";
|
|
29
|
+
export * from "./maxn.js";
|
|
30
|
+
export * from "./min.js";
|
|
31
|
+
export * from "./minn.js";
|
|
32
|
+
export * from "./mul.js";
|
|
33
|
+
export * from "./mulm.js";
|
|
34
|
+
export * from "./muln.js";
|
|
35
|
+
export * from "./mulv.js";
|
|
36
|
+
export * from "./normalize.js";
|
|
37
|
+
export * from "./pow.js";
|
|
38
|
+
export * from "./pown.js";
|
|
39
|
+
export * from "./product.js";
|
|
40
|
+
export * from "./rand-distrib.js";
|
|
41
|
+
export * from "./relu.js";
|
|
42
|
+
export * from "./relun.js";
|
|
43
|
+
export * from "./select.js";
|
|
44
|
+
export * from "./set.js";
|
|
45
|
+
export * from "./setn.js";
|
|
46
|
+
export * from "./sigmoid.js";
|
|
47
|
+
export * from "./sin.js";
|
|
48
|
+
export * from "./softmax.js";
|
|
49
|
+
export * from "./softplus.js";
|
|
50
|
+
export * from "./sqrt.js";
|
|
51
|
+
export * from "./step.js";
|
|
52
|
+
export * from "./storage.js";
|
|
53
|
+
export * from "./sub.js";
|
|
54
|
+
export * from "./subn.js";
|
|
55
|
+
export * from "./sum.js";
|
|
56
|
+
export * from "./tan.js";
|
|
57
|
+
export * from "./tanh.js";
|
|
58
|
+
export * from "./tensor.js";
|
|
59
|
+
export * from "./top.js";
|