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


##########
src/main/java/org/apache/sysds/runtime/matrix/data/LibMatrixFourier.java:
##########
@@ -0,0 +1,309 @@
+/*
+ * 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.math3.util.FastMath;
+
+public class LibMatrixFourier {
+
+       /**
+        * Function to perform FFT for two given matrices. The first one 
represents the real values and the second one the
+        * imaginary values. The output also contains one matrix for the real 
and one for the imaginary values.
+        *
+        * @param re matrix object representing the real values
+        * @param im matrix object representing the imaginary values
+        * @return array of two matrix blocks
+        */
+       public static MatrixBlock[] fft(MatrixBlock re, MatrixBlock im) {
+
+               int rows = re.getNumRows();
+               int cols = re.getNumColumns();
+               if(!isPowerOfTwo(rows) || !isPowerOfTwo(cols))
+                       throw new RuntimeException("false dimensions");
+
+               fft(re.getDenseBlockValues(), im.getDenseBlockValues(), rows, 
cols, true);
+
+               return new MatrixBlock[] {re, im};
+       }
+
+       /**
+        * Function to perform IFFT for two given matrices. The first one 
represents the real values and the second one the
+        * imaginary values. The output also contains one matrix for the real 
and one for the imaginary values.
+        *
+        * @param re matrix object representing the real values
+        * @param im matrix object representing the imaginary values
+        * @return array of two matrix blocks
+        */
+       public static MatrixBlock[] ifft(MatrixBlock re, MatrixBlock im) {
+
+               int rows = re.getNumRows();
+               int cols = re.getNumColumns();
+               if(!isPowerOfTwo(rows) || !isPowerOfTwo(cols))
+                       throw new RuntimeException("false dimensions");
+
+               ifft(re.getDenseBlockValues(), im.getDenseBlockValues(), rows, 
cols, true);
+
+               return new MatrixBlock[] {re, im};
+       }
+
+       /**
+        * Function to perform FFT for each row of two given matrices. The 
first one represents the real values and the
+        * second one the imaginary values. The output also contains one matrix 
for the real and one for the imaginary
+        * values.
+        *
+        * @param re matrix object representing the real values
+        * @param im matrix object representing the imaginary values
+        * @return array of two matrix blocks
+        */
+       public static MatrixBlock[] fft_linearized(MatrixBlock re, MatrixBlock 
im) {
+
+               int rows = re.getNumRows();
+               int cols = re.getNumColumns();
+               if(!isPowerOfTwo(cols))
+                       throw new RuntimeException("false dimensions");
+
+               fft(re.getDenseBlockValues(), im.getDenseBlockValues(), rows, 
cols, false);
+
+               return new MatrixBlock[] {re, im};
+       }
+
+       /**
+        * Function to perform IFFT for each row of two given matrices. The 
first one represents the real values and the
+        * second one the imaginary values. The output also contains one matrix 
for the real and one for the imaginary
+        * values.
+        *
+        * @param re matrix object representing the real values
+        * @param im matrix object representing the imaginary values
+        * @return array of two matrix blocks
+        */
+       public static MatrixBlock[] ifft_linearized(MatrixBlock re, MatrixBlock 
im) {
+
+               int rows = re.getNumRows();
+               int cols = re.getNumColumns();
+               if(!isPowerOfTwo(cols))
+                       throw new RuntimeException("false dimensions");
+
+               ifft(re.getDenseBlockValues(), im.getDenseBlockValues(), rows, 
cols, false);
+
+               return new MatrixBlock[] {re, im};
+       }
+
+       /**
+        * Function to perform FFT for two given double arrays. The first one 
represents the real values and the second one
+        * the imaginary values. Both arrays get updated and contain the result.
+        *
+        * @param re          array representing the real values
+        * @param im          array representing the imaginary values
+        * @param rows        number of rows
+        * @param cols        number of rows
+        * @param inclColCalc if true, fft is also calculated for each column, 
otherwise only for each row
+        */
+       public static void fft(double[] re, double[] im, int rows, int cols, 
boolean inclColCalc) {
+
+               double[] re_inter = new double[rows * cols];
+               double[] im_inter = new double[rows * cols];
+
+               for(int i = 0; i < rows; i++) {
+                       fft_one_dim(re, im, re_inter, im_inter, i * cols, (i + 
1) * cols, cols, 1);
+               }
+
+               if(inclColCalc) {
+                       for(int j = 0; j < cols; j++) {
+                               fft_one_dim(re, im, re_inter, im_inter, j, j + 
rows * cols, rows, cols);
+                       }
+               }
+
+       }
+
+       /**
+        * Function to perform IFFT for two given double arrays. The first one 
represents the real values and the second one
+        * the imaginary values. Both arrays get updated and contain the result.
+        *
+        * @param re          array representing the real values
+        * @param im          array representing the imaginary values
+        * @param rows        number of rows
+        * @param cols        number of rows
+        * @param inclColCalc if true, fft is also calculated for each column, 
otherwise only for each row
+        */
+       public static void ifft(double[] re, double[] im, int rows, int cols, 
boolean inclColCalc) {
+
+               double[] re_inter = new double[rows * cols];
+               double[] im_inter = new double[rows * cols];
+
+               if(inclColCalc) {
+                       for(int j = 0; j < cols; j++) {
+                               ifft_one_dim(re, im, re_inter, im_inter, j, j + 
rows * cols, rows, cols);
+                       }
+               }
+
+               for(int i = 0; i < rows; i++) {
+                       ifft_one_dim(re, im, re_inter, im_inter, i * cols, (i + 
1) * cols, cols, 1);

Review Comment:
   full example of parallel execution: 
   
https://github.com/apache/systemds/blob/f4b7a47cbba9951210eef45263dc4a927b59225c/src/main/java/org/apache/sysds/runtime/frame/data/lib/FrameLibDetectSchema.java#L84



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