当前位置: 首页>>代码示例>>C#>>正文


C# ConstantExpression类代码示例

本文整理汇总了C#中ConstantExpression的典型用法代码示例。如果您正苦于以下问题:C# ConstantExpression类的具体用法?C# ConstantExpression怎么用?C# ConstantExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ConstantExpression类属于命名空间,在下文中一共展示了ConstantExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OrIsShortcircuit

        public void OrIsShortcircuit()
        {
            IExpression trueexpr = new ConstantExpression(true);
            IExpression dividebyzero = new BinaryOperatorExpression(new ConstantExpression(1), new ConstantExpression(0), BinaryOperator.Divide);

            Assert.IsTrue((bool)(new BooleanExpression(trueexpr, dividebyzero, BooleanOperator.Or)).Evaluate(null));
        }
开发者ID:ajlopez,项目名称:PythonSharp,代码行数:7,代码来源:BooleanExpressionTests.cs

示例2: Parse

        public Node Parse()
        {
            Expression curExpr = null;
            for (; ; ) {
                _tokens.MoveNext();
                Token t = _tokens.Current;

                switch (t.Kind) {
                    case TokenKinds.EOF:
                        return curExpr;
                    case TokenKinds.Operator:
                        if (curExpr == null) {
                            throw new SyntaxErrorException("expected value before operator");
                        }

                        curExpr = ActionExpression.Operator(((OperatorToken)t).DlrOperator,
                            curExpr,
                            (Expression)Parse());
                        break;
                    case TokenKinds.Constant:
                        curExpr = new ConstantExpression(((ConstantToken)t).Value);
                        break;
                }
            }
        }
开发者ID:xxjeng,项目名称:nuxleus,代码行数:25,代码来源:ToyParser.cs

示例3: CreateNotExpression

        public void CreateNotExpression()
        {
            IExpression trueexpr = new ConstantExpression(true);
            NotExpression expression = new NotExpression(trueexpr);

            Assert.AreEqual(trueexpr, expression.Expression);
        }
开发者ID:jose2190,项目名称:PythonSharp,代码行数:7,代码来源:NotExpressionTests.cs

示例4: AndIsShortcircuit

        public void AndIsShortcircuit()
        {
            IExpression falseexpr = new ConstantExpression(false);
            IExpression dividebyzero = new BinaryOperatorExpression(new ConstantExpression(1), new ConstantExpression(0), BinaryOperator.Divide);

            Assert.IsFalse((bool)(new BooleanExpression(falseexpr, dividebyzero, BooleanOperator.And)).Evaluate(null));
        }
开发者ID:ajlopez,项目名称:PythonSharp,代码行数:7,代码来源:BooleanExpressionTests.cs

示例5: EvaluateNotExpression

        public void EvaluateNotExpression()
        {
            IExpression trueexpr = new ConstantExpression(true);
            IExpression falseexpr = new ConstantExpression(false);

            Assert.IsFalse((bool)(new NotExpression(trueexpr)).Evaluate(null));
            Assert.IsTrue((bool)(new NotExpression(falseexpr)).Evaluate(null));
        }
开发者ID:jose2190,项目名称:PythonSharp,代码行数:8,代码来源:NotExpressionTests.cs

示例6: SetVariable

        public void SetVariable()
        {
            IExpression expression = new ConstantExpression(1);
            BindingEnvironment environment = new BindingEnvironment();
            ICommand command = new SetCommand("spam", expression);
            command.Execute(environment);

            Assert.AreEqual(1, environment.GetValue("spam"));
        }
开发者ID:ajlopez,项目名称:PythonSharp,代码行数:9,代码来源:SetCommandTests.cs

示例7: EvaluateOr

        public void EvaluateOr()
        {
            IExpression trueexpr = new ConstantExpression(true);
            IExpression falseexpr = new ConstantExpression(false);

            Assert.IsTrue((bool)(new BooleanExpression(trueexpr, trueexpr, BooleanOperator.Or)).Evaluate(null));
            Assert.IsTrue((bool)(new BooleanExpression(trueexpr, falseexpr, BooleanOperator.Or)).Evaluate(null));
            Assert.IsTrue((bool)(new BooleanExpression(falseexpr, trueexpr, BooleanOperator.Or)).Evaluate(null));
            Assert.IsFalse((bool)(new BooleanExpression(falseexpr, falseexpr, BooleanOperator.Or)).Evaluate(null));
        }
开发者ID:ajlopez,项目名称:PythonSharp,代码行数:10,代码来源:BooleanExpressionTests.cs

示例8: CreateBooleanExpression

        public void CreateBooleanExpression()
        {
            IExpression trueexpr = new ConstantExpression(true);
            IExpression falseexpr = new ConstantExpression(false);
            BooleanExpression expression = new BooleanExpression(trueexpr, falseexpr, BooleanOperator.Or);

            Assert.AreEqual(trueexpr, expression.Left);
            Assert.AreEqual(falseexpr, expression.Right);

            Assert.AreEqual(BooleanOperator.Or, expression.Operation);
        }
开发者ID:ajlopez,项目名称:PythonSharp,代码行数:11,代码来源:BooleanExpressionTests.cs

示例9: CreateSetIndexCommand

        public void CreateSetIndexCommand()
        {
            IExpression targetExpression = new ConstantExpression(1);
            IExpression indexExpression = new ConstantExpression(2);
            IExpression valueExpression = new ConstantExpression(3);

            var command = new SetIndexCommand(targetExpression, indexExpression, valueExpression);

            Assert.AreEqual(targetExpression, command.TargetExpression);
            Assert.AreEqual(indexExpression, command.IndexExpression);
            Assert.AreEqual(valueExpression, command.Expression);
        }
开发者ID:Refandler,项目名称:PythonSharp,代码行数:12,代码来源:SetIndexCommandTests.cs

示例10: CreateSetCommand

        public void CreateSetCommand()
        {
            IExpression expression = new ConstantExpression("bar");
            SetCommand command = new SetCommand("foo", expression);

            Assert.IsNotNull(command);
            Assert.IsNotNull(command.Target);
            Assert.IsNotNull(command.Expression);

            Assert.AreEqual("foo", command.Target);
            Assert.AreEqual(expression, command.Expression);
        }
开发者ID:ajlopez,项目名称:PythonSharp,代码行数:12,代码来源:SetCommandTests.cs

示例11: ExecuteSetIndexCommandOnList

        public void ExecuteSetIndexCommandOnList()
        {
            var list = new List<object>() { 1, 2, 2 };
            IExpression targetExpression = new ConstantExpression(list);
            IExpression indexExpression = new ConstantExpression(2);
            IExpression valueExpression = new ConstantExpression(3);

            var command = new SetIndexCommand(targetExpression, indexExpression, valueExpression);
            command.Execute(null);

            Assert.AreEqual(3, list[2]);
        }
开发者ID:Refandler,项目名称:PythonSharp,代码行数:12,代码来源:SetIndexCommandTests.cs

示例12: AConstant_ShouldReturnTheConstantValue

        public void AConstant_ShouldReturnTheConstantValue()
        {
            // Arrange
            var expectedValue = 3;
            var sut = new ConstantExpression(expectedValue);

            // Act
            var actual = sut.Eval();

            // Assert
            Assert.AreEqual(expectedValue, actual);
        }
开发者ID:thibautdavid,项目名称:netpatterns,代码行数:12,代码来源:ExpressionsTests.cs

示例13: ExecuteSetIndexCommandOnArray

        public void ExecuteSetIndexCommandOnArray()
        {
            var array = new object[] { 1, 2, 2 };
            IExpression targetExpression = new ConstantExpression(array);
            IExpression indexExpression = new ConstantExpression(2);
            IExpression valueExpression = new ConstantExpression(3);

            var command = new SetIndexCommand(targetExpression, indexExpression, valueExpression);
            command.Execute(null);

            Assert.AreEqual(3, array[2]);
        }
开发者ID:Refandler,项目名称:PythonSharp,代码行数:12,代码来源:SetIndexCommandTests.cs

示例14: ExecuteSetIndexCommandOnDictionary

        public void ExecuteSetIndexCommandOnDictionary()
        {
            var dictionary = new Hashtable();
            IExpression targetExpression = new ConstantExpression(dictionary);
            IExpression indexExpression = new ConstantExpression("foo");
            IExpression valueExpression = new ConstantExpression("bar");

            var command = new SetIndexCommand(targetExpression, indexExpression, valueExpression);
            command.Execute(null);

            Assert.AreEqual("bar", dictionary["foo"]);
        }
开发者ID:Refandler,项目名称:PythonSharp,代码行数:12,代码来源:SetIndexCommandTests.cs

示例15: Differentiate

        /// <summary>
        /// Performs reverse-mode (adjoint) automatic differentiation 
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="dependentVariable"></param>
        /// <param name="independentVariables"></param>
        public static void Differentiate(BlockExpressionBuilder builder, 
            out IList<Expression> derivativeExpressions,
            VectorParameterExpression dependentVariable,
            params VectorParameterExpression[] independentVariables)
        {
            if (independentVariables.Length == 0)
            {
                derivativeExpressions = null;
                return;
            }

            var block = builder.ToBlock();
            // change the numbering of variables; arguments first, then locals
            List<int>[] jLookup;
            Function[] f;

            // we want a list of functions which can be unary or binary (in principle high order if it makes sense) and a look-up
            // each function is associated with a parameter, which is either an argument or a local
            // for each function index we return a list of the indices of the functions that reference the parameter
            GetFunctions(block, out f, out jLookup);

            int N = dependentVariable.Index;

            bool[] derivativeRequired; int[] derivativeExpressionIndex;
            IdentifyNeccesaryDerivatives(N, jLookup, independentVariables, out derivativeRequired, out derivativeExpressionIndex);

            // the list of operations needed to calculate the derivatives (*all* derivatives)
            derivativeExpressions = new Expression[independentVariables.Length];
            var dxNdx = new Expression[N + 1];
            dxNdx[N] = new ConstantExpression<double>(1.0);
            for (int i = N - 1; i >= 0; i--)
            {
                if (!derivativeRequired[i]) continue;
                // dxN / dxi
                // need to find all operation indices j such that p(j) contains i
                // that is, all functions that have xi as an argument (these must therefore have a higher index than i)
                VectorParameterExpression total = new ConstantExpression<double>(0);
                var xi = f[i].Parameter;
                //need sum of dfj/dxi dXN/dxj
                foreach (var j in jLookup[i])
                {
                    var fj = f[j];
                    var dfjdxi = Differentiate(fj, xi, builder); // dfj/dxi
                    var dXNdxj = dxNdx[j]; // dXN/dxj
                    var product = builder.AddProductExpression(dfjdxi, dXNdxj);
                    total = builder.AddAdditionExpression(total, product);
                }
                dxNdx[i] = total;
                int targetIndex = derivativeExpressionIndex[i];
                if (targetIndex != -1) derivativeExpressions[targetIndex] = total;
            }
        }
开发者ID:joemoorhouse,项目名称:vector-accelerator,代码行数:58,代码来源:AlgorithmicDifferentiator.cs


注:本文中的ConstantExpression类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。