@@ -24,7 +24,7 @@ discard block |
||
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 | 29 | /** |
30 | 30 | * create empty 2d matrix for given data type |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | * @return matrix |
252 | 252 | */ |
253 | 253 | public function minimum(matrix $m): matrix { |
254 | - if ($this->checkShape($this,$m)) { |
|
254 | + if ($this->checkShape($this, $m)) { |
|
255 | 255 | $ar = self::factory($this->row, $this->col, $this->dtype); |
256 | 256 | for ($i = 0; $i < $this->ndim; ++$i) { |
257 | 257 | $ar->data[$i] = min($this->data[$i], $m->data[$i]); |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | * @param \Np\matrix|\Np\vector $d |
344 | 344 | * @return matrix|vector |
345 | 345 | */ |
346 | - public function dot(matrix|vector $d): matrix|vector { |
|
346 | + public function dot(matrix | vector $d): matrix | vector { |
|
347 | 347 | if ($d instanceof self) { |
348 | 348 | return $this->dotMatrix($d); |
349 | 349 | } else { |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | * @return \Np\matrix |
358 | 358 | */ |
359 | 359 | protected function dotMatrix(matrix $matrix): matrix { |
360 | - if ($this->checkDtype($this, $matrix) && $this->checkDimensions($this,$matrix)) { |
|
360 | + if ($this->checkDtype($this, $matrix) && $this->checkDimensions($this, $matrix)) { |
|
361 | 361 | $ar = self::factory($this->row, $this->col, $this->dtype); |
362 | 362 | blas::gemm($this, $matrix, $ar); |
363 | 363 | return $ar; |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | * @param int|float|matrix|vector $m |
386 | 386 | * @return matrix|vector |
387 | 387 | */ |
388 | - public function multiply(int|float|matrix|vector $m): matrix|vector { |
|
388 | + public function multiply(int | float | matrix | vector $m): matrix | vector { |
|
389 | 389 | if ($m instanceof self) { |
390 | 390 | return $this->multiplyMatrix($m); |
391 | 391 | } else if ($m instanceof vector) { |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | * @param int|float $scalar |
435 | 435 | * @return matrix |
436 | 436 | */ |
437 | - public function scale(int|float $scalar): matrix { |
|
437 | + public function scale(int | float $scalar): matrix { |
|
438 | 438 | if ($scalar == 0) { |
439 | 439 | return self::zeros($this->row, $this->col, $this->dtype); |
440 | 440 | } |
@@ -469,7 +469,7 @@ discard block |
||
469 | 469 | * @param int|float|matrix|vector $m |
470 | 470 | * @return matrix |
471 | 471 | */ |
472 | - public function sum(int|float|matrix|vector $m): matrix { |
|
472 | + public function sum(int | float | matrix | vector $m): matrix { |
|
473 | 473 | if ($m instanceof self) { |
474 | 474 | return $this->sumMatrix($m); |
475 | 475 | } elseif ($m instanceof vector) { |
@@ -479,7 +479,7 @@ discard block |
||
479 | 479 | } |
480 | 480 | } |
481 | 481 | |
482 | - protected function sumScalar(int|float $s): matrix { |
|
482 | + protected function sumScalar(int | float $s): matrix { |
|
483 | 483 | $ar = self::factory($this->row, $this->col, $this->dtype); |
484 | 484 | for ($i = 0; $i < $this->ndim; ++$i) { |
485 | 485 | $ar->data[$i] = $this->data[$i] + $s; |
@@ -514,7 +514,7 @@ discard block |
||
514 | 514 | * @param int|float|matrix|vector $d matrix|$scalar to subtract this matrix |
515 | 515 | * @return \Np\matrix |
516 | 516 | */ |
517 | - public function subtract(int|float|matrix|vector $d): matrix { |
|
517 | + public function subtract(int | float | matrix | vector $d): matrix { |
|
518 | 518 | if ($d instanceof self) { |
519 | 519 | return $this->subtractMatrix($d); |
520 | 520 | } elseif ($d instanceof vector) { |
@@ -524,7 +524,7 @@ discard block |
||
524 | 524 | } |
525 | 525 | } |
526 | 526 | |
527 | - protected function subtractScalar(int|float $s): matrix { |
|
527 | + protected function subtractScalar(int | float $s): matrix { |
|
528 | 528 | $ar = self::factory($this->row, $this->col, $this->dtype); |
529 | 529 | for ($i = 0; $i < $this->ndim; ++$i) { |
530 | 530 | $ar->data[$i] = $this->data[$i] - $s; |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | * @return matrix |
554 | 554 | */ |
555 | 555 | protected function subtractVector(vector $v): matrix { |
556 | - if ($this->checkDimensions($v, $this) && $this->checkDtype($this,$v)) { |
|
556 | + if ($this->checkDimensions($v, $this) && $this->checkDtype($this, $v)) { |
|
557 | 557 | $ar = self::factory($this->row, $this->col, $this->dtype); |
558 | 558 | for ($i = 0; $i < $this->row; ++$i) { |
559 | 559 | for ($j = 0; $j < $this->col; ++$j) { |
@@ -586,7 +586,7 @@ discard block |
||
586 | 586 | * @param int|float|matrix $d |
587 | 587 | * @return matrix |
588 | 588 | */ |
589 | - public function divide(int|float|matrix|vector $d): matrix { |
|
589 | + public function divide(int | float | matrix | vector $d): matrix { |
|
590 | 590 | if ($d instanceof self) { |
591 | 591 | return $this->divideMatrix($d); |
592 | 592 | } elseif ($d instanceof vector) { |
@@ -618,7 +618,7 @@ discard block |
||
618 | 618 | } |
619 | 619 | } |
620 | 620 | |
621 | - protected function divideScalar(int|float $s): matrix { |
|
621 | + protected function divideScalar(int | float $s): matrix { |
|
622 | 622 | $ar = self::factory($this->row, $this->col, $this->dtype); |
623 | 623 | for ($i = 0; $i < $this->ndim; ++$i) { |
624 | 624 | $ar->data[$i] = $this->data[$i] / $s; |
@@ -633,7 +633,7 @@ discard block |
||
633 | 633 | * @param int|float|matrix $m |
634 | 634 | * @return matrix |
635 | 635 | */ |
636 | - public function pow(int|float|matrix|vector $d): matrix { |
|
636 | + public function pow(int | float | matrix | vector $d): matrix { |
|
637 | 637 | if ($d instanceof self) { |
638 | 638 | return $this->powMatrix($d); |
639 | 639 | } else if ($d instanceof vector) { |
@@ -665,7 +665,7 @@ discard block |
||
665 | 665 | } |
666 | 666 | } |
667 | 667 | |
668 | - protected function powScalar(int|float $s): matrix { |
|
668 | + protected function powScalar(int | float $s): matrix { |
|
669 | 669 | $ar = $this->copyMatrix(); |
670 | 670 | for ($i = 0; $i < $this->ndim; ++$i) { |
671 | 671 | $ar->data[$i] **= $s; |
@@ -678,7 +678,7 @@ discard block |
||
678 | 678 | * @param int|float|matrix|vector $d |
679 | 679 | * @return matrix |
680 | 680 | */ |
681 | - public function mod(int|float|matrix|vector $d): matrix { |
|
681 | + public function mod(int | float | matrix | vector $d): matrix { |
|
682 | 682 | if ($d instanceof self) { |
683 | 683 | $this->modMatrix($d); |
684 | 684 | } else if ($d instanceof vector) { |
@@ -710,7 +710,7 @@ discard block |
||
710 | 710 | } |
711 | 711 | } |
712 | 712 | |
713 | - protected function modScalar(int|float $s): matrix { |
|
713 | + protected function modScalar(int | float $s): matrix { |
|
714 | 714 | $ar = $this->copyMatrix(); |
715 | 715 | for ($i = 0; $i < $this->ndim; ++$i) { |
716 | 716 | $ar->data[$i] %= $s; |
@@ -869,7 +869,7 @@ discard block |
||
869 | 869 | * @return matrix |
870 | 870 | */ |
871 | 871 | public function joinRight(matrix $m): matrix { |
872 | - if ($this->row != $m->row && !$this->checkDtype($this,$m)) { |
|
872 | + if ($this->row != $m->row && !$this->checkDtype($this, $m)) { |
|
873 | 873 | self::_err('Error::Invalid size! or DataType!'); |
874 | 874 | } |
875 | 875 | $col = $this->col + $m->col; |
@@ -935,7 +935,7 @@ discard block |
||
935 | 935 | * |
936 | 936 | * @return matrix|null |
937 | 937 | */ |
938 | - public function ref(): matrix|null { |
|
938 | + public function ref(): matrix | null { |
|
939 | 939 | return ref::factory($this); |
940 | 940 | } |
941 | 941 | |
@@ -944,7 +944,7 @@ discard block |
||
944 | 944 | * |
945 | 945 | * @return matrix|null |
946 | 946 | */ |
947 | - public function cholesky(): matrix|null { |
|
947 | + public function cholesky(): matrix | null { |
|
948 | 948 | return cholesky::factory($this); |
949 | 949 | } |
950 | 950 | |
@@ -1027,7 +1027,7 @@ discard block |
||
1027 | 1027 | * @param bool $dignoal |
1028 | 1028 | * @return void |
1029 | 1029 | */ |
1030 | - public function setData(int|float|array $data, bool $dignoal = false): void { |
|
1030 | + public function setData(int | float | array $data, bool $dignoal = false): void { |
|
1031 | 1031 | if ($dignoal == false) { |
1032 | 1032 | if (is_array($data) && is_array($data[0])) { |
1033 | 1033 | $f = $this->flattenArray($data); |
@@ -1051,7 +1051,7 @@ discard block |
||
1051 | 1051 | * @return object |
1052 | 1052 | */ |
1053 | 1053 | public function getShape(): object { |
1054 | - return (object) ['m' => $this->row, 'n' => $this->col]; |
|
1054 | + return (object)['m' => $this->row, 'n' => $this->col]; |
|
1055 | 1055 | } |
1056 | 1056 | |
1057 | 1057 | /** |
@@ -1184,7 +1184,7 @@ discard block |
||
1184 | 1184 | * Compute the (Moore-Penrose) pseudo inverse of the general matrix. |
1185 | 1185 | * @return matrix|null |
1186 | 1186 | */ |
1187 | - public function pseudoInverse(): matrix|null { |
|
1187 | + public function pseudoInverse(): matrix | null { |
|
1188 | 1188 | $k = min($this->row, $this->col); |
1189 | 1189 | $s = vector::factory($k, $this->dtype); |
1190 | 1190 | $u = self::factory($this->row, $this->row, $this->dtype); |
@@ -1368,7 +1368,7 @@ discard block |
||
1368 | 1368 | * @param vector|null $mean |
1369 | 1369 | * @return vector |
1370 | 1370 | */ |
1371 | - public function variance(vector|null $mean = null): vector { |
|
1371 | + public function variance(vector | null $mean = null): vector { |
|
1372 | 1372 | if (isset($mean)) { |
1373 | 1373 | if (!$mean instanceof vector) { |
1374 | 1374 | self::_invalidArgument('mean must be a vector!'); |
@@ -1410,7 +1410,7 @@ discard block |
||
1410 | 1410 | * @param vector|null $mean |
1411 | 1411 | * @return matrix |
1412 | 1412 | */ |
1413 | - public function covariance(vector|null $mean = null): matrix { |
|
1413 | + public function covariance(vector | null $mean = null): matrix { |
|
1414 | 1414 | if (isset($mean)) { |
1415 | 1415 | if ($mean->col !== $this->row) { |
1416 | 1416 | self::_err('Err:: given mean vector dimensionality mismatched!'); |
@@ -1497,7 +1497,7 @@ discard block |
||
1497 | 1497 | * @param int|float|matrix|vector $d |
1498 | 1498 | * @return matrix |
1499 | 1499 | */ |
1500 | - public function equal(int|float|matrix|vector $d): matrix { |
|
1500 | + public function equal(int | float | matrix | vector $d): matrix { |
|
1501 | 1501 | if ($d instanceof self) { |
1502 | 1502 | return $this->equalMatrix($d); |
1503 | 1503 | } elseif ($d instanceof vector) { |
@@ -1529,7 +1529,7 @@ discard block |
||
1529 | 1529 | } |
1530 | 1530 | } |
1531 | 1531 | |
1532 | - protected function equalScalar(int|float $s): matrix { |
|
1532 | + protected function equalScalar(int | float $s): matrix { |
|
1533 | 1533 | $ar = self::factory($this->row, $this->col, $this->dtype); |
1534 | 1534 | for ($i = 0; $i < $this->ndim; ++$i) { |
1535 | 1535 | $ar->data[$i] = $this->data[$i] == $s ? 1 : 0; |
@@ -1542,7 +1542,7 @@ discard block |
||
1542 | 1542 | * @param int|float|matrix|vector $d |
1543 | 1543 | * @return matrix |
1544 | 1544 | */ |
1545 | - public function greater(int|float|matrix|vector $d): matrix { |
|
1545 | + public function greater(int | float | matrix | vector $d): matrix { |
|
1546 | 1546 | if ($d instanceof self) { |
1547 | 1547 | return $this->greaterMatrix($d); |
1548 | 1548 | } elseif ($d instanceof vector) { |
@@ -1553,7 +1553,7 @@ discard block |
||
1553 | 1553 | } |
1554 | 1554 | |
1555 | 1555 | protected function greaterMatrix(matrix $m): matrix { |
1556 | - if ($this->checkShape($this, $m) && $this->checkDtype($this,$m)) { |
|
1556 | + if ($this->checkShape($this, $m) && $this->checkDtype($this, $m)) { |
|
1557 | 1557 | $ar = self::factory($this->row, $this->col, $this->dtype); |
1558 | 1558 | for ($i = 0; $i < $this->ndim; ++$i) { |
1559 | 1559 | $ar->data[$i] = $this->data[$i] > $m->data[$i] ? 1 : 0; |
@@ -1563,7 +1563,7 @@ discard block |
||
1563 | 1563 | } |
1564 | 1564 | |
1565 | 1565 | protected function greaterVector(vector $v): matrix { |
1566 | - if ($this->checkDimensions($v, $this) && $this->checkDtype($this,$v)) { |
|
1566 | + if ($this->checkDimensions($v, $this) && $this->checkDtype($this, $v)) { |
|
1567 | 1567 | $ar = self::factory($this->row, $this->col, $this->dtype); |
1568 | 1568 | for ($i = 0; $i < $this->row; ++$i) { |
1569 | 1569 | for ($j = 0; $j < $this->col; ++$j) { |
@@ -1574,7 +1574,7 @@ discard block |
||
1574 | 1574 | } |
1575 | 1575 | } |
1576 | 1576 | |
1577 | - protected function greaterScalar(int|float $s): matrix { |
|
1577 | + protected function greaterScalar(int | float $s): matrix { |
|
1578 | 1578 | $ar = self::factory($this->row, $this->col, $this->dtype); |
1579 | 1579 | for ($i = 0; $i < $this->ndim; ++$i) { |
1580 | 1580 | $ar->data[$i] = $this->data[$i] > $s ? 1 : 0; |
@@ -1587,10 +1587,10 @@ discard block |
||
1587 | 1587 | * @param int|float|matrix $m |
1588 | 1588 | * @return matrix |
1589 | 1589 | */ |
1590 | - public function less(int|float|matrix $m): matrix { |
|
1590 | + public function less(int | float | matrix $m): matrix { |
|
1591 | 1591 | $ar = self::factory($this->row, $this->col, $this->dtype); |
1592 | 1592 | if ($m instanceof self) { |
1593 | - if ($this->checkShape($this,$m)) { |
|
1593 | + if ($this->checkShape($this, $m)) { |
|
1594 | 1594 | for ($i = 0; $i < $this->ndim; ++$i) { |
1595 | 1595 | $ar->data[$i] = $this->data[$i] < $m->data[$i] ? 1 : 0; |
1596 | 1596 | } |
@@ -1638,7 +1638,7 @@ discard block |
||
1638 | 1638 | } |
1639 | 1639 | |
1640 | 1640 | public function __toString() { |
1641 | - return (string) $this->printMatrix(); |
|
1641 | + return (string)$this->printMatrix(); |
|
1642 | 1642 | } |
1643 | 1643 | |
1644 | 1644 | protected function flattenArray(array $ar) { |