public MonadicScalar() { this.allowedTypes = new HashSet <ATypes>(); Type currentType = this.GetType(); DefaultResultAttribute attribute = currentType.GetSingleAttribute <DefaultResultAttribute>(); this.defaultResultType = (attribute != null) ? attribute.DefaultType : ATypes.AType; MethodInfo[] methods = currentType.GetMethods( BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public ); foreach (MethodInfo method in methods) { if (!method.IsVirtual) { continue; } ParameterInfo[] parameterInfo = method.GetParameters(); this.allowedTypes.Add(Utils.GetATypesFromType(parameterInfo[0].ParameterType)); } }
public Check_Hardware_Memory_Load() { warning = new ATypes(90); critical = new ATypes(95); hasArgs = false; loadOpenHardwareDll(); }
private LocalAArray(ATypes type, params AType[] items) : base(type) { this.items = new List<AType>(items); this.UpdateInfo(); }
public Check_Hardware_Memory_Load(string warning, string critical) { this.warning = new ATypes(warning); this.critical = new ATypes(critical); hasArgs = true; loadOpenHardwareDll(); }
public EncodeInformation(double[] encodeKeys, double[] encodeValues, ATypes resultingType) { this.index = 0; this.encodeKeys = encodeKeys; this.encodeValues = encodeValues; this.resultingType = resultingType; }
public Check_User_Cpu_Usage(string w, string c) { warning = new ATypes(w); critical = new ATypes(c); hasArgs = true; initializeUserExclusions(); }
public Check_User_Cpu_Usage() { warning = new ATypes("40"); critical = new ATypes("50"); hasArgs = false; initializeUserExclusions(); }
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> /// Determines the system size of the given AType. /// </summary> /// <exception cref="Error.Domain"> /// Throws Domain error, if the argument is invalid for bitwise cast. /// </exception> /// <param name="argument">AType of the input.</param> /// <returns>Size of the given AType.</returns> private int GetTypeSize(ATypes argument) { int result; switch (argument) { case ATypes.AInteger: result = sizeof(Int32); break; case ATypes.AFloat: result = sizeof(Double); break; case ATypes.ASymbol: result = symbolSize; break; case ATypes.AChar: result = charSize; break; default: throw new Error.Domain(this.DomainErrorText); } return(result); }
public Check_User_Used_Memory() { warning = new ATypes("500"); critical = new ATypes("1000"); hasArgs = false; initializeUserExclusions(); }
protected AArray(ATypes type) { this.length = 0; this.shape = new List<int>() { 0 }; this.rank = 1; this.type = type; }
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; }
public static string ToTypeString(this ATypes type) { switch (type) { case ATypes.AInteger: return("int"); case ATypes.AFloat: return("float"); case ATypes.ASymbol: return("sym"); case ATypes.AChar: return("char"); case ATypes.ANull: return("null"); case ATypes.ABox: return("box"); case ATypes.AFunc: return("func"); default: return("unknown"); } }
private LocalAArray(ATypes type, params AType[] items) : base(type) { this.items = new List <AType>(items); this.UpdateInfo(); }
public DyadicScalar() { this.allowedMethods = new Dictionary<byte, MethodInfo>(); Type currentType = this.GetType(); DefaultResultAttribute attribute = currentType.GetSingleAttribute<DefaultResultAttribute>(); this.defaultResultType = (attribute != null) ? attribute.DefaultType : ATypes.AType; MethodInfo[] methods = currentType.GetMethods( BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public ); // Detect the methods and add a rule for it based on the parameter types foreach (MethodInfo method in methods) { DyadicScalarMethodAttribute scalarAttribute = method.GetSingleAttribute<DyadicScalarMethodAttribute>(); if (scalarAttribute == null) { continue; } ParameterInfo[] parameterInfo = method.GetParameters(); // Add the method to the allowed method's list this.allowedMethods.Add( ATypeMask( Utils.GetATypesFromType(parameterInfo[0].ParameterType), Utils.GetATypesFromType(parameterInfo[1].ParameterType) ), method ); } }
public AType BuildArray(List <int> shape, ref byte[] data, ATypes type, int index) { AType result = Utils.ANull(); int typeSize; ItemConstructDelegate itemConstruct; switch (type) { case ATypes.AInteger: typeSize = sizeof(Int32); itemConstruct = ConstructAInteger; break; case ATypes.AChar: typeSize = sizeof(Char) / 2; // FIXMEEE!!!!! sizeof(Char) == 2 in C#!!!!! itemConstruct = ConstructAChar; break; case ATypes.AFloat: typeSize = sizeof(Double); itemConstruct = ConstructAFloat; break; default: throw new ADAPException(ADAPExceptionType.Import); } if (data.Length < (typeSize * shape.Product() + index)) { throw new ADAPException(ADAPExceptionType.Import); } if (shape.Count == 0) { result = itemConstruct(ref data, index); } else if (shape.Count == 1) { for (int i = 0; i < shape[0]; i++) { result.Add(itemConstruct(ref data, index)); index += typeSize; } } else { for (int i = 0; i < shape[0]; i++) { List <int> nextShape = shape.GetRange(1, shape.Count - 1); int subDimensionLength = nextShape.Product() * typeSize; result.Add(BuildArray(nextShape, ref data, type, index)); index += subDimensionLength; } } return(result); }
private ABox(AType item, ATypes type = ATypes.ABox) { this.value = item; this.length = 1; this.shape = new List <int>(); this.rank = 0; this.type = item.Data is AFunc ? ATypes.AFunc : type; }
private ABox(AType item, ATypes type = ATypes.ABox) { this.value = item; this.length = 1; this.shape = new List<int>(); this.rank = 0; this.type = item.Data is AFunc ? ATypes.AFunc : type; }
protected AArray(ATypes type) { this.length = 0; this.shape = new List <int>() { 0 }; this.rank = 1; this.type = type; }
public AType BuildArray(List<int> shape, ref byte[] data, ATypes type, int index) { AType result = Utils.ANull(); int typeSize; ItemConstructDelegate itemConstruct; switch (type) { case ATypes.AInteger: typeSize = sizeof(Int32); itemConstruct = ConstructAInteger; break; case ATypes.AChar: typeSize = sizeof(Char) / 2; // FIXMEEE!!!!! sizeof(Char) == 2 in C#!!!!! itemConstruct = ConstructAChar; break; case ATypes.AFloat: typeSize = sizeof(Double); itemConstruct = ConstructAFloat; break; default: throw new ADAPException(ADAPExceptionType.Import); } if (data.Length < (typeSize * shape.Product() + index)) { throw new ADAPException(ADAPExceptionType.Import); } if (shape.Count == 0) { result = itemConstruct(ref data, index); } else if (shape.Count == 1) { for (int i = 0; i < shape[0]; i++) { result.Add(itemConstruct(ref data, index)); index += typeSize; } } else { for (int i = 0; i < shape[0]; i++) { List<int> nextShape = shape.GetRange(1, shape.Count - 1); int subDimensionLength = nextShape.Product() * typeSize; result.Add(BuildArray(nextShape, ref data, type, index)); index += subDimensionLength; } } return result; }
internal FormatInformation(ATypes type, int printingPrecision) { this.type = type; this.precision = printingPrecision; this.index = 0; this.items = new List<string>(); this.intervalMax = -1; this.fractionMax = -1; this.dotFound = false; }
internal FormatInformation(ATypes type, int printingPrecision) { this.type = type; this.precision = printingPrecision; this.index = 0; this.items = new List <string>(); this.intervalMax = -1; this.fractionMax = -1; this.dotFound = false; }
/// <summary> /// Extracts <see cref="DecodeInformation"/> from the arguments. /// </summary> /// <param name="left"></param> /// <param name="right"></param> /// <returns></returns> private DecodeInformation ExtractDecodeInformation(AType left, AType right) { // Error if the arguments are not numbers or Null if (!((left.IsNumber || left.Type == ATypes.ANull) && (right.IsNumber || right.Type == ATypes.ANull))) { throw new Error.Type(TypeErrorText); } // righ side must be array if (!right.IsArray) { throw new Error.Rank(RankErrorText); } // left side must be scalar or vector if (left.Rank > 1) { throw new Error.Rank(RankErrorText); } ATypes resultType = (left.Type == ATypes.AFloat || right.Type == ATypes.AFloat || right.Type == ATypes.ANull) ? ATypes.AFloat : ATypes.AInteger; double[] decodeValues; if (left.IsArray) { if (left.Length == 1) { // one-element vector case, then we reshape it: (#x) rho y. decodeValues = Enumerable.Repeat(left[0].asFloat, right.Length).ToArray(); } else { // left and right side length have to equal! if (left.Length != right.Length) { throw new Error.Length(LengthErrorText); } decodeValues = left.Select(item => item.asFloat).ToArray(); } } else { // scalar case, reshape it: (#x) rho y. decodeValues = Enumerable.Repeat(left.asFloat, right.Length).ToArray(); } return(new DecodeInformation(resultType, decodeValues)); }
protected override void SetVariables(ATypes type) { if (type == ATypes.AFloat) { this.type = ATypes.AFloat; this.fillerElement = AFloat.Create(0); } else { this.type = ATypes.AInteger; this.fillerElement = AInteger.Create(0); } this.function = DyadicFunctionInstance.Add; }
protected override void SetVariables(ATypes type) { if (type == ATypes.AFloat) { this.type = ATypes.AFloat; this.fillerElement = AFloat.Create(1); } else { this.type = ATypes.AInteger; this.fillerElement = AInteger.Create(1); } this.function = DyadicFunctionInstance.Multiply; }
internal static AType GetSystemVariable(Aplus environment, AType input) { ATypes type = input.Type; if (type != ATypes.ASymbol && type != ATypes.AChar) { throw new Error.Type("_gsv"); } string name = (type == ATypes.ASymbol) ? input.asString : input.ToString(); if (!environment.SystemVariables.Contains(name)) { throw new Error.Domain("_gsv"); } return(environment.SystemVariables[name]); }
/// <summary> /// AArray generated by type and shape with Reshape dyadic nonscalar function. /// If shape list is null, we give back the filler elemenet. /// </summary> /// <param name="type"></param> /// <param name="shape"></param> internal static AType FillElement(ATypes type, AType shape = null) { AType filler = null; switch (type) { case ATypes.ABox: case ATypes.AFunc: filler = ABox.Create(ANull()); break; case ATypes.AChar: filler = AChar.Create(' '); break; case ATypes.AFloat: filler = AFloat.Create(0); break; case ATypes.AInteger: filler = AInteger.Create(0); break; case ATypes.ASymbol: filler = ASymbol.Create(""); break; default: throw new NotImplementedException("Invalid use-case"); } if (shape != null) { return(AplusCore.Runtime.Function.Dyadic.DyadicFunctionInstance.Reshape.Execute(filler, shape)); } else { return(filler); } }
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 AType Execute(AType function, AType n, AType argument, Aplus environment = null) { if (!(function.Data is AFunc)) { throw new Error.NonFunction("Rank"); } AFunc func = (AFunc)function.Data; if (!func.IsBuiltin) { if (func.Valence - 1 != 1) { throw new Error.Valence("Rank"); } } AType result; int number = GetNumber(argument, n, environment); if (argument.Shape.Contains(0)) { result = NullWalker(argument, func, number, environment); } else { ATypes typeChecker = ATypes.AType; bool floatConvert = false; result = Walker(argument, func, number, environment, ref typeChecker, ref floatConvert); if (floatConvert && result.IsArray) { result.ConvertToFloat(); } } return(result); }
private void TypeCheck(ATypes type, RankJobInfo rankInfo) { if (!rankInfo.FloatConvert) { if (rankInfo.Check == ATypes.AType) { rankInfo.Check = type; } else if (rankInfo.Check != type) { if (rankInfo.Check == ATypes.AFloat && type == ATypes.AInteger || type == ATypes.AFloat && rankInfo.Check == ATypes.AInteger) { rankInfo.FloatConvert = true; } else if (!type.MixedType()) { throw new Error.Type("Rank"); } } } }
public MonadicScalar() { this.allowedTypes = new HashSet<ATypes>(); Type currentType = this.GetType(); DefaultResultAttribute attribute = currentType.GetSingleAttribute<DefaultResultAttribute>(); this.defaultResultType = (attribute != null) ? attribute.DefaultType : ATypes.AType; MethodInfo[] methods = currentType.GetMethods( BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public ); foreach (MethodInfo method in methods) { if (!method.IsVirtual) { continue; } ParameterInfo[] parameterInfo = method.GetParameters(); this.allowedTypes.Add(Utils.GetATypesFromType(parameterInfo[0].ParameterType)); } }
public override AType Execute(AType argument, Aplus environment = null) { ATypes currentType = argument.Type; if (argument.Length == 0) { if (currentType == ATypes.AFunc) { if (!this.allowedTypes.Contains(currentType)) { throw new Error.NonData(DomainErrorText); } return(ExecutePrimitive((AFunc)argument.Data, environment)); } return(AArray.Create(this.defaultResultType != ATypes.AType ? this.defaultResultType : argument.Type)); } // Check if we have a rule for the specific input type else if (!this.allowedTypes.Contains(currentType)) { // Rule not found // reset to the general case currentType = ATypes.AType; // Check if we have default case if (!this.allowedTypes.Contains(currentType)) { // throw a type error throw new Error.Type(this.TypeErrorText); } } return(ExecuteRecursion(argument, currentType, environment)); }
public DyadicScalar() { this.allowedMethods = new Dictionary <byte, MethodInfo>(); Type currentType = this.GetType(); DefaultResultAttribute attribute = currentType.GetSingleAttribute <DefaultResultAttribute>(); this.defaultResultType = (attribute != null) ? attribute.DefaultType : ATypes.AType; MethodInfo[] methods = currentType.GetMethods( BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public ); // Detect the methods and add a rule for it based on the parameter types foreach (MethodInfo method in methods) { DyadicScalarMethodAttribute scalarAttribute = method.GetSingleAttribute <DyadicScalarMethodAttribute>(); if (scalarAttribute == null) { continue; } ParameterInfo[] parameterInfo = method.GetParameters(); // Add the method to the allowed method's list this.allowedMethods.Add( ATypeMask( Utils.GetATypesFromType(parameterInfo[0].ParameterType), Utils.GetATypesFromType(parameterInfo[1].ParameterType) ), method ); } }
internal DecodeInformation(ATypes resultingType, double[] decodeValues) { this.type = resultingType; this.RequiresConvert = (resultingType != ATypes.AFloat);// ? false : true; this.decodeValues = decodeValues; }
private AType ExecuteRecursion(AType argument, ATypes currentType, Aplus environment) { AType result; if (argument.IsArray) { uint floatTypeCounter = 0; AType currentItem; result = AArray.Create(ATypes.AArray); for (int i = 0; i < argument.Length; i++) { currentItem = ExecuteRecursion(argument[i], currentType, environment); floatTypeCounter += (uint)((currentItem.Type == ATypes.AFloat) ? 1 : 0); result.AddWithNoUpdate(currentItem); } result.UpdateInfo(); if ((floatTypeCounter != result.Length) && (floatTypeCounter != 0)) { result.ConvertToFloat(); } } else { switch (currentType) { case ATypes.AInteger: result = ExecutePrimitive((AInteger)argument.Data, environment); break; case ATypes.AFloat: result = ExecutePrimitive((AFloat)argument.Data, environment); break; case ATypes.AChar: result = ExecutePrimitive((AChar)argument.Data, environment); break; case ATypes.ASymbol: result = ExecutePrimitive((ASymbol)argument.Data, environment); break; case ATypes.ABox: result = ExecutePrimitive((ABox)argument.Data, environment); break; case ATypes.AType: result = ExecuteDefault((AType)argument.Data, environment); break; default: throw new Error.Invalid("Something really went wrong..."); } } return result; }
public static AType Create(AType item, ATypes type = ATypes.ABox) { return new AReference(new ABox(item, type)); }
public static AType Create(ATypes type, params AType[] items) { return LocalAArray.Create(type, items); }
public DefaultResultAttribute(ATypes defaultType) { this.defaultType = defaultType; }
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; }
protected override void SetVariables(ATypes type) { this.type = ATypes.AFloat; this.fillerElement = AFloat.Create(double.PositiveInfinity); this.function = DyadicFunctionInstance.Min; }
protected override void SetVariables(ATypes type) { this.type = ATypes.AInteger; this.fillerElement = AInteger.Create(0); this.function = DyadicFunctionInstance.Or; }
public static AType ANull(ATypes type = ATypes.ANull) { return AArray.Create(type); }
/// <summary> /// AArray generated by type and shape with Reshape dyadic nonscalar function. /// If shape list is null, we give back the filler elemenet. /// </summary> /// <param name="type"></param> /// <param name="shape"></param> internal static AType FillElement(ATypes type, AType shape = null) { AType filler = null; switch (type) { case ATypes.ABox: case ATypes.AFunc: filler = ABox.Create(ANull()); break; case ATypes.AChar: filler = AChar.Create(' '); break; case ATypes.AFloat: filler = AFloat.Create(0); break; case ATypes.AInteger: filler = AInteger.Create(0); break; case ATypes.ASymbol: filler = ASymbol.Create(""); break; default: throw new NotImplementedException("Invalid use-case"); } if (shape != null) { return AplusCore.Runtime.Function.Dyadic.DyadicFunctionInstance.Reshape.Execute(filler, shape); } else { return filler; } }
public CastInfo(ATypes resultingType) { this.resultingType = resultingType; }
public static AType Create(ATypes type, params AType[] items) { return(LocalAArray.Create(type, items)); }
/// <summary> /// Returns an byte mask representing the type combination /// </summary> /// <param name="rightArgType">converted to int and shifted by 4</param> /// <param name="leftArgType">converted to int</param> /// <returns>type combination byte mask</returns> private byte ATypeMask(ATypes rightArgType, ATypes leftArgType) { return (byte)((((int)rightArgType) << 4) | ((int)leftArgType)); }
public new static AType Create(ATypes type, params AType[] items) { return new AReference(new LocalAArray(type, items)); }
public static AType ANull(ATypes type = ATypes.ANull) { return(AArray.Create(type)); }
public static bool MixedType(this ATypes argument) { return(argument == ATypes.ABox || argument == ATypes.AFunc || argument == ATypes.ASymbol); }
protected override void SetVariables(ATypes type) { this.type = ATypes.AFloat; this.fillerElement = AFloat.Create(double.NegativeInfinity); this.function = DyadicFunctionInstance.Max; }
/// <summary> /// This method sets the variables. /// </summary> /// <param name="type"></param> protected abstract void SetVariables(ATypes type);
/// <summary> /// Determines the system size of the given AType. /// </summary> /// <exception cref="Error.Domain"> /// Throws Domain error, if the argument is invalid for bitwise cast. /// </exception> /// <param name="argument">AType of the input.</param> /// <returns>Size of the given AType.</returns> private int GetTypeSize(ATypes argument) { int result; switch (argument) { case ATypes.AInteger: result = sizeof(Int32); break; case ATypes.AFloat: result = sizeof(Double); break; case ATypes.ASymbol: result = symbolSize; break; case ATypes.AChar: result = charSize; break; default: throw new Error.Domain(this.DomainErrorText); } return result; }
public LaminateJobInfo(ATypes resultType) { this.resultType = resultType; }