Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
RowVector.cs
1using System;
2using System.Threading.Tasks;
7
9{
14 {
24 public RowVector(ScriptNode Left, ScriptNode Y, bool NullCheck, int Start, int Length, Expression Expression)
25 : base(Left, Y, NullCheck, Start, Length, Expression)
26 {
27 }
28
35 {
36 IElement Left = this.left.Evaluate(Variables);
37 if (this.nullCheck && Left.AssociatedObjectValue is null)
38 return Left;
39
40 IElement Right = this.right.Evaluate(Variables);
41
42 return EvaluateIndex(Left, Right, this.nullCheck, this);
43 }
44
50 public override async Task<IElement> EvaluateAsync(Variables Variables)
51 {
52 if (!this.isAsync)
53 return this.Evaluate(Variables);
54
55 IElement Left = await this.left.EvaluateAsync(Variables);
56 if (this.nullCheck && Left.AssociatedObjectValue is null)
57 return Left;
58
59 IElement Right = await this.right.EvaluateAsync(Variables);
60
61 return EvaluateIndex(Left, Right, this.nullCheck, this);
62 }
71 public static IElement EvaluateIndex(IElement Matrix, IElement Index, bool NullCheck, ScriptNode Node)
72 {
73 if (Matrix is IMatrix M)
74 return EvaluateIndex(M, Index, Node);
75 else if (Matrix.IsScalar)
76 {
77 if (NullCheck && Matrix.AssociatedObjectValue is null)
78 return Matrix;
79
80 throw new ScriptRuntimeException("The row index operator operates on matrices.", Node);
81 }
82 else
83 {
85
86 foreach (IElement E in Matrix.ChildElements)
87 Elements.Add(EvaluateIndex(E, Index, NullCheck, Node));
88
89 return Matrix.Encapsulate(Elements, Node);
90 }
91 }
92
100 public static IElement EvaluateIndex(IMatrix Matrix, IElement Index, ScriptNode Node)
101 {
102 if (Index.AssociatedObjectValue is double d)
103 {
104 if (d < 0 || d > int.MaxValue || d != Math.Truncate(d))
105 throw new ArgumentNonNegativeIntegerScriptException("Row Index", Node);
106
107 return Matrix.GetRow((int)d);
108 }
109
110 if (Index.IsScalar)
111 throw new ArgumentNonNegativeIntegerScriptException("Row Index", Node);
112 else
113 {
115
116 foreach (IElement E in Index.ChildElements)
117 Elements.Add(EvaluateIndex(Matrix, E, Node));
118
119 return Index.Encapsulate(Elements, Node);
120 }
121 }
122
123 }
124}
A chunked list is a linked list of chunks of objects of type T .
Definition: ChunkedList.cs:54
Class managing a script expression.
Definition: Expression.cs:41
ScriptNode right
Right operand.
ScriptNode left
Left operand.
bool isAsync
If subtree is asynchroneous.
Base class for all unary operators performing operand null checks.
readonly bool nullCheck
If null should be returned if operand is null.
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
static IElement EvaluateIndex(IMatrix Matrix, IElement Index, ScriptNode Node)
Evaluates the row index operator.
Definition: RowVector.cs:100
static IElement EvaluateIndex(IElement Matrix, IElement Index, bool NullCheck, ScriptNode Node)
Evaluates the row index operator.
Definition: RowVector.cs:71
RowVector(ScriptNode Left, ScriptNode Y, bool NullCheck, int Start, int Length, Expression Expression)
Row Vector operator.
Definition: RowVector.cs:24
override async Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
Definition: RowVector.cs:50
override IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
Definition: RowVector.cs:34
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:21
object AssociatedObjectValue
Associated object value.
Definition: IElement.cs:34
ICollection< IElement > ChildElements
An enumeration of child elements. If the element is a scalar, this property will return null.
Definition: IElement.cs:50
IElement Encapsulate(ChunkedList< IElement > Elements, ScriptNode Node)
Encapsulates a set of elements into a similar structure as that provided by the current element.
bool IsScalar
If the element represents a scalar value.
Definition: IElement.cs:42
Basic interface for matrices.
Definition: IMatrix.cs:7
IVector GetRow(int Row)
Gets a row vector from the matrix.