1 8 package org.lsmp.djep.matrixJep; 9 import org.nfunk.jep.*; 10 import org.lsmp.djep.vectorJep.*; 11 import org.lsmp.djep.vectorJep.values.*; 12 import org.lsmp.djep.xjep.*; 13 import org.lsmp.djep.djep.*; 14 import java.util.*; 15 29 public class MatrixVariable extends DVariable implements MatrixVariableI { 30 31 private Dimensions dims; 32 private MatrixValueI mvalue = null; 33 34 35 42 protected PartialDerivative createDerivative(String derivnames[],Node eqn) 43 { 44 return new MatrixPartialDerivative(this,derivnames,eqn); 45 } 46 47 51 MatrixVariable(String name) 52 { 53 super(name); 54 this.dims = Dimensions.ONE; 55 this.mvalue = new Scaler(); 56 setValidValue(false); 57 } 58 59 MatrixVariable(String name,Object value) 60 { 61 super(name); 62 if(value instanceof MatrixValueI) 63 this.mvalue = (MatrixValueI) value; 64 else 65 { 66 this.mvalue = new Scaler(); 67 this.mvalue.setEle(0,value); 68 } 69 this.dims = mvalue.getDim(); 70 setValidValue(true); 71 } 72 73 public Dimensions getDimensions() { return dims; } 74 public void setDimensions(Dimensions dims) { 75 this.dims = dims; 76 this.mvalue=Tensor.getInstance(dims); 77 this.invalidateAll(); 78 } 79 80 81 public MatrixValueI getMValue() { return mvalue; } 82 83 84 public Object getValue() { 85 if(mvalue instanceof Scaler) 86 return mvalue.getEle(0); 87 else 88 return mvalue; 89 } 90 91 96 protected boolean setValueRaw(Object val) { 97 if(val instanceof MatrixValueI) 98 { 99 mvalue = (MatrixValueI) val; 100 this.dims = mvalue.getDim(); 101 } 102 else 103 mvalue.setEle(0,val); 104 return true; 105 } 106 107 public void setMValue(MatrixValueI val) { 108 if(this.isConstant()) return; 109 mvalue.setEles(val); 110 setValidValue(true); 111 setChanged(); 112 notifyObservers(); 113 } 114 115 118 public void print(PrintVisitor bpv) 119 { 120 StringBuffer sb = new StringBuffer (name); 121 sb.append(": "); 122 if(dims!=null) sb.append("dim "+dims.toString()); 123 if(hasValidValue() && mvalue != null) sb.append(" val "+getMValue() ); 124 else sb.append(" null value"); 125 sb.append(" "); 126 if(this.getEquation()!=null) 127 sb.append("eqn "+bpv.toString(this.getEquation())); 128 else 129 sb.append("no equation"); 130 sb.append("\n"); 131 for(java.util.Enumeration e = this.derivatives.elements(); e.hasMoreElements(); ) 132 { 133 MatrixPartialDerivative var = (MatrixPartialDerivative) e.nextElement(); 134 sb.append("\t"+var.toString()+": "); 135 if(var.hasValidValue()) sb.append(" val "+var.getMValue() ); 136 else sb.append(" null value"); 137 sb.append(" "); 138 sb.append(bpv.toString(var.getEquation())); 139 sb.append("\n"); 140 } 141 System.out.print(sb.toString()); 142 } 143 144 145 } 146 | Popular Tags |