Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
BinaryElementWiseDoubleOperator.cs
1using System;
2using System.Threading.Tasks;
6
7namespace Waher.Script.Model
8{
13 {
23 : base(Left, Right, Start, Length, Expression)
24 {
25 }
26
33 {
34 IElement L = this.left.Evaluate(Variables);
35 IElement R = this.right.Evaluate(Variables);
36
37 if (L.AssociatedObjectValue is double DL && R.AssociatedObjectValue is double DR)
38 return this.Evaluate(DL, DR);
39 else
40 return this.Evaluate(L, R, Variables);
41 }
42
48 public override async Task<IElement> EvaluateAsync(Variables Variables)
49 {
50 if (!this.isAsync)
51 return this.Evaluate(Variables);
52
53 IElement L = await this.left.EvaluateAsync(Variables);
54 IElement R = await this.right.EvaluateAsync(Variables);
55
56 if (L.AssociatedObjectValue is double DL && R.AssociatedObjectValue is double DR)
57 return await this.EvaluateAsync(DL, DR);
58 else
59 return await this.EvaluateAsync(L, R, Variables);
60 }
61
69 public override IElement Evaluate(IElement Left, IElement Right, Variables Variables)
70 {
71 ISet LS = Left.AssociatedSet;
72 ISet RS = Right.AssociatedSet;
73
74 if (!LS.Equals(RS))
75 {
76 bool b;
77
78 try
79 {
80 b = LS is IRightModule RM && RM.ScalarRing.Contains(Right);
81 }
82 catch (Exception)
83 {
84 b = false;
85 }
86
87 if (b)
88 {
90
91 foreach (IElement LeftChild in Left.ChildElements)
92 Result.Add(this.Evaluate(LeftChild, Right, Variables));
93
94 return Left.Encapsulate(Result, this);
95 }
96
97 try
98 {
99 b = RS is ILeftModule LM && LM.ScalarRing.Contains(Left);
100 }
101 catch (Exception)
102 {
103 b = false;
104 }
105
106 if (b)
107 {
109
110 foreach (IElement RightChild in Right.ChildElements)
111 Result.Add(this.Evaluate(Left, RightChild, Variables));
112
113 return Right.Encapsulate(Result, this);
114 }
115 }
116
117 return base.Evaluate(Left, Right, Variables);
118 }
119
120 }
121}
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
Base class for binary double operators.
Base class for binary element-wise double operators.
BinaryElementWiseDoubleOperator(ScriptNode Left, ScriptNode Right, int Start, int Length, Expression Expression)
Base class for binary element-wise double operators.
override IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
override IElement Evaluate(IElement Left, IElement Right, Variables Variables)
Evaluates the operator.
override async Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
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
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.
Basic interface for all types of left modules.
Definition: ILeftModule.cs:10
Basic interface for all types of right modules.
Definition: IRightModule.cs:10
Basic interface for all types of sets.
Definition: ISet.cs:10
bool Contains(IElement Element)
Checks if the set contains an element.