@@ -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->copy(); |
33 | 33 | $lp = lapack::potrf($ar); |
@@ -24,8 +24,8 @@ |
||
24 | 24 | * @copyright (c) 2020-2021, Shubham Chaudhary |
25 | 25 | * |
26 | 26 | */ |
27 | - class vector extends nd { |
|
28 | - use ops, linAlg; |
|
27 | + class vector extends nd { |
|
28 | + use ops, linAlg; |
|
29 | 29 | |
30 | 30 | /** |
31 | 31 | * Factory method to build a new vector. |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | * @param int $dtype |
135 | 135 | * @return vector |
136 | 136 | */ |
137 | - public static function full(int $col, int|float $val, int $dtype = self::FLOAT): vector { |
|
137 | + public static function full(int $col, int | float $val, int $dtype = self::FLOAT): vector { |
|
138 | 138 | $ar = self::factory($col, $dtype); |
139 | 139 | for ($i = 0; $i < $col; ++$i) { |
140 | 140 | $ar->data[$i] = $val; |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | * @param int $dtype |
152 | 152 | * @return vector |
153 | 153 | */ |
154 | - public static function range(int|float $start, int|float $end, int|float $interval = 1, int $dtype = self::FLOAT): vector { |
|
154 | + public static function range(int | float $start, int | float $end, int | float $interval = 1, int $dtype = self::FLOAT): vector { |
|
155 | 155 | return self::ar(range($start, $end, $interval), $dtype); |
156 | 156 | } |
157 | 157 | |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | * @param int|float|matrix|vector $d |
286 | 286 | * @return matrix|vector |
287 | 287 | */ |
288 | - public function divide(int|float|matrix|vector $d): matrix|vector { |
|
288 | + public function divide(int | float | matrix | vector $d): matrix | vector { |
|
289 | 289 | if ($d instanceof matrix) { |
290 | 290 | return $this->divideMatrix($d); |
291 | 291 | } elseif ($d instanceof self) { |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | * @param int|float $s |
333 | 333 | * @return vector |
334 | 334 | */ |
335 | - protected function divideScalar(int|float $s): vector { |
|
335 | + protected function divideScalar(int | float $s): vector { |
|
336 | 336 | $vr = self::factory($this->col, $this->dtype); |
337 | 337 | for ($i = 0; $i < $this->col; ++$i) { |
338 | 338 | $vr->data[$i] = $this->data[$i] / $s; |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | * @param int|float|matrix|vector $d |
346 | 346 | * @return matrix|vector |
347 | 347 | */ |
348 | - public function multiply(int|float|matrix|vector $d): matrix|vector { |
|
348 | + public function multiply(int | float | matrix | vector $d): matrix | vector { |
|
349 | 349 | if ($d instanceof matrix) { |
350 | 350 | return $this->multiplyMatrix($d); |
351 | 351 | } elseif ($d instanceof self) { |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | * @param int|float $s |
393 | 393 | * @return vector |
394 | 394 | */ |
395 | - protected function multiplyScalar(int|float $s): vector { |
|
395 | + protected function multiplyScalar(int | float $s): vector { |
|
396 | 396 | $vr = $this->copy(); |
397 | 397 | blas::scale($s, $vr); |
398 | 398 | return $vr; |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | * @param int|float|matrix|vector $d |
404 | 404 | * @return matrix|vector |
405 | 405 | */ |
406 | - public function add(int|float|matrix|vector $d): matrix|vector { |
|
406 | + public function add(int | float | matrix | vector $d): matrix | vector { |
|
407 | 407 | if ($d instanceof matrix) { |
408 | 408 | return $this->addMatrix($d); |
409 | 409 | } elseif ($d instanceof self) { |
@@ -450,7 +450,7 @@ discard block |
||
450 | 450 | * @param int|float $s |
451 | 451 | * @return vector |
452 | 452 | */ |
453 | - protected function addScalar(int|float $s): vector { |
|
453 | + protected function addScalar(int | float $s): vector { |
|
454 | 454 | $vr = $this->copy(); |
455 | 455 | for ($i = 0; $i < $this->col; ++$i) { |
456 | 456 | $vr->data[$i] += $s; |
@@ -463,7 +463,7 @@ discard block |
||
463 | 463 | * @param int|float|\Np\matrix|\Np\vector $d |
464 | 464 | * @return matrix|vector |
465 | 465 | */ |
466 | - public function pow(int|float|\Np\matrix|\Np\vector $d): matrix|vector { |
|
466 | + public function pow(int | float | \Np\matrix | \Np\vector $d): matrix | vector { |
|
467 | 467 | if ($d instanceof matrix) { |
468 | 468 | return $this->powMatrix($d); |
469 | 469 | } elseif ($d instanceof vector) { |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | * @param int|float $s |
511 | 511 | * @return vector |
512 | 512 | */ |
513 | - protected function powScalar(int|float $s): vector { |
|
513 | + protected function powScalar(int | float $s): vector { |
|
514 | 514 | $v = $this->copy(); |
515 | 515 | for ($i = 0; $i < $this->col; ++$i) { |
516 | 516 | $v->data[$i] = $v->data[$i] ** $s; |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | * @param int|float|\Np\matrix|\Np\vector $d |
524 | 524 | * @return matrix|vector |
525 | 525 | */ |
526 | - public function mod(int|float|\Np\matrix|\Np\vector $d): matrix|vector { |
|
526 | + public function mod(int | float | \Np\matrix | \Np\vector $d): matrix | vector { |
|
527 | 527 | if ($d instanceof matrix) { |
528 | 528 | return $this->powMatrix($d); |
529 | 529 | } elseif ($d instanceof vector) { |
@@ -569,7 +569,7 @@ discard block |
||
569 | 569 | * |
570 | 570 | * @param int|float $s |
571 | 571 | */ |
572 | - protected function modScalar(int|float $s) { |
|
572 | + protected function modScalar(int | float $s) { |
|
573 | 573 | $v = $this->copy(); |
574 | 574 | for ($i = 0; $i < $this->col; ++$i) { |
575 | 575 | $v->data[$i] = $v->data[$i] % $s; |
@@ -581,7 +581,7 @@ discard block |
||
581 | 581 | * @param int|float|matrix|vector $d |
582 | 582 | * @return matrix|vector |
583 | 583 | */ |
584 | - public function subtract(int|float|matrix|vector $d): matrix|vector { |
|
584 | + public function subtract(int | float | matrix | vector $d): matrix | vector { |
|
585 | 585 | if ($d instanceof matrix) { |
586 | 586 | return $this->subtractMatrix($d); |
587 | 587 | } elseif ($d instanceof self) { |
@@ -628,7 +628,7 @@ discard block |
||
628 | 628 | * @param \Np\vector $scalar |
629 | 629 | * @return \Np\vector |
630 | 630 | */ |
631 | - protected function substractScalar(int|float $scalar): vector { |
|
631 | + protected function substractScalar(int | float $scalar): vector { |
|
632 | 632 | $vr = self::factory($this->col, $this->dtype); |
633 | 633 | for ($i = 0; $i < $this->col; ++$i) { |
634 | 634 | $vr->data[$i] = $this->data[$i] - $scalar; |
@@ -701,15 +701,15 @@ discard block |
||
701 | 701 | * |
702 | 702 | * @return int|float |
703 | 703 | */ |
704 | - public function mean():int|float { |
|
705 | - return $this->sum()/ $this->col; |
|
704 | + public function mean():int | float { |
|
705 | + return $this->sum() / $this->col; |
|
706 | 706 | } |
707 | 707 | |
708 | 708 | /** |
709 | 709 | * |
710 | 710 | * @return int|float |
711 | 711 | */ |
712 | - public function median():int|float { |
|
712 | + public function median():int | float { |
|
713 | 713 | $mid = intdiv($this->col, 2); |
714 | 714 | |
715 | 715 | $a = $this->copy()->sort(); |
@@ -756,7 +756,7 @@ discard block |
||
756 | 756 | * set data to vector |
757 | 757 | * @param int|float|array $data |
758 | 758 | */ |
759 | - public function setData(int|float|array $data) { |
|
759 | + public function setData(int | float | array $data) { |
|
760 | 760 | if (is_array($data) && !is_array($data[0])) { |
761 | 761 | for ($i = 0; $i < $this->col; ++$i) { |
762 | 762 | $this->data[$i] = $data[$i]; |
@@ -796,7 +796,7 @@ discard block |
||
796 | 796 | } |
797 | 797 | |
798 | 798 | public function __toString() { |
799 | - return (string) $this->printVector(); |
|
799 | + return (string)$this->printVector(); |
|
800 | 800 | } |
801 | 801 | |
802 | 802 | protected function __construct(public int $col, int $dtype = self::FLOAT) { |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * @param matrix|vector $d |
20 | 20 | * @return matrix|vector |
21 | 21 | */ |
22 | - public function max(matrix|vector $d): matrix|vector { |
|
22 | + public function max(matrix | vector $d): matrix | vector { |
|
23 | 23 | if ($this instanceof matrix && $d instanceof matrix && $this->checkShape($this, $d) && $this->checkDtype($this, $d)) { |
24 | 24 | $r = self::factory($this->row, $this->col, $this->dtype); |
25 | 25 | } elseif ($this instanceof vector && $d instanceof vector && $this->checkShape($this, $d) && $this->checkDtype($this, $d)) { |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * @param matrix|vector $d |
37 | 37 | * @return matrix|vector |
38 | 38 | */ |
39 | - public function min(matrix|vector $d): matrix|vector { |
|
39 | + public function min(matrix | vector $d): matrix | vector { |
|
40 | 40 | if ($this instanceof matrix && $d instanceof matrix && $this->checkShape($this, $d) && $this->checkDtype($this, $d)) { |
41 | 41 | $r = self::factory($this->row, $this->col, $this->dtype); |
42 | 42 | } elseif ($this instanceof vector && $d instanceof vector && $this->checkShape($this, $d) && $this->checkDtype($this, $d)) { |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * @param callable $func |
54 | 54 | * @return matrix|vector |
55 | 55 | */ |
56 | - public function map(callable $func): matrix|vector { |
|
56 | + public function map(callable $func): matrix | vector { |
|
57 | 57 | if ($this instanceof matrix) { |
58 | 58 | $r = self::factory($this->row, $this->col, $this->dtype); |
59 | 59 | } else { |
@@ -65,23 +65,23 @@ discard block |
||
65 | 65 | return $r; |
66 | 66 | } |
67 | 67 | |
68 | - public function abs(): matrix|vector { |
|
68 | + public function abs(): matrix | vector { |
|
69 | 69 | return $this->map('abs'); |
70 | 70 | } |
71 | 71 | |
72 | - public function sqrt(): matrix|vector { |
|
72 | + public function sqrt(): matrix | vector { |
|
73 | 73 | return $this->map('sqrt'); |
74 | 74 | } |
75 | 75 | |
76 | - public function exp(): matrix|vector { |
|
76 | + public function exp(): matrix | vector { |
|
77 | 77 | return $this->map('exp'); |
78 | 78 | } |
79 | 79 | |
80 | - public function exp1(): matrix|vector { |
|
80 | + public function exp1(): matrix | vector { |
|
81 | 81 | return $this->map('exp1'); |
82 | 82 | } |
83 | 83 | |
84 | - public function log(float $b = M_E): matrix|vector { |
|
84 | + public function log(float $b = M_E): matrix | vector { |
|
85 | 85 | $ar = $this->copy(); |
86 | 86 | for ($i = 0; $i < $ar->ndim; ++$i) { |
87 | 87 | log($ar->data[$i], $b); |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * make a copy of matrix|vector; |
138 | 138 | * @return matrix|vector |
139 | 139 | */ |
140 | - public function copy(): matrix|vector { |
|
140 | + public function copy(): matrix | vector { |
|
141 | 141 | return clone $this; |
142 | 142 | } |
143 | 143 | |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @param float $max |
150 | 150 | * @return matrix |
151 | 151 | */ |
152 | - public function clip(float $min, float $max): matrix|vector { |
|
152 | + public function clip(float $min, float $max): matrix | vector { |
|
153 | 153 | if ($this instanceof matrix) { |
154 | 154 | $ar = self::factory($this->row, $this->col, $this->dtype); |
155 | 155 | } else { |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | * @param float $max |
197 | 197 | * @return matrix |
198 | 198 | */ |
199 | - public function clipUpper(float $max): matrix|vector { |
|
199 | + public function clipUpper(float $max): matrix | vector { |
|
200 | 200 | if ($this instanceof matrix) { |
201 | 201 | $ar = self::factory($this->row, $this->col, $this->dtype); |
202 | 202 | } else { |
@@ -26,8 +26,10 @@ |
||
26 | 26 | $lead = 0; |
27 | 27 | $ar = $m->copy(); |
28 | 28 | for ($r = 0; $r < $ar->row; ++$r) { |
29 | - if ($lead >= $ar->col) |
|
30 | - break; { |
|
29 | + if ($lead >= $ar->col) { |
|
30 | + break; |
|
31 | + } |
|
32 | + { |
|
31 | 33 | $i = $r; |
32 | 34 | while ($ar->data[$i * $ar->col + $lead] == 0) { |
33 | 35 | $i++; |
@@ -24,9 +24,9 @@ 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 | - 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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
973 | 973 | * @param bool $dignoal |
974 | 974 | * @return void |
975 | 975 | */ |
976 | - public function setData(int|float|array $data, bool $dignoal = false): void { |
|
976 | + public function setData(int | float | array $data, bool $dignoal = false): void { |
|
977 | 977 | if ($dignoal == false) { |
978 | 978 | if (is_array($data) && is_array($data[0])) { |
979 | 979 | $f = $this->flattenArray($data); |
@@ -1005,7 +1005,7 @@ discard block |
||
1005 | 1005 | * @return object |
1006 | 1006 | */ |
1007 | 1007 | public function getShape(): object { |
1008 | - return (object) ['m' => $this->row, 'n' => $this->col]; |
|
1008 | + return (object)['m' => $this->row, 'n' => $this->col]; |
|
1009 | 1009 | } |
1010 | 1010 | |
1011 | 1011 | /** |
@@ -1187,7 +1187,7 @@ discard block |
||
1187 | 1187 | * @param vector|null $mean |
1188 | 1188 | * @return vector |
1189 | 1189 | */ |
1190 | - public function variance(vector|null $mean = null): vector { |
|
1190 | + public function variance(vector | null $mean = null): vector { |
|
1191 | 1191 | if (isset($mean)) { |
1192 | 1192 | if (!$mean instanceof vector) { |
1193 | 1193 | self::_invalidArgument('mean must be a vector!'); |
@@ -1229,7 +1229,7 @@ discard block |
||
1229 | 1229 | * @param vector|null $mean |
1230 | 1230 | * @return matrix |
1231 | 1231 | */ |
1232 | - public function covariance(vector|null $mean = null): matrix { |
|
1232 | + public function covariance(vector | null $mean = null): matrix { |
|
1233 | 1233 | if (isset($mean)) { |
1234 | 1234 | if ($mean->col !== $this->row) { |
1235 | 1235 | self::_err('Err:: given mean vector dimensionality mismatched!'); |
@@ -1257,7 +1257,7 @@ discard block |
||
1257 | 1257 | * @param int|float|matrix|vector $d |
1258 | 1258 | * @return matrix |
1259 | 1259 | */ |
1260 | - public function equal(int|float|matrix|vector $d): matrix { |
|
1260 | + public function equal(int | float | matrix | vector $d): matrix { |
|
1261 | 1261 | if ($d instanceof self) { |
1262 | 1262 | return $this->equalMatrix($d); |
1263 | 1263 | } elseif ($d instanceof vector) { |
@@ -1289,7 +1289,7 @@ discard block |
||
1289 | 1289 | } |
1290 | 1290 | } |
1291 | 1291 | |
1292 | - protected function equalScalar(int|float $s): matrix { |
|
1292 | + protected function equalScalar(int | float $s): matrix { |
|
1293 | 1293 | $ar = self::factory($this->row, $this->col, $this->dtype); |
1294 | 1294 | for ($i = 0; $i < $this->ndim; ++$i) { |
1295 | 1295 | $ar->data[$i] = $this->data[$i] == $s ? 1 : 0; |
@@ -1302,7 +1302,7 @@ discard block |
||
1302 | 1302 | * @param int|float|matrix|vector $d |
1303 | 1303 | * @return matrix |
1304 | 1304 | */ |
1305 | - public function greater(int|float|matrix|vector $d): matrix { |
|
1305 | + public function greater(int | float | matrix | vector $d): matrix { |
|
1306 | 1306 | if ($d instanceof self) { |
1307 | 1307 | return $this->greaterMatrix($d); |
1308 | 1308 | } elseif ($d instanceof vector) { |
@@ -1313,7 +1313,7 @@ discard block |
||
1313 | 1313 | } |
1314 | 1314 | |
1315 | 1315 | protected function greaterMatrix(matrix $m): matrix { |
1316 | - if ($this->checkShape($this, $m) && $this->checkDtype($this,$m)) { |
|
1316 | + if ($this->checkShape($this, $m) && $this->checkDtype($this, $m)) { |
|
1317 | 1317 | $ar = self::factory($this->row, $this->col, $this->dtype); |
1318 | 1318 | for ($i = 0; $i < $this->ndim; ++$i) { |
1319 | 1319 | $ar->data[$i] = $this->data[$i] > $m->data[$i] ? 1 : 0; |
@@ -1323,7 +1323,7 @@ discard block |
||
1323 | 1323 | } |
1324 | 1324 | |
1325 | 1325 | protected function greaterVector(vector $v): matrix { |
1326 | - if ($this->checkDimensions($v, $this) && $this->checkDtype($this,$v)) { |
|
1326 | + if ($this->checkDimensions($v, $this) && $this->checkDtype($this, $v)) { |
|
1327 | 1327 | $ar = self::factory($this->row, $this->col, $this->dtype); |
1328 | 1328 | for ($i = 0; $i < $this->row; ++$i) { |
1329 | 1329 | for ($j = 0; $j < $this->col; ++$j) { |
@@ -1334,7 +1334,7 @@ discard block |
||
1334 | 1334 | } |
1335 | 1335 | } |
1336 | 1336 | |
1337 | - protected function greaterScalar(int|float $s): matrix { |
|
1337 | + protected function greaterScalar(int | float $s): matrix { |
|
1338 | 1338 | $ar = self::factory($this->row, $this->col, $this->dtype); |
1339 | 1339 | for ($i = 0; $i < $this->ndim; ++$i) { |
1340 | 1340 | $ar->data[$i] = $this->data[$i] > $s ? 1 : 0; |
@@ -1347,10 +1347,10 @@ discard block |
||
1347 | 1347 | * @param int|float|matrix $m |
1348 | 1348 | * @return matrix |
1349 | 1349 | */ |
1350 | - public function less(int|float|matrix $m): matrix { |
|
1350 | + public function less(int | float | matrix $m): matrix { |
|
1351 | 1351 | $ar = self::factory($this->row, $this->col, $this->dtype); |
1352 | 1352 | if ($m instanceof self) { |
1353 | - if ($this->checkShape($this,$m)) { |
|
1353 | + if ($this->checkShape($this, $m)) { |
|
1354 | 1354 | for ($i = 0; $i < $this->ndim; ++$i) { |
1355 | 1355 | $ar->data[$i] = $this->data[$i] < $m->data[$i] ? 1 : 0; |
1356 | 1356 | } |
@@ -1398,7 +1398,7 @@ discard block |
||
1398 | 1398 | } |
1399 | 1399 | |
1400 | 1400 | public function __toString() { |
1401 | - return (string) $this->printMatrix(); |
|
1401 | + return (string)$this->printMatrix(); |
|
1402 | 1402 | } |
1403 | 1403 | |
1404 | 1404 | private function flattenArray(array $ar) { |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * @param \Np\matrix|\Np\vector $d |
24 | 24 | * @return matrix|vector |
25 | 25 | */ |
26 | - public function dot(matrix|vector $d): matrix|vector { |
|
26 | + public function dot(matrix | vector $d): matrix | vector { |
|
27 | 27 | if ($this instanceof matrix) { |
28 | 28 | if ($d instanceof self) { |
29 | 29 | return $this->dotMatrix($d); |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @return \Np\matrix |
44 | 44 | */ |
45 | 45 | protected function dotMatrix(matrix $matrix): matrix { |
46 | - if ($this->checkDtype($this, $matrix) && $this->checkDimensions($this,$matrix)) { |
|
46 | + if ($this->checkDtype($this, $matrix) && $this->checkDimensions($this, $matrix)) { |
|
47 | 47 | $ar = self::factory($this->row, $this->col, $this->dtype); |
48 | 48 | blas::gemm($this, $matrix, $ar); |
49 | 49 | return $ar; |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * Compute the (Moore-Penrose) pseudo inverse of the general matrix. |
92 | 92 | * @return matrix|null |
93 | 93 | */ |
94 | - public function pseudoInverse(): matrix|null { |
|
94 | + public function pseudoInverse(): matrix | null { |
|
95 | 95 | $k = min($this->row, $this->col); |
96 | 96 | $s = vector::factory($k, $this->dtype); |
97 | 97 | $u = self::factory($this->row, $this->row, $this->dtype); |