4using System.Threading.Tasks;
131 private readonly
bool allNormal;
132 private readonly
int nrArguments;
133 private bool isAsync;
147 throw new ArgumentException(
"Size of ArgumentTypes must match the size of Arguments.", nameof(
ArgumentTypes));
153 this.nrArguments = this.arguments.Length;
155 this.allNormal =
true;
160 this.allNormal =
false;
168 private void CalcIsAsync()
170 this.isAsync =
false;
172 for (
int i = 0; i < this.nrArguments; i++)
209 for (i = 0; i < this.nrArguments; i++)
211 Node = this.arguments[i];
221 return this.EvaluateCanonicalExtension(Arg,
Variables);
231 if (!this.IsAsynchronous)
238 for (i = 0; i < this.nrArguments; i++)
240 Node = this.arguments[i];
250 return await this.EvaluateCanonicalExtensionAsync(Arg,
Variables);
266 for (j = 0; j < Dimension; j++)
268 for (i = 0; i < this.nrArguments; i++)
270 if (e[i] is
null || !e[i].MoveNext())
273 Arguments2[i] = e[i].Current;
276 Result.
Add(this.EvaluateCanonicalExtension(Arguments2,
Variables));
286 for (i = 0, j = e?.
Length ?? 0; i < j; i++)
293 ICollection<IElement> ChildElements;
300 e =
new IEnumerator<IElement>[this.nrArguments];
304 for (i = 0; i < this.nrArguments; i++)
308 switch (this.argumentTypes[i])
322 Dimension = ChildElements.Count;
323 else if (ChildElements.Count != Dimension)
326 e[i] = ChildElements.GetEnumerator();
335 else if (!((M = Argument as
IMatrix) is
null))
339 else if (M.
Rows != Dimension)
344 for (j = 0; j < Dimension; j++)
349 Encapsulation = Operators.LambdaDefinition.EncapsulateToVector;
351 else if (!((S = Argument as
ISet) is
null))
358 Dimension = Size.Value;
359 else if (Size.Value != Dimension)
371 Arguments[i] = Operators.Vectors.VectorDefinition.Encapsulate(Enumerable,
false,
this);
376 Arguments[i] = Operators.Vectors.VectorDefinition.Encapsulate(
new IElement[] { Argument },
false,
this);
382 if (Argument is
ISet)
389 else if (!((M = Argument as
IMatrix) is
null))
393 else if (M.
Rows != Dimension)
398 for (j = 0; j < Dimension; j++)
404 e[i] = ChildElements.GetEnumerator();
406 Encapsulation = Operators.LambdaDefinition.EncapsulateToVector;
413 Arguments[i] = Operators.Sets.SetDefinition.Encapsulate(Enumerable);
418 Arguments[i] = Operators.Sets.SetDefinition.Encapsulate(
new IElement[] { Argument });
431 else if (!((S = Argument as
ISet) is
null))
438 Dimension = Size.Value;
439 else if (Size.Value != Dimension)
448 Arguments[i] = Operators.Matrices.MatrixDefinition.Encapsulate(
new IElement[] { Argument }, 1, 1,
this);
472 for (j = 0; j < Dimension; j++)
474 for (i = 0; i < this.nrArguments; i++)
476 if (e[i] is
null || !e[i].MoveNext())
479 Arguments2[i] = e[i].Current;
482 Result.
Add(await this.EvaluateCanonicalExtensionAsync(Arguments2,
Variables));
492 for (i = 0, j = e?.
Length ?? 0; i < j; i++)
529 if (!this.arguments.ForAllChildNodes(Callback, State, Order))
534 bool RecalcIsAsync =
false;
536 for (i = 0; i < this.nrArguments; i++)
538 Node = this.arguments[i];
541 bool b = !Callback(Node, out
ScriptNode NewNode, State);
542 if (!(NewNode is
null))
544 this.arguments[i] = NewNode;
545 NewNode.SetParent(
this);
548 RecalcIsAsync =
true;
566 if (!this.arguments.ForAllChildNodes(Callback, State, Order))
577 AreEqual(this.arguments, O.arguments) &&
578 AreEqual(this.argumentTypes, O.argumentTypes) &&
585 int Result = base.GetHashCode();
586 Result ^= Result << 5 ^
GetHashCode(this.arguments);
587 Result ^= Result << 5 ^
GetHashCode(this.argumentTypes);
A chunked list is a linked list of chunks of objects of type T .
IEnumerator< T > GetEnumerator()
Returns an enumerator for the collection.
void Add(T Item)
Adds an item to the collection.
Exception thrown if argument dimensions are not consistent.
Script runtime exception.
Class managing a script expression.
Base class for all funcions.
Base class for multivariate funcions.
static readonly ArgumentType[] argumentTypes3Normal
Three normal parameters.
static readonly ArgumentType[] argumentTypes5Scalar
Five scalar parameters.
override IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
static readonly ArgumentType[] argumentTypes4Normal
Four normal parameters.
static readonly ArgumentType[] argumentTypes1Matrix
One matrix parameter.
static readonly ArgumentType[] argumentTypes8Normal
Eight normal parameters.
static readonly ArgumentType[] argumentTypes2Normal
Two normal parameters.
ScriptNode[] Arguments
Function arguments.
override bool Equals(object obj)
FunctionMultiVariate(ScriptNode[] Arguments, ArgumentType[] ArgumentTypes, int Start, int Length, Expression Expression)
Base class for funcions of one variable.
override int GetHashCode()
static readonly ArgumentType[] argumentTypes2Scalar
Two scalar parameters.
static readonly ArgumentType[] argumentTypes0
Zero parameters.
static readonly ArgumentType[] argumentTypes7Normal
Seven normal parameters.
abstract IElement Evaluate(IElement[] Arguments, Variables Variables)
Evaluates the function.
static readonly ArgumentType[] argumentTypes1Normal
One scalar parameter.
static readonly ArgumentType[] argumentTypes9Normal
Nine normal parameters.
override bool IsAsynchronous
If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluat...
static readonly ArgumentType[] argumentTypes1Vector
One vector parameter.
static readonly ArgumentType[] argumentTypes3Scalar
Three scalar parameters.
static readonly ArgumentType[] argumentTypes7Scalar
Seven scalar parameters.
static readonly ArgumentType[] argumentTypes9Scalar
Nine scalar parameters.
static readonly ArgumentType[] argumentTypes8Scalar
Eight scalar parameters.
static readonly ArgumentType[] argumentTypes6Normal
Six normal parameters.
ArgumentType[] ArgumentTypes
Function argument types.
static readonly ArgumentType[] argumentTypes5Normal
Five normal parameters.
virtual Task< IElement > EvaluateAsync(IElement[] Arguments, Variables Variables)
Evaluates the function.
override bool ForAllChildNodes(ScriptNodeEventHandler Callback, object State, SearchMethod Order)
Calls the callback method for all child nodes.
override async Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
static readonly ArgumentType[] argumentTypes1Scalar
One scalar parameter.
static readonly ArgumentType[] argumentTypes1Set
One set parameter.
static readonly ArgumentType[] argumentTypes6Scalar
Six scalar parameters.
static readonly ArgumentType[] argumentTypes4Scalar
Four scalar parameters.
Base class for all nodes in a parsed script tree.
bool ForAllChildNodes(ScriptNodeEventHandler Callback, object State, bool DepthFirst)
Calls the callback method for all child nodes.
int Length
Length of expression covered by node.
static bool AreEqual(ScriptNode S1, ScriptNode S2)
Compares if two script nodes are equal.
int Start
Start position in script expression.
void SetParent(ScriptNode Parent)
Sets the parent node. Can only be used when expression is being parsed or created.
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 ...
static readonly ObjectValue Null
Null value.
Basic interface for all types of elements.
object AssociatedObjectValue
Associated object value.
ICollection< IElement > ChildElements
An enumeration of child elements. If the element is a scalar, this property will return null.
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.
Basic interface for matrices.
IVector GetRow(int Row)
Gets a row vector from the matrix.
Basic interface for vectors.
int Dimension
Dimension of vector.
Basic interface for all types of module elements.
Basic interface for all types of sets.
int? Size
Size of set, if finite and known, otherwise null is returned.
delegate IElement Encapsulation(ICollection< IElement > Elements, ScriptNode Node)
Delegate for encapsulation methods.
delegate bool ScriptNodeEventHandler(ScriptNode Node, out ScriptNode NewNode, object State)
Delegate for ScriptNode callback methods.
ArgumentType
Type of parameter used in a function definition or a lambda definition.
SearchMethod
Method to traverse the expression structure