@@ -8,6 +8,6 @@ |
||
8 | 8 | * |
9 | 9 | * @author ghost |
10 | 10 | */ |
11 | -class dtypeException extends invalidArgumentException{ |
|
11 | +class dtypeException extends invalidArgumentException { |
|
12 | 12 | //put your code here |
13 | 13 | } |
@@ -5,7 +5,7 @@ |
||
5 | 5 | use Np\vector; |
6 | 6 | vector::time(); |
7 | 7 | vector::getMemory(); |
8 | -$v = vector::ar(range(random_int(1,2), random_int(99999,9999999))); |
|
8 | +$v = vector::ar(range(random_int(1, 2), random_int(99999, 9999999))); |
|
9 | 9 | |
10 | 10 | echo $v->sum() . PHP_EOL; |
11 | 11 | vector::getMemory(); |
@@ -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); |
@@ -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 | } |
@@ -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) { |
@@ -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 | |
@@ -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) { |
@@ -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; |
@@ -515,7 +515,7 @@ discard block |
||
515 | 515 | * @param int|float|\Np\matrix|\Np\vector $d |
516 | 516 | * @return matrix|vector |
517 | 517 | */ |
518 | - public function pow(int|float|\Np\matrix|\Np\vector $d): matrix|vector { |
|
518 | + public function pow(int | float | \Np\matrix | \Np\vector $d): matrix | vector { |
|
519 | 519 | if ($d instanceof matrix) { |
520 | 520 | return $this->powMatrix($d); |
521 | 521 | } elseif ($d instanceof vector) { |
@@ -561,7 +561,7 @@ discard block |
||
561 | 561 | * |
562 | 562 | * @param int|float $s |
563 | 563 | */ |
564 | - protected function powScalar(int|float $s) { |
|
564 | + protected function powScalar(int | float $s) { |
|
565 | 565 | $v = $this->copyVector(); |
566 | 566 | for ($i = 0; $i < $this->col; ++$i) { |
567 | 567 | $v->data[$i] = $v->data[$i] ** $s; |
@@ -573,7 +573,7 @@ discard block |
||
573 | 573 | * @param int|float|\Np\matrix|\Np\vector $d |
574 | 574 | * @return matrix|vector |
575 | 575 | */ |
576 | - public function mod(int|float|\Np\matrix|\Np\vector $d): matrix|vector { |
|
576 | + public function mod(int | float | \Np\matrix | \Np\vector $d): matrix | vector { |
|
577 | 577 | if ($d instanceof matrix) { |
578 | 578 | return $this->powMatrix($d); |
579 | 579 | } elseif ($d instanceof vector) { |
@@ -619,7 +619,7 @@ discard block |
||
619 | 619 | * |
620 | 620 | * @param int|float $s |
621 | 621 | */ |
622 | - protected function modScalar(int|float $s) { |
|
622 | + protected function modScalar(int | float $s) { |
|
623 | 623 | $v = $this->copyVector(); |
624 | 624 | for ($i = 0; $i < $this->col; ++$i) { |
625 | 625 | $v->data[$i] = $v->data[$i] % $s; |
@@ -631,7 +631,7 @@ discard block |
||
631 | 631 | * @param int|float|matrix|vector $d |
632 | 632 | * @return matrix|vector |
633 | 633 | */ |
634 | - public function subtract(int|float|matrix|vector $d): matrix|vector { |
|
634 | + public function subtract(int | float | matrix | vector $d): matrix | vector { |
|
635 | 635 | if ($d instanceof matrix) { |
636 | 636 | return $this->subtractMatrix($d); |
637 | 637 | } elseif ($d instanceof self) { |
@@ -678,7 +678,7 @@ discard block |
||
678 | 678 | * @param \Np\vector $scalar |
679 | 679 | * @return \Np\vector |
680 | 680 | */ |
681 | - protected function substractScalar(int|float $scalar): vector { |
|
681 | + protected function substractScalar(int | float $scalar): vector { |
|
682 | 682 | $vr = self::factory($this->col, $this->dtype); |
683 | 683 | for ($i = 0; $i < $this->col; ++$i) { |
684 | 684 | $vr->data[$i] = $this->data[$i] - $scalar; |
@@ -799,7 +799,7 @@ discard block |
||
799 | 799 | |
800 | 800 | $vr = self::factory($this->col, $this->dtype); |
801 | 801 | |
802 | - for($i = 0; $i < $this->col; ++$i) { |
|
802 | + for ($i = 0; $i < $this->col; ++$i) { |
|
803 | 803 | if ($this->data[$i] > $max) { |
804 | 804 | $vr->data[$i] = $max; |
805 | 805 | continue; |
@@ -815,7 +815,7 @@ discard block |
||
815 | 815 | |
816 | 816 | public function clipUpper(float $min) : vector { |
817 | 817 | $vr = self::factory($this->col, $this->dtype); |
818 | - for($i = 0; $i < $this->col; ++$i) { |
|
818 | + for ($i = 0; $i < $this->col; ++$i) { |
|
819 | 819 | if ($this->data[$i] > $min) { |
820 | 820 | $vr->data[$i] = $min; |
821 | 821 | continue; |
@@ -826,7 +826,7 @@ discard block |
||
826 | 826 | |
827 | 827 | public function clipLower(float $min) : vector { |
828 | 828 | $vr = self::factory($this->col, $this->dtype); |
829 | - for($i = 0; $i < $this->col; ++$i) { |
|
829 | + for ($i = 0; $i < $this->col; ++$i) { |
|
830 | 830 | if ($this->data[$i] < $min) { |
831 | 831 | $vr->data[$i] = $min; |
832 | 832 | continue; |
@@ -882,15 +882,15 @@ discard block |
||
882 | 882 | * |
883 | 883 | * @return int|float |
884 | 884 | */ |
885 | - public function mean():int|float { |
|
886 | - return $this->sum()/ $this->col; |
|
885 | + public function mean():int | float { |
|
886 | + return $this->sum() / $this->col; |
|
887 | 887 | } |
888 | 888 | |
889 | 889 | /** |
890 | 890 | * |
891 | 891 | * @return int|float |
892 | 892 | */ |
893 | - public function median():int|float { |
|
893 | + public function median():int | float { |
|
894 | 894 | $mid = intdiv($this->col, 2); |
895 | 895 | |
896 | 896 | $a = $this->copyVector()->sort(); |
@@ -937,7 +937,7 @@ discard block |
||
937 | 937 | * set data to vector |
938 | 938 | * @param int|float|array $data |
939 | 939 | */ |
940 | - public function setData(int|float|array $data) { |
|
940 | + public function setData(int | float | array $data) { |
|
941 | 941 | if (is_array($data) && !is_array($data[0])) { |
942 | 942 | for ($i = 0; $i < $this->col; ++$i) { |
943 | 943 | $this->data[$i] = $data[$i]; |
@@ -950,7 +950,7 @@ discard block |
||
950 | 950 | } |
951 | 951 | |
952 | 952 | public function asMatrix(): matrix { |
953 | - $size = (int) sqrt($this->col); |
|
953 | + $size = (int)sqrt($this->col); |
|
954 | 954 | $ar = matrix::factory($size, $size, $this->dtype); |
955 | 955 | for ($i = 0; $i < $ar->ndim; ++$i) { |
956 | 956 | $ar->data[$i] = $this->data[$i]; |
@@ -986,7 +986,7 @@ discard block |
||
986 | 986 | } |
987 | 987 | |
988 | 988 | public function __toString() { |
989 | - return (string) $this->printVector(); |
|
989 | + return (string)$this->printVector(); |
|
990 | 990 | } |
991 | 991 | |
992 | 992 | protected function __construct(public int $col, int $dtype = self::FLOAT) { |
@@ -30,21 +30,21 @@ |
||
30 | 30 | public $data; |
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; |