Passed
Push — main ( b63ebb...d6f51d )
by Shubham
02:04
created
src/vector.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -17,8 +17,8 @@
 block discarded – undo
17 17
  * @copyright (c) 2020-2021, Shubham Chaudhary
18 18
  * 
19 19
  */
20
- class vector extends nd {
21
-     use ops,linAlgb\linAlg;
20
+    class vector extends nd {
21
+        use ops,linAlgb\linAlg;
22 22
 
23 23
     /**
24 24
      * Factory method to build a new vector.
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 
5 5
 namespace Np;
6 6
 
7
-use Np\core\{nd,blas,lapack};
7
+use Np\core\{nd, blas, lapack};
8 8
 use Np\exceptions\invalidArgumentException;
9 9
 
10 10
 /** 
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
  * 
19 19
  */
20 20
  class vector extends nd {
21
-     use ops,linAlgb\linAlg;
21
+     use ops, linAlgb\linAlg;
22 22
 
23 23
     /**
24 24
      * Factory method to build a new vector.
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
      * @param int|float|double $val
123 123
      * @return vector
124 124
      */
125
-    public static function full(int $col, int|float $val): vector {
125
+    public static function full(int $col, int | float $val): vector {
126 126
         $ar = self::factory($col);
127 127
         for ($i = 0; $i < $col; ++$i) {
128 128
             $ar->data[$i] = $val;
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
      * @param int|float $interval
139 139
      * @return vector
140 140
      */
141
-    public static function range(int|float $start, int|float $end, int|float $interval = 1): vector {
141
+    public static function range(int | float $start, int | float $end, int | float $interval = 1): vector {
142 142
         return self::ar(range($start, $end, $interval));
143 143
     }
144 144
 
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
      * @param int|float|matrix|vector $d
270 270
      * @return matrix|vector
271 271
      */
272
-    public function divide(int|float|matrix|vector $d): matrix|vector {
272
+    public function divide(int | float | matrix | vector $d): matrix | vector {
273 273
         if ($d instanceof matrix) {
274 274
             return $this->divideMatrix($d);
275 275
         }
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
      * @param int|float $s
317 317
      * @return vector
318 318
      */
319
-    protected function divideScalar(int|float $s): vector {
319
+    protected function divideScalar(int | float $s): vector {
320 320
         $vr = self::factory($this->col);
321 321
         for ($i = 0; $i < $this->col; ++$i) {
322 322
             $vr->data[$i] = $this->data[$i] / $s;
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
      * @param int|float|matrix|vector $d
330 330
      * @return matrix|vector
331 331
      */
332
-    public function multiply(int|float|matrix|vector $d): matrix|vector {
332
+    public function multiply(int | float | matrix | vector $d): matrix | vector {
333 333
         if ($d instanceof matrix) {
334 334
             return $this->multiplyMatrix($d);
335 335
         }
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
      * @param int|float $s
377 377
      * @return vector
378 378
      */
379
-    protected function multiplyScalar(int|float $s): vector {
379
+    protected function multiplyScalar(int | float $s): vector {
380 380
         $vr = $this->copy();
381 381
         blas::scale($s, $vr);
382 382
         return $vr;
@@ -387,7 +387,7 @@  discard block
 block discarded – undo
387 387
      * @param int|float|matrix|vector $d
388 388
      * @return matrix|vector
389 389
      */
390
-    public function add(int|float|matrix|vector $d): matrix|vector {
390
+    public function add(int | float | matrix | vector $d): matrix | vector {
391 391
         if ($d instanceof matrix) {
392 392
             return $this->addMatrix($d);
393 393
         }
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
      * @param int|float $s
435 435
      * @return vector
436 436
      */
437
-    protected function addScalar(int|float $s): vector {
437
+    protected function addScalar(int | float $s): vector {
438 438
         $vr = $this->copy();
439 439
         for ($i = 0; $i < $this->col; ++$i) {
440 440
             $vr->data[$i] += $s;
@@ -447,7 +447,7 @@  discard block
 block discarded – undo
447 447
      * @param int|float|\Np\matrix|\Np\vector $d
448 448
      * @return matrix|vector
449 449
      */
450
-    public function pow(int|float|\Np\matrix|\Np\vector $d): matrix|vector {
450
+    public function pow(int | float | \Np\matrix | \Np\vector $d): matrix | vector {
451 451
         if ($d instanceof matrix) {
452 452
             return $this->powMatrix($d);
453 453
         }
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
      * @param int|float $s
496 496
      * @return vector
497 497
      */
498
-    protected function powScalar(int|float $s): vector {
498
+    protected function powScalar(int | float $s): vector {
499 499
         $v = $this->copy();
500 500
         for ($i = 0; $i < $this->col; ++$i) {
501 501
             $v->data[$i] = $v->data[$i] ** $s;
@@ -508,7 +508,7 @@  discard block
 block discarded – undo
508 508
      * @param int|float|\Np\matrix|\Np\vector $d
509 509
      * @return matrix|vector
510 510
      */
511
-    public function mod(int|float|\Np\matrix|\Np\vector $d): matrix|vector {
511
+    public function mod(int | float | \Np\matrix | \Np\vector $d): matrix | vector {
512 512
         if ($d instanceof matrix) {
513 513
             return $this->powMatrix($d);
514 514
         }
@@ -554,7 +554,7 @@  discard block
 block discarded – undo
554 554
      * 
555 555
      * @param int|float $s
556 556
      */
557
-    protected function modScalar(int|float $s) {
557
+    protected function modScalar(int | float $s) {
558 558
         $v = $this->copy();
559 559
         for ($i = 0; $i < $this->col; ++$i) {
560 560
             $v->data[$i] = $v->data[$i] % $s;
@@ -566,7 +566,7 @@  discard block
 block discarded – undo
566 566
      * @param int|float|matrix|vector $d
567 567
      * @return matrix|vector
568 568
      */
569
-    public function subtract(int|float|matrix|vector $d): matrix|vector {
569
+    public function subtract(int | float | matrix | vector $d): matrix | vector {
570 570
         if ($d instanceof matrix) {
571 571
             return $this->subtractMatrix($d);
572 572
         }
@@ -599,7 +599,7 @@  discard block
 block discarded – undo
599 599
      * @return vector
600 600
      */
601 601
     protected function subtractVector(\Np\vector $vector): vector {
602
-        if ($this->checkShape($this, $vector) ) {
602
+        if ($this->checkShape($this, $vector)) {
603 603
             $vr = self::factory($this->col);
604 604
             for ($i = 0; $i < $this->col; ++$i) {
605 605
                 $vr->data[$i] = $this->data[$i] - $vector->data[$i];
@@ -613,7 +613,7 @@  discard block
 block discarded – undo
613 613
      * @param \Np\vector $scalar
614 614
      * @return \Np\vector
615 615
      */
616
-    protected function substractScalar(int|float $scalar): vector {
616
+    protected function substractScalar(int | float $scalar): vector {
617 617
         $vr = self::factory($this->col);
618 618
         for ($i = 0; $i < $this->col; ++$i) {
619 619
             $vr->data[$i] = $this->data[$i] - $scalar;
@@ -685,15 +685,15 @@  discard block
 block discarded – undo
685 685
      * 
686 686
      * @return int|float
687 687
      */
688
-    public function mean():int|float {
689
-        return $this->sum()/ $this->col;
688
+    public function mean():int | float {
689
+        return $this->sum() / $this->col;
690 690
     }
691 691
     
692 692
     /**
693 693
      * 
694 694
      * @return int|float
695 695
      */
696
-    public function median():int|float {
696
+    public function median():int | float {
697 697
         $mid = intdiv($this->col, 2);
698 698
 
699 699
         $a = $this->copy()->sort();
@@ -738,7 +738,7 @@  discard block
 block discarded – undo
738 738
      * set data to vector
739 739
      * @param int|float|array $data
740 740
      */
741
-    public function setData(int|float|array $data) {
741
+    public function setData(int | float | array $data) {
742 742
         if (is_array($data) && !is_array($data[0])) {
743 743
             for ($i = 0; $i < $this->col; ++$i) {
744 744
                 $this->data[$i] = $data[$i];
@@ -780,7 +780,7 @@  discard block
 block discarded – undo
780 780
     }
781 781
 
782 782
     public function __toString() {
783
-        return (string) $this->printVector();
783
+        return (string)$this->printVector();
784 784
     }
785 785
 
786 786
     protected function __construct(public int $col, int $dtype = self::DOUBLE) {
Please login to merge, or discard this patch.
src/ops.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
      * @param matrix|vector $d
20 20
      * @return matrix|vector
21 21
      */
22
-    public function max(matrix|vector $d): matrix|vector {
22
+    public function max(matrix | vector $d): matrix | vector {
23 23
         if ($this instanceof matrix && $d instanceof matrix && $this->checkShape($this, $d)) {
24 24
             $r = self::factory($this->row, $this->col);
25 25
         } elseif ($this instanceof vector && $d instanceof vector && $this->checkShape($this, $d)) {
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
      * @param matrix|vector $d
37 37
      * @return matrix|vector
38 38
      */
39
-    public function min(matrix|vector $d): matrix|vector {
39
+    public function min(matrix | vector $d): matrix | vector {
40 40
         if ($this instanceof matrix && $d instanceof matrix && $this->checkShape($this, $d)) {
41 41
             $r = self::factory($this->row, $this->col);
42 42
         } elseif ($this instanceof vector && $d instanceof vector && $this->checkShape($this, $d)) {
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
      * @param callable $func
54 54
      * @return matrix|vector
55 55
      */
56
-    public function map(callable $func): matrix|vector {
56
+    public function map(callable $func): matrix | vector {
57 57
         if ($this instanceof matrix) {
58 58
             $r = self::factory($this->row, $this->col);
59 59
         } else {
@@ -65,23 +65,23 @@  discard block
 block discarded – undo
65 65
         return $r;
66 66
     }
67 67
 
68
-    public function abs(): matrix|vector {
68
+    public function abs(): matrix | vector {
69 69
         return $this->map('abs');
70 70
     }
71 71
 
72
-    public function sqrt(): matrix|vector {
72
+    public function sqrt(): matrix | vector {
73 73
         return $this->map('sqrt');
74 74
     }
75 75
 
76
-    public function exp(): matrix|vector {
76
+    public function exp(): matrix | vector {
77 77
         return $this->map('exp');
78 78
     }
79 79
 
80
-    public function exp1(): matrix|vector {
80
+    public function exp1(): matrix | vector {
81 81
         return $this->map('exp1');
82 82
     }
83 83
 
84
-    public function log(float $b = M_E): matrix|vector {
84
+    public function log(float $b = M_E): matrix | vector {
85 85
         $ar = $this->copy();
86 86
         for ($i = 0; $i < $ar->ndim; ++$i) {
87 87
             log($ar->data[$i], $b);
@@ -89,52 +89,52 @@  discard block
 block discarded – undo
89 89
         return $ar;
90 90
     }
91 91
 
92
-    public function log1p(): matrix|vector {
92
+    public function log1p(): matrix | vector {
93 93
         return $this->map('log1p');
94 94
     }
95 95
 
96
-    public function sin(): matrix|vector {
96
+    public function sin(): matrix | vector {
97 97
         return $this->map('sin');
98 98
     }
99 99
 
100
-    public function asin(): matrix|vector {
100
+    public function asin(): matrix | vector {
101 101
         return $this->map('asin');
102 102
     }
103 103
 
104
-    public function cos(): matrix|vector {
104
+    public function cos(): matrix | vector {
105 105
         return $this->map('cos');
106 106
     }
107 107
 
108
-    public function acos(): matrix|vector {
108
+    public function acos(): matrix | vector {
109 109
         return $this->map('acos');
110 110
     }
111 111
 
112
-    public function tan(): matrix|vector {
112
+    public function tan(): matrix | vector {
113 113
         return $this->map('tan');
114 114
     }
115 115
 
116
-    public function atan(): matrix|vector {
116
+    public function atan(): matrix | vector {
117 117
         return $this->map('atan');
118 118
     }
119 119
 
120
-    public function radToDeg(): matrix|vector {
120
+    public function radToDeg(): matrix | vector {
121 121
         return $this->map('rad2deg');
122 122
     }
123 123
 
124
-    public function degToRad(): matrix|vector {
124
+    public function degToRad(): matrix | vector {
125 125
         return $this->map('deg2rad');
126 126
     }
127 127
 
128
-    public function floor(): matrix|vector {
128
+    public function floor(): matrix | vector {
129 129
         return $this->map('floor');
130 130
     }
131 131
 
132
-    public function ceil(): matrix|vector {
132
+    public function ceil(): matrix | vector {
133 133
         return $this->map('ceil');
134 134
     }
135 135
     
136 136
     public function free():void {
137
-        if($this instanceof matrix) {
137
+        if ($this instanceof matrix) {
138 138
             unset($this->row);
139 139
             unset($this->col);
140 140
             unset($this->ndim);
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
      * make a copy of matrix|vector;
154 154
      * @return matrix|vector
155 155
      */
156
-    public function copy(): matrix|vector {
156
+    public function copy(): matrix | vector {
157 157
         return clone $this;
158 158
     }
159 159
     
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
      * @param float $max
166 166
      * @return matrix
167 167
      */
168
-    public function clip(float $min, float $max): matrix|vector {
168
+    public function clip(float $min, float $max): matrix | vector {
169 169
         if ($this instanceof matrix) {
170 170
             $ar = self::factory($this->row, $this->col);
171 171
         } else {
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
      * @param float $min
191 191
      * @return matrix
192 192
      */
193
-    public function clipLower(float $min): matrix|vector {
193
+    public function clipLower(float $min): matrix | vector {
194 194
         if ($this instanceof matrix) {
195 195
             $ar = self::factory($this->row, $this->col);
196 196
         } else {
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
      * @param float $max
213 213
      * @return matrix
214 214
      */
215
-    public function clipUpper(float $max): matrix|vector {
215
+    public function clipUpper(float $max): matrix | vector {
216 216
         if ($this instanceof matrix) {
217 217
             $ar = self::factory($this->row, $this->col);
218 218
         } else {
Please login to merge, or discard this patch.
src/linAlgb/decompositions/svd.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare (strict_types=1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Np\linAlgb\decompositions;
6 6
 
Please login to merge, or discard this patch.
src/linAlgb/decompositions/lu.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare (strict_types=1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Np\linAlgb\decompositions;
6 6
 
Please login to merge, or discard this patch.
src/linAlgb/decompositions/eigen.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare (strict_types=1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Np\linAlgb\decompositions;
6 6
 
Please login to merge, or discard this patch.
src/linAlgb/decompositions/cholesky.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare (strict_types=1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Np\linAlgb\decompositions;
6 6
 
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
      * @return matrix|null
28 28
      * 
29 29
      */
30
-    public static function factory(matrix $m): matrix|null {
30
+    public static function factory(matrix $m): matrix | null {
31 31
         if ($m->isSquare()) {
32 32
             $ar = $m->copy();
33 33
             $lp = lapack::potrf($ar);
Please login to merge, or discard this patch.
src/linAlgb/linAlg.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 declare(strict_types=1);
3 3
 namespace Np\linAlgb;
4 4
 
5
-use Np\core\{blas,lapack};
5
+use Np\core\{blas, lapack};
6 6
 use Np\matrix, Np\vector;
7 7
 /**
8 8
  * Linear Algebra
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
      * @param \Np\matrix|\Np\vector $d
25 25
      * @return matrix|vector
26 26
      */
27
-    public function dot(matrix|vector $d): matrix|vector {
27
+    public function dot(matrix | vector $d): matrix | vector {
28 28
         if ($this instanceof matrix) {
29 29
             if ($d instanceof matrix) {
30 30
                 return $this->dotMatrix($d);
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
      * @return \Np\matrix
41 41
      */
42 42
     protected function dotMatrix(matrix $matrix): matrix {
43
-        if ($this->checkDimensions($this,$matrix)) {
43
+        if ($this->checkDimensions($this, $matrix)) {
44 44
             $ar = self::factory($this->row, $matrix->col);
45 45
             blas::gemm($this, $matrix, $ar);
46 46
             return $ar;
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
      * Compute the multiplicative inverse of the matrix.
66 66
      * @return matrix|null
67 67
      */
68
-    public function inverse(): matrix|null {
68
+    public function inverse(): matrix | null {
69 69
         if ($this->isSquare()) {
70 70
             $imat = $this->copy();
71 71
             $ipiv = vector::factory($this->row, vector::INT);
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
      * Compute the (Moore-Penrose) pseudo inverse of the general matrix.
90 90
      * @return matrix|null
91 91
      */
92
-    public function pseudoInverse(): matrix|null {
92
+    public function pseudoInverse(): matrix | null {
93 93
         $k = min($this->row, $this->col);
94 94
         $s = vector::factory($k);
95 95
         $u = self::factory($this->row, $this->row);
Please login to merge, or discard this patch.
src/core/nd.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -31,21 +31,21 @@  discard block
 block discarded – undo
31 31
     public $data;
32 32
     protected $_time = null, $_mem = null;
33 33
     
34
-    public function checkDimensions(\Np\matrix|\Np\vector $Obj1, \Np\matrix $Obj2) {
35
-        if($Obj1->col == $Obj2->row){
34
+    public function checkDimensions(\Np\matrix | \Np\vector $Obj1, \Np\matrix $Obj2) {
35
+        if ($Obj1->col == $Obj2->row) {
36 36
             return true;
37 37
         }
38 38
         self::_dimensionaMisMatchErr('Mismatch Dimensions of given Objects! Obj-A col & Obj-B row amount need to be the same!');
39 39
     }
40 40
     
41
-    public function checkDtype(\Np\matrix|\Np\vector $Obj1, \Np\matrix|\Np\vector $Obj2){
42
-        if($Obj1->dtype == $Obj2->dtype) {
41
+    public function checkDtype(\Np\matrix | \Np\vector $Obj1, \Np\matrix | \Np\vector $Obj2) {
42
+        if ($Obj1->dtype == $Obj2->dtype) {
43 43
             return true;
44 44
         }
45 45
         self::_dtypeErr('mismatch data type of given Np\Objects!');
46 46
     }
47 47
     
48
-    public function checkShape(\Np\matrix|\Np\vector $Obj1, \Np\matrix|\Np\vector $Obj2) {
48
+    public function checkShape(\Np\matrix | \Np\vector $Obj1, \Np\matrix | \Np\vector $Obj2) {
49 49
         if ($Obj1 instanceof \Np\vector && $Obj2 instanceof \Np\vector) {
50 50
             if ($Obj1->col == $Obj2->col) {
51 51
                 return true;
@@ -64,8 +64,8 @@  discard block
 block discarded – undo
64 64
         }
65 65
     }
66 66
     
67
-    public function asType(int $dtype){
68
-        switch ($dtype){
67
+    public function asType(int $dtype) {
68
+        switch ($dtype) {
69 69
             case self::FLOAT:
70 70
                 \FFI::cast('float *', $this->data);
71 71
                 break;
Please login to merge, or discard this patch.
src/core/blas.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -318,7 +318,7 @@
 block discarded – undo
318 318
      * @param \Np\vector|\Np\matrix $v
319 319
      * @return \FFI\CData
320 320
      */
321
-    public static function scale(float $alpha, \Np\vector|\Np\matrix $v) {
321
+    public static function scale(float $alpha, \Np\vector | \Np\matrix $v) {
322 322
         self::init();
323 323
         return self::$ffi_blas->cblas_dscal($v->ndim, $alpha, $v->data, 1);
324 324
     }
Please login to merge, or discard this patch.