/// <summary> /// Separate symbol constant by definiton. /// </summary> /// <param name="argument"></param> /// <returns></returns> private AType SeparateSymbol(AType argument) { AType result = AArray.Create(ATypes.ASymbol); string symbol = argument.asString; int index = symbol.LastIndexOf('.'); if (index != -1) { result.AddWithNoUpdate(ASymbol.Create(symbol.Substring(0, index))); result.AddWithNoUpdate(ASymbol.Create(symbol.Substring(index + 1))); } else { result.AddWithNoUpdate(ASymbol.Create("")); result.AddWithNoUpdate(argument.Clone()); } result.Length = 2; result.Shape = new List <int>() { 2 }; result.Rank = 1; return(result); }
/// <summary> /// Encode right side with left side. /// </summary> /// <param name="shape"></param> /// <param name="counter"></param> /// <param name="encodeInfo"></param> /// <returns></returns> private static AType EncodeArray(List <int> shape, int counter, EncodeInformation encodeInfo) { List <int> cutShape; AType result = AArray.Create(encodeInfo.ResultingType); for (int i = 0; i < shape[0]; i++) { if (shape.Count > 1) { cutShape = shape.GetRange(1, shape.Count - 1); result.AddWithNoUpdate(EncodeArray(cutShape, counter, encodeInfo)); } else { result.AddWithNoUpdate(EncodeOneStep(counter, encodeInfo)); } } result.Length = shape[0]; result.Shape = new List <int>(shape); result.Rank = shape.Count; return(result); }
/// <summary> /// Compose left and right side. /// </summary> /// <param name="laminateInfo">Instead of class variables.</param> /// <returns></returns> private AType Compute(LaminateJobInfo laminateInfo) { AType result = AArray.Create(laminateInfo.ResultType); if (laminateInfo.Left.Length == 0 || laminateInfo.Right.Length == 0) { result.Type = laminateInfo.Left.Type = laminateInfo.Right.Type = laminateInfo.ResultType.MixedType() ? ATypes.ANull : laminateInfo.ResultType; } result.AddWithNoUpdate(laminateInfo.Left); result.AddWithNoUpdate(laminateInfo.Right); result.Length = 2; result.Shape = new List <int>() { 2 }; if (laminateInfo.Right.Rank >= 1) { result.Shape.AddRange(laminateInfo.Right.Shape); } result.Rank = 1 + laminateInfo.Right.Rank; return(result); }
private AType Compute(AType inputItems, PartitionJobInfo info) { // the left side is equal with 0, then the result is Enclosed null if (info.PartitionVector.Length == 1 && info.PartitionVector[0] == 0) { return(CreateEnclosedNull(inputItems)); } // the result is a nested vector AType result = AArray.Create(ATypes.AType); int counter = 0; // enclose y[i] items from x array //for (int i = 0; i < arguments.PartitionVector.Length; i++) foreach (int partitionNumber in info.PartitionVector) { AType item = AArray.Create(inputItems[counter].Type); for (int j = 0; j < partitionNumber; j++) { item.AddWithNoUpdate(inputItems[counter]); counter++; } item.Length = partitionNumber; item.Shape = new List <int>() { partitionNumber }; if (inputItems.Rank > 1) { item.Shape.AddRange(inputItems.Shape.GetRange(1, inputItems.Shape.Count - 1)); } item.Rank = inputItems.Rank; result.AddWithNoUpdate(ABox.Create(item)); } // add the remainder Enclosed null for (int i = 0; i < info.Remainder; i++) { result.AddWithNoUpdate(CreateEnclosedNull(inputItems)); } result.Length = info.PartitionVector.Length + info.Remainder; result.Shape = new List <int>() { result.Length }; result.Rank = 1; result.Type = result.Length > 0 ? ATypes.ABox : ATypes.ANull; return(result); }
/// <summary> /// </summary> /// <remarks> /// If argument is matrix, each element i#r of the result is evaluation /// of the column x[;i]. If (rho rho x) > 2, each element of the result is the /// evalution corresponding vector along the first axis of x. /// </remarks> /// <param name="argument"></param> /// <param name="decodeInfo"></param> /// <returns></returns> private static AType DecodeArray(AType argument, DecodeInformation decodeInfo) { List <AType> indexes = new List <AType>() { Utils.ANull() }; AType index; if (argument.Rank > 1) { AType result = AArray.Create(ATypes.AFloat); for (int i = 0; i < argument.Shape[1]; i++) { index = AInteger.Create(i); indexes.Add(index); result.AddWithNoUpdate(DecodeArray(argument[indexes], decodeInfo)); indexes.Remove(index); } result.Length = argument.Shape[1]; result.Shape = new List <int>(); result.Shape.AddRange(argument.Shape.GetRange(1, argument.Rank - 1)); result.Rank = argument.Rank - 1; return(result); } else { return(DecodeVector(argument, decodeInfo)); } }
/// <summary> /// Convert argument to integer. /// </summary> /// <param name="argument"></param> /// <returns></returns> protected AType ConvertToInt(AType argument) { if (argument.IsArray) { AType result = AArray.Create(ATypes.AInteger); foreach (AType item in argument) { result.AddWithNoUpdate(ConvertToInt(item)); } result.Length = argument.Length; result.Shape = new List <int>(argument.Shape); result.Rank = argument.Rank; return(result); } else { int result; if (argument.ConvertToRestrictedWholeNumber(out result)) { return(AInteger.Create(result)); } else { throw new Error.Type(TypeErrorText); } } }
private AType Process(AType shape, AType input, ref int pos, int shapePos) { if (!shape.IsArray) { return(ProcessToVector(shape, input, ref pos)); } AType result = AArray.Create(input.Type); int itemCount = shape[shapePos].asInteger; for (int i = 0; i < itemCount; i++) { if (shapePos + 1 >= shape.Length) { return(ProcessToVector(shape[shapePos], input, ref pos)); } else { result.AddWithNoUpdate(Process(shape, input, ref pos, shapePos + 1)); } } result.UpdateInfo(); return(result); }
public override AType Execute(AType argument, Aplus environment = null) { if (argument.Rank < 2) { throw new Error.Rank(RankErrorText); } AType result = AArray.Create(argument.Type); foreach (AType item in argument) { foreach (AType element in item) { result.AddWithNoUpdate(element.Clone()); } } result.Shape = new List <int>() { argument.Shape[0] * argument.Shape[1] }; result.Shape.AddRange(argument.Shape.GetRange(2, argument.Shape.Count - 2)); result.Length = result.Shape[0]; result.Rank = result.Shape.Count; return(result); }
/// <summary> /// Execute padding on all items and make the result character array. /// </summary> /// <param name="shape"></param> /// <param name="arguments">Instead of class variables.</param> /// <returns></returns> private AType FormatArray(List <int> shape, FormatInformation arguments) { AType result = AArray.Create(ATypes.AChar); int rank = shape.Count; if (rank > 0) { for (int i = 0; i < shape[0]; i++) { if (rank > 1) { result.AddWithNoUpdate(FormatArray(shape.GetRange(1, rank - 1), arguments)); } else { result.AddRangeWithNoUpdate(FormatScalar(arguments)); } } result.UpdateInfo(); } else { result.AddRange(FormatScalar(arguments)); } return(result); }
/// <summary> /// /// </summary> /// <param name="indexers">List containing all of the indexes</param> /// <param name="indexpos"></param> /// <param name="currentIdx">Array containing the current indexes</param> /// <returns></returns> public static AType VectorIndexing(this AType input, List <AType> indexers, int indexpos, AType currentIdx, bool isAssign, bool isMemoryMapped) { if (currentIdx.Length == 0) { // A Null item found!, select all of the current items for (int i = 0; i < input.Length; i++) { currentIdx.Add(AInteger.Create(i)); } } // Create an array for the results AType result = AArray.Create(input.Type); // Iterate over the indexes foreach (AType index in currentIdx) { AType item = index.IsArray ? input.VectorIndexing(indexers, indexpos, index, isAssign, isMemoryMapped) : input.SimpleIndex(indexers, indexpos, index, isAssign, isMemoryMapped); result.AddWithNoUpdate(item); } result.UpdateInfo(); return(result); }
/// <summary> /// Convert Character constant array to symbol array. /// </summary> /// <param name="argument"></param> /// <returns></returns> private AType Compute(AType argument) { //If argument is character constant or character constant vector then we convert it symbol, //and cut blanks from end. if (argument.Rank <= 1) { return(ASymbol.Create(argument.ToString().TrimEnd())); } else { AType result = AArray.Create(ATypes.ASymbol); foreach (AType item in argument) { result.AddWithNoUpdate(Compute(item)); } result.Length = argument.Length; result.Shape = new List <int>(); result.Shape.AddRange(argument.Shape.GetRange(0, argument.Shape.Count - 1)); result.Rank = argument.Rank - 1; return(result); } }
private static AType Compute(ReplicateJobInfo replicateInfo) { AType result = AArray.Create(ATypes.AArray); int length = 0; if (replicateInfo.ReplicateVector.Length == 1) { for (int i = 0; i < replicateInfo.Items.Length; i++) { for (int j = 0; j < replicateInfo.ReplicateVector[0]; j++) { result.AddWithNoUpdate(replicateInfo.Items[i].Clone()); } } length = replicateInfo.ReplicateVector[0] * replicateInfo.Items.Length; } else //replicateCounter.Count > 1 { for (int i = 0; i < replicateInfo.ReplicateVector.Length; i++) { for (int j = 0; j < replicateInfo.ReplicateVector[i]; j++) { result.AddWithNoUpdate(replicateInfo.Items[replicateInfo.Items.Length > 1 ? i : 0].Clone()); } length += replicateInfo.ReplicateVector[i]; } } result.Length = length; result.Shape = new List <int>() { length }; if (replicateInfo.Items.Rank > 1) { result.Shape.AddRange(replicateInfo.Items.Shape.GetRange(1, replicateInfo.Items.Shape.Count - 1)); } result.Rank = replicateInfo.Items.Rank; result.Type = length > 0 ? result[0].Type : (replicateInfo.Items.MixedType() ? ATypes.ANull : replicateInfo.Items.Type); return(result); }
/// <summary> /// Catenate items to the result. /// </summary> /// <param name="items"></param> /// <param name="result"></param> /// <returns>Number of items added to the result.</returns> private static int Catenate(AType items, AType result) { for (int i = 0; i < items.Length; i++) { result.AddWithNoUpdate(items[i].Clone()); } return(items.Length); }
private AType GenerateVector(int itemCount) { AType vector = AArray.Create(ATypes.AInteger); for (int i = 0; i < itemCount; i++) { vector.AddWithNoUpdate(AInteger.Create(i)); } vector.UpdateInfo(); return(vector); }
/// <summary> /// </summary> /// <remarks> /// (function\argument)[i] == function/argument[iota i + 1] for every valid i. /// </remarks> /// <param name="argument"></param> /// <returns></returns> private AType ScanAlgorithm(AType argument) { AType result = AArray.Create(this.type); AType temp = PreProcess(argument[0]); result.AddWithNoUpdate(temp); for (int i = 1; i < argument.Length; i++) { temp = this.function.Execute(argument[i], temp); result.AddWithNoUpdate(temp); } result.Length = argument.Length; result.Shape = new List <int>(argument.Shape); result.Rank = argument.Rank; return(PostProcess(argument, result)); }
/// <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); } } }
/// <summary> /// Create the result array with corrpesond shape. /// </summary> /// <param name="items"></param> /// <param name="shape"></param> /// <param name="pathVector"></param> /// <param name="transposeVector"></param> /// <returns></returns> private AType CreateArray(AType items, LinkedList <int> shape, List <int> pathVector, int[] transposeVector) { List <int> newPathVector; LinkedList <int> cutShape = null; AType result = AArray.Create(ATypes.AArray); for (int i = 0; i < shape.First(); i++) { newPathVector = new List <int>(); newPathVector.AddRange(pathVector); newPathVector.Add(i); if (shape.Count > 1) { cutShape = new LinkedList <int>(shape); cutShape.RemoveFirst(); result.AddWithNoUpdate(CreateArray(items, cutShape, newPathVector, transposeVector)); } else { result.AddWithNoUpdate(GetItem(items, newPathVector, transposeVector)); } } result.Length = shape.First(); result.Shape = new List <int>() { result.Length }; if (shape.Count > 1) { result.Shape.AddRange(cutShape.ToList()); } result.Rank = result.Shape.Count; result.Type = result.Length > 0 ? result[0].Type : (items.MixedType() ? ATypes.ANull : items.Type); return(result); }
/// <summary> /// Creates an AArray from the input arguments. /// </summary> /// <param name="arguments">The array containing the ATypes, in REVERSE order!</param> /// <returns></returns> public static AType BuildArray(AType[] arguments) { AType result = AArray.Create(ATypes.AArray); for (int i = arguments.Length - 1; i >= 0; i--) { result.AddWithNoUpdate(arguments[i]); } result.UpdateInfo(); return(result); }
/// <summary> /// Creates an AArray with type AInteger from the input list of integers /// </summary> /// <param name="list">List of Integers</param> /// <returns></returns> public static AType ToAArray(this IEnumerable <int> list) { AType array = AArray.Create(ATypes.AInteger); foreach (int item in list) { array.AddWithNoUpdate(AInteger.Create(item)); } array.UpdateInfo(); return(array); }
/// <summary> /// Creates a strand from the input arguments. Boxes each element. /// </summary> /// <param name="arguments">The array containing the strand arguments, in REVERSE order!</param> /// <returns>AArray with ABox elements</returns> public static AType BuildStrand(AType[] arguments) { AType result = AArray.Create(ATypes.ABox); for (int i = arguments.Length - 1; i >= 0; i--) { //There is no environment now! result.AddWithNoUpdate(MonadicFunctionInstance.Enclose.Execute(arguments[i])); } result.UpdateInfo(); return(result); }
private AType Compute(AType items, byte[] expandVector) { AType result = AArray.Create(ATypes.AType); int index = 0; // get the filler element based on the right argument AType fillElementShape = items.Rank > 1 ? items.Shape.GetRange(1, items.Shape.Count - 1).ToAArray() : null; AType filler = Utils.FillElement(items.Type, fillElementShape); for (int i = 0; i < expandVector.Length; i++) { if (expandVector[i] == 1) { result.AddWithNoUpdate(items[items.Length > 1 ? index++ : 0].Clone()); } else { result.AddWithNoUpdate(filler.Clone()); } } result.Length = expandVector.Length; result.Shape = new List <int>() { expandVector.Length }; if (items.Rank > 1) { result.Shape.AddRange(items.Shape.GetRange(1, items.Shape.Count - 1)); } result.Rank = items.Rank; result.Type = result.Length > 0 ? result[0].Type : (items.MixedType() ? ATypes.ANull : items.Type); return(result); }
public static AType Export(Aplus environment, AType argument) { byte[] exportedMessage = SysExp.Instance.Format(argument); AType result = AArray.Create(ATypes.AChar); foreach (byte charcter in exportedMessage) { result.AddWithNoUpdate(AChar.Create((char)charcter)); } result.UpdateInfo(); return(result); }
/// <summary> /// ExtractItems from the <see cref="argument"/> and add it to the <see cref="result"/> vector. /// </summary> /// <param name="argument"></param> /// <param name="result">The array stores the result vector</param> private void ExtractItems(AType argument, AType result) { if (argument.IsArray) { foreach (AType item in argument) { ExtractItems(item, result); } } else { result.AddWithNoUpdate(argument); } }
private AType LeftSideWalk(AType left, AType right, Aplus environment, RankJobInfo rankInfo) { AType result = AArray.Create(ATypes.ANull); AType temp; foreach (AType item in left) { temp = Walker(item, right, environment, rankInfo); TypeCheck(temp.Type, rankInfo); result.AddWithNoUpdate(temp); } return(result); }
/// <summary> /// Partition count. /// </summary> /// <param name="argument"></param> /// <returns></returns> private AType Compute(AType argument, byte[] vector) { AType result = AArray.Create(ATypes.AArray); // If argument is () than result is (). result.Type = (argument.Type == ATypes.ANull) ? ATypes.ANull : ATypes.AInteger; if (vector.Length > 0) { int length = 1; int counter = 0; for (int i = 1; i < vector.Length; i++) { counter++; if (vector[i] == 1) { length++; result.AddWithNoUpdate(AInteger.Create(counter)); counter = 0; } } counter++; result.AddWithNoUpdate(AInteger.Create(counter)); result.Length = length; result.Shape = new List <int>() { length }; result.Rank = 1; } return(result); }
/// <summary> /// Generate a vector with the length of the specified shape /// </summary> /// <param name="shape"></param> /// <param name="input">Vector of input elements</param> /// <param name="pos"></param> /// <returns></returns> private AType ProcessToVector(AType shape, AType input, ref int pos) { AType result = AArray.Create(input.Type); int itemCount = shape.asInteger; for (int i = 0; i < itemCount; i++) { result.AddWithNoUpdate(input[pos++].Clone()); if (pos >= input.Length) { pos = 0; } } result.UpdateInfo(); return(result); }
public override AType Clone() { AType result = LocalAArray.Create(this.Type); for (int i = 0; i < this.Length; i++) { result.AddWithNoUpdate(this[i].Clone()); } result.Length = this.Length; result.Shape.Clear(); result.Shape.AddRange(this.Shape); result.Type = this.Type; result.Rank = this.Rank; return(result.Data); }
/// <summary> /// /// </summary> /// <param name="argument"></param> /// <param name="formaters"></param> /// <returns></returns> private static AType FormatArray(AType argument, List <FormatInfo> formaters) { AType result = AArray.Create(ATypes.AChar); AType[] formatted; if (argument.IsArray) { for (int i = 0; i < argument.Length; i++) { if (argument.Rank > 1) { result.AddWithNoUpdate(FormatArray(argument[i], formaters)); } else { FormatInfo format = formaters[formaters.Count > 1 ? i : 0]; formatted = argument.IsNumber ? FormatNumber(argument[i], format) : FormatSymbol(argument[i], format); if (formatted != null) { result.AddRangeWithNoUpdate(formatted); } } } result.UpdateInfo(); } else { FormatInfo format = formaters[0]; formatted = argument.IsNumber ? FormatNumber(argument, format) : FormatSymbol(argument, format); if (formatted != null) { result.AddRange(formatted); } } return(result); }
/// <summary> /// Convert Symbol to Character constant vector. /// </summary> /// <param name="symbol"></param> /// <returns></returns> private AType Convert(AType symbol, int lastDimension) { string item = symbol.asString; AType result = AArray.Create(ATypes.AChar); for (int i = 0; i < lastDimension; i++) { result.AddWithNoUpdate(AChar.Create(i >= item.Length ? ' ' : item[i])); } result.Length = lastDimension; result.Shape = new List <int>() { lastDimension }; result.Rank = 1; return(result); }
/// <summary> /// Convert symbol array/scalar to float or integer constant. /// </summary> /// <param name="item"></param> /// <param name="castInfo"></param> /// <returns></returns> private AType ConvertSymbolConstantToNumber(AType item, CastInfo castInfo) { AType result = AArray.Create(castInfo.ResultingType); string temp = item.asString.PadRight(castInfo.LongestSymbolLength); foreach (char character in temp) { result.AddWithNoUpdate(ConvertToNumber(character, castInfo)); } result.Length = temp.Length; result.Shape = new List <int>() { temp.Length }; result.Rank = 1; return(result); }
/// <summary> /// The result is a nested vector whose depth is one. /// </summary> /// <param name="argument"></param> /// <param name="result"></param> /// <returns>Number of items disclosed.</returns> private int DiscloseNestedElement(AType argument, AType result) { int count = 0; if (argument.IsArray) { // if rank of the argument is higher than one, so not vector, we ravel it AType raveled = (argument.Rank > 1 ? MonadicFunctionInstance.Ravel.Execute(argument) : argument); // call this function recursively for each element in the array. foreach (AType item in raveled) { count += DiscloseNestedElement(item, result); } } else { // get the depth of the argument int depth = MonadicFunctionInstance.Depth.Execute(argument).asInteger; // if depth is bigger than 1, we disclose it if (depth > 1) { count += DiscloseNestedElement(MonadicFunctionInstance.Disclose.Execute(argument), result); } else { bool isBox = argument.IsBox; // leave out Null item if((isBox && argument.NestedItem.Type != ATypes.ANull) || !isBox) { result.AddWithNoUpdate(argument); count++; } } } return count; }
/// <summary> /// Catenate items to the result. /// </summary> /// <param name="items"></param> /// <param name="result"></param> /// <returns>Number of items added to the result.</returns> private static int Catenate(AType items, AType result) { for (int i = 0; i < items.Length; i++) { result.AddWithNoUpdate(items[i].Clone()); } return items.Length; }