@@ -40,7 +40,7 @@ public void cartesian(double[][][] args, int level, int col, double[] buf, doubl
4040 }
4141 }
4242
43- public static double [][] cartesion (double []... args ) {
43+ public static double [][] cartesian (double []... args ) {
4444 int colMax = args .length ;
4545 double [] buf = new double [colMax ];
4646 int rowMax = 1 ;
@@ -53,7 +53,22 @@ public static double[][] cartesion(double[]... args) {
5353 return newArgs ;
5454 }
5555
56- public static double [][] cartesion (double [][]... args ) {
56+ public static double [][] cartesian (int vecLen , double []... args ) {
57+ int colMax = args .length ;
58+ double [][] buf = new double [colMax ][vecLen ];
59+ int rowMax = 1 ;
60+ for (int i =0 ; i <args .length ; i ++) {
61+ rowMax *= (args [i ].length /vecLen );
62+ }
63+ rowMax *= vecLen ;
64+ double [][] newArgs = new double [colMax ][rowMax ];
65+ BytecodeSelect sel = new BytecodeSelect (null );
66+ sel .simpleCartesian (vecLen , args , 0 , buf , newArgs );
67+ return newArgs ;
68+ }
69+
70+
71+ public static double [][] cartesian (double [][]... args ) {
5772 int colMax = 0 ;
5873 for (int i =0 ; i <args .length ; i ++)
5974 colMax += args [i ].length ;
@@ -86,6 +101,26 @@ public void simpleCartesian(double[][] args, int col, double[] buf, double[][] n
86101 }
87102 }
88103
104+ public void simpleCartesian (int vecLen , double [][] args , int col , double [][] buf , double [][] newArgs ) {
105+ if (col == args .length - 1 ) {
106+ for (int i =0 ; i <args [col ].length ; i +=vecLen ) {
107+ for (int k =0 ; k <vecLen ; k ++)
108+ buf [col ][k ] = args [col ][i +k ];
109+ for (int j =0 ; j <buf .length ; j ++) {
110+ for (int k =0 ; k <vecLen ; k ++)
111+ newArgs [j ][row +k ] = buf [j ][k ];
112+ }
113+ row +=vecLen ;
114+ }
115+ return ;
116+ }
117+ for (int i =0 ; i <args [col ].length ; i +=vecLen ) {
118+ for (int k =0 ; k <vecLen ; k ++)
119+ buf [col ][k ] = args [col ][i +k ];
120+ simpleCartesian (vecLen , args , col +1 , buf , newArgs );
121+ }
122+ }
123+
89124 public void testSimpleCartesian () {
90125 double [][] args = {{1 ,2 },{3 ,4 ,5 ,6 },{7 ,8 }};
91126 int colMax = args .length ;
@@ -104,6 +139,18 @@ public void testSimpleCartesian() {
104139 }
105140 }
106141
142+ public void testSimpleCartesian2 () {
143+ double [][] args = {{1 ,2 ,3 ,5 ,7 ,9 },{4 ,5 ,6 ,7 ,8 ,9 }};
144+ double [][] newArgs = cartesian (3 , args );
145+
146+ for (int j =0 ; j <newArgs [0 ].length ; j ++) {
147+ for (int i =0 ; i <newArgs .length ; i ++) {
148+ System .out .print (newArgs [i ][j ]+" " );
149+ }
150+ System .out .println ();
151+ }
152+ }
153+
107154 public void testCartesian () {
108155 //double[][][] args = { {{1,2},{3,4}}, {{7,8,9},{5,6,7}} };
109156 double [][][] args = { {{1 ,2 },{3 ,4 }}, {{7 ,8 ,9 }}, {{5 ,6 ,7 }} };
@@ -130,8 +177,12 @@ public static void main(String[] args) {
130177// BytecodeSelect bs = new BytecodeSelect(null);
131178// bs.testSimpleCartesian();
132179
180+ // //row = 0;
181+ // BytecodeSelect bs2 = new BytecodeSelect(null);
182+ // bs2.testCartesian();
183+
133184 //row = 0;
134- BytecodeSelect bs2 = new BytecodeSelect (null );
135- bs2 . testCartesian ();
185+ BytecodeSelect bs = new BytecodeSelect (null );
186+ bs . testSimpleCartesian2 ();
136187 }
137188}
0 commit comments