internal RankJobInfo(int[] rankSpecifier, AFunc function) { this.rankSpecifier = rankSpecifier; this.function = (Func<Aplus, AType, AType, AType>)function.Method; this.check = ATypes.AType; this.floatConvert = false; }
/// <summary> /// Execute 'dyadic' Each algorithm. /// </summary> /// <param name="left"></param> /// <param name="right"></param> /// <param name="environment"></param> /// <param name="isNull"></param> /// <param name="function"></param> /// <returns></returns> private AType Walker(AType left, AType right, Aplus environment, bool isNull, AFunc function) { if (left.IsArray) { AType result = AArray.Create(ATypes.AArray); AType rightArray = right.IsArray ? right : AArray.Create(right.Type, right); for (int i = 0; i < left.Length; i++) { result.AddWithNoUpdate(Walker(left[i], rightArray[right.IsArray ? i : 0], environment, isNull, function)); } result.Type = isNull ? ATypes.ANull : ATypes.ABox; result.Length = left.Length; result.Shape = new List<int>(left.Shape); result.Rank = left.Rank; return result; } else { if (right.IsArray) { AType result = AArray.Create(ATypes.AArray); for (int i = 0; i < right.Length; i++) { result.AddWithNoUpdate(Walker(left, right[i], environment, isNull, function)); } result.Type = isNull ? ATypes.ANull : ATypes.ABox; result.Length = right.Length; result.Shape = new List<int>(right.Shape); result.Rank = right.Rank; return result; } else { //Disclose left and right scalar argument. AType disclosedRight = MonadicFunctionInstance.Disclose.Execute(right, environment); AType disclosedLeft = MonadicFunctionInstance.Disclose.Execute(left, environment); var method = (Func<Aplus, AType, AType, AType>)function.Method; //Execute the holden function and enclose the result. AType result = method(environment, disclosedRight, disclosedLeft); result = MonadicFunctionInstance.Enclose.Execute(result); return result; } } }
public static bool IsPrimitiveFunction(this AType argument) { if (argument.IsFunctionScalar) { AFunc function = (AFunc)argument.NestedItem.Data; return(function.IsBuiltin); } else { return(false); } }
/// <summary> /// Execute 'monadic' Each algorithm. /// </summary> /// <param name="argument"></param> /// <param name="environment"></param> /// <param name="isNull"></param> /// <param name="function"></param> /// <returns></returns> private AType Walker(AType argument, Aplus environment, bool isNull, AFunc function) { if (argument.IsArray) { AType result = AArray.Create(ATypes.AArray); foreach (AType item in argument) { result.AddWithNoUpdate(Walker(item, environment, isNull, function)); } result.Type = isNull ? ATypes.ANull : ATypes.ABox; result.Length = argument.Length; result.Shape = new List<int>(argument.Shape); result.Rank = argument.Rank; return result; } else { //Disclose scalar argument. AType result = MonadicFunctionInstance.Disclose.Execute(argument); //Pick the holden function and apply it. if (function.IsBuiltin) { var method = (Func<Aplus, AType, AType, AType>)function.Method; result = method(environment, result, null); } else { var method = (Func<Aplus, AType, AType>)function.Method; result = method(environment, result); } //Enclose the result. result = MonadicFunctionInstance.Enclose.Execute(result); return result; } }
private AType NullWalker(AType argument, AFunc function, int number, Aplus environment) { AType result; if (argument.Type == ATypes.ANull) { if (number == 0) { throw new Error.Type("Rank"); } result = ExecuteFunction(function, Utils.ANull(), environment); if (result.Type == ATypes.ABox || result.Type == ATypes.ASymbol) { result.Type = ATypes.ANull; } } else { result = AArray.Create(ATypes.AArray); result.Length = argument.Length; result.Shape = new List<int>(argument.Shape.GetRange(0, argument.Rank)); result.Rank = argument.Rank; result.Type = ExecuteFunction(function, Utils.ANull(argument.Type), environment).Type; } return result; }
private static AType ExecuteFunction(AFunc function, AType argument, Aplus environment) { AType result; if (function.IsBuiltin) { var method = (Func<Aplus, AType, AType, AType>)function.Method; result = method(environment, argument, null); } else { var method = (Func<Aplus, AType, AType>)function.Method; result = method(environment, argument); } return result; }
private AType Walker( AType argument, AFunc function, int number, Aplus environment, ref ATypes typeChecker, ref bool floatConvert) { AType result; if (argument.Rank != number) { result = AArray.Create(ATypes.AArray); foreach (AType item in argument) { AType resultItem = Walker(item, function, number, environment, ref typeChecker, ref floatConvert); if (typeChecker == ATypes.AType) { typeChecker = resultItem.Type; } else if (typeChecker == ATypes.AFloat && resultItem.Type == ATypes.AInteger || resultItem.Type == ATypes.AFloat && typeChecker == ATypes.AInteger) { floatConvert = true; } else if (typeChecker != resultItem.Type) { throw new Error.Type("Rank"); } result.AddWithNoUpdate(resultItem); } result.UpdateInfo(); } else { result = ExecuteFunction(function, argument, environment); } return result; }
public override AType ExecutePrimitive(AFunc argument, Aplus environment = null) { return new AReference(argument); }
public virtual AType ExecutePrimitive(AFunc argument, Aplus environment = null) { throw new NotImplementedException("Invalid use-case"); }