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

baunsgaard 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 3b48c4ae5b [SYSTEMDS-3545] Linearized Img Sample Shear & Rotate
3b48c4ae5b is described below

commit 3b48c4ae5b82ec8e44e1d9425a9a8662f755c2ba
Author: baristerzioglu <[email protected]>
AuthorDate: Fri Sep 8 12:53:15 2023 +0200

    [SYSTEMDS-3545] Linearized Img Sample Shear & Rotate
    
    This commit merge the remaining linearized image operations
    from #1914 #1913 and #1912
    
    It contains the combination of image sample shear and rotate.
    The commit is combined since the three PRs does not clearly
    separate the changed files.
    
    LDE Project SoSe 2023
    
    Co-authored-by: baristerzioglu <[email protected]>
    Co-authored-by: slnkahveci <[email protected]>
    
    Closes #1914 #1913 #1912 #1965
---
 scripts/builtin/img_rotate_linearized.dml          |  62 ++++++
 scripts/builtin/img_sample_pairing_linearized.dml  |  48 +++++
 scripts/builtin/img_shear_linearized.dml           |  40 ++++
 scripts/builtin/img_transform_linearized.dml       |   3 -
 .../java/org/apache/sysds/common/Builtins.java     |   3 +
 .../BuiltinImageSamplePairingLinearizedTest.java   | 106 ++++++++++
 .../pipelines/BuiltinImageRotateLinTest.java       | 116 +++++++++++
 .../pipelines/BuiltinImageShearLinTest.java        | 122 ++++++++++++
 .../pipelines/BuiltinImageTransformLinTest.java    | 218 ++++++++++-----------
 .../expected/ImageTransformLinRotated.csv          |   1 +
 .../expected/ImageTransformLinTransformed.csv      |   1 -
 .../functions/builtin/image_rotate_linearized.dml  |  33 ++++
 .../builtin/image_sample_pairing_linearized.dml    |  37 ++++
 .../functions/builtin/image_shear_linearized.dml   |  34 ++++
 .../functions/builtin/image_transform_linearized.R |   1 +
 15 files changed, 711 insertions(+), 114 deletions(-)

diff --git a/scripts/builtin/img_rotate_linearized.dml 
b/scripts/builtin/img_rotate_linearized.dml
new file mode 100644
index 0000000000..f5ac43625d
--- /dev/null
+++ b/scripts/builtin/img_rotate_linearized.dml
@@ -0,0 +1,62 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+# The Linearized Image Rotate function rotates the linearized input images 
counter-clockwise around the center.
+# Uses nearest neighbor sampling.
+#
+# INPUT:
+# 
-----------------------------------------------------------------------------------------------
+# img_in      Linearized input images as 2D matrix with top left corner at [1, 
1]
+# radians     The value by which to rotate in radian.
+# fill_value   The background color revealed by the rotation
+# 
-----------------------------------------------------------------------------------------------
+#
+# OUTPUT:
+# 
---------------------------------------------------------------------------------------------
+# img_out   Output images in linearized form as 2D matrix with top left corner 
at [1, 1]
+# 
---------------------------------------------------------------------------------------------
+
+m_img_rotate_linearized = function(Matrix[Double] img_in, Double radians, 
Double fill_value, Integer s_cols, Integer s_rows) return (Matrix[Double] 
img_out) {
+  # Translation matrix for moving the origin to the center of the image
+  t1 = matrix("1 0 0 0 1 0 0 0 1", rows=3, cols=3)
+  t1[1, 3] = -s_cols / 2
+  t1[2, 3] = -s_rows / 2
+
+  # Translation matrix for moving the origin back to the top left corner
+  t2 = matrix("1 0 0 0 1 0 0 0 1", rows=3, cols=3)
+  t2[1, 3] = s_cols / 2
+  t2[2, 3] = s_rows / 2
+
+  # The rotation matrix around the origin
+  rot = matrix("1 0 0 0 1 0 0 0 1", rows=3, cols=3)
+  c = cos(radians)
+  s = sin(radians)
+  rot[1, 1] = c
+  rot[1, 2] = s
+  rot[2, 1] = -s
+  rot[2, 2] = c
+
+  # Combined transformation matrix
+  m = t2 %*% rot %*% t1
+
+  # Transform image
+  img_out = img_transform_linearized(img_in, s_cols, s_rows, 
as.scalar(m[1,1]), as.scalar(m[1,2]), as.scalar(m[1,3]), as.scalar(m[2,1]), 
as.scalar(m[2,2]), as.scalar(m[2,3]), fill_value, s_cols, s_rows)
+}
diff --git a/scripts/builtin/img_sample_pairing_linearized.dml 
b/scripts/builtin/img_sample_pairing_linearized.dml
new file mode 100644
index 0000000000..f09046cc18
--- /dev/null
+++ b/scripts/builtin/img_sample_pairing_linearized.dml
@@ -0,0 +1,48 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+# The image sample pairing function blends two images together.
+#
+# INPUT:
+# 
-------------------------------------------------------------------------------------------
+# img_in1  input matrix/image (every row is a linearized image)
+# img_in2  Second input image (one image represented as a single row 
linearized matrix)
+# weight   The weight given to the second image.
+#          0 means only img_in1, 1 means only img_in2 will be visible
+# 
-------------------------------------------------------------------------------------------
+#
+# OUTPUT:
+# 
--------------------------------------------------------------------------------------------
+# img_out  Output image
+# 
--------------------------------------------------------------------------------------------
+
+m_img_sample_pairing_linearized= function(Matrix[Double] img_in1, 
Matrix[Double] img_in2, Double weight) return (Matrix[Double] img_out) {
+  if (weight < 0 | 1 < weight) {
+    print("Invalid weight. Set weight to 0.5")
+    weight = 0.5
+  }
+  num_images= nrow(img_in1)
+  img_out = matrix (0 ,rows=nrow(img_in1),cols=ncol(img_in2))
+  parfor(i in 1:num_images) {
+    img_out[i,] = (1 - weight) * img_in1[i,]+ weight * img_in2
+  }
+ 
+}
diff --git a/scripts/builtin/img_shear_linearized.dml 
b/scripts/builtin/img_shear_linearized.dml
new file mode 100644
index 0000000000..79471f358b
--- /dev/null
+++ b/scripts/builtin/img_shear_linearized.dml
@@ -0,0 +1,40 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+# This function applies a shearing transformation to linearized images.
+# Uses nearest neighbor sampling.
+#
+# INPUT:
+# 
---------------------------------------------------------------------------------------------
+# img_in      Linearized input images as 2D matrix with top left corner at [1, 
1]
+# shear_x     Shearing factor for horizontal shearing
+# shear_y     Shearing factor for vertical shearing
+# fill_value   The background color revealed by the shearing
+# 
---------------------------------------------------------------------------------------------
+#
+# OUTPUT:
+# 
------------------------------------------------------------------------------------------
+# img_out     Output images in linearized form as 2D matrix with top left 
corner at [1, 1]
+# 
------------------------------------------------------------------------------------------
+
+m_img_shear_linearized = function(Matrix[Double] img_in, Double shear_x, 
Double shear_y, Double fill_value, Integer s_cols, Integer s_rows) return 
(Matrix[Double] img_out) {
+  img_out = img_transform_linearized(img_in, s_cols, s_rows, 1, shear_x, 0, 
shear_y, 1, 0, fill_value, s_cols, s_rows)
+}
diff --git a/scripts/builtin/img_transform_linearized.dml 
b/scripts/builtin/img_transform_linearized.dml
index e351c4cf7c..06867d61b2 100644
--- a/scripts/builtin/img_transform_linearized.dml
+++ b/scripts/builtin/img_transform_linearized.dml
@@ -68,9 +68,6 @@ m_img_transform_linearized = function(Matrix[Double] img_in, 
Integer out_w, Inte
     # compute sampling pixel indices
     coords = floor(T_inv %*% coords) + 1
 
-    # fill output image
-    img_out = matrix(fill_value, rows=nrow(img_in), cols=out_w*out_h)
-
     inx = t(coords[1,])
     iny = t(coords[2,])
 
diff --git a/src/main/java/org/apache/sysds/common/Builtins.java 
b/src/main/java/org/apache/sysds/common/Builtins.java
index f8377ce1ed..3dae7a80ae 100644
--- a/src/main/java/org/apache/sysds/common/Builtins.java
+++ b/src/main/java/org/apache/sysds/common/Builtins.java
@@ -165,10 +165,13 @@ public enum Builtins {
        IMG_TRANSLATE("img_translate", true),
        IMG_TRANSLATE_LINEARIZED("img_translate_linearized", true),
        IMG_ROTATE("img_rotate", true),
+       IMG_ROTATE_LINEARIZED("img_rotate_linearized", true),
        IMG_SHEAR("img_shear", true),
+       IMG_SHEAR_LINEARIZED("img_shear_linearized", true),
        IMG_CUTOUT("img_cutout", true),
        IMG_CUTOUT_LINEARIZED("img_cutout_linearized", true),
        IMG_SAMPLE_PAIRING("img_sample_pairing", true),
+       IMG_SAMPLE_PAIRING_LINEARIZED("img_sample_pairing_linearized", true),
        IMG_INVERT("img_invert", true),
        IMG_INVERT_LINEARIZED("img_invert_linearized", true),
        IMG_POSTERIZE("img_posterize", true),
diff --git 
a/src/test/java/org/apache/sysds/test/functions/builtin/part1/BuiltinImageSamplePairingLinearizedTest.java
 
b/src/test/java/org/apache/sysds/test/functions/builtin/part1/BuiltinImageSamplePairingLinearizedTest.java
new file mode 100644
index 0000000000..5cfe345747
--- /dev/null
+++ 
b/src/test/java/org/apache/sysds/test/functions/builtin/part1/BuiltinImageSamplePairingLinearizedTest.java
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sysds.test.functions.builtin.part1;
+
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.apache.sysds.common.Types.ExecMode;
+import org.apache.sysds.common.Types.ExecType;
+import org.apache.sysds.runtime.matrix.data.MatrixValue;
+import org.apache.sysds.test.AutomatedTestBase;
+import org.apache.sysds.test.TestConfiguration;
+import org.apache.sysds.test.TestUtils;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+
+@RunWith(Parameterized.class)
[email protected]
+public class BuiltinImageSamplePairingLinearizedTest extends AutomatedTestBase 
{
+
+    private final static String TEST_NAME_LINEARIZED = 
"image_sample_pairing_linearized";
+    private final static String TEST_DIR = "functions/builtin/";
+    private final static String TEST_CLASS_DIR = TEST_DIR + 
BuiltinImageSamplePairingLinearizedTest.class.getSimpleName() + "/";
+    private final static double eps = 1e-10;
+    private final static double spSparse = 0.05; 
+    private final static double spDense = 0.5; 
+
+    @Parameterized.Parameter()
+    public int value;
+    
+    @Parameterized.Parameters
+    public static Collection<Object[]> data() {
+        return Arrays.asList(new Object[][] {
+          {10},
+          {-5},
+           {3}
+        });
+    }
+
+    @Override
+    public void setUp() {
+
+        addTestConfiguration(TEST_NAME_LINEARIZED, new 
TestConfiguration(TEST_CLASS_DIR, TEST_NAME_LINEARIZED, new String[]{"B_x"}));
+    }
+
+    @Test
+    public void testImageSamplePairingLinearized() {
+        runImageSamplePairingLinearizedTest(false, ExecType.CP);
+    }
+
+    private void runImageSamplePairingLinearizedTest(boolean sparse, ExecType 
instType) {
+        ExecMode platformOld = setExecMode(instType);
+        disableOutAndExpectedDeletion();
+
+        try {
+            loadTestConfiguration(getTestConfiguration(TEST_NAME_LINEARIZED));
+
+            double sparsity = sparse ? spSparse : spDense;
+            String HOME = SCRIPT_DIR + TEST_DIR;
+
+            fullDMLScriptName = HOME + TEST_NAME_LINEARIZED + ".dml";
+            programArgs = new String[]{"-nvargs",
+                 "in_file=" + input("A"), 
+                 "in_file_second=" + input("secondMatrix"),
+                 "x_out_reshape_file=" + output("B_x_reshape"), 
+                 "x_out_file=" + output("B_x"),
+                 "value=" +value
+            };
+
+            double[][] A = getRandomMatrix(100,50, 0, 255, sparsity, 7);
+            double[][] secondMatrix = getRandomMatrix(1,50, 0, 255, sparsity, 
7);
+            writeInputMatrixWithMTD("A", A, true);
+            writeInputMatrixWithMTD("secondMatrix", secondMatrix, true);
+            runTest(true, false, null, -1);
+
+            HashMap<MatrixValue.CellIndex, Double> dmlfileLinearizedX = 
readDMLMatrixFromOutputDir("B_x");
+
+            HashMap<MatrixValue.CellIndex, Double> dmlfileX = 
readDMLMatrixFromOutputDir("B_x_reshape");
+
+            TestUtils.compareMatrices(dmlfileLinearizedX, dmlfileX, eps, 
"Stat-DML-LinearizedX", "Stat-DML-X");
+
+
+        } finally {
+            rtplatform = platformOld;
+        }
+    }
+}
diff --git 
a/src/test/java/org/apache/sysds/test/functions/pipelines/BuiltinImageRotateLinTest.java
 
b/src/test/java/org/apache/sysds/test/functions/pipelines/BuiltinImageRotateLinTest.java
new file mode 100644
index 0000000000..6a7e02a82f
--- /dev/null
+++ 
b/src/test/java/org/apache/sysds/test/functions/pipelines/BuiltinImageRotateLinTest.java
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sysds.test.functions.pipelines;
+
+import org.apache.sysds.runtime.matrix.data.MatrixValue;
+import org.apache.sysds.test.AutomatedTestBase;
+import org.apache.sysds.test.TestConfiguration;
+import org.apache.sysds.test.TestUtils;
+import org.junit.Test;
+
+import java.util.HashMap;
+
+public class BuiltinImageRotateLinTest extends AutomatedTestBase {
+       private final static String TEST_NAME = "image_rotate_linearized";
+       private final static String TEST_DIR = "functions/builtin/";
+       private final static String TEST_CLASS_DIR = TEST_DIR + 
BuiltinImageRotateLinTest.class.getSimpleName() + "/";
+
+       private final static double eps = 1e-10;
+       private final static int s_rows = 135;
+       private final static int s_cols = 500;
+       private final static int n_imgs = 1;
+
+       private final static double angle = 42 * (Math.PI / 180);
+
+       @Override
+       public void setUp() {
+               addTestConfiguration(TEST_NAME, new 
TestConfiguration(TEST_CLASS_DIR, TEST_NAME, new String[] { "B" }));
+       }
+
+       @Test
+       public void testImageRotateLinZero() throws Exception {
+               loadTestConfiguration(getTestConfiguration(TEST_NAME));
+               setOutputBuffering(true);
+               final int w = 500, h = 135;
+               final double fill_value = 128.0;
+               double[][] input = 
TestUtils.readExpectedResource("ImageTransformLinInput.csv", n_imgs, h * w);
+               double[][] reference = input;
+               String HOME = SCRIPT_DIR + TEST_DIR;
+               fullDMLScriptName = HOME + TEST_NAME + ".dml";
+               programArgs = new String[] { "-nvargs", "in_file=" + 
input("A"), "out_file=" + output("B"),
+                               "width=" + s_rows * s_cols,
+                               "height=" + n_imgs, "angle=" + 0, "fill_value=" 
+ fill_value, "s_cols=" + s_cols, "s_rows=" + s_rows };
+               writeInputMatrixWithMTD("A", input, true);
+               runTest(true, false, null, -1);
+
+               HashMap<MatrixValue.CellIndex, Double> dmlfile = 
readDMLMatrixFromOutputDir("B");
+               double[][] dml_res = 
TestUtils.convertHashMapToDoubleArray(dmlfile, n_imgs, h * w);
+               TestUtils.compareMatrices(reference, dml_res, eps, "Input vs. 
DML");
+       }
+
+       @Test
+       public void testImageRotateLinComplete() throws Exception {
+               loadTestConfiguration(getTestConfiguration(TEST_NAME));
+               setOutputBuffering(true);
+               final int w = 500, h = 135;
+               final double fill_value = 128.0;
+               double[][] input = 
TestUtils.readExpectedResource("ImageTransformLinInput.csv", n_imgs, h * w);
+               double[][] reference = input;
+               String HOME = SCRIPT_DIR + TEST_DIR;
+               fullDMLScriptName = HOME + TEST_NAME + ".dml";
+               programArgs = new String[] { "-nvargs", "in_file=" + 
input("A"), "out_file=" + output("B"),
+                               "width=" + s_rows * s_cols,
+                               "height=" + n_imgs, "angle=" + (2 * Math.PI), 
"fill_value=" + fill_value, "s_cols=" + s_cols,
+                               "s_rows=" + s_rows };
+               writeInputMatrixWithMTD("A", input, true);
+               runTest(true, false, null, -1);
+
+               HashMap<MatrixValue.CellIndex, Double> dmlfile = 
readDMLMatrixFromOutputDir("B");
+               double[][] dml_res = 
TestUtils.convertHashMapToDoubleArray(dmlfile, n_imgs, h * w);
+               TestUtils.compareMatrices(reference, dml_res, eps, "Input vs. 
DML");
+       }
+
+       @Test
+       public void testImageRotateLinPillow() throws Exception {
+               loadTestConfiguration(getTestConfiguration(TEST_NAME));
+               setOutputBuffering(true);
+               final int w = 500, h = 135;
+               final double fill_value = 128.0;
+               double[][] input = 
TestUtils.readExpectedResource("ImageTransformLinInput.csv", n_imgs, h * w);
+               double[][] reference = 
TestUtils.readExpectedResource("ImageTransformLinRotated.csv", n_imgs, h * w);
+               String HOME = SCRIPT_DIR + TEST_DIR;
+               fullDMLScriptName = HOME + TEST_NAME + ".dml";
+               programArgs = new String[] { "-nvargs", "in_file=" + 
input("A"), "out_file=" + output("B"),
+                               "width=" + s_rows * s_cols,
+                               "height=" + n_imgs, "angle=" + angle, 
"fill_value=" + fill_value, "s_cols=" + s_cols,
+                               "s_rows=" + s_rows };
+               writeInputMatrixWithMTD("A", input, true);
+               runTest(true, false, null, -1);
+
+               HashMap<MatrixValue.CellIndex, Double> dmlfile = 
readDMLMatrixFromOutputDir("B");
+               double[][] dml_res = 
TestUtils.convertHashMapToDoubleArray(dmlfile, n_imgs, h * w);
+               TestUtils.compareMatrices(reference, dml_res, eps, "Pillow vs. 
DML");
+               // The error here seems to be in the pillow implementation. It 
calculates that
+               // the source coordinates of
+               // (339, 14) are (351, 87) using fixed point arithmetic, while 
the floating
+               // point implementation returns
+               // (351.975384 88.000514) rounded down to (351, 88). (All 
indices here start at
+               // 0)
+       }
+}
diff --git 
a/src/test/java/org/apache/sysds/test/functions/pipelines/BuiltinImageShearLinTest.java
 
b/src/test/java/org/apache/sysds/test/functions/pipelines/BuiltinImageShearLinTest.java
new file mode 100644
index 0000000000..0e07634102
--- /dev/null
+++ 
b/src/test/java/org/apache/sysds/test/functions/pipelines/BuiltinImageShearLinTest.java
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sysds.test.functions.pipelines;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+
+import org.apache.sysds.common.Types.ExecMode;
+import org.apache.sysds.common.Types.ExecType;
+import org.apache.sysds.runtime.matrix.data.MatrixValue;
+import org.apache.sysds.test.AutomatedTestBase;
+import org.apache.sysds.test.TestConfiguration;
+import org.apache.sysds.test.TestUtils;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
[email protected]
+
+public class BuiltinImageShearLinTest extends AutomatedTestBase {
+       private final static String TEST_NAME = "image_shear_linearized";
+       private final static String TEST_DIR = "functions/builtin/";
+       private final static String TEST_CLASS_DIR = TEST_DIR + 
BuiltinImageShearLinTest.class.getSimpleName() + "/";
+
+       private final static double eps = 1e-10;
+       private final static double spSparse = 0.1;
+       private final static double spDense = 0.9;
+       /*
+        * private final static int s_rows = 200; private final static int 
s_cols = 120; private final static int n_imgs = 5;
+        * 
+        * private final static double shearX = 0.0; private final static 
double shearY = 0.2; private final static double
+        * fill_value = 128.0;
+        */
+       @Parameterized.Parameter(0)
+       public int s_rows;
+       @Parameterized.Parameter(1)
+       public int s_cols;
+       @Parameterized.Parameter(2)
+       public int n_imgs;
+       @Parameterized.Parameter(3)
+       public double shearX;
+       @Parameterized.Parameter(4)
+       public double shearY;
+       @Parameterized.Parameter(5)
+       public double fill_value;
+
+       @Parameterized.Parameters
+       public static Collection<Object[]> data() {
+               return Arrays.asList(new Object[][] {{16, 15, 200, 0.0, 0.7, 
255.0}, {31, 32, 100, 0.9, -0.2, 0.0},
+                       {64, 64, 100, -0.3, 0.01, 50.0}, {128, 127, 100, 0.0, 
0.55, 80.0}, {256, 256, 100, 0.11, 0.0, 25.0}
+
+               });
+       }
+
+       @Override
+       public void setUp() {
+               addTestConfiguration(TEST_NAME, new 
TestConfiguration(TEST_CLASS_DIR, TEST_NAME, new String[] {"B"}));
+       }
+
+       @Test
+       public void testImageShearLinDenseCP() {
+               runImageShearLinTest(false, ExecType.CP);
+       }
+
+       @Test
+       public void testImageShearLinSparseCP() {
+               runImageShearLinTest(true, ExecType.CP);
+       }
+
+       private void runImageShearLinTest(boolean sparse, ExecType instType) {
+               ExecMode platformOld = setExecMode(instType);
+               disableOutAndExpectedDeletion();
+
+               try {
+                       loadTestConfiguration(getTestConfiguration(TEST_NAME));
+                       double sparsity = sparse ? spSparse : spDense;
+
+                       String HOME = SCRIPT_DIR + TEST_DIR;
+                       fullDMLScriptName = HOME + TEST_NAME + ".dml";
+                       programArgs = new String[] {"-nvargs", "in_file=" + 
input("A"), "out_file=" + output("B"),
+                               "width=" + s_cols * s_rows, "height=" + n_imgs, 
"shear_x=" + shearX, "shear_y=" + shearY,
+                               "fill_value=" + fill_value, "s_cols=" + s_cols, 
"s_rows=" + s_rows};
+
+                       double[][] A = getRandomMatrix(n_imgs, s_rows * s_cols, 
0, 255, sparsity, 7);
+                       writeInputMatrixWithMTD("A", A, true);
+
+                       fullRScriptName = HOME + "image_transform_linearized.R";
+                       rCmd = "Rscript" + " " + fullRScriptName + " " + 
inputDir() + " " + expectedDir() + " " + s_cols * s_rows + " "
+                               + n_imgs + " " + s_cols + " " + s_rows + " " + 
1 + " " + shearX + " " + 0 + " " + shearY + " " + 1 + " " + 0
+                               + " " + fill_value + " " + s_cols + " " + 
s_rows;
+
+                       runTest(true, false, null, -1);
+                       runRScript(true);
+
+                       HashMap<MatrixValue.CellIndex, Double> dmlfile = 
readDMLMatrixFromOutputDir("B");
+                       HashMap<MatrixValue.CellIndex, Double> rfile = 
readRMatrixFromExpectedDir("B");
+                       TestUtils.compareMatrices(dmlfile, rfile, eps, 
"Stat-DML", "Stat-R");
+               }
+               finally {
+                       rtplatform = platformOld;
+               }
+       }
+
+}
diff --git 
a/src/test/java/org/apache/sysds/test/functions/pipelines/BuiltinImageTransformLinTest.java
 
b/src/test/java/org/apache/sysds/test/functions/pipelines/BuiltinImageTransformLinTest.java
index 8448af7262..fcecea85db 100644
--- 
a/src/test/java/org/apache/sysds/test/functions/pipelines/BuiltinImageTransformLinTest.java
+++ 
b/src/test/java/org/apache/sysds/test/functions/pipelines/BuiltinImageTransformLinTest.java
@@ -18,128 +18,126 @@
  */
 package org.apache.sysds.test.functions.pipelines;
 
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+
 import org.apache.sysds.common.Types.ExecMode;
 import org.apache.sysds.common.Types.ExecType;
 import org.apache.sysds.runtime.matrix.data.MatrixValue;
 import org.apache.sysds.test.AutomatedTestBase;
 import org.apache.sysds.test.TestConfiguration;
 import org.apache.sysds.test.TestUtils;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Arrays;
-
 @RunWith(Parameterized.class)
 @net.jcip.annotations.NotThreadSafe
 
 public class BuiltinImageTransformLinTest extends AutomatedTestBase {
-    private final static String TEST_NAME = "image_transform_linearized";
-    private final static String TEST_DIR = "functions/builtin/";
-    private final static String TEST_CLASS_DIR = TEST_DIR + 
BuiltinImageTransformLinTest.class.getSimpleName()
-            + "/";
-
-    private final static double eps = 1e-10;
-    private final static double spSparse = 0.1;
-    private final static double spDense = 0.9;
-    private final static double fill_value = 0.0;
-
-    @Parameterized.Parameter(0)
-    public int s_rows;
-    @Parameterized.Parameter(1)
-    public int s_cols;
-    @Parameterized.Parameter(2)
-    public int n_imgs;
-
-    public double a;
-    public double b;
-    public double c;
-    public double d;
-    public double e;
-    public double f;
-
-    @Parameterized.Parameters
-    public static Collection<Object[]> data() {
-        return Arrays.asList(new Object[][] {
-                { 16, 15, 50 },
-                { 32, 31, 100 },
-                { 64, 64, 200 },
-                { 127, 128, 100 },
-                { 256, 256, 200 },
-                { 500, 135, 100 }
-        });
-    }
-
-    @Override
-    public void setUp() {
-        // rotate 30 degrees around the center
-        a = Math.sqrt(3) / 2;
-        b = -1.0 / 2.0;
-        c = s_cols / 4.0 * (3 - Math.sqrt(3));
-        d = 1.0 / 2.0;
-        e = Math.sqrt(3) / 2;
-        f = s_rows / 4.0 * (1 - Math.sqrt(3));
-
-        addTestConfiguration(TEST_NAME, new TestConfiguration(TEST_CLASS_DIR, 
TEST_NAME, new String[] { "B" }));
-    }
-
-    @Test
-    public void testImageTransformLinMatrixDenseCP() {
-        runImageTransformLinTest(false, ExecType.CP);
-    }
-
-    @Test
-    public void testImageTransformLinMatrixSparseCP() {
-        runImageTransformLinTest(true, ExecType.CP);
-    }
-
-    @Test
-    public void testImageTransformLinMatrixDenseSP() {
-        runImageTransformLinTest(false, ExecType.SPARK);
-    }
-
-    @Test
-    public void testImageTransformLinMatrixSparseSP() {
-        runImageTransformLinTest(true, ExecType.SPARK);
-    }
-
-    private void runImageTransformLinTest(boolean sparse, ExecType instType) {
-        ExecMode platformOld = setExecMode(instType);
-        disableOutAndExpectedDeletion();
-        setOutputBuffering(true);
-
-        try {
-            loadTestConfiguration(getTestConfiguration(TEST_NAME));
-            double sparsity = sparse ? spSparse : spDense;
-
-            String HOME = SCRIPT_DIR + TEST_DIR;
-            fullDMLScriptName = HOME + TEST_NAME + ".dml";
-            programArgs = new String[] { "-nvargs", "in_file=" + input("A"), 
"out_file=" + output("B"),
-                    "width=" + s_cols * s_rows,
-                    "height=" + n_imgs, "out_w=" + s_cols, "out_h=" + s_rows * 
1.2,
-                    "a=" + a, "b=" + b, "c=" + c, "d=" + d, "e=" + e, "f=" + 
f, "fill_value=" + fill_value,
-                    "s_cols=" + s_cols,
-                    "s_rows=" + s_rows };
-
-            fullRScriptName = HOME + TEST_NAME + ".R";
-            rCmd = "Rscript" + " " + fullRScriptName + " " + inputDir() + " " 
+ expectedDir() + " " + s_cols * s_rows
-                    + " " + n_imgs + " " + s_cols + " " + (s_rows * 1.2) + " " 
+ a + " " + b + " " + c + " " + d + " "
-                    + e + " " + f + " " + fill_value + " " + s_cols + " " + 
s_rows;
-
-            // generate actual dataset
-            double[][] A = getRandomMatrix(n_imgs, s_cols * s_rows, 0, 255, 
sparsity, 7);
-            writeInputMatrixWithMTD("A", A, true);
-
-            runTest(true, false, null, -1);
-            runRScript(true);
-
-            HashMap<MatrixValue.CellIndex, Double> dmlfile = 
readDMLMatrixFromOutputDir("B");
-            HashMap<MatrixValue.CellIndex, Double> rfile = 
readRMatrixFromExpectedDir("B");
-            TestUtils.compareMatrices(dmlfile, rfile, eps, "Stat-DML", 
"Stat-R");
-        } finally {
-            rtplatform = platformOld;
-        }
-    }
+       private final static String TEST_NAME = "image_transform_linearized";
+       private final static String TEST_DIR = "functions/builtin/";
+       private final static String TEST_CLASS_DIR = TEST_DIR + 
BuiltinImageTransformLinTest.class.getSimpleName() + "/";
+
+       private final static double eps = 1e-10;
+
+       private final static double spSparse = 0.1;
+       private final static double spDense = 0.9;
+       private final static double fill_value = 0.0;
+
+       @Parameterized.Parameter(0)
+       public int s_rows;
+       @Parameterized.Parameter(1)
+       public int s_cols;
+       @Parameterized.Parameter(2)
+       public int n_imgs;
+
+       public double a;
+       public double b;
+       public double c;
+       public double d;
+       public double e;
+       public double f;
+
+       @Parameterized.Parameters
+       public static Collection<Object[]> data() {
+               return Arrays.asList(new Object[][] {{16, 15, 50}, {32, 31, 
100}, {64, 64, 200}, {127, 128, 100}, {256, 256, 200},
+                       {500, 135, 100}});
+       }
+
+       @Override
+       public void setUp() {
+               // rotate 30 degrees around the center
+               a = Math.sqrt(3) / 2;
+               b = -1.0 / 2.0;
+               c = s_cols / 4.0 * (3 - Math.sqrt(3));
+               d = 1.0 / 2.0;
+               e = Math.sqrt(3) / 2;
+               f = s_rows / 4.0 * (1 - Math.sqrt(3));
+
+               addTestConfiguration(TEST_NAME, new 
TestConfiguration(TEST_CLASS_DIR, TEST_NAME, new String[] {"B"}));
+       }
+
+       @Test
+       public void testImageTransformLinMatrixDenseCP() {
+               runImageTransformLinTest(false, ExecType.CP);
+       }
+
+       @Test
+       public void testImageTransformLinMatrixSparseCP() {
+               runImageTransformLinTest(true, ExecType.CP);
+       }
+
+       @Ignore
+       @Test
+       public void testImageTransformLinMatrixDenseSP() {
+               runImageTransformLinTest(false, ExecType.SPARK);
+       }
+
+       @Ignore
+       @Test
+       public void testImageTransformLinMatrixSparseSP() {
+               runImageTransformLinTest(false, ExecType.SPARK);
+       }
+
+       private void runImageTransformLinTest(boolean sparse, ExecType 
instType) {
+               ExecMode platformOld = setExecMode(instType);
+               disableOutAndExpectedDeletion();
+               setOutputBuffering(true);
+
+               try {
+                       loadTestConfiguration(getTestConfiguration(TEST_NAME));
+                       double sparsity = sparse ? spSparse : spDense;
+
+                       String HOME = SCRIPT_DIR + TEST_DIR;
+                       fullDMLScriptName = HOME + TEST_NAME + ".dml";
+                       programArgs = new String[] {"-nvargs", "in_file=" + 
input("A"), "out_file=" + output("B"),
+                               "width=" + s_cols * s_rows, "height=" + n_imgs, 
"out_w=" + s_cols, "out_h=" + s_rows * 1.2, "a=" + a,
+                               "b=" + b, "c=" + c, "d=" + d, "e=" + e, "f=" + 
f, "fill_value=" + fill_value, "s_cols=" + s_cols,
+                               "s_rows=" + s_rows};
+
+                       fullRScriptName = HOME + TEST_NAME + ".R";
+                       rCmd = "Rscript" + " " + fullRScriptName + " " + 
inputDir() + " " + expectedDir() + " " + s_cols * s_rows + " "
+                               + n_imgs + " " + s_cols + " " + (s_rows * 1.2) 
+ " " + a + " " + b + " " + c + " " + d + " " + e + " " + f
+                               + " " + fill_value + " " + s_cols + " " + 
s_rows;
+
+                       // generate actual dataset
+                       double[][] A = getRandomMatrix(n_imgs, s_cols * s_rows, 
0, 255, sparsity, 7);
+                       writeInputMatrixWithMTD("A", A, true);
+
+                       runTest(true, false, null, -1);
+                       runRScript(true);
+
+                       // compare matrices
+
+                       HashMap<MatrixValue.CellIndex, Double> dmlfile = 
readDMLMatrixFromOutputDir("B");
+                       HashMap<MatrixValue.CellIndex, Double> rfile = 
readRMatrixFromExpectedDir("B");
+                       TestUtils.compareMatrices(dmlfile, rfile, eps, 
"Stat-DML", "Stat-R");
+               }
+               finally {
+                       rtplatform = platformOld;
+               }
+       }
 }
diff --git a/src/test/resources/expected/ImageTransformLinRotated.csv 
b/src/test/resources/expected/ImageTransformLinRotated.csv
new file mode 100644
index 0000000000..064c63c7d1
--- /dev/null
+++ b/src/test/resources/expected/ImageTransformLinRotated.csv
@@ -0,0 +1 @@
+128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 
128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 
128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 
128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 
128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 
128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 
128 128 128 128  [...]
diff --git a/src/test/resources/expected/ImageTransformLinTransformed.csv 
b/src/test/resources/expected/ImageTransformLinTransformed.csv
deleted file mode 100644
index 02b5bdb87d..0000000000
--- a/src/test/resources/expected/ImageTransformLinTransformed.csv
+++ /dev/null
@@ -1 +0,0 @@
-128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 
128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 
128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 
128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 
128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 
128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 
128 128 128 128  [...]
diff --git a/src/test/scripts/functions/builtin/image_rotate_linearized.dml 
b/src/test/scripts/functions/builtin/image_rotate_linearized.dml
new file mode 100644
index 0000000000..52b2625c9e
--- /dev/null
+++ b/src/test/scripts/functions/builtin/image_rotate_linearized.dml
@@ -0,0 +1,33 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+input = read($in_file)
+width = ifdef($width, 512)
+height = ifdef($height, 512)
+radians = ifdef($angle, 0)
+fill_value = ifdef($fill_value, 128)
+s_cols = ifdef($s_cols, 512)
+s_rows = ifdef($s_rows, 512)
+
+input = matrix(input, rows=height, cols=width)
+
+rotated = img_rotate_linearized(input, radians, fill_value, s_cols, s_rows)
+write(rotated, $out_file)
diff --git 
a/src/test/scripts/functions/builtin/image_sample_pairing_linearized.dml 
b/src/test/scripts/functions/builtin/image_sample_pairing_linearized.dml
new file mode 100644
index 0000000000..82f0e6aa0a
--- /dev/null
+++ b/src/test/scripts/functions/builtin/image_sample_pairing_linearized.dml
@@ -0,0 +1,37 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+input_linearized = read($in_file);
+input = read($in_file_second);
+value =$value;
+rows_linear = nrow(input_linearized);
+cols_linear = ncol(input_linearized);
+img = matrix(input_linearized, rows=rows_linear, cols=cols_linear);
+img_two=matrix(input, rows=nrow(input), cols=ncol(input));
+img_out = img_sample_pairing_linearized(img,img_two,value)
+write(img_out, $x_out_file);
+img_out_batched= matrix(0, rows=rows_linear, cols=cols_linear);
+for(i in 1:rows_linear) {
+    image_i = matrix(img[i,], rows=1, cols= cols_linear);
+    img_out = img_sample_pairing(image_i,img_two,value);
+    img_out_batched[i,] = matrix(img_out, rows=1, cols=cols_linear);
+}
+
+write(img_out_batched,$x_out_reshape_file); 
\ No newline at end of file
diff --git a/src/test/scripts/functions/builtin/image_shear_linearized.dml 
b/src/test/scripts/functions/builtin/image_shear_linearized.dml
new file mode 100644
index 0000000000..95d21a2599
--- /dev/null
+++ b/src/test/scripts/functions/builtin/image_shear_linearized.dml
@@ -0,0 +1,34 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+input = read($in_file)
+width = ifdef($width, 512)
+height = ifdef($height, 512)
+shear_x = ifdef($shear_x, 0)
+shear_y = ifdef($shear_y, 0)
+fill_value = ifdef($fill_value, 128)
+s_cols = ifdef($s_cols, 512)
+s_rows = ifdef($s_rows, 512)
+
+input = matrix(input, rows=height, cols=width)
+
+sheared = img_shear_linearized(input, shear_x, shear_y, fill_value, s_cols, 
s_rows)
+write(sheared, $out_file)
diff --git a/src/test/scripts/functions/builtin/image_transform_linearized.R 
b/src/test/scripts/functions/builtin/image_transform_linearized.R
index 2b2498d8c9..1e8a151050 100644
--- a/src/test/scripts/functions/builtin/image_transform_linearized.R
+++ b/src/test/scripts/functions/builtin/image_transform_linearized.R
@@ -74,4 +74,5 @@ input = matrix(input, ncol=as.integer(args[3]), 
nrow=as.integer(args[4]))
 transformed = image_transform_linearized(input, as.integer(args[5]), 
as.integer(args[6]), as.double(args[7]), 
 as.double(args[8]), as.double(args[9]), as.double(args[10]), 
as.double(args[11]), as.double(args[12]), 
 as.double(args[13]), as.integer(args[14]),as.integer(args[15]))
+
 writeMM(as(transformed, "CsparseMatrix"), paste(args[2], "B", sep=""))


Reply via email to