@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/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://mastodon.thi.ng/@toxi)
|
|
8
8
|
|
|
9
9
|
> [!NOTE]
|
|
10
|
-
> This is one of
|
|
10
|
+
> This is one of 214 standalone projects, maintained as part
|
|
11
11
|
> of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
|
|
12
12
|
> and anti-framework.
|
|
13
13
|
>
|
|
@@ -250,7 +250,7 @@ For Node.js REPL:
|
|
|
250
250
|
const ten = await import("@thi.ng/tensors");
|
|
251
251
|
```
|
|
252
252
|
|
|
253
|
-
Package sizes (brotli'd, pre-treeshake): ESM: 11.
|
|
253
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 11.45 KB
|
|
254
254
|
|
|
255
255
|
## Dependencies
|
|
256
256
|
|
package/api.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Type as $Type, ICopy, IEqualsDelta, IEquiv, ILength, IRelease, Maybe, NumericArray } from "@thi.ng/api";
|
|
2
|
-
import type { Tensor0, Tensor1, Tensor2, Tensor3, Tensor4 } from "./tensor.js";
|
|
3
2
|
export interface TensorData<T = number> extends Iterable<T>, ILength {
|
|
4
3
|
[id: number]: T;
|
|
5
4
|
fill(x: T, start?: number, end?: number): TensorData<T>;
|
|
@@ -12,9 +11,9 @@ export type Shape2 = [number, number];
|
|
|
12
11
|
export type Shape3 = [number, number, number];
|
|
13
12
|
export type Shape4 = [number, number, number, number];
|
|
14
13
|
export type Shape = Shape0 | Shape1 | Shape2 | Shape3 | Shape4;
|
|
15
|
-
export type ShapeTensor<S extends Shape, T> = S extends Shape4 ?
|
|
14
|
+
export type ShapeTensor<S extends Shape, T> = S extends Shape4 ? ITensor4<T> : S extends Shape3 ? ITensor3<T> : S extends Shape2 ? ITensor2<T> : S extends Shape1 ? ITensor1<T> : ITensor0<T>;
|
|
16
15
|
export type Nested<T> = T[] | T[][] | T[][][] | T[][][][];
|
|
17
|
-
export type NestedTensor<N extends Nested<T>, T> = N extends T[][][][] ?
|
|
16
|
+
export type NestedTensor<N extends Nested<T>, T> = N extends T[][][][] ? ITensor4<T> : N extends T[][][] ? ITensor3<T> : N extends T[][] ? ITensor2<T> : ITensor1<T>;
|
|
18
17
|
export interface TypeMap {
|
|
19
18
|
u8: number;
|
|
20
19
|
u8c: number;
|
|
@@ -105,6 +104,7 @@ export interface ITensor<T = number> extends ICopy<ITensor<T>>, IEquiv, IEqualsD
|
|
|
105
104
|
* @param storage
|
|
106
105
|
*/
|
|
107
106
|
empty(storage?: ITensorStorage<T>): this;
|
|
107
|
+
fill(x: T): this;
|
|
108
108
|
/**
|
|
109
109
|
* Computes linear array index from given grid position. Reverse-op of
|
|
110
110
|
* {@link ITensor.position}.
|
|
@@ -116,6 +116,10 @@ export interface ITensor<T = number> extends ICopy<ITensor<T>>, IEquiv, IEqualsD
|
|
|
116
116
|
* @param pos
|
|
117
117
|
*/
|
|
118
118
|
index(pos: NumericArray): number;
|
|
119
|
+
/**
|
|
120
|
+
* Returns an iterator of array indices used by this tensor
|
|
121
|
+
*/
|
|
122
|
+
indices(): IterableIterator<number>;
|
|
119
123
|
/**
|
|
120
124
|
* Computes nD grid position for given linear array index. Reverse-op of
|
|
121
125
|
* {@link ITensor.index}.
|
|
@@ -327,6 +331,11 @@ export interface ITensor<T = number> extends ICopy<ITensor<T>>, IEquiv, IEqualsD
|
|
|
327
331
|
* that of the current shape (otherwise an error will be thrown).
|
|
328
332
|
*
|
|
329
333
|
* @remarks
|
|
334
|
+
* **IMPORTANT:** If no `newStride` is given, only "dense" tensors can be
|
|
335
|
+
* reshaped reliably (if in doubt, use {@link ITensor.pack} prior to
|
|
336
|
+
* reshaping).
|
|
337
|
+
*
|
|
338
|
+
* @remarks
|
|
330
339
|
* Also see {@link ITensor.crop} and {@link ITensor.resize}
|
|
331
340
|
*
|
|
332
341
|
* @example
|
|
@@ -414,6 +423,21 @@ export interface ITensor<T = number> extends ICopy<ITensor<T>>, IEquiv, IEqualsD
|
|
|
414
423
|
transpose(order: NumericArray): this;
|
|
415
424
|
toJSON(): any;
|
|
416
425
|
}
|
|
426
|
+
export type ITensor0<T = number> = ITensor<T> & {
|
|
427
|
+
dim: 0;
|
|
428
|
+
};
|
|
429
|
+
export type ITensor1<T = number> = ITensor<T> & {
|
|
430
|
+
dim: 1;
|
|
431
|
+
};
|
|
432
|
+
export type ITensor2<T = number> = ITensor<T> & {
|
|
433
|
+
dim: 2;
|
|
434
|
+
};
|
|
435
|
+
export type ITensor3<T = number> = ITensor<T> & {
|
|
436
|
+
dim: 3;
|
|
437
|
+
};
|
|
438
|
+
export type ITensor4<T = number> = ITensor<T> & {
|
|
439
|
+
dim: 4;
|
|
440
|
+
};
|
|
417
441
|
export interface TensorCtor<T = number> {
|
|
418
442
|
new (type: Type, storage: ITensorStorage<T>, data: TensorData<T>, shape: number[], stride: number[], offset?: number): ITensor<T>;
|
|
419
443
|
}
|
|
@@ -442,186 +466,193 @@ export interface ITensorStorage<T> {
|
|
|
442
466
|
}
|
|
443
467
|
export type StorageRegistry = Record<Type, ITensorStorage<any>>;
|
|
444
468
|
export interface TensorOpT<T = number> {
|
|
445
|
-
(out:
|
|
446
|
-
(out:
|
|
447
|
-
(out:
|
|
448
|
-
(out:
|
|
449
|
-
(out:
|
|
469
|
+
(out: ITensor0<T> | null, a: ITensor0<T>): ITensor0<T>;
|
|
470
|
+
(out: ITensor1<T> | null, a: ITensor1<T>): ITensor1<T>;
|
|
471
|
+
(out: ITensor2<T> | null, a: ITensor2<T>): ITensor2<T>;
|
|
472
|
+
(out: ITensor3<T> | null, a: ITensor3<T>): ITensor3<T>;
|
|
473
|
+
(out: ITensor4<T> | null, a: ITensor4<T>): ITensor4<T>;
|
|
450
474
|
}
|
|
451
475
|
export interface TensorOpTT<T = number> {
|
|
452
|
-
(out:
|
|
453
|
-
(out:
|
|
454
|
-
(out:
|
|
455
|
-
(out:
|
|
456
|
-
(out:
|
|
457
|
-
(out:
|
|
458
|
-
(out:
|
|
459
|
-
(out:
|
|
460
|
-
(out:
|
|
461
|
-
(out:
|
|
462
|
-
(out:
|
|
463
|
-
(out:
|
|
464
|
-
(out:
|
|
465
|
-
(out:
|
|
466
|
-
(out:
|
|
467
|
-
(out:
|
|
468
|
-
(out:
|
|
469
|
-
(out:
|
|
470
|
-
(out:
|
|
471
|
-
(out:
|
|
472
|
-
(out:
|
|
473
|
-
(out:
|
|
474
|
-
(out:
|
|
475
|
-
(out:
|
|
476
|
-
(out:
|
|
476
|
+
(out: ITensor0<T> | null, a: ITensor0<T>, b: ITensor0<T>): ITensor0<T>;
|
|
477
|
+
(out: ITensor1<T> | null, a: ITensor0<T>, b: ITensor1<T>): ITensor1<T>;
|
|
478
|
+
(out: ITensor2<T> | null, a: ITensor0<T>, b: ITensor2<T>): ITensor2<T>;
|
|
479
|
+
(out: ITensor3<T> | null, a: ITensor0<T>, b: ITensor3<T>): ITensor3<T>;
|
|
480
|
+
(out: ITensor4<T> | null, a: ITensor0<T>, b: ITensor4<T>): ITensor4<T>;
|
|
481
|
+
(out: ITensor1<T> | null, a: ITensor1<T>, b: ITensor0<T>): ITensor1<T>;
|
|
482
|
+
(out: ITensor1<T> | null, a: ITensor1<T>, b: ITensor1<T>): ITensor1<T>;
|
|
483
|
+
(out: ITensor2<T> | null, a: ITensor1<T>, b: ITensor2<T>): ITensor2<T>;
|
|
484
|
+
(out: ITensor3<T> | null, a: ITensor1<T>, b: ITensor3<T>): ITensor3<T>;
|
|
485
|
+
(out: ITensor4<T> | null, a: ITensor1<T>, b: ITensor4<T>): ITensor4<T>;
|
|
486
|
+
(out: ITensor2<T> | null, a: ITensor2<T>, b: ITensor0<T>): ITensor2<T>;
|
|
487
|
+
(out: ITensor2<T> | null, a: ITensor2<T>, b: ITensor1<T>): ITensor2<T>;
|
|
488
|
+
(out: ITensor2<T> | null, a: ITensor2<T>, b: ITensor2<T>): ITensor2<T>;
|
|
489
|
+
(out: ITensor3<T> | null, a: ITensor2<T>, b: ITensor3<T>): ITensor3<T>;
|
|
490
|
+
(out: ITensor4<T> | null, a: ITensor2<T>, b: ITensor4<T>): ITensor4<T>;
|
|
491
|
+
(out: ITensor3<T> | null, a: ITensor3<T>, b: ITensor0<T>): ITensor3<T>;
|
|
492
|
+
(out: ITensor3<T> | null, a: ITensor3<T>, b: ITensor1<T>): ITensor3<T>;
|
|
493
|
+
(out: ITensor3<T> | null, a: ITensor3<T>, b: ITensor2<T>): ITensor3<T>;
|
|
494
|
+
(out: ITensor3<T> | null, a: ITensor3<T>, b: ITensor3<T>): ITensor3<T>;
|
|
495
|
+
(out: ITensor4<T> | null, a: ITensor3<T>, b: ITensor4<T>): ITensor4<T>;
|
|
496
|
+
(out: ITensor4<T> | null, a: ITensor4<T>, b: ITensor0<T>): ITensor4<T>;
|
|
497
|
+
(out: ITensor4<T> | null, a: ITensor4<T>, b: ITensor1<T>): ITensor4<T>;
|
|
498
|
+
(out: ITensor4<T> | null, a: ITensor4<T>, b: ITensor2<T>): ITensor4<T>;
|
|
499
|
+
(out: ITensor4<T> | null, a: ITensor4<T>, b: ITensor3<T>): ITensor4<T>;
|
|
500
|
+
(out: ITensor4<T> | null, a: ITensor4<T>, b: ITensor4<T>): ITensor4<T>;
|
|
477
501
|
}
|
|
478
502
|
export interface TensorOpTTT<T = number> {
|
|
479
|
-
(out:
|
|
480
|
-
(out:
|
|
481
|
-
(out:
|
|
482
|
-
(out:
|
|
483
|
-
(out:
|
|
484
|
-
(out:
|
|
485
|
-
(out:
|
|
486
|
-
(out:
|
|
487
|
-
(out:
|
|
488
|
-
(out:
|
|
489
|
-
(out:
|
|
490
|
-
(out:
|
|
491
|
-
(out:
|
|
492
|
-
(out:
|
|
493
|
-
(out:
|
|
494
|
-
(out:
|
|
495
|
-
(out:
|
|
496
|
-
(out:
|
|
497
|
-
(out:
|
|
498
|
-
(out:
|
|
499
|
-
(out:
|
|
500
|
-
(out:
|
|
501
|
-
(out:
|
|
502
|
-
(out:
|
|
503
|
-
(out:
|
|
504
|
-
(out:
|
|
505
|
-
(out:
|
|
506
|
-
(out:
|
|
507
|
-
(out:
|
|
508
|
-
(out:
|
|
509
|
-
(out:
|
|
510
|
-
(out:
|
|
511
|
-
(out:
|
|
512
|
-
(out:
|
|
513
|
-
(out:
|
|
514
|
-
(out:
|
|
515
|
-
(out:
|
|
516
|
-
(out:
|
|
517
|
-
(out:
|
|
518
|
-
(out:
|
|
519
|
-
(out:
|
|
520
|
-
(out:
|
|
521
|
-
(out:
|
|
522
|
-
(out:
|
|
523
|
-
(out:
|
|
524
|
-
(out:
|
|
525
|
-
(out:
|
|
526
|
-
(out:
|
|
527
|
-
(out:
|
|
528
|
-
(out:
|
|
529
|
-
(out:
|
|
530
|
-
(out:
|
|
531
|
-
(out:
|
|
532
|
-
(out:
|
|
533
|
-
(out:
|
|
534
|
-
(out:
|
|
535
|
-
(out:
|
|
536
|
-
(out:
|
|
537
|
-
(out:
|
|
538
|
-
(out:
|
|
539
|
-
(out:
|
|
540
|
-
(out:
|
|
541
|
-
(out:
|
|
542
|
-
(out:
|
|
543
|
-
(out:
|
|
544
|
-
(out:
|
|
545
|
-
(out:
|
|
546
|
-
(out:
|
|
547
|
-
(out:
|
|
548
|
-
(out:
|
|
549
|
-
(out:
|
|
550
|
-
(out:
|
|
551
|
-
(out:
|
|
552
|
-
(out:
|
|
553
|
-
(out:
|
|
554
|
-
(out:
|
|
555
|
-
(out:
|
|
556
|
-
(out:
|
|
557
|
-
(out:
|
|
558
|
-
(out:
|
|
559
|
-
(out:
|
|
560
|
-
(out:
|
|
561
|
-
(out:
|
|
562
|
-
(out:
|
|
563
|
-
(out:
|
|
564
|
-
(out:
|
|
565
|
-
(out:
|
|
566
|
-
(out:
|
|
567
|
-
(out:
|
|
568
|
-
(out:
|
|
569
|
-
(out:
|
|
570
|
-
(out:
|
|
571
|
-
(out:
|
|
572
|
-
(out:
|
|
573
|
-
(out:
|
|
574
|
-
(out:
|
|
575
|
-
(out:
|
|
576
|
-
(out:
|
|
577
|
-
(out:
|
|
578
|
-
(out:
|
|
579
|
-
(out:
|
|
580
|
-
(out:
|
|
581
|
-
(out:
|
|
582
|
-
(out:
|
|
583
|
-
(out:
|
|
584
|
-
(out:
|
|
585
|
-
(out:
|
|
586
|
-
(out:
|
|
587
|
-
(out:
|
|
588
|
-
(out:
|
|
589
|
-
(out:
|
|
590
|
-
(out:
|
|
591
|
-
(out:
|
|
592
|
-
(out:
|
|
593
|
-
(out:
|
|
594
|
-
(out:
|
|
595
|
-
(out:
|
|
596
|
-
(out:
|
|
597
|
-
(out:
|
|
598
|
-
(out:
|
|
599
|
-
(out:
|
|
600
|
-
(out:
|
|
601
|
-
(out:
|
|
602
|
-
(out:
|
|
603
|
-
(out:
|
|
503
|
+
(out: ITensor0<T> | null, a: ITensor0<T>, b: ITensor0<T>, c: ITensor0<T>): ITensor0<T>;
|
|
504
|
+
(out: ITensor1<T> | null, a: ITensor0<T>, b: ITensor0<T>, c: ITensor1<T>): ITensor1<T>;
|
|
505
|
+
(out: ITensor2<T> | null, a: ITensor0<T>, b: ITensor0<T>, c: ITensor2<T>): ITensor2<T>;
|
|
506
|
+
(out: ITensor3<T> | null, a: ITensor0<T>, b: ITensor0<T>, c: ITensor3<T>): ITensor3<T>;
|
|
507
|
+
(out: ITensor4<T> | null, a: ITensor0<T>, b: ITensor0<T>, c: ITensor4<T>): ITensor4<T>;
|
|
508
|
+
(out: ITensor1<T> | null, a: ITensor0<T>, b: ITensor1<T>, c: ITensor0<T>): ITensor1<T>;
|
|
509
|
+
(out: ITensor1<T> | null, a: ITensor0<T>, b: ITensor1<T>, c: ITensor1<T>): ITensor1<T>;
|
|
510
|
+
(out: ITensor2<T> | null, a: ITensor0<T>, b: ITensor1<T>, c: ITensor2<T>): ITensor2<T>;
|
|
511
|
+
(out: ITensor3<T> | null, a: ITensor0<T>, b: ITensor1<T>, c: ITensor3<T>): ITensor3<T>;
|
|
512
|
+
(out: ITensor4<T> | null, a: ITensor0<T>, b: ITensor1<T>, c: ITensor4<T>): ITensor4<T>;
|
|
513
|
+
(out: ITensor2<T> | null, a: ITensor0<T>, b: ITensor2<T>, c: ITensor0<T>): ITensor2<T>;
|
|
514
|
+
(out: ITensor2<T> | null, a: ITensor0<T>, b: ITensor2<T>, c: ITensor1<T>): ITensor2<T>;
|
|
515
|
+
(out: ITensor2<T> | null, a: ITensor0<T>, b: ITensor2<T>, c: ITensor2<T>): ITensor2<T>;
|
|
516
|
+
(out: ITensor3<T> | null, a: ITensor0<T>, b: ITensor2<T>, c: ITensor3<T>): ITensor3<T>;
|
|
517
|
+
(out: ITensor4<T> | null, a: ITensor0<T>, b: ITensor2<T>, c: ITensor4<T>): ITensor4<T>;
|
|
518
|
+
(out: ITensor3<T> | null, a: ITensor0<T>, b: ITensor3<T>, c: ITensor0<T>): ITensor3<T>;
|
|
519
|
+
(out: ITensor3<T> | null, a: ITensor0<T>, b: ITensor3<T>, c: ITensor1<T>): ITensor3<T>;
|
|
520
|
+
(out: ITensor3<T> | null, a: ITensor0<T>, b: ITensor3<T>, c: ITensor2<T>): ITensor3<T>;
|
|
521
|
+
(out: ITensor3<T> | null, a: ITensor0<T>, b: ITensor3<T>, c: ITensor3<T>): ITensor3<T>;
|
|
522
|
+
(out: ITensor4<T> | null, a: ITensor0<T>, b: ITensor3<T>, c: ITensor4<T>): ITensor4<T>;
|
|
523
|
+
(out: ITensor4<T> | null, a: ITensor0<T>, b: ITensor4<T>, c: ITensor0<T>): ITensor4<T>;
|
|
524
|
+
(out: ITensor4<T> | null, a: ITensor0<T>, b: ITensor4<T>, c: ITensor1<T>): ITensor4<T>;
|
|
525
|
+
(out: ITensor4<T> | null, a: ITensor0<T>, b: ITensor4<T>, c: ITensor2<T>): ITensor4<T>;
|
|
526
|
+
(out: ITensor4<T> | null, a: ITensor0<T>, b: ITensor4<T>, c: ITensor3<T>): ITensor4<T>;
|
|
527
|
+
(out: ITensor4<T> | null, a: ITensor0<T>, b: ITensor4<T>, c: ITensor4<T>): ITensor4<T>;
|
|
528
|
+
(out: ITensor1<T> | null, a: ITensor1<T>, b: ITensor0<T>, c: ITensor0<T>): ITensor1<T>;
|
|
529
|
+
(out: ITensor1<T> | null, a: ITensor1<T>, b: ITensor0<T>, c: ITensor1<T>): ITensor1<T>;
|
|
530
|
+
(out: ITensor2<T> | null, a: ITensor1<T>, b: ITensor0<T>, c: ITensor2<T>): ITensor2<T>;
|
|
531
|
+
(out: ITensor3<T> | null, a: ITensor1<T>, b: ITensor0<T>, c: ITensor3<T>): ITensor3<T>;
|
|
532
|
+
(out: ITensor4<T> | null, a: ITensor1<T>, b: ITensor0<T>, c: ITensor4<T>): ITensor4<T>;
|
|
533
|
+
(out: ITensor1<T> | null, a: ITensor1<T>, b: ITensor1<T>, c: ITensor0<T>): ITensor1<T>;
|
|
534
|
+
(out: ITensor1<T> | null, a: ITensor1<T>, b: ITensor1<T>, c: ITensor1<T>): ITensor1<T>;
|
|
535
|
+
(out: ITensor2<T> | null, a: ITensor1<T>, b: ITensor1<T>, c: ITensor2<T>): ITensor2<T>;
|
|
536
|
+
(out: ITensor3<T> | null, a: ITensor1<T>, b: ITensor1<T>, c: ITensor3<T>): ITensor3<T>;
|
|
537
|
+
(out: ITensor4<T> | null, a: ITensor1<T>, b: ITensor1<T>, c: ITensor4<T>): ITensor4<T>;
|
|
538
|
+
(out: ITensor2<T> | null, a: ITensor1<T>, b: ITensor2<T>, c: ITensor0<T>): ITensor2<T>;
|
|
539
|
+
(out: ITensor2<T> | null, a: ITensor1<T>, b: ITensor2<T>, c: ITensor1<T>): ITensor2<T>;
|
|
540
|
+
(out: ITensor2<T> | null, a: ITensor1<T>, b: ITensor2<T>, c: ITensor2<T>): ITensor2<T>;
|
|
541
|
+
(out: ITensor3<T> | null, a: ITensor1<T>, b: ITensor2<T>, c: ITensor3<T>): ITensor3<T>;
|
|
542
|
+
(out: ITensor4<T> | null, a: ITensor1<T>, b: ITensor2<T>, c: ITensor4<T>): ITensor4<T>;
|
|
543
|
+
(out: ITensor3<T> | null, a: ITensor1<T>, b: ITensor3<T>, c: ITensor0<T>): ITensor3<T>;
|
|
544
|
+
(out: ITensor3<T> | null, a: ITensor1<T>, b: ITensor3<T>, c: ITensor1<T>): ITensor3<T>;
|
|
545
|
+
(out: ITensor3<T> | null, a: ITensor1<T>, b: ITensor3<T>, c: ITensor2<T>): ITensor3<T>;
|
|
546
|
+
(out: ITensor3<T> | null, a: ITensor1<T>, b: ITensor3<T>, c: ITensor3<T>): ITensor3<T>;
|
|
547
|
+
(out: ITensor4<T> | null, a: ITensor1<T>, b: ITensor3<T>, c: ITensor4<T>): ITensor4<T>;
|
|
548
|
+
(out: ITensor4<T> | null, a: ITensor1<T>, b: ITensor4<T>, c: ITensor0<T>): ITensor4<T>;
|
|
549
|
+
(out: ITensor4<T> | null, a: ITensor1<T>, b: ITensor4<T>, c: ITensor1<T>): ITensor4<T>;
|
|
550
|
+
(out: ITensor4<T> | null, a: ITensor1<T>, b: ITensor4<T>, c: ITensor2<T>): ITensor4<T>;
|
|
551
|
+
(out: ITensor4<T> | null, a: ITensor1<T>, b: ITensor4<T>, c: ITensor3<T>): ITensor4<T>;
|
|
552
|
+
(out: ITensor4<T> | null, a: ITensor1<T>, b: ITensor4<T>, c: ITensor4<T>): ITensor4<T>;
|
|
553
|
+
(out: ITensor2<T> | null, a: ITensor2<T>, b: ITensor0<T>, c: ITensor0<T>): ITensor2<T>;
|
|
554
|
+
(out: ITensor2<T> | null, a: ITensor2<T>, b: ITensor0<T>, c: ITensor1<T>): ITensor2<T>;
|
|
555
|
+
(out: ITensor2<T> | null, a: ITensor2<T>, b: ITensor0<T>, c: ITensor2<T>): ITensor2<T>;
|
|
556
|
+
(out: ITensor3<T> | null, a: ITensor2<T>, b: ITensor0<T>, c: ITensor3<T>): ITensor3<T>;
|
|
557
|
+
(out: ITensor4<T> | null, a: ITensor2<T>, b: ITensor0<T>, c: ITensor4<T>): ITensor4<T>;
|
|
558
|
+
(out: ITensor2<T> | null, a: ITensor2<T>, b: ITensor1<T>, c: ITensor0<T>): ITensor2<T>;
|
|
559
|
+
(out: ITensor2<T> | null, a: ITensor2<T>, b: ITensor1<T>, c: ITensor1<T>): ITensor2<T>;
|
|
560
|
+
(out: ITensor2<T> | null, a: ITensor2<T>, b: ITensor1<T>, c: ITensor2<T>): ITensor2<T>;
|
|
561
|
+
(out: ITensor3<T> | null, a: ITensor2<T>, b: ITensor1<T>, c: ITensor3<T>): ITensor3<T>;
|
|
562
|
+
(out: ITensor4<T> | null, a: ITensor2<T>, b: ITensor1<T>, c: ITensor4<T>): ITensor4<T>;
|
|
563
|
+
(out: ITensor2<T> | null, a: ITensor2<T>, b: ITensor2<T>, c: ITensor0<T>): ITensor2<T>;
|
|
564
|
+
(out: ITensor2<T> | null, a: ITensor2<T>, b: ITensor2<T>, c: ITensor1<T>): ITensor2<T>;
|
|
565
|
+
(out: ITensor2<T> | null, a: ITensor2<T>, b: ITensor2<T>, c: ITensor2<T>): ITensor2<T>;
|
|
566
|
+
(out: ITensor3<T> | null, a: ITensor2<T>, b: ITensor2<T>, c: ITensor3<T>): ITensor3<T>;
|
|
567
|
+
(out: ITensor4<T> | null, a: ITensor2<T>, b: ITensor2<T>, c: ITensor4<T>): ITensor4<T>;
|
|
568
|
+
(out: ITensor3<T> | null, a: ITensor2<T>, b: ITensor3<T>, c: ITensor0<T>): ITensor3<T>;
|
|
569
|
+
(out: ITensor3<T> | null, a: ITensor2<T>, b: ITensor3<T>, c: ITensor1<T>): ITensor3<T>;
|
|
570
|
+
(out: ITensor3<T> | null, a: ITensor2<T>, b: ITensor3<T>, c: ITensor2<T>): ITensor3<T>;
|
|
571
|
+
(out: ITensor3<T> | null, a: ITensor2<T>, b: ITensor3<T>, c: ITensor3<T>): ITensor3<T>;
|
|
572
|
+
(out: ITensor4<T> | null, a: ITensor2<T>, b: ITensor3<T>, c: ITensor4<T>): ITensor4<T>;
|
|
573
|
+
(out: ITensor4<T> | null, a: ITensor2<T>, b: ITensor4<T>, c: ITensor0<T>): ITensor4<T>;
|
|
574
|
+
(out: ITensor4<T> | null, a: ITensor2<T>, b: ITensor4<T>, c: ITensor1<T>): ITensor4<T>;
|
|
575
|
+
(out: ITensor4<T> | null, a: ITensor2<T>, b: ITensor4<T>, c: ITensor2<T>): ITensor4<T>;
|
|
576
|
+
(out: ITensor4<T> | null, a: ITensor2<T>, b: ITensor4<T>, c: ITensor3<T>): ITensor4<T>;
|
|
577
|
+
(out: ITensor4<T> | null, a: ITensor2<T>, b: ITensor4<T>, c: ITensor4<T>): ITensor4<T>;
|
|
578
|
+
(out: ITensor3<T> | null, a: ITensor3<T>, b: ITensor0<T>, c: ITensor0<T>): ITensor3<T>;
|
|
579
|
+
(out: ITensor3<T> | null, a: ITensor3<T>, b: ITensor0<T>, c: ITensor1<T>): ITensor3<T>;
|
|
580
|
+
(out: ITensor3<T> | null, a: ITensor3<T>, b: ITensor0<T>, c: ITensor2<T>): ITensor3<T>;
|
|
581
|
+
(out: ITensor3<T> | null, a: ITensor3<T>, b: ITensor0<T>, c: ITensor3<T>): ITensor3<T>;
|
|
582
|
+
(out: ITensor4<T> | null, a: ITensor3<T>, b: ITensor0<T>, c: ITensor4<T>): ITensor4<T>;
|
|
583
|
+
(out: ITensor3<T> | null, a: ITensor3<T>, b: ITensor1<T>, c: ITensor0<T>): ITensor3<T>;
|
|
584
|
+
(out: ITensor3<T> | null, a: ITensor3<T>, b: ITensor1<T>, c: ITensor1<T>): ITensor3<T>;
|
|
585
|
+
(out: ITensor3<T> | null, a: ITensor3<T>, b: ITensor1<T>, c: ITensor2<T>): ITensor3<T>;
|
|
586
|
+
(out: ITensor3<T> | null, a: ITensor3<T>, b: ITensor1<T>, c: ITensor3<T>): ITensor3<T>;
|
|
587
|
+
(out: ITensor4<T> | null, a: ITensor3<T>, b: ITensor1<T>, c: ITensor4<T>): ITensor4<T>;
|
|
588
|
+
(out: ITensor3<T> | null, a: ITensor3<T>, b: ITensor2<T>, c: ITensor0<T>): ITensor3<T>;
|
|
589
|
+
(out: ITensor3<T> | null, a: ITensor3<T>, b: ITensor2<T>, c: ITensor1<T>): ITensor3<T>;
|
|
590
|
+
(out: ITensor3<T> | null, a: ITensor3<T>, b: ITensor2<T>, c: ITensor2<T>): ITensor3<T>;
|
|
591
|
+
(out: ITensor3<T> | null, a: ITensor3<T>, b: ITensor2<T>, c: ITensor3<T>): ITensor3<T>;
|
|
592
|
+
(out: ITensor4<T> | null, a: ITensor3<T>, b: ITensor2<T>, c: ITensor4<T>): ITensor4<T>;
|
|
593
|
+
(out: ITensor3<T> | null, a: ITensor3<T>, b: ITensor3<T>, c: ITensor0<T>): ITensor3<T>;
|
|
594
|
+
(out: ITensor3<T> | null, a: ITensor3<T>, b: ITensor3<T>, c: ITensor1<T>): ITensor3<T>;
|
|
595
|
+
(out: ITensor3<T> | null, a: ITensor3<T>, b: ITensor3<T>, c: ITensor2<T>): ITensor3<T>;
|
|
596
|
+
(out: ITensor3<T> | null, a: ITensor3<T>, b: ITensor3<T>, c: ITensor3<T>): ITensor3<T>;
|
|
597
|
+
(out: ITensor4<T> | null, a: ITensor3<T>, b: ITensor3<T>, c: ITensor4<T>): ITensor4<T>;
|
|
598
|
+
(out: ITensor4<T> | null, a: ITensor3<T>, b: ITensor4<T>, c: ITensor0<T>): ITensor4<T>;
|
|
599
|
+
(out: ITensor4<T> | null, a: ITensor3<T>, b: ITensor4<T>, c: ITensor1<T>): ITensor4<T>;
|
|
600
|
+
(out: ITensor4<T> | null, a: ITensor3<T>, b: ITensor4<T>, c: ITensor2<T>): ITensor4<T>;
|
|
601
|
+
(out: ITensor4<T> | null, a: ITensor3<T>, b: ITensor4<T>, c: ITensor3<T>): ITensor4<T>;
|
|
602
|
+
(out: ITensor4<T> | null, a: ITensor3<T>, b: ITensor4<T>, c: ITensor4<T>): ITensor4<T>;
|
|
603
|
+
(out: ITensor4<T> | null, a: ITensor4<T>, b: ITensor0<T>, c: ITensor0<T>): ITensor4<T>;
|
|
604
|
+
(out: ITensor4<T> | null, a: ITensor4<T>, b: ITensor0<T>, c: ITensor1<T>): ITensor4<T>;
|
|
605
|
+
(out: ITensor4<T> | null, a: ITensor4<T>, b: ITensor0<T>, c: ITensor2<T>): ITensor4<T>;
|
|
606
|
+
(out: ITensor4<T> | null, a: ITensor4<T>, b: ITensor0<T>, c: ITensor3<T>): ITensor4<T>;
|
|
607
|
+
(out: ITensor4<T> | null, a: ITensor4<T>, b: ITensor0<T>, c: ITensor4<T>): ITensor4<T>;
|
|
608
|
+
(out: ITensor4<T> | null, a: ITensor4<T>, b: ITensor1<T>, c: ITensor0<T>): ITensor4<T>;
|
|
609
|
+
(out: ITensor4<T> | null, a: ITensor4<T>, b: ITensor1<T>, c: ITensor1<T>): ITensor4<T>;
|
|
610
|
+
(out: ITensor4<T> | null, a: ITensor4<T>, b: ITensor1<T>, c: ITensor2<T>): ITensor4<T>;
|
|
611
|
+
(out: ITensor4<T> | null, a: ITensor4<T>, b: ITensor1<T>, c: ITensor3<T>): ITensor4<T>;
|
|
612
|
+
(out: ITensor4<T> | null, a: ITensor4<T>, b: ITensor1<T>, c: ITensor4<T>): ITensor4<T>;
|
|
613
|
+
(out: ITensor4<T> | null, a: ITensor4<T>, b: ITensor2<T>, c: ITensor0<T>): ITensor4<T>;
|
|
614
|
+
(out: ITensor4<T> | null, a: ITensor4<T>, b: ITensor2<T>, c: ITensor1<T>): ITensor4<T>;
|
|
615
|
+
(out: ITensor4<T> | null, a: ITensor4<T>, b: ITensor2<T>, c: ITensor2<T>): ITensor4<T>;
|
|
616
|
+
(out: ITensor4<T> | null, a: ITensor4<T>, b: ITensor2<T>, c: ITensor3<T>): ITensor4<T>;
|
|
617
|
+
(out: ITensor4<T> | null, a: ITensor4<T>, b: ITensor2<T>, c: ITensor4<T>): ITensor4<T>;
|
|
618
|
+
(out: ITensor4<T> | null, a: ITensor4<T>, b: ITensor3<T>, c: ITensor0<T>): ITensor4<T>;
|
|
619
|
+
(out: ITensor4<T> | null, a: ITensor4<T>, b: ITensor3<T>, c: ITensor1<T>): ITensor4<T>;
|
|
620
|
+
(out: ITensor4<T> | null, a: ITensor4<T>, b: ITensor3<T>, c: ITensor2<T>): ITensor4<T>;
|
|
621
|
+
(out: ITensor4<T> | null, a: ITensor4<T>, b: ITensor3<T>, c: ITensor3<T>): ITensor4<T>;
|
|
622
|
+
(out: ITensor4<T> | null, a: ITensor4<T>, b: ITensor3<T>, c: ITensor4<T>): ITensor4<T>;
|
|
623
|
+
(out: ITensor4<T> | null, a: ITensor4<T>, b: ITensor4<T>, c: ITensor0<T>): ITensor4<T>;
|
|
624
|
+
(out: ITensor4<T> | null, a: ITensor4<T>, b: ITensor4<T>, c: ITensor1<T>): ITensor4<T>;
|
|
625
|
+
(out: ITensor4<T> | null, a: ITensor4<T>, b: ITensor4<T>, c: ITensor2<T>): ITensor4<T>;
|
|
626
|
+
(out: ITensor4<T> | null, a: ITensor4<T>, b: ITensor4<T>, c: ITensor3<T>): ITensor4<T>;
|
|
627
|
+
(out: ITensor4<T> | null, a: ITensor4<T>, b: ITensor4<T>, c: ITensor4<T>): ITensor4<T>;
|
|
604
628
|
}
|
|
605
629
|
export interface TensorOpN<A = number, B = A> {
|
|
606
|
-
(out:
|
|
607
|
-
(out:
|
|
608
|
-
(out:
|
|
609
|
-
(out:
|
|
610
|
-
(out:
|
|
630
|
+
(out: ITensor0<B>, n: A): ITensor0<B>;
|
|
631
|
+
(out: ITensor1<B>, n: A): ITensor1<B>;
|
|
632
|
+
(out: ITensor2<B>, n: A): ITensor2<B>;
|
|
633
|
+
(out: ITensor3<B>, n: A): ITensor3<B>;
|
|
634
|
+
(out: ITensor4<B>, n: A): ITensor4<B>;
|
|
611
635
|
}
|
|
612
636
|
export interface TensorOpTN<T = number> {
|
|
613
|
-
(out:
|
|
614
|
-
(out:
|
|
615
|
-
(out:
|
|
616
|
-
(out:
|
|
617
|
-
(out:
|
|
637
|
+
(out: ITensor0<T> | null, a: ITensor0<T>, n: T): ITensor0<T>;
|
|
638
|
+
(out: ITensor1<T> | null, a: ITensor1<T>, n: T): ITensor1<T>;
|
|
639
|
+
(out: ITensor2<T> | null, a: ITensor2<T>, n: T): ITensor2<T>;
|
|
640
|
+
(out: ITensor3<T> | null, a: ITensor3<T>, n: T): ITensor3<T>;
|
|
641
|
+
(out: ITensor4<T> | null, a: ITensor4<T>, n: T): ITensor4<T>;
|
|
642
|
+
}
|
|
643
|
+
export interface TensorOpTNO<T = number> {
|
|
644
|
+
(out: ITensor0<T> | null, a: ITensor0<T>, n?: T): ITensor0<T>;
|
|
645
|
+
(out: ITensor1<T> | null, a: ITensor1<T>, n?: T): ITensor1<T>;
|
|
646
|
+
(out: ITensor2<T> | null, a: ITensor2<T>, n?: T): ITensor2<T>;
|
|
647
|
+
(out: ITensor3<T> | null, a: ITensor3<T>, n?: T): ITensor3<T>;
|
|
648
|
+
(out: ITensor4<T> | null, a: ITensor4<T>, n?: T): ITensor4<T>;
|
|
618
649
|
}
|
|
619
650
|
export interface TensorOpTNN<T = number> {
|
|
620
|
-
(out:
|
|
621
|
-
(out:
|
|
622
|
-
(out:
|
|
623
|
-
(out:
|
|
624
|
-
(out:
|
|
651
|
+
(out: ITensor0<T>, a: ITensor0<T>, n: T, m: T): ITensor0<T>;
|
|
652
|
+
(out: ITensor1<T>, a: ITensor1<T>, n: T, m: T): ITensor1<T>;
|
|
653
|
+
(out: ITensor2<T>, a: ITensor2<T>, n: T, m: T): ITensor2<T>;
|
|
654
|
+
(out: ITensor3<T>, a: ITensor3<T>, n: T, m: T): ITensor3<T>;
|
|
655
|
+
(out: ITensor4<T>, a: ITensor4<T>, n: T, m: T): ITensor4<T>;
|
|
625
656
|
}
|
|
626
657
|
export type TensorOpRT<A, B, TA extends ITensor<A> = ITensor<A>> = (a: TA) => B;
|
|
627
658
|
export type TensorOpRTT<A, B, TA extends ITensor<A> = ITensor<A>> = (a: TA, b: TA) => B;
|
package/broadcast.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ import type { ITensor, Shape } from "./api.js";
|
|
|
18
18
|
*/
|
|
19
19
|
export declare const broadcast: <T = number>(a: ITensor<T>, b: ITensor<T>) => {
|
|
20
20
|
shape: Shape;
|
|
21
|
-
a: ITensor<T
|
|
22
|
-
b: ITensor<T
|
|
21
|
+
a: ITensor<T>;
|
|
22
|
+
b: ITensor<T>;
|
|
23
23
|
};
|
|
24
24
|
//# sourceMappingURL=broadcast.d.ts.map
|
package/cdf.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ITensor1 } from "./api.js";
|
|
2
|
+
/**
|
|
3
|
+
* Computes the cumulative distribution of `a` and writes it to `out`. If `out`
|
|
4
|
+
* is null, mutates `a` in place.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Reference:
|
|
8
|
+
*
|
|
9
|
+
* - https://en.wikipedia.org/wiki/Cumulative_distribution_function
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts tangle:../export/cdf.ts
|
|
13
|
+
* import { cdf, tensor } from "@thi.ng/tensors";
|
|
14
|
+
*
|
|
15
|
+
* const a = tensor("num", [10], {data: [0,0,1,0,0,1,0,1,1,0]});
|
|
16
|
+
*
|
|
17
|
+
* console.log([...cdf(null, a)]);
|
|
18
|
+
* // [ 0, 0, 1, 1, 1, 2, 2, 3, 4, 4 ]
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @param out
|
|
22
|
+
* @param a
|
|
23
|
+
*/
|
|
24
|
+
export declare const cdf: (out: ITensor1 | null, a: ITensor1) => ITensor1;
|
|
25
|
+
//# sourceMappingURL=cdf.d.ts.map
|
package/cdf.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ensureShape } from "./errors.js";
|
|
2
|
+
const cdf = (out, a) => {
|
|
3
|
+
!out && (out = a);
|
|
4
|
+
ensureShape(out, a.shape);
|
|
5
|
+
const {
|
|
6
|
+
offset: oa,
|
|
7
|
+
shape: [sa],
|
|
8
|
+
stride: [ta],
|
|
9
|
+
data: adata
|
|
10
|
+
} = a;
|
|
11
|
+
const {
|
|
12
|
+
offset: oo,
|
|
13
|
+
stride: [to],
|
|
14
|
+
data: odata
|
|
15
|
+
} = out;
|
|
16
|
+
let total = 0;
|
|
17
|
+
for (let i = 0; i < sa; i++) {
|
|
18
|
+
total += adata[oa + i * ta];
|
|
19
|
+
odata[oo + i * to] = total;
|
|
20
|
+
}
|
|
21
|
+
return out;
|
|
22
|
+
};
|
|
23
|
+
export {
|
|
24
|
+
cdf
|
|
25
|
+
};
|
package/convert.d.ts
CHANGED
|
@@ -44,5 +44,5 @@ export interface FloatBufferLike {
|
|
|
44
44
|
*
|
|
45
45
|
* @param buffer
|
|
46
46
|
*/
|
|
47
|
-
export declare const fromFloatBuffer: ({ size: [sx, sy], stride: [tx, ty], data, format: { size }, }: FloatBufferLike) => import("./
|
|
47
|
+
export declare const fromFloatBuffer: ({ size: [sx, sy], stride: [tx, ty], data, format: { size }, }: FloatBufferLike) => import("./api.js").ITensor3<number> | import("./api.js").ITensor2<number>;
|
|
48
48
|
//# sourceMappingURL=convert.d.ts.map
|
package/diagonal.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import type { ITensor } from "./api.js";
|
|
2
|
-
import { Tensor1 } from "./tensor.js";
|
|
1
|
+
import type { ITensor, ITensor1 } from "./api.js";
|
|
3
2
|
/**
|
|
4
3
|
* Returns a 1D tensor view of the nD diagonal of the given tensor.
|
|
5
4
|
*
|
|
6
5
|
* @remarks
|
|
7
6
|
* For 1D tensors this will merely by a shallow copy.
|
|
8
7
|
*/
|
|
9
|
-
export declare const diagonal: <T>(a: ITensor<T>) =>
|
|
8
|
+
export declare const diagonal: <T>(a: ITensor<T>) => ITensor1<T>;
|
|
10
9
|
/**
|
|
11
10
|
* Computes the trace of given tensor, i.e. the component sum of `diagonal(a)`.
|
|
12
11
|
*
|