Files
trueskill/src/Numerics/DiagonalMatrix.php

29 lines
794 B
PHP
Raw Normal View History

2022-07-05 15:55:47 +02:00
<?php
namespace DNW\Skills\Numerics;
class DiagonalMatrix extends Matrix
{
2023-08-03 13:08:04 +00:00
/**
* @param float[] $diagonalValues
*/
public function __construct(array $diagonalValues)
{
$diagonalCount = count($diagonalValues);
$rowCount = $diagonalCount;
$colCount = $rowCount;
parent::__construct($rowCount, $colCount);
for ($currentRow = 0; $currentRow < $rowCount; $currentRow++) {
for ($currentCol = 0; $currentCol < $colCount; $currentCol++) {
2022-07-05 16:21:06 +02:00
if ($currentRow === $currentCol) {
$this->setValue($currentRow, $currentCol, $diagonalValues[$currentRow]);
} else {
$this->setValue($currentRow, $currentCol, 0);
}
}
}
}
2022-07-05 15:55:47 +02:00
}