/// <summary> /// Tries to multiply a scalar to the current element. /// </summary> /// <param name="Scalar">Scalar to multiply.</param> /// <returns>Result, if understood, null otherwise.</returns> public override IVectorSpaceElement MultiplyScalar(IFieldElement Scalar) { ComplexNumber ComplexNumber = Scalar as ComplexNumber; Complex d; if (ComplexNumber == null) { DoubleNumber DoubleNumber = Scalar as DoubleNumber; if (DoubleNumber == null) { return(null); } else { d = new Complex(DoubleNumber.Value, 0); } } else { d = ComplexNumber.Value; } int i; Complex[] Values = this.Values; Complex[] v = new Complex[this.dimension]; for (i = 0; i < this.dimension; i++) { v[i] = d * Values[i]; } return(new ComplexVector(v)); }
/// <summary> /// Evaluates the function on two scalar arguments. /// </summary> /// <param name="Argument1">Function argument 1.</param> /// <param name="Argument2">Function argument 2.</param> /// <param name="Variables">Variables collection.</param> /// <returns>Function result.</returns> public override IElement EvaluateScalar(IElement Argument1, IElement Argument2, Variables Variables) { StringValue S = Argument1 as StringValue; if (S == null) { throw new ScriptRuntimeException("Expected string in first argument.", this); } DoubleNumber N = Argument2 as DoubleNumber; double d; if (N == null || (d = N.Value) < 0 || d > int.MaxValue || d != Math.Truncate(d)) { throw new ScriptRuntimeException("Expected nonnegative integer in second argument.", this); } int i = (int)d; string s = S.Value; if (i > s.Length) { return(S); } else { return(new StringValue(s.Substring(s.Length - i, i))); } }
/// <summary> /// Tries to multiply an element to the current element, from the left. /// </summary> /// <param name="Element">Element to multiply.</param> /// <returns>Result, if understood, null otherwise.</returns> public override IRingElement MultiplyLeft(IRingElement Element) { double[,] Values = this.Values; DoubleNumber Number = Element as DoubleNumber; DoubleMatrix Matrix; double[,] v; double n; int x, y, z; if (!(Number is null)) { n = Number.Value; v = new double[this.rows, this.columns]; for (y = 0; y < this.rows; y++) { for (x = 0; x < this.columns; x++) { v[y, x] = n * Values[y, x]; } } return(new DoubleMatrix(v)); }
/// <summary> /// Evaluates the operator on scalar operands. /// </summary> /// <param name="Operand">Operand.</param> /// <param name="Variables">Variables collection.</param> /// <returns>Result</returns> public override IElement EvaluateScalar(IElement Operand, Variables Variables) { DoubleNumber D = Operand as DoubleNumber; if (!(D is null)) { return(new PhysicalQuantity(D.Value, this.unit)); } PhysicalQuantity Q = Operand as PhysicalQuantity; if (!(Q is null)) { double Magnitude; if (Unit.TryConvert(Q.Magnitude, Q.Unit, this.unit, out Magnitude)) { return(new PhysicalQuantity(Magnitude, this.unit)); } else { throw new ScriptRuntimeException("Unable to convert from " + Q.Unit.ToString() + " to " + this.unit.ToString() + ".", this); } } throw new ScriptRuntimeException("Unable to set physical unit.", this); }
/// <summary> /// Evaluates the node, using the variables provided in the <paramref name="Variables"/> collection. /// </summary> /// <param name="Variables">Variables collection.</param> /// <returns>Result.</returns> public override IElement Evaluate(Variables Variables) { IElement Left = this.left.Evaluate(Variables); IVector V = Left as IVector; if (V == null) { throw new ScriptRuntimeException("Vector element assignment can only be performed on vectors.", this); } IElement Index = this.middle.Evaluate(Variables); DoubleNumber IE = Index as DoubleNumber; double d; if (IE == null || (d = IE.Value) < 0 || d > int.MaxValue || d != Math.Truncate(d)) { throw new ScriptRuntimeException("Index must be a non-negative integer.", this); } IElement Value = this.right.Evaluate(Variables); V.SetElement((int)d, Value); return(Value); }
/// <summary> /// Evaluates the operator. /// </summary> /// <param name="Operand">Operand.</param> /// <returns>Result</returns> public virtual IElement Evaluate(IElement Operand) { DoubleNumber DOp = Operand as DoubleNumber; if (DOp != null) { double d = DOp.Value; return(new DoubleNumber(d * d * d)); } IRingElement E = Operand as IRingElement; if (E != null) { IRingElement E2 = (IRingElement)Multiply.EvaluateMultiplication(E, E, this); return(Multiply.EvaluateMultiplication(E2, E, this)); } if (Operand.IsScalar) { throw new ScriptRuntimeException("Scalar operands must be double values or ring elements.", this); } LinkedList <IElement> Result = new LinkedList <IElement>(); foreach (IElement Child in Operand.ChildElements) { Result.AddLast(this.Evaluate(Child)); } return(Operand.Encapsulate(Result, this)); }
/// <summary> /// Evaluates the node, using the variables provided in the <paramref name="Variables"/> collection. /// </summary> /// <param name="Variables">Variables collection.</param> /// <returns>Result.</returns> public override IElement Evaluate(Variables Variables) { IElement Left = this.left.Evaluate(Variables); IMatrix M = Left as IMatrix; if (M == null) { throw new ScriptRuntimeException("Matrix element assignment can only be performed on matrices.", this); } IElement ColIndex = this.middle.Evaluate(Variables); IElement RowIndex = this.middle2.Evaluate(Variables); DoubleNumber X = ColIndex as DoubleNumber; DoubleNumber Y = RowIndex as DoubleNumber; double x, y; if (X == null || (x = X.Value) < 0 || x > int.MaxValue || x != Math.Truncate(x) || Y == null || (y = Y.Value) < 0 || y > int.MaxValue || y != Math.Truncate(y)) { throw new ScriptRuntimeException("Indices must be non-negative integers.", this); } IElement Value = this.right.Evaluate(Variables); M.SetElement((int)x, (int)y, Value); return(Value); }
static void Main(string[] args) { Number number = new Number(); number.RecursionNumber(new int[] { 1, 2, 3, 4, 5, 5 }); number.RecursionNumber(123); Line line = new Line(); line.RecursionString(new string[] { "God" }); line.RecursionString(); DoubleNumber doubleNumber = new DoubleNumber(); doubleNumber.Sort(); MagicSing magicSing = new MagicSing(); magicSing.MagicRecursion(new string[2] { "Nikita", "Dut" }); Don_tReverse don_TReverse = new Don_tReverse(); don_TReverse.DoReveres(); int[] num; don_TReverse.DoReveres3(out num); num = new int[] { 1, 2, 3, 4 }; don_TReverse.DoReveres4(ref num); }
static void Main(string[] args) { Number number = new Number(); number.RecursionNumber(new int[] { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }); number.RecursionNumber(0123456789); Line line = new Line(); line.RecursionString(new string[] { "Something" }); line.RecursionString(); DoubleNumber doubleNumber = new DoubleNumber(); doubleNumber.Sort(); MagicSing magicSing = new MagicSing(); magicSing.MagicRecursion(new string[2] { "Something", "gnihtemoS" }); Don_tReverse don_TReverse = new Don_tReverse(); don_TReverse.DoReveres(); int[] num; don_TReverse.DoReveres3(out num); num = new int[] { 1, 2, 3, 4 }; don_TReverse.DoReveres4(ref num); }
/// <summary> /// Evaluates the node, using the variables provided in the <paramref name="Variables"/> collection. /// </summary> /// <param name="Variables">Variables collection.</param> /// <returns>Result.</returns> public override IElement Evaluate(Variables Variables) { Variable v; if (!Variables.TryGetVariable(this.variableName, out v)) { throw new ScriptRuntimeException("Variable not found: " + this.variableName, this); } IElement Value = v.ValueElement; IElement Value2; DoubleNumber n = Value as DoubleNumber; if (n != null) { Value2 = new DoubleNumber(n.Value + 1); } else { Value2 = PreIncrement.Increment(Value, this); } Variables[this.variableName] = Value2; return(Value); }
/// <summary> /// Evaluates the operator on scalar operands. /// </summary> /// <param name="Left">Left value.</param> /// <param name="Right">Right value.</param> /// <param name="Variables">Variables collection.</param> /// <returns>Result</returns> public override IElement EvaluateScalar(IElement Left, IElement Right, Variables Variables) { DoubleNumber DR = Right as DoubleNumber; if (Left is DoubleNumber DL && !(DR is null)) { return(new DoubleNumber(DL.Value / DR.Value)); }
/// <summary> /// Draws the graph on a canvas. /// </summary> /// <param name="Canvas">Canvas to draw on.</param> /// <param name="Points">Points to draw.</param> /// <param name="Parameters">Graph-specific parameters.</param> /// <param name="PrevPoints">Points of previous graph of same type (if available), null (if not available).</param> /// <param name="PrevParameters">Parameters of previous graph of same type (if available), null (if not available).</param> /// <param name="DrawingArea">Current drawing area.</param> public void DrawGraph(SKCanvas Canvas, SKPoint[] Points, object[] Parameters, SKPoint[] PrevPoints, object[] PrevParameters, DrawingArea DrawingArea) { SKPaint Brush = null; SKPath Path = null; try { Brush = new SKPaint() { Style = SKPaintStyle.Fill, Color = Graph.ToColor(Parameters[0]) }; Path = new SKPath(); Path = Plot2DCurvePainter.CreateSpline(Points); if (PrevPoints is null) { IElement Zero; ISet Set = DrawingArea.MinY.AssociatedSet; if (Set is IGroup Group) { Zero = Group.AdditiveIdentity; } else { Zero = new DoubleNumber(0); } IVector XAxis = VectorDefinition.Encapsulate(new IElement[] { DrawingArea.MinX, DrawingArea.MaxX }, false, null) as IVector; IVector YAxis = VectorDefinition.Encapsulate(new IElement[] { Zero, Zero }, false, null) as IVector; PrevPoints = DrawingArea.Scale(XAxis, YAxis); if (DrawingArea.MinX is StringValue && DrawingArea.MaxX is StringValue) { PrevPoints[0].X = Points[0].X; PrevPoints[1].X = Points[Points.Length - 1].X; } } PrevPoints = (SKPoint[])PrevPoints.Clone(); Array.Reverse(PrevPoints); Plot2DCurvePainter.CreateSpline(Path, PrevPoints); Path.LineTo(Points[0]); Canvas.DrawPath(Path, Brush); } finally { Brush?.Dispose(); Path?.Dispose(); } }
/// <summary> /// Tries to multiply an element to the current element, from the right. /// </summary> /// <param name="Element">Element to multiply.</param> /// <returns>Result, if understood, null otherwise.</returns> public override IRingElement MultiplyRight(IRingElement Element) { double[,] Values = this.Values; DoubleNumber Number = Element as DoubleNumber; DoubleMatrix Matrix; double[,] v; double n; int x, y, z; if (Number != null) { n = Number.Value; v = new double[this.rows, this.columns]; for (y = 0; y < this.rows; y++) { for (x = 0; x < this.columns; x++) { v[y, x] = n * Values[y, x]; } } return(new DoubleMatrix(v)); } else if ((Matrix = Element as DoubleMatrix) != null) { if (this.columns != Matrix.rows) { return(null); } double[,] Values2 = Matrix.Values; v = new double[this.rows, Matrix.columns]; for (y = 0; y < this.rows; y++) { for (x = 0; x < Matrix.columns; x++) { n = 0; for (z = 0; z < this.columns; z++) { n += Values[y, z] * Values2[z, x]; } v[y, x] = n; } } return(new DoubleMatrix(v)); } else { return(null); } }
/// <summary> /// Evaluates the node, using the variables provided in the <paramref name="Variables"/> collection. /// </summary> /// <param name="Variables">Variables collection.</param> /// <returns>Result.</returns> public override IElement Evaluate(Variables Variables) { IElement L = this.left.Evaluate(Variables); IElement R = this.right.Evaluate(Variables); DoubleNumber DR = R as DoubleNumber; if (L is DoubleNumber DL && !(DR is null)) { return(this.Evaluate(DL.Value, DR.Value)); }
/// <summary> /// Evaluates the operator on scalar operands. /// </summary> /// <param name="Left">Left value.</param> /// <param name="Right">Right value.</param> /// <param name="Variables">Variables collection.</param> /// <returns>Result</returns> public override IElement EvaluateScalar(IElement Left, IElement Right, Variables Variables) { DoubleNumber DL = Left as DoubleNumber; DoubleNumber DR = Right as DoubleNumber; if (DL != null && DR != null) { return(this.Evaluate(DL.Value, DR.Value)); } else { double l, r; PhysicalQuantity Q; if (DL != null) { l = DL.Value; } else { Q = Left as PhysicalQuantity; if (Q != null) { l = Q.Magnitude; } else { throw new ScriptRuntimeException("Scalar operands must be double values or physical magnitudes.", this); } } if (DR != null) { r = DR.Value; } else { Q = Right as PhysicalQuantity; if (Q != null) { r = Q.Magnitude; } else { throw new ScriptRuntimeException("Scalar operands must be double values or physical magnitudes.", this); } } return(this.Evaluate(l, r)); } }
/// <summary> /// Evaluates the operator on scalar operands. /// </summary> /// <param name="Left">Left value.</param> /// <param name="Right">Right value.</param> /// <param name="Variables">Variables collection.</param> /// <returns>Result</returns> public override IElement EvaluateScalar(IElement Left, IElement Right, Variables Variables) { DoubleNumber DL = Left as DoubleNumber; DoubleNumber DR = Right as DoubleNumber; if (DL != null && DR != null) { return(new DoubleNumber(DL.Value * DR.Value)); } else { return(Multiply.EvaluateMultiplication(Left, Right, this)); } }
/// <summary> /// Tries to add an element to the current element. /// </summary> /// <param name="Element">Element to add.</param> /// <returns>Result, if understood, null otherwise.</returns> public override IAbelianGroupElement Add(IAbelianGroupElement Element) { double[,] Values = this.Values; DoubleNumber Number = Element as DoubleNumber; DoubleMatrix Matrix; double[,] v; double n; int x, y; if (Number != null) { n = Number.Value; v = new double[this.rows, this.columns]; for (y = 0; y < this.rows; y++) { for (x = 0; x < this.columns; x++) { v[y, x] = n + Values[y, x]; } } return(new DoubleMatrix(v)); } else if ((Matrix = Element as DoubleMatrix) != null) { if (this.columns != Matrix.columns || this.rows != Matrix.rows) { return(null); } double[,] Values2 = Matrix.Values; v = new double[this.rows, this.columns]; for (y = 0; y < this.rows; y++) { for (x = 0; x < this.columns; x++) { v[y, x] = Values[y, x] + Values2[y, x]; } } return(new DoubleMatrix(v)); } else { return(null); } }
/// <summary> /// Evaluates the node, using the variables provided in the <paramref name="Variables"/> collection. /// </summary> /// <param name="Variables">Variables collection.</param> /// <returns>Result.</returns> public override IElement Evaluate(Variables Variables) { IElement From = this.left.Evaluate(Variables); IElement To = this.middle.Evaluate(Variables); IElement StepSize = this.right?.Evaluate(Variables); DoubleNumber S = StepSize as DoubleNumber; if (!(From is DoubleNumber F) || !(To is DoubleNumber T) || (S is null && !(StepSize is null))) { throw new ScriptRuntimeException("The interval operator requires double-valued operands.", this); } return(new Objects.Sets.Interval(F.Value, T.Value, true, true, S is null ? (double?)null : S.Value)); }
public void BackwardNeuron() { sGate1.Backward(); aGate2.Backward(); aGate1.Backward(); mGate2.Backward(); mGate1.Backward(); var step_size = new DoubleNumber(0.01); a.Value = a.Value.AddMe(step_size.MultiplyMe(a.Gradient)); b.Value = b.Value.AddMe(step_size.MultiplyMe(b.Gradient)); c.Value = c.Value.AddMe(step_size.MultiplyMe(b.Gradient)); x.Value = x.Value.AddMe(step_size.MultiplyMe(x.Gradient)); y.Value = y.Value.AddMe(step_size.MultiplyMe(y.Gradient)); }
/// <summary> /// Evaluates the node, using the variables provided in the <paramref name="Variables"/> collection. /// </summary> /// <param name="Variables">Variables collection.</param> /// <returns>Result.</returns> public override IElement Evaluate(Variables Variables) { IElement L = this.left.Evaluate(Variables); IElement R = this.right.Evaluate(Variables); DoubleNumber DL = L as DoubleNumber; DoubleNumber DR = R as DoubleNumber; if (DL != null && DR != null) { return(this.Evaluate(DL.Value, DR.Value)); } else { return(this.Evaluate(L, R, Variables)); } }
/// <summary> /// Evaluates the node, using the variables provided in the <paramref name="Variables"/> collection. /// </summary> /// <param name="Variables">Variables collection.</param> /// <returns>Result.</returns> public override IElement Evaluate(Variables Variables) { IElement From = this.left.Evaluate(Variables); IElement To = this.middle.Evaluate(Variables); IElement StepSize = this.right == null ? null : this.right.Evaluate(Variables); DoubleNumber F = From as DoubleNumber; DoubleNumber T = To as DoubleNumber; DoubleNumber S = StepSize as DoubleNumber; if (F == null || T == null || (S == null && StepSize != null)) { throw new ScriptRuntimeException("The interval operator requires double-valued operands.", this); } return(new Objects.Sets.Interval(F.Value, T.Value, true, true, S == null ? (double?)null : S.Value)); }
public FlameFunction(DoubleMatrix M, ScriptNode Node) { double[,] E = M.Values; this.homogeneousTransform = new double[9]; this.node = Node; this.xv = new DoubleNumber(0); this.yv = new DoubleNumber(0); this.zv = new ComplexNumber(0); this.doubleParameters = new IElement[] { xv, yv }; this.complexParameters = new IElement[] { zv }; if (M.Columns == 2 && M.Rows == 2) { this.homogeneousTransform[0] = (double)E[0, 0]; this.homogeneousTransform[1] = (double)E[0, 1]; this.homogeneousTransform[2] = 0; this.homogeneousTransform[3] = (double)E[1, 0]; this.homogeneousTransform[4] = (double)E[1, 1]; this.homogeneousTransform[5] = 0; this.homogeneousTransform[6] = 0; this.homogeneousTransform[7] = 0; this.homogeneousTransform[8] = 1; this.hasProjection = false; } else if (M.Columns == 3 && M.Rows == 3) { this.homogeneousTransform[0] = (double)E[0, 0]; this.homogeneousTransform[1] = (double)E[0, 1]; this.homogeneousTransform[2] = (double)E[0, 2]; this.homogeneousTransform[3] = (double)E[1, 0]; this.homogeneousTransform[4] = (double)E[1, 1]; this.homogeneousTransform[5] = (double)E[1, 2]; this.homogeneousTransform[6] = (double)E[2, 0]; this.homogeneousTransform[7] = (double)E[2, 1]; this.homogeneousTransform[8] = (double)E[2, 2]; this.hasProjection = this.homogeneousTransform[6] != 0 || this.homogeneousTransform[7] != 0 || this.homogeneousTransform[8] != 1; } else { throw new ScriptRuntimeException("Linear transformation must be a 2D or homogeneous 2D transformation.", Node); } }
/// <summary> /// Evaluates the node, using the variables provided in the <paramref name="Variables"/> collection. /// </summary> /// <param name="Variables">Variables collection.</param> /// <returns>Result.</returns> public override IElement Evaluate(Variables Variables) { try { IElement E = this.Argument.Evaluate(Variables); DoubleNumber D = E as DoubleNumber; if (D != null) { if (double.IsNaN(D.Value)) { return(BooleanValue.False); } else { return(BooleanValue.True); } } ComplexNumber C = E as ComplexNumber; if (C != null) { if (double.IsNaN(C.Value.Real) || double.IsNaN(C.Value.Imaginary)) { return(BooleanValue.False); } else { return(BooleanValue.True); } } ObjectValue O = E as ObjectValue; if (O != null && O.Value == null) { return(BooleanValue.False); } else { return(BooleanValue.True); } } catch (Exception) { return(BooleanValue.False); } }
/// <summary> /// Evaluates the node, using the variables provided in the <paramref name="Variables"/> collection. /// </summary> /// <param name="Variables">Variables collection.</param> /// <returns>Result.</returns> public override IElement Evaluate(Variables Variables) { IElement L = this.left.Evaluate(Variables); IElement R = null; if (this.bothDouble.HasValue && this.bothDouble.Value) { DoubleNumber DL = L as DoubleNumber; DoubleNumber DR = R as DoubleNumber; if (!(DL is null) && !(DR is null)) { return(this.Evaluate(DL.Value, DR.Value)); } else { this.bothDouble = false; } }
/// <summary> /// Sets an element in the vector. /// </summary> /// <param name="Index">Index.</param> /// <param name="Value">Element to set.</param> public override void SetElement(int Index, IElement Value) { if (Index < 0 || Index >= this.dimension) { throw new ScriptException("Index out of bounds."); } DoubleNumber V = Value as DoubleNumber; if (V == null) { throw new ScriptException("Elements in a double vector are required to be double values."); } double[] Values = this.Values; this.elements = null; Values[Index] = V.Value; }
/// <summary> /// Sets an element in the matrix. /// </summary> /// <param name="Column">Zero-based column index into the matrix.</param> /// <param name="Row">Zero-based row index into the matrix.</param> /// <param name="Value">Element value.</param> public void SetElement(int Column, int Row, IElement Value) { if (Column < 0 || Column >= this.columns || Row < 0 || Row >= this.rows) { throw new ScriptException("Index out of bounds."); } DoubleNumber V = Value as DoubleNumber; if (V == null) { throw new ScriptException("Elements in a double matrix must be double values."); } double[,] M = this.Values; this.elements = null; M[Row, Column] = V.Value; }
/// <summary> /// Evaluates the function on two scalar arguments. /// </summary> /// <param name="Arguments">Function arguments.</param> /// <param name="Variables">Variables collection.</param> /// <returns>Function result.</returns> public override IElement Evaluate(IElement[] Arguments, Variables Variables) { StringValue S = Arguments[0] as StringValue; if (S == null) { throw new ScriptRuntimeException("Expected string in first argument.", this); } DoubleNumber Start = Arguments[1] as DoubleNumber; DoubleNumber Len = Arguments[2] as DoubleNumber; double d; if (Start == null || (d = Start.Value) < 0 || d > int.MaxValue || d != Math.Truncate(d)) { throw new ScriptRuntimeException("Expected nonnegative integer in second argument.", this); } int pos = (int)d; if (Len == null || (d = Start.Value) < 0 || d > int.MaxValue || d != Math.Truncate(d)) { throw new ScriptRuntimeException("Expected nonnegative integer in third argument.", this); } string s = S.Value; int n = (int)d; int len = s.Length; if (pos > len) { return(StringValue.Empty); } else if (pos + n >= len) { return(new StringValue(s.Substring(pos))); } else { return(new StringValue(s.Substring(pos, n))); } }
/// <summary> /// Evaluates the node, using the variables provided in the <paramref name="Variables"/> collection. /// </summary> /// <param name="Variables">Variables collection.</param> /// <returns>Result.</returns> public override IElement Evaluate(Variables Variables) { if (!Variables.TryGetVariable(this.variableName, out Variable v)) { throw new ScriptRuntimeException("Variable not found: " + this.variableName, this); } IElement Value = v.ValueElement; if (Value is DoubleNumber n) { Value = new DoubleNumber(n.Value + 1); } else { Value = Increment(Value, this); } Variables[this.variableName] = Value; return(Value); }
/// <summary> /// Tries to multiply a scalar to the current element. /// </summary> /// <param name="Scalar">Scalar to multiply.</param> /// <returns>Result, if understood, null otherwise.</returns> public override IVectorSpaceElement MultiplyScalar(IFieldElement Scalar) { DoubleNumber DoubleNumber = Scalar as DoubleNumber; if (DoubleNumber == null) { return(null); } double d = DoubleNumber.Value; int i; double[] Values = this.Values; double[] v = new double[this.dimension]; for (i = 0; i < this.dimension; i++) { v[i] = d * Values[i]; } return(new DoubleVector(v)); }
/// <summary> /// Checks if the set contains an element. /// </summary> /// <param name="Element">Element.</param> /// <returns>If the element is contained in the set.</returns> public override bool Contains(IElement Element) { DoubleNumber n = Element as DoubleNumber; if (n == null) { return(false); } double d = n.Value; if (d == this.from) { return(this.includesFrom); } else if (d == this.to) { return(this.includesTo); } else { return(d > this.from && d < this.to); } }
/// <summary> /// Evaluates the node, using the variables provided in the <paramref name="Variables"/> collection. /// </summary> /// <param name="Variables">Variables collection.</param> /// <returns>Result.</returns> public override IElement Evaluate(Variables Variables) { IElement Left = this.left.Evaluate(Variables); IMatrix M = Left as IMatrix; if (M is null) { throw new ScriptRuntimeException("Matrix column vector assignment can only be performed on matrices.", this); } IElement Index = this.middle.Evaluate(Variables); DoubleNumber IE = Index as DoubleNumber; double d; if (IE is null || (d = IE.Value) < 0 || d > int.MaxValue || d != Math.Truncate(d)) { throw new ScriptRuntimeException("Index must be a non-negative integer.", this); } IElement Value = this.right.Evaluate(Variables); IVector V = Value as IVector; if (V is null) { throw new ScriptRuntimeException("Matrix columns must be vectors.", this); } if (M.Rows != V.Dimension) { throw new ScriptRuntimeException("Vector dimension does not match number of rows in matrix.", this); } M.SetColumn((int)d, V); return(Value); }
private Expr _Numericize(DoubleNumber n) { return n; }
private Expr _Canonicalize(DoubleNumber n) { return n; }