whirgod commented on a change in pull request #1275:
URL: https://github.com/apache/systemds/pull/1275#discussion_r633107021



##########
File path: src/test/java/org/apache/sysds/test/TestUtils.java
##########
@@ -3073,4 +3059,46 @@ public static int isGPUAvailable() {
                final int[] deviceCount = new int[1];
                return JCuda.cudaGetDeviceCount(deviceCount);
        }
+
+       public static double[][] convertMatrix(HashMap<MatrixValue.CellIndex, 
Double> m, int rows, int cols) {
+               double[][] res = new double[rows][cols];
+               m.forEach((k, v) -> res[k.row - 1][k.column - 1] = v);
+               return res;
+       }
+
+       public static HashMap<MatrixValue.CellIndex, Double> 
convertMatrix(double[][] m) {
+               HashMap<MatrixValue.CellIndex, Double> res = new 
HashMap<MatrixValue.CellIndex, Double>();
+               for (int r = 0; r < m.length; ++r) {
+                       double[] row = m[r];
+                       for (int c = 0; c < row.length; ++c) {
+                               res.put(new CellIndex(r + 1, c + 1), row[c]);
+                       }
+               }
+
+               return res;
+       }
+
+       /**
+        * Reads a matrix from a text file. Rows are separated by newline, 
Values are separated by space.
+        * Take from 
https://www.tutorialspoint.com/How-to-read-a-2d-array-from-a-file-in-java
+        * @param url URL to the resource file obtained by Class.getResource()
+        * @param rows The expected number of rows
+        * @param cols The expected number of columns
+        * @return The matrix
+        * @throws Exception

Review comment:
       Done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to