Files
trueskill/src/Numerics/SquareMatrix.php

26 lines
618 B
PHP
Raw Normal View History

2022-07-05 15:55:47 +02:00
<?php
declare(strict_types=1);
2022-07-05 15:55:47 +02:00
namespace DNW\Skills\Numerics;
class SquareMatrix extends Matrix
{
2023-08-02 13:19:35 +00:00
public function __construct(float|int ...$allValues)
{
$rows = (int)sqrt(count($allValues));
$cols = $rows;
2022-07-05 15:55:47 +02:00
$matrixData = [];
$allValuesIndex = 0;
for ($currentRow = 0; $currentRow < $rows; $currentRow++) {
for ($currentColumn = 0; $currentColumn < $cols; $currentColumn++) {
$matrixData[$currentRow][$currentColumn] = $allValues[$allValuesIndex++];
}
}
parent::__construct($rows, $cols, $matrixData);
}
2022-07-05 15:55:47 +02:00
}