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


##########
scripts/builtin/img_transform_linearized.dml:
##########
@@ -85,7 +85,8 @@ m_img_transform_linearized = function(Matrix[Double] img_in, 
Integer out_w, Inte
     ind= matrix(seq(1,ncol(xs),1),1,ncol(xs))
     z = table(xs, ind) 
     output = ys%*%z
-
+    print(nrow(img_in))
+    print(ncol(img_in))

Review Comment:
   Remove print statements in the DML scripts.
   
   Furthermore, could we change this DML script to use your new builtin feature?



##########
scripts/builtin/img_transform_matrix.dml:
##########
@@ -0,0 +1,77 @@
+#-------------------------------------------------------------
+#
+# 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.
+#
+#-------------------------------------------------------------
+
+# Generates the z matrix for the new linearized image transformation function 
in order to apply
+# affine transformation to linearized images.
+#
+# INPUT:
+# 
-------------------------------------------------------------------------------------------
+# transMat      3x3 matrix for affine transformation (transformation Matrix)
+# dimMat        2x2 matrix containing the original size of the image in the 
first row as follows
+#               [1,1] original height; [1,2] original width
+#               and the target size of the new image in the second row as 
follows
+#               [2,1] target height; [2,2] target width
+#               (dimensionMatrix)
+# 
-------------------------------------------------------------------------------------------
+# OUTPUT:
+# 
---------------------------------------------------------------------------------------
+# zMat          transformation matrix to be multiplied with for the linearized 
image
+#               transformation function (arbitrary naming)
+# isFillable    returns a boolean which indicates if cells need to be filled 
(with fillvalue),
+                in this case the image is extended, otherwise the original 
image is used

Review Comment:
   this line is missing the hashtag



##########
scripts/builtin/img_transform_matrix.dml:
##########
@@ -0,0 +1,77 @@
+#-------------------------------------------------------------
+#
+# 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.
+#
+#-------------------------------------------------------------
+
+# Generates the z matrix for the new linearized image transformation function 
in order to apply
+# affine transformation to linearized images.
+#
+# INPUT:
+# 
-------------------------------------------------------------------------------------------
+# transMat      3x3 matrix for affine transformation (transformation Matrix)
+# dimMat        2x2 matrix containing the original size of the image in the 
first row as follows
+#               [1,1] original height; [1,2] original width
+#               and the target size of the new image in the second row as 
follows
+#               [2,1] target height; [2,2] target width
+#               (dimensionMatrix)
+# 
-------------------------------------------------------------------------------------------
+# OUTPUT:
+# 
---------------------------------------------------------------------------------------
+# zMat          transformation matrix to be multiplied with for the linearized 
image
+#               transformation function (arbitrary naming)
+# isFillable    returns a boolean which indicates if cells need to be filled 
(with fillvalue),
+                in this case the image is extended, otherwise the original 
image is used
+# 
---------------------------------------------------------------------------------------
+
+ m_img_transform_matrix = function(Matrix[Double] transMat, Integer orig_w, 
Integer orig_h, Integer out_w, Integer out_h)
+            return (Matrix[Double] zMat, Matrix[Double] isFillable){
+         #orig_w = as.scalar(dimMat[1,2])

Review Comment:
   we have a convention of 2 space indentations of our builtin scripts.



##########
src/main/java/org/apache/sysds/parser/BuiltinFunctionExpression.java:
##########
@@ -1325,7 +1351,6 @@ else if( getOpCode() == Builtins.RBIND ) {
                        output.setBlocksize(0);
                        output.setValueType(ValueType.BOOLEAN);
                        break;
-               

Review Comment:
   avoid this formatting.



##########
src/main/java/org/apache/sysds/runtime/instructions/cp/MultiReturnComplexMatrixBuiltinCPInstruction.java:
##########
@@ -138,6 +138,16 @@ else if(parts.length == 8 && 
opcode.equalsIgnoreCase("stft")) {
 
                        return new 
MultiReturnComplexMatrixBuiltinCPInstruction(null, in1, in2, windowSize, 
overlap, outputs, opcode,
                                str, threads);
+               } else if (opcode.equalsIgnoreCase("img_transform_matrix")) {
+                       // 2 inputs and two outputs
+                       CPOperand in1 = new CPOperand(parts[1]); 
//transformation matrix

Review Comment:
   move comments to line above.



##########
src/main/java/org/apache/sysds/hops/FunctionOp.java:
##########
@@ -183,43 +183,41 @@ protected double computeOutputMemEstimate( long dim1, 
long dim2, long nnz )
                if ( getFunctionType() != FunctionType.MULTIRETURN_BUILTIN )
                        throw new RuntimeException("Invalid call of 
computeOutputMemEstimate in FunctionOp.");
                else {
-                       if ( getFunctionName().equalsIgnoreCase("qr") ) {
+                       if (getFunctionName().equalsIgnoreCase("qr")) {

Review Comment:
   while i 100% agree with the formatting of code, we try to not make 
modifications of code parts, that you do not change.
   Therefore we need to revert many of the changes in this file to the 
previously unformatted code.



##########
src/main/java/org/apache/sysds/runtime/matrix/data/LibMatrixIMGTransform.java:
##########
@@ -0,0 +1,232 @@
+/*
+ * 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.runtime.matrix.data;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.sysds.runtime.functionobjects.Builtin;
+import org.apache.sysds.runtime.functionobjects.CTable;
+import org.apache.sysds.runtime.functionobjects.SwapIndex;
+import org.apache.sysds.runtime.instructions.InstructionUtils;
+import org.apache.sysds.runtime.matrix.operators.*;
+import org.apache.sysds.runtime.util.DataConverter;
+
+import static org.apache.commons.math3.util.FastMath.floor;
+
+/**Separate class for generating the transformation matrix based on an affine 
transformation matrix and a matrix
+ * containing the dimensions of the input and the target dimensions of the 
output
+ */
+public class LibMatrixIMGTransform {
+
+    protected static final Log LOG = 
LogFactory.getLog(LibMatrixIMGTransform.class.getName());
+
+
+//     * affine transformation matrix for calculated for a picture of original 
size and target dimensions
+//     * see: https://en.wikipedia.org/wiki/Affine_transformation
+//     *
+//     * #orig_w = as.scalar(dimMat[1,2])
+//     * #orig_h = as.scalar(dimMat[1,1])
+//     * #out_w = as.scalar(dimMat[2,2])
+//     * #out_h = as.scalar(dimMat[2,1])
+//     * T_inv = inv(transMat)
+//     *
+//     * ## coordinates of output pixel-centers linearized in row-major order
+//     * coords = matrix(1, rows=3, cols=out_w*out_h)
+//     * coords[1,] = t((seq(0, out_w*out_h-1) %% out_w) + 0.5)
+//     * coords[2,] = t((seq(0, out_w*out_h-1) %/% out_w) + 0.5)
+//     * # compute sampling pixel indices
+//     * coords = floor(T_inv %*% coords) + 1
+//     * inx = t(coords[1,])
+//     * iny = t(coords[2,])
+//     * # any out-of-range pixels, if present, correspond to an extra pixel 
with fill_value at the end of the input
+//     * index_vector = (orig_w *(iny-1) + inx) * ((0<inx) & (inx<=orig_w) & 
(0<iny) & (iny<=orig_h))
+//     * index_vector = t(index_vector)
+//     * xs = ((index_vector == 0)*(orig_w*orig_h +1)) + index_vector
+//     * #if(min(index_vector) == 0){
+//     * #  ys=cbind(img_in, matrix(fill_value,nrow(img_in), 1))
+//     * #}else{
+//     * #  ys = img_in
+//     * #}
+//     * ind= matrix(seq(1,ncol(xs),1),1,ncol(xs))
+//     * z = table(xs, ind)
+//     * zMat = transMat
+//     * isFillable = as.double(min(index_vector) == 0)
+    /** This method produces a transformation matrix for affine transformation 
(see Wikipedia: "Affine transformation").
+     * It takes a transformation 3x3 matrix (last row is always 0,0,1 for 
images), called affine matrix, and a dimension matrix, where the
+     * original image dimensions (width x height) are stored alongside the 
output image dimensions (width x height)
+     * @param transMat affine 3x3 matrix for image transformations
+     * @param dimMat 2x2 matrix with original and output image dimensions
+     * @param threads number of threads for use in different methods
+     *
+     * @return array of two matrix blocks, 1st is the transformation matrix, 
2nd a 1x1 matrix with 1 or 0
+     */
+    public static MatrixBlock[] transformationMatrix(MatrixBlock transMat, 
MatrixBlock dimMat, int threads) {
+        //check the correctness of the input dimension matrix
+        isValidDimensionMatrix(dimMat);
+
+        int orig_w = (int) dimMat.get(0,0);
+        int orig_h = (int) dimMat.get(0,1);
+        int out_w = (int) dimMat.get(1,0);
+        int out_h = (int) dimMat.get(1,1);
+
+        //calculate the inverse of the transformation matrix
+        MatrixBlock t_Inv = LibCommonsMath.unaryOperations(transMat, 
"inverse");
+
+        //create the coords matrix: coords = matrix(1, rows=3, 
cols=out_w*out_h)
+        MatrixBlock coords = new MatrixBlock(3, out_w*out_h, false);
+        //change values to coords[1, ] = t((seq(0, out_w * out_h - 1) %% 
out_w) + 0.5)
+        //coords[2, ] = t((seq(0, out_w * out_h - 1) %/% out_w) + 0.5)
+        double [] coords1 = new double[out_w*out_h];
+        double [] coords2 = new double[out_w*out_h];
+        double [] coords3 = new double[out_w*out_h];

Review Comment:
   if possible we should avoid allocating this much, 
   
   For instance what is the coords3 used for when it only assign ones?



##########
src/main/java/org/apache/sysds/runtime/matrix/data/LibCommonsMath.java:
##########
@@ -169,6 +172,9 @@ public static MatrixBlock[] 
multiReturnOperations(MatrixBlock in1, MatrixBlock i
                                return computeIFFT_LINEARIZED(in1, in2, 
threads);
                        case "rcm":
                                return computeRCM(in1, in2);
+                       case "img_transform_matrix":
+                               //throw new NotImplementedException("Hope we 
get here");

Review Comment:
   remove commented error.



##########
src/test/java/org/apache/sysds/test/functions/builtin/part1/BuiltinImageTransformMatrixTest.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.apache.commons.lang3.NotImplementedException;
+import org.apache.sysds.test.AutomatedTestBase;
+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.test.TestConfiguration;
+
+import java.util.*;

Review Comment:
   no wildcard imports.



##########
src/test/scripts/functions/builtin/image_transform_matrix.dml:
##########
@@ -0,0 +1,55 @@
+#-------------------------------------------------------------
+#
+# 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.
+#
+#-------------------------------------------------------------
+
+#get the transformation matrix (3x3) as an input
+transformationMatrix = read($transMat)
+#print(toString(transformationMatrix))
+
+# get a matrix with the original image dimensions and the target dimensions 
(2x2)
+# -----original width----original height
+# -----target width------target height
+dimensionMatrix = read($dimMat)
+
+# print(toString(dimensionMatrix))
+
+#orig_w = as.scalar(dimensionMatrix[1,1])
+#orig_h = as.scalar(dimensionMatrix[1,2])
+#out_w = as.scalar(dimensionMatrix[2,1])
+#out_h = as.scalar(dimensionMatrix[2,2])
+#print("orig_w: " + orig_w + "; orig_h: " + orig_h + "; out_w: " + out_w + "; 
out_h: " + out_h)
+input = matrix(transformationMatrix, rows=3, cols=3)
+
+builtin = TRUE
+if(builtin){
+    [zMat, isFillable] = img_transform_matrix(input, dimensionMatrix)
+}else{
+    [zMat, isFillable] = img_transform_test(input, dimensionMatrix)
+}
+
+# function for calculating the matrix which will be matrix multiplied with
+# the image for matrix multiplication
+isFillable = as.logical(as.scalar(isFillable))
+
+#print(toString(zMat))
+print(nrow(zMat))
+print(ncol(zMat))

Review Comment:
   remove print statements not used.



##########
src/test/scripts/functions/builtin/image_transform_linearized.dml:
##########
@@ -24,17 +24,57 @@ width = ifdef($width, 512)
 height = ifdef($height, 512)
 out_w = ifdef($out_w, 512)
 out_h = ifdef($out_h, 512)
-a = ifdef($a, 1)
-b = ifdef($b, 0)
-c = ifdef($c, 0)
+a = ifdef($a, 2)
+b = ifdef($b, 1)
+c = ifdef($c, 1)
 d = ifdef($d, 0)
 e = ifdef($e, 1)
 f = ifdef($f, 0)
 fill_value = ifdef($fill_value, 0)
 s_cols = ifdef($s_cols, 512)
 s_rows = ifdef($s_rows, 512)
 
-input = matrix(input, rows=height, cols=width)
+inputMat = matrix(input, rows=1, cols=width*height)
+print(nrow(input))
+print(ncol(input))
+transformed = img_transform_linearized(inputMat, out_w, out_h, a, b, c, d, e, 
f, fill_value, s_cols, s_rows)
+print(nrow(transformed))
+print(ncol(transformed))
 
-transformed = img_transform_linearized(input, out_w, out_h, a, b, c, d, e, f, 
fill_value, s_cols, s_rows)
+#affineMat = matrix(0,rows=3, cols=3)
+#affineMat[1,1] = a
+#affineMat[1,2] = b
+#affineMat[1,3] = c
+#affineMat[2,1] = d
+#affineMat[2,2] = e
+#affineMat[2,3] = f
+#affineMat[3,3] = 1
+#dimMat = matrix(0,rows=2, cols=2)
+#dimMat[1,1] = width
+#dimMat[1,2] = height
+#dimMat[2,1] = out_w
+#dimMat[2,2] = out_h
+
+#[zMat, isFillable] = img_transform_test(affineMat, dimMat)
+
+#print(nrow(zMat))
+#print(ncol(zMat))
+#print(toString(isFillable))
+
+#if(min(as.logical(as.scalar(isFillable))){
+#      ys=cbind(input, matrix(fill_value,nrow(input), 1))
+#    }else{
+#      ys = input
+#    }
+
+    #ind= matrix(seq(1,ncol(xs),1),1,ncol(xs))
+    #z = table(xs, ind)
+#output = ys%*%zMat
+
+#img_out = matrix(output, rows=nrow(input), cols=out_w*out_h)
+
+
+#print(toString(affineMat))
+#print(toString(dimMat))

Review Comment:
   and remove print statements not used.



##########
scripts/builtin/img_transform_matrix.dml:
##########
@@ -0,0 +1,77 @@
+#-------------------------------------------------------------
+#
+# 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.
+#
+#-------------------------------------------------------------
+
+# Generates the z matrix for the new linearized image transformation function 
in order to apply
+# affine transformation to linearized images.
+#
+# INPUT:
+# 
-------------------------------------------------------------------------------------------
+# transMat      3x3 matrix for affine transformation (transformation Matrix)
+# dimMat        2x2 matrix containing the original size of the image in the 
first row as follows
+#               [1,1] original height; [1,2] original width
+#               and the target size of the new image in the second row as 
follows
+#               [2,1] target height; [2,2] target width
+#               (dimensionMatrix)
+# 
-------------------------------------------------------------------------------------------
+# OUTPUT:
+# 
---------------------------------------------------------------------------------------
+# zMat          transformation matrix to be multiplied with for the linearized 
image
+#               transformation function (arbitrary naming)
+# isFillable    returns a boolean which indicates if cells need to be filled 
(with fillvalue),
+                in this case the image is extended, otherwise the original 
image is used
+# 
---------------------------------------------------------------------------------------
+
+ m_img_transform_matrix = function(Matrix[Double] transMat, Integer orig_w, 
Integer orig_h, Integer out_w, Integer out_h)
+            return (Matrix[Double] zMat, Matrix[Double] isFillable){
+         #orig_w = as.scalar(dimMat[1,2])
+         #orig_h = as.scalar(dimMat[1,1])
+
+         #out_w = as.scalar(dimMat[2,2])
+         #out_h = as.scalar(dimMat[2,1])
+         T_inv = inv(transMat)
+
+         ## coordinates of output pixel-centers linearized in row-major order
+         coords = matrix(1, rows=3, cols=out_w*out_h)
+         coords[1,] = t((seq(0, out_w*out_h-1) %% out_w) + 0.5)
+         coords[2,] = t((seq(0, out_w*out_h-1) %/% out_w) + 0.5)
+
+         # compute sampling pixel indices
+         coords = floor(T_inv %*% coords) + 1
+
+         inx = t(coords[1,])
+         iny = t(coords[2,])
+
+         # any out-of-range pixels, if present, correspond to an extra pixel 
with fill_value at the end of the input
+         index_vector = (orig_w *(iny-1) + inx) * ((0<inx) & (inx<=orig_w) & 
(0<iny) & (iny<=orig_h))
+         index_vector = t(index_vector)
+         xs = ((index_vector == 0)*(orig_w*orig_h +1)) + index_vector
+
+         #if(min(index_vector) == 0){
+         #  ys=cbind(img_in, matrix(fill_value,nrow(img_in), 1))
+         #}else{
+         #  ys = img_in
+         #}
+
+         ind= matrix(seq(1,ncol(xs),1),1,ncol(xs))
+         z = table(xs, ind)
+         zMat = transMat
+         isFillable = as.logical(as.double(min(index_vector) == 0))
+ }

Review Comment:
   add a newline in the end of files.



##########
src/main/java/org/apache/sysds/common/Builtins.java:
##########
@@ -168,6 +168,8 @@ public enum Builtins {
        IMG_CROP_LINEARIZED("img_crop_linearized", true),
        IMG_TRANSFORM("img_transform", true),
        IMG_TRANSFORM_LINEARIZED("img_transform_linearized", true),
+       IMG_TRANSFORM_MATRIX("img_transform_matrix", false, 
ReturnType.MULTI_RETURN),
+       IMG_TRANSFORM_TEST("img_transform_test", true),

Review Comment:
   please remove the test function.



##########
scripts/builtin/img_transform_test.dml:
##########
@@ -0,0 +1,52 @@
+#-------------------------------------------------------------

Review Comment:
   test scripts is not allowed in the builtin folder, please move this to the 
testing folder in /src/test/scripts/functions/builtin. 
   You can then source it and use the functionality without it having to be a 
dedicated builtin function.



##########
src/main/java/org/apache/sysds/runtime/instructions/cp/MultiReturnBuiltinCPInstruction.java:
##########
@@ -138,8 +138,8 @@ else if(parts.length == 3 && 
opcode.equalsIgnoreCase("fft_linearized")) {
 
                        return new MultiReturnBuiltinCPInstruction(null, null, 
outputs, opcode, str, threads);
 
-               }
-               else if ( opcode.equalsIgnoreCase("stft") ) {
+
+               } else if ( opcode.equalsIgnoreCase("stft") ) {

Review Comment:
   revert formatting.



##########
src/test/java/org/apache/sysds/test/functions/builtin/part1/BuiltinImageTransformLinearizedTest.java:
##########
@@ -0,0 +1,175 @@
+/*
+ * 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.apache.spark.sql.catalyst.expressions.CheckOverflowInTableInsert;
+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)
+@net.jcip.annotations.NotThreadSafe
+
+public class BuiltinImageTransformLinearizedTest extends AutomatedTestBase {
+    private final static String TEST_NAME_LINEARIZED = 
"image_transform_linearized";
+    private final static String TEST_DIR = "functions/builtin/";
+    private final static String TEST_CLASS_DIR = TEST_DIR + 
BuiltinImageTransformLinearizedTest.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(0)
+    public int rows; //number of linearized images
+    @Parameterized.Parameter(1)
+    public int width;
+    @Parameterized.Parameter(2)
+    public int height;
+    @Parameterized.Parameter(3)
+    public int out_w;
+    @Parameterized.Parameter(4)
+    public int out_h;
+    @Parameterized.Parameter(5)
+    public int a;
+    @Parameterized.Parameter(6)
+    public int b;
+    @Parameterized.Parameter(7)
+    public int c;
+    @Parameterized.Parameter(8)
+    public int d;
+    @Parameterized.Parameter(9)
+    public int e;
+    @Parameterized.Parameter(10)
+    public int f;
+    @Parameterized.Parameter(11)
+    public int fill_value;
+    @Parameterized.Parameter(12)
+    public int s_cols;
+    @Parameterized.Parameter(13)
+    public int s_rows;
+
+
+    @Parameterized.Parameters
+    public static Collection<Object[]> data() {
+        return Arrays.asList(new Object[][] {{1, 512, 512, 512, 512, 
2,0,0,0,1,0,1, 512, 512}});

Review Comment:
   great with parameterized tests!
   
   I would suggest that you add a few more test cases such that we have a 
'tall' image, and a 'wide' image case at least. 



##########
src/main/java/org/apache/sysds/runtime/matrix/data/LibMatrixIMGTransform.java:
##########
@@ -0,0 +1,232 @@
+/*
+ * 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.runtime.matrix.data;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.sysds.runtime.functionobjects.Builtin;
+import org.apache.sysds.runtime.functionobjects.CTable;
+import org.apache.sysds.runtime.functionobjects.SwapIndex;
+import org.apache.sysds.runtime.instructions.InstructionUtils;
+import org.apache.sysds.runtime.matrix.operators.*;
+import org.apache.sysds.runtime.util.DataConverter;
+
+import static org.apache.commons.math3.util.FastMath.floor;
+
+/**Separate class for generating the transformation matrix based on an affine 
transformation matrix and a matrix
+ * containing the dimensions of the input and the target dimensions of the 
output
+ */
+public class LibMatrixIMGTransform {
+
+    protected static final Log LOG = 
LogFactory.getLog(LibMatrixIMGTransform.class.getName());
+
+
+//     * affine transformation matrix for calculated for a picture of original 
size and target dimensions

Review Comment:
   remove commented code here.



##########
src/main/java/org/apache/sysds/parser/BuiltinFunctionExpression.java:
##########
@@ -24,6 +24,7 @@
 import java.util.HashMap;
 import java.util.HashSet;
 
+import javassist.expr.Expr;

Review Comment:
   i do not know, but i do not think that this import is used.



##########
src/main/java/org/apache/sysds/runtime/matrix/data/LibMatrixIMGTransform.java:
##########
@@ -0,0 +1,232 @@
+/*
+ * 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.runtime.matrix.data;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.sysds.runtime.functionobjects.Builtin;
+import org.apache.sysds.runtime.functionobjects.CTable;
+import org.apache.sysds.runtime.functionobjects.SwapIndex;
+import org.apache.sysds.runtime.instructions.InstructionUtils;
+import org.apache.sysds.runtime.matrix.operators.*;

Review Comment:
   wildcard imports is not allowed in SystemDS. It is probably something you 
can set in your IDE.



##########
src/main/java/org/apache/sysds/runtime/matrix/data/LibMatrixIMGTransform.java:
##########
@@ -0,0 +1,232 @@
+/*
+ * 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.runtime.matrix.data;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.sysds.runtime.functionobjects.Builtin;
+import org.apache.sysds.runtime.functionobjects.CTable;
+import org.apache.sysds.runtime.functionobjects.SwapIndex;
+import org.apache.sysds.runtime.instructions.InstructionUtils;
+import org.apache.sysds.runtime.matrix.operators.*;
+import org.apache.sysds.runtime.util.DataConverter;
+
+import static org.apache.commons.math3.util.FastMath.floor;
+
+/**Separate class for generating the transformation matrix based on an affine 
transformation matrix and a matrix
+ * containing the dimensions of the input and the target dimensions of the 
output
+ */
+public class LibMatrixIMGTransform {
+
+    protected static final Log LOG = 
LogFactory.getLog(LibMatrixIMGTransform.class.getName());
+
+
+//     * affine transformation matrix for calculated for a picture of original 
size and target dimensions
+//     * see: https://en.wikipedia.org/wiki/Affine_transformation
+//     *
+//     * #orig_w = as.scalar(dimMat[1,2])
+//     * #orig_h = as.scalar(dimMat[1,1])
+//     * #out_w = as.scalar(dimMat[2,2])
+//     * #out_h = as.scalar(dimMat[2,1])
+//     * T_inv = inv(transMat)
+//     *
+//     * ## coordinates of output pixel-centers linearized in row-major order
+//     * coords = matrix(1, rows=3, cols=out_w*out_h)
+//     * coords[1,] = t((seq(0, out_w*out_h-1) %% out_w) + 0.5)
+//     * coords[2,] = t((seq(0, out_w*out_h-1) %/% out_w) + 0.5)
+//     * # compute sampling pixel indices
+//     * coords = floor(T_inv %*% coords) + 1
+//     * inx = t(coords[1,])
+//     * iny = t(coords[2,])
+//     * # any out-of-range pixels, if present, correspond to an extra pixel 
with fill_value at the end of the input
+//     * index_vector = (orig_w *(iny-1) + inx) * ((0<inx) & (inx<=orig_w) & 
(0<iny) & (iny<=orig_h))
+//     * index_vector = t(index_vector)
+//     * xs = ((index_vector == 0)*(orig_w*orig_h +1)) + index_vector
+//     * #if(min(index_vector) == 0){
+//     * #  ys=cbind(img_in, matrix(fill_value,nrow(img_in), 1))
+//     * #}else{
+//     * #  ys = img_in
+//     * #}
+//     * ind= matrix(seq(1,ncol(xs),1),1,ncol(xs))
+//     * z = table(xs, ind)
+//     * zMat = transMat
+//     * isFillable = as.double(min(index_vector) == 0)
+    /** This method produces a transformation matrix for affine transformation 
(see Wikipedia: "Affine transformation").
+     * It takes a transformation 3x3 matrix (last row is always 0,0,1 for 
images), called affine matrix, and a dimension matrix, where the
+     * original image dimensions (width x height) are stored alongside the 
output image dimensions (width x height)
+     * @param transMat affine 3x3 matrix for image transformations
+     * @param dimMat 2x2 matrix with original and output image dimensions
+     * @param threads number of threads for use in different methods
+     *
+     * @return array of two matrix blocks, 1st is the transformation matrix, 
2nd a 1x1 matrix with 1 or 0
+     */
+    public static MatrixBlock[] transformationMatrix(MatrixBlock transMat, 
MatrixBlock dimMat, int threads) {

Review Comment:
   Overall, it is a good starting point for the operation. 
   You can probably benefit from some of the instructions to use threads, and 
some of the scalar operations where the MatrixBlock is allocated can probably 
be hand optimized. 
   
   It would be good if you could modify the lines, to not have the comments on 
the lines but on the line above.
   



##########
src/test/scripts/functions/builtin/image_transform_linearized.dml:
##########
@@ -24,17 +24,57 @@ width = ifdef($width, 512)
 height = ifdef($height, 512)
 out_w = ifdef($out_w, 512)
 out_h = ifdef($out_h, 512)
-a = ifdef($a, 1)
-b = ifdef($b, 0)
-c = ifdef($c, 0)
+a = ifdef($a, 2)
+b = ifdef($b, 1)
+c = ifdef($c, 1)
 d = ifdef($d, 0)
 e = ifdef($e, 1)
 f = ifdef($f, 0)
 fill_value = ifdef($fill_value, 0)
 s_cols = ifdef($s_cols, 512)
 s_rows = ifdef($s_rows, 512)
 
-input = matrix(input, rows=height, cols=width)
+inputMat = matrix(input, rows=1, cols=width*height)
+print(nrow(input))
+print(ncol(input))
+transformed = img_transform_linearized(inputMat, out_w, out_h, a, b, c, d, e, 
f, fill_value, s_cols, s_rows)
+print(nrow(transformed))
+print(ncol(transformed))
 
-transformed = img_transform_linearized(input, out_w, out_h, a, b, c, d, e, f, 
fill_value, s_cols, s_rows)
+#affineMat = matrix(0,rows=3, cols=3)

Review Comment:
   we need to clean these tests up, such that we do not have this commented 
code.



##########
src/test/java/org/apache/sysds/test/functions/builtin/part1/BuiltinImageTransformMatrixTest.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.apache.commons.lang3.NotImplementedException;
+import org.apache.sysds.test.AutomatedTestBase;
+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.test.TestConfiguration;
+
+import java.util.*;
+
+@RunWith(Parameterized.class)
+@net.jcip.annotations.NotThreadSafe
+
+public class BuiltinImageTransformMatrixTest extends AutomatedTestBase {
+    private final static String TEST_NAME_LINEARIZED = 
"image_transform_matrix";
+    private final static String TEST_DIR = "functions/builtin/";
+    private final static String TEST_CLASS_DIR = TEST_DIR + 
BuiltinImageTransformMatrixTest.class.getSimpleName() + "/";
+
+    @Parameterized.Parameter(0)
+    public double[][] transMat;
+    @Parameterized.Parameter(1)
+    public double[][] dimMat;
+    @Parameterized.Parameter(2)
+    public boolean fails;
+
+    private final static double [][] t1 = new double[][] 
{{2,0,0},{0,1,0},{0,0,1}}; //initial test for warmup
+    private final static double [][] d1 = new double[][] {{10, 10},{15,15}};
+    private final static double [][] t2 = new double[][] 
{{2,0,0},{0,1,0},{0,0,1}};
+    private final static double [][] d2 = new double[][] {{100, 
100},{100,100}}; //test1: 100x100
+    private final static double [][] t3 = new double[][] 
{{2,0,0},{0,1,0},{0,0,1}};
+    private final static double [][] d3 = new double[][] {{640, 
480},{640,480}}; //test2: 640x480
+    private final static double [][] t4 = new double[][] 
{{4,0,0},{0,1,0},{0,0,1}};
+    private final static double [][] d4 = new double[][] {{1280, 720},{1280, 
720}};//test3: 1280x720
+    private final static double [][] t5 = new double[][] 
{{2,0,0},{0,1,0},{0,0,1}};
+    private final static double [][] d5 = new double[][] {{1920, 1080},{1920, 
1080}};//test4 1920x1080
+    private final static double [][] t6 = new double[][] 
{{2,0,0},{0,1,0},{0,0,1}};
+    private final static double [][] d6 = new double[][] {{2560, 1440},{2560, 
1440}};//test5 2560x1440
+    private final static double [][] t7 = new double[][] 
{{2,0,0},{0,1,0},{0,0,1}};
+    private final static double [][] d7 = new double[][] {{3840, 2160},{3840, 
2160}}; //test6 3840x2160
+    private final static double [][] t8 = new double[][] 
{{2,0,0},{0,1,0},{0,0,1}};
+    private final static double [][] d8 = new double[][] {{3840, 2160},{1980, 
1080}};
+    private final static double [][] t9 = new double[][] 
{{2,0,0},{0,1,0},{0,0,1}};
+    private final static double [][] d9 = new double[][] {{20.10, 200},{200, 
200}};
+    private final static double [][] t10 = new double[][] 
{{0,0,0},{0,0,0},{0,0,0}};
+    private final static double [][] d10 = new double[][] {{20.10, 200},{200, 
200}};
+    private final static double [][] t11 = new double[][] 
{{0,0,0},{0,1,0},{0,0,0}};
+    private final static double [][] d11 = new double[][] {{20.10, 200},{200, 
200}};
+    private final static double [][] t12 = new double[][] 
{{2,0,0},{0,1,0},{0,0,1}};
+    private final static double [][] d12 = new double[][] {{0, 0},{0, 0}};
+    private final static double [][] t13 = new double[][] 
{{2,0,0},{0,1,0},{0,0,1}};
+    private final static double [][] d13 = new double[][] {{0.10, 200},{200, 
200}};
+
+    @Parameterized.Parameters
+    public static Collection<Object[]> data() {
+        return Arrays.asList(new Object[][] {{t1, d1, false},{t2, d2, 
false},{t3, d3, false},{t4, d4, false},
+                {t5, d5,false},{t6, d6, false},{t7, d7,false},{t8, d8,false},
+                {t9, d9,true},{t10,d10,true},{t11, d11,true},{t12, 
d12,true},{t13, d13,true}});
+    }
+
+    @Override
+    public void setUp() {
+        addTestConfiguration(TEST_NAME_LINEARIZED,
+                new TestConfiguration(TEST_CLASS_DIR, TEST_NAME_LINEARIZED, 
new String[] {"B_x"}));
+    }
+
+    @Test
+    public void testImageTransformMatrix() {
+        runImageTransformMatrixTest(ExecType.CP);
+    }
+
+    private void runImageTransformMatrixTest(ExecType instType) {
+        ExecMode platformOld = setExecMode(instType);
+        disableOutAndExpectedDeletion();
+
+        try {
+            loadTestConfiguration(getTestConfiguration(TEST_NAME_LINEARIZED));
+
+            String HOME = SCRIPT_DIR + TEST_DIR;
+
+            writeInputMatrixWithMTD("transMat", transMat, true);
+            writeInputMatrixWithMTD("dimMat", dimMat, true);
+
+            fullDMLScriptName = HOME + TEST_NAME_LINEARIZED + ".dml";
+            programArgs = new String[]{"-nvargs", "transMat=" + 
input("transMat"), "dimMat=" + input("dimMat"), "out_file=" + output("B_x"), 
"--debug"};
+
+
+            runTest(true, fails, null, -1);

Review Comment:
   verify the results.



##########
src/test/java/org/apache/sysds/test/functions/builtin/part1/BuiltinImageTransformLinearizedTest.java:
##########
@@ -0,0 +1,175 @@
+/*
+ * 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.apache.spark.sql.catalyst.expressions.CheckOverflowInTableInsert;
+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)
+@net.jcip.annotations.NotThreadSafe
+
+public class BuiltinImageTransformLinearizedTest extends AutomatedTestBase {
+    private final static String TEST_NAME_LINEARIZED = 
"image_transform_linearized";
+    private final static String TEST_DIR = "functions/builtin/";
+    private final static String TEST_CLASS_DIR = TEST_DIR + 
BuiltinImageTransformLinearizedTest.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(0)
+    public int rows; //number of linearized images
+    @Parameterized.Parameter(1)
+    public int width;
+    @Parameterized.Parameter(2)
+    public int height;
+    @Parameterized.Parameter(3)
+    public int out_w;
+    @Parameterized.Parameter(4)
+    public int out_h;
+    @Parameterized.Parameter(5)
+    public int a;
+    @Parameterized.Parameter(6)
+    public int b;
+    @Parameterized.Parameter(7)
+    public int c;
+    @Parameterized.Parameter(8)
+    public int d;
+    @Parameterized.Parameter(9)
+    public int e;
+    @Parameterized.Parameter(10)
+    public int f;
+    @Parameterized.Parameter(11)
+    public int fill_value;
+    @Parameterized.Parameter(12)
+    public int s_cols;
+    @Parameterized.Parameter(13)
+    public int s_rows;
+
+
+    @Parameterized.Parameters
+    public static Collection<Object[]> data() {
+        return Arrays.asList(new Object[][] {{1, 512, 512, 512, 512, 
2,0,0,0,1,0,1, 512, 512}});
+    }
+
+    @Override
+    public void setUp() {
+        addTestConfiguration(TEST_NAME_LINEARIZED,
+                new TestConfiguration(TEST_CLASS_DIR, TEST_NAME_LINEARIZED, 
new String[] {"B_x"}));
+    }
+
+    @Test
+    public void testImageTransformLinearized() {
+        runImageTransformLinearizedTest(false, ExecType.CP);
+    }
+
+    @Test
+    public void testImageTransformLinearizedEmpty() {
+        runImageTransformLinearizedTestEmpty(false, ExecType.CP);
+    }
+
+    @Test
+    @Ignore
+    public void testImageTransformLinearizedSP() {
+        runImageTransformLinearizedTest(true, ExecType.SPARK);
+    }
+
+
+
+    private void runImageTransformLinearizedTest(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=/home/mark-p4/data/pic1.csv",
+                    //"in_file=" + input("A"),
+                    "width=" + width, "height=" + height,
+                    "out_w=" + out_w, "out_h=" + out_h, "a=" + a, "b=" + b, 
"c=" + c, "d=" + d, "e=" + e, "f=" + f,
+                    "fill_value=" + fill_value, "s_cols=" + s_cols, "s_rows=" 
+ s_rows,
+                    "out_file=" + output("B_x")};
+
+            double[][] A = getRandomMatrix(rows, height*width, 0, 255, 
sparsity, 7);
+            writeInputMatrixWithMTD("A", A, true);
+
+            runTest(true, false, null, -1);
+
+            //HashMap<MatrixValue.CellIndex, Double> dmlfileLinearizedX = 
readDMLMatrixFromOutputDir("B_x");

Review Comment:
   we need to add verification of the output. For now the test just runs to 
verify if it crash not if the result is correct.



##########
src/test/java/org/apache/sysds/test/functions/builtin/part1/BuiltinImageTransformMatrixTest.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.apache.commons.lang3.NotImplementedException;
+import org.apache.sysds.test.AutomatedTestBase;
+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.test.TestConfiguration;
+
+import java.util.*;
+
+@RunWith(Parameterized.class)
+@net.jcip.annotations.NotThreadSafe
+
+public class BuiltinImageTransformMatrixTest extends AutomatedTestBase {
+    private final static String TEST_NAME_LINEARIZED = 
"image_transform_matrix";
+    private final static String TEST_DIR = "functions/builtin/";
+    private final static String TEST_CLASS_DIR = TEST_DIR + 
BuiltinImageTransformMatrixTest.class.getSimpleName() + "/";
+
+    @Parameterized.Parameter(0)
+    public double[][] transMat;
+    @Parameterized.Parameter(1)
+    public double[][] dimMat;
+    @Parameterized.Parameter(2)
+    public boolean fails;
+
+    private final static double [][] t1 = new double[][] 
{{2,0,0},{0,1,0},{0,0,1}}; //initial test for warmup
+    private final static double [][] d1 = new double[][] {{10, 10},{15,15}};
+    private final static double [][] t2 = new double[][] 
{{2,0,0},{0,1,0},{0,0,1}};
+    private final static double [][] d2 = new double[][] {{100, 
100},{100,100}}; //test1: 100x100
+    private final static double [][] t3 = new double[][] 
{{2,0,0},{0,1,0},{0,0,1}};
+    private final static double [][] d3 = new double[][] {{640, 
480},{640,480}}; //test2: 640x480
+    private final static double [][] t4 = new double[][] 
{{4,0,0},{0,1,0},{0,0,1}};
+    private final static double [][] d4 = new double[][] {{1280, 720},{1280, 
720}};//test3: 1280x720
+    private final static double [][] t5 = new double[][] 
{{2,0,0},{0,1,0},{0,0,1}};
+    private final static double [][] d5 = new double[][] {{1920, 1080},{1920, 
1080}};//test4 1920x1080
+    private final static double [][] t6 = new double[][] 
{{2,0,0},{0,1,0},{0,0,1}};
+    private final static double [][] d6 = new double[][] {{2560, 1440},{2560, 
1440}};//test5 2560x1440
+    private final static double [][] t7 = new double[][] 
{{2,0,0},{0,1,0},{0,0,1}};
+    private final static double [][] d7 = new double[][] {{3840, 2160},{3840, 
2160}}; //test6 3840x2160
+    private final static double [][] t8 = new double[][] 
{{2,0,0},{0,1,0},{0,0,1}};
+    private final static double [][] d8 = new double[][] {{3840, 2160},{1980, 
1080}};
+    private final static double [][] t9 = new double[][] 
{{2,0,0},{0,1,0},{0,0,1}};
+    private final static double [][] d9 = new double[][] {{20.10, 200},{200, 
200}};
+    private final static double [][] t10 = new double[][] 
{{0,0,0},{0,0,0},{0,0,0}};
+    private final static double [][] d10 = new double[][] {{20.10, 200},{200, 
200}};
+    private final static double [][] t11 = new double[][] 
{{0,0,0},{0,1,0},{0,0,0}};
+    private final static double [][] d11 = new double[][] {{20.10, 200},{200, 
200}};
+    private final static double [][] t12 = new double[][] 
{{2,0,0},{0,1,0},{0,0,1}};
+    private final static double [][] d12 = new double[][] {{0, 0},{0, 0}};
+    private final static double [][] t13 = new double[][] 
{{2,0,0},{0,1,0},{0,0,1}};
+    private final static double [][] d13 = new double[][] {{0.10, 200},{200, 
200}};
+
+    @Parameterized.Parameters
+    public static Collection<Object[]> data() {
+        return Arrays.asList(new Object[][] {{t1, d1, false},{t2, d2, 
false},{t3, d3, false},{t4, d4, false},
+                {t5, d5,false},{t6, d6, false},{t7, d7,false},{t8, d8,false},
+                {t9, d9,true},{t10,d10,true},{t11, d11,true},{t12, 
d12,true},{t13, d13,true}});
+    }
+
+    @Override
+    public void setUp() {
+        addTestConfiguration(TEST_NAME_LINEARIZED,
+                new TestConfiguration(TEST_CLASS_DIR, TEST_NAME_LINEARIZED, 
new String[] {"B_x"}));
+    }
+
+    @Test
+    public void testImageTransformMatrix() {
+        runImageTransformMatrixTest(ExecType.CP);
+    }
+
+    private void runImageTransformMatrixTest(ExecType instType) {
+        ExecMode platformOld = setExecMode(instType);
+        disableOutAndExpectedDeletion();
+
+        try {
+            loadTestConfiguration(getTestConfiguration(TEST_NAME_LINEARIZED));
+
+            String HOME = SCRIPT_DIR + TEST_DIR;
+
+            writeInputMatrixWithMTD("transMat", transMat, true);
+            writeInputMatrixWithMTD("dimMat", dimMat, true);
+
+            fullDMLScriptName = HOME + TEST_NAME_LINEARIZED + ".dml";
+            programArgs = new String[]{"-nvargs", "transMat=" + 
input("transMat"), "dimMat=" + input("dimMat"), "out_file=" + output("B_x"), 
"--debug"};
+
+
+            runTest(true, fails, null, -1);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            rtplatform = platformOld;
+        }
+    }
+
+
+}

Review Comment:
   newlne in the end.



##########
src/test/java/org/apache/sysds/test/functions/builtin/part1/BuiltinImageTransformLinearizedTest.java:
##########
@@ -0,0 +1,175 @@
+/*
+ * 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.apache.spark.sql.catalyst.expressions.CheckOverflowInTableInsert;
+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)
+@net.jcip.annotations.NotThreadSafe
+
+public class BuiltinImageTransformLinearizedTest extends AutomatedTestBase {
+    private final static String TEST_NAME_LINEARIZED = 
"image_transform_linearized";
+    private final static String TEST_DIR = "functions/builtin/";
+    private final static String TEST_CLASS_DIR = TEST_DIR + 
BuiltinImageTransformLinearizedTest.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(0)
+    public int rows; //number of linearized images
+    @Parameterized.Parameter(1)
+    public int width;
+    @Parameterized.Parameter(2)
+    public int height;
+    @Parameterized.Parameter(3)
+    public int out_w;
+    @Parameterized.Parameter(4)
+    public int out_h;
+    @Parameterized.Parameter(5)
+    public int a;
+    @Parameterized.Parameter(6)
+    public int b;
+    @Parameterized.Parameter(7)
+    public int c;
+    @Parameterized.Parameter(8)
+    public int d;
+    @Parameterized.Parameter(9)
+    public int e;
+    @Parameterized.Parameter(10)
+    public int f;
+    @Parameterized.Parameter(11)
+    public int fill_value;
+    @Parameterized.Parameter(12)
+    public int s_cols;
+    @Parameterized.Parameter(13)
+    public int s_rows;
+
+
+    @Parameterized.Parameters
+    public static Collection<Object[]> data() {
+        return Arrays.asList(new Object[][] {{1, 512, 512, 512, 512, 
2,0,0,0,1,0,1, 512, 512}});
+    }
+
+    @Override
+    public void setUp() {
+        addTestConfiguration(TEST_NAME_LINEARIZED,
+                new TestConfiguration(TEST_CLASS_DIR, TEST_NAME_LINEARIZED, 
new String[] {"B_x"}));
+    }
+
+    @Test
+    public void testImageTransformLinearized() {
+        runImageTransformLinearizedTest(false, ExecType.CP);
+    }
+
+    @Test
+    public void testImageTransformLinearizedEmpty() {
+        runImageTransformLinearizedTestEmpty(false, ExecType.CP);
+    }
+
+    @Test
+    @Ignore
+    public void testImageTransformLinearizedSP() {
+        runImageTransformLinearizedTest(true, ExecType.SPARK);
+    }
+
+
+
+    private void runImageTransformLinearizedTest(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=/home/mark-p4/data/pic1.csv",
+                    //"in_file=" + input("A"),
+                    "width=" + width, "height=" + height,
+                    "out_w=" + out_w, "out_h=" + out_h, "a=" + a, "b=" + b, 
"c=" + c, "d=" + d, "e=" + e, "f=" + f,
+                    "fill_value=" + fill_value, "s_cols=" + s_cols, "s_rows=" 
+ s_rows,
+                    "out_file=" + output("B_x")};
+
+            double[][] A = getRandomMatrix(rows, height*width, 0, 255, 
sparsity, 7);
+            writeInputMatrixWithMTD("A", A, 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;
+        }
+    }
+    private void runImageTransformLinearizedTestEmpty(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"), 
"width=", "height=",
+                    "out_w=", "out_h=", "a=", "b=", "c=", "d=", "e=", "f=",
+                    "fill_value=", "s_cols=", "s_rows=",
+                    "out_file=" + output("B_x")};
+
+            double[][] A = getRandomMatrix(rows, height * width, 0, 255, 
sparsity, 7);
+            writeInputMatrixWithMTD("A", A, true);
+
+            runTest(true, false, null, -1);
+
+            //HashMap<MatrixValue.CellIndex, Double> dmlfileLinearizedX = 
readDMLMatrixFromOutputDir("B_x");

Review Comment:
   same here, we do not verify the result.



##########
src/main/java/org/apache/sysds/runtime/instructions/cp/MultiReturnComplexMatrixBuiltinCPInstruction.java:
##########
@@ -138,6 +138,16 @@ else if(parts.length == 8 && 
opcode.equalsIgnoreCase("stft")) {
 
                        return new 
MultiReturnComplexMatrixBuiltinCPInstruction(null, in1, in2, windowSize, 
overlap, outputs, opcode,
                                str, threads);
+               } else if (opcode.equalsIgnoreCase("img_transform_matrix")) {
+                       // 2 inputs and two outputs
+                       CPOperand in1 = new CPOperand(parts[1]); 
//transformation matrix
+                       CPOperand in2 = new CPOperand(parts[2]); //dimension 
matrix [[orig_w, orig_h],[out_w, out_h]]
+
+                       outputs.add(new CPOperand(parts[3], ValueType.FP64, 
DataType.MATRIX));
+                       outputs.add(new CPOperand(parts[4], ValueType.FP64, 
DataType.MATRIX));
+                       int threads = Integer.parseInt(parts[5]);
+                       //throw new NotImplementedException("Has yet to be 
done. Check number of inputs" + Arrays.toString(parts) + "; Number of parts: " 
+ parts.length);

Review Comment:
   remove commented error.



-- 
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: dev-unsubscr...@systemds.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to