Passed
Push — main ( 051221...b63ebb )
by Shubham
02:26
created
src/core/lapack.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -167,10 +167,10 @@
 block discarded – undo
167 167
         self::init();
168 168
         if($m->dtype == \Np\matrix::FLOAT){
169 169
             return self::$ffi_lapack->LAPACKE_sgels( $matLayout, $trans, $m->row, $m->col, $b->col, $m->data,
170
-                          $m->col, $b->data, $b->col );
170
+                            $m->col, $b->data, $b->col );
171 171
         }
172 172
         return self::$ffi_lapack->LAPACKE_dgels( $matLayout, $trans, $m->row, $m->col, $b->col, $m->data,
173
-                          $m->col, $b->data, $b->col );
173
+                            $m->col, $b->data, $b->col );
174 174
     }
175 175
 
176 176
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -163,14 +163,14 @@
 block discarded – undo
163 163
      * @param string $trans
164 164
      * @return type
165 165
      */
166
-    public static function gels(\Np\matrix $m, \Np\matrix|\Np\vector $b, int $matLayout = self::ROW_MAJOR,string $trans = 'N') {
166
+    public static function gels(\Np\matrix $m, \Np\matrix | \Np\vector $b, int $matLayout = self::ROW_MAJOR, string $trans = 'N') {
167 167
         self::init();
168
-        if($m->dtype == \Np\matrix::FLOAT){
169
-            return self::$ffi_lapack->LAPACKE_sgels( $matLayout, $trans, $m->row, $m->col, $b->col, $m->data,
170
-                          $m->col, $b->data, $b->col );
168
+        if ($m->dtype == \Np\matrix::FLOAT) {
169
+            return self::$ffi_lapack->LAPACKE_sgels($matLayout, $trans, $m->row, $m->col, $b->col, $m->data,
170
+                          $m->col, $b->data, $b->col);
171 171
         }
172
-        return self::$ffi_lapack->LAPACKE_dgels( $matLayout, $trans, $m->row, $m->col, $b->col, $m->data,
173
-                          $m->col, $b->data, $b->col );
172
+        return self::$ffi_lapack->LAPACKE_dgels($matLayout, $trans, $m->row, $m->col, $b->col, $m->data,
173
+                          $m->col, $b->data, $b->col);
174 174
     }
175 175
 
176 176
 }
Please login to merge, or discard this patch.
src/linAlg.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -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 self) {
30 30
                 return $this->dotMatrix($d);
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
      * @return \Np\matrix
45 45
      */
46 46
     protected function dotMatrix(matrix $matrix): matrix {
47
-        if ($this->checkDtype($this, $matrix) && $this->checkDimensions($this,$matrix)) {
47
+        if ($this->checkDtype($this, $matrix) && $this->checkDimensions($this, $matrix)) {
48 48
             $ar = self::factory($this->row, $matrix->col, $this->dtype);
49 49
             blas::gemm($this, $matrix, $ar);
50 50
             return $ar;
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
      * Compute the multiplicative inverse of the matrix.
70 70
      * @return matrix|null
71 71
      */
72
-    public function inverse(): matrix|null {
72
+    public function inverse(): matrix | null {
73 73
         if (!$this->isSquare()) {
74 74
             self::_err('Error::invalid Size of matrix!');
75 75
         }
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
      * Compute the (Moore-Penrose) pseudo inverse of the general matrix.
94 94
      * @return matrix|null
95 95
      */
96
-    public function pseudoInverse(): matrix|null {
96
+    public function pseudoInverse(): matrix | null {
97 97
         $k = min($this->row, $this->col);
98 98
         $s = vector::factory($k, $this->dtype);
99 99
         $u = self::factory($this->row, $this->row, $this->dtype);
Please login to merge, or discard this patch.
src/matrix.php 1 patch
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -24,9 +24,9 @@  discard block
 block discarded – undo
24 24
  * @email     [email protected]
25 25
  * @copyright (c) 2020-2021, Shubham Chaudhary
26 26
  */
27
-class matrix extends nd{
27
+class matrix extends nd {
28 28
     
29
-    use ops,linAlg;
29
+    use ops, linAlg;
30 30
     /**
31 31
      * create empty 2d matrix for given data type
32 32
      * @param int $row  num of rows 
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
      * @param int|float|matrix|vector $m
311 311
      * @return matrix|vector
312 312
      */
313
-    public function multiply(int|float|matrix|vector $m): matrix|vector {
313
+    public function multiply(int | float | matrix | vector $m): matrix | vector {
314 314
         if ($m instanceof self) {
315 315
             return $this->multiplyMatrix($m);
316 316
         } else if ($m instanceof vector) {
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
      * @param int|float|matrix|vector $m
377 377
      * @return matrix
378 378
      */
379
-    public function sum(int|float|matrix|vector $m): matrix {
379
+    public function sum(int | float | matrix | vector $m): matrix {
380 380
         if ($m instanceof self) {
381 381
             return $this->sumMatrix($m);
382 382
         } elseif ($m instanceof vector) {
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
         }
387 387
     }
388 388
 
389
-    protected function sumScalar(int|float $s): matrix {
389
+    protected function sumScalar(int | float $s): matrix {
390 390
         $ar = self::factory($this->row, $this->col, $this->dtype);
391 391
         for ($i = 0; $i < $this->ndim; ++$i) {
392 392
             $ar->data[$i] = $this->data[$i] + $s;
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
      * @param int|float|matrix|vector $d matrix|$scalar to subtract this matrix
422 422
      * @return \Np\matrix
423 423
      */
424
-    public function subtract(int|float|matrix|vector $d): matrix {
424
+    public function subtract(int | float | matrix | vector $d): matrix {
425 425
         if ($d instanceof self) {
426 426
             return $this->subtractMatrix($d);
427 427
         } elseif ($d instanceof vector) {
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
         }
432 432
     }
433 433
 
434
-    protected function subtractScalar(int|float $s): matrix {
434
+    protected function subtractScalar(int | float $s): matrix {
435 435
         $ar = self::factory($this->row, $this->col, $this->dtype);
436 436
         for ($i = 0; $i < $this->ndim; ++$i) {
437 437
             $ar->data[$i] = $this->data[$i] - $s;
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
      * @return matrix
461 461
      */
462 462
     protected function subtractVector(vector $v): matrix {
463
-        if ($this->checkDimensions($v, $this) && $this->checkDtype($this,$v)) {
463
+        if ($this->checkDimensions($v, $this) && $this->checkDtype($this, $v)) {
464 464
             $ar = self::factory($this->row, $this->col, $this->dtype);
465 465
             for ($i = 0; $i < $this->row; ++$i) {
466 466
                 for ($j = 0; $j < $this->col; ++$j) {
@@ -493,7 +493,7 @@  discard block
 block discarded – undo
493 493
      * @param int|float|matrix $d
494 494
      * @return matrix
495 495
      */
496
-    public function divide(int|float|matrix|vector $d): matrix {
496
+    public function divide(int | float | matrix | vector $d): matrix {
497 497
         if ($d instanceof self) {
498 498
             return $this->divideMatrix($d);
499 499
         } elseif ($d instanceof vector) {
@@ -525,7 +525,7 @@  discard block
 block discarded – undo
525 525
         }
526 526
     }
527 527
 
528
-    protected function divideScalar(int|float $s): matrix {
528
+    protected function divideScalar(int | float $s): matrix {
529 529
         $ar = self::factory($this->row, $this->col, $this->dtype);
530 530
         for ($i = 0; $i < $this->ndim; ++$i) {
531 531
             $ar->data[$i] = $this->data[$i] / $s;
@@ -540,7 +540,7 @@  discard block
 block discarded – undo
540 540
      * @param int|float|matrix $m
541 541
      * @return matrix
542 542
      */
543
-    public function pow(int|float|matrix|vector $d): matrix {
543
+    public function pow(int | float | matrix | vector $d): matrix {
544 544
         if ($d instanceof self) {
545 545
             return $this->powMatrix($d);
546 546
         } else if ($d instanceof vector) {
@@ -572,7 +572,7 @@  discard block
 block discarded – undo
572 572
         }
573 573
     }
574 574
 
575
-    protected function powScalar(int|float $s): matrix {
575
+    protected function powScalar(int | float $s): matrix {
576 576
         $ar = $this->copy();
577 577
         for ($i = 0; $i < $this->ndim; ++$i) {
578 578
             $ar->data[$i] **= $s;
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
      * @param int|float|matrix|vector $d
586 586
      * @return matrix
587 587
      */
588
-    public function mod(int|float|matrix|vector $d): matrix {
588
+    public function mod(int | float | matrix | vector $d): matrix {
589 589
         if ($d instanceof self) {
590 590
             $this->modMatrix($d);
591 591
         } else if ($d instanceof vector) {
@@ -617,7 +617,7 @@  discard block
 block discarded – undo
617 617
         }
618 618
     }
619 619
 
620
-    protected function modScalar(int|float $s): matrix {
620
+    protected function modScalar(int | float $s): matrix {
621 621
         $ar = $this->copy();
622 622
         for ($i = 0; $i < $this->ndim; ++$i) {
623 623
             $ar->data[$i] %= $s;
@@ -729,7 +729,7 @@  discard block
 block discarded – undo
729 729
      * @param int|float $scalar
730 730
      * @return matrix
731 731
      */
732
-    public function scale(int|float $scalar): matrix {
732
+    public function scale(int | float $scalar): matrix {
733 733
         if ($scalar == 0) {
734 734
             return self::zeros($this->row, $this->col, $this->dtype);
735 735
         }
@@ -747,7 +747,7 @@  discard block
 block discarded – undo
747 747
      * @param int $row
748 748
      * @param int|float $c
749 749
      */
750
-    public function scaleRow(int $row, int|float $c) {
750
+    public function scaleRow(int $row, int | float $c) {
751 751
         for ($i = 0; $i < $this->col; ++$i) {
752 752
             $this->data[$row * $this->col + $i] *= $c;
753 753
         }
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
      * @param int $col
759 759
      * @param int|float $c
760 760
      */
761
-    public function scaleCol(int $col, int|float $c) {
761
+    public function scaleCol(int $col, int | float $c) {
762 762
         for ($i = 0; $i < $this->row; ++$i) {
763 763
             $this->data[$i * $this->col + $col] *= $c;
764 764
         }
@@ -769,14 +769,14 @@  discard block
 block discarded – undo
769 769
      * @param int|float $c
770 770
      * @param bool $lDig
771 771
      */
772
-    public function scaleDigonalCol(int|float $c, bool $lDig = true) {
773
-        if($lDig){
774
-            for ($i = 0; $i < $this->row ; ++$i) {
772
+    public function scaleDigonalCol(int | float $c, bool $lDig = true) {
773
+        if ($lDig) {
774
+            for ($i = 0; $i < $this->row; ++$i) {
775 775
                 $this->data[$i * $this->col + $i] *= $c;
776 776
             }
777 777
         }
778
-        else{
779
-            for ($i = $this->row; $i > 0 ; --$i) {
778
+        else {
779
+            for ($i = $this->row; $i > 0; --$i) {
780 780
                 $this->data[$i * $this->col - $i] *= $c;
781 781
             }
782 782
         }
@@ -823,7 +823,7 @@  discard block
 block discarded – undo
823 823
      * @return matrix
824 824
      */
825 825
     public function joinRight(matrix $m): matrix {
826
-        if ($this->row != $m->row && !$this->checkDtype($this,$m)) {
826
+        if ($this->row != $m->row && !$this->checkDtype($this, $m)) {
827 827
             self::_err('Error::Invalid size! or DataType!');
828 828
         }
829 829
         $col = $this->col + $m->col;
@@ -889,7 +889,7 @@  discard block
 block discarded – undo
889 889
      *
890 890
      * @return matrix|null
891 891
      */
892
-    public function ref(): matrix|null {
892
+    public function ref(): matrix | null {
893 893
         return ref::factory($this);
894 894
     }
895 895
 
@@ -898,7 +898,7 @@  discard block
 block discarded – undo
898 898
      *
899 899
      * @return matrix|null
900 900
      */
901
-    public function cholesky(): matrix|null {
901
+    public function cholesky(): matrix | null {
902 902
         return cholesky::factory($this);
903 903
     }
904 904
 
@@ -973,7 +973,7 @@  discard block
 block discarded – undo
973 973
      * @param bool $dignoal
974 974
      * @return void
975 975
      */
976
-    public function setData(int|float|array $data): void {
976
+    public function setData(int | float | array $data): void {
977 977
 
978 978
         if (is_array($data) && is_array($data[0])) {
979 979
             $f = $this->flattenArray($data);
@@ -1004,7 +1004,7 @@  discard block
 block discarded – undo
1004 1004
      * @return object
1005 1005
      */
1006 1006
     public function getShape(): object {
1007
-        return (object) ['m' => $this->row, 'n' => $this->col];
1007
+        return (object)['m' => $this->row, 'n' => $this->col];
1008 1008
     }
1009 1009
 
1010 1010
     /**
@@ -1186,7 +1186,7 @@  discard block
 block discarded – undo
1186 1186
      * @param vector|null $mean
1187 1187
      * @return vector
1188 1188
      */
1189
-    public function variance(vector|null $mean = null): vector {
1189
+    public function variance(vector | null $mean = null): vector {
1190 1190
         if (isset($mean)) {
1191 1191
             if (!$mean instanceof vector) {
1192 1192
                 self::_invalidArgument('mean must be a vector!');
@@ -1228,7 +1228,7 @@  discard block
 block discarded – undo
1228 1228
      * @param vector|null $mean
1229 1229
      * @return matrix
1230 1230
      */
1231
-    public function covariance(vector|null $mean = null): matrix {
1231
+    public function covariance(vector | null $mean = null): matrix {
1232 1232
         if (isset($mean)) {
1233 1233
             if ($mean->col !== $this->row) {
1234 1234
                 self::_err('Err:: given mean vector dimensionality mismatched!');
@@ -1256,7 +1256,7 @@  discard block
 block discarded – undo
1256 1256
      * @param int|float|matrix|vector $d
1257 1257
      * @return matrix
1258 1258
      */
1259
-    public function equal(int|float|matrix|vector $d): matrix {
1259
+    public function equal(int | float | matrix | vector $d): matrix {
1260 1260
         if ($d instanceof self) {
1261 1261
             return $this->equalMatrix($d);
1262 1262
         } elseif ($d instanceof vector) {
@@ -1288,7 +1288,7 @@  discard block
 block discarded – undo
1288 1288
         }
1289 1289
     }
1290 1290
 
1291
-    protected function equalScalar(int|float $s): matrix {
1291
+    protected function equalScalar(int | float $s): matrix {
1292 1292
         $ar = self::factory($this->row, $this->col, $this->dtype);
1293 1293
         for ($i = 0; $i < $this->ndim; ++$i) {
1294 1294
             $ar->data[$i] = $this->data[$i] == $s ? 1 : 0;
@@ -1301,7 +1301,7 @@  discard block
 block discarded – undo
1301 1301
      * @param int|float|matrix|vector $d
1302 1302
      * @return matrix
1303 1303
      */
1304
-    public function greater(int|float|matrix|vector $d): matrix {
1304
+    public function greater(int | float | matrix | vector $d): matrix {
1305 1305
         if ($d instanceof self) {
1306 1306
             return $this->greaterMatrix($d);
1307 1307
         } elseif ($d instanceof vector) {
@@ -1312,7 +1312,7 @@  discard block
 block discarded – undo
1312 1312
     }
1313 1313
 
1314 1314
     protected function greaterMatrix(matrix $m): matrix {
1315
-        if ($this->checkShape($this, $m) && $this->checkDtype($this,$m)) {
1315
+        if ($this->checkShape($this, $m) && $this->checkDtype($this, $m)) {
1316 1316
             $ar = self::factory($this->row, $this->col, $this->dtype);
1317 1317
             for ($i = 0; $i < $this->ndim; ++$i) {
1318 1318
                 $ar->data[$i] = $this->data[$i] > $m->data[$i] ? 1 : 0;
@@ -1322,7 +1322,7 @@  discard block
 block discarded – undo
1322 1322
     }
1323 1323
 
1324 1324
     protected function greaterVector(vector $v): matrix {
1325
-        if ($this->checkDimensions($v, $this) && $this->checkDtype($this,$v)) {
1325
+        if ($this->checkDimensions($v, $this) && $this->checkDtype($this, $v)) {
1326 1326
             $ar = self::factory($this->row, $this->col, $this->dtype);
1327 1327
             for ($i = 0; $i < $this->row; ++$i) {
1328 1328
                 for ($j = 0; $j < $this->col; ++$j) {
@@ -1333,7 +1333,7 @@  discard block
 block discarded – undo
1333 1333
         }
1334 1334
     }
1335 1335
 
1336
-    protected function greaterScalar(int|float $s): matrix {
1336
+    protected function greaterScalar(int | float $s): matrix {
1337 1337
         $ar = self::factory($this->row, $this->col, $this->dtype);
1338 1338
         for ($i = 0; $i < $this->ndim; ++$i) {
1339 1339
             $ar->data[$i] = $this->data[$i] > $s ? 1 : 0;
@@ -1346,10 +1346,10 @@  discard block
 block discarded – undo
1346 1346
      * @param int|float|matrix $m
1347 1347
      * @return matrix
1348 1348
      */
1349
-    public function less(int|float|matrix $m): matrix {
1349
+    public function less(int | float | matrix $m): matrix {
1350 1350
         $ar = self::factory($this->row, $this->col, $this->dtype);
1351 1351
         if ($m instanceof self) {
1352
-            if ($this->checkShape($this,$m)) {
1352
+            if ($this->checkShape($this, $m)) {
1353 1353
                 for ($i = 0; $i < $this->ndim; ++$i) {
1354 1354
                     $ar->data[$i] = $this->data[$i] < $m->data[$i] ? 1 : 0;
1355 1355
                 }
@@ -1397,7 +1397,7 @@  discard block
 block discarded – undo
1397 1397
     }
1398 1398
 
1399 1399
     public function __toString() {
1400
-        return (string) $this->printMatrix();
1400
+        return (string)$this->printMatrix();
1401 1401
     }
1402 1402
 
1403 1403
     private function flattenArray(array $ar) {
Please login to merge, or discard this patch.