Pint applied for formatting

This commit is contained in:
Alex Wulf
2022-07-05 15:55:47 +02:00
parent bfc558d1f2
commit 7d4547df6a
68 changed files with 670 additions and 402 deletions

View File

@@ -1,4 +1,6 @@
<?php namespace DNW\Skills\Numerics;
<?php
namespace DNW\Skills\Numerics;
use Exception;
@@ -7,7 +9,9 @@ class Matrix
const ERROR_TOLERANCE = 0.0000000001;
private $_matrixRowData;
private $_rowCount;
private $_columnCount;
public function __construct($rows = 0, $columns = 0, $matrixData = null)
@@ -19,7 +23,7 @@ class Matrix
public static function fromColumnValues($rows, $columns, $columnValues)
{
$data = array();
$data = [];
$result = new Matrix($rows, $columns, $data);
for ($currentColumn = 0; $currentColumn < $columns; $currentColumn++) {
@@ -73,7 +77,7 @@ class Matrix
public function getTranspose()
{
// Just flip everything
$transposeMatrix = array();
$transposeMatrix = [];
$rowMatrixData = $this->_matrixRowData;
for ($currentRowTransposeMatrix = 0;
@@ -98,8 +102,8 @@ class Matrix
public function getDeterminant()
{
// Basic argument checking
if (!$this->isSquare()) {
throw new Exception("Matrix must be square!");
if (! $this->isSquare()) {
throw new Exception('Matrix must be square!');
}
if ($this->_rowCount == 1) {
@@ -117,6 +121,7 @@ class Matrix
$b = $this->_matrixRowData[0][1];
$c = $this->_matrixRowData[1][0];
$d = $this->_matrixRowData[1][1];
return $a * $d - $b * $c;
}
@@ -141,8 +146,8 @@ class Matrix
public function getAdjugate()
{
if (!$this->isSquare()) {
throw new Exception("Matrix must be square!");
if (! $this->isSquare()) {
throw new Exception('Matrix must be square!');
}
// See http://en.wikipedia.org/wiki/Adjugate_matrix
@@ -165,7 +170,7 @@ class Matrix
}
// The idea is that it's the transpose of the cofactors
$result = array();
$result = [];
for ($currentColumn = 0; $currentColumn < $this->_columnCount; $currentColumn++) {
for ($currentRow = 0; $currentRow < $this->_rowCount; $currentRow++) {
@@ -194,7 +199,7 @@ class Matrix
{
$rows = $matrix->getRowCount();
$columns = $matrix->getColumnCount();
$newValues = array();
$newValues = [];
for ($currentRow = 0; $currentRow < $rows; $currentRow++) {
for ($currentColumn = 0; $currentColumn < $columns; $currentColumn++) {
@@ -212,12 +217,12 @@ class Matrix
||
($left->getColumnCount() != $right->getColumnCount())
) {
throw new Exception("Matrices must be of the same size");
throw new Exception('Matrices must be of the same size');
}
// simple addition of each item
$resultMatrix = array();
$resultMatrix = [];
for ($currentRow = 0; $currentRow < $left->getRowCount(); $currentRow++) {
for ($currentColumn = 0; $currentColumn < $right->getColumnCount(); $currentColumn++) {
@@ -237,13 +242,13 @@ class Matrix
// See http://en.wikipedia.org/wiki/Matrix_multiplication for details
if ($left->getColumnCount() != $right->getRowCount()) {
throw new Exception("The width of the left matrix must match the height of the right matrix");
throw new Exception('The width of the left matrix must match the height of the right matrix');
}
$resultRows = $left->getRowCount();
$resultColumns = $right->getColumnCount();
$resultMatrix = array();
$resultMatrix = [];
for ($currentRow = 0; $currentRow < $resultRows; $currentRow++) {
for ($currentColumn = 0; $currentColumn < $resultColumns; $currentColumn++) {
@@ -268,7 +273,7 @@ class Matrix
// See http://en.wikipedia.org/wiki/Minor_(linear_algebra)
// I'm going to use a horribly naïve algorithm... because I can :)
$result = array();
$result = [];
$actualRow = 0;
@@ -334,4 +339,4 @@ class Matrix
return true;
}
}
}