@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/defopt.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Fn } from "@thi.ng/api";
|
|
2
|
+
import type { MultiTensorOpT, TensorOpT } from "./api.js";
|
|
3
|
+
import type { Tensor1, Tensor2, Tensor3, Tensor4 } from "./tensor.js";
|
|
4
|
+
/**
|
|
5
|
+
* Higher order tensor op factory. Takes given `fn` and returns a 4-tuple of
|
|
6
|
+
* {@link TensorOpT}s applying the given function component-wise. The result
|
|
7
|
+
* tuple uses this order: `[polymorphic, 1d, 2d, 3d, 4d]`.
|
|
8
|
+
*
|
|
9
|
+
* @param fn
|
|
10
|
+
* @param dispatch
|
|
11
|
+
*/
|
|
12
|
+
export declare const defOpT: <T = number>(fn: Fn<T, T>, dispatch?: number) => [MultiTensorOpT<T>, TensorOpT<T, T, Tensor1<T>, Tensor1<T>>, TensorOpT<T, T, Tensor2<T>, Tensor2<T>>, TensorOpT<T, T, Tensor3<T>, Tensor3<T>>, TensorOpT<T, T, Tensor4<T>, Tensor4<T>>];
|
|
13
|
+
//# sourceMappingURL=defopt.d.ts.map
|
package/defopt.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { top } from "./top.js";
|
|
2
|
+
const defOpT = (fn, dispatch = 1) => {
|
|
3
|
+
const f1 = (out, a) => {
|
|
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
|
+
for (let x = 0; x < sx; x++) {
|
|
17
|
+
odata[oo + x * txo] = fn(adata[oa + x * txa]);
|
|
18
|
+
}
|
|
19
|
+
return out;
|
|
20
|
+
};
|
|
21
|
+
const f2 = (out, a) => {
|
|
22
|
+
!out && (out = a);
|
|
23
|
+
const {
|
|
24
|
+
data: odata,
|
|
25
|
+
offset: oo,
|
|
26
|
+
stride: [txo, tyo]
|
|
27
|
+
} = out;
|
|
28
|
+
const {
|
|
29
|
+
data: adata,
|
|
30
|
+
offset: oa,
|
|
31
|
+
shape: [sx, sy],
|
|
32
|
+
stride: [txa, tya]
|
|
33
|
+
} = a;
|
|
34
|
+
for (let x = 0; x < sx; x++) {
|
|
35
|
+
const oox = oo + x * txo;
|
|
36
|
+
const oax = oa + x * txa;
|
|
37
|
+
for (let y = 0; y < sy; y++) {
|
|
38
|
+
odata[oox + y * tyo] = fn(adata[oax + y * tya]);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
};
|
|
43
|
+
const f3 = (out, a) => {
|
|
44
|
+
!out && (out = a);
|
|
45
|
+
const {
|
|
46
|
+
data: odata,
|
|
47
|
+
offset: oo,
|
|
48
|
+
stride: [txo, tyo, tzo]
|
|
49
|
+
} = out;
|
|
50
|
+
const {
|
|
51
|
+
data: adata,
|
|
52
|
+
offset: oa,
|
|
53
|
+
shape: [sx, sy, sz],
|
|
54
|
+
stride: [txa, tya, tza]
|
|
55
|
+
} = a;
|
|
56
|
+
for (let x = 0; x < sx; x++) {
|
|
57
|
+
const oox = oo + x * txo;
|
|
58
|
+
const oax = oa + x * txa;
|
|
59
|
+
for (let y = 0; y < sy; y++) {
|
|
60
|
+
const ooy = oox + y * tyo;
|
|
61
|
+
const oay = oax + y * tya;
|
|
62
|
+
for (let z = 0; z < sz; z++) {
|
|
63
|
+
odata[ooy + z * tzo] = fn(adata[oay + z * tza]);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return out;
|
|
68
|
+
};
|
|
69
|
+
const f4 = (out, a) => {
|
|
70
|
+
!out && (out = a);
|
|
71
|
+
const {
|
|
72
|
+
data: odata,
|
|
73
|
+
offset: oo,
|
|
74
|
+
stride: [txo, tyo, tzo, two]
|
|
75
|
+
} = out;
|
|
76
|
+
const {
|
|
77
|
+
data: adata,
|
|
78
|
+
offset: oa,
|
|
79
|
+
shape: [sx, sy, sz, sw],
|
|
80
|
+
stride: [txa, tya, tza, twa]
|
|
81
|
+
} = a;
|
|
82
|
+
for (let x = 0; x < sx; x++) {
|
|
83
|
+
const oox = oo + x * txo;
|
|
84
|
+
const oax = oa + x * txa;
|
|
85
|
+
for (let y = 0; y < sy; y++) {
|
|
86
|
+
const ooy = oox + y * tyo;
|
|
87
|
+
const oay = oax + y * tya;
|
|
88
|
+
for (let z = 0; z < sz; z++) {
|
|
89
|
+
const ooz = ooy + z * tzo;
|
|
90
|
+
const oaz = oay + z * tza;
|
|
91
|
+
for (let w = 0; w < sw; w++) {
|
|
92
|
+
odata[ooz + w * two] = fn(adata[oaz + w * twa]);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return out;
|
|
98
|
+
};
|
|
99
|
+
return [
|
|
100
|
+
top(dispatch, void 0, f1, f2, f3, f4),
|
|
101
|
+
f1,
|
|
102
|
+
f2,
|
|
103
|
+
f3,
|
|
104
|
+
f4
|
|
105
|
+
];
|
|
106
|
+
};
|
|
107
|
+
export {
|
|
108
|
+
defOpT
|
|
109
|
+
};
|
package/defoptn.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FnU2 } from "@thi.ng/api";
|
|
2
|
+
import type { MultiTensorOpTN, TensorOpTN } from "./api.js";
|
|
3
|
+
import type { Tensor1, Tensor2, Tensor3, Tensor4 } from "./tensor.js";
|
|
4
|
+
/**
|
|
5
|
+
* Higher order tensor op factory. Takes given `fn` and returns a 4-tuple of
|
|
6
|
+
* {@link TensorOpTN}s applying the given function component-wise. The result
|
|
7
|
+
* tuple uses this order: `[polymorphic, 1d, 2d, 3d, 4d]`.
|
|
8
|
+
*
|
|
9
|
+
* @param fn
|
|
10
|
+
* @param dispatch
|
|
11
|
+
*/
|
|
12
|
+
export declare const defOpTN: <T = number>(fn: FnU2<T>, dispatch?: number) => [MultiTensorOpTN<T>, TensorOpTN<T, T, Tensor1<T>, Tensor1<T>>, TensorOpTN<T, T, Tensor2<T>, Tensor2<T>>, TensorOpTN<T, T, Tensor3<T>, Tensor3<T>>, TensorOpTN<T, T, Tensor4<T>, Tensor4<T>>];
|
|
13
|
+
//# sourceMappingURL=defoptn.d.ts.map
|
package/defoptn.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { top } from "./top.js";
|
|
2
|
+
const defOpTN = (fn, dispatch = 1) => {
|
|
3
|
+
const f1 = (out, a, n) => {
|
|
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
|
+
for (let x = 0; x < sx; x++) {
|
|
17
|
+
odata[oo + x * txo] = fn(adata[oa + x * txa], n);
|
|
18
|
+
}
|
|
19
|
+
return out;
|
|
20
|
+
};
|
|
21
|
+
const f2 = (out, a, n) => {
|
|
22
|
+
!out && (out = a);
|
|
23
|
+
const {
|
|
24
|
+
data: odata,
|
|
25
|
+
offset: oo,
|
|
26
|
+
stride: [txo, tyo]
|
|
27
|
+
} = out;
|
|
28
|
+
const {
|
|
29
|
+
data: adata,
|
|
30
|
+
offset: oa,
|
|
31
|
+
shape: [sx, sy],
|
|
32
|
+
stride: [txa, tya]
|
|
33
|
+
} = a;
|
|
34
|
+
for (let x = 0; x < sx; x++) {
|
|
35
|
+
const oox = oo + x * txo;
|
|
36
|
+
const oax = oa + x * txa;
|
|
37
|
+
for (let y = 0; y < sy; y++) {
|
|
38
|
+
odata[oox + y * tyo] = fn(adata[oax + y * tya], n);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
};
|
|
43
|
+
const f3 = (out, a, n) => {
|
|
44
|
+
!out && (out = a);
|
|
45
|
+
const {
|
|
46
|
+
data: odata,
|
|
47
|
+
offset: oo,
|
|
48
|
+
stride: [txo, tyo, tzo]
|
|
49
|
+
} = out;
|
|
50
|
+
const {
|
|
51
|
+
data: adata,
|
|
52
|
+
offset: oa,
|
|
53
|
+
shape: [sx, sy, sz],
|
|
54
|
+
stride: [txa, tya, tza]
|
|
55
|
+
} = a;
|
|
56
|
+
for (let x = 0; x < sx; x++) {
|
|
57
|
+
const oox = oo + x * txo;
|
|
58
|
+
const oax = oa + x * txa;
|
|
59
|
+
for (let y = 0; y < sy; y++) {
|
|
60
|
+
const ooy = oox + y * tyo;
|
|
61
|
+
const oay = oax + y * tya;
|
|
62
|
+
for (let z = 0; z < sz; z++) {
|
|
63
|
+
odata[ooy + z * tzo] = fn(adata[oay + z * tza], n);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return out;
|
|
68
|
+
};
|
|
69
|
+
const f4 = (out, a, n) => {
|
|
70
|
+
!out && (out = a);
|
|
71
|
+
const {
|
|
72
|
+
data: odata,
|
|
73
|
+
offset: oo,
|
|
74
|
+
stride: [txo, tyo, tzo, two]
|
|
75
|
+
} = out;
|
|
76
|
+
const {
|
|
77
|
+
data: adata,
|
|
78
|
+
offset: oa,
|
|
79
|
+
shape: [sx, sy, sz, sw],
|
|
80
|
+
stride: [txa, tya, tza, twa]
|
|
81
|
+
} = a;
|
|
82
|
+
for (let x = 0; x < sx; x++) {
|
|
83
|
+
const oox = oo + x * txo;
|
|
84
|
+
const oax = oa + x * txa;
|
|
85
|
+
for (let y = 0; y < sy; y++) {
|
|
86
|
+
const ooy = oox + y * tyo;
|
|
87
|
+
const oay = oax + y * tya;
|
|
88
|
+
for (let z = 0; z < sz; z++) {
|
|
89
|
+
const ooz = ooy + z * tzo;
|
|
90
|
+
const oaz = oay + z * tza;
|
|
91
|
+
for (let w = 0; w < sw; w++) {
|
|
92
|
+
odata[ooz + w * two] = fn(adata[oaz + w * twa], n);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return out;
|
|
98
|
+
};
|
|
99
|
+
return [
|
|
100
|
+
top(dispatch, void 0, f1, f2, f3, f4),
|
|
101
|
+
f1,
|
|
102
|
+
f2,
|
|
103
|
+
f3,
|
|
104
|
+
f4
|
|
105
|
+
];
|
|
106
|
+
};
|
|
107
|
+
export {
|
|
108
|
+
defOpTN
|
|
109
|
+
};
|
package/defoptnn.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FnU3 } from "@thi.ng/api";
|
|
2
|
+
import type { MultiTensorOpTNN, TensorOpTNN } from "./api.js";
|
|
3
|
+
import type { Tensor1, Tensor2, Tensor3, Tensor4 } from "./tensor.js";
|
|
4
|
+
/**
|
|
5
|
+
* Higher order tensor op factory. Takes given `fn` and returns a 4-tuple of
|
|
6
|
+
* {@link TensorOpTNN}s applying the given function component-wise. The result
|
|
7
|
+
* tuple uses this order: `[polymorphic, 1d, 2d, 3d, 4d]`.
|
|
8
|
+
*
|
|
9
|
+
* @param fn
|
|
10
|
+
* @param dispatch
|
|
11
|
+
*/
|
|
12
|
+
export declare const defOpTNN: <T = number>(fn: FnU3<T>, dispatch?: number) => [MultiTensorOpTNN<T>, TensorOpTNN<T, T, Tensor1<T>, Tensor1<T>>, TensorOpTNN<T, T, Tensor2<T>, Tensor2<T>>, TensorOpTNN<T, T, Tensor3<T>, Tensor3<T>>, TensorOpTNN<T, T, Tensor4<T>, Tensor4<T>>];
|
|
13
|
+
//# sourceMappingURL=defoptnn.d.ts.map
|
package/defoptnn.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { top } from "./top.js";
|
|
2
|
+
const defOpTNN = (fn, dispatch = 1) => {
|
|
3
|
+
const f1 = (out, a, n, m) => {
|
|
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
|
+
for (let x = 0; x < sx; x++) {
|
|
17
|
+
odata[oo + x * txo] = fn(adata[oa + x * txa], n, m);
|
|
18
|
+
}
|
|
19
|
+
return out;
|
|
20
|
+
};
|
|
21
|
+
const f2 = (out, a, n, m) => {
|
|
22
|
+
!out && (out = a);
|
|
23
|
+
const {
|
|
24
|
+
data: odata,
|
|
25
|
+
offset: oo,
|
|
26
|
+
stride: [txo, tyo]
|
|
27
|
+
} = out;
|
|
28
|
+
const {
|
|
29
|
+
data: adata,
|
|
30
|
+
offset: oa,
|
|
31
|
+
shape: [sx, sy],
|
|
32
|
+
stride: [txa, tya]
|
|
33
|
+
} = a;
|
|
34
|
+
for (let x = 0; x < sx; x++) {
|
|
35
|
+
const oox = oo + x * txo;
|
|
36
|
+
const oax = oa + x * txa;
|
|
37
|
+
for (let y = 0; y < sy; y++) {
|
|
38
|
+
odata[oox + y * tyo] = fn(adata[oax + y * tya], n, m);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
};
|
|
43
|
+
const f3 = (out, a, n, m) => {
|
|
44
|
+
!out && (out = a);
|
|
45
|
+
const {
|
|
46
|
+
data: odata,
|
|
47
|
+
offset: oo,
|
|
48
|
+
stride: [txo, tyo, tzo]
|
|
49
|
+
} = out;
|
|
50
|
+
const {
|
|
51
|
+
data: adata,
|
|
52
|
+
offset: oa,
|
|
53
|
+
shape: [sx, sy, sz],
|
|
54
|
+
stride: [txa, tya, tza]
|
|
55
|
+
} = a;
|
|
56
|
+
for (let x = 0; x < sx; x++) {
|
|
57
|
+
const oox = oo + x * txo;
|
|
58
|
+
const oax = oa + x * txa;
|
|
59
|
+
for (let y = 0; y < sy; y++) {
|
|
60
|
+
const ooy = oox + y * tyo;
|
|
61
|
+
const oay = oax + y * tya;
|
|
62
|
+
for (let z = 0; z < sz; z++) {
|
|
63
|
+
odata[ooy + z * tzo] = fn(adata[oay + z * tza], n, m);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return out;
|
|
68
|
+
};
|
|
69
|
+
const f4 = (out, a, n, m) => {
|
|
70
|
+
!out && (out = a);
|
|
71
|
+
const {
|
|
72
|
+
data: odata,
|
|
73
|
+
offset: oo,
|
|
74
|
+
stride: [txo, tyo, tzo, two]
|
|
75
|
+
} = out;
|
|
76
|
+
const {
|
|
77
|
+
data: adata,
|
|
78
|
+
offset: oa,
|
|
79
|
+
shape: [sx, sy, sz, sw],
|
|
80
|
+
stride: [txa, tya, tza, twa]
|
|
81
|
+
} = a;
|
|
82
|
+
for (let x = 0; x < sx; x++) {
|
|
83
|
+
const oox = oo + x * txo;
|
|
84
|
+
const oax = oa + x * txa;
|
|
85
|
+
for (let y = 0; y < sy; y++) {
|
|
86
|
+
const ooy = oox + y * tyo;
|
|
87
|
+
const oay = oax + y * tya;
|
|
88
|
+
for (let z = 0; z < sz; z++) {
|
|
89
|
+
const ooz = ooy + z * tzo;
|
|
90
|
+
const oaz = oay + z * tza;
|
|
91
|
+
for (let w = 0; w < sw; w++) {
|
|
92
|
+
odata[ooz + w * two] = fn(adata[oaz + w * twa], n, m);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return out;
|
|
98
|
+
};
|
|
99
|
+
return [
|
|
100
|
+
top(dispatch, void 0, f1, f2, f3, f4),
|
|
101
|
+
f1,
|
|
102
|
+
f2,
|
|
103
|
+
f3,
|
|
104
|
+
f4
|
|
105
|
+
];
|
|
106
|
+
};
|
|
107
|
+
export {
|
|
108
|
+
defOpTNN
|
|
109
|
+
};
|
package/defoptt.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FnU2 } from "@thi.ng/api";
|
|
2
|
+
import type { MultiTensorOpTT, TensorOpTT } from "./api.js";
|
|
3
|
+
import type { Tensor1, Tensor2, Tensor3, Tensor4 } from "./tensor.js";
|
|
4
|
+
/**
|
|
5
|
+
* Higher order tensor op factory. Takes given `fn` and returns a 4-tuple of
|
|
6
|
+
* {@link TensorOpTT}s applying the given function component-wise. The result
|
|
7
|
+
* tuple uses this order: `[polymorphic, 1d, 2d, 3d, 4d]`.
|
|
8
|
+
*
|
|
9
|
+
* @param fn
|
|
10
|
+
* @param dispatch
|
|
11
|
+
*/
|
|
12
|
+
export declare const defOpTT: <T = number>(fn: FnU2<T>, dispatch?: number) => [MultiTensorOpTT<T>, TensorOpTT<T, T, Tensor1<T>, Tensor1<T>>, TensorOpTT<T, T, Tensor2<T>, Tensor2<T>>, TensorOpTT<T, T, Tensor3<T>, Tensor3<T>>, TensorOpTT<T, T, Tensor4<T>, Tensor4<T>>];
|
|
13
|
+
//# sourceMappingURL=defoptt.d.ts.map
|
package/defoptt.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { top } from "./top.js";
|
|
2
|
+
const defOpTT = (fn, dispatch = 1) => {
|
|
3
|
+
const f1 = (out, a, b) => {
|
|
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
|
+
for (let x = 0; x < sx; x++) {
|
|
22
|
+
odata[oo + x * txo] = fn(adata[oa + x * txa], bdata[ob + x * txb]);
|
|
23
|
+
}
|
|
24
|
+
return out;
|
|
25
|
+
};
|
|
26
|
+
const f2 = (out, a, b) => {
|
|
27
|
+
!out && (out = a);
|
|
28
|
+
const {
|
|
29
|
+
data: odata,
|
|
30
|
+
offset: oo,
|
|
31
|
+
stride: [txo, tyo]
|
|
32
|
+
} = out;
|
|
33
|
+
const {
|
|
34
|
+
data: adata,
|
|
35
|
+
offset: oa,
|
|
36
|
+
shape: [sx, sy],
|
|
37
|
+
stride: [txa, tya]
|
|
38
|
+
} = a;
|
|
39
|
+
const {
|
|
40
|
+
data: bdata,
|
|
41
|
+
offset: ob,
|
|
42
|
+
stride: [txb, tyb]
|
|
43
|
+
} = b;
|
|
44
|
+
for (let x = 0; x < sx; x++) {
|
|
45
|
+
const oox = oo + x * txo;
|
|
46
|
+
const oax = oa + x * txa;
|
|
47
|
+
const obx = ob + x * txb;
|
|
48
|
+
for (let y = 0; y < sy; y++) {
|
|
49
|
+
odata[oox + y * tyo] = fn(
|
|
50
|
+
adata[oax + y * tya],
|
|
51
|
+
bdata[obx + y * tyb]
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
};
|
|
57
|
+
const f3 = (out, a, b) => {
|
|
58
|
+
!out && (out = a);
|
|
59
|
+
const {
|
|
60
|
+
data: odata,
|
|
61
|
+
offset: oo,
|
|
62
|
+
stride: [txo, tyo, tzo]
|
|
63
|
+
} = out;
|
|
64
|
+
const {
|
|
65
|
+
data: adata,
|
|
66
|
+
offset: oa,
|
|
67
|
+
shape: [sx, sy, sz],
|
|
68
|
+
stride: [txa, tya, tza]
|
|
69
|
+
} = a;
|
|
70
|
+
const {
|
|
71
|
+
data: bdata,
|
|
72
|
+
offset: ob,
|
|
73
|
+
stride: [txb, tyb, tzb]
|
|
74
|
+
} = b;
|
|
75
|
+
for (let x = 0; x < sx; x++) {
|
|
76
|
+
const oox = oo + x * txo;
|
|
77
|
+
const oax = oa + x * txa;
|
|
78
|
+
const obx = ob + x * txb;
|
|
79
|
+
for (let y = 0; y < sy; y++) {
|
|
80
|
+
const ooy = oox + y * tyo;
|
|
81
|
+
const oay = oax + y * tya;
|
|
82
|
+
const oby = obx + y * tyb;
|
|
83
|
+
for (let z = 0; z < sz; z++) {
|
|
84
|
+
odata[ooy + z * tzo] = fn(
|
|
85
|
+
adata[oay + z * tza],
|
|
86
|
+
bdata[oby + z * tzb]
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return out;
|
|
92
|
+
};
|
|
93
|
+
const f4 = (out, a, b) => {
|
|
94
|
+
!out && (out = a);
|
|
95
|
+
const {
|
|
96
|
+
data: odata,
|
|
97
|
+
offset: oo,
|
|
98
|
+
stride: [txo, tyo, tzo, two]
|
|
99
|
+
} = out;
|
|
100
|
+
const {
|
|
101
|
+
data: adata,
|
|
102
|
+
offset: oa,
|
|
103
|
+
shape: [sx, sy, sz, sw],
|
|
104
|
+
stride: [txa, tya, tza, twa]
|
|
105
|
+
} = a;
|
|
106
|
+
const {
|
|
107
|
+
data: bdata,
|
|
108
|
+
offset: ob,
|
|
109
|
+
stride: [txb, tyb, tzb, twb]
|
|
110
|
+
} = b;
|
|
111
|
+
for (let x = 0; x < sx; x++) {
|
|
112
|
+
const oox = oo + x * txo;
|
|
113
|
+
const oax = oa + x * txa;
|
|
114
|
+
const obx = ob + x * txb;
|
|
115
|
+
for (let y = 0; y < sy; y++) {
|
|
116
|
+
const ooy = oox + y * tyo;
|
|
117
|
+
const oay = oax + y * tya;
|
|
118
|
+
const oby = obx + y * tyb;
|
|
119
|
+
for (let z = 0; z < sz; z++) {
|
|
120
|
+
const ooz = ooy + z * tzo;
|
|
121
|
+
const oaz = oay + z * tza;
|
|
122
|
+
const obz = oby + z * tzb;
|
|
123
|
+
for (let w = 0; w < sw; w++) {
|
|
124
|
+
odata[ooz + w * two] = fn(
|
|
125
|
+
adata[oaz + w * twa],
|
|
126
|
+
bdata[obz + w * twb]
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return out;
|
|
133
|
+
};
|
|
134
|
+
return [
|
|
135
|
+
top(dispatch, void 0, f1, f2, f3, f4),
|
|
136
|
+
f1,
|
|
137
|
+
f2,
|
|
138
|
+
f3,
|
|
139
|
+
f4
|
|
140
|
+
];
|
|
141
|
+
};
|
|
142
|
+
export {
|
|
143
|
+
defOpTT
|
|
144
|
+
};
|
package/defopttt.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FnU3 } from "@thi.ng/api";
|
|
2
|
+
import type { MultiTensorOpTTT, TensorOpTTT } from "./api.js";
|
|
3
|
+
import type { Tensor1, Tensor2, Tensor3, Tensor4 } from "./tensor.js";
|
|
4
|
+
/**
|
|
5
|
+
* Higher order tensor op factory. Takes given `fn` and returns a 4-tuple of
|
|
6
|
+
* {@link TensorOpTTT}s applying the given function component-wise. The result
|
|
7
|
+
* tuple uses this order: `[polymorphic, 1d, 2d, 3d, 4d]`.
|
|
8
|
+
*
|
|
9
|
+
* @param fn
|
|
10
|
+
* @param dispatch
|
|
11
|
+
*/
|
|
12
|
+
export declare const defOpTTT: <T = number>(fn: FnU3<T>, dispatch?: number) => [MultiTensorOpTTT<T>, TensorOpTTT<T, T, Tensor1<T>, Tensor1<T>>, TensorOpTTT<T, T, Tensor2<T>, Tensor2<T>>, TensorOpTTT<T, T, Tensor3<T>, Tensor3<T>>, TensorOpTTT<T, T, Tensor4<T>, Tensor4<T>>];
|
|
13
|
+
//# sourceMappingURL=defopttt.d.ts.map
|