mirror of
https://github.com/furyfire/trueskill.git
synced 2025-04-19 04:14:28 +00:00
Optimization efforts
This commit is contained in:
@ -15,11 +15,11 @@ class BasicMath
|
||||
/**
|
||||
* Squares the input (x^2 = x * x)
|
||||
*
|
||||
* @param float $x Value to square (x)
|
||||
* @param $x Value to square (x)
|
||||
*
|
||||
* @return float The squared value (x^2)
|
||||
*/
|
||||
public static function square($x): float
|
||||
public static function square(float $x): float
|
||||
{
|
||||
return $x * $x;
|
||||
}
|
||||
|
@ -12,13 +12,11 @@ class DiagonalMatrix extends Matrix
|
||||
public function __construct(array $diagonalValues)
|
||||
{
|
||||
$diagonalCount = count($diagonalValues);
|
||||
$rowCount = $diagonalCount;
|
||||
$colCount = $rowCount;
|
||||
|
||||
parent::__construct($rowCount, $colCount);
|
||||
parent::__construct($diagonalCount, $diagonalCount);
|
||||
|
||||
for ($currentRow = 0; $currentRow < $rowCount; $currentRow++) {
|
||||
for ($currentCol = 0; $currentCol < $colCount; $currentCol++) {
|
||||
for ($currentRow = 0; $currentRow < $diagonalCount; $currentRow++) {
|
||||
for ($currentCol = 0; $currentCol < $diagonalCount; $currentCol++) {
|
||||
if ($currentRow === $currentCol) {
|
||||
$this->setValue($currentRow, $currentCol, $diagonalValues[$currentRow]);
|
||||
} else {
|
||||
|
@ -8,18 +8,17 @@ class SquareMatrix extends Matrix
|
||||
{
|
||||
public function __construct(float|int ...$allValues)
|
||||
{
|
||||
$rows = (int)sqrt(count($allValues));
|
||||
$cols = $rows;
|
||||
$size = (int)sqrt(count($allValues));
|
||||
|
||||
$matrixData = [];
|
||||
$allValuesIndex = 0;
|
||||
|
||||
for ($currentRow = 0; $currentRow < $rows; $currentRow++) {
|
||||
for ($currentColumn = 0; $currentColumn < $cols; $currentColumn++) {
|
||||
for ($currentRow = 0; $currentRow < $size; $currentRow++) {
|
||||
for ($currentColumn = 0; $currentColumn < $size; $currentColumn++) {
|
||||
$matrixData[$currentRow][$currentColumn] = $allValues[$allValuesIndex++];
|
||||
}
|
||||
}
|
||||
|
||||
parent::__construct($rows, $cols, $matrixData);
|
||||
parent::__construct($size, $size, $matrixData);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user