private AType ConvertNumberToChar(AType argument) { AType result = AArray.Create(ATypes.AChar); if (argument.IsArray) { foreach (AType item in argument) { AType convertedItem = ConvertNumberToChar(item); if (item.IsArray) { result.Add(convertedItem); } else { result.AddRange(convertedItem); } } } else { byte[] bytes = (argument.Type == ATypes.AFloat) ? BitConverter.GetBytes(argument.asFloat) : BitConverter.GetBytes(argument.asInteger); result.AddRange(bytes.Select <byte, AType>(item => AChar.Create((char)item))); } return(result); }
private AType ConvertFloatToInt(AType argument) { AType result = AArray.Create(ATypes.AInteger); if (argument.IsArray) { foreach (AType item in argument) { AType convertedItem = ConvertFloatToInt(item); if (item.IsArray) { result.Add(convertedItem); } else { result.AddRange(convertedItem); } } } else { int destinationTypeSize = GetTypeSize(ATypes.AInteger); byte[] bytes = BitConverter.GetBytes(argument.asFloat); for (int i = 0; i < bytes.Length; i += destinationTypeSize) { result.Add(AInteger.Create(BitConverter.ToInt32(bytes, i))); } } 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); }
internal static AType ConvertATypeListToAType(List <AType> list) { AType result; AType indexers = AArray.Create(ATypes.AArray); indexers.AddRange(list); if (!indexers.TryFirstScalar(out result, true)) { result = indexers; } return(result); }
/// <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> /// Creates the resulting AArray /// </summary> /// <param name="right"></param> /// <param name="left"></param> /// <returns>AArray containing the concatenated elements.</returns> private AType CreateResult(AType right, AType left) { AType result = AArray.Create(left.Type); // Create a clone from the arguments to avoid side effects AType clonedLeft = left.Clone(); AType clonedRight = right.Clone(); if (!clonedLeft.IsArray && !clonedRight.IsArray) { // example input: 1 , 2 result.AddWithNoUpdate(clonedLeft); result.Add(clonedRight); } else if (clonedLeft.IsArray && !clonedRight.IsArray) { // example input: 1 2 , 3 result.AddRange(clonedLeft); AType item = PrepareItem(clonedRight, clonedLeft); result.Add(item); } else if (!clonedLeft.IsArray && clonedRight.IsArray) { // example input: 1 , 2 3 result.AddWithNoUpdate(PrepareItem(clonedLeft, clonedRight)); result.AddRange(clonedRight); } // now both left and right argument is an AArray else if (clonedLeft.Rank == clonedRight.Rank) { // example input: (iota 2 2) , (iota 2 2) CheckItemsShape(clonedLeft, clonedRight); if (clonedLeft.Length > 0) { result.AddRange(clonedLeft); } if (clonedRight.Length > 0) { result.AddRange(clonedRight); } } else if ((clonedLeft.Rank - clonedRight.Rank) == 1) { // example input: (iota 2 2 2) , (iota 2 2) CheckShape(clonedLeft.Shape.GetRange(1, clonedLeft.Shape.Count - 1), clonedRight.Shape); result.AddRange(clonedLeft); result.Add(clonedRight); } else if ((clonedLeft.Rank - clonedRight.Rank) == -1) { // example input: (iota 2 2) , (iota 2 2 2) CheckShape(clonedLeft.Shape, clonedRight.Shape.GetRange(1, clonedRight.Shape.Count - 1)); result.AddWithNoUpdate(clonedLeft); result.AddRange(clonedRight); } else { // The rank difference was bigger than 1. throw new Error.Rank(this.RankErrorText); } return(result); }