1 9 10 package org.lsmp.djep.vectorJep.function; 11 12 import java.util.*; 13 import org.nfunk.jep.*; 14 import org.lsmp.djep.vectorJep.Dimensions; 15 import org.lsmp.djep.vectorJep.values.*; 16 17 23 public class VList extends org.nfunk.jep.function.List 24 implements NaryOperatorI 25 { 26 public VList() 27 { 28 numberOfParameters = -1; 29 } 30 31 32 public Dimensions calcDim(Dimensions dims[]) throws ParseException 33 { 34 return Dimensions.valueOf(dims.length,dims[0]); 35 } 36 37 40 public MatrixValueI calcValue(MatrixValueI res, 41 MatrixValueI inputs[]) throws ParseException 42 { 43 int eleSize = inputs[0].getNumEles(); 44 for(int i=0;i<inputs.length;++i) 45 { 46 for(int j=0;j<eleSize;++j) 47 { 48 res.setEle(i*eleSize+j,inputs[i].getEle(j)); 49 } 50 } 51 return res; 52 } 53 54 public void run(Stack inStack) throws ParseException 55 { 56 checkStack(inStack); if(curNumberOfParameters <1) 58 throw new ParseException("Empty list"); 59 Object param1 = inStack.pop(); 60 61 if(param1 instanceof Vector) 62 { 63 Vector vec1 = (Vector) param1; 64 int rows = curNumberOfParameters; 65 int cols = vec1.size(); 66 Matrix res = new Matrix(rows,cols); 67 for(int j=0;j<cols;++j) 68 res.setEle(rows-1,j,vec1.elementAt(j)); 69 for(int i=rows-2;i>=0;--i) 70 { 71 Vector vec = (Vector) inStack.pop(); 72 for(int j=0;j<cols;++j) 73 res.setEle(i,j,vec.elementAt(j)); 74 } 75 inStack.push(res); 76 return; 77 } 78 else if(param1 instanceof MatrixValueI) 79 { 80 MatrixValueI mat1 = (MatrixValueI) param1; 81 int rows = curNumberOfParameters; 82 int neles = mat1.getNumEles(); 83 MatrixValueI res = Tensor.getInstance(Dimensions.valueOf(rows,mat1.getDim())); 84 for(int j=0;j<neles;++j) 85 res.setEle((rows-1)*neles+j,mat1.getEle(j)); 86 for(int i=rows-2;i>=0;--i) 87 { 88 MatrixValueI mat = (MatrixValueI) inStack.pop(); 89 for(int j=0;j<neles;++j) 90 res.setEle(i*neles+j,mat.getEle(j)); 91 } 92 inStack.push(res); 93 return; 94 } 95 else 96 { 97 MVector res = new MVector(curNumberOfParameters); 98 res.setEle(curNumberOfParameters-1,param1); 99 for(int i=curNumberOfParameters-2;i>=0;--i) 100 { 101 Object param = inStack.pop(); 102 res.setEle(i,param); 103 } 104 inStack.push(res); 105 return; 106 } 107 } 108 } 109 | Popular Tags |