-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathNumMatrix.java
More file actions
67 lines (58 loc) · 1.25 KB
/
NumMatrix.java
File metadata and controls
67 lines (58 loc) · 1.25 KB
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
package symjava.numeric;
import symjava.bytecode.BytecodeBatchFunc;
import symjava.matrix.ExprMatrix;
import symjava.symbolic.Expr;
import symjava.symbolic.utils.JIT;
public class NumMatrix {
public BytecodeBatchFunc func;
int nRow;
int nCol;
double[] lastEvalData;
public NumMatrix() {
}
/**
* Create an empty matrix
* @param m number of rows
* @param n number of columns
*/
public NumMatrix(int m, int n) {
this.nRow = m;
this.nCol = n;
}
public NumMatrix(ExprMatrix sm, Expr[] args) {
this.nRow = sm.rowDim();
this.nCol = sm.colDim();
Expr[] exprs = new Expr[nRow*nCol];
int idx = 0;
for(int i=0; i<nRow; i++) {
for(int j=0; j<nCol; j++) {
exprs[idx++] = sm.get(i, j);
}
}
this.func = JIT.compileBatchFunc(args, exprs);
}
public int rowDim() {
return nRow;
}
public int colDim() {
return nCol;
}
/**
* Return result: row by row
* @param args
* @return
*/
public void eval(double[] outAry, double ...args) {
func.apply(outAry, 0, args);
this.lastEvalData = outAry;
}
public double[][] copyData() {
int m = rowDim();
int n = colDim();
double [][] ret = new double[m][n];
for(int i=0; i<m; i++) {
System.arraycopy(this.lastEvalData, i*n, ret[i], 0, nCol);
}
return ret;
}
}