catniff 0.2.9 → 0.2.10

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/dist/core.d.ts CHANGED
@@ -43,14 +43,25 @@ export declare class Tensor {
43
43
  mean(dims?: number[] | number, keepDims?: boolean): Tensor;
44
44
  add(other: TensorValue | Tensor): Tensor;
45
45
  sub(other: TensorValue | Tensor): Tensor;
46
+ subtract: (other: TensorValue | Tensor) => Tensor;
46
47
  mul(other: TensorValue | Tensor): Tensor;
48
+ multiply: (other: TensorValue | Tensor) => Tensor;
47
49
  pow(other: TensorValue | Tensor): Tensor;
48
50
  div(other: TensorValue | Tensor): Tensor;
51
+ divide: (other: TensorValue | Tensor) => Tensor;
52
+ remainder(other: TensorValue | Tensor): Tensor;
49
53
  ge(other: TensorValue | Tensor): Tensor;
54
+ greaterEqual: (other: TensorValue | Tensor) => Tensor;
50
55
  le(other: TensorValue | Tensor): Tensor;
56
+ lessEqual: (other: TensorValue | Tensor) => Tensor;
51
57
  gt(other: TensorValue | Tensor): Tensor;
58
+ greater: (other: TensorValue | Tensor) => Tensor;
52
59
  lt(other: TensorValue | Tensor): Tensor;
60
+ less: (other: TensorValue | Tensor) => Tensor;
53
61
  eq(other: TensorValue | Tensor): Tensor;
62
+ equal: (other: TensorValue | Tensor) => Tensor;
63
+ ne(other: TensorValue | Tensor): Tensor;
64
+ notEqual: (other: TensorValue | Tensor) => Tensor;
54
65
  logicalAnd(other: TensorValue | Tensor): Tensor;
55
66
  logicalOr(other: TensorValue | Tensor): Tensor;
56
67
  logicalXor(other: TensorValue | Tensor): Tensor;
@@ -62,21 +73,38 @@ export declare class Tensor {
62
73
  bitwiseLeftShift(other: TensorValue | Tensor): Tensor;
63
74
  bitwiseRightShift(other: TensorValue | Tensor): Tensor;
64
75
  neg(): Tensor;
76
+ negative: () => Tensor;
77
+ reciprocal(): Tensor;
78
+ square(): Tensor;
65
79
  abs(): Tensor;
80
+ absolute: () => Tensor;
66
81
  sign(): Tensor;
67
82
  sin(): Tensor;
68
83
  cos(): Tensor;
69
84
  tan(): Tensor;
70
85
  asin(): Tensor;
86
+ arcsin: () => Tensor;
71
87
  acos(): Tensor;
88
+ arccos: () => Tensor;
72
89
  atan(): Tensor;
90
+ arctan: () => Tensor;
91
+ atan2(other: TensorValue | Tensor): Tensor;
92
+ arctan2: (other: TensorValue | Tensor) => Tensor;
73
93
  sinh(): Tensor;
74
94
  cosh(): Tensor;
75
95
  asinh(): Tensor;
96
+ arcsinh: () => Tensor;
76
97
  acosh(): Tensor;
98
+ arccosh: () => Tensor;
77
99
  atanh(): Tensor;
100
+ arctanh: () => Tensor;
101
+ deg2rad(): Tensor;
102
+ rad2deg(): Tensor;
78
103
  sqrt(): Tensor;
104
+ rsqrt(): Tensor;
79
105
  exp(): Tensor;
106
+ exp2(): Tensor;
107
+ expm1(): Tensor;
80
108
  log(): Tensor;
81
109
  log2(): Tensor;
82
110
  log10(): Tensor;
@@ -84,7 +112,17 @@ export declare class Tensor {
84
112
  relu(): Tensor;
85
113
  sigmoid(): Tensor;
86
114
  tanh(): Tensor;
115
+ round(): Tensor;
116
+ floor(): Tensor;
117
+ ceil(): Tensor;
118
+ trunc(): Tensor;
119
+ fix: () => Tensor;
120
+ frac(): Tensor;
121
+ clip(min: number, max: number): Tensor;
122
+ clamp: (min: number, max: number) => Tensor;
87
123
  transpose(dim1: number, dim2: number): Tensor;
124
+ swapaxes: (dim1: number, dim2: number) => Tensor;
125
+ swapdims: (dim1: number, dim2: number) => Tensor;
88
126
  t(): Tensor;
89
127
  dot(other: TensorValue | Tensor): Tensor;
90
128
  mm(other: TensorValue | Tensor): Tensor;
package/dist/core.js CHANGED
@@ -522,10 +522,12 @@ class Tensor {
522
522
  sub(other) {
523
523
  return this.elementWiseABDAG(other, (a, b) => a - b, (self, other, outGrad) => outGrad, (self, other, outGrad) => outGrad.neg());
524
524
  }
525
+ subtract = this.sub;
525
526
  // Tensor element-wise multiplication
526
527
  mul(other) {
527
528
  return this.elementWiseABDAG(other, (a, b) => a * b, (self, other, outGrad) => outGrad.mul(other), (self, other, outGrad) => outGrad.mul(self));
528
529
  }
530
+ multiply = this.mul;
529
531
  // Tensor element-wise power
530
532
  pow(other) {
531
533
  return this.elementWiseABDAG(other, (a, b) => a ** b, (self, other, outGrad) => outGrad.mul(other.mul(self.pow(other.sub(1)))), (self, other, outGrad) => outGrad.mul(self.pow(other).mul(self.log())));
@@ -534,26 +536,41 @@ class Tensor {
534
536
  div(other) {
535
537
  return this.elementWiseABDAG(other, (a, b) => a / b, (self, other, outGrad) => outGrad.div(other), (self, other, outGrad) => outGrad.mul(self.neg().div(other.pow(2))));
536
538
  }
539
+ divide = this.div;
540
+ // Tensor element-wise modulo
541
+ remainder(other) {
542
+ return this.elementWiseABDAG(other, (a, b) => a % b);
543
+ }
537
544
  // Tensor element-wise greater or equal comparison
538
545
  ge(other) {
539
546
  return this.elementWiseABDAG(other, (a, b) => a >= b ? 1 : 0);
540
547
  }
548
+ greaterEqual = this.ge;
541
549
  // Tensor element-wise less or equal comparison
542
550
  le(other) {
543
551
  return this.elementWiseABDAG(other, (a, b) => a <= b ? 1 : 0);
544
552
  }
553
+ lessEqual = this.le;
545
554
  // Tensor element-wise greater-than comparison
546
555
  gt(other) {
547
556
  return this.elementWiseABDAG(other, (a, b) => a > b ? 1 : 0);
548
557
  }
558
+ greater = this.gt;
549
559
  // Tensor element-wise less-than comparison
550
560
  lt(other) {
551
561
  return this.elementWiseABDAG(other, (a, b) => a < b ? 1 : 0);
552
562
  }
563
+ less = this.lt;
553
564
  // Tensor element-wise equality comparison
554
565
  eq(other) {
555
566
  return this.elementWiseABDAG(other, (a, b) => a === b ? 1 : 0);
556
567
  }
568
+ equal = this.eq;
569
+ // Tensor element-wise not equality comparison
570
+ ne(other) {
571
+ return this.elementWiseABDAG(other, (a, b) => a !== b ? 1 : 0);
572
+ }
573
+ notEqual = this.ne;
557
574
  // Tensor element-wise logical and
558
575
  logicalAnd(other) {
559
576
  return this.elementWiseABDAG(other, (a, b) => a === 1 && b === 1 ? 1 : 0);
@@ -598,10 +615,20 @@ class Tensor {
598
615
  neg() {
599
616
  return this.elementWiseSelfDAG((a) => -a, (self, outGrad) => outGrad.mul(-1));
600
617
  }
618
+ negative = this.neg;
619
+ // Tensor element-wise reciprocal
620
+ reciprocal() {
621
+ return this.elementWiseSelfDAG((a) => 1 / a, (self, outGrad) => outGrad.mul(self.neg().pow(-2)));
622
+ }
623
+ // Tensor element-wise square
624
+ square() {
625
+ return this.elementWiseSelfDAG((a) => a * a, (self, outGrad) => outGrad.mul(self.mul(2)));
626
+ }
601
627
  // Tensor element-wise absolute
602
628
  abs() {
603
629
  return this.elementWiseSelfDAG((a) => Math.abs(a), (self, outGrad) => outGrad.mul(self.sign()));
604
630
  }
631
+ absolute = this.abs;
605
632
  // Tensor element-wise sign function
606
633
  sign() {
607
634
  return this.elementWiseSelfDAG((a) => Math.sign(a));
@@ -622,14 +649,22 @@ class Tensor {
622
649
  asin() {
623
650
  return this.elementWiseSelfDAG((a) => Math.asin(a), (self, outGrad) => outGrad.div(self.pow(2).neg().add(1).sqrt()));
624
651
  }
652
+ arcsin = this.asin;
625
653
  // Tensor element-wise acos
626
654
  acos() {
627
655
  return this.elementWiseSelfDAG((a) => Math.acos(a), (self, outGrad) => outGrad.div(self.pow(2).neg().add(1).sqrt()).neg());
628
656
  }
657
+ arccos = this.acos;
629
658
  // Tensor element-wise atan
630
659
  atan() {
631
660
  return this.elementWiseSelfDAG((a) => Math.atan(a), (self, outGrad) => outGrad.div(self.pow(2).add(1)));
632
661
  }
662
+ arctan = this.atan;
663
+ // Tensor element-wise atan2
664
+ atan2(other) {
665
+ return this.elementWiseABDAG(other, (a, b) => Math.atan2(a, b), (self, other, outGrad) => outGrad.mul(other.div(self.square().add(other.square()))), (self, other, outGrad) => outGrad.mul(self.neg().div(self.square().add(other.square()))));
666
+ }
667
+ arctan2 = this.atan2;
633
668
  // Tensor element-wise sinh
634
669
  sinh() {
635
670
  return this.elementWiseSelfDAG((a) => Math.sinh(a), (self, outGrad) => outGrad.mul(self.cosh()));
@@ -642,22 +677,45 @@ class Tensor {
642
677
  asinh() {
643
678
  return this.elementWiseSelfDAG((a) => Math.asinh(a), (self, outGrad) => outGrad.div(self.pow(2).add(1).sqrt()));
644
679
  }
680
+ arcsinh = this.asinh;
645
681
  // Tensor element-wise acosh
646
682
  acosh() {
647
683
  return this.elementWiseSelfDAG((a) => Math.acosh(a), (self, outGrad) => outGrad.div(self.add(1).sqrt().mul(self.sub(1).sqrt())));
648
684
  }
685
+ arccosh = this.acosh;
649
686
  // Tensor element-wise atanh
650
687
  atanh() {
651
688
  return this.elementWiseSelfDAG((a) => Math.atanh(a), (self, outGrad) => outGrad.div(self.pow(2).neg().add(1)));
652
689
  }
690
+ arctanh = this.atanh;
691
+ // Tensor element-wise degree to radian
692
+ deg2rad() {
693
+ return this.elementWiseSelfDAG((a) => a * (Math.PI / 180), (self, outGrad) => outGrad.mul(Math.PI / 180));
694
+ }
695
+ // Tensor element-wise radian to degree
696
+ rad2deg() {
697
+ return this.elementWiseSelfDAG((a) => a / (Math.PI / 180), (self, outGrad) => outGrad.div(Math.PI / 180));
698
+ }
653
699
  // Tensor element-wise square root
654
700
  sqrt() {
655
701
  return this.elementWiseSelfDAG((a) => Math.sqrt(a), (self, outGrad) => outGrad.div(self.sqrt().mul(2)));
656
702
  }
703
+ // Tensor element-wise reciprocal of square root
704
+ rsqrt() {
705
+ return this.elementWiseSelfDAG((a) => 1 / Math.sqrt(a), (self, outGrad) => outGrad.mul(self.pow(-1.5).mul(-0.5)));
706
+ }
657
707
  // Tensor element-wise e^x
658
708
  exp() {
659
709
  return this.elementWiseSelfDAG((a) => Math.exp(a), (self, outGrad) => outGrad.mul(self.exp()));
660
710
  }
711
+ // Tensor element-wise 2^x
712
+ exp2() {
713
+ return this.elementWiseSelfDAG((a) => 2 ** a, (self, outGrad) => outGrad.mul(self.exp2().mul(Math.log(2))));
714
+ }
715
+ // Tensor element-wise e^x - 1
716
+ expm1() {
717
+ return this.elementWiseSelfDAG((a) => Math.expm1(a), (self, outGrad) => outGrad.mul(self.exp()));
718
+ }
661
719
  // Tensor element-wise natural log
662
720
  log() {
663
721
  return this.elementWiseSelfDAG((a) => Math.log(a), (self, outGrad) => outGrad.div(self));
@@ -689,6 +747,32 @@ class Tensor {
689
747
  tanh() {
690
748
  return this.elementWiseSelfDAG((a) => Math.tanh(a), (self, outGrad) => outGrad.mul(self.tanh().pow(2).neg().add(1)));
691
749
  }
750
+ // Tensor element-wise round
751
+ round() {
752
+ return this.elementWiseSelfDAG((a) => Math.round(a));
753
+ }
754
+ // Tensor element-wise floor
755
+ floor() {
756
+ return this.elementWiseSelfDAG((a) => Math.floor(a));
757
+ }
758
+ // Tensor element-wise ceil
759
+ ceil() {
760
+ return this.elementWiseSelfDAG((a) => Math.ceil(a));
761
+ }
762
+ // Tensor element-wise truncation
763
+ trunc() {
764
+ return this.elementWiseSelfDAG((a) => Math.trunc(a));
765
+ }
766
+ fix = this.trunc;
767
+ // Tensor element-wise fraction portion
768
+ frac() {
769
+ return this.elementWiseSelfDAG((a) => a - Math.floor(a));
770
+ }
771
+ // Tensor element-wise clip and clamp
772
+ clip(min, max) {
773
+ return this.elementWiseSelfDAG((a) => Math.max(min, Math.min(max, a)), (self, outGrad) => outGrad.mul(self.ge(min).mul(self.le(max))));
774
+ }
775
+ clamp = this.clip;
692
776
  // Transpose
693
777
  transpose(dim1, dim2) {
694
778
  // If dimension out of bound, throw error
@@ -716,6 +800,8 @@ class Tensor {
716
800
  }
717
801
  return out;
718
802
  }
803
+ swapaxes = this.transpose;
804
+ swapdims = this.transpose;
719
805
  // Transpose 2D
720
806
  t() {
721
807
  // Verify matrix shape
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "catniff",
3
- "version": "0.2.9",
3
+ "version": "0.2.10",
4
4
  "description": "A cute autograd engine for Javascript",
5
5
  "main": "index.js",
6
6
  "scripts": {