@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | * @email [email protected] |
| 23 | 23 | * @copyright (c) 2020-2021, Shubham Chaudhary |
| 24 | 24 | */ |
| 25 | -class matrix extends nd{ |
|
| 25 | +class matrix extends nd { |
|
| 26 | 26 | |
| 27 | 27 | public $row, $col; |
| 28 | 28 | /** |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | * @param \Np\matrix|\Np\vector $d |
| 343 | 343 | * @return matrix|vector |
| 344 | 344 | */ |
| 345 | - public function dot(matrix|vector $d): matrix|vector { |
|
| 345 | + public function dot(matrix | vector $d): matrix | vector { |
|
| 346 | 346 | if ($d instanceof self) { |
| 347 | 347 | return $this->dotMatrix($d); |
| 348 | 348 | } else { |
@@ -388,7 +388,7 @@ discard block |
||
| 388 | 388 | * @param int|float|matrix|vector $m |
| 389 | 389 | * @return matrix|vector |
| 390 | 390 | */ |
| 391 | - public function multiply(int|float|matrix|vector $m): matrix|vector { |
|
| 391 | + public function multiply(int | float | matrix | vector $m): matrix | vector { |
|
| 392 | 392 | if ($m instanceof self) { |
| 393 | 393 | return $this->multiplyMatrix($m); |
| 394 | 394 | } else if ($m instanceof vector) { |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | * @param int|float $scalar |
| 438 | 438 | * @return matrix |
| 439 | 439 | */ |
| 440 | - public function scale(int|float $scalar): matrix { |
|
| 440 | + public function scale(int | float $scalar): matrix { |
|
| 441 | 441 | if ($scalar == 0) { |
| 442 | 442 | return self::zeros($this->row, $this->col, $this->dtype); |
| 443 | 443 | } |
@@ -472,7 +472,7 @@ discard block |
||
| 472 | 472 | * @param int|float|matrix|vector $m |
| 473 | 473 | * @return matrix |
| 474 | 474 | */ |
| 475 | - public function sum(int|float|matrix|vector $m): matrix { |
|
| 475 | + public function sum(int | float | matrix | vector $m): matrix { |
|
| 476 | 476 | if ($m instanceof self) { |
| 477 | 477 | return $this->sumMatrix($m); |
| 478 | 478 | } elseif ($m instanceof vector) { |
@@ -482,7 +482,7 @@ discard block |
||
| 482 | 482 | } |
| 483 | 483 | } |
| 484 | 484 | |
| 485 | - protected function sumScalar(int|float $s): matrix { |
|
| 485 | + protected function sumScalar(int | float $s): matrix { |
|
| 486 | 486 | $ar = self::factory($this->row, $this->col, $this->dtype); |
| 487 | 487 | for ($i = 0; $i < $this->ndim; ++$i) { |
| 488 | 488 | $ar->data[$i] = $this->data[$i] + $s; |
@@ -517,7 +517,7 @@ discard block |
||
| 517 | 517 | * @param int|float|matrix|vector $d matrix|$scalar to subtract this matrix |
| 518 | 518 | * @return \Np\matrix |
| 519 | 519 | */ |
| 520 | - public function subtract(int|float|matrix|vector $d): matrix { |
|
| 520 | + public function subtract(int | float | matrix | vector $d): matrix { |
|
| 521 | 521 | if ($d instanceof self) { |
| 522 | 522 | return $this->subtractMatrix($d); |
| 523 | 523 | } elseif ($d instanceof vector) { |
@@ -527,7 +527,7 @@ discard block |
||
| 527 | 527 | } |
| 528 | 528 | } |
| 529 | 529 | |
| 530 | - protected function subtractScalar(int|float $s): matrix { |
|
| 530 | + protected function subtractScalar(int | float $s): matrix { |
|
| 531 | 531 | $ar = self::factory($this->row, $this->col, $this->dtype); |
| 532 | 532 | for ($i = 0; $i < $this->ndim; ++$i) { |
| 533 | 533 | $ar->data[$i] = $this->data[$i] - $s; |
@@ -589,7 +589,7 @@ discard block |
||
| 589 | 589 | * @param int|float|matrix $d |
| 590 | 590 | * @return matrix |
| 591 | 591 | */ |
| 592 | - public function divide(int|float|matrix|vector $d): matrix { |
|
| 592 | + public function divide(int | float | matrix | vector $d): matrix { |
|
| 593 | 593 | if ($d instanceof self) { |
| 594 | 594 | return $this->divideMatrix($d); |
| 595 | 595 | } elseif ($d instanceof vector) { |
@@ -625,7 +625,7 @@ discard block |
||
| 625 | 625 | } |
| 626 | 626 | } |
| 627 | 627 | |
| 628 | - protected function divideScalar(int|float $s): matrix { |
|
| 628 | + protected function divideScalar(int | float $s): matrix { |
|
| 629 | 629 | $ar = self::factory($this->row, $this->col, $this->dtype); |
| 630 | 630 | for ($i = 0; $i < $this->ndim; ++$i) { |
| 631 | 631 | $ar->data[$i] = $this->data[$i] / $s; |
@@ -640,7 +640,7 @@ discard block |
||
| 640 | 640 | * @param int|float|matrix $m |
| 641 | 641 | * @return matrix |
| 642 | 642 | */ |
| 643 | - public function pow(int|float|matrix|vector $d): matrix { |
|
| 643 | + public function pow(int | float | matrix | vector $d): matrix { |
|
| 644 | 644 | if ($d instanceof self) { |
| 645 | 645 | return $this->powMatrix($d); |
| 646 | 646 | } else if ($d instanceof vector) { |
@@ -672,7 +672,7 @@ discard block |
||
| 672 | 672 | } |
| 673 | 673 | } |
| 674 | 674 | |
| 675 | - protected function powScalar(int|float $s): matrix { |
|
| 675 | + protected function powScalar(int | float $s): matrix { |
|
| 676 | 676 | $ar = $this->copyMatrix(); |
| 677 | 677 | for ($i = 0; $i < $this->ndim; ++$i) { |
| 678 | 678 | $ar->data[$i] **= $s; |
@@ -685,7 +685,7 @@ discard block |
||
| 685 | 685 | * @param int|float|matrix|vector $d |
| 686 | 686 | * @return matrix |
| 687 | 687 | */ |
| 688 | - public function mod(int|float|matrix|vector $d): matrix { |
|
| 688 | + public function mod(int | float | matrix | vector $d): matrix { |
|
| 689 | 689 | if ($d instanceof self) { |
| 690 | 690 | $this->modMatrix($d); |
| 691 | 691 | } else if ($d instanceof vector) { |
@@ -719,7 +719,7 @@ discard block |
||
| 719 | 719 | } |
| 720 | 720 | } |
| 721 | 721 | |
| 722 | - protected function modScalar(int|float $s): matrix { |
|
| 722 | + protected function modScalar(int | float $s): matrix { |
|
| 723 | 723 | $ar = $this->copyMatrix(); |
| 724 | 724 | for ($i = 0; $i < $this->ndim; ++$i) { |
| 725 | 725 | $ar->data[$i] %= $s; |
@@ -944,7 +944,7 @@ discard block |
||
| 944 | 944 | * |
| 945 | 945 | * @return matrix|null |
| 946 | 946 | */ |
| 947 | - public function ref(): matrix|null { |
|
| 947 | + public function ref(): matrix | null { |
|
| 948 | 948 | return ref::factory($this); |
| 949 | 949 | } |
| 950 | 950 | |
@@ -953,7 +953,7 @@ discard block |
||
| 953 | 953 | * |
| 954 | 954 | * @return matrix|null |
| 955 | 955 | */ |
| 956 | - public function cholesky(): matrix|null { |
|
| 956 | + public function cholesky(): matrix | null { |
|
| 957 | 957 | return cholesky::factory($this); |
| 958 | 958 | } |
| 959 | 959 | |
@@ -1036,7 +1036,7 @@ discard block |
||
| 1036 | 1036 | * @param bool $dignoal |
| 1037 | 1037 | * @return void |
| 1038 | 1038 | */ |
| 1039 | - public function setData(int|float|array $data, bool $dignoal = false): void { |
|
| 1039 | + public function setData(int | float | array $data, bool $dignoal = false): void { |
|
| 1040 | 1040 | if ($dignoal == false) { |
| 1041 | 1041 | if (is_array($data) && is_array($data[0])) { |
| 1042 | 1042 | $f = $this->flattenArray($data); |
@@ -1060,7 +1060,7 @@ discard block |
||
| 1060 | 1060 | * @return object |
| 1061 | 1061 | */ |
| 1062 | 1062 | public function getShape(): object { |
| 1063 | - return (object) ['m' => $this->row, 'n' => $this->col]; |
|
| 1063 | + return (object)['m' => $this->row, 'n' => $this->col]; |
|
| 1064 | 1064 | } |
| 1065 | 1065 | |
| 1066 | 1066 | /** |
@@ -1192,7 +1192,7 @@ discard block |
||
| 1192 | 1192 | * Compute the (Moore-Penrose) pseudo inverse of the general matrix. |
| 1193 | 1193 | * @return matrix|null |
| 1194 | 1194 | */ |
| 1195 | - public function pseudoInverse(): matrix|null { |
|
| 1195 | + public function pseudoInverse(): matrix | null { |
|
| 1196 | 1196 | $k = min($this->row, $this->col); |
| 1197 | 1197 | $s = vector::factory($k, $this->dtype); |
| 1198 | 1198 | $u = self::factory($this->row, $this->row, $this->dtype); |
@@ -1376,7 +1376,7 @@ discard block |
||
| 1376 | 1376 | * @param vector|null $mean |
| 1377 | 1377 | * @return vector |
| 1378 | 1378 | */ |
| 1379 | - public function variance(vector|null $mean = null): vector { |
|
| 1379 | + public function variance(vector | null $mean = null): vector { |
|
| 1380 | 1380 | if (isset($mean)) { |
| 1381 | 1381 | if (!$mean instanceof vector) { |
| 1382 | 1382 | self::_invalidArgument('mean must be a vector!'); |
@@ -1418,7 +1418,7 @@ discard block |
||
| 1418 | 1418 | * @param vector|null $mean |
| 1419 | 1419 | * @return matrix |
| 1420 | 1420 | */ |
| 1421 | - public function covariance(vector|null $mean = null): matrix { |
|
| 1421 | + public function covariance(vector | null $mean = null): matrix { |
|
| 1422 | 1422 | if (isset($mean)) { |
| 1423 | 1423 | if ($mean->col !== $this->row) { |
| 1424 | 1424 | self::_err('Err:: given mean vector dimensionality mismatched!'); |
@@ -1505,7 +1505,7 @@ discard block |
||
| 1505 | 1505 | * @param int|float|matrix|vector $d |
| 1506 | 1506 | * @return matrix |
| 1507 | 1507 | */ |
| 1508 | - public function equal(int|float|matrix|vector $d): matrix { |
|
| 1508 | + public function equal(int | float | matrix | vector $d): matrix { |
|
| 1509 | 1509 | if ($d instanceof self) { |
| 1510 | 1510 | return $this->equalMatrix($d); |
| 1511 | 1511 | } elseif ($d instanceof vector) { |
@@ -1537,7 +1537,7 @@ discard block |
||
| 1537 | 1537 | } |
| 1538 | 1538 | } |
| 1539 | 1539 | |
| 1540 | - protected function equalScalar(int|float $s): matrix { |
|
| 1540 | + protected function equalScalar(int | float $s): matrix { |
|
| 1541 | 1541 | $ar = self::factory($this->row, $this->col, $this->dtype); |
| 1542 | 1542 | for ($i = 0; $i < $this->ndim; ++$i) { |
| 1543 | 1543 | $ar->data[$i] = $this->data[$i] == $s ? 1 : 0; |
@@ -1550,7 +1550,7 @@ discard block |
||
| 1550 | 1550 | * @param int|float|matrix|vector $d |
| 1551 | 1551 | * @return matrix |
| 1552 | 1552 | */ |
| 1553 | - public function greater(int|float|matrix|vector $d): matrix { |
|
| 1553 | + public function greater(int | float | matrix | vector $d): matrix { |
|
| 1554 | 1554 | if ($d instanceof self) { |
| 1555 | 1555 | return $this->greaterMatrix($d); |
| 1556 | 1556 | } elseif ($d instanceof vector) { |
@@ -1582,7 +1582,7 @@ discard block |
||
| 1582 | 1582 | } |
| 1583 | 1583 | } |
| 1584 | 1584 | |
| 1585 | - protected function greaterScalar(int|float $s): matrix { |
|
| 1585 | + protected function greaterScalar(int | float $s): matrix { |
|
| 1586 | 1586 | $ar = self::factory($this->row, $this->col, $this->dtype); |
| 1587 | 1587 | for ($i = 0; $i < $this->ndim; ++$i) { |
| 1588 | 1588 | $ar->data[$i] = $this->data[$i] > $s ? 1 : 0; |
@@ -1595,7 +1595,7 @@ discard block |
||
| 1595 | 1595 | * @param int|float|matrix $m |
| 1596 | 1596 | * @return matrix |
| 1597 | 1597 | */ |
| 1598 | - public function less(int|float|matrix $m): matrix { |
|
| 1598 | + public function less(int | float | matrix $m): matrix { |
|
| 1599 | 1599 | $ar = self::factory($this->row, $this->col, $this->dtype); |
| 1600 | 1600 | if ($m instanceof self) { |
| 1601 | 1601 | if ($this->checkShape($m)) { |
@@ -1646,7 +1646,7 @@ discard block |
||
| 1646 | 1646 | } |
| 1647 | 1647 | |
| 1648 | 1648 | public function __toString() { |
| 1649 | - return (string) $this->printMatrix(); |
|
| 1649 | + return (string)$this->printMatrix(); |
|
| 1650 | 1650 | } |
| 1651 | 1651 | |
| 1652 | 1652 | protected function flattenArray(array $ar) { |
@@ -1686,7 +1686,7 @@ discard block |
||
| 1686 | 1686 | if ($row < 1 || $col < 1) { |
| 1687 | 1687 | self::_invalidArgument('* To create Numphp/Matrix row & col must be greater than 0!, Op Failed! * '); |
| 1688 | 1688 | } |
| 1689 | - parent::__construct($row*$col, $dtype); |
|
| 1689 | + parent::__construct($row * $col, $dtype); |
|
| 1690 | 1690 | $this->row = $row; |
| 1691 | 1691 | $this->col = $col; |
| 1692 | 1692 | return $this; |