@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/package.json
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@thi.ng/tensors",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "1D/2D/3D/4D tensors with extensible polymorphic operations and customizable storage",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"module": "./index.js",
|
|
7
|
+
"typings": "./index.d.ts",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/thi-ng/umbrella.git"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://thi.ng/tensors",
|
|
14
|
+
"funding": [
|
|
15
|
+
{
|
|
16
|
+
"type": "github",
|
|
17
|
+
"url": "https://github.com/sponsors/postspectacular"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"type": "patreon",
|
|
21
|
+
"url": "https://patreon.com/thing_umbrella"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"type": "liberapay",
|
|
25
|
+
"url": "https://liberapay.com/thi.ng"
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"author": "Karsten Schmidt (https://thi.ng)",
|
|
29
|
+
"license": "Apache-2.0",
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "yarn build:esbuild && yarn build:decl",
|
|
32
|
+
"build:decl": "tsc --declaration --emitDeclarationOnly",
|
|
33
|
+
"build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
|
|
34
|
+
"clean": "bun ../../tools/src/clean-package.ts",
|
|
35
|
+
"doc": "typedoc --options ../../typedoc.json --out doc src/index.ts",
|
|
36
|
+
"doc:readme": "bun ../../tools/src/module-stats.ts && bun ../../tools/src/readme.ts",
|
|
37
|
+
"pub": "yarn npm publish --access public",
|
|
38
|
+
"test": "bun test",
|
|
39
|
+
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@thi.ng/api": "^8.11.27",
|
|
43
|
+
"@thi.ng/arrays": "^2.11.0",
|
|
44
|
+
"@thi.ng/checks": "^3.7.7",
|
|
45
|
+
"@thi.ng/equiv": "^2.1.83",
|
|
46
|
+
"@thi.ng/errors": "^2.5.33",
|
|
47
|
+
"@thi.ng/math": "^5.11.27",
|
|
48
|
+
"@thi.ng/random": "^4.1.18",
|
|
49
|
+
"@thi.ng/strings": "^3.9.12",
|
|
50
|
+
"@thi.ng/vectors": "^8.1.0"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"esbuild": "^0.25.3",
|
|
54
|
+
"typedoc": "^0.28.3",
|
|
55
|
+
"typescript": "^5.8.3"
|
|
56
|
+
},
|
|
57
|
+
"keywords": [
|
|
58
|
+
"typescript"
|
|
59
|
+
],
|
|
60
|
+
"publishConfig": {
|
|
61
|
+
"access": "public"
|
|
62
|
+
},
|
|
63
|
+
"browser": {
|
|
64
|
+
"process": false,
|
|
65
|
+
"setTimeout": false
|
|
66
|
+
},
|
|
67
|
+
"engines": {
|
|
68
|
+
"node": ">=18"
|
|
69
|
+
},
|
|
70
|
+
"files": [
|
|
71
|
+
"./*.js",
|
|
72
|
+
"./*.d.ts"
|
|
73
|
+
],
|
|
74
|
+
"exports": {
|
|
75
|
+
".": {
|
|
76
|
+
"default": "./index.js"
|
|
77
|
+
},
|
|
78
|
+
"./abs": {
|
|
79
|
+
"default": "./abs.js"
|
|
80
|
+
},
|
|
81
|
+
"./add": {
|
|
82
|
+
"default": "./add.js"
|
|
83
|
+
},
|
|
84
|
+
"./addn": {
|
|
85
|
+
"default": "./addn.js"
|
|
86
|
+
},
|
|
87
|
+
"./api": {
|
|
88
|
+
"default": "./api.js"
|
|
89
|
+
},
|
|
90
|
+
"./clamp": {
|
|
91
|
+
"default": "./clamp.js"
|
|
92
|
+
},
|
|
93
|
+
"./clampn": {
|
|
94
|
+
"default": "./clampn.js"
|
|
95
|
+
},
|
|
96
|
+
"./cos": {
|
|
97
|
+
"default": "./cos.js"
|
|
98
|
+
},
|
|
99
|
+
"./defopn": {
|
|
100
|
+
"default": "./defopn.js"
|
|
101
|
+
},
|
|
102
|
+
"./defoprt": {
|
|
103
|
+
"default": "./defoprt.js"
|
|
104
|
+
},
|
|
105
|
+
"./defoprtt": {
|
|
106
|
+
"default": "./defoprtt.js"
|
|
107
|
+
},
|
|
108
|
+
"./defopt": {
|
|
109
|
+
"default": "./defopt.js"
|
|
110
|
+
},
|
|
111
|
+
"./defoptn": {
|
|
112
|
+
"default": "./defoptn.js"
|
|
113
|
+
},
|
|
114
|
+
"./defoptnn": {
|
|
115
|
+
"default": "./defoptnn.js"
|
|
116
|
+
},
|
|
117
|
+
"./defoptt": {
|
|
118
|
+
"default": "./defoptt.js"
|
|
119
|
+
},
|
|
120
|
+
"./defopttt": {
|
|
121
|
+
"default": "./defopttt.js"
|
|
122
|
+
},
|
|
123
|
+
"./div": {
|
|
124
|
+
"default": "./div.js"
|
|
125
|
+
},
|
|
126
|
+
"./divn": {
|
|
127
|
+
"default": "./divn.js"
|
|
128
|
+
},
|
|
129
|
+
"./dot": {
|
|
130
|
+
"default": "./dot.js"
|
|
131
|
+
},
|
|
132
|
+
"./errors": {
|
|
133
|
+
"default": "./errors.js"
|
|
134
|
+
},
|
|
135
|
+
"./exp": {
|
|
136
|
+
"default": "./exp.js"
|
|
137
|
+
},
|
|
138
|
+
"./exp2": {
|
|
139
|
+
"default": "./exp2.js"
|
|
140
|
+
},
|
|
141
|
+
"./format": {
|
|
142
|
+
"default": "./format.js"
|
|
143
|
+
},
|
|
144
|
+
"./identity": {
|
|
145
|
+
"default": "./identity.js"
|
|
146
|
+
},
|
|
147
|
+
"./log": {
|
|
148
|
+
"default": "./log.js"
|
|
149
|
+
},
|
|
150
|
+
"./log2": {
|
|
151
|
+
"default": "./log2.js"
|
|
152
|
+
},
|
|
153
|
+
"./mag": {
|
|
154
|
+
"default": "./mag.js"
|
|
155
|
+
},
|
|
156
|
+
"./magsq": {
|
|
157
|
+
"default": "./magsq.js"
|
|
158
|
+
},
|
|
159
|
+
"./max": {
|
|
160
|
+
"default": "./max.js"
|
|
161
|
+
},
|
|
162
|
+
"./maxn": {
|
|
163
|
+
"default": "./maxn.js"
|
|
164
|
+
},
|
|
165
|
+
"./min": {
|
|
166
|
+
"default": "./min.js"
|
|
167
|
+
},
|
|
168
|
+
"./minn": {
|
|
169
|
+
"default": "./minn.js"
|
|
170
|
+
},
|
|
171
|
+
"./mul": {
|
|
172
|
+
"default": "./mul.js"
|
|
173
|
+
},
|
|
174
|
+
"./mulm": {
|
|
175
|
+
"default": "./mulm.js"
|
|
176
|
+
},
|
|
177
|
+
"./muln": {
|
|
178
|
+
"default": "./muln.js"
|
|
179
|
+
},
|
|
180
|
+
"./mulv": {
|
|
181
|
+
"default": "./mulv.js"
|
|
182
|
+
},
|
|
183
|
+
"./normalize": {
|
|
184
|
+
"default": "./normalize.js"
|
|
185
|
+
},
|
|
186
|
+
"./pow": {
|
|
187
|
+
"default": "./pow.js"
|
|
188
|
+
},
|
|
189
|
+
"./pown": {
|
|
190
|
+
"default": "./pown.js"
|
|
191
|
+
},
|
|
192
|
+
"./product": {
|
|
193
|
+
"default": "./product.js"
|
|
194
|
+
},
|
|
195
|
+
"./rand-distrib": {
|
|
196
|
+
"default": "./rand-distrib.js"
|
|
197
|
+
},
|
|
198
|
+
"./relu": {
|
|
199
|
+
"default": "./relu.js"
|
|
200
|
+
},
|
|
201
|
+
"./relun": {
|
|
202
|
+
"default": "./relun.js"
|
|
203
|
+
},
|
|
204
|
+
"./select": {
|
|
205
|
+
"default": "./select.js"
|
|
206
|
+
},
|
|
207
|
+
"./set": {
|
|
208
|
+
"default": "./set.js"
|
|
209
|
+
},
|
|
210
|
+
"./setn": {
|
|
211
|
+
"default": "./setn.js"
|
|
212
|
+
},
|
|
213
|
+
"./sigmoid": {
|
|
214
|
+
"default": "./sigmoid.js"
|
|
215
|
+
},
|
|
216
|
+
"./sin": {
|
|
217
|
+
"default": "./sin.js"
|
|
218
|
+
},
|
|
219
|
+
"./softmax": {
|
|
220
|
+
"default": "./softmax.js"
|
|
221
|
+
},
|
|
222
|
+
"./softplus": {
|
|
223
|
+
"default": "./softplus.js"
|
|
224
|
+
},
|
|
225
|
+
"./sqrt": {
|
|
226
|
+
"default": "./sqrt.js"
|
|
227
|
+
},
|
|
228
|
+
"./step": {
|
|
229
|
+
"default": "./step.js"
|
|
230
|
+
},
|
|
231
|
+
"./storage": {
|
|
232
|
+
"default": "./storage.js"
|
|
233
|
+
},
|
|
234
|
+
"./sub": {
|
|
235
|
+
"default": "./sub.js"
|
|
236
|
+
},
|
|
237
|
+
"./subn": {
|
|
238
|
+
"default": "./subn.js"
|
|
239
|
+
},
|
|
240
|
+
"./sum": {
|
|
241
|
+
"default": "./sum.js"
|
|
242
|
+
},
|
|
243
|
+
"./tan": {
|
|
244
|
+
"default": "./tan.js"
|
|
245
|
+
},
|
|
246
|
+
"./tanh": {
|
|
247
|
+
"default": "./tanh.js"
|
|
248
|
+
},
|
|
249
|
+
"./tensor": {
|
|
250
|
+
"default": "./tensor.js"
|
|
251
|
+
},
|
|
252
|
+
"./top": {
|
|
253
|
+
"default": "./top.js"
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
"thi.ng": {
|
|
257
|
+
"status": "alpha",
|
|
258
|
+
"year": 2018
|
|
259
|
+
},
|
|
260
|
+
"gitHead": "4354686a6fb1f82c09ea48f92f87786191b231a0\n"
|
|
261
|
+
}
|
package/pow.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Componentwise computes `Math.pow` 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 pow: import("./api.js").MultiTensorOpTT<number>;
|
|
9
|
+
/**
|
|
10
|
+
* Same as {@link pow} for 1D tensors.
|
|
11
|
+
*
|
|
12
|
+
* @param out - output tensor
|
|
13
|
+
* @param a - input tensor
|
|
14
|
+
*/
|
|
15
|
+
export declare const pow1: import("./api.js").TensorOpTT<number, number, import("./tensor.js").Tensor1<number>, import("./tensor.js").Tensor1<number>>;
|
|
16
|
+
/**
|
|
17
|
+
* Same as {@link pow} for 2D tensors.
|
|
18
|
+
*
|
|
19
|
+
* @param out - output tensor
|
|
20
|
+
* @param a - input tensor
|
|
21
|
+
*/
|
|
22
|
+
export declare const pow2: import("./api.js").TensorOpTT<number, number, import("./tensor.js").Tensor2<number>, import("./tensor.js").Tensor2<number>>;
|
|
23
|
+
/**
|
|
24
|
+
* Same as {@link pow} for 3D tensors.
|
|
25
|
+
*
|
|
26
|
+
* @param out - output tensor
|
|
27
|
+
* @param a - input tensor
|
|
28
|
+
*/
|
|
29
|
+
export declare const pow3: import("./api.js").TensorOpTT<number, number, import("./tensor.js").Tensor3<number>, import("./tensor.js").Tensor3<number>>;
|
|
30
|
+
/**
|
|
31
|
+
* Same as {@link pow} for 4D tensors.
|
|
32
|
+
*
|
|
33
|
+
* @param out - output tensor
|
|
34
|
+
* @param a - input tensor
|
|
35
|
+
*/
|
|
36
|
+
export declare const pow4: import("./api.js").TensorOpTT<number, number, import("./tensor.js").Tensor4<number>, import("./tensor.js").Tensor4<number>>;
|
|
37
|
+
//# sourceMappingURL=pow.d.ts.map
|
package/pow.js
ADDED
package/pown.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Componentwise computes `Math.pow` of given nD tensor and uniform scalar `n`.
|
|
3
|
+
* Writes result 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 exponent
|
|
8
|
+
*/
|
|
9
|
+
export declare const powN: import("./api.js").MultiTensorOpTN<number>;
|
|
10
|
+
/**
|
|
11
|
+
* Same as {@link powN} for 1D tensors.
|
|
12
|
+
*
|
|
13
|
+
* @param out - output tensor
|
|
14
|
+
* @param a - input tensor
|
|
15
|
+
* @param n - scalar exponent
|
|
16
|
+
*/
|
|
17
|
+
export declare const powN1: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor1<number>, import("./tensor.js").Tensor1<number>>;
|
|
18
|
+
/**
|
|
19
|
+
* Same as {@link powN} for 2D tensors.
|
|
20
|
+
*
|
|
21
|
+
* @param out - output tensor
|
|
22
|
+
* @param a - input tensor
|
|
23
|
+
* @param n - scalar exponent
|
|
24
|
+
*/
|
|
25
|
+
export declare const powN2: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor2<number>, import("./tensor.js").Tensor2<number>>;
|
|
26
|
+
/**
|
|
27
|
+
* Same as {@link powN} for 3D tensors.
|
|
28
|
+
*
|
|
29
|
+
* @param out - output tensor
|
|
30
|
+
* @param a - input tensor
|
|
31
|
+
* @param n - scalar exponent
|
|
32
|
+
*/
|
|
33
|
+
export declare const powN3: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor3<number>, import("./tensor.js").Tensor3<number>>;
|
|
34
|
+
/**
|
|
35
|
+
* Same as {@link powN} for 4D tensors.
|
|
36
|
+
*
|
|
37
|
+
* @param out - output tensor
|
|
38
|
+
* @param a - input tensor
|
|
39
|
+
* @param n - scalar exponent
|
|
40
|
+
*/
|
|
41
|
+
export declare const powN4: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor4<number>, import("./tensor.js").Tensor4<number>>;
|
|
42
|
+
//# sourceMappingURL=pown.d.ts.map
|
package/pown.js
ADDED
package/product.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Componentwise product of given nD tensor. Multi-method.
|
|
3
|
+
*
|
|
4
|
+
* @param a - input tensor
|
|
5
|
+
*/
|
|
6
|
+
export declare const product: import("./api.js").MultiTensorOpRT<number, number>;
|
|
7
|
+
/**
|
|
8
|
+
* Componentwise product of given 1D tensor.
|
|
9
|
+
*
|
|
10
|
+
* @param a - input tensor
|
|
11
|
+
*/
|
|
12
|
+
export declare const product1: import("./api.js").TensorOpRT<number, number, import("./tensor.js").Tensor1<number>>;
|
|
13
|
+
/**
|
|
14
|
+
* Componentwise product of given 2D tensor.
|
|
15
|
+
*
|
|
16
|
+
* @param a - input tensor
|
|
17
|
+
*/
|
|
18
|
+
export declare const product2: import("./api.js").TensorOpRT<number, number, import("./tensor.js").Tensor2<number>>;
|
|
19
|
+
/**
|
|
20
|
+
* Componentwise product of given 3D tensor.
|
|
21
|
+
*
|
|
22
|
+
* @param a - input tensor
|
|
23
|
+
*/
|
|
24
|
+
export declare const product3: import("./api.js").TensorOpRT<number, number, import("./tensor.js").Tensor3<number>>;
|
|
25
|
+
/**
|
|
26
|
+
* Componentwise product of given 4D tensor.
|
|
27
|
+
*
|
|
28
|
+
* @param a - input tensor
|
|
29
|
+
*/
|
|
30
|
+
export declare const product4: import("./api.js").TensorOpRT<number, number, import("./tensor.js").Tensor4<number>>;
|
|
31
|
+
//# sourceMappingURL=product.d.ts.map
|
package/product.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { $mul } from "@thi.ng/vectors/ops";
|
|
2
|
+
import { defOpRT } from "./defoprt.js";
|
|
3
|
+
const [a, b, c, d, e] = defOpRT($mul, () => 1);
|
|
4
|
+
const product = a;
|
|
5
|
+
const product1 = b;
|
|
6
|
+
const product2 = c;
|
|
7
|
+
const product3 = d;
|
|
8
|
+
const product4 = e;
|
|
9
|
+
export {
|
|
10
|
+
product,
|
|
11
|
+
product1,
|
|
12
|
+
product2,
|
|
13
|
+
product3,
|
|
14
|
+
product4
|
|
15
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Fn0 } from "@thi.ng/api";
|
|
2
|
+
import type { ITensor } from "./api.js";
|
|
3
|
+
import type { Tensor1, Tensor2, Tensor3 } from "./tensor.js";
|
|
4
|
+
/**
|
|
5
|
+
* Same as {@link randDistrib}, optimized for 1D tensors.
|
|
6
|
+
*
|
|
7
|
+
* @param a
|
|
8
|
+
* @param rnd
|
|
9
|
+
* @param n
|
|
10
|
+
*/
|
|
11
|
+
export declare const randDistrib1: (a: Tensor1, rnd?: () => number, n?: number) => Tensor1<number>;
|
|
12
|
+
/**
|
|
13
|
+
* Same as {@link randDistrib}, optimized for 2D tensors.
|
|
14
|
+
*
|
|
15
|
+
* @param a
|
|
16
|
+
* @param rnd
|
|
17
|
+
* @param n
|
|
18
|
+
*/
|
|
19
|
+
export declare const randDistrib2: (a: Tensor2, rnd?: () => number, n?: number) => Tensor2<number>;
|
|
20
|
+
/**
|
|
21
|
+
* Same as {@link randDistrib}, optimized for 3D tensors.
|
|
22
|
+
*
|
|
23
|
+
* @param a
|
|
24
|
+
* @param rnd
|
|
25
|
+
* @param n
|
|
26
|
+
*/
|
|
27
|
+
export declare const randDistrib3: (a: Tensor3, rnd?: () => number, n?: number) => Tensor3<number>;
|
|
28
|
+
/**
|
|
29
|
+
* Randomizes given nD tensor `a`, with each component drawn from given random
|
|
30
|
+
* distribution function (default: gaussian/normal distribution) and scaled to
|
|
31
|
+
* `n` (default: 1).
|
|
32
|
+
*
|
|
33
|
+
* @remarks
|
|
34
|
+
* References:
|
|
35
|
+
*
|
|
36
|
+
* - https://docs.thi.ng/umbrella/random/#random-distributions
|
|
37
|
+
* - https://docs.thi.ng/umbrella/random/functions/normal.html
|
|
38
|
+
*
|
|
39
|
+
* @param a - tensor
|
|
40
|
+
* @param rnd - random distribution function
|
|
41
|
+
* @param n - scale factor
|
|
42
|
+
*/
|
|
43
|
+
export declare const randDistrib: {
|
|
44
|
+
(...args: any[]): any;
|
|
45
|
+
add(dim: number, fn: (a: ITensor, rnd?: Fn0<number>, n?: number) => ITensor): (a: ITensor, rnd?: Fn0<number>, n?: number) => ITensor;
|
|
46
|
+
default(fn: (a: ITensor, rnd?: Fn0<number>, n?: number) => ITensor): (a: ITensor, rnd?: Fn0<number>, n?: number) => ITensor;
|
|
47
|
+
impl(dim?: number): import("@thi.ng/api").Maybe<(a: ITensor, rnd?: Fn0<number>, n?: number) => ITensor>;
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=rand-distrib.d.ts.map
|
package/rand-distrib.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { normal as op } from "@thi.ng/random/distributions/normal";
|
|
2
|
+
import { top } from "./top.js";
|
|
3
|
+
const randDistrib1 = (a, rnd = op(), n = 1) => {
|
|
4
|
+
const {
|
|
5
|
+
data,
|
|
6
|
+
offset,
|
|
7
|
+
shape: [l],
|
|
8
|
+
stride: [s]
|
|
9
|
+
} = a;
|
|
10
|
+
for (let i = 0; i < l; i++) data[offset + i * s] = rnd() * n;
|
|
11
|
+
return a;
|
|
12
|
+
};
|
|
13
|
+
const randDistrib2 = (a, rnd = op(), n = 1) => {
|
|
14
|
+
const {
|
|
15
|
+
data: adata,
|
|
16
|
+
shape: [rows, cols],
|
|
17
|
+
stride: [txa, tya],
|
|
18
|
+
offset: offa
|
|
19
|
+
} = a;
|
|
20
|
+
for (let i = 0; i < rows; i++) {
|
|
21
|
+
const ia = offa + i * txa;
|
|
22
|
+
for (let j = 0; j < cols; j++) {
|
|
23
|
+
adata[ia + j * tya] = rnd() * n;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return a;
|
|
27
|
+
};
|
|
28
|
+
const randDistrib3 = (a, rnd = op(), n = 1) => {
|
|
29
|
+
const {
|
|
30
|
+
data: adata,
|
|
31
|
+
shape: [slices, rows, cols],
|
|
32
|
+
stride: [txa, tya, tza],
|
|
33
|
+
offset: offa
|
|
34
|
+
} = a;
|
|
35
|
+
for (let i = 0; i < slices; i++) {
|
|
36
|
+
const $offa = offa + i * txa;
|
|
37
|
+
for (let j = 0; j < rows; j++) {
|
|
38
|
+
const ia = $offa + j * tya;
|
|
39
|
+
for (let k = 0; k < cols; k++) {
|
|
40
|
+
adata[ia + k * tza] = rnd() * n;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return a;
|
|
45
|
+
};
|
|
46
|
+
const randDistrib = top(0, void 0, randDistrib1, randDistrib2, randDistrib3);
|
|
47
|
+
export {
|
|
48
|
+
randDistrib,
|
|
49
|
+
randDistrib1,
|
|
50
|
+
randDistrib2,
|
|
51
|
+
randDistrib3
|
|
52
|
+
};
|
package/relu.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Componentwise computes ReLU of given nD tensor and writes result to `out`. If
|
|
3
|
+
* `out` is null, mutates original. Multi-method.
|
|
4
|
+
*
|
|
5
|
+
* @param out - output tensor
|
|
6
|
+
* @param a - input tensor
|
|
7
|
+
*/
|
|
8
|
+
export declare const relu: import("./api.js").MultiTensorOpT<number>;
|
|
9
|
+
/**
|
|
10
|
+
* Same as {@link relu} for 1D tensors.
|
|
11
|
+
*
|
|
12
|
+
* @param out - output tensor
|
|
13
|
+
* @param a - input tensor
|
|
14
|
+
*/
|
|
15
|
+
export declare const relu1: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor1<number>, import("./tensor.js").Tensor1<number>>;
|
|
16
|
+
/**
|
|
17
|
+
* Same as {@link relu} for 2D tensors.
|
|
18
|
+
*
|
|
19
|
+
* @param out - output tensor
|
|
20
|
+
* @param a - input tensor
|
|
21
|
+
*/
|
|
22
|
+
export declare const relu2: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor2<number>, import("./tensor.js").Tensor2<number>>;
|
|
23
|
+
/**
|
|
24
|
+
* Same as {@link relu} for 3D tensors.
|
|
25
|
+
*
|
|
26
|
+
* @param out - output tensor
|
|
27
|
+
* @param a - input tensor
|
|
28
|
+
*/
|
|
29
|
+
export declare const relu3: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor3<number>, import("./tensor.js").Tensor3<number>>;
|
|
30
|
+
/**
|
|
31
|
+
* Same as {@link relu} for 4D tensors.
|
|
32
|
+
*
|
|
33
|
+
* @param out - output tensor
|
|
34
|
+
* @param a - input tensor
|
|
35
|
+
*/
|
|
36
|
+
export declare const relu4: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor4<number>, import("./tensor.js").Tensor4<number>>;
|
|
37
|
+
//# sourceMappingURL=relu.d.ts.map
|
package/relu.js
ADDED
package/relun.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Componentwise computes leaky ReLU of given nD tensor (using slope `n` for
|
|
3
|
+
* negative inputs) and writes result to `out`. If `out` is null, mutates
|
|
4
|
+
* original. Multi-method.
|
|
5
|
+
*
|
|
6
|
+
* @param out - output tensor
|
|
7
|
+
* @param a - input tensor
|
|
8
|
+
* @param n - slope
|
|
9
|
+
*/
|
|
10
|
+
export declare const reluN: import("./api.js").MultiTensorOpTN<number>;
|
|
11
|
+
/**
|
|
12
|
+
* Same as {@link reluN} for 1D tensors.
|
|
13
|
+
*
|
|
14
|
+
* @param out - output tensor
|
|
15
|
+
* @param a - input tensor
|
|
16
|
+
* @param n - slope
|
|
17
|
+
*/
|
|
18
|
+
export declare const reluN1: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor1<number>, import("./tensor.js").Tensor1<number>>;
|
|
19
|
+
/**
|
|
20
|
+
* Same as {@link reluN} for 2D tensors.
|
|
21
|
+
*
|
|
22
|
+
* @param out - output tensor
|
|
23
|
+
* @param a - input tensor
|
|
24
|
+
* @param n - slope
|
|
25
|
+
*/
|
|
26
|
+
export declare const reluN2: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor2<number>, import("./tensor.js").Tensor2<number>>;
|
|
27
|
+
/**
|
|
28
|
+
* Same as {@link reluN} for 3D tensors.
|
|
29
|
+
*
|
|
30
|
+
* @param out - output tensor
|
|
31
|
+
* @param a - input tensor
|
|
32
|
+
* @param n - slope
|
|
33
|
+
*/
|
|
34
|
+
export declare const reluN3: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor3<number>, import("./tensor.js").Tensor3<number>>;
|
|
35
|
+
/**
|
|
36
|
+
* Same as {@link reluN} for 4D tensors.
|
|
37
|
+
*
|
|
38
|
+
* @param out - output tensor
|
|
39
|
+
* @param a - input tensor
|
|
40
|
+
* @param n - slope
|
|
41
|
+
*/
|
|
42
|
+
export declare const reluN4: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor4<number>, import("./tensor.js").Tensor4<number>>;
|
|
43
|
+
//# sourceMappingURL=relun.d.ts.map
|
package/relun.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { defOpTN } from "./defoptn.js";
|
|
2
|
+
const [a, b, c, d, e] = defOpTN((x, n) => x >= 0 ? x : x * n);
|
|
3
|
+
const reluN = a;
|
|
4
|
+
const reluN1 = b;
|
|
5
|
+
const reluN2 = c;
|
|
6
|
+
const reluN3 = d;
|
|
7
|
+
const reluN4 = e;
|
|
8
|
+
export {
|
|
9
|
+
reluN,
|
|
10
|
+
reluN1,
|
|
11
|
+
reluN2,
|
|
12
|
+
reluN3,
|
|
13
|
+
reluN4
|
|
14
|
+
};
|