Skip to content

Commit 2c3347f

Browse files
committed
Test simple cartesian with vector supported
1 parent bea562a commit 2c3347f

File tree

2 files changed

+59
-8
lines changed

2 files changed

+59
-8
lines changed

src/lambdacloud/test/TestBatchVec.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static void testSimpleCartesian() {
7575
}
7676

7777
BytecodeBatchVecFunc ff = new BytecodeBatchVecFunc(func, dim, dim);
78-
double[][] args2 = BytecodeSelect.cartesion(args);
78+
double[][] args2 = BytecodeSelect.cartesian(args);
7979
double[] outAry2 = new double[args2[0].length];
8080
ff.apply(outAry2, 0, args2);
8181
for(double d : outAry2) {
@@ -90,7 +90,7 @@ public static void testCartesian() {
9090
double[][][] args = { { {1,2,3}, {4,5,6} }, {{0,1,2,3}}};
9191

9292
BytecodeBatchVecFunc ff = new BytecodeBatchVecFunc(func, dim, dim);
93-
double[][] args2 = BytecodeSelect.cartesion(args);
93+
double[][] args2 = BytecodeSelect.cartesian(args);
9494
double[] outAry2 = new double[args2[0].length];
9595
ff.apply(outAry2, 0, args2);
9696
for(double d : outAry2) {
@@ -120,7 +120,7 @@ public static void testBatchVector() {
120120
double[][][] args = { { {1,2,3}, {4,5,6} }, {{0,1,2,3}}};
121121

122122
BytecodeBatchVecFunc ff = new BytecodeBatchVecFunc(func, dim, dim);
123-
double[][] args2 = BytecodeSelect.cartesion(args);
123+
double[][] args2 = BytecodeSelect.cartesian(args);
124124
double[] outAry2 = new double[args2[0].length];
125125
ff.apply(outAry2, 0, args2);
126126
for(double d : outAry2) {
@@ -149,7 +149,7 @@ public static void testBatchVectorDot1() {
149149
int dim = 3;
150150
// The length of the return value of dot product is 1.
151151
BytecodeBatchVecFunc ff = new BytecodeBatchVecFunc(func, dim, 1);
152-
double[][] args2 = BytecodeSelect.cartesion(args);
152+
double[][] args2 = BytecodeSelect.cartesian(args);
153153
double[] outAry2 = new double[dim];
154154
ff.apply(outAry2, 0, args2);
155155
for(double d : outAry2) {

src/symjava/bytecode/BytecodeSelect.java

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)