1 package mpi
.fruitfly
.general
;
8 * <p>Copyright: Copyright (c) 2006</p>
12 * @author not attributable
16 public class ArrayConverter
18 public static float[] twoDimArrayToOneDimArray(float[][] filter
)
20 float[] result
= new float[filter
.length
* filter
[0].length
];
22 for (int y
= 0; y
< filter
[0].length
; y
++)
23 for (int x
= 0; x
< filter
.length
; x
++)
24 result
[x
+ filter
.length
*y
] = filter
[x
][y
];
29 public static double[] twoDimArrayToOneDimArray(double[][] filter
)
31 double[] result
= new double[filter
.length
* filter
[0].length
];
33 for (int y
= 0; y
< filter
[0].length
; y
++)
34 for (int x
= 0; x
< filter
.length
; x
++)
35 result
[x
+ filter
.length
*y
] = filter
[x
][y
];
40 public static double[][] oneDimArrayToTwoDimArray(double[] filter
, int width
, int height
)
42 double[][] result
= new double[width
][height
];
44 for (int y
= 0; y
< height
; y
++)
45 for (int x
= 0; x
< width
; x
++)
46 result
[x
][y
] = filter
[x
+ width
*y
];
51 // needed because matrix dimension is [row][column] which is the opposite of [x][y]!!!
53 public static double[][] oneDimArrayToTwoDimArrayInvert(double[] filter
, int width
/*columns*/, int height
/*rows*/)
56 double[][] result
= new double[height
][width
];
58 for (int row
= 0; row
< height
; row
++)
59 for (int column
= 0; column
< width
; column
++)
60 result
[row
][column
] = filter
[column
+ width
*row
];