@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare (strict_types=1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Np\decompositions; |
| 6 | 6 | |
@@ -27,7 +27,7 @@ discard block |
||
| 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->copyMatrix(); |
| 33 | 33 | $lp = lapack::potrf($ar); |
@@ -398,7 +398,7 @@ |
||
| 398 | 398 | * @param \Np\vector|\Np\matrix $v |
| 399 | 399 | * @return \FFI\CData |
| 400 | 400 | */ |
| 401 | - public static function scale(float $alpha, \Np\vector|\Np\matrix $v) { |
|
| 401 | + public static function scale(float $alpha, \Np\vector | \Np\matrix $v) { |
|
| 402 | 402 | self::init(); |
| 403 | 403 | if ($v->dtype == \Np\vector::DOUBLE) { |
| 404 | 404 | return self::$ffi_blas->cblas_dscal($v->ndim, $alpha, $v->data, 1); |
@@ -30,21 +30,21 @@ |
||
| 30 | 30 | public $data, $ndim, $dtype; |
| 31 | 31 | public static $_time = null, $_mem = null; |
| 32 | 32 | |
| 33 | - public function checkDimensions(\Np\matrix|\Np\vector $Obj1, \Np\matrix $Obj2) { |
|
| 34 | - if($Obj1->col == $Obj2->row){ |
|
| 33 | + public function checkDimensions(\Np\matrix | \Np\vector $Obj1, \Np\matrix $Obj2) { |
|
| 34 | + if ($Obj1->col == $Obj2->row) { |
|
| 35 | 35 | return true; |
| 36 | 36 | } |
| 37 | 37 | self::_dimensionaMisMatchErr('Mismatch Dimensions of given Objects! Obj-A col & Obj-B row amount need to be the same!'); |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - public function checkDtype(\Np\matrix|\Np\vector $Obj1, \Np\matrix|\Np\vector $Obj2){ |
|
| 41 | - if($Obj1->dtype == $Obj2->dtype) { |
|
| 40 | + public function checkDtype(\Np\matrix | \Np\vector $Obj1, \Np\matrix | \Np\vector $Obj2) { |
|
| 41 | + if ($Obj1->dtype == $Obj2->dtype) { |
|
| 42 | 42 | return true; |
| 43 | 43 | } |
| 44 | 44 | self::_dtypeErr('mismatch data type of given Np\Objects!'); |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - public function checkShape(\Np\matrix|\Np\vector $Obj1, \Np\matrix|\Np\vector $Obj2) { |
|
| 47 | + public function checkShape(\Np\matrix | \Np\vector $Obj1, \Np\matrix | \Np\vector $Obj2) { |
|
| 48 | 48 | if ($Obj1 instanceof \Np\vector && $Obj2 instanceof \Np\vector) { |
| 49 | 49 | if ($Obj1->col == $Obj2->col) { |
| 50 | 50 | return true; |
@@ -29,8 +29,7 @@ discard block |
||
| 29 | 29 | $r->data[$i] = $sigma; |
| 30 | 30 | } |
| 31 | 31 | return $r; |
| 32 | - } |
|
| 33 | - else { |
|
| 32 | + } else { |
|
| 34 | 33 | throw new dtypeException('Err::given vectors has diffrent data type!'); |
| 35 | 34 | } |
| 36 | 35 | } |
@@ -69,8 +68,7 @@ discard block |
||
| 69 | 68 | } |
| 70 | 69 | } |
| 71 | 70 | return $rc; |
| 72 | - } |
|
| 73 | - else { |
|
| 71 | + } else { |
|
| 74 | 72 | throw new \Exception('Err::given matrixes has different data type!'); |
| 75 | 73 | } |
| 76 | 74 | } |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | * @param int $dtype |
| 134 | 134 | * @return vector |
| 135 | 135 | */ |
| 136 | - public static function full(int $col, int|float $val, int $dtype = self::FLOAT): vector { |
|
| 136 | + public static function full(int $col, int | float $val, int $dtype = self::FLOAT): vector { |
|
| 137 | 137 | $ar = self::factory($col, $dtype); |
| 138 | 138 | for ($i = 0; $i < $col; ++$i) { |
| 139 | 139 | $ar->data[$i] = $val; |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | * @param int $dtype |
| 151 | 151 | * @return vector |
| 152 | 152 | */ |
| 153 | - public static function range(int|float $start, int|float $end, int|float $interval = 1, int $dtype = self::FLOAT): vector { |
|
| 153 | + public static function range(int | float $start, int | float $end, int | float $interval = 1, int $dtype = self::FLOAT): vector { |
|
| 154 | 154 | return self::ar(range($start, $end, $interval), $dtype); |
| 155 | 155 | } |
| 156 | 156 | |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | $a[] = end($a) + $interval; |
| 226 | 226 | } |
| 227 | 227 | $a[] = $max; |
| 228 | - return self::ar($a,$dtype); |
|
| 228 | + return self::ar($a, $dtype); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -243,10 +243,10 @@ discard block |
||
| 243 | 243 | * @return vector |
| 244 | 244 | */ |
| 245 | 245 | public function maximum(\Np\vector $vector): vector { |
| 246 | - if ($this->checkShape($this,$vector) && $this->checkDtype($this,$vector)) { |
|
| 246 | + if ($this->checkShape($this, $vector) && $this->checkDtype($this, $vector)) { |
|
| 247 | 247 | $v = new self($this->ndim, $this->dtype); |
| 248 | - for($i = 0; $i<$v->ndim; ++$i) { |
|
| 249 | - $v->data[$i] = max($this->data[$i],$vector->data[$i]); |
|
| 248 | + for ($i = 0; $i < $v->ndim; ++$i) { |
|
| 249 | + $v->data[$i] = max($this->data[$i], $vector->data[$i]); |
|
| 250 | 250 | } |
| 251 | 251 | return $v; |
| 252 | 252 | } |
@@ -261,8 +261,8 @@ discard block |
||
| 261 | 261 | public function minium(\Np\vector $vector): vector { |
| 262 | 262 | if ($this->checkShape($this, $vector) && $this->checkDtype($this, $vector)) { |
| 263 | 263 | $v = new self($this->ndim, $this->dtype); |
| 264 | - for($i = 0; $i<$v->ndim; ++$i) { |
|
| 265 | - $v->data[$i] = min($this->data[$i],$vector->data[$i]); |
|
| 264 | + for ($i = 0; $i < $v->ndim; ++$i) { |
|
| 265 | + $v->data[$i] = min($this->data[$i], $vector->data[$i]); |
|
| 266 | 266 | } |
| 267 | 267 | return $v; |
| 268 | 268 | } |
@@ -337,7 +337,7 @@ discard block |
||
| 337 | 337 | * @param int|float|matrix|vector $d |
| 338 | 338 | * @return matrix|vector |
| 339 | 339 | */ |
| 340 | - public function divide(int|float|matrix|vector $d): matrix|vector { |
|
| 340 | + public function divide(int | float | matrix | vector $d): matrix | vector { |
|
| 341 | 341 | if ($d instanceof matrix) { |
| 342 | 342 | return $this->divideMatrix($d); |
| 343 | 343 | } elseif ($d instanceof self) { |
@@ -384,7 +384,7 @@ discard block |
||
| 384 | 384 | * @param int|float $s |
| 385 | 385 | * @return vector |
| 386 | 386 | */ |
| 387 | - protected function divideScalar(int|float $s): vector { |
|
| 387 | + protected function divideScalar(int | float $s): vector { |
|
| 388 | 388 | $vr = self::factory($this->col, $this->dtype); |
| 389 | 389 | for ($i = 0; $i < $this->col; ++$i) { |
| 390 | 390 | $vr->data[$i] = $this->data[$i] / $s; |
@@ -397,7 +397,7 @@ discard block |
||
| 397 | 397 | * @param int|float|matrix|vector $d |
| 398 | 398 | * @return matrix|vector |
| 399 | 399 | */ |
| 400 | - public function multiply(int|float|matrix|vector $d): matrix|vector { |
|
| 400 | + public function multiply(int | float | matrix | vector $d): matrix | vector { |
|
| 401 | 401 | if ($d instanceof matrix) { |
| 402 | 402 | return $this->multiplyMatrix($d); |
| 403 | 403 | } elseif ($d instanceof self) { |
@@ -430,7 +430,7 @@ discard block |
||
| 430 | 430 | * @return vector |
| 431 | 431 | */ |
| 432 | 432 | protected function multiplyVector(\Np\vector $vector): vector { |
| 433 | - if ($this->checkShape($this,$vector) && $this->checkDtype($this,$vector)) { |
|
| 433 | + if ($this->checkShape($this, $vector) && $this->checkDtype($this, $vector)) { |
|
| 434 | 434 | $vr = self::factory($this->col, $this->dtype); |
| 435 | 435 | for ($i = 0; $i < $this->col; ++$i) { |
| 436 | 436 | $vr->data[$i] = $this->data[$i] * $vector->data[$i]; |
@@ -444,7 +444,7 @@ discard block |
||
| 444 | 444 | * @param int|float $s |
| 445 | 445 | * @return vector |
| 446 | 446 | */ |
| 447 | - protected function multiplyScalar(int|float $s): vector { |
|
| 447 | + protected function multiplyScalar(int | float $s): vector { |
|
| 448 | 448 | $vr = $this->copyVector(); |
| 449 | 449 | blas::scale($s, $vr); |
| 450 | 450 | return $vr; |
@@ -455,7 +455,7 @@ discard block |
||
| 455 | 455 | * @param int|float|matrix|vector $d |
| 456 | 456 | * @return matrix|vector |
| 457 | 457 | */ |
| 458 | - public function add(int|float|matrix|vector $d): matrix|vector { |
|
| 458 | + public function add(int | float | matrix | vector $d): matrix | vector { |
|
| 459 | 459 | if ($d instanceof matrix) { |
| 460 | 460 | return $this->addMatrix($d); |
| 461 | 461 | } elseif ($d instanceof self) { |
@@ -502,7 +502,7 @@ discard block |
||
| 502 | 502 | * @param int|float $s |
| 503 | 503 | * @return vector |
| 504 | 504 | */ |
| 505 | - protected function addScalar(int|float $s): vector { |
|
| 505 | + protected function addScalar(int | float $s): vector { |
|
| 506 | 506 | $vr = $this->copyVector(); |
| 507 | 507 | for ($i = 0; $i < $this->col; ++$i) { |
| 508 | 508 | $vr->data[$i] += $s; |
@@ -516,7 +516,7 @@ discard block |
||
| 516 | 516 | * @return vector |
| 517 | 517 | */ |
| 518 | 518 | public function powVector(\Np\vector $vector): vector { |
| 519 | - if ($this->checkShape($this, $vector) && $this->checkDtype($this, $vector)) { |
|
| 519 | + if ($this->checkShape($this, $vector) && $this->checkDtype($this, $vector)) { |
|
| 520 | 520 | $vr = self::factory($this->col, $this->dtype); |
| 521 | 521 | for ($i = 0; $i < $this->col; ++$i) { |
| 522 | 522 | $vr->data[$i] = $this->data[$i] ** $vector->data[$i]; |
@@ -545,7 +545,7 @@ discard block |
||
| 545 | 545 | * @param int|float|matrix|vector $d |
| 546 | 546 | * @return matrix|vector |
| 547 | 547 | */ |
| 548 | - public function subtract(int|float|matrix|vector $d): matrix|vector { |
|
| 548 | + public function subtract(int | float | matrix | vector $d): matrix | vector { |
|
| 549 | 549 | if ($d instanceof matrix) { |
| 550 | 550 | return $this->subtractMatrix($d); |
| 551 | 551 | } elseif ($d instanceof self) { |
@@ -578,7 +578,7 @@ discard block |
||
| 578 | 578 | * @return vector |
| 579 | 579 | */ |
| 580 | 580 | protected function subtractVector(\Np\vector $vector): vector { |
| 581 | - if ($this->checkShape($this,$vector) && $this->checkDtype($this,$vector)) { |
|
| 581 | + if ($this->checkShape($this, $vector) && $this->checkDtype($this, $vector)) { |
|
| 582 | 582 | $vr = self::factory($this->col, $this->dtype); |
| 583 | 583 | for ($i = 0; $i < $this->col; ++$i) { |
| 584 | 584 | $vr->data[$i] = $this->data[$i] - $vector->data[$i]; |
@@ -592,7 +592,7 @@ discard block |
||
| 592 | 592 | * @param \Np\vector $scalar |
| 593 | 593 | * @return \Np\vector |
| 594 | 594 | */ |
| 595 | - protected function substractScalar(int|float $scalar): vector { |
|
| 595 | + protected function substractScalar(int | float $scalar): vector { |
|
| 596 | 596 | $vr = self::factory($this->col, $this->dtype); |
| 597 | 597 | for ($i = 0; $i < $this->col; ++$i) { |
| 598 | 598 | $vr->data[$i] = $this->data[$i] - $scalar; |
@@ -642,7 +642,7 @@ discard block |
||
| 642 | 642 | * set data to vector |
| 643 | 643 | * @param int|float|array $data |
| 644 | 644 | */ |
| 645 | - public function setData(int|float|array $data) { |
|
| 645 | + public function setData(int | float | array $data) { |
|
| 646 | 646 | if (is_array($data) && !is_array($data[0])) { |
| 647 | 647 | for ($i = 0; $i < $this->col; ++$i) { |
| 648 | 648 | $this->data[$i] = $data[$i]; |
@@ -655,7 +655,7 @@ discard block |
||
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | public function asMatrix(): matrix { |
| 658 | - $size = (int) sqrt($this->col); |
|
| 658 | + $size = (int)sqrt($this->col); |
|
| 659 | 659 | $ar = matrix::factory($size, $size, $this->dtype); |
| 660 | 660 | for ($i = 0; $i < $ar->ndim; ++$i) { |
| 661 | 661 | $ar->data[$i] = $this->data[$i]; |
@@ -691,7 +691,7 @@ discard block |
||
| 691 | 691 | } |
| 692 | 692 | |
| 693 | 693 | public function __toString() { |
| 694 | - return (string) $this->printVector(); |
|
| 694 | + return (string)$this->printVector(); |
|
| 695 | 695 | } |
| 696 | 696 | |
| 697 | 697 | protected function __construct(public int $col, int $dtype = self::FLOAT) { |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | * @param \Np\matrix $m |
| 25 | 25 | * @return matrix|null |
| 26 | 26 | */ |
| 27 | - public static function factory(\Np\matrix $m): matrix|null { |
|
| 27 | + public static function factory(\Np\matrix $m): matrix | null { |
|
| 28 | 28 | $ipiv = vector::factory(min($m->row, $m->col), vector::INT); |
| 29 | 29 | $ar = $m->copyMatrix(); |
| 30 | 30 | $lp = lapack::getrf($ar, $ipiv); |
@@ -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,7 +1587,7 @@ 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 | 1593 | if ($this->checkShape($m)) { |
@@ -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) { |