Skip to content

Commit c2124f9

Browse files
committed
Add and test cartesian with vector supported
1 parent 2c3347f commit c2124f9

File tree

1 file changed

+108
-66
lines changed

1 file changed

+108
-66
lines changed

src/symjava/bytecode/BytecodeSelect.java

Lines changed: 108 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public BytecodeSelect(BytecodeVecFunc[] funcs) {
2121
// _apply(args, args.length, newArgs);
2222
// }
2323

24-
public void cartesian(double[][][] args, int level, int col, double[] buf, double[][] newArgs) {
24+
public void _cartesian(double[][][] args, int level, int col, double[] buf,
25+
double[][] newArgs) {
2526
if(level == args.length - 1) {
2627
for(int i=0; i<args[level][0].length; i++) {
2728
for(int k=0; k<args[level].length; k++)
@@ -36,55 +37,41 @@ public void cartesian(double[][][] args, int level, int col, double[] buf, doubl
3637
for(int i=0; i<args[level][0].length; i++) {
3738
for(int k=0; k<args[level].length; k++)
3839
buf[col+k] = args[level][k][i];
39-
cartesian(args, level+1, col+args[level].length, buf, newArgs);
40+
_cartesian(args, level+1, col+args[level].length, buf, newArgs);
4041
}
4142
}
4243

43-
public static double[][] cartesian(double[]... args) {
44-
int colMax = args.length;
45-
double[] buf = new double[colMax];
46-
int rowMax = 1;
47-
for(int i=0; i<args.length; i++) {
48-
rowMax *= args[i].length;
49-
}
50-
double[][] newArgs = new double[colMax][rowMax];
51-
BytecodeSelect sel = new BytecodeSelect(null);
52-
sel.simpleCartesian(args, 0, buf, newArgs);
53-
return newArgs;
54-
}
55-
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);
44+
public void _cartesian(int vecLen, double[][][] args, int level, int col, double[][] buf,
45+
double[][] newArgs) {
46+
if(level == args.length - 1) {
47+
for(int i=0; i<args[level][0].length; i+=vecLen) {
48+
for(int j=0; j<args[level].length; j++) {
49+
for(int k=0; k<vecLen; k++)
50+
buf[col+j][k] = args[level][j][i+k];
51+
}
52+
for(int j=0; j<buf.length; j++) {
53+
for(int k=0; k<vecLen; k++)
54+
newArgs[j][row+k] = buf[j][k];
55+
}
56+
row+=vecLen;
57+
}
58+
return;
6259
}
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) {
72-
int colMax = 0 ;
73-
for(int i=0; i<args.length; i++)
74-
colMax += args[i].length;
75-
double[] buf = new double[colMax];
76-
int rowMax = 1;
77-
for(int i=0; i<args.length; i++) {
78-
rowMax *= args[i][0].length;
60+
//row level
61+
for(int i=0; i<args[level][0].length; i+=vecLen) {
62+
//column level
63+
for(int j=0; j<args[level].length; j++) {
64+
//vector level
65+
for(int k=0; k<vecLen; k++)
66+
buf[col+j][k] = args[level][j][i+k];
67+
}
68+
_cartesian(vecLen, args, level+1, col+args[level].length, buf, newArgs);
7969
}
80-
double[][] newArgs = new double[colMax][rowMax];
81-
BytecodeSelect sel = new BytecodeSelect(null);
82-
sel.cartesian(args, 0, 0, buf, newArgs);
83-
return newArgs;
8470
}
8571

8672
public int row = 0;
87-
public void simpleCartesian(double[][] args, int col, double[] buf, double[][] newArgs) {
73+
public void _simpleCartesian(double[][] args, int col, double[] buf,
74+
double[][] newArgs) {
8875
if(col == args.length - 1) {
8976
for(int i=0; i<args[col].length; i++) {
9077
buf[col] = args[col][i];
@@ -97,11 +84,12 @@ public void simpleCartesian(double[][] args, int col, double[] buf, double[][] n
9784
}
9885
for(int i=0; i<args[col].length; i++) {
9986
buf[col] = args[col][i];
100-
simpleCartesian(args, col+1, buf, newArgs);
87+
_simpleCartesian(args, col+1, buf, newArgs);
10188
}
10289
}
10390

104-
public void simpleCartesian(int vecLen, double[][] args, int col, double[][] buf, double[][] newArgs) {
91+
public void _simpleCartesian(int vecLen, double[][] args, int col, double[][] buf,
92+
double[][] newArgs) {
10593
if(col == args.length - 1) {
10694
for(int i=0; i<args[col].length; i+=vecLen) {
10795
for(int k=0; k<vecLen; k++)
@@ -117,20 +105,71 @@ public void simpleCartesian(int vecLen, double[][] args, int col, double[][] buf
117105
for(int i=0; i<args[col].length; i+=vecLen) {
118106
for(int k=0; k<vecLen; k++)
119107
buf[col][k] = args[col][i+k];
120-
simpleCartesian(vecLen, args, col+1, buf, newArgs);
108+
_simpleCartesian(vecLen, args, col+1, buf, newArgs);
121109
}
122110
}
123111

124-
public void testSimpleCartesian() {
125-
double[][] args = {{1,2},{3,4,5,6},{7,8}};
112+
public static double[][] cartesian(double[]... args) {
126113
int colMax = args.length;
127114
double[] buf = new double[colMax];
128115
int rowMax = 1;
129116
for(int i=0; i<args.length; i++) {
130117
rowMax *= args[i].length;
131118
}
132119
double[][] newArgs = new double[colMax][rowMax];
133-
simpleCartesian(args, 0, buf, newArgs);
120+
BytecodeSelect sel = new BytecodeSelect(null);
121+
sel._simpleCartesian(args, 0, buf, newArgs);
122+
return newArgs;
123+
}
124+
125+
public static double[][] cartesian(int vecLen, double[]... args) {
126+
int colMax = args.length;
127+
double[][] buf = new double[colMax][vecLen];
128+
int rowMax = 1;
129+
for(int i=0; i<args.length; i++) {
130+
rowMax *= (args[i].length/vecLen);
131+
}
132+
rowMax *= vecLen;
133+
double[][] newArgs = new double[colMax][rowMax];
134+
BytecodeSelect sel = new BytecodeSelect(null);
135+
sel._simpleCartesian(vecLen, args, 0, buf, newArgs);
136+
return newArgs;
137+
}
138+
139+
public static double[][] cartesian(double[][]... args) {
140+
int colMax = 0 ;
141+
for(int i=0; i<args.length; i++)
142+
colMax += args[i].length;
143+
double[] buf = new double[colMax];
144+
int rowMax = 1;
145+
for(int i=0; i<args.length; i++) {
146+
rowMax *= args[i][0].length;
147+
}
148+
double[][] newArgs = new double[colMax][rowMax];
149+
BytecodeSelect sel = new BytecodeSelect(null);
150+
sel._cartesian(args, 0, 0, buf, newArgs);
151+
return newArgs;
152+
}
153+
154+
public static double[][] cartesian(int vecLen, double[][]... args) {
155+
int colMax = 0 ;
156+
for(int i=0; i<args.length; i++)
157+
colMax += args[i].length;
158+
double[][] buf = new double[colMax][vecLen];
159+
int rowMax = 1;
160+
for(int i=0; i<args.length; i++) {
161+
rowMax *= args[i][0].length/vecLen;
162+
}
163+
rowMax *= vecLen;
164+
double[][] newArgs = new double[colMax][rowMax];
165+
BytecodeSelect sel = new BytecodeSelect(null);
166+
sel._cartesian(vecLen, args, 0, 0, buf, newArgs);
167+
return newArgs;
168+
}
169+
170+
public void testSimpleCartesian() {
171+
double[][] args = {{1,2},{3,4,5,6},{7,8}};
172+
double[][] newArgs = cartesian(args);
134173
for(int j=0; j<newArgs[0].length; j++) {
135174
for(int i=0; i<newArgs.length; i++) {
136175
System.out.print(newArgs[i][j]+" ");
@@ -154,16 +193,19 @@ public void testSimpleCartesian2() {
154193
public void testCartesian() {
155194
//double[][][] args = { {{1,2},{3,4}}, {{7,8,9},{5,6,7}} };
156195
double[][][] args = { {{1,2},{3,4}}, {{7,8,9}}, {{5,6,7}} };
157-
int colMax = 0 ;
158-
for(int i=0; i<args.length; i++)
159-
colMax += args[i].length;
160-
double[] buf = new double[colMax];
161-
int rowMax = 1;
162-
for(int i=0; i<args.length; i++) {
163-
rowMax *= args[i][0].length;
196+
double[][] newArgs = cartesian(args);
197+
for(int j=0; j<newArgs[0].length; j++) {
198+
for(int i=0; i<newArgs.length; i++) {
199+
System.out.print(newArgs[i][j]+" ");
200+
}
201+
System.out.println();
164202
}
165-
double[][] newArgs = new double[colMax][rowMax];
166-
cartesian(args, 0, 0, buf, newArgs);
203+
}
204+
205+
public void testCartesian2() {
206+
double[][][] args = { {{1,2,3,4,5,6},{7,8,9,10,11,12}}, {{10,20,30,40,50,60}}};
207+
int vecLen = 3;
208+
double[][] newArgs = cartesian(vecLen, args);
167209
for(int j=0; j<newArgs[0].length; j++) {
168210
for(int i=0; i<newArgs.length; i++) {
169211
System.out.print(newArgs[i][j]+" ");
@@ -173,16 +215,16 @@ public void testCartesian() {
173215
}
174216

175217
public static void main(String[] args) {
176-
// //row = 0;
177-
// BytecodeSelect bs = new BytecodeSelect(null);
178-
// bs.testSimpleCartesian();
218+
BytecodeSelect bs = new BytecodeSelect(null);
219+
bs.testSimpleCartesian();
179220

180-
// //row = 0;
181-
// BytecodeSelect bs2 = new BytecodeSelect(null);
182-
// bs2.testCartesian();
221+
BytecodeSelect bs2 = new BytecodeSelect(null);
222+
bs2.testCartesian();
183223

184-
//row = 0;
185-
BytecodeSelect bs = new BytecodeSelect(null);
186-
bs.testSimpleCartesian2();
224+
BytecodeSelect bs3 = new BytecodeSelect(null);
225+
bs3.testSimpleCartesian2();
226+
227+
BytecodeSelect bs4 = new BytecodeSelect(null);
228+
bs4.testCartesian2();
187229
}
188230
}

0 commit comments

Comments
 (0)