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.Collections.Generic;
3using System.Threading.Tasks;
7
8namespace Waher.Script.Model
9{
14 {
24 : base(Left, Right, Start, Length, Expression)
25 {
26 }
27
34 {
35 IElement L = this.left.Evaluate(Variables);
36 IElement R = this.right.Evaluate(Variables);
37
38 if (L.AssociatedObjectValue is double DL && R.AssociatedObjectValue is double DR)
39 return this.Evaluate(DL, DR);
40 else
41 return this.Evaluate(L, R, Variables);
42 }
43
49 public override async Task<IElement> EvaluateAsync(Variables Variables)
50 {
51 if (!this.isAsync)
52 return this.Evaluate(Variables);
53
54 IElement L = await this.left.EvaluateAsync(Variables);
55 IElement R = await this.right.EvaluateAsync(Variables);
56
57 if (L.AssociatedObjectValue is double DL && R.AssociatedObjectValue is double DR)
58 return await this.EvaluateAsync(DL, DR);
59 else
60 return await this.EvaluateAsync(L, R, Variables);
61 }
62
70 public override IElement Evaluate(IElement Left, IElement Right, Variables Variables)
71 {
72 ISet LS = Left.AssociatedSet;
73 ISet RS = Right.AssociatedSet;
74
75 if (!LS.Equals(RS))
76 {
77 bool b;
78
79 try
80 {
81 b = LS is IRightModule RM && RM.ScalarRing.Contains(Right);
82 }
83 catch (Exception)
84 {
85 b = false;
86 }
87
88 if (b)
89 {
90 LinkedList<IElement> Result = new LinkedList<IElement>();
91
92 foreach (IElement LeftChild in Left.ChildElements)
93 Result.AddLast(this.Evaluate(LeftChild, Right, Variables));
94
95 return Left.Encapsulate(Result, this);
96 }
97
98 try
99 {
100 b = RS is ILeftModule LM && LM.ScalarRing.Contains(Left);
101 }
102 catch (Exception)
103 {
104 b = false;
105 }
106
107 if (b)
108 {
109 LinkedList<IElement> Result = new LinkedList<IElement>();
110
111 foreach (IElement RightChild in Right.ChildElements)
112 Result.AddLast(this.Evaluate(Left, RightChild, Variables));
113
114 return Right.Encapsulate(Result, this);
115 }
116 }
117
118 return base.Evaluate(Left, Right, Variables);
119 }
120
121 }
122}
Class managing a script expression.
Definition: Expression.cs:39
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:20
object AssociatedObjectValue
Associated object value.
Definition: IElement.cs:33
ICollection< IElement > ChildElements
An enumeration of child elements. If the element is a scalar, this property will return null.
Definition: IElement.cs:49
IElement Encapsulate(ICollection< 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.