You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2017/03/31 14:50:00 UTC

commons-numbers git commit: Added 4D interleaved2Complex

Repository: commons-numbers
Updated Branches:
  refs/heads/complex-dev 70a1156a1 -> e2668df11


Added 4D interleaved2Complex


Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/e2668df1
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/e2668df1
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/e2668df1

Branch: refs/heads/complex-dev
Commit: e2668df11371dee73f6f2d64e33faecf02f12306
Parents: 70a1156
Author: Eric Barnhill <er...@apache.org>
Authored: Fri Mar 31 16:49:52 2017 +0200
Committer: Eric Barnhill <er...@apache.org>
Committed: Fri Mar 31 16:49:52 2017 +0200

----------------------------------------------------------------------
 .../commons/numbers/complex/ComplexUtils.java   | 67 ++++++++++++++++++++
 1 file changed, 67 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/e2668df1/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/ComplexUtils.java
----------------------------------------------------------------------
diff --git a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/ComplexUtils.java b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/ComplexUtils.java
index d02e306..4718ac5 100644
--- a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/ComplexUtils.java
+++ b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/ComplexUtils.java
@@ -1146,6 +1146,73 @@ public class ComplexUtils {
     }
 
     /**
+     * Converts a 4D interleaved complex {@code double[][][][]} array to a
+     * {@code Complex[][][][]} array.
+     *
+     * @param d 4D complex interleaved array
+     * @param interleavedDim Depth level of the array to interleave
+     * @return 4D {@code Complex} array
+     *
+     * @since 1.0
+     */
+    public static Complex[][][][] interleaved2Complex(double[][][][] i, int interleavedDim) {
+        if (interleavedDim > 2 || interleavedDim < 0) {
+            new IndexOutOfRangeException(interleavedDim);
+        }
+        final int w = i.length;
+        final int h = i[0].length;
+        final int d = i[0][0].length;
+        final int v = i[0][0][0].length;
+        Complex[][][][] c;
+        if (interleavedDim == 0) {
+            c = new Complex[w / 2][h][d][v];
+            for (int x = 0; x < w / 2; x++) {
+                for (int y = 0; y < h; y++) {
+                    for (int z = 0; z < d; z++) {
+                        for (int t = 0; t < v; t++) {
+                            c[x][y][z][t] = new Complex(i[x * 2][y][z][t], i[x * 2 + 1][y][z][t]);
+                        }
+                    }
+                }
+            }
+        } else if (interleavedDim == 1) {
+            c = new Complex[w][h / 2][d][v];
+            for (int x = 0; x < w; x++) {
+                for (int y = 0; y < h / 2; y++) {
+                    for (int z = 0; z < d; z++) {
+                        for (int t = 0; t < v; t++) {
+                            c[x][y][z][t] = new Complex(i[x][y * 2][z][t], i[x][y * 2 + 1][z][t]);
+                        }
+                    }
+                }
+            }
+        } else if (interleavedDim == 2) {
+            c = new Complex[w][h][d / 2][v];
+            for (int x = 0; x < w; x++) {
+                for (int y = 0; y < h; y++) {
+                    for (int z = 0; z < d / 2; z++) {
+                        for (int t = 0; t < v; t++) {
+                            c[x][y][z][t] = new Complex(i[x][y][z * 2][t], i[x][y][z * 2 + 1][t]);
+                        }
+                    }
+                }
+            }
+        } else {
+            c = new Complex[w][h][d][v / 2];
+            for (int x = 0; x < w; x++) {
+                for (int y = 0; y < h; y++) {
+                    for (int z = 0; z < d; z++) {
+                        for (int t = 0; t < v / 2; t++) {
+                            c[x][y][z][t] = new Complex(i[x][y][z][t * 2], i[x][y][z][t * 2 + 1]);
+                        }
+                    }
+                }
+            }
+        }
+        return c;
+    }
+
+    /**
      * Converts a 3D interleaved complex {@code double[][][]} array to a
      * {@code Complex[][][]} array. The third d level is assumed to be
      * interleaved.