Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
MatrixIndexAssignment.cs
1using System;
2using System.Threading.Tasks;
8
10{
15 {
26 {
27 }
28
35 {
36 IElement Left = this.left.Evaluate(Variables);
37 if (!(Left is IMatrix M))
38 throw new ScriptRuntimeException("Matrix element assignment can only be performed on matrices.", this);
39
40 IElement ColIndex = this.middle.Evaluate(Variables);
41 IElement RowIndex = this.middle2.Evaluate(Variables);
42
43 if (!(ColIndex.AssociatedObjectValue is double x) || x < 0 || x > int.MaxValue || x != Math.Truncate(x) ||
44 !(RowIndex.AssociatedObjectValue is double y) || y < 0 || y > int.MaxValue || y != Math.Truncate(y))
45 {
46 throw new ScriptRuntimeException("Indices must be non-negative integers.", this);
47 }
48
49 IElement Value = this.right.Evaluate(Variables);
50
51 M.SetElement((int)x, (int)y, Value);
52
53 return Value;
54 }
55
61 public override async Task<IElement> EvaluateAsync(Variables Variables)
62 {
63 if (!this.isAsync)
64 return this.Evaluate(Variables);
65
66 IElement Left = await this.left.EvaluateAsync(Variables);
67 if (!(Left is IMatrix M))
68 throw new ScriptRuntimeException("Matrix element assignment can only be performed on matrices.", this);
69
70 IElement ColIndex = await this.middle.EvaluateAsync(Variables);
71 IElement RowIndex = await this.middle2.EvaluateAsync(Variables);
72
73 if (!(ColIndex.AssociatedObjectValue is double x) || x < 0 || x > int.MaxValue || x != Math.Truncate(x) ||
74 !(RowIndex.AssociatedObjectValue is double y) || y < 0 || y > int.MaxValue || y != Math.Truncate(y))
75 {
76 throw new ScriptRuntimeException("Indices must be non-negative integers.", this);
77 }
78
79 IElement Value = await this.right.EvaluateAsync(Variables);
80
81 M.SetElement((int)x, (int)y, Value);
82
83 return Value;
84 }
85
86 }
87}
Class managing a script expression.
Definition: Expression.cs:39
ScriptNode RightOperand
Right operand.
ScriptNode LeftOperand
Left operand.
ScriptNode right
Right operand.
ScriptNode left
Left operand.
bool isAsync
If subtree is asynchroneous.
Base class for all quaternary operators.
ScriptNode middle2
Second Middle operand.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
abstract IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection. This method should be ...
virtual Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection. This method should be ...
Definition: ScriptNode.cs:158
ScriptNode middle
Middle operand.
ScriptNode MiddleOperand
Middle operand.
override IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
MatrixIndexAssignment(MatrixIndex MatrixIndex, ScriptNode Operand, int Start, int Length, Expression Expression)
Matrix Index Assignment operator.
override async Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20
object AssociatedObjectValue
Associated object value.
Definition: IElement.cs:33
Basic interface for matrices.
Definition: IMatrix.cs:9