Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
MatrixRowAssignment.cs
1using System;
2using System.Threading.Tasks;
8
10{
15 {
25 : base(MatrixRow.LeftOperand, MatrixRow.RightOperand, Operand, Start, Length, Expression)
26 {
27 }
28
35 {
36 IElement Left = this.left.Evaluate(Variables);
37 if (!(Left is IMatrix M))
38 throw new ScriptRuntimeException("Matrix row vector assignment can only be performed on matrices.", this);
39
40 IElement Index = this.middle.Evaluate(Variables);
41
42 if (!(Index.AssociatedObjectValue is double d) || d < 0 || d > int.MaxValue || d != Math.Truncate(d))
43 throw new ScriptRuntimeException("Index must be a non-negative integer.", this);
44
45 IElement Value = this.right.Evaluate(Variables);
46 if (!(Value is IVector V))
47 throw new ScriptRuntimeException("Matrix rows must be vectors.", this);
48
49 if (M.Columns != V.Dimension)
50 throw new ScriptRuntimeException("Vector dimension does not match number of columns in matrix.", this);
51
52 M.SetRow((int)d, V);
53
54 return Value;
55 }
56
62 public override async Task<IElement> EvaluateAsync(Variables Variables)
63 {
64 if (!this.isAsync)
65 return this.Evaluate(Variables);
66
67 IElement Left = await this.left.EvaluateAsync(Variables);
68 if (!(Left is IMatrix M))
69 throw new ScriptRuntimeException("Matrix row vector assignment can only be performed on matrices.", this);
70
71 IElement Index = await this.middle.EvaluateAsync(Variables);
72
73 if (!(Index.AssociatedObjectValue is double d) || d < 0 || d > int.MaxValue || d != Math.Truncate(d))
74 throw new ScriptRuntimeException("Index must be a non-negative integer.", this);
75
76 IElement Value = await this.right.EvaluateAsync(Variables);
77 if (!(Value is IVector V))
78 throw new ScriptRuntimeException("Matrix rows must be vectors.", this);
79
80 if (M.Columns != V.Dimension)
81 throw new ScriptRuntimeException("Vector dimension does not match number of columns in matrix.", this);
82
83 M.SetRow((int)d, V);
84
85 return Value;
86 }
87
88 }
89}
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 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
Base class for all ternary operators.
ScriptNode middle
Middle operand.
override IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
MatrixRowAssignment(RowVector MatrixRow, ScriptNode Operand, int Start, int Length, Expression Expression)
Matrix Row 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
Basic interface for vectors.
Definition: IVector.cs:9