@@ -21,9 +21,9 @@ |
||
| 21 | 21 | protected $b; |
| 22 | 22 | |
| 23 | 23 | public function setUp() : void { |
| 24 | - $this->a = matrix::uniform(500,500); |
|
| 24 | + $this->a = matrix::uniform(500, 500); |
|
| 25 | 25 | |
| 26 | - $this->b = matrix::uniform(50,50); |
|
| 26 | + $this->b = matrix::uniform(50, 50); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | /** |
| 14 | 14 | * @var \Np\matrix |
| 15 | 15 | */ |
| 16 | - protected $a,$b; |
|
| 16 | + protected $a, $b; |
|
| 17 | 17 | |
| 18 | 18 | public function setUp() : void { |
| 19 | 19 | $this->a = matrix::uniform(500, 500); |
@@ -2,7 +2,7 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace Np\benchmarks\matrix\arithmetic; |
| 4 | 4 | |
| 5 | -use Np\{matrix,vector}; |
|
| 5 | +use Np\{matrix, vector}; |
|
| 6 | 6 | |
| 7 | 7 | /** |
| 8 | 8 | * @Groups({"Arithmetic"}) |
@@ -26,8 +26,10 @@ |
||
| 26 | 26 | $lead = 0; |
| 27 | 27 | $ar = $m->copyMatrix(); |
| 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++; |
@@ -19,11 +19,11 @@ |
||
| 19 | 19 | |
| 20 | 20 | class ref { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * |
|
| 24 | - * @param \Np\matrix $m |
|
| 25 | - * @return matrix|null |
|
| 26 | - */ |
|
| 22 | + /** |
|
| 23 | + * |
|
| 24 | + * @param \Np\matrix $m |
|
| 25 | + * @return matrix|null |
|
| 26 | + */ |
|
| 27 | 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(); |
@@ -24,10 +24,10 @@ |
||
| 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 | - if($m->dtype == matrix::FLOAT) { |
|
| 30 | + if ($m->dtype == matrix::FLOAT) { |
|
| 31 | 31 | $lp = lapack::sgetrf($ar, $ipiv); |
| 32 | 32 | if ($lp != 0) { |
| 33 | 33 | return null; |
@@ -76,12 +76,12 @@ discard block |
||
| 76 | 76 | return $ar; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * |
|
| 81 | - * @param int $col |
|
| 82 | - * @param int $dtype |
|
| 83 | - * @return vector |
|
| 84 | - */ |
|
| 79 | + /** |
|
| 80 | + * |
|
| 81 | + * @param int $col |
|
| 82 | + * @param int $dtype |
|
| 83 | + * @return vector |
|
| 84 | + */ |
|
| 85 | 85 | public static function zeros(int $col, int $dtype = self::FLOAT): vector { |
| 86 | 86 | $ar = self::factory($col, $dtype); |
| 87 | 87 | for ($i = 0; $i < $col; ++$i) { |
@@ -104,10 +104,10 @@ discard block |
||
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
| 107 | - * create a null like vector |
|
| 108 | - * @param int $col |
|
| 109 | - * @return vector |
|
| 110 | - */ |
|
| 107 | + * create a null like vector |
|
| 108 | + * @param int $col |
|
| 109 | + * @return vector |
|
| 110 | + */ |
|
| 111 | 111 | public static function null(int $col, int $dtype = self::FLOAT): vector { |
| 112 | 112 | $ar = self::factory($col, $dtype); |
| 113 | 113 | for ($i = 0; $i < $col; ++$i) { |
@@ -674,7 +674,7 @@ discard block |
||
| 674 | 674 | return true; |
| 675 | 675 | } |
| 676 | 676 | |
| 677 | - protected function checkDtype(vector $vector) { |
|
| 677 | + protected function checkDtype(vector $vector) { |
|
| 678 | 678 | if($this->dtype != $vector->dtype) { |
| 679 | 679 | self::_err('Mismatch Dtype of given vector'); |
| 680 | 680 | } |
@@ -15,8 +15,8 @@ discard block |
||
| 15 | 15 | * |
| 16 | 16 | */ |
| 17 | 17 | class vector { |
| 18 | - const INT=0, FLOAT = 1, DOUBLE = 2; |
|
| 19 | - public $data,$col,$ndim,$dtype; |
|
| 18 | + const INT = 0, FLOAT = 1, DOUBLE = 2; |
|
| 19 | + public $data, $col, $ndim, $dtype; |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * |
@@ -34,9 +34,9 @@ discard block |
||
| 34 | 34 | * @param int $dtype |
| 35 | 35 | * @return vector |
| 36 | 36 | */ |
| 37 | - public static function ar(array $data, int $dtype= self::FLOAT): vector { |
|
| 37 | + public static function ar(array $data, int $dtype = self::FLOAT): vector { |
|
| 38 | 38 | if (is_array($data) && !is_array($data[0])) { |
| 39 | - $ar = self::factory(count($data),$dtype); |
|
| 39 | + $ar = self::factory(count($data), $dtype); |
|
| 40 | 40 | $ar->setData($data); |
| 41 | 41 | } else { |
| 42 | 42 | self::_err('data must be of same dimensions'); |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * @param int $dtype |
| 52 | 52 | * @return vector |
| 53 | 53 | */ |
| 54 | - public static function randn(int $col, int $dtype= self::FLOAT): vector { |
|
| 54 | + public static function randn(int $col, int $dtype = self::FLOAT): vector { |
|
| 55 | 55 | $ar = self::factory($col, $dtype); |
| 56 | 56 | $max = getrandmax(); |
| 57 | 57 | for ($i = 0; $i < $ar->col; ++$i) { |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | |
| 243 | 243 | public function sum():float { |
| 244 | 244 | $r = 0.0; |
| 245 | - for($i = 0; $i < $this->col; ++$i) { |
|
| 245 | + for ($i = 0; $i < $this->col; ++$i) { |
|
| 246 | 246 | $r += $this->data[$i]; |
| 247 | 247 | } |
| 248 | 248 | return $r; |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | */ |
| 255 | 255 | public function product():float { |
| 256 | 256 | $r = 1.0; |
| 257 | - for($i = 0; $i < $this->col; ++$i) { |
|
| 257 | + for ($i = 0; $i < $this->col; ++$i) { |
|
| 258 | 258 | $r *= $this->data[$i]; |
| 259 | 259 | } |
| 260 | 260 | return $r; |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | * @return vector |
| 267 | 267 | */ |
| 268 | 268 | public function dotMatrix(\Np\matrix $m): vector { |
| 269 | - if($this->dtype != $m->dtype) { |
|
| 269 | + if ($this->dtype != $m->dtype) { |
|
| 270 | 270 | self::_err('Mismatch Dtype of given matrix'); |
| 271 | 271 | } |
| 272 | 272 | $mvr = self::factory($this->col, $this->dtype); |
@@ -280,8 +280,8 @@ discard block |
||
| 280 | 280 | * @param int|float|matrix|vector $d |
| 281 | 281 | * @return matrix|vector |
| 282 | 282 | */ |
| 283 | - public function divide(int|float|matrix|vector $d):matrix|vector { |
|
| 284 | - if($d instanceof matrix){ |
|
| 283 | + public function divide(int | float | matrix | vector $d):matrix | vector { |
|
| 284 | + if ($d instanceof matrix) { |
|
| 285 | 285 | return $this->divideMatrix($d); |
| 286 | 286 | } elseif ($d instanceof self) { |
| 287 | 287 | return $this->divideVector($d); |
@@ -296,11 +296,11 @@ discard block |
||
| 296 | 296 | * @return matrix |
| 297 | 297 | */ |
| 298 | 298 | protected function divideMatrix(\Np\matrix $m):matrix { |
| 299 | - if($this->col == $m->col && $this->dtype == $m->dtype) { |
|
| 300 | - $vr = matrix::factory($m->row,$m->col, $m->dtype); |
|
| 301 | - for($i = 0; $i < $m->row; ++$i) { |
|
| 302 | - for($j = 0; $j < $m->col; ++$j) { |
|
| 303 | - $vr->data[$i * $m->col +$j] = $this->data[$j] / $m->data[$i * $m->col + $j]; |
|
| 299 | + if ($this->col == $m->col && $this->dtype == $m->dtype) { |
|
| 300 | + $vr = matrix::factory($m->row, $m->col, $m->dtype); |
|
| 301 | + for ($i = 0; $i < $m->row; ++$i) { |
|
| 302 | + for ($j = 0; $j < $m->col; ++$j) { |
|
| 303 | + $vr->data[$i * $m->col + $j] = $this->data[$j] / $m->data[$i * $m->col + $j]; |
|
| 304 | 304 | } |
| 305 | 305 | } |
| 306 | 306 | return $vr; |
@@ -314,9 +314,9 @@ discard block |
||
| 314 | 314 | * @return vector |
| 315 | 315 | */ |
| 316 | 316 | protected function divideVector(vector $v) :vector { |
| 317 | - if($this->checkDimensions($v) && $this->checkDtype($v)) { |
|
| 317 | + if ($this->checkDimensions($v) && $this->checkDtype($v)) { |
|
| 318 | 318 | $vr = self::factory($this->col, $this->dtype); |
| 319 | - for($i = 0; $i < $this->col; ++$i) { |
|
| 319 | + for ($i = 0; $i < $this->col; ++$i) { |
|
| 320 | 320 | $vr->data[$i] = $this->data[$i] / $v->data[$i]; |
| 321 | 321 | } |
| 322 | 322 | return $vr; |
@@ -328,7 +328,7 @@ discard block |
||
| 328 | 328 | * @param int|float $s |
| 329 | 329 | * @return vector |
| 330 | 330 | */ |
| 331 | - protected function divideScalar(int|float $s): vector { |
|
| 331 | + protected function divideScalar(int | float $s): vector { |
|
| 332 | 332 | $vr = self::factory($this->col, $this->dtype); |
| 333 | 333 | for ($i = 0; $i < $this->col; ++$i) { |
| 334 | 334 | $vr->data[$i] = $this->data[$i] / $s; |
@@ -341,8 +341,8 @@ discard block |
||
| 341 | 341 | * @param int|float|matrix|vector $d |
| 342 | 342 | * @return matrix|vector |
| 343 | 343 | */ |
| 344 | - public function multiply(int|float|matrix|vector $d):matrix|vector { |
|
| 345 | - if($d instanceof matrix){ |
|
| 344 | + public function multiply(int | float | matrix | vector $d):matrix | vector { |
|
| 345 | + if ($d instanceof matrix) { |
|
| 346 | 346 | return $this->multiplyMatrix($d); |
| 347 | 347 | } elseif ($d instanceof self) { |
| 348 | 348 | return $this->multiplyVector($d); |
@@ -357,11 +357,11 @@ discard block |
||
| 357 | 357 | * @return matrix |
| 358 | 358 | */ |
| 359 | 359 | protected function multiplyMatrix(\Np\matrix $m):matrix { |
| 360 | - if($this->col == $m->col && $this->dtype == $m->dtype) { |
|
| 361 | - $vr = matrix::factory($m->row,$m->col, $m->dtype);; |
|
| 362 | - for($i = 0; $i < $m->row; ++$i) { |
|
| 363 | - for($j = 0; $j < $m->col; ++$j) { |
|
| 364 | - $vr->data[$i * $m->col +$j] = $this->data[$j] * $m->data[$i * $m->col + $j]; |
|
| 360 | + if ($this->col == $m->col && $this->dtype == $m->dtype) { |
|
| 361 | + $vr = matrix::factory($m->row, $m->col, $m->dtype); ; |
|
| 362 | + for ($i = 0; $i < $m->row; ++$i) { |
|
| 363 | + for ($j = 0; $j < $m->col; ++$j) { |
|
| 364 | + $vr->data[$i * $m->col + $j] = $this->data[$j] * $m->data[$i * $m->col + $j]; |
|
| 365 | 365 | } |
| 366 | 366 | } |
| 367 | 367 | return $vr; |
@@ -375,9 +375,9 @@ discard block |
||
| 375 | 375 | * @return vector |
| 376 | 376 | */ |
| 377 | 377 | protected function multiplyVector(\Np\vector $vector):vector { |
| 378 | - if($this->checkDimensions($vector) && $this->checkDtype($vector)) { |
|
| 378 | + if ($this->checkDimensions($vector) && $this->checkDtype($vector)) { |
|
| 379 | 379 | $vr = self::factory($this->col, $this->dtype); |
| 380 | - for($i = 0; $i < $this->col; ++$i) { |
|
| 380 | + for ($i = 0; $i < $this->col; ++$i) { |
|
| 381 | 381 | $vr->data[$i] = $this->data[$i] * $vector->data[$i]; |
| 382 | 382 | } |
| 383 | 383 | return $vr; |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | * @param int|float $s |
| 391 | 391 | * @return vector |
| 392 | 392 | */ |
| 393 | - protected function multiplyScalar(int|float $s): vector { |
|
| 393 | + protected function multiplyScalar(int | float $s): vector { |
|
| 394 | 394 | $vr = $this->copyVector(); |
| 395 | 395 | core\blas::scale($s, $vr); |
| 396 | 396 | return $vr; |
@@ -402,8 +402,8 @@ discard block |
||
| 402 | 402 | * @param int|float|matrix|vector $d |
| 403 | 403 | * @return matrix|vector |
| 404 | 404 | */ |
| 405 | - public function add(int|float|matrix|vector $d):matrix|vector { |
|
| 406 | - if($d instanceof matrix){ |
|
| 405 | + public function add(int | float | matrix | vector $d):matrix | vector { |
|
| 406 | + if ($d instanceof matrix) { |
|
| 407 | 407 | return $this->addMatrix($d); |
| 408 | 408 | } elseif ($d instanceof self) { |
| 409 | 409 | return $this->addVector($d); |
@@ -418,11 +418,11 @@ discard block |
||
| 418 | 418 | * @return matrix |
| 419 | 419 | */ |
| 420 | 420 | protected function addMatrix(\Np\matrix $m):matrix { |
| 421 | - if($this->col == $m->col && $this->dtype == $m->dtype) { |
|
| 422 | - $vr = matrix::factory($m->row,$m->col, $m->dtype); |
|
| 423 | - for($i = 0; $i < $m->row; ++$i) { |
|
| 424 | - for($j = 0; $j < $m->col; ++$j) { |
|
| 425 | - $vr->data[$i * $m->col +$j] = $this->data[$j] + $m->data[$i * $m->col + $j]; |
|
| 421 | + if ($this->col == $m->col && $this->dtype == $m->dtype) { |
|
| 422 | + $vr = matrix::factory($m->row, $m->col, $m->dtype); |
|
| 423 | + for ($i = 0; $i < $m->row; ++$i) { |
|
| 424 | + for ($j = 0; $j < $m->col; ++$j) { |
|
| 425 | + $vr->data[$i * $m->col + $j] = $this->data[$j] + $m->data[$i * $m->col + $j]; |
|
| 426 | 426 | } |
| 427 | 427 | } |
| 428 | 428 | return $vr; |
@@ -436,9 +436,9 @@ discard block |
||
| 436 | 436 | * @return vector |
| 437 | 437 | */ |
| 438 | 438 | protected function addVector(\Np\vector $vector):vector { |
| 439 | - if($this->checkDimensions($vector) && $this->checkDtype($vector)) { |
|
| 439 | + if ($this->checkDimensions($vector) && $this->checkDtype($vector)) { |
|
| 440 | 440 | $vr = self::factory($this->col, $this->dtype); |
| 441 | - for($i = 0; $i < $this->col; ++$i) { |
|
| 441 | + for ($i = 0; $i < $this->col; ++$i) { |
|
| 442 | 442 | $vr->data[$i] = $this->data[$i] + $vector->data[$i]; |
| 443 | 443 | } |
| 444 | 444 | return $vr; |
@@ -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->copyVector(); |
| 455 | 455 | for ($i = 0; $i < $this->col; ++$i) { |
| 456 | 456 | $vr->data[$i] += $s; |
@@ -465,9 +465,9 @@ discard block |
||
| 465 | 465 | * @return vector |
| 466 | 466 | */ |
| 467 | 467 | public function powVector(\Np\vector $vector):vector { |
| 468 | - if($this->checkDimensions($vector) && $this->checkDtype($vector)) { |
|
| 468 | + if ($this->checkDimensions($vector) && $this->checkDtype($vector)) { |
|
| 469 | 469 | $vr = self::factory($this->col, $this->dtype); |
| 470 | - for($i = 0; $i < $this->col; ++$i) { |
|
| 470 | + for ($i = 0; $i < $this->col; ++$i) { |
|
| 471 | 471 | $vr->data[$i] = $this->data[$i] ** $vector->data[$i]; |
| 472 | 472 | } |
| 473 | 473 | return $vr; |
@@ -480,9 +480,9 @@ discard block |
||
| 480 | 480 | * @return vector |
| 481 | 481 | */ |
| 482 | 482 | public function modVector(\Np\vector $vector):vector { |
| 483 | - if($this->checkDimensions($vector) && $this->checkDtype($vector)) { |
|
| 483 | + if ($this->checkDimensions($vector) && $this->checkDtype($vector)) { |
|
| 484 | 484 | $vr = self::factory($this->col, $this->dtype); |
| 485 | - for($i = 0; $i < $this->col; ++$i) { |
|
| 485 | + for ($i = 0; $i < $this->col; ++$i) { |
|
| 486 | 486 | $vr->data[$i] = $this->data[$i] % $vector->data[$i]; |
| 487 | 487 | } |
| 488 | 488 | return $vr; |
@@ -494,8 +494,8 @@ discard block |
||
| 494 | 494 | * @param int|float|matrix|vector $d |
| 495 | 495 | * @return matrix|vector |
| 496 | 496 | */ |
| 497 | - public function subtract(int|float|matrix|vector $d):matrix|vector { |
|
| 498 | - if($d instanceof matrix){ |
|
| 497 | + public function subtract(int | float | matrix | vector $d):matrix | vector { |
|
| 498 | + if ($d instanceof matrix) { |
|
| 499 | 499 | return $this->subtractMatrix($d); |
| 500 | 500 | } elseif ($d instanceof self) { |
| 501 | 501 | return $this->subtractVector($d); |
@@ -510,11 +510,11 @@ discard block |
||
| 510 | 510 | * @return matrix |
| 511 | 511 | */ |
| 512 | 512 | protected function subtractMatrix(\Np\matrix $m):matrix { |
| 513 | - if($this->col == $m->col && $this->dtype == $m->dtype) { |
|
| 514 | - $vr = matrix::factory($m->row,$m->col, $m->dtype); |
|
| 515 | - for($i = 0; $i < $m->row; ++$i) { |
|
| 516 | - for($j = 0; $j < $m->col; ++$j) { |
|
| 517 | - $vr->data[$i * $m->col +$j] = $this->data[$j] - $m->data[$i * $m->col + $j]; |
|
| 513 | + if ($this->col == $m->col && $this->dtype == $m->dtype) { |
|
| 514 | + $vr = matrix::factory($m->row, $m->col, $m->dtype); |
|
| 515 | + for ($i = 0; $i < $m->row; ++$i) { |
|
| 516 | + for ($j = 0; $j < $m->col; ++$j) { |
|
| 517 | + $vr->data[$i * $m->col + $j] = $this->data[$j] - $m->data[$i * $m->col + $j]; |
|
| 518 | 518 | } |
| 519 | 519 | } |
| 520 | 520 | return $vr; |
@@ -528,9 +528,9 @@ discard block |
||
| 528 | 528 | * @return vector |
| 529 | 529 | */ |
| 530 | 530 | protected function subtractVector(\Np\vector $vector):vector { |
| 531 | - if($this->checkDimensions($vector) && $this->checkDtype($vector)) { |
|
| 531 | + if ($this->checkDimensions($vector) && $this->checkDtype($vector)) { |
|
| 532 | 532 | $vr = self::factory($this->col, $this->dtype); |
| 533 | - for($i = 0; $i < $this->col; ++$i) { |
|
| 533 | + for ($i = 0; $i < $this->col; ++$i) { |
|
| 534 | 534 | $vr->data[$i] = $this->data[$i] - $vector->data[$i]; |
| 535 | 535 | } |
| 536 | 536 | return $vr; |
@@ -542,7 +542,7 @@ discard block |
||
| 542 | 542 | * @param \Np\vector $scalar |
| 543 | 543 | * @return \Np\vector |
| 544 | 544 | */ |
| 545 | - protected function substractScalar(int|float $scalar): vector { |
|
| 545 | + protected function substractScalar(int | float $scalar): vector { |
|
| 546 | 546 | $vr = self::factory($this->col, $this->dtype); |
| 547 | 547 | for ($i = 0; $i < $this->col; ++$i) { |
| 548 | 548 | $vr->data[$i] = $this->data[$i] - $scalar; |
@@ -584,7 +584,7 @@ discard block |
||
| 584 | 584 | * @return vector |
| 585 | 585 | */ |
| 586 | 586 | public function maximum(\Np\vector $vector) :vector { |
| 587 | - if($this->checkDimensions($vector)) { |
|
| 587 | + if ($this->checkDimensions($vector)) { |
|
| 588 | 588 | |
| 589 | 589 | } |
| 590 | 590 | } |
@@ -595,7 +595,7 @@ discard block |
||
| 595 | 595 | * @return vector |
| 596 | 596 | */ |
| 597 | 597 | public function minium(\Np\vector $vector) :vector { |
| 598 | - if($this->checkDimensions($vector)) { |
|
| 598 | + if ($this->checkDimensions($vector)) { |
|
| 599 | 599 | |
| 600 | 600 | } |
| 601 | 601 | } |
@@ -604,7 +604,7 @@ discard block |
||
| 604 | 604 | * @param string $type i or d |
| 605 | 605 | * |
| 606 | 606 | */ |
| 607 | - public function sort($type='i') { |
|
| 607 | + public function sort($type = 'i') { |
|
| 608 | 608 | core\lapack::sort($this, $type); |
| 609 | 609 | return $this; |
| 610 | 610 | } |
@@ -614,7 +614,7 @@ discard block |
||
| 614 | 614 | * set data to vector |
| 615 | 615 | * @param int|float|array $data |
| 616 | 616 | */ |
| 617 | - public function setData(int|float|array $data) { |
|
| 617 | + public function setData(int | float | array $data) { |
|
| 618 | 618 | if (is_array($data) && !is_array($data[0])) { |
| 619 | 619 | for ($i = 0; $i < $this->col; ++$i) { |
| 620 | 620 | $this->data[$i] = $data[$i]; |
@@ -628,9 +628,9 @@ discard block |
||
| 628 | 628 | |
| 629 | 629 | |
| 630 | 630 | public function asMatrix():matrix { |
| 631 | - $size = (int) sqrt($this->col); |
|
| 631 | + $size = (int)sqrt($this->col); |
|
| 632 | 632 | $ar = matrix::factory($size, $size, $this->dtype); |
| 633 | - for($i = 0; $i < $ar->ndim; ++$i) { |
|
| 633 | + for ($i = 0; $i < $ar->ndim; ++$i) { |
|
| 634 | 634 | $ar->data[$i] = $this->data[$i]; |
| 635 | 635 | } |
| 636 | 636 | return $ar; |
@@ -650,7 +650,7 @@ discard block |
||
| 650 | 650 | |
| 651 | 651 | public function asArray() { |
| 652 | 652 | $ar = array_fill(0, $this->col, null); |
| 653 | - for($i = 0; $i < $this->col; ++$i) { |
|
| 653 | + for ($i = 0; $i < $this->col; ++$i) { |
|
| 654 | 654 | $ar[$i] = $this->data[$i]; |
| 655 | 655 | } |
| 656 | 656 | return $ar; |
@@ -664,25 +664,25 @@ discard block |
||
| 664 | 664 | } |
| 665 | 665 | |
| 666 | 666 | public function __toString() { |
| 667 | - return (string) $this->printVector(); |
|
| 667 | + return (string)$this->printVector(); |
|
| 668 | 668 | } |
| 669 | 669 | |
| 670 | 670 | protected function checkDimensions(vector $vector) { |
| 671 | - if($this->col != $vector->col) { |
|
| 671 | + if ($this->col != $vector->col) { |
|
| 672 | 672 | self::_err('Mismatch Dimensions of given vector'); |
| 673 | 673 | } |
| 674 | 674 | return true; |
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | protected function checkDtype(vector $vector) { |
| 678 | - if($this->dtype != $vector->dtype) { |
|
| 678 | + if ($this->dtype != $vector->dtype) { |
|
| 679 | 679 | self::_err('Mismatch Dtype of given vector'); |
| 680 | 680 | } |
| 681 | 681 | return true; |
| 682 | 682 | } |
| 683 | 683 | |
| 684 | 684 | protected function __construct(int $col, int $dtype = self::FLOAT) { |
| 685 | - if($col < 1 ) { |
|
| 685 | + if ($col < 1) { |
|
| 686 | 686 | throw new InvalidArgumentException('* To create Numphp/Vector col must be greater than 0!, Op Failed! * '); |
| 687 | 687 | } |
| 688 | 688 | $this->col = $col; |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare (strict_types=1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Np\decompositions; |
| 6 | 6 | |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare (strict_types=1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Np\decompositions; |
| 6 | 6 | |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare (strict_types=1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Np\decompositions; |
| 6 | 6 | |