/// <summary> /// Создание листа /// </summary> /// <param name="parent"></param> /// <param name="value"></param> /// <param name="decision"></param> public DecisionNode(ComparisonKind comparison, double value, int decision) { this.Value = value; this.Comparison = comparison; this.Attribute = null; this.Decision = decision; }
public static bool Compare(ComparisonKind comparison, double x, double y) { switch (comparison) { case ComparisonKind.Equal: return(x == y); case ComparisonKind.GreaterThan: return(x > y); case ComparisonKind.GreaterThanOrEqual: return(x >= y); case ComparisonKind.LessThan: return(x < y); case ComparisonKind.LessThanOrEqual: return(x <= y); case ComparisonKind.NotEqual: return(x != y); case ComparisonKind.None: throw new InvalidOperationException("Node comparison type not specified"); default: throw new InvalidOperationException("Unexpected node comparison type"); } }
/// <summary> /// создание узла /// </summary> /// <param name="parent"></param> /// <param name="value"></param> /// <param name="comparison"></param> public DecisionNode(ComparisonKind comparison, double value, AttributeVariable attribute) { this.Value = value; this.Comparison = comparison; this.Attribute = attribute; this.Decision = null; }
internal static VkCompareOp VdToVkCompareOp(ComparisonKind comparisonKind) { switch (comparisonKind) { case ComparisonKind.Never: return(VkCompareOp.Never); case ComparisonKind.Less: return(VkCompareOp.Less); case ComparisonKind.Equal: return(VkCompareOp.Equal); case ComparisonKind.LessEqual: return(VkCompareOp.LessOrEqual); case ComparisonKind.Greater: return(VkCompareOp.Greater); case ComparisonKind.NotEqual: return(VkCompareOp.NotEqual); case ComparisonKind.GreaterEqual: return(VkCompareOp.GreaterOrEqual); case ComparisonKind.Always: return(VkCompareOp.Always); default: throw Illegal.Value <ComparisonKind>(); } }
public static bool Check(this ComparisonKind comparisonKind, double left, double right) { switch (comparisonKind) { case ComparisonKind.Equal: return(Math.Abs(left - right) < Double.Epsilon); case ComparisonKind.NotEqual: return(Math.Abs(left - right) > Double.Epsilon); case ComparisonKind.GreaterThanOrEqual: return(left >= right); case ComparisonKind.GreaterThan: return(left > right); case ComparisonKind.LessThan: return(left < right); case ComparisonKind.LessThanOrEqual: return(left <= right); default: throw new ArgumentException(); } }
public Comp(ComparisonKind kind, ComparisonLiftingKind lifting, StackType inputType, Sign sign, ILInstruction left, ILInstruction right) : base(OpCode.Comp, left, right) { this.kind = kind; this.LiftingKind = lifting; this.InputType = inputType; this.Sign = sign; }
/// <summary> /// Lift a C# comparison. /// /// The output instructions should evaluate to <c>false</c> when any of the <c>nullableVars</c> is <c>null</c>. /// Otherwise, the output instruction should evaluate to the same value as the input instruction. /// The output instruction should have the same side-effects (incl. exceptions being thrown) as the input instruction. /// This means unlike LiftNormal(), we cannot rely on the input instruction not being evaluated if /// a variable is <c>null</c>. /// </summary> Comp LiftCSharpComparison(Comp comp, ComparisonKind newComparisonKind) { var(left, leftBits) = DoLift(comp.Left); var(right, rightBits) = DoLift(comp.Right); if (left != null && right == null && SemanticHelper.IsPure(comp.Right.Flags)) { // Embed non-nullable pure expression in lifted expression. right = comp.Right.Clone(); } if (left == null && right != null && SemanticHelper.IsPure(comp.Left.Flags)) { // Embed non-nullable pure expression in lifted expression. left = comp.Left.Clone(); } // due to the restrictions on side effects, we only allow instructions that are pure after lifting. // (we can't check this before lifting due to the calls to GetValueOrDefault()) if (left != null && right != null && SemanticHelper.IsPure(left.Flags) && SemanticHelper.IsPure(right.Flags)) { var bits = leftBits ?? rightBits; if (rightBits != null) { bits.UnionWith(rightBits); } if (!bits.All(0, nullableVars.Count)) { // don't lift if a nullableVar doesn't contribute to the result return(null); } context.Step("NullableLiftingTransform: C# comparison", comp); return(new Comp(newComparisonKind, ComparisonLiftingKind.CSharp, comp.InputType, comp.Sign, left, right)); } return(null); }
public static ComparisonKind Negate(this ComparisonKind kind) { switch (kind) { case ComparisonKind.Equality: return(ComparisonKind.Inequality); case ComparisonKind.Inequality: return(ComparisonKind.Equality); case ComparisonKind.LessThan: return(ComparisonKind.GreaterThanOrEqual); case ComparisonKind.LessThanOrEqual: return(ComparisonKind.GreaterThan); case ComparisonKind.GreaterThan: return(ComparisonKind.LessThanOrEqual); case ComparisonKind.GreaterThanOrEqual: return(ComparisonKind.LessThan); default: throw new NotSupportedException(); } }
public static ComparisonKind GetOpposed(this ComparisonKind comparisonKind) { switch (comparisonKind) { case ComparisonKind.None: return(ComparisonKind.None); case ComparisonKind.Equal: return(ComparisonKind.NotEqual); case ComparisonKind.NotEqual: return(ComparisonKind.Equal); case ComparisonKind.GreaterThanOrEqual: return(ComparisonKind.LessThan); case ComparisonKind.GreaterThan: return(ComparisonKind.LessThanOrEqual); case ComparisonKind.LessThan: return(ComparisonKind.GreaterThanOrEqual); case ComparisonKind.LessThanOrEqual: return(ComparisonKind.GreaterThan); default: throw new ArgumentException(); } }
public static BinaryOperatorType ToBinaryOperatorType(this ComparisonKind kind) { switch (kind) { case ComparisonKind.Equality: return(BinaryOperatorType.Equality); case ComparisonKind.Inequality: return(BinaryOperatorType.InEquality); case ComparisonKind.LessThan: return(BinaryOperatorType.LessThan); case ComparisonKind.LessThanOrEqual: return(BinaryOperatorType.LessThanOrEqual); case ComparisonKind.GreaterThan: return(BinaryOperatorType.GreaterThan); case ComparisonKind.GreaterThanOrEqual: return(BinaryOperatorType.GreaterThanOrEqual); default: throw new NotSupportedException(); } }
/// <summary> /// Returns a <see cref="System.String"/> that represents this instance. /// </summary> /// /// <param name="comparison">The comparison type.</param> /// /// <returns> /// A <see cref="System.String"/> that represents this instance. /// </returns> /// public static string ToString(this ComparisonKind comparison) { switch (comparison) { case ComparisonKind.Equal: return("=="); case ComparisonKind.GreaterThan: return(">"); case ComparisonKind.GreaterThanOrEqual: return(">="); case ComparisonKind.LessThan: return("<"); case ComparisonKind.LessThanOrEqual: return("<="); case ComparisonKind.NotEqual: return("!="); default: throw new InvalidOperationException("Unexpected node comparison type."); } }
/// <summary> /// Creates a new <see cref="DecisionRule"/> from a <see cref="DecisionTree"/>'s /// <see cref="DecisionNode"/>. This node must be a leaf, cannot be the root, and /// should have one output value. /// </summary> /// /// <param name="node">A <see cref="DecisionNode"/> from a <see cref="DecisionTree"/>.</param> /// /// <returns>A <see cref="DecisionRule"/> representing the given <paramref name="node"/>.</returns> /// public static DecisionRule FromNode(DecisionNode node) { if (node == null) { throw new ArgumentNullException("node"); } if (!node.IsLeaf || node.IsRoot || !node.Value.HasValue) { throw new InvalidOperationException( "Only leaf nodes that have a parent can be converted to rules."); } DecisionNode current = node; DecisionTree owner = current.Owner; double output = current.Output.Value; var antecedents = new List <Antecedent>(); while (current.Parent != null) { int index = current.Parent.Branches.AttributeIndex; ComparisonKind comparison = current.Comparison; double value = current.Value.Value; antecedents.Insert(0, new Antecedent(index, comparison, value)); current = current.Parent; } return(new DecisionRule(node.Owner.Attributes, output, antecedents)); }
public PipelineKey( FaceCullMode cullMode, bool depthWriteEnabled, ComparisonKind depthComparison, bool blendEnabled, BlendFactor sourceFactor, BlendFactor destinationColorFactor, BlendFactor destinationAlphaFactor) { CullMode = cullMode; DepthWriteEnabled = depthWriteEnabled; DepthComparison = depthComparison; BlendEnabled = blendEnabled; SourceFactor = sourceFactor; DestinationColorFactor = destinationColorFactor; DestinationAlphaFactor = destinationAlphaFactor; _hashCode = HashCode.Combine( CullMode, DepthWriteEnabled, DepthComparison, BlendEnabled, SourceFactor, DestinationColorFactor, DestinationAlphaFactor); }
/// <summary> /// Initializes a new instance of the <see cref="PropertyInfo"/> class. /// </summary> /// <param name="description"> /// The description of the property, for use in a summary comment. /// </param> /// <param name="serializedName"> /// The name of the property as serialized in the JSON file. /// </param> /// <param name="comparisonKind"> /// The kind of comparison code required by the property. /// </param> /// <param name="hashKind"> /// The kind of hash value computation code required by the property. /// </param> /// <param name="initializationKind"> /// The kind of initialization code required by the property. /// </param> /// <param name="type"> /// The type of the property. /// </param> /// <param name="typeName"> /// The name of the type of the property. /// </param> /// <param name="namespaceName"> /// The qualified name of the namespace declaration required by this type, /// or <code>null</code> if no namespace declaration is required. /// </param> /// <param name="isRequired"> /// <code>true</code> if this property is required by the schema; /// otherwise <code>false</code>. /// </param> /// <param name="isOfSchemaDefinedType"> /// <code>true</code> if this property is of a type defined by the schema (or an; /// array of a schema-defined type otherwise <code>false</code>. /// </param> /// <param name="arrayRank"> /// The array rank of the property type. 0 means the property is not an array. /// </param> /// <param name="declarationOrder"> /// The 0-based order in which the property was declared in the schema. /// </param> public PropertyInfo( string description, string serializedName, ComparisonKind comparisonKind, HashKind hashKind, InitializationKind initializationKind, TypeSyntax type, string namespaceName, bool isRequired, bool isOfSchemaDefinedType, int arrayRank, int declarationOrder) { Description = description; SerializedName = serializedName; ComparisonKind = comparisonKind; HashKind = hashKind; InitializationKind = initializationKind; Type = type; TypeName = type.ToString(); NamespaceName = namespaceName; IsRequired = isRequired; IsOfSchemaDefinedType = isOfSchemaDefinedType; ArrayRank = arrayRank; DeclarationOrder = declarationOrder; }
internal static StencilFunction VdToGLStencilFunction(ComparisonKind comparison) { switch (comparison) { case ComparisonKind.Never: return(StencilFunction.Never); case ComparisonKind.Less: return(StencilFunction.Less); case ComparisonKind.Equal: return(StencilFunction.Equal); case ComparisonKind.LessEqual: return(StencilFunction.Lequal); case ComparisonKind.Greater: return(StencilFunction.Greater); case ComparisonKind.NotEqual: return(StencilFunction.Notequal); case ComparisonKind.GreaterEqual: return(StencilFunction.Gequal); case ComparisonKind.Always: return(StencilFunction.Always); default: throw Illegal.Value <ComparisonKind>(); } }
internal static Comparison VdToD3D11Comparison(ComparisonKind comparisonKind) { switch (comparisonKind) { case ComparisonKind.Never: return(Comparison.Never); case ComparisonKind.Less: return(Comparison.Less); case ComparisonKind.Equal: return(Comparison.Equal); case ComparisonKind.LessEqual: return(Comparison.LessEqual); case ComparisonKind.Greater: return(Comparison.Greater); case ComparisonKind.NotEqual: return(Comparison.NotEqual); case ComparisonKind.GreaterEqual: return(Comparison.GreaterEqual); case ComparisonKind.Always: return(Comparison.Always); default: throw Illegal.Value <ComparisonKind>(); } }
public IEnumerable <IRowsAnalyzer> Instantiate(ComparisonKind kind) { var list = new List <IRowsAnalyzer>(); list.Add(new KeyMatchingRowsAnalyzer()); switch (kind) { case ComparisonKind.SubsetOf: list.Add(new UnexpectedRowsAnalyzer()); break; case ComparisonKind.SupersetOf: list.Add(new MissingRowsAnalyzer()); break; case ComparisonKind.EqualTo: list.Add(new MissingRowsAnalyzer()); list.Add(new UnexpectedRowsAnalyzer()); break; default: throw new ArgumentOutOfRangeException(); } return(list); }
private StatementSyntax GeneratePropertyComparison( string propertyName, ExpressionSyntax left, ExpressionSyntax right) { ComparisonKind comparisonKind = _propertyInfoDictionary[propertyName].ComparisonKind; switch (comparisonKind) { case ComparisonKind.OperatorEquals: return(GeneratorOperatorEqualsComparison(left, right)); case ComparisonKind.ObjectEquals: return(GenerateObjectEqualsComparison(left, right)); case ComparisonKind.EqualityComparerEquals: return(GenerateEqualityEqualsComparison(propertyName, left, right)); case ComparisonKind.Collection: return(MakeCollectionEqualsTest(propertyName, left, right)); case ComparisonKind.Dictionary: return(MakeDictionaryEqualsTest(propertyName, left, right)); default: throw new ArgumentException($"Property {propertyName} has unknown comparison type {comparisonKind}."); } }
public static double[] GetVeryfied(this double[] array, ComparisonKind comparisonKind, double comparisonConstant) { var corrects = new List <double>(); corrects.AddRange(array.Where(element => comparisonKind.Check(element, comparisonConstant))); return(corrects.ToArray()); }
public Comp(ComparisonKind kind, Sign sign, ILInstruction left, ILInstruction right) : base(OpCode.Comp, left, right) { this.kind = kind; this.LiftingKind = ComparisonLiftingKind.None; this.InputType = left.ResultType; this.Sign = sign; Debug.Assert(left.ResultType == right.ResultType); }
Comp LiftCSharpEqualityComparison(Comp valueComp, ComparisonKind newComparisonKind, ILInstruction hasValueTest) { Debug.Assert(newComparisonKind.IsEqualityOrInequality()); bool hasValueTestNegated = false; while (hasValueTest.MatchLogicNot(out var arg)) { hasValueTest = arg; hasValueTestNegated = !hasValueTestNegated; } // The HasValue comparison must be the same operator as the Value comparison. if (hasValueTest is Comp hasValueComp) { // Comparing two nullables: HasValue comparison must be the same operator as the Value comparison if ((hasValueTestNegated ? hasValueComp.Kind.Negate() : hasValueComp.Kind) != newComparisonKind) { return(null); } if (!MatchHasValueCall(hasValueComp.Left, out var leftVar)) { return(null); } if (!MatchHasValueCall(hasValueComp.Right, out var rightVar)) { return(null); } nullableVars = new List <ILVariable> { leftVar }; var(left, leftBits) = DoLift(valueComp.Left); nullableVars[0] = rightVar; var(right, rightBits) = DoLift(valueComp.Right); if (left != null && right != null && leftBits[0] && rightBits[0] && SemanticHelper.IsPure(left.Flags) && SemanticHelper.IsPure(right.Flags) ) { context.Step("NullableLiftingTransform: C# (in)equality comparison", valueComp); return(new Comp(newComparisonKind, ComparisonLiftingKind.CSharp, valueComp.InputType, valueComp.Sign, left, right)); } } else if (newComparisonKind == ComparisonKind.Equality && !hasValueTestNegated && MatchHasValueCall(hasValueTest, out var v)) { // Comparing nullable with non-nullable -> we can fall back to the normal comparison code. nullableVars = new List <ILVariable> { v }; return(LiftCSharpComparison(valueComp, newComparisonKind)); } else if (newComparisonKind == ComparisonKind.Inequality && hasValueTestNegated && MatchHasValueCall(hasValueTest, out v)) { // Comparing nullable with non-nullable -> we can fall back to the normal comparison code. nullableVars = new List <ILVariable> { v }; return(LiftCSharpComparison(valueComp, newComparisonKind)); } return(null); }
internal SuggestSplitPoint(int attributeIndex, ComparisonKind comparisonKind, double splitValue, SplitInformation left, SplitInformation right = null) { AttributeIndex = attributeIndex; ComparisonKind = comparisonKind; SplitValue = splitValue; Left = left; Right = right; }
/// <summary> /// Constructs a new StencilBehaviorDescription. /// </summary> /// <param name="fail">The operation performed on samples that fail the stencil test.</param> /// <param name="pass">The operation performed on samples that pass the stencil test.</param> /// <param name="depthFail">The operation performed on samples that pass the stencil test but fail the depth test.</param> /// <param name="comparison">The comparison operator used in the stencil test.</param> public StencilBehaviorDescription( StencilOperation fail, StencilOperation pass, StencilOperation depthFail, ComparisonKind comparison) { Fail = fail; Pass = pass; DepthFail = depthFail; Comparison = comparison; }
internal SplitDecisionNode(DecisionTree owner, DecisionNode parent, SplitInformation splitInformation, ComparisonKind comparisonKind, double splitValue, int attributeIndex) : base(owner) { Parent = parent; Value = splitValue; Comparison = comparisonKind; SplitInformation = splitInformation; AttributeIndex = attributeIndex; }
/// <summary> /// Constructs a new <see cref="DepthStencilStateDescription"/>. This describes a depth-stencil state with no stencil /// testing enabled. /// </summary> /// <param name="depthTestEnabled">Controls whether depth testing is enabled.</param> /// <param name="depthWriteEnabled">Controls whether new depth values are written to the depth buffer.</param> /// <param name="comparisonKind">The <see cref="Veldrid.ComparisonKind"/> used when considering new depth values.</param> public DepthStencilStateDescription(bool depthTestEnabled, bool depthWriteEnabled, ComparisonKind comparisonKind) { DepthTestEnabled = depthTestEnabled; DepthWriteEnabled = depthWriteEnabled; DepthComparison = comparisonKind; StencilTestEnabled = false; StencilFront = default(StencilBehaviorDescription); StencilBack = default(StencilBehaviorDescription); StencilReadMask = 0; StencilWriteMask = 0; StencilReference = 0; }
public ComparisonRelationship(ComparisonKind comparisonKind, SymbolicValue leftOperand, SymbolicValue rightOperand) : base(leftOperand, rightOperand) { ComparisonKind = comparisonKind; this.hash = new Lazy <int>(() => { var h = 19; h = h * 31 + ComparisonKind.GetHashCode(); h = h * 31 + base.GetHashCode(); return(h); }); }
public Pipeline GetCachedPipeline( FaceCullMode cullMode, bool depthWriteEnabled, ComparisonKind depthComparison, bool blendEnabled, BlendFactor sourceFactor, BlendFactor destinationColorFactor, BlendFactor destinationAlphaFactor) { var key = new PipelineKey( cullMode, depthWriteEnabled, depthComparison, blendEnabled, sourceFactor, destinationColorFactor, destinationAlphaFactor); if (!_pipelines.TryGetValue(key, out var result)) { var blendState = new BlendStateDescription( RgbaFloat.White, new BlendAttachmentDescription( blendEnabled, sourceFactor, destinationColorFactor, BlendFunction.Add, sourceFactor, destinationAlphaFactor, BlendFunction.Add)); var depthState = DepthStencilStateDescription.DepthOnlyLessEqual; depthState.DepthWriteEnabled = depthWriteEnabled; depthState.DepthComparison = depthComparison; var rasterizerState = RasterizerStateDescriptionUtility.DefaultFrontIsCounterClockwise; rasterizerState.CullMode = cullMode; _pipelines.Add(key, result = AddDisposable(GraphicsDevice.ResourceFactory.CreateGraphicsPipeline( new GraphicsPipelineDescription( blendState, depthState, rasterizerState, PrimitiveTopology.TriangleList, ShaderSet.Description, _resourceLayouts, RenderPipeline.GameOutputDescription)))); } return(result); }
public void Parse_Symbols_Success(string input, ComparisonKind expectedComparisonKind, string expectedLeftSymbol, string expectedRightSymbol) { AssertParser.SucceedsWith(Parsers.Comparison, input, actualComparison => { Assert.Equal(expectedComparisonKind, actualComparison.ComparisonKind); Assert.NotNull(actualComparison.Left); Symbol left = Assert.IsType <Symbol>(actualComparison.Left); Assert.Equal(left.Name, expectedLeftSymbol); Assert.NotNull(actualComparison.Right); Symbol right = Assert.IsType <Symbol>(actualComparison.Right); Assert.Equal(right.Name, expectedRightSymbol); }); }
public void ParseCompare_QuotedStrings_Success(string input, ComparisonKind expectedComparisonKind, string expectedLeftContent, string expectedRightContent) { AssertParser.SucceedsWith(Parsers.Comparison, input, actualComparison => { Assert.Equal(expectedComparisonKind, actualComparison.ComparisonKind); Assert.NotNull(actualComparison.Left); QuotedString left = Assert.IsType <QuotedString>(actualComparison.Left); Assert.Equal(expectedLeftContent, left.StringContent); Assert.NotNull(actualComparison.Right); QuotedString right = Assert.IsType <QuotedString>(actualComparison.Right); Assert.Equal(expectedRightContent, right.StringContent); }); }
public void Parse_Unary_Not_Comparison_QuotedString_Success(string input, ComparisonKind expectedComparisonKind, string expectedLeftString, string expectedRightString) { AssertParser.SucceedsWith(Parsers.Logical, input, actualLogical => { Assert.Equal(LogicalOperatorKind.Not, actualLogical.OperatorKind); Compare comparison = Assert.IsType <Compare>(actualLogical.Right); Assert.Equal(expectedComparisonKind, comparison.ComparisonKind); QuotedString leftString = Assert.IsType <QuotedString>(comparison.Left); Assert.Equal(expectedLeftString, leftString.StringContent); QuotedString rightString = Assert.IsType <QuotedString>(comparison.Right); Assert.Equal(expectedRightString, rightString.StringContent); }); }
public ComparisonExpression(Expression left, Expression right, ComparisonKind kind) { Left = left; Right = right; Kind = kind; }
private static string getComparisonString(ComparisonKind comparison) { switch (comparison) { case ComparisonKind.Equal: return "=="; case ComparisonKind.GreaterThan: return ">"; case ComparisonKind.GreaterThanOrEqual: return ">="; case ComparisonKind.LessThan: return "<"; case ComparisonKind.LessThanOrEqual: return "<="; case ComparisonKind.NotEqual: return "!="; default: throw new InvalidOperationException("Unexpected node comparison type."); } }
public ComparisonSymbolicValue(ComparisonKind comparisonKind, SymbolicValue leftOperand, SymbolicValue rightOperand) : base(leftOperand, rightOperand) { this.comparisonKind = comparisonKind; }
public ComparisonRelationship(ComparisonKind comparisonKind, SymbolicValue leftOperand, SymbolicValue rightOperand) : base(leftOperand, rightOperand) { ComparisonKind = comparisonKind; }