Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
126 lines (108 loc) · 3.79 KB

File metadata and controls

126 lines (108 loc) · 3.79 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package symjava.symbolic;
import java.util.Map;
import com.sun.org.apache.bcel.internal.Constants;
import com.sun.org.apache.bcel.internal.generic.ALOAD;
import com.sun.org.apache.bcel.internal.generic.ASTORE;
import com.sun.org.apache.bcel.internal.generic.ArrayType;
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
import com.sun.org.apache.bcel.internal.generic.InstructionConstants;
import com.sun.org.apache.bcel.internal.generic.InstructionFactory;
import com.sun.org.apache.bcel.internal.generic.InstructionHandle;
import com.sun.org.apache.bcel.internal.generic.InstructionList;
import com.sun.org.apache.bcel.internal.generic.LocalVariableGen;
import com.sun.org.apache.bcel.internal.generic.MethodGen;
import com.sun.org.apache.bcel.internal.generic.NEW;
import com.sun.org.apache.bcel.internal.generic.ObjectType;
import com.sun.org.apache.bcel.internal.generic.PUSH;
import com.sun.org.apache.bcel.internal.generic.Type;
import symjava.matrix.ExprVector;
public class Vector extends Tensor {
public int nStart;
public int nDim;
public Vector parent;
protected int indexLVT = -1;
public Vector(String name, int nDim) {
super(name);
this.nStart = 0;
this.nDim = nDim;
}
public Vector(Vector parent, int nStart, int nDim) {
super(parent.label+"_"+nStart+"_"+nDim);
this.nStart = nStart;
this.nDim = nDim;
this.parent = parent;
}
public Vector(Vector parent, String name, int nStart, int nDim) {
super(name);
this.nStart = nStart;
this.nDim = nDim;
this.parent = parent;
}
public ExprVector split(int nBlock) {
int n = nDim/nBlock;
if(nDim%nBlock > 0)
n = (nDim+(nBlock-nDim%nBlock))/nBlock;
int last_n = nDim%n==0?n:nDim%n;
//System.out.println(n);
//System.out.println(last_n);
Expr[] items = new Expr[nBlock];
for(int j=0; j<nBlock-1; j++) {
items[j] = new Vector(this, this.label+"_"+j, j*n, n);
}
items[nBlock-1] = new Vector(this, this.label+"_"+(nBlock-1), (nBlock-1)*n, last_n);
return new ExprVector(items);
}
@Override
public InstructionHandle bytecodeGen(String clsName, MethodGen mg,
ConstantPoolGen cp, InstructionFactory factory,
InstructionList il, Map<String, Integer> argsMap, int argsStartPos,
Map<Expr, Integer> funcRefsMap) {
if(indexLVT == -1) {
//jama.Matrix l_m = null;
LocalVariableGen lg = mg.addLocalVariable("l_"+getLabel(),
new ObjectType("Jama.Matrix"), null, null);
indexLVT = lg.getIndex();
// il.append(InstructionConstants.ACONST_NULL);
// lg.setStart(il.append(new DSTORE(idx)));
// First time touch the matrix, declare a local reference of Java.Matrix
il.append(new NEW(cp.addClass("Jama.Matrix")));
il.append(InstructionConstants.DUP);
//prepare argument: double[] vals
il.append(new ALOAD(argsStartPos));
il.append(new PUSH(cp, argsMap.get(this.label)));
il.append(InstructionConstants.AALOAD); //Load double from array
//prepare argument: double m - number of rows
il.append(new PUSH(cp, nDim));
il.append(factory.createInvoke("Jama.Matrix", "<init>",
Type.VOID, new Type[] { new ArrayType(Type.DOUBLE, 1), Type.INT },
Constants.INVOKESPECIAL));
//jama.Matrix l_m = new jama.Matrix(args[], nRow);
lg.setStart(il.append(new ASTORE(indexLVT)));
}
return il.append(new ALOAD(indexLVT));
//il.append(new ALOAD(indexLVT));
//il.append(new PUSH(cp, 1.0));
//return il.append(InstructionConstants.DRETURN);
}
@Override
public TypeInfo getTypeInfo() {
TypeInfo ti = new TypeInfo(TYPE.VECTOR, new int[1]);
ti.dim[0] = nDim;
return ti;
}
public void bytecodeGenReset() {
this.indexLVT = -1;
}
@Override
public Expr getParent() {
return this.parent;
}
public int dim() {
return this.nDim;
}
public static void main(String[] args) {
Vector v = new Vector("A",8);
ExprVector sv = v.split(3);
System.out.println(sv);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.