public static IVariable Add(ScalarString s, ScalarVal d, bool invert) { double dd = d.GetVal(Globals.tNull); string i = null; if (G.isNumericalError(dd)) { i = "M"; } else { i = dd.ToString(); } string z = null; if (invert) { z = i + s._string2; } else { z = s._string2 + i; } return(new ScalarString(z)); }
public IVariable Indexer(GekkoTime t, bool isLhs, params IVariable[] indexes) { if (indexes.Length == 1) { IVariable index1 = indexes[0]; int i1 = O.GetInt(index1); int d1 = this.data.GetLength(0); int d2 = this.data.GetLength(1); if (d2 == 1) { //1 col: column vector IVariable one = new ScalarVal(1d); IVariable[] newIndex = new IVariable[2]; newIndex[0] = index1; newIndex[1] = one; return(Handle2dIndexer(newIndex)); //we implicitly understand #a[3] as #a[3,1] here. But we cannot do the inverse on a row vector. } G.Writeln("*** ERROR: You are trying to use [" + i1 + "] on a " + d1 + "x" + d2 + " matrix"); G.Writeln(" This notation can only be used regarding nx1 matrices (column vectors)"); throw new GekkoException(); } else if (indexes.Length == 2) { return(Handle2dIndexer(indexes)); } else { G.Writeln2("*** ERROR: Cannot use " + indexes.Length + "-dimensional indexer on MATRIX"); throw new GekkoException(); } }
public static IVariable Add(ScalarDate t, ScalarVal d) { int i = O.GetInt(d); GekkoTime t2 = t.date.Add(i); ScalarDate z = new ScalarDate(t2); return(z); }
public static IVariable Subtract(ScalarDate t, ScalarVal d) { //HMMM, what about rounding up and down here?? int i = O.GetInt(d); GekkoTime t2 = t.date.Add(-i); ScalarDate z = new ScalarDate(t2); return(z); }
public IVariable Indexer(GekkoTime t, bool isLhs, params IVariable[] indexes) { if (indexes.Length == 1) { IVariable index = indexes[0]; //Indices run from 1, 2, 3, ... n. Element 0 is length of list. if (index.Type() == EVariableType.Val) { int ival = O.GetInt(index); if (ival < 0) { G.Writeln2("*** ERROR: Illegal element access [" + ival + "]: negative number not allowed"); throw new GekkoException(); } else if (ival == 0) { ScalarVal a = new ScalarVal(this.list.Count); return(a); } else if (ival > this.list.Count) { G.Writeln2("*** ERROR: Illegal element access [" + ival + "]: larger than length of list (" + this.list.Count + ")"); throw new GekkoException(); } string s = this.list[ival - 1]; IVariable ss = null; ss = new ScalarString(s, isNameList); if (Globals.fixIndexerMaybeTransform) { bool didTransform = false; ss = O.MaybeTransform(ref didTransform, ss, true); } return(ss); } else if (index.Type() == EVariableType.String) { string s5 = ((ScalarString)index)._string2; List <string> found = Program.MatchWildcard(s5, this.list, null); return(new MetaList(found)); } else { G.Writeln2("*** ERROR: Type mismatch regarding []-index"); throw new GekkoException(); } } else { G.Writeln2("*** ERROR: Cannot use " + indexes.Length + "-dimensional indexer on LIST"); throw new GekkoException(); } }
public static IVariable Add(ScalarVal x, MetaTimeSeries ats, GekkoTime t) { //no need to implement swap if (t.IsNull()) { throw new GekkoException(); } TimeSeries ts = ats.ts; double val1 = x.val; double val2 = ts.GetData(t.Add(ats.offset)); return(new ScalarVal(val1 + val2)); }
public IVariable SetData(IVariablesFilterRange indexRange1, IVariablesFilterRange indexRange2, IVariable x3) { int i1 = 1; int i2 = this.data.GetLength(0); int j1 = 1; int j2 = this.data.GetLength(1); if (indexRange1.first != null) { i1 = O.GetInt(indexRange1.first); } if (indexRange1.last != null) { i2 = O.GetInt(indexRange1.last); } if (indexRange2.first != null) { j1 = O.GetInt(indexRange2.first); } if (indexRange2.last != null) { j2 = O.GetInt(indexRange2.last); } if (i1 > i2) { G.Writeln2("*** ERROR: Range " + i1 + ".." + i2 + " is descending"); throw new GekkoException(); } if (j1 > j2) { G.Writeln2("*** ERROR: Range " + j1 + ".." + j2 + " is descending"); throw new GekkoException(); } if (x3.Type() == EVariableType.Matrix) { Matrix m = (Matrix)x3; int dimI = i2 - i1 + 1; int dimJ = j2 - j1 + 1; if (dimI != m.data.GetLength(0) || dimJ != m.data.GetLength(1)) { G.Writeln2("*** ERROR: Left-hand side selection is " + dimI + "x" + dimJ + ", but right-hand matrix is " + m.data.GetLength(0) + "x" + m.data.GetLength(1)); throw new GekkoException(); } try { int ii1 = i1 - 1; int jj1 = j1 - 1; for (int i = i1 - 1; i <= i2 - 1; i++) { for (int j = j1 - 1; j <= j2 - 1; j++) { this.data[i, j] = m.data[i - ii1, j - jj1]; } } return(this); } catch (System.IndexOutOfRangeException e) // CS0168 { G.Writeln("*** ERROR: Left-side index out of range: [" + i1 + " .. " + i2 + ", " + j1 + " .. " + j2 + " ]"); if (i1 == 0 || i2 == 0 || j1 == 0 || j2 == 0) { G.Writeln(" Please note that indicies are 1-based"); } throw new GekkoException(); } } else if (x3.Type() == EVariableType.Val) { ScalarVal v = (ScalarVal)x3; try { int ii1 = i1 - 1; int jj1 = j1 - 1; for (int i = i1 - 1; i <= i2 - 1; i++) { for (int j = j1 - 1; j <= j2 - 1; j++) { this.data[i, j] = v.val; } } return(this); } catch (System.IndexOutOfRangeException e) // CS0168 { G.Writeln("*** ERROR: Left-side index out of range: [" + i1 + " .. " + i2 + ", " + j1 + " .. " + j2 + " ]"); if (i1 == 0 || i2 == 0 || j1 == 0 || j2 == 0) { G.Writeln(" Please note that indicies are 1-based"); } throw new GekkoException(); } } else { G.Writeln2("*** ERROR: Expected right-hand side to be a matrix or a scalar"); throw new GekkoException(); } }