Java Matrix Flatten Flatten(int[][] in, int[] out)

Here you can find the source of Flatten(int[][] in, int[] out)

Description

Flatten

License

Open Source License

Declaration

public static final int[] Flatten(int[][] in, int[] out) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static final int[] Flatten(int[][] in, int[] out) {
        if (out == null || out.length < NElem(in))
            out = new int[NElem(in)];
        int ind = 0;
        for (int i = 0, s = in.length; i < s; i++) {
            System.arraycopy(in[i], 0, out, ind, in[i].length);
            ind += in[i].length;//from  w  w w  . j a  v  a2s .  c om
        }
        return out;
    }

    public static final int[] Flatten(int[][] in) {
        return Flatten(in, null);
    }

    public static final int[] Flatten(int[][][] in, int[] out) {
        if (out == null || out.length < NElem(in))
            out = new int[NElem(in)];
        int ind = 0;
        for (int i = 0, s = in.length; i < s; i++) {
            int temp[] = Flatten(in[i]);
            System.arraycopy(temp, 0, out, ind, temp.length);
            ind += temp.length;
        }
        return out;
    }

    public static final int[] Flatten(int[][][] in) {
        return Flatten(in, null);
    }

    public static final int NElem(Object in) {
        if (in instanceof int[])
            return ((int[]) in).length;
        else {
            int sum = 0;
            for (int i = 0, s = ((Object[]) in).length; i < s; i++)
                sum += NElem(((Object[]) in)[i]);
            return sum;
        }
    }
}

Related

  1. flatten(double[][] array)
  2. flatten(double[][] matrix)
  3. flatten(double[][] matrix)
  4. flatten(double[][] spills)
  5. flatten(int[][] arr)
  6. flatten(String[][] table)
  7. flatten2DArray(byte[][] array)
  8. flatten2DArray(double[][] array)
  9. flatten4(float[][] in, int size, float[] out)