@@ -24,10 +24,14 @@ discard block |
||
24 | 24 | public static function submatrix($matrix, $columns) |
25 | 25 | { |
26 | 26 | $n = count($matrix); |
27 | - if ($n == 0) return []; |
|
27 | + if ($n == 0) { |
|
28 | + return []; |
|
29 | + } |
|
28 | 30 | |
29 | 31 | $m = count($matrix[0]); |
30 | - if ($m == 0) return $matrix; |
|
32 | + if ($m == 0) { |
|
33 | + return $matrix; |
|
34 | + } |
|
31 | 35 | |
32 | 36 | $result = []; |
33 | 37 | for ($i=0; $i<$n; $i++) { |
@@ -47,7 +51,9 @@ discard block |
||
47 | 51 | public static function toSquareMatrix($matrix, $ncol, $mcol, $vcol, $sparse = False) |
48 | 52 | { |
49 | 53 | $n = count($matrix); |
50 | - if ($n == 0) return []; |
|
54 | + if ($n == 0) { |
|
55 | + return []; |
|
56 | + } |
|
51 | 57 | |
52 | 58 | $labels = []; |
53 | 59 | $id = 0; |
@@ -64,7 +70,9 @@ discard block |
||
64 | 70 | $val = $matrix[$i][$vcol]; |
65 | 71 | $data[] = [$nid, $mid, $val]; |
66 | 72 | } |
67 | - if ($sparse) return ["data" => $data, "labels" => $labels]; |
|
73 | + if ($sparse) { |
|
74 | + return ["data" => $data, "labels" => $labels]; |
|
75 | + } |
|
68 | 76 | $nlab = count($labels); |
69 | 77 | $result = []; |
70 | 78 | for ($i=0; $i<$nlab; $i++) { |
@@ -84,7 +92,9 @@ discard block |
||
84 | 92 | { |
85 | 93 | $result = []; |
86 | 94 | $n = count($matrix1); |
87 | - if ($n != count($matrix2)) throw new \Exception("Summing non compatible matrices. "); |
|
95 | + if ($n != count($matrix2)) { |
|
96 | + throw new \Exception("Summing non compatible matrices. "); |
|
97 | + } |
|
88 | 98 | $m = count($matrix1[0]); |
89 | 99 | for ($i=0;$i<$n;$i++) { |
90 | 100 | $tmp = []; |
@@ -107,7 +117,9 @@ discard block |
||
107 | 117 | $n2 = count($matrix2); |
108 | 118 | $m2 = count($matrix2[0]); |
109 | 119 | |
110 | - if ($n2 !== $m1) throw new \Exception("Incompatible matrices: matrix1.columns != matrix2.rows"); |
|
120 | + if ($n2 !== $m1) { |
|
121 | + throw new \Exception("Incompatible matrices: matrix1.columns != matrix2.rows"); |
|
122 | + } |
|
111 | 123 | |
112 | 124 | $result = []; |
113 | 125 | for ($i=0; $i<$n1; $i++) { |
@@ -154,9 +166,13 @@ discard block |
||
154 | 166 | */ |
155 | 167 | public static function power($matrix, $n) |
156 | 168 | { |
157 | - if($n <= 1) return $matrix; |
|
169 | + if($n <= 1) { |
|
170 | + return $matrix; |
|
171 | + } |
|
158 | 172 | $resp = self::multiply($matrix, $matrix); |
159 | - if($n == 2) return $resp; |
|
173 | + if($n == 2) { |
|
174 | + return $resp; |
|
175 | + } |
|
160 | 176 | for($i=2; $i<$n; $i++) { |
161 | 177 | $resp = self::multiply($resp, $matrix); |
162 | 178 | } |
@@ -179,7 +179,9 @@ |
||
179 | 179 | $resp = []; |
180 | 180 | foreach ($tests as $test) { |
181 | 181 | $counts = self::getCountsById($pdo, $config, $test[0]); |
182 | - if (count($counts) > 0) $resp[] = $counts; |
|
182 | + if (count($counts) > 0) { |
|
183 | + $resp[] = $counts; |
|
184 | + } |
|
183 | 185 | } |
184 | 186 | return $resp; |
185 | 187 | } |
@@ -179,8 +179,7 @@ discard block |
||
179 | 179 | |
180 | 180 | if (array_key_exists("level", $options)) { |
181 | 181 | $level = $options["level"]; |
182 | - } |
|
183 | - else { |
|
182 | + } else { |
|
184 | 183 | $level = count($labels) - 1; |
185 | 184 | } |
186 | 185 | |
@@ -212,8 +211,7 @@ discard block |
||
212 | 211 | |
213 | 212 | if (array_key_exists("level", $options)) { |
214 | 213 | $level = $options["level"]; |
215 | - } |
|
216 | - else { |
|
214 | + } else { |
|
217 | 215 | $level = count($labels) - 1; |
218 | 216 | } |
219 | 217 |
@@ -31,7 +31,9 @@ |
||
31 | 31 | $niter = 0; |
32 | 32 | $maxiter = 100; |
33 | 33 | $npoints = count($data); |
34 | - if ($npoints <= 0) throw new \Exception("Not enough data. "); |
|
34 | + if ($npoints <= 0) { |
|
35 | + throw new \Exception("Not enough data. "); |
|
36 | + } |
|
35 | 37 | $ndimensions = count($data[0]); |
36 | 38 | $centroids = []; |
37 | 39 | for ($i=0;$i<$nclusters;$i++){ |