This is an automated email from the ASF dual-hosted git repository.

mboehm7 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/systemds.git


The following commit(s) were added to refs/heads/main by this push:
     new 1406e7b000 [SYSTEMDS-3768] Fix mtx file header handling in java test
1406e7b000 is described below

commit 1406e7b00006f3bfd362df057b8d26aea2697364
Author: min-guk <[email protected]>
AuthorDate: Wed Sep 11 14:48:24 2024 +0200

    [SYSTEMDS-3768] Fix mtx file header handling in java test
    
    Closes #2104.
---
 src/test/java/org/apache/sysds/test/TestUtils.java | 25 +++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/src/test/java/org/apache/sysds/test/TestUtils.java 
b/src/test/java/org/apache/sysds/test/TestUtils.java
index b738040c8c..1a0cbdfa87 100644
--- a/src/test/java/org/apache/sysds/test/TestUtils.java
+++ b/src/test/java/org/apache/sysds/test/TestUtils.java
@@ -26,6 +26,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.FileReader;
+import java.io.RandomAccessFile;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.OutputStreamWriter;
@@ -578,6 +579,9 @@ public class TestUtils {
 
                        line = reader.readLine(); // header line with dimension 
and nnz information
 
+                       if (line.startsWith("%"))       // skip blank 
comment(%) line in mtx file
+                               line = reader.readLine();
+
                        while ((line = reader.readLine()) != null) {
                                StringTokenizer st = new StringTokenizer(line, 
" ");
                                int i = Integer.parseInt(st.nextToken());
@@ -2720,13 +2724,16 @@ public class TestUtils {
                                out = new DataOutputStream(new 
FileOutputStream(file));
                        }
 
+                       int non_zero_cnt = 0;
+
                        try( BufferedWriter pw = new BufferedWriter(new 
OutputStreamWriter(out))) {
 
-                               //write header
+                               //write dummy header
                                if( isR ) {
-                                       /** add R header */
+                                       /** add space for R header */
                                        pw.append("%%MatrixMarket matrix 
coordinate real general\n");
-                                       pw.append("" + matrix.length + " " + 
matrix[0].length + " " + matrix.length*matrix[0].length+"\n");
+                                       pw.append("" + matrix.length + " " + 
matrix[0].length + " " +
+                                                       " 
".repeat((String.valueOf(matrix.length * matrix[0].length)).length()) + "\n");
                                }
 
                                //writer actual matrix
@@ -2745,6 +2752,8 @@ public class TestUtils {
                                                pw.append(sb.toString());
                                                sb.setLength(0);
                                                emptyOutput = false;
+
+                                               non_zero_cnt++;
                                        }
                                }
 
@@ -2752,6 +2761,16 @@ public class TestUtils {
                                if( emptyOutput )
                                        pw.append("1 1 " + matrix[0][0]);
                        }
+
+                       //write real header
+                       if (isR) {
+                               try (RandomAccessFile raf = new 
RandomAccessFile(file, "rws")) {
+                                       raf.seek(0);
+
+                                       raf.write("%%MatrixMarket matrix 
coordinate real general\n".getBytes());
+                                       raf.write(("" + matrix.length + " " + 
matrix[0].length + " " + non_zero_cnt).getBytes());
+                               }
+                       }
                }
                catch (IOException e)
                {

Reply via email to