Passed
Push — main ( b63ebb...d6f51d )
by Shubham
02:04
created
src/matrix.php 1 patch
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -4,9 +4,9 @@  discard block
 block discarded – undo
4 4
 
5 5
 namespace Np;
6 6
 
7
-use Np\core\{nd,blas,lapack};
8
-use Np\linAlgb\reductions\{ref,rref};
9
-use Np\linAlgb\decompositions\{lu,svd,eigen,cholesky};
7
+use Np\core\{nd, blas, lapack};
8
+use Np\linAlgb\reductions\{ref, rref};
9
+use Np\linAlgb\decompositions\{lu, svd, eigen, cholesky};
10 10
 
11 11
 /**
12 12
  * Matrix
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
  */
20 20
 class matrix extends nd {
21 21
 
22
-    use ops,linAlgb\linAlg;
22
+    use ops, linAlgb\linAlg;
23 23
 
24 24
     /**
25 25
      * create empty 2d matrix for given data type
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
      * @param int|float $val
127 127
      * @return \Np\matrix
128 128
      */
129
-    public static function full(int $row, int $col, int|float $val): matrix {
129
+    public static function full(int $row, int $col, int | float $val): matrix {
130 130
         $ar = self::factory($row, $col);
131 131
         for ($i = 0; $i < $ar->ndim; ++$i) {
132 132
             $ar->data[$i] = $val;
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
      * @param int|float|matrix|vector $m
351 351
      * @return matrix|vector
352 352
      */
353
-    public function multiply(int|float|matrix|vector $m): matrix|vector {
353
+    public function multiply(int | float | matrix | vector $m): matrix | vector {
354 354
         if ($m instanceof self) {
355 355
             return $this->multiplyMatrix($m);
356 356
         } else if ($m instanceof vector) {
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
      * @param int|float|matrix|vector $m
401 401
      * @return matrix
402 402
      */
403
-    public function sum(int|float|matrix|vector $m): matrix {
403
+    public function sum(int | float | matrix | vector $m): matrix {
404 404
         if ($m instanceof self) {
405 405
             return $this->sumMatrix($m);
406 406
         } elseif ($m instanceof vector) {
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
         }
411 411
     }
412 412
 
413
-    protected function sumScalar(int|float $s): matrix {
413
+    protected function sumScalar(int | float $s): matrix {
414 414
         $ar = self::factory($this->row, $this->col);
415 415
         for ($i = 0; $i < $this->ndim; ++$i) {
416 416
             $ar->data[$i] = $this->data[$i] + $s;
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
      * @param int|float|matrix|vector $d matrix|$scalar to subtract this matrix
462 462
      * @return \Np\matrix
463 463
      */
464
-    public function subtract(int|float|matrix|vector $d): matrix {
464
+    public function subtract(int | float | matrix | vector $d): matrix {
465 465
         if ($d instanceof self) {
466 466
             return $this->subtractMatrix($d);
467 467
         } elseif ($d instanceof vector) {
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
         }
472 472
     }
473 473
 
474
-    protected function subtractScalar(int|float $s): matrix {
474
+    protected function subtractScalar(int | float $s): matrix {
475 475
         $ar = self::factory($this->row, $this->col);
476 476
         for ($i = 0; $i < $this->ndim; ++$i) {
477 477
             $ar->data[$i] = $this->data[$i] - $s;
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
      * @param int|float|matrix $d
534 534
      * @return matrix
535 535
      */
536
-    public function divide(int|float|matrix|vector $d): matrix {
536
+    public function divide(int | float | matrix | vector $d): matrix {
537 537
         if ($d instanceof self) {
538 538
             return $this->divideMatrix($d);
539 539
         } elseif ($d instanceof vector) {
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
         }
566 566
     }
567 567
 
568
-    protected function divideScalar(int|float $s): matrix {
568
+    protected function divideScalar(int | float $s): matrix {
569 569
         $ar = self::factory($this->row, $this->col);
570 570
         for ($i = 0; $i < $this->ndim; ++$i) {
571 571
             $ar->data[$i] = $this->data[$i] / $s;
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
      * @param int|float|matrix $m
581 581
      * @return matrix
582 582
      */
583
-    public function pow(int|float|matrix|vector $d): matrix {
583
+    public function pow(int | float | matrix | vector $d): matrix {
584 584
         if ($d instanceof self) {
585 585
             return $this->powMatrix($d);
586 586
         } else if ($d instanceof vector) {
@@ -612,7 +612,7 @@  discard block
 block discarded – undo
612 612
         }
613 613
     }
614 614
 
615
-    protected function powScalar(int|float $s): matrix {
615
+    protected function powScalar(int | float $s): matrix {
616 616
         $ar = $this->copy();
617 617
         for ($i = 0; $i < $this->ndim; ++$i) {
618 618
             $ar->data[$i] **= $s;
@@ -625,7 +625,7 @@  discard block
 block discarded – undo
625 625
      * @param int|float|matrix|vector $d
626 626
      * @return matrix
627 627
      */
628
-    public function mod(int|float|matrix|vector $d): matrix {
628
+    public function mod(int | float | matrix | vector $d): matrix {
629 629
         if ($d instanceof self) {
630 630
             $this->modMatrix($d);
631 631
         } else if ($d instanceof vector) {
@@ -657,7 +657,7 @@  discard block
 block discarded – undo
657 657
         }
658 658
     }
659 659
 
660
-    protected function modScalar(int|float $s): matrix {
660
+    protected function modScalar(int | float $s): matrix {
661 661
         $ar = $this->copy();
662 662
         for ($i = 0; $i < $this->ndim; ++$i) {
663 663
             $ar->data[$i] %= $s;
@@ -730,7 +730,7 @@  discard block
 block discarded – undo
730 730
      * @param int|float $scalar
731 731
      * @return matrix
732 732
      */
733
-    public function scale(int|float $scalar): matrix {
733
+    public function scale(int | float $scalar): matrix {
734 734
         if ($scalar == 0) {
735 735
             return self::zeros($this->row, $this->col);
736 736
         }
@@ -748,7 +748,7 @@  discard block
 block discarded – undo
748 748
      * @param int $row
749 749
      * @param int|float $c
750 750
      */
751
-    public function scaleRow(int $row, int|float $c) {
751
+    public function scaleRow(int $row, int | float $c) {
752 752
         for ($i = 0; $i < $this->col; ++$i) {
753 753
             $this->data[$row * $this->col + $i] *= $c;
754 754
         }
@@ -759,7 +759,7 @@  discard block
 block discarded – undo
759 759
      * @param int $col
760 760
      * @param int|float $c
761 761
      */
762
-    public function scaleCol(int $col, int|float $c) {
762
+    public function scaleCol(int $col, int | float $c) {
763 763
         for ($i = 0; $i < $this->row; ++$i) {
764 764
             $this->data[$i * $this->col + $col] *= $c;
765 765
         }
@@ -770,7 +770,7 @@  discard block
 block discarded – undo
770 770
      * @param int|float $c
771 771
      * @param bool $lDig
772 772
      */
773
-    public function scaleDigonalCol(int|float $c, bool $lDig = true) {
773
+    public function scaleDigonalCol(int | float $c, bool $lDig = true) {
774 774
         if ($lDig) {
775 775
             for ($i = 0; $i < $this->row; ++$i) {
776 776
                 $this->data[$i * $this->col + $i] *= $c;
@@ -944,7 +944,7 @@  discard block
 block discarded – undo
944 944
      * @param bool $dignoal
945 945
      * @return void
946 946
      */
947
-    public function setData(int|float|array $data): void {
947
+    public function setData(int | float | array $data): void {
948 948
 
949 949
         if (is_array($data) && is_array($data[0])) {
950 950
             $f = $this->flattenArray($data);
@@ -975,7 +975,7 @@  discard block
 block discarded – undo
975 975
      * @return object
976 976
      */
977 977
     public function getShape(): object {
978
-        return (object) ['m' => $this->row, 'n' => $this->col];
978
+        return (object)['m' => $this->row, 'n' => $this->col];
979 979
     }
980 980
 
981 981
     /**
@@ -1087,7 +1087,7 @@  discard block
 block discarded – undo
1087 1087
      *
1088 1088
      * @return matrix|null
1089 1089
      */
1090
-    public function ref(): matrix|null {
1090
+    public function ref(): matrix | null {
1091 1091
         return ref::factory($this);
1092 1092
     }
1093 1093
 
@@ -1096,7 +1096,7 @@  discard block
 block discarded – undo
1096 1096
      *
1097 1097
      * @return matrix|null
1098 1098
      */
1099
-    public function cholesky(): matrix|null {
1099
+    public function cholesky(): matrix | null {
1100 1100
         return cholesky::factory($this);
1101 1101
     }
1102 1102
 
@@ -1189,7 +1189,7 @@  discard block
 block discarded – undo
1189 1189
      * @param vector|null $mean
1190 1190
      * @return vector
1191 1191
      */
1192
-    public function variance(vector|null $mean = null): vector {
1192
+    public function variance(vector | null $mean = null): vector {
1193 1193
         if (isset($mean)) {
1194 1194
             if (!$mean instanceof vector) {
1195 1195
                 self::_invalidArgument('mean must be a vector!');
@@ -1231,7 +1231,7 @@  discard block
 block discarded – undo
1231 1231
      * @param vector|null $mean
1232 1232
      * @return matrix
1233 1233
      */
1234
-    public function covariance(vector|null $mean = null): matrix {
1234
+    public function covariance(vector | null $mean = null): matrix {
1235 1235
         if (isset($mean)) {
1236 1236
             if ($mean->col !== $this->row) {
1237 1237
                 self::_err('Err:: given mean vector dimensionality mismatched!');
@@ -1259,7 +1259,7 @@  discard block
 block discarded – undo
1259 1259
      * @param int|float|matrix|vector $d
1260 1260
      * @return matrix
1261 1261
      */
1262
-    public function equal(int|float|matrix|vector $d): matrix {
1262
+    public function equal(int | float | matrix | vector $d): matrix {
1263 1263
         if ($d instanceof self) {
1264 1264
             return $this->equalMatrix($d);
1265 1265
         }
@@ -1291,7 +1291,7 @@  discard block
 block discarded – undo
1291 1291
         }
1292 1292
     }
1293 1293
 
1294
-    protected function equalScalar(int|float $s): matrix {
1294
+    protected function equalScalar(int | float $s): matrix {
1295 1295
         $ar = self::factory($this->row, $this->col);
1296 1296
         for ($i = 0; $i < $this->ndim; ++$i) {
1297 1297
             $ar->data[$i] = $this->data[$i] == $s ? 1 : 0;
@@ -1304,7 +1304,7 @@  discard block
 block discarded – undo
1304 1304
      * @param int|float|matrix|vector $d
1305 1305
      * @return matrix
1306 1306
      */
1307
-    public function greater(int|float|matrix|vector $d): matrix {
1307
+    public function greater(int | float | matrix | vector $d): matrix {
1308 1308
         if ($d instanceof self) {
1309 1309
             return $this->greaterMatrix($d);
1310 1310
         }
@@ -1336,7 +1336,7 @@  discard block
 block discarded – undo
1336 1336
         }
1337 1337
     }
1338 1338
 
1339
-    protected function greaterScalar(int|float $s): matrix {
1339
+    protected function greaterScalar(int | float $s): matrix {
1340 1340
         $ar = self::factory($this->row, $this->col);
1341 1341
         for ($i = 0; $i < $this->ndim; ++$i) {
1342 1342
             $ar->data[$i] = $this->data[$i] > $s ? 1 : 0;
@@ -1349,7 +1349,7 @@  discard block
 block discarded – undo
1349 1349
      * @param int|float|matrix $m
1350 1350
      * @return matrix
1351 1351
      */
1352
-    public function less(int|float|matrix $m): matrix {
1352
+    public function less(int | float | matrix $m): matrix {
1353 1353
         $ar = self::factory($this->row, $this->col);
1354 1354
         if ($m instanceof self) {
1355 1355
             if ($this->checkShape($this, $m)) {
@@ -1380,7 +1380,7 @@  discard block
 block discarded – undo
1380 1380
     }
1381 1381
 
1382 1382
     public function __toString() {
1383
-        return (string) $this->printMatrix();
1383
+        return (string)$this->printMatrix();
1384 1384
     }
1385 1385
 
1386 1386
     private function flattenArray(array $ar) {
Please login to merge, or discard this patch.