Baunsgaard commented on code in PR #1843:
URL: https://github.com/apache/systemds/pull/1843#discussion_r1231986836


##########
src/main/java/org/apache/sysds/utils/NativeHelper.java:
##########
@@ -416,4 +416,7 @@ public static native boolean conv2dSparse(int apos, int 
alen, int[] aix, double[
        // different tradeoffs. In current implementation, we always use 
GetPrimitiveArrayCritical as it has proven to be
        // fastest. We can revisit this decision later and hence I would not 
recommend removing this method.
        private static native void setMaxNumThreads(int numThreads);
+
+       //test interface for native binding

Review Comment:
   it is not a test inteface anymore, 
   please write a full Javadoc definition using:
   
   /** */



##########
src/test/java/org/apache/sysds/test/functions/native/NativeBindingTestWithDgemm.java:
##########
@@ -0,0 +1,74 @@
+import java.util.Random;
+import org.apache.sysds.utils.NativeHelper;
+
+public class NativeBindingTestWithDgemm {
+    static {
+        System.loadLibrary("systemds_mkl-Darwin-x86_64");
+    }
+    // Helper method to flatten a 2D matrix into a 1D array
+    private double[] flattenMatrix(double[][] matrix) {
+        int rows = matrix.length;
+        int columns = matrix[0].length;
+        double[] flattened = new double[rows * columns];
+
+        for (int i = 0; i < rows; i++) {
+            for (int j = 0; j < columns; j++) {
+                flattened[i * columns + j] = matrix[i][j];
+            }
+        }
+
+        return flattened;
+    }
+
+    // Helper method to generate a random matrix
+    private double[][] generateRandomMatrix(int rows, int columns) {
+        Random random = new Random();
+        double[][] matrix = new double[rows][columns];
+
+        for (int i = 0; i < rows; i++) {
+            for (int j = 0; j < columns; j++) {
+                matrix[i][j] = random.nextDouble();
+            }
+        }
+
+        return matrix;
+    }
+
+    // Method to test the dgemm function
+    public void testDgemm() {
+        char transa = 'N';
+        char transb = 'N';
+        int m = 2000;
+        int n = 200;
+        int k = 1000;
+        double alpha = 1.0;
+        double beta = 0.0;
+
+        // Generate random input matrices A, B, and C
+        double[][] A = generateRandomMatrix(m, k);
+        double[][] B = generateRandomMatrix(k, n);
+        double[][] C = new double[m][n];
+
+        // Convert matrices to 1D arrays
+        double[] flatA = flattenMatrix(A);
+        double[] flatB = flattenMatrix(B);
+        double[] flatC = flattenMatrix(C);
+
+        // Call the native dgemm method
+
+        NativeHelper.testNativeBindingWithDgemm(transa, transb, m, n, k, 
alpha, flatA, k, flatB, n, beta, flatC, n);
+
+        // Print the result matrix C
+        System.out.println("Result Matrix C:");
+        for (int i = 0; i < m; i++) {
+            for (int j = 0; j < n; j++) {
+                System.out.print(flatC[i * n + j] + " ");
+            }
+            System.out.println();

Review Comment:
   avoid printing in tests. 
   A general design for clean tests is to only print once something goes wrong. 
   you can imagine if we have a million tests that print. then we would not be 
able to decipher what is wrong or what is right. (and we would use all our time 
printing in the tests) 



##########
src/test/java/org/apache/sysds/test/functions/native/NativeBindingTestWithDgemm.java:
##########
@@ -0,0 +1,74 @@
+import java.util.Random;

Review Comment:
   license



##########
src/test/java/org/apache/sysds/test/functions/native/NativeBindingTestWithDgemm.java:
##########
@@ -0,0 +1,74 @@
+import java.util.Random;
+import org.apache.sysds.utils.NativeHelper;
+
+public class NativeBindingTestWithDgemm {
+    static {
+        System.loadLibrary("systemds_mkl-Darwin-x86_64");
+    }
+    // Helper method to flatten a 2D matrix into a 1D array
+    private double[] flattenMatrix(double[][] matrix) {
+        int rows = matrix.length;
+        int columns = matrix[0].length;
+        double[] flattened = new double[rows * columns];
+
+        for (int i = 0; i < rows; i++) {
+            for (int j = 0; j < columns; j++) {
+                flattened[i * columns + j] = matrix[i][j];
+            }
+        }
+
+        return flattened;
+    }
+
+    // Helper method to generate a random matrix
+    private double[][] generateRandomMatrix(int rows, int columns) {
+        Random random = new Random();
+        double[][] matrix = new double[rows][columns];
+
+        for (int i = 0; i < rows; i++) {
+            for (int j = 0; j < columns; j++) {
+                matrix[i][j] = random.nextDouble();
+            }
+        }
+
+        return matrix;
+    }
+
+    // Method to test the dgemm function
+    public void testDgemm() {
+        char transa = 'N';
+        char transb = 'N';
+        int m = 2000;
+        int n = 200;
+        int k = 1000;
+        double alpha = 1.0;
+        double beta = 0.0;
+
+        // Generate random input matrices A, B, and C
+        double[][] A = generateRandomMatrix(m, k);
+        double[][] B = generateRandomMatrix(k, n);
+        double[][] C = new double[m][n];
+
+        // Convert matrices to 1D arrays
+        double[] flatA = flattenMatrix(A);
+        double[] flatB = flattenMatrix(B);
+        double[] flatC = flattenMatrix(C);
+
+        // Call the native dgemm method
+
+        NativeHelper.testNativeBindingWithDgemm(transa, transb, m, n, k, 
alpha, flatA, k, flatB, n, beta, flatC, n);
+
+        // Print the result matrix C
+        System.out.println("Result Matrix C:");
+        for (int i = 0; i < m; i++) {
+            for (int j = 0; j < n; j++) {
+                System.out.print(flatC[i * n + j] + " ");
+            }
+            System.out.println();
+        }
+    }
+
+    public static void main(String[] args) {

Review Comment:
   you can leave this function for tests purposes, but ideally please integrate 
the test you make into JUnit.
   this is as simple as marking methods with \@ Test  See other files for 
examples.



##########
src/main/cpp/libAnish.cpp:
##########


Review Comment:
   for the future, if you have general comments i suggest you put them in the 
general comments, not as a comment on a comment like this. Thanks.



-- 
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.

To unsubscribe, e-mail: [email protected]

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

Reply via email to