Skip to content

Commit 35a2d1a

Browse files
author
Mark Baker
authored
Return datatypes for decomposition methods (#10)
1 parent 130cba1 commit 35a2d1a

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

classes/src/Decomposition/LU.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function __construct(Matrix $matrix)
2626
*
2727
* @return Matrix Lower triangular factor
2828
*/
29-
public function getL()
29+
public function getL(): Matrix
3030
{
3131
$lower = [];
3232

@@ -51,7 +51,7 @@ public function getL()
5151
*
5252
* @return Matrix Upper triangular factor
5353
*/
54-
public function getU()
54+
public function getU(): Matrix
5555
{
5656
$upper = [];
5757

@@ -74,7 +74,7 @@ public function getU()
7474
*
7575
* @return Matrix Pivot matrix
7676
*/
77-
public function getP()
77+
public function getP(): Matrix
7878
{
7979
$pMatrix = [];
8080

@@ -93,7 +93,7 @@ public function getP()
9393
*
9494
* @return array Pivot vector
9595
*/
96-
public function getPivot()
96+
public function getPivot(): array
9797
{
9898
return $this->pivot;
9999
}
@@ -103,7 +103,7 @@ public function getPivot()
103103
*
104104
* @return bool true if U, and hence A, is nonsingular
105105
*/
106-
public function isNonsingular()
106+
public function isNonsingular(): bool
107107
{
108108
for ($diagonal = 0; $diagonal < $this->columns; ++$diagonal) {
109109
if ($this->luMatrix[$diagonal][$diagonal] === 0.0) {
@@ -114,7 +114,7 @@ public function isNonsingular()
114114
return true;
115115
}
116116

117-
private function buildPivot()
117+
private function buildPivot(): void
118118
{
119119
for ($row = 0; $row < $this->rows; ++$row) {
120120
$this->pivot[$row] = $row;
@@ -136,7 +136,7 @@ private function buildPivot()
136136
}
137137
}
138138

139-
private function localisedReferenceColumn($column)
139+
private function localisedReferenceColumn($column): array
140140
{
141141
$luColumn = [];
142142

@@ -147,7 +147,7 @@ private function localisedReferenceColumn($column)
147147
return $luColumn;
148148
}
149149

150-
private function applyTransformations($column, array $luColumn)
150+
private function applyTransformations($column, array $luColumn): void
151151
{
152152
for ($row = 0; $row < $this->rows; ++$row) {
153153
$luRow = $this->luMatrix[$row];
@@ -161,7 +161,7 @@ private function applyTransformations($column, array $luColumn)
161161
}
162162
}
163163

164-
private function findPivot($column, array $luColumn)
164+
private function findPivot($column, array $luColumn): int
165165
{
166166
$pivot = $column;
167167
for ($row = $column + 1; $row < $this->rows; ++$row) {
@@ -173,7 +173,7 @@ private function findPivot($column, array $luColumn)
173173
return $pivot;
174174
}
175175

176-
private function pivotExchange($pivot, $column)
176+
private function pivotExchange($pivot, $column): void
177177
{
178178
for ($kValue = 0; $kValue < $this->columns; ++$kValue) {
179179
$tValue = $this->luMatrix[$pivot][$kValue];
@@ -186,7 +186,7 @@ private function pivotExchange($pivot, $column)
186186
$this->pivot[$column] = $lValue;
187187
}
188188

189-
private function computeMultipliers($diagonal)
189+
private function computeMultipliers($diagonal): void
190190
{
191191
if (($diagonal < $this->rows) && ($this->luMatrix[$diagonal][$diagonal] != 0.0)) {
192192
for ($row = $diagonal + 1; $row < $this->rows; ++$row) {

classes/src/Decomposition/QR.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function __construct(Matrix $matrix)
2121
$this->decompose();
2222
}
2323

24-
public function getHouseholdVectors()
24+
public function getHouseholdVectors(): Matrix
2525
{
2626
$householdVectors = [];
2727
for ($row = 0; $row < $this->rows; ++$row) {
@@ -37,7 +37,7 @@ public function getHouseholdVectors()
3737
return new Matrix($householdVectors);
3838
}
3939

40-
public function getQ()
40+
public function getQ(): Matrix
4141
{
4242
$qGrid = [];
4343

@@ -76,7 +76,7 @@ function (&$row) use ($rowCount) {
7676
return new Matrix($qGrid);
7777
}
7878

79-
public function getR()
79+
public function getR(): Matrix
8080
{
8181
$rGrid = [];
8282

@@ -99,7 +99,7 @@ public function getR()
9999
return new Matrix($rGrid);
100100
}
101101

102-
private function hypo($a, $b)
102+
private function hypo($a, $b): float
103103
{
104104
if (abs($a) > abs($b)) {
105105
$r = $b / $a;
@@ -117,7 +117,7 @@ private function hypo($a, $b)
117117
/**
118118
* QR Decomposition computed by Householder reflections.
119119
*/
120-
private function decompose()
120+
private function decompose(): void
121121
{
122122
for ($k = 0; $k < $this->columns; ++$k) {
123123
// Compute 2-norm of k-th column without under/overflow.

0 commit comments

Comments
 (0)