@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/addn.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Componentwise nD tensor addition 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 addN: import("./api.js").MultiTensorOpTN<number>;
|
|
10
|
+
/**
|
|
11
|
+
* Same as {@link addN} for 1D tensors.
|
|
12
|
+
*
|
|
13
|
+
* @param out - output tensor
|
|
14
|
+
* @param a - input tensor
|
|
15
|
+
* @param n - scalar
|
|
16
|
+
*/
|
|
17
|
+
export declare const addN1: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor1<number>, import("./tensor.js").Tensor1<number>>;
|
|
18
|
+
/**
|
|
19
|
+
* Same as {@link addN} for 2D tensors.
|
|
20
|
+
*
|
|
21
|
+
* @param out - output tensor
|
|
22
|
+
* @param a - input tensor
|
|
23
|
+
* @param n - scalar
|
|
24
|
+
*/
|
|
25
|
+
export declare const addN2: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor2<number>, import("./tensor.js").Tensor2<number>>;
|
|
26
|
+
/**
|
|
27
|
+
* Same as {@link addN} for 3D tensors.
|
|
28
|
+
*
|
|
29
|
+
* @param out - output tensor
|
|
30
|
+
* @param a - input tensor
|
|
31
|
+
* @param n - scalar
|
|
32
|
+
*/
|
|
33
|
+
export declare const addN3: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor3<number>, import("./tensor.js").Tensor3<number>>;
|
|
34
|
+
/**
|
|
35
|
+
* Same as {@link addN} for 4D tensors.
|
|
36
|
+
*
|
|
37
|
+
* @param out - output tensor
|
|
38
|
+
* @param a - input tensor
|
|
39
|
+
* @param n - scalar
|
|
40
|
+
*/
|
|
41
|
+
export declare const addN4: import("./api.js").TensorOpTN<number, number, import("./tensor.js").Tensor4<number>, import("./tensor.js").Tensor4<number>>;
|
|
42
|
+
//# sourceMappingURL=addn.d.ts.map
|
package/addn.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { $add } from "@thi.ng/vectors/ops";
|
|
2
|
+
import { defOpTN } from "./defoptn.js";
|
|
3
|
+
const [a, b, c, d, e] = defOpTN($add);
|
|
4
|
+
const addN = a;
|
|
5
|
+
const addN1 = b;
|
|
6
|
+
const addN2 = c;
|
|
7
|
+
const addN3 = d;
|
|
8
|
+
const addN4 = e;
|
|
9
|
+
export {
|
|
10
|
+
addN,
|
|
11
|
+
addN1,
|
|
12
|
+
addN2,
|
|
13
|
+
addN3,
|
|
14
|
+
addN4
|
|
15
|
+
};
|
package/api.d.ts
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import type { Type as $Type, Fn2, Fn3, Fn4, ICopy, IEqualsDelta, IEquiv, ILength, Maybe, NumericArray } from "@thi.ng/api";
|
|
2
|
+
import type { Tensor1, Tensor2, Tensor3, Tensor4 } from "./tensor.js";
|
|
3
|
+
export interface TensorData<T = number> extends Iterable<T>, ILength {
|
|
4
|
+
[id: number]: T;
|
|
5
|
+
fill(x: T, start?: number, end?: number): TensorData<T>;
|
|
6
|
+
}
|
|
7
|
+
export type Type = $Type | "num" | "str";
|
|
8
|
+
export type NumType = Type | "num";
|
|
9
|
+
export type Shape1 = [number];
|
|
10
|
+
export type Shape2 = [number, number];
|
|
11
|
+
export type Shape3 = [number, number, number];
|
|
12
|
+
export type Shape4 = [number, number, number, number];
|
|
13
|
+
export type Shape = Shape1 | Shape2 | Shape3 | Shape4;
|
|
14
|
+
export type ShapeTensor<S extends Shape, T> = S extends Shape4 ? Tensor4<T> : S extends Shape3 ? Tensor3<T> : S extends Shape2 ? Tensor2<T> : Tensor1<T>;
|
|
15
|
+
export type Nested<T> = T[] | T[][] | T[][][] | T[][][][];
|
|
16
|
+
export type NestedTensor<N extends Nested<T>, T> = N extends T[][][][] ? Tensor4<T> : N extends T[][][] ? Tensor3<T> : N extends T[][] ? Tensor2<T> : Tensor1<T>;
|
|
17
|
+
export interface TypeMap {
|
|
18
|
+
u8: number;
|
|
19
|
+
u8c: number;
|
|
20
|
+
i8: number;
|
|
21
|
+
u16: number;
|
|
22
|
+
i16: number;
|
|
23
|
+
u32: number;
|
|
24
|
+
i32: number;
|
|
25
|
+
f32: number;
|
|
26
|
+
f64: number;
|
|
27
|
+
num: number;
|
|
28
|
+
str: string;
|
|
29
|
+
}
|
|
30
|
+
export interface TensorOpts<T, S extends Shape> {
|
|
31
|
+
/**
|
|
32
|
+
* Tensor data. Unless {@link TensorOpts.copy} is false, by default will be
|
|
33
|
+
* copied to memory obtained from configured storage.
|
|
34
|
+
*/
|
|
35
|
+
data?: TensorData<T>;
|
|
36
|
+
/**
|
|
37
|
+
* Optionally configured storage provider. By default uses the
|
|
38
|
+
* datatype-specific implementation from global {@link STORAGE} registry.
|
|
39
|
+
*/
|
|
40
|
+
storage?: ITensorStorage<T>;
|
|
41
|
+
/**
|
|
42
|
+
* Optionally configured stride tuple. By default the strides will be
|
|
43
|
+
* obtained from the tensor shape and will be in row-major order.
|
|
44
|
+
*/
|
|
45
|
+
stride?: S;
|
|
46
|
+
/**
|
|
47
|
+
* Optional start index of the data values (only inteded to be used if
|
|
48
|
+
* {@link TensorOpts.data} is given).
|
|
49
|
+
*/
|
|
50
|
+
offset?: number;
|
|
51
|
+
/**
|
|
52
|
+
* Only used if {@link TensorOpts.data} is given. If true (default), the
|
|
53
|
+
* data will be copied to memory obtained from configured storage.
|
|
54
|
+
*/
|
|
55
|
+
copy?: boolean;
|
|
56
|
+
}
|
|
57
|
+
export interface TensorFromArrayOpts<T extends Type, V> {
|
|
58
|
+
type: T;
|
|
59
|
+
storage?: ITensorStorage<V>;
|
|
60
|
+
}
|
|
61
|
+
export interface ITensor<T = number> extends ICopy<ITensor<T>>, IEquiv, IEqualsDelta<ITensor<T>> {
|
|
62
|
+
readonly type: Type;
|
|
63
|
+
readonly storage: ITensorStorage<T>;
|
|
64
|
+
readonly data: TensorData<T>;
|
|
65
|
+
readonly shape: number[];
|
|
66
|
+
readonly stride: number[];
|
|
67
|
+
readonly offset: number;
|
|
68
|
+
readonly length: number;
|
|
69
|
+
readonly dim: number;
|
|
70
|
+
readonly order: number[];
|
|
71
|
+
orderedShape: number[];
|
|
72
|
+
orderedStride: number[];
|
|
73
|
+
[Symbol.iterator](): IterableIterator<T>;
|
|
74
|
+
empty(storage?: ITensorStorage<T>): this;
|
|
75
|
+
index(pos: NumericArray): number;
|
|
76
|
+
get(pos: NumericArray): T;
|
|
77
|
+
set(pos: NumericArray, value: T): this;
|
|
78
|
+
lo(pos: NumericArray): this;
|
|
79
|
+
hi(pos: NumericArray): this;
|
|
80
|
+
step(select: NumericArray): this;
|
|
81
|
+
pick(select: NumericArray): ITensor<T>;
|
|
82
|
+
pack(storage?: ITensorStorage<T>): this;
|
|
83
|
+
reshape<S extends Shape>(newShape: S, newStride?: S): ShapeTensor<S, T>;
|
|
84
|
+
resize<S extends Shape>(newShape: S, fill?: T, storage?: ITensorStorage<T>): ShapeTensor<S, T>;
|
|
85
|
+
transpose(order: NumericArray): this;
|
|
86
|
+
toJSON(): any;
|
|
87
|
+
}
|
|
88
|
+
export interface TensorCtor<T = number> {
|
|
89
|
+
new (type: Type, storage: ITensorStorage<T>, data: TensorData<T>, shape: number[], stride: number[], offset?: number): ITensor<T>;
|
|
90
|
+
}
|
|
91
|
+
export interface ITensorStorage<T> {
|
|
92
|
+
alloc(size: number): TensorData<T>;
|
|
93
|
+
from(iter: Iterable<T>): TensorData<T>;
|
|
94
|
+
release(buf: TensorData<T>): boolean;
|
|
95
|
+
}
|
|
96
|
+
export type StorageRegistry = Record<Type, ITensorStorage<any>>;
|
|
97
|
+
export type TensorOpN<A = number, B = A, TB extends ITensor<B> = ITensor<B>> = Fn2<TB, A, TB>;
|
|
98
|
+
export type TensorOpT<A = number, B = A, TA extends ITensor<A> = ITensor<A>, TB extends ITensor<B> = ITensor<B>> = Fn2<TB | null, TA, TB>;
|
|
99
|
+
export type TensorOpTN<A = number, B = A, TA extends ITensor<A> = ITensor<A>, TB extends ITensor<B> = ITensor<B>> = Fn3<TB | null, TA, A, TB>;
|
|
100
|
+
export type TensorOpTNN<A = number, B = A, TA extends ITensor<A> = ITensor<A>, TB extends ITensor<B> = ITensor<B>> = Fn4<TB | null, TA, A, A, TB>;
|
|
101
|
+
export type TensorOpTT<A = number, B = A, TA extends ITensor<A> = ITensor<A>, TB extends ITensor<B> = ITensor<B>> = Fn3<TB | null, TA, TA, TB>;
|
|
102
|
+
export type TensorOpTTT<A = number, B = A, TA extends ITensor<A> = ITensor<A>, TB extends ITensor<B> = ITensor<B>> = Fn4<TB | null, TA, TA, TA, TB>;
|
|
103
|
+
export type TensorOpRT<A, B, TA extends ITensor<A> = ITensor<A>> = (a: TA) => B;
|
|
104
|
+
export type TensorOpRTT<A, B, TA extends ITensor<A> = ITensor<A>> = (a: TA, b: TA) => B;
|
|
105
|
+
export interface MultiTensorOp<TOP> {
|
|
106
|
+
/**
|
|
107
|
+
* Adds / overwrites implementation for given tensor dimension.
|
|
108
|
+
*
|
|
109
|
+
* @param dim -
|
|
110
|
+
* @param op -
|
|
111
|
+
*/
|
|
112
|
+
add(dim: number, op: TOP): TOP;
|
|
113
|
+
/**
|
|
114
|
+
* Adds / overwrites default implementation (SHOULD support arbitrary tensor
|
|
115
|
+
* dimensions).
|
|
116
|
+
*
|
|
117
|
+
* @param op -
|
|
118
|
+
*/
|
|
119
|
+
default(op: TOP): TOP;
|
|
120
|
+
/**
|
|
121
|
+
* Returns implementation for given tensor dimension or default
|
|
122
|
+
* implementation.
|
|
123
|
+
*
|
|
124
|
+
* @param dim -
|
|
125
|
+
*/
|
|
126
|
+
impl(dim?: number): Maybe<TOP>;
|
|
127
|
+
}
|
|
128
|
+
export type MultiTensorOpImpl<T> = T & MultiTensorOp<T>;
|
|
129
|
+
export type MultiTensorOpN<A = number, B = A> = MultiTensorOpImpl<TensorOpN<A, B>>;
|
|
130
|
+
export type MultiTensorOpT<A = number, B = A> = MultiTensorOpImpl<TensorOpT<A, B>>;
|
|
131
|
+
export type MultiTensorOpTN<A = number, B = A> = MultiTensorOpImpl<TensorOpTN<A, B>>;
|
|
132
|
+
export type MultiTensorOpTNN<A = number, B = A> = MultiTensorOpImpl<TensorOpTNN<A, B>>;
|
|
133
|
+
export type MultiTensorOpTT<A = number, B = A> = MultiTensorOpImpl<TensorOpTT<A, B>>;
|
|
134
|
+
export type MultiTensorOpTTT<A = number, B = A> = MultiTensorOpImpl<TensorOpTTT<A, B>>;
|
|
135
|
+
export type MultiTensorOpRT<A = number, B = A> = MultiTensorOpImpl<TensorOpRT<A, B>>;
|
|
136
|
+
export type MultiTensorOpRTT<A = number, B = A> = MultiTensorOpImpl<TensorOpRTT<A, B>>;
|
|
137
|
+
//# sourceMappingURL=api.d.ts.map
|
package/api.js
ADDED
|
File without changes
|
package/clamp.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Componentwise clamps nD tensor `a` to closed interval defined by `[b,c]`.
|
|
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 b - input tensor (min)
|
|
8
|
+
* @param c - input tensor (max)
|
|
9
|
+
*/
|
|
10
|
+
export declare const clamp: import("./api.js").MultiTensorOpTTT<number>;
|
|
11
|
+
/**
|
|
12
|
+
* Same as {@link clamp} for 1D tensors.
|
|
13
|
+
*
|
|
14
|
+
* @param out - output tensor
|
|
15
|
+
* @param a - input tensor
|
|
16
|
+
* @param b - input tensor (min)
|
|
17
|
+
* @param c - input tensor (max)
|
|
18
|
+
*/
|
|
19
|
+
export declare const clamp1: import("./api.js").TensorOpTTT<number, number, import("./tensor.js").Tensor1<number>, import("./tensor.js").Tensor1<number>>;
|
|
20
|
+
/**
|
|
21
|
+
* Same as {@link clamp} for 2D tensors.
|
|
22
|
+
*
|
|
23
|
+
* @param out - output tensor
|
|
24
|
+
* @param a - input tensor
|
|
25
|
+
* @param b - input tensor (min)
|
|
26
|
+
* @param c - input tensor (max)
|
|
27
|
+
*/
|
|
28
|
+
export declare const clamp2: import("./api.js").TensorOpTTT<number, number, import("./tensor.js").Tensor2<number>, import("./tensor.js").Tensor2<number>>;
|
|
29
|
+
/**
|
|
30
|
+
* Same as {@link clamp} for 3D tensors.
|
|
31
|
+
*
|
|
32
|
+
* @param out - output tensor
|
|
33
|
+
* @param a - input tensor
|
|
34
|
+
* @param b - input tensor (min)
|
|
35
|
+
* @param c - input tensor (max)
|
|
36
|
+
*/
|
|
37
|
+
export declare const clamp3: import("./api.js").TensorOpTTT<number, number, import("./tensor.js").Tensor3<number>, import("./tensor.js").Tensor3<number>>;
|
|
38
|
+
/**
|
|
39
|
+
* Same as {@link clamp} for 4D tensors.
|
|
40
|
+
*
|
|
41
|
+
* @param out - output tensor
|
|
42
|
+
* @param a - input tensor
|
|
43
|
+
* @param b - input tensor (min)
|
|
44
|
+
* @param c - input tensor (max)
|
|
45
|
+
*/
|
|
46
|
+
export declare const clamp4: import("./api.js").TensorOpTTT<number, number, import("./tensor.js").Tensor4<number>, import("./tensor.js").Tensor4<number>>;
|
|
47
|
+
//# sourceMappingURL=clamp.d.ts.map
|
package/clamp.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { clamp as op } from "@thi.ng/math/interval";
|
|
2
|
+
import { defOpTTT } from "./defopttt.js";
|
|
3
|
+
const [a, b, c, d, e] = defOpTTT(op);
|
|
4
|
+
const clamp = a;
|
|
5
|
+
const clamp1 = b;
|
|
6
|
+
const clamp2 = c;
|
|
7
|
+
const clamp3 = d;
|
|
8
|
+
const clamp4 = e;
|
|
9
|
+
export {
|
|
10
|
+
clamp,
|
|
11
|
+
clamp1,
|
|
12
|
+
clamp2,
|
|
13
|
+
clamp3,
|
|
14
|
+
clamp4
|
|
15
|
+
};
|
package/clampn.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Componentwise clamps nD tensor `a` to closed interval defined by `[b,c]`.
|
|
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 b - scalar (min)
|
|
8
|
+
* @param c - scalar (max)
|
|
9
|
+
*/
|
|
10
|
+
export declare const clampN: import("./api.js").MultiTensorOpTNN<number>;
|
|
11
|
+
/**
|
|
12
|
+
* Same as {@link clampN} for 1D tensors.
|
|
13
|
+
*
|
|
14
|
+
* @param out - output tensor
|
|
15
|
+
* @param a - input tensor
|
|
16
|
+
* @param b - scalar (min)
|
|
17
|
+
* @param c - scalar (max)
|
|
18
|
+
*/
|
|
19
|
+
export declare const clampN1: import("./api.js").TensorOpTNN<number, number, import("./tensor.js").Tensor1<number>, import("./tensor.js").Tensor1<number>>;
|
|
20
|
+
/**
|
|
21
|
+
* Same as {@link clampN} for 2D tensors.
|
|
22
|
+
*
|
|
23
|
+
* @param out - output tensor
|
|
24
|
+
* @param a - input tensor
|
|
25
|
+
* @param b - scalar (min)
|
|
26
|
+
* @param c - scalar (max)
|
|
27
|
+
*/
|
|
28
|
+
export declare const clampN2: import("./api.js").TensorOpTNN<number, number, import("./tensor.js").Tensor2<number>, import("./tensor.js").Tensor2<number>>;
|
|
29
|
+
/**
|
|
30
|
+
* Same as {@link clampN} for 3D tensors.
|
|
31
|
+
*
|
|
32
|
+
* @param out - output tensor
|
|
33
|
+
* @param a - input tensor
|
|
34
|
+
* @param b - scalar (min)
|
|
35
|
+
* @param c - scalar (max)
|
|
36
|
+
*/
|
|
37
|
+
export declare const clampN3: import("./api.js").TensorOpTNN<number, number, import("./tensor.js").Tensor3<number>, import("./tensor.js").Tensor3<number>>;
|
|
38
|
+
/**
|
|
39
|
+
* Same as {@link clampN} for 4D tensors.
|
|
40
|
+
*
|
|
41
|
+
* @param out - output tensor
|
|
42
|
+
* @param a - input tensor
|
|
43
|
+
* @param b - scalar (min)
|
|
44
|
+
* @param c - scalar (max)
|
|
45
|
+
*/
|
|
46
|
+
export declare const clampN4: import("./api.js").TensorOpTNN<number, number, import("./tensor.js").Tensor4<number>, import("./tensor.js").Tensor4<number>>;
|
|
47
|
+
//# sourceMappingURL=clampn.d.ts.map
|
package/clampn.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { clamp as op } from "@thi.ng/math/interval";
|
|
2
|
+
import { defOpTNN } from "./defoptnn.js";
|
|
3
|
+
const [a, b, c, d, e] = defOpTNN(op);
|
|
4
|
+
const clampN = a;
|
|
5
|
+
const clampN1 = b;
|
|
6
|
+
const clampN2 = c;
|
|
7
|
+
const clampN3 = d;
|
|
8
|
+
const clampN4 = e;
|
|
9
|
+
export {
|
|
10
|
+
clampN,
|
|
11
|
+
clampN1,
|
|
12
|
+
clampN2,
|
|
13
|
+
clampN3,
|
|
14
|
+
clampN4
|
|
15
|
+
};
|
package/cos.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Componentwise computes `Math.cos` 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 cos: import("./api.js").MultiTensorOpT<number>;
|
|
9
|
+
/**
|
|
10
|
+
* Same as {@link cos} for 1D tensors.
|
|
11
|
+
*
|
|
12
|
+
* @param out - output tensor
|
|
13
|
+
* @param a - input tensor
|
|
14
|
+
*/
|
|
15
|
+
export declare const cos1: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor1<number>, import("./tensor.js").Tensor1<number>>;
|
|
16
|
+
/**
|
|
17
|
+
* Same as {@link cos} for 2D tensors.
|
|
18
|
+
*
|
|
19
|
+
* @param out - output tensor
|
|
20
|
+
* @param a - input tensor
|
|
21
|
+
*/
|
|
22
|
+
export declare const cos2: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor2<number>, import("./tensor.js").Tensor2<number>>;
|
|
23
|
+
/**
|
|
24
|
+
* Same as {@link cos} for 3D tensors.
|
|
25
|
+
*
|
|
26
|
+
* @param out - output tensor
|
|
27
|
+
* @param a - input tensor
|
|
28
|
+
*/
|
|
29
|
+
export declare const cos3: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor3<number>, import("./tensor.js").Tensor3<number>>;
|
|
30
|
+
/**
|
|
31
|
+
* Same as {@link cos} for 4D tensors.
|
|
32
|
+
*
|
|
33
|
+
* @param out - output tensor
|
|
34
|
+
* @param a - input tensor
|
|
35
|
+
*/
|
|
36
|
+
export declare const cos4: import("./api.js").TensorOpT<number, number, import("./tensor.js").Tensor4<number>, import("./tensor.js").Tensor4<number>>;
|
|
37
|
+
//# sourceMappingURL=cos.d.ts.map
|
package/cos.js
ADDED
package/defopn.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Fn } from "@thi.ng/api";
|
|
2
|
+
import type { MultiTensorOpN, TensorOpN } 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 TensorOpN}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 defOpN: <A = number, B = A>(fn: Fn<A, B>) => [MultiTensorOpN<A, B>, TensorOpN<A, B, Tensor1<B>>, TensorOpN<A, B, Tensor2<B>>, TensorOpN<A, B, Tensor3<B>>, TensorOpN<A, B, Tensor4<B>>];
|
|
13
|
+
//# sourceMappingURL=defopn.d.ts.map
|
package/defopn.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { top } from "./top.js";
|
|
2
|
+
const defOpN = (fn) => {
|
|
3
|
+
const f1 = (out, a) => {
|
|
4
|
+
const {
|
|
5
|
+
data,
|
|
6
|
+
offset,
|
|
7
|
+
shape: [sx],
|
|
8
|
+
stride: [tx]
|
|
9
|
+
} = out;
|
|
10
|
+
for (let x = 0; x < sx; x++) data[offset + x * tx] = fn(a);
|
|
11
|
+
return out;
|
|
12
|
+
};
|
|
13
|
+
const f2 = (out, a) => {
|
|
14
|
+
const {
|
|
15
|
+
data,
|
|
16
|
+
shape: [sx, sy],
|
|
17
|
+
stride: [tx, ty],
|
|
18
|
+
offset
|
|
19
|
+
} = out;
|
|
20
|
+
for (let x = 0; x < sx; x++) {
|
|
21
|
+
const ox = offset + x * tx;
|
|
22
|
+
for (let y = 0; y < sy; y++) data[ox + y * ty] = fn(a);
|
|
23
|
+
}
|
|
24
|
+
return out;
|
|
25
|
+
};
|
|
26
|
+
const f3 = (out, a) => {
|
|
27
|
+
const {
|
|
28
|
+
data,
|
|
29
|
+
shape: [sx, sy, sz],
|
|
30
|
+
stride: [tx, ty, tz],
|
|
31
|
+
offset
|
|
32
|
+
} = out;
|
|
33
|
+
for (let x = 0; x < sx; x++) {
|
|
34
|
+
const ox = offset + x * tx;
|
|
35
|
+
for (let y = 0; y < sy; y++) {
|
|
36
|
+
const oy = ox + y * ty;
|
|
37
|
+
for (let z = 0; z < sz; z++) data[oy + z * tz] = fn(a);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return out;
|
|
41
|
+
};
|
|
42
|
+
const f4 = (out, a) => {
|
|
43
|
+
const {
|
|
44
|
+
data,
|
|
45
|
+
shape: [sx, sy, sz, sw],
|
|
46
|
+
stride: [tx, ty, tz, tw],
|
|
47
|
+
offset
|
|
48
|
+
} = out;
|
|
49
|
+
for (let x = 0; x < sx; x++) {
|
|
50
|
+
const ox = offset + x * tx;
|
|
51
|
+
for (let y = 0; y < sy; y++) {
|
|
52
|
+
const oy = ox + y * ty;
|
|
53
|
+
for (let z = 0; z < sz; z++) {
|
|
54
|
+
const oz = oy + z * tz;
|
|
55
|
+
for (let w = 0; w < sw; w++) data[oz + w * tw] = fn(a);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return out;
|
|
60
|
+
};
|
|
61
|
+
return [top(0, void 0, f1, f2, f3, f4), f1, f2, f3, f4];
|
|
62
|
+
};
|
|
63
|
+
export {
|
|
64
|
+
defOpN
|
|
65
|
+
};
|
package/defoprt.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Fn0, Fn2 } from "@thi.ng/api";
|
|
2
|
+
import type { MultiTensorOpRT, TensorOpRT } from "./api.js";
|
|
3
|
+
import type { Tensor1, Tensor2, Tensor3, Tensor4 } from "./tensor.js";
|
|
4
|
+
/**
|
|
5
|
+
* Higher order tensor reduction op factory. Takes given reduction `rfn` and
|
|
6
|
+
* `init` function to produce an initial result. Returns a 4-tuple of
|
|
7
|
+
* {@link TensorOpRT}s applying the given function component-wise. The result
|
|
8
|
+
* tuple uses this order: `[polymorphic, 1d, 2d, 3d]`.
|
|
9
|
+
*
|
|
10
|
+
* @param rfn
|
|
11
|
+
* @param init
|
|
12
|
+
*/
|
|
13
|
+
export declare const defOpRT: <A = number, B = A>(rfn: Fn2<B, A, B>, init: Fn0<B>) => [MultiTensorOpRT<A, B>, TensorOpRT<A, B, Tensor1<A>>, TensorOpRT<A, B, Tensor2<A>>, TensorOpRT<A, B, Tensor3<A>>, TensorOpRT<A, B, Tensor4<A>>];
|
|
14
|
+
//# sourceMappingURL=defoprt.d.ts.map
|
package/defoprt.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { top } from "./top.js";
|
|
2
|
+
const defOpRT = (rfn, init) => {
|
|
3
|
+
const f1 = (a) => {
|
|
4
|
+
const {
|
|
5
|
+
data,
|
|
6
|
+
offset,
|
|
7
|
+
shape: [sx],
|
|
8
|
+
stride: [tx]
|
|
9
|
+
} = a;
|
|
10
|
+
let res = init();
|
|
11
|
+
for (let x = 0; x < sx; x++) {
|
|
12
|
+
res = rfn(res, data[offset + x * tx]);
|
|
13
|
+
}
|
|
14
|
+
return res;
|
|
15
|
+
};
|
|
16
|
+
const f2 = (a) => {
|
|
17
|
+
const {
|
|
18
|
+
data,
|
|
19
|
+
offset,
|
|
20
|
+
shape: [sx, sy],
|
|
21
|
+
stride: [tx, ty]
|
|
22
|
+
} = a;
|
|
23
|
+
let res = init();
|
|
24
|
+
for (let x = 0; x < sx; x++) {
|
|
25
|
+
const ox = offset + x * tx;
|
|
26
|
+
for (let y = 0; y < sy; y++) {
|
|
27
|
+
res = rfn(res, data[ox + y * ty]);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return res;
|
|
31
|
+
};
|
|
32
|
+
const f3 = (a) => {
|
|
33
|
+
const {
|
|
34
|
+
data,
|
|
35
|
+
offset,
|
|
36
|
+
shape: [sx, sy, sz],
|
|
37
|
+
stride: [tx, ty, tz]
|
|
38
|
+
} = a;
|
|
39
|
+
let res = init();
|
|
40
|
+
for (let x = 0; x < sx; x++) {
|
|
41
|
+
const ox = offset + x * tx;
|
|
42
|
+
for (let y = 0; y < sy; y++) {
|
|
43
|
+
const oy = ox + y * ty;
|
|
44
|
+
for (let z = 0; z < sz; z++) {
|
|
45
|
+
res = rfn(res, data[oy + z * tz]);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return res;
|
|
50
|
+
};
|
|
51
|
+
const f4 = (a) => {
|
|
52
|
+
const {
|
|
53
|
+
data,
|
|
54
|
+
offset,
|
|
55
|
+
shape: [sx, sy, sz, sw],
|
|
56
|
+
stride: [tx, ty, tz, tw]
|
|
57
|
+
} = a;
|
|
58
|
+
let res = init();
|
|
59
|
+
for (let x = 0; x < sx; x++) {
|
|
60
|
+
const ox = offset + x * tx;
|
|
61
|
+
for (let y = 0; y < sy; y++) {
|
|
62
|
+
const oy = ox + y * ty;
|
|
63
|
+
for (let z = 0; z < sz; z++) {
|
|
64
|
+
const oz = oy + z * tz;
|
|
65
|
+
for (let w = 0; w < sw; w++) {
|
|
66
|
+
res = rfn(res, data[oz + w * tw]);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return res;
|
|
72
|
+
};
|
|
73
|
+
return [top(0, void 0, f1, f2, f3, f4), f1, f2, f3, f4];
|
|
74
|
+
};
|
|
75
|
+
export {
|
|
76
|
+
defOpRT
|
|
77
|
+
};
|
package/defoprtt.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Fn0, Fn3 } from "@thi.ng/api";
|
|
2
|
+
import type { MultiTensorOpRTT, TensorOpRTT } from "./api.js";
|
|
3
|
+
import type { Tensor1, Tensor2, Tensor3, Tensor4 } from "./tensor.js";
|
|
4
|
+
/**
|
|
5
|
+
* Higher order tensor reduction op factory. Takes given reduction `rfn` and
|
|
6
|
+
* `init` function to produce an initial result. Returns a 4-tuple of
|
|
7
|
+
* {@link TensorOpRTT}s applying the given function component-wise. The result
|
|
8
|
+
* tuple uses this order: `[polymorphic, 1d, 2d, 3d]`.
|
|
9
|
+
*
|
|
10
|
+
* @param rfn
|
|
11
|
+
* @param init
|
|
12
|
+
*/
|
|
13
|
+
export declare const defOpRTT: <A = number, B = A>(rfn: Fn3<B, A, A, B>, init: Fn0<B>) => [MultiTensorOpRTT<A, B>, TensorOpRTT<A, B, Tensor1<A>>, TensorOpRTT<A, B, Tensor2<A>>, TensorOpRTT<A, B, Tensor3<A>>, TensorOpRTT<A, B, Tensor4<A>>];
|
|
14
|
+
//# sourceMappingURL=defoprtt.d.ts.map
|
package/defoprtt.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { top } from "./top.js";
|
|
2
|
+
const defOpRTT = (rfn, init) => {
|
|
3
|
+
const f1 = (a, b) => {
|
|
4
|
+
const {
|
|
5
|
+
data: adata,
|
|
6
|
+
offset: oa,
|
|
7
|
+
shape: [sx],
|
|
8
|
+
stride: [txa]
|
|
9
|
+
} = a;
|
|
10
|
+
const {
|
|
11
|
+
data: bdata,
|
|
12
|
+
offset: ob,
|
|
13
|
+
stride: [txb]
|
|
14
|
+
} = b;
|
|
15
|
+
let res = init();
|
|
16
|
+
for (let x = 0; x < sx; x++) {
|
|
17
|
+
res = rfn(res, adata[oa + x * txa], bdata[ob + x * txb]);
|
|
18
|
+
}
|
|
19
|
+
return res;
|
|
20
|
+
};
|
|
21
|
+
const f2 = (a, b) => {
|
|
22
|
+
const {
|
|
23
|
+
data: adata,
|
|
24
|
+
offset: oa,
|
|
25
|
+
shape: [sx, sy],
|
|
26
|
+
stride: [txa, tya]
|
|
27
|
+
} = a;
|
|
28
|
+
const {
|
|
29
|
+
data: bdata,
|
|
30
|
+
offset: ob,
|
|
31
|
+
stride: [txb, tyb]
|
|
32
|
+
} = b;
|
|
33
|
+
let res = init();
|
|
34
|
+
for (let x = 0; x < sx; x++) {
|
|
35
|
+
const oax = oa + x * txa;
|
|
36
|
+
const obx = ob + x * txb;
|
|
37
|
+
for (let y = 0; y < sy; y++) {
|
|
38
|
+
res = rfn(res, adata[oax + y * tya], bdata[obx + y * tyb]);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return res;
|
|
42
|
+
};
|
|
43
|
+
const f3 = (a, b) => {
|
|
44
|
+
const {
|
|
45
|
+
data: adata,
|
|
46
|
+
offset: oa,
|
|
47
|
+
shape: [sx, sy, sz],
|
|
48
|
+
stride: [txa, tya, tza]
|
|
49
|
+
} = a;
|
|
50
|
+
const {
|
|
51
|
+
data: bdata,
|
|
52
|
+
offset: ob,
|
|
53
|
+
stride: [txb, tyb, tzb]
|
|
54
|
+
} = b;
|
|
55
|
+
let res = init();
|
|
56
|
+
for (let x = 0; x < sx; x++) {
|
|
57
|
+
const oax = oa + x * txa;
|
|
58
|
+
const obx = ob + x * txb;
|
|
59
|
+
for (let y = 0; y < sy; y++) {
|
|
60
|
+
const oay = oax + y * tya;
|
|
61
|
+
const oby = obx + y * tyb;
|
|
62
|
+
for (let z = 0; z < sz; z++) {
|
|
63
|
+
res = rfn(res, adata[oay + z * tza], bdata[oby + z * tzb]);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return res;
|
|
68
|
+
};
|
|
69
|
+
const f4 = (a, b) => {
|
|
70
|
+
const {
|
|
71
|
+
data: adata,
|
|
72
|
+
offset: oa,
|
|
73
|
+
shape: [sx, sy, sz, sw],
|
|
74
|
+
stride: [txa, tya, tza, twa]
|
|
75
|
+
} = a;
|
|
76
|
+
const {
|
|
77
|
+
data: bdata,
|
|
78
|
+
offset: ob,
|
|
79
|
+
stride: [txb, tyb, tzb, twb]
|
|
80
|
+
} = b;
|
|
81
|
+
let res = init();
|
|
82
|
+
for (let x = 0; x < sx; x++) {
|
|
83
|
+
const oax = oa + x * txa;
|
|
84
|
+
const obx = ob + x * txb;
|
|
85
|
+
for (let y = 0; y < sy; y++) {
|
|
86
|
+
const oay = oax + y * tya;
|
|
87
|
+
const oby = obx + y * tyb;
|
|
88
|
+
for (let z = 0; z < sz; z++) {
|
|
89
|
+
const oaz = oay + z * tza;
|
|
90
|
+
const obz = oby + z * tzb;
|
|
91
|
+
for (let w = 0; w < sw; w++) {
|
|
92
|
+
res = rfn(
|
|
93
|
+
res,
|
|
94
|
+
adata[oaz + w * twa],
|
|
95
|
+
bdata[obz + w * twb]
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return res;
|
|
102
|
+
};
|
|
103
|
+
return [
|
|
104
|
+
top(0, void 0, f1, f2, f3, f4),
|
|
105
|
+
f1,
|
|
106
|
+
f2,
|
|
107
|
+
f3,
|
|
108
|
+
f4
|
|
109
|
+
];
|
|
110
|
+
};
|
|
111
|
+
export {
|
|
112
|
+
defOpRTT
|
|
113
|
+
};
|