@thi.ng/tensors 0.10.13 → 0.11.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/README.md +2 -2
- package/api.d.ts +204 -173
- package/broadcast.d.ts +2 -2
- package/cdf.d.ts +25 -0
- package/cdf.js +25 -0
- package/convert.d.ts +1 -1
- package/diagonal.d.ts +2 -3
- package/diagonal.js +8 -10
- package/find.d.ts +4 -0
- package/find.js +14 -0
- package/histogram.d.ts +69 -0
- package/histogram.js +60 -0
- package/identity.d.ts +2 -3
- package/index.d.ts +3 -0
- package/index.js +3 -0
- package/integrate.d.ts +2 -3
- package/integrate.js +1 -1
- package/kernels.d.ts +7 -7
- package/mulm.d.ts +2 -2
- package/mulv.d.ts +2 -2
- package/normalize.d.ts +2 -2
- package/normalize.js +1 -1
- package/package.json +13 -12
- package/rand-distrib.d.ts +6 -7
- package/range.d.ts +3 -4
- package/range.js +1 -1
- package/sample.d.ts +8 -9
- package/sample.js +25 -5
- package/select.d.ts +5 -6
- package/set.d.ts +1 -1
- package/softmax.d.ts +2 -2
- package/svd.d.ts +5 -5
- package/tensor.d.ts +21 -20
- package/tensor.js +64 -57
- package/top.js +2 -2
package/diagonal.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { sum as vsum } from "@thi.ng/vectors/sum";
|
|
2
2
|
import { sum } from "./sum.js";
|
|
3
3
|
import { Tensor1 } from "./tensor.js";
|
|
4
|
-
const diagonal = (a) =>
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
);
|
|
13
|
-
};
|
|
4
|
+
const diagonal = (a) => new Tensor1(
|
|
5
|
+
a.type,
|
|
6
|
+
a.storage,
|
|
7
|
+
a.data,
|
|
8
|
+
[Math.min(...a.shape)],
|
|
9
|
+
[vsum(a.stride)],
|
|
10
|
+
a.offset
|
|
11
|
+
);
|
|
14
12
|
const trace = (a) => sum(diagonal(a));
|
|
15
13
|
export {
|
|
16
14
|
diagonal,
|
package/find.d.ts
ADDED
package/find.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const findIndex = (a, pred, start = 0, end = a.length) => {
|
|
2
|
+
const {
|
|
3
|
+
offset: oa,
|
|
4
|
+
stride: [ta],
|
|
5
|
+
data: adata
|
|
6
|
+
} = a;
|
|
7
|
+
for (let i = start; i < end; i++) {
|
|
8
|
+
if (pred(adata[oa + i * ta])) return i;
|
|
9
|
+
}
|
|
10
|
+
return -1;
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
findIndex
|
|
14
|
+
};
|
package/histogram.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { Range1_24 } from "@thi.ng/api";
|
|
2
|
+
import type { ITensor, ITensor1 } from "./api.js";
|
|
3
|
+
/**
|
|
4
|
+
* Computes the histogram of given uint-based tensor. Returns histogram as a 1D
|
|
5
|
+
* tensor of `u32` values. The `depth` param defines the value range (as number
|
|
6
|
+
* of bits) of the input values (max. 24 bits). The optional `mask` and `shift`
|
|
7
|
+
* params are used to transform input values like so: `(x >>> shift) & mask`.
|
|
8
|
+
* This allows extracting sub-ranges from a packed integer representation (e.g.
|
|
9
|
+
* indidivual color channels from a pixel buffer).
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* Also see {@link equalizeHistogram} and {@link applyLUT}.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts tangle:../export/histogram-uint.ts
|
|
16
|
+
* import { histogramUint, tensor } from "@thi.ng/tensors";
|
|
17
|
+
*
|
|
18
|
+
* const src = tensor("u8", [3,3], { data: [12,4,4, 16,16,32, 64,48,4] });
|
|
19
|
+
*
|
|
20
|
+
* // compute histogram with input value range = 8 bits
|
|
21
|
+
* const hist = histogramUint(src, 8);
|
|
22
|
+
*
|
|
23
|
+
* console.log(hist.data);
|
|
24
|
+
* // Uint8Array(256) [
|
|
25
|
+
* // 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
|
|
26
|
+
* // 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
27
|
+
* // 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
28
|
+
* // 1, 0, 0, 0, 0, 0, 0 ...
|
|
29
|
+
* // ]
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @param src
|
|
33
|
+
* @param depth
|
|
34
|
+
* @param mask
|
|
35
|
+
* @param shift
|
|
36
|
+
*/
|
|
37
|
+
export declare const histogramUint: (src: ITensor, depth: Range1_24, mask?: number, shift?: number) => ITensor1<number>;
|
|
38
|
+
/**
|
|
39
|
+
* Takes a 1D tensor containing a histogram (e.g. obtained via
|
|
40
|
+
* {@link histogramUint}) and applies histogram equalization by first
|
|
41
|
+
* normalizing the histogram, computing its cumulative distribution (via
|
|
42
|
+
* {@link cdf}), determining the used min/max input value range and then
|
|
43
|
+
* rescaling values to produce a lookup table (LUT) for remapping input values
|
|
44
|
+
* via {@link applyLUT}.
|
|
45
|
+
*
|
|
46
|
+
* @remarks
|
|
47
|
+
* References:
|
|
48
|
+
*
|
|
49
|
+
* - https://en.wikipedia.org/wiki/Histogram_equalization
|
|
50
|
+
*
|
|
51
|
+
* @param out
|
|
52
|
+
* @param src
|
|
53
|
+
* @param depth
|
|
54
|
+
* @param numSamples
|
|
55
|
+
* @param threshold
|
|
56
|
+
*/
|
|
57
|
+
export declare const equalizeHistogram: (out: ITensor1 | null, src: ITensor1, depth: number, numSamples: number, threshold?: number) => ITensor1;
|
|
58
|
+
/**
|
|
59
|
+
* Applies given lookup table to `a` and writes results to `out`. I.e. `out[i] =
|
|
60
|
+
* lut[a[i]]`. This is intended as last step of a histogram equalization process
|
|
61
|
+
* to transform `a` via applying the histogram obtained via
|
|
62
|
+
* {@link equalizeHistogram}.
|
|
63
|
+
*
|
|
64
|
+
* @param out
|
|
65
|
+
* @param a
|
|
66
|
+
* @param lut
|
|
67
|
+
*/
|
|
68
|
+
export declare const applyLUT: (out: ITensor | null, a: ITensor, lut: ITensor1) => import("./api.js").ITensor0<number>;
|
|
69
|
+
//# sourceMappingURL=histogram.d.ts.map
|
package/histogram.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { cdf } from "./cdf.js";
|
|
2
|
+
import { defOpT } from "./defopt.js";
|
|
3
|
+
import { ensureShape } from "./errors.js";
|
|
4
|
+
import { findIndex } from "./find.js";
|
|
5
|
+
import { mulN } from "./muln.js";
|
|
6
|
+
import { tensor } from "./tensor.js";
|
|
7
|
+
const histogramUint = (src, depth, mask = (1 << depth) - 1, shift = 0) => {
|
|
8
|
+
const histType = src.length < 256 ? "u8" : src.length < 65536 ? "u16" : "u32";
|
|
9
|
+
const histogram = tensor(histType, [1 << depth]);
|
|
10
|
+
if (src.dim > 1) src = src.reshape([src.length]);
|
|
11
|
+
const {
|
|
12
|
+
offset: oa,
|
|
13
|
+
shape: [sa],
|
|
14
|
+
stride: [ta],
|
|
15
|
+
data: adata
|
|
16
|
+
} = src;
|
|
17
|
+
for (let i = 0; i < sa; i++)
|
|
18
|
+
histogram.data[adata[oa + i * ta] >>> shift & mask]++;
|
|
19
|
+
return histogram;
|
|
20
|
+
};
|
|
21
|
+
const equalizeHistogram = (out, src, depth, numSamples, threshold = 0) => {
|
|
22
|
+
!out && (out = src);
|
|
23
|
+
ensureShape(out, src.shape);
|
|
24
|
+
const norm = mulN(tensor("f64", [src.length]), src, 1 / numSamples);
|
|
25
|
+
const $cdf = cdf(null, norm);
|
|
26
|
+
const lo = findIndex($cdf, (x) => x > threshold);
|
|
27
|
+
if (lo < 0) return out.fill(0);
|
|
28
|
+
const {
|
|
29
|
+
offset: oc,
|
|
30
|
+
shape: [sc],
|
|
31
|
+
stride: [tc],
|
|
32
|
+
data: cdata
|
|
33
|
+
} = $cdf;
|
|
34
|
+
const {
|
|
35
|
+
offset: oo,
|
|
36
|
+
stride: [to],
|
|
37
|
+
data: odata
|
|
38
|
+
} = out;
|
|
39
|
+
const base = cdata[oc + lo * tc];
|
|
40
|
+
const scale = (2 ** depth - 1) / (cdata[oc + (sc - 1) * tc] - base);
|
|
41
|
+
for (let i = 0; i < sc; i++) {
|
|
42
|
+
odata[oo + i * to] = Math.max(0, scale * (cdata[oc + i * tc] - base));
|
|
43
|
+
}
|
|
44
|
+
return out;
|
|
45
|
+
};
|
|
46
|
+
const applyLUT = (out, a, lut) => {
|
|
47
|
+
!out && (out = a);
|
|
48
|
+
ensureShape(out, a.shape);
|
|
49
|
+
const {
|
|
50
|
+
offset: ol,
|
|
51
|
+
stride: [tl],
|
|
52
|
+
data: ldata
|
|
53
|
+
} = lut;
|
|
54
|
+
return defOpT((x) => ldata[ol + x * tl])(out, a);
|
|
55
|
+
};
|
|
56
|
+
export {
|
|
57
|
+
applyLUT,
|
|
58
|
+
equalizeHistogram,
|
|
59
|
+
histogramUint
|
|
60
|
+
};
|
package/identity.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { TensorOpts, Type } from "./api.js";
|
|
2
|
-
import { Tensor2 } from "./tensor.js";
|
|
1
|
+
import type { ITensor2, TensorOpts, Type } from "./api.js";
|
|
3
2
|
/**
|
|
4
3
|
* Creates a square identity matrix of given `size` and options.
|
|
5
4
|
*
|
|
@@ -7,5 +6,5 @@ import { Tensor2 } from "./tensor.js";
|
|
|
7
6
|
* @param size
|
|
8
7
|
* @param opts
|
|
9
8
|
*/
|
|
10
|
-
export declare const identity: <T extends Exclude<Type, "str">>(type: T, size: number, opts?: Pick<TensorOpts<any, any>, "storage">) =>
|
|
9
|
+
export declare const identity: <T extends Exclude<Type, "str">>(type: T, size: number, opts?: Pick<TensorOpts<any, any>, "storage">) => ITensor2;
|
|
11
10
|
//# sourceMappingURL=identity.d.ts.map
|
package/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from "./addn.js";
|
|
|
4
4
|
export * from "./api.js";
|
|
5
5
|
export * from "./apply-kernel.js";
|
|
6
6
|
export * from "./broadcast.js";
|
|
7
|
+
export * from "./cdf.js";
|
|
7
8
|
export * from "./clamp.js";
|
|
8
9
|
export * from "./clampn.js";
|
|
9
10
|
export * from "./convert.js";
|
|
@@ -24,8 +25,10 @@ export * from "./dot.js";
|
|
|
24
25
|
export * from "./errors.js";
|
|
25
26
|
export * from "./exp.js";
|
|
26
27
|
export * from "./exp2.js";
|
|
28
|
+
export * from "./find.js";
|
|
27
29
|
export * from "./filtered-indices.js";
|
|
28
30
|
export * from "./format.js";
|
|
31
|
+
export * from "./histogram.js";
|
|
29
32
|
export * from "./identity.js";
|
|
30
33
|
export * from "./integrate.js";
|
|
31
34
|
export * from "./kernels.js";
|
package/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export * from "./addn.js";
|
|
|
4
4
|
export * from "./api.js";
|
|
5
5
|
export * from "./apply-kernel.js";
|
|
6
6
|
export * from "./broadcast.js";
|
|
7
|
+
export * from "./cdf.js";
|
|
7
8
|
export * from "./clamp.js";
|
|
8
9
|
export * from "./clampn.js";
|
|
9
10
|
export * from "./convert.js";
|
|
@@ -24,8 +25,10 @@ export * from "./dot.js";
|
|
|
24
25
|
export * from "./errors.js";
|
|
25
26
|
export * from "./exp.js";
|
|
26
27
|
export * from "./exp2.js";
|
|
28
|
+
export * from "./find.js";
|
|
27
29
|
export * from "./filtered-indices.js";
|
|
28
30
|
export * from "./format.js";
|
|
31
|
+
export * from "./histogram.js";
|
|
29
32
|
export * from "./identity.js";
|
|
30
33
|
export * from "./integrate.js";
|
|
31
34
|
export * from "./kernels.js";
|
package/integrate.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Fn } from "@thi.ng/api";
|
|
2
|
-
import type { ITensor } from "./api.js";
|
|
3
|
-
import { Tensor1 } from "./tensor.js";
|
|
2
|
+
import type { ITensor, ITensor1 } from "./api.js";
|
|
4
3
|
/**
|
|
5
4
|
* Integrates given tensor along innermost dimension and writes result to 1D
|
|
6
5
|
* tensor `out` (or creates new one).
|
|
@@ -30,5 +29,5 @@ import { Tensor1 } from "./tensor.js";
|
|
|
30
29
|
* @param a
|
|
31
30
|
* @param fn
|
|
32
31
|
*/
|
|
33
|
-
export declare const integrate: (out:
|
|
32
|
+
export declare const integrate: (out: ITensor1 | null, a: ITensor, fn?: Fn<ITensor, number>) => ITensor1;
|
|
34
33
|
//# sourceMappingURL=integrate.d.ts.map
|
package/integrate.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ensureShape } from "./errors.js";
|
|
2
|
-
import { Tensor1 } from "./tensor.js";
|
|
3
2
|
import { sum } from "./sum.js";
|
|
3
|
+
import { Tensor1 } from "./tensor.js";
|
|
4
4
|
const integrate = (out, a, fn = sum) => {
|
|
5
5
|
const { shape, dim } = a;
|
|
6
6
|
const odim = shape[shape.length - 1];
|
package/kernels.d.ts
CHANGED
|
@@ -2,46 +2,46 @@ import type { KernelSpec } from "./api.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* 1D Sobel convolution kernel.
|
|
4
4
|
*/
|
|
5
|
-
export declare const SOBEL1: import("./
|
|
5
|
+
export declare const SOBEL1: import("./api.js").ITensor1<number>;
|
|
6
6
|
/**
|
|
7
7
|
* 2D Sobel convolution kernel (along outer axis).
|
|
8
8
|
*
|
|
9
9
|
* @remarks
|
|
10
10
|
* Use `SOBEL2.transpose([1, 0])` for inner axis.
|
|
11
11
|
*/
|
|
12
|
-
export declare const SOBEL2: import("./
|
|
12
|
+
export declare const SOBEL2: import("./api.js").ITensor2<number>;
|
|
13
13
|
/**
|
|
14
14
|
* 3D Sobel convolution kernel (along outer axis).
|
|
15
15
|
*
|
|
16
16
|
* @remarks
|
|
17
17
|
* Use `SOBEL3.transpose()` for other axes.
|
|
18
18
|
*/
|
|
19
|
-
export declare const SOBEL3: import("./
|
|
19
|
+
export declare const SOBEL3: import("./api.js").ITensor3<number>;
|
|
20
20
|
/**
|
|
21
21
|
* 2D edge detection convolution kernel factory for given integer radius `r`.
|
|
22
22
|
* Returns 2D tensor of size `2*r+1`.
|
|
23
23
|
*
|
|
24
24
|
* @param r
|
|
25
25
|
*/
|
|
26
|
-
export declare const EDGE2: (r: number) => import("./
|
|
26
|
+
export declare const EDGE2: (r: number) => import("./api.js").ITensor2<number>;
|
|
27
27
|
/**
|
|
28
28
|
* 2D sharpen 3x3 kernel preset.
|
|
29
29
|
*/
|
|
30
|
-
export declare const SHARPEN2_3x3: import("./
|
|
30
|
+
export declare const SHARPEN2_3x3: import("./api.js").ITensor2<number>;
|
|
31
31
|
/**
|
|
32
32
|
* 2D box blur convolution kernel factory for given integer radius `r`. Returns
|
|
33
33
|
* 2D tensor of size `2*r+1`.
|
|
34
34
|
*
|
|
35
35
|
* @param r
|
|
36
36
|
*/
|
|
37
|
-
export declare const BOX_BLUR2: (r: number) => import("./
|
|
37
|
+
export declare const BOX_BLUR2: (r: number) => import("./api.js").ITensor2<number>;
|
|
38
38
|
/**
|
|
39
39
|
* 2D Gaussian blur kernel factory for given integer radius `r`. Returns 2D
|
|
40
40
|
* tensor of size `2r+1`.
|
|
41
41
|
*
|
|
42
42
|
* @param r -
|
|
43
43
|
*/
|
|
44
|
-
export declare const GAUSSIAN_BLUR2: (r: number) => import("./
|
|
44
|
+
export declare const GAUSSIAN_BLUR2: (r: number) => import("./api.js").ITensor2<number>;
|
|
45
45
|
/**
|
|
46
46
|
* Max. pool kernel factory for given window size and use with
|
|
47
47
|
* {@link applyKernel}. The kernel produces the maximum value in its window.
|
package/mulm.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ITensor2 } from "./api.js";
|
|
2
2
|
/**
|
|
3
3
|
* Matrix-matrix multiplication between matrix `a` (MxN) and matrix `b` (PxQ).
|
|
4
4
|
* If `out` is given, it MUST be a MxQ tensor. If null then a new one will be
|
|
@@ -8,5 +8,5 @@ import { type Tensor2 } from "./tensor.js";
|
|
|
8
8
|
* @param a
|
|
9
9
|
* @param b
|
|
10
10
|
*/
|
|
11
|
-
export declare const mulM: (out:
|
|
11
|
+
export declare const mulM: (out: ITensor2 | null, a: ITensor2, b: ITensor2) => ITensor2;
|
|
12
12
|
//# sourceMappingURL=mulm.d.ts.map
|
package/mulv.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ITensor1, ITensor2 } from "./api.js";
|
|
2
2
|
/**
|
|
3
3
|
* Matrix-vector multiplication. If `out` is null, a new 1D tensor will be
|
|
4
4
|
* created, using vector `b`'s type and storage impl.
|
|
@@ -7,5 +7,5 @@ import { type Tensor1, type Tensor2 } from "./tensor.js";
|
|
|
7
7
|
* @param a
|
|
8
8
|
* @param b
|
|
9
9
|
*/
|
|
10
|
-
export declare const mulV: (out:
|
|
10
|
+
export declare const mulV: (out: ITensor1 | null, a: ITensor2, b: ITensor1) => ITensor1;
|
|
11
11
|
//# sourceMappingURL=mulv.d.ts.map
|
package/normalize.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TensorOpTNO } from "./api.js";
|
|
2
2
|
/**
|
|
3
3
|
* Normalizes tensor `a` to given magnitude `n` (default: 1) and writes result
|
|
4
4
|
* to `out`. If `out` is null, mutates `a`.
|
|
@@ -7,5 +7,5 @@ import type { ITensor } from "./api.js";
|
|
|
7
7
|
* @param a
|
|
8
8
|
* @param n
|
|
9
9
|
*/
|
|
10
|
-
export declare const normalize:
|
|
10
|
+
export declare const normalize: TensorOpTNO;
|
|
11
11
|
//# sourceMappingURL=normalize.d.ts.map
|
package/normalize.js
CHANGED
|
@@ -4,7 +4,7 @@ import { set } from "./set.js";
|
|
|
4
4
|
const normalize = (out, a, n = 1) => {
|
|
5
5
|
!out && (out = a);
|
|
6
6
|
const m = Math.sqrt(magSq(a));
|
|
7
|
-
return m >= 1e-6 ? mulN(out
|
|
7
|
+
return m >= 1e-6 ? mulN(out, a, n / m) : out !== a ? set(out, a) : out;
|
|
8
8
|
};
|
|
9
9
|
export {
|
|
10
10
|
normalize
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/tensors",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "0D/1D/2D/3D/4D tensors with extensible polymorphic operations and customizable storage",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/thi-ng/umbrella.git"
|
|
11
|
+
"url": "git+https://github.com/thi-ng/umbrella.git",
|
|
12
|
+
"directory": "packages/tensors"
|
|
12
13
|
},
|
|
13
14
|
"homepage": "https://thi.ng/tensors",
|
|
14
15
|
"funding": [
|
|
@@ -39,15 +40,15 @@
|
|
|
39
40
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
40
41
|
},
|
|
41
42
|
"dependencies": {
|
|
42
|
-
"@thi.ng/api": "^8.12.
|
|
43
|
-
"@thi.ng/arrays": "^2.14.
|
|
44
|
-
"@thi.ng/checks": "^3.8.
|
|
45
|
-
"@thi.ng/equiv": "^2.1.
|
|
46
|
-
"@thi.ng/errors": "^2.6.
|
|
47
|
-
"@thi.ng/math": "^5.15.
|
|
48
|
-
"@thi.ng/random": "^4.1.
|
|
49
|
-
"@thi.ng/strings": "^3.9.
|
|
50
|
-
"@thi.ng/vectors": "^8.6.
|
|
43
|
+
"@thi.ng/api": "^8.12.14",
|
|
44
|
+
"@thi.ng/arrays": "^2.14.7",
|
|
45
|
+
"@thi.ng/checks": "^3.8.4",
|
|
46
|
+
"@thi.ng/equiv": "^2.1.104",
|
|
47
|
+
"@thi.ng/errors": "^2.6.3",
|
|
48
|
+
"@thi.ng/math": "^5.15.3",
|
|
49
|
+
"@thi.ng/random": "^4.1.39",
|
|
50
|
+
"@thi.ng/strings": "^3.9.35",
|
|
51
|
+
"@thi.ng/vectors": "^8.6.20"
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|
|
53
54
|
"esbuild": "^0.27.2",
|
|
@@ -342,5 +343,5 @@
|
|
|
342
343
|
"status": "alpha",
|
|
343
344
|
"year": 2018
|
|
344
345
|
},
|
|
345
|
-
"gitHead": "
|
|
346
|
+
"gitHead": "3f0b151fb2283888314eb34206ba50c2dd5c7af6\n"
|
|
346
347
|
}
|
package/rand-distrib.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { Fn0 } from "@thi.ng/api";
|
|
2
|
-
import type { ITensor } from "./api.js";
|
|
3
|
-
|
|
4
|
-
export declare const randDistrib0: (a: Tensor0, rnd?: () => number, n?: number) => Tensor0<number>;
|
|
2
|
+
import type { ITensor, ITensor0, ITensor1, ITensor2, ITensor3, ITensor4 } from "./api.js";
|
|
3
|
+
export declare const randDistrib0: (a: ITensor0, rnd?: () => number, n?: number) => ITensor0;
|
|
5
4
|
/**
|
|
6
5
|
* Same as {@link randDistrib} for 1D tensors.
|
|
7
6
|
*
|
|
@@ -9,7 +8,7 @@ export declare const randDistrib0: (a: Tensor0, rnd?: () => number, n?: number)
|
|
|
9
8
|
* @param rnd
|
|
10
9
|
* @param n
|
|
11
10
|
*/
|
|
12
|
-
export declare const randDistrib1: (a:
|
|
11
|
+
export declare const randDistrib1: (a: ITensor1, rnd?: () => number, n?: number) => ITensor1;
|
|
13
12
|
/**
|
|
14
13
|
* Same as {@link randDistrib} for 2D tensors.
|
|
15
14
|
*
|
|
@@ -17,7 +16,7 @@ export declare const randDistrib1: (a: Tensor1, rnd?: () => number, n?: number)
|
|
|
17
16
|
* @param rnd
|
|
18
17
|
* @param n
|
|
19
18
|
*/
|
|
20
|
-
export declare const randDistrib2: (a:
|
|
19
|
+
export declare const randDistrib2: (a: ITensor2, rnd?: () => number, n?: number) => ITensor2;
|
|
21
20
|
/**
|
|
22
21
|
* Same as {@link randDistrib} for 3D tensors.
|
|
23
22
|
*
|
|
@@ -25,7 +24,7 @@ export declare const randDistrib2: (a: Tensor2, rnd?: () => number, n?: number)
|
|
|
25
24
|
* @param rnd
|
|
26
25
|
* @param n
|
|
27
26
|
*/
|
|
28
|
-
export declare const randDistrib3: (a:
|
|
27
|
+
export declare const randDistrib3: (a: ITensor3, rnd?: () => number, n?: number) => ITensor3;
|
|
29
28
|
/**
|
|
30
29
|
* Same as {@link randDistrib} for 3D tensors.
|
|
31
30
|
*
|
|
@@ -33,7 +32,7 @@ export declare const randDistrib3: (a: Tensor3, rnd?: () => number, n?: number)
|
|
|
33
32
|
* @param rnd
|
|
34
33
|
* @param n
|
|
35
34
|
*/
|
|
36
|
-
export declare const randDistrib4: (a:
|
|
35
|
+
export declare const randDistrib4: (a: ITensor4, rnd?: () => number, n?: number) => ITensor4;
|
|
37
36
|
/**
|
|
38
37
|
* Randomizes given nD tensor `a`, with each component drawn from given random
|
|
39
38
|
* distribution function (default: gaussian/normal distribution) and scaled to
|
package/range.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { NumType, TensorOpts } from "./api.js";
|
|
2
|
-
import { Tensor1 } from "./tensor.js";
|
|
1
|
+
import type { ITensor1, NumType, TensorOpts } from "./api.js";
|
|
3
2
|
export interface RangeOpts<T extends NumType> extends Pick<TensorOpts<T, [number]>, "storage"> {
|
|
4
3
|
/**
|
|
5
4
|
* Tensor data type.
|
|
@@ -14,7 +13,7 @@ export interface RangeOpts<T extends NumType> extends Pick<TensorOpts<T, [number
|
|
|
14
13
|
* @param max
|
|
15
14
|
* @param opts
|
|
16
15
|
*/
|
|
17
|
-
export declare function range<T extends NumType>(max: number, opts?: RangeOpts<T>):
|
|
16
|
+
export declare function range<T extends NumType>(max: number, opts?: RangeOpts<T>): ITensor1;
|
|
18
17
|
/**
|
|
19
18
|
* Creates a 1D tensor of monotonically increasing values in the interval
|
|
20
19
|
* `[min,max)`, using optional `step` and `opts`. If `from <= to`, the default
|
|
@@ -24,5 +23,5 @@ export declare function range<T extends NumType>(max: number, opts?: RangeOpts<T
|
|
|
24
23
|
* @param to
|
|
25
24
|
* @param opts
|
|
26
25
|
*/
|
|
27
|
-
export declare function range<T extends NumType>(from: number, to: number, step?: number, opts?: RangeOpts<T>):
|
|
26
|
+
export declare function range<T extends NumType>(from: number, to: number, step?: number, opts?: RangeOpts<T>): ITensor1;
|
|
28
27
|
//# sourceMappingURL=range.d.ts.map
|
package/range.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { peek } from "@thi.ng/arrays/peek";
|
|
2
2
|
import { isPlainObject } from "@thi.ng/checks";
|
|
3
|
-
import { tensor
|
|
3
|
+
import { tensor } from "./tensor.js";
|
|
4
4
|
function range(...args) {
|
|
5
5
|
const opts = isPlainObject(peek(args)) ? args.pop() : void 0;
|
|
6
6
|
const type = opts?.type ?? "num";
|
package/sample.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { Fn2, Fn3, Fn4, Fn5, FnN, FnN2 } from "@thi.ng/api";
|
|
2
|
-
import type {
|
|
3
|
-
import { type Tensor1 } from "./tensor.js";
|
|
2
|
+
import type { ITensor1, ITensor2, ITensor3, ITensor4 } from "./api.js";
|
|
4
3
|
type BoundaryFn = FnN2;
|
|
5
|
-
type Sampler1 = Fn2<
|
|
6
|
-
type Sampler2 = Fn3<
|
|
7
|
-
type Sampler3 = Fn4<
|
|
8
|
-
type Sampler4 = Fn5<
|
|
4
|
+
type Sampler1 = Fn2<ITensor1, number, number>;
|
|
5
|
+
type Sampler2 = Fn3<ITensor2, number, number, number>;
|
|
6
|
+
type Sampler3 = Fn4<ITensor3, number, number, number, number>;
|
|
7
|
+
type Sampler4 = Fn5<ITensor4, number, number, number, number, number>;
|
|
9
8
|
type BoundaryType = "clamp" | "mirror" | "wrap" | "zero";
|
|
10
9
|
type SamplerType = "nearest" | "linear" | "cubic" | "lanczos";
|
|
11
10
|
interface SamplerKernel {
|
|
@@ -20,8 +19,8 @@ export declare const defSampler1: (kernel: SamplerKernel | SamplerType, boundary
|
|
|
20
19
|
export declare const defSampler2: (kernel: SamplerType | SamplerKernel | [SamplerType | SamplerKernel, SamplerType | SamplerKernel], boundary?: BoundaryType | BoundaryFn | [BoundaryType | BoundaryFn, BoundaryType | BoundaryFn]) => Sampler2;
|
|
21
20
|
export declare const defSampler3: (kernel: SamplerType | SamplerKernel | [SamplerType | SamplerKernel, SamplerType | SamplerKernel, SamplerType | SamplerKernel], boundary?: BoundaryType | BoundaryFn | [BoundaryType | BoundaryFn, BoundaryType | BoundaryFn, BoundaryType | BoundaryFn]) => Sampler3;
|
|
22
21
|
export declare const defSampler4: (kernel: SamplerType | SamplerKernel | [SamplerType | SamplerKernel, SamplerType | SamplerKernel, SamplerType | SamplerKernel, SamplerType | SamplerKernel], boundary?: BoundaryType | BoundaryFn | [BoundaryType | BoundaryFn, BoundaryType | BoundaryFn, BoundaryType | BoundaryFn, BoundaryType | BoundaryFn]) => Sampler4;
|
|
23
|
-
export declare const resample1: (out:
|
|
24
|
-
export declare const resample2: (out:
|
|
25
|
-
export declare const resample3: (out:
|
|
22
|
+
export declare const resample1: (out: ITensor1, a: ITensor1, sampler: Sampler1) => ITensor1;
|
|
23
|
+
export declare const resample2: (out: ITensor2, a: ITensor2, [samplerX, samplerY]: Sampler1[]) => ITensor2;
|
|
24
|
+
export declare const resample3: (out: ITensor3, a: ITensor3, [samplerX, samplerY, samplerZ]: Sampler1[]) => ITensor3;
|
|
26
25
|
export {};
|
|
27
26
|
//# sourceMappingURL=sample.d.ts.map
|
package/sample.js
CHANGED
|
@@ -238,10 +238,18 @@ const resample2 = (out, a, [samplerX, samplerY]) => {
|
|
|
238
238
|
} = a;
|
|
239
239
|
const tmp = tensor("num", [sxa, syo]);
|
|
240
240
|
for (let x = 0; x < sxa; x++) {
|
|
241
|
-
resample1(
|
|
241
|
+
resample1(
|
|
242
|
+
tmp.pick([x, -1]),
|
|
243
|
+
a.pick([x, -1]),
|
|
244
|
+
samplerX
|
|
245
|
+
);
|
|
242
246
|
}
|
|
243
247
|
for (let y = 0; y < syo; y++) {
|
|
244
|
-
resample1(
|
|
248
|
+
resample1(
|
|
249
|
+
out.pick([-1, y]),
|
|
250
|
+
tmp.pick([-1, y]),
|
|
251
|
+
samplerY
|
|
252
|
+
);
|
|
245
253
|
}
|
|
246
254
|
return out;
|
|
247
255
|
};
|
|
@@ -257,7 +265,11 @@ const resample3 = (out, a, [samplerX, samplerY, samplerZ]) => {
|
|
|
257
265
|
const src = a.pick([i]);
|
|
258
266
|
const dest = tmpX.pick([i]);
|
|
259
267
|
for (let j = 0; j < sya; j++) {
|
|
260
|
-
resample1(
|
|
268
|
+
resample1(
|
|
269
|
+
dest.pick([j]),
|
|
270
|
+
src.pick([j]),
|
|
271
|
+
samplerX
|
|
272
|
+
);
|
|
261
273
|
}
|
|
262
274
|
}
|
|
263
275
|
const tmpY = tensor("num", [sxa, syo, szo]);
|
|
@@ -265,12 +277,20 @@ const resample3 = (out, a, [samplerX, samplerY, samplerZ]) => {
|
|
|
265
277
|
const src = tmpX.pick([i]);
|
|
266
278
|
const dest = tmpY.pick([i]);
|
|
267
279
|
for (let j = 0; j < szo; j++) {
|
|
268
|
-
resample1(
|
|
280
|
+
resample1(
|
|
281
|
+
dest.pick([-1, j]),
|
|
282
|
+
src.pick([-1, j]),
|
|
283
|
+
samplerY
|
|
284
|
+
);
|
|
269
285
|
}
|
|
270
286
|
}
|
|
271
287
|
for (let i = 0; i < syo; i++) {
|
|
272
288
|
for (let j = 0; j < szo; j++) {
|
|
273
|
-
resample1(
|
|
289
|
+
resample1(
|
|
290
|
+
out.pick([-1, i, j]),
|
|
291
|
+
tmpY.pick([-1, i, j]),
|
|
292
|
+
samplerZ
|
|
293
|
+
);
|
|
274
294
|
}
|
|
275
295
|
}
|
|
276
296
|
return out;
|
package/select.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Fn, Predicate2 } from "@thi.ng/api";
|
|
2
|
-
import type { ITensor } from "./api.js";
|
|
3
|
-
import type { Tensor1, Tensor2, Tensor3, Tensor4 } from "./tensor.js";
|
|
2
|
+
import type { ITensor, ITensor1, ITensor2, ITensor3, ITensor4 } from "./api.js";
|
|
4
3
|
/**
|
|
5
4
|
* Result type of {@link select}.
|
|
6
5
|
*/
|
|
@@ -16,7 +15,7 @@ export type SelectResult<T> = {
|
|
|
16
15
|
* @param pred
|
|
17
16
|
* @param initial
|
|
18
17
|
*/
|
|
19
|
-
export declare const select1: <A, B>(a:
|
|
18
|
+
export declare const select1: <A, B>(a: ITensor1<A>, xform: Fn<A, B>, pred: Predicate2<B>, initial: B) => SelectResult<B>;
|
|
20
19
|
/**
|
|
21
20
|
* Same as {@link select} for 2D tensors.
|
|
22
21
|
*
|
|
@@ -25,7 +24,7 @@ export declare const select1: <A, B>(a: Tensor1<A>, xform: Fn<A, B>, pred: Predi
|
|
|
25
24
|
* @param pred
|
|
26
25
|
* @param initial
|
|
27
26
|
*/
|
|
28
|
-
export declare const select2: <A, B>(a:
|
|
27
|
+
export declare const select2: <A, B>(a: ITensor2<A>, xform: Fn<A, B>, pred: Predicate2<B>, initial: B) => SelectResult<B>;
|
|
29
28
|
/**
|
|
30
29
|
* Same as {@link select} for 3D tensors.
|
|
31
30
|
*
|
|
@@ -34,7 +33,7 @@ export declare const select2: <A, B>(a: Tensor2<A>, xform: Fn<A, B>, pred: Predi
|
|
|
34
33
|
* @param pred
|
|
35
34
|
* @param initial
|
|
36
35
|
*/
|
|
37
|
-
export declare const select3: <A, B>(a:
|
|
36
|
+
export declare const select3: <A, B>(a: ITensor3<A>, xform: Fn<A, B>, pred: Predicate2<B>, initial: B) => SelectResult<B>;
|
|
38
37
|
/**
|
|
39
38
|
* Same as {@link select} for 4D tensors.
|
|
40
39
|
*
|
|
@@ -43,7 +42,7 @@ export declare const select3: <A, B>(a: Tensor3<A>, xform: Fn<A, B>, pred: Predi
|
|
|
43
42
|
* @param pred
|
|
44
43
|
* @param initial
|
|
45
44
|
*/
|
|
46
|
-
export declare const select4: <A, B>(a:
|
|
45
|
+
export declare const select4: <A, B>(a: ITensor4<A>, xform: Fn<A, B>, pred: Predicate2<B>, initial: B) => SelectResult<B>;
|
|
47
46
|
/**
|
|
48
47
|
* Uses given value transform `xform` and predicate `pred` to select a specific
|
|
49
48
|
* component value and its position in the tensor. The `initial` value is used
|
package/set.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ITensor } from "./api.js";
|
|
2
|
-
export declare const set: <T>(out: ITensor<T>, src: ITensor<T>) => import("./
|
|
2
|
+
export declare const set: <T>(out: ITensor<T>, src: ITensor<T>) => import("./api.js").ITensor0<any>;
|
|
3
3
|
//# sourceMappingURL=set.d.ts.map
|
package/softmax.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TensorOpTNO } from "./api.js";
|
|
2
2
|
/**
|
|
3
3
|
* Computes softmax (aka normalized {@link exp}) of input tensor `src` and
|
|
4
4
|
* writes results to `out` (or if null, back into `src`). The optional
|
|
@@ -23,5 +23,5 @@ import type { ITensor } from "./api.js";
|
|
|
23
23
|
* @param src -
|
|
24
24
|
* @param temperature -
|
|
25
25
|
*/
|
|
26
|
-
export declare const softMax:
|
|
26
|
+
export declare const softMax: TensorOpTNO;
|
|
27
27
|
//# sourceMappingURL=softmax.d.ts.map
|