Passed
Push — master ( 5e8c3b...31fead )
by Ruben
02:18
created
src/Matrix.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -24,13 +24,13 @@  discard block
 block discarded – undo
24 24
     public static function submatrix($matrix, $columns)
25 25
     {
26 26
         $n = count($matrix);
27
-        if ($n == 0) return [];
27
+        if ($n==0) return [];
28 28
        
29 29
         $m = count($matrix[0]);
30
-        if ($m == 0) return $matrix;
30
+        if ($m==0) return $matrix;
31 31
        
32 32
         $result = [];       
33
-        for ($i=0; $i<$n; $i++) {
33
+        for ($i = 0; $i < $n; $i++) {
34 34
             $tmp = [];
35 35
             foreach ($columns as $col) {
36 36
                 $tmp[] = $matrix[$i][$col];
@@ -47,12 +47,12 @@  discard block
 block discarded – undo
47 47
     public static function toSquareMatrix($matrix, $ncol, mcol, $val, $sparse = False)
48 48
     {
49 49
         $n = count($matrix);
50
-        if ($n == 0) return [];
50
+        if ($n==0) return [];
51 51
         
52 52
         $labels = {};
53 53
         $id = 0;
54 54
         $data = [];
55
-        for ($i=0; $i<$n; $i++) {              
55
+        for ($i = 0; $i < $n; $i++) {              
56 56
             $nid = $labels[$matrix[$i][$ncol]];                
57 57
             $mid = $labels[$matrix[$i][$mcol]];
58 58
             $val = $matrix[$i][$val];
@@ -62,11 +62,11 @@  discard block
 block discarded – undo
62 62
         
63 63
         $nlab = count($labels);
64 64
         $result = [];
65
-        for ($i=0; $i<$nlab; $i++) {           
65
+        for ($i = 0; $i < $nlab; $i++) {           
66 66
             $tmp = array_fill(0, $nlab, 0);
67 67
             $result[] = $tmp;
68 68
         }
69
-        for ($i=0; $i<$n; $i++) {           
69
+        for ($i = 0; $i < $n; $i++) {           
70 70
             $result[$data[0]][$data[1]] = $data[2];
71 71
         }
72 72
         return ["data" => $result, "labels" => $labels];
@@ -83,16 +83,16 @@  discard block
 block discarded – undo
83 83
         $n2 = count($matrix2);        
84 84
         $m2 = count($matrix2[0]);
85 85
         
86
-        if ($n2 !== $m1) throw new Exception("Incompatible matrices: matrix1.columns != matrix2.rows");
86
+        if ($n2!==$m1) throw new Exception("Incompatible matrices: matrix1.columns != matrix2.rows");
87 87
 
88 88
         $result = [];
89
-        for ($i=0; $i<$n1; $i++) {           
89
+        for ($i = 0; $i < $n1; $i++) {           
90 90
             $result[] = array_fill(0, $m2, 0);                    
91 91
         }
92
-        for ($i=0; $i<$n1; $i++) {
93
-            for ($j=0; $j<$m2; $j++) {
94
-                 for ($k=0; $k<$n2; $k++) {
95
-                     $result[$i][$j] += $matrix1[$i][$k]*$matrix2[$k][$j];
92
+        for ($i = 0; $i < $n1; $i++) {
93
+            for ($j = 0; $j < $m2; $j++) {
94
+                 for ($k = 0; $k < $n2; $k++) {
95
+                     $result[$i][$j] += $matrix1[$i][$k] * $matrix2[$k][$j];
96 96
                  }
97 97
             }
98 98
         }        
@@ -104,10 +104,10 @@  discard block
 block discarded – undo
104 104
      */
105 105
     public static function power($matrix, $n)
106 106
     {
107
-        if($n <= 1) return $matrix;        
107
+        if ($n <= 1) return $matrix;        
108 108
         $resp = multiply($matrix, $matrix);
109
-        if($n == 2) return $resp;
110
-        for($i=2; $i<$n; $i++) {
109
+        if ($n==2) return $resp;
110
+        for ($i = 2; $i < $n; $i++) {
111 111
             $resp = multiply($resp, $matrix);
112 112
         }
113 113
         return $resp;
Please login to merge, or discard this patch.