• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# ConstantExpression类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: Add

 /// <summary>
 /// Adds the specified constant expression.
 /// </summary>
 /// <param name="constantExpression">The constant expression.</param>
 /// <param name="exponent">The exponent.</param>
 public void Add(ConstantExpression constantExpression, double exponent)
 {
     var additionalConstant = Math.Pow(constantExpression.Constant, exponent);
     if (this.constantFlatIdentifierRepresentation == null)
     {
         this.constantFlatIdentifierRepresentation = new ConstantFlatIdentifierRepresentation(additionalConstant);
         this.additionalCount++;
     }
     else
     {
         this.constantFlatIdentifierRepresentation =
             new ConstantFlatIdentifierRepresentation(
                 this.constantFlatIdentifierRepresentation.Constant * additionalConstant);
     }
 }
开发者ID:hugener,项目名称:Sundew.Quantities,代码行数:20,代码来源:FlatRepresentationBuilder.cs


示例17: Main

        static void Main(string[] args)
        {
            IArithmeticVisitor visitor = new ConsoleArithmeticVisitor();

            IArithmeticExpression leftInnerNode = new ConstantExpression(39);
            IArithmeticExpression rightInnerNode = new ConstantExpression(13);

            IArithmeticExpression leftNode = new ConstantExpression(15);
            IArithmeticExpression rightNode = new SubtractionExpression(leftInnerNode, rightInnerNode);

            IArithmeticExpression rootNode = new MultiplicationExpression(leftNode, new BracketsExpression(rightNode));

            rootNode.Accept(visitor);

            Console.WriteLine();
        }
开发者ID:hatchan,项目名称:ArithmeticVisitor,代码行数:16,代码来源:Program.cs


示例18: PostWalk

 public virtual void PostWalk(ConstantExpression node) { }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:1,代码来源:PythonWalker.Generated.cs


示例19: Walk

 // ConstantExpression
 public virtual bool Walk(ConstantExpression node) { return true; }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:2,代码来源:PythonWalker.Generated.cs


示例20: ExpressionsEnumerable

        public void ExpressionsEnumerable(object value, int blockSize)
        {
            ConstantExpression[] values = new ConstantExpression[blockSize];
            for (int i = 0; i != values.Length; ++i)
                values[i] = Expression.Constant(value);

            BlockExpression block = Expression.Block(SingleParameter, values);

            Assert.True(values.SequenceEqual(block.Expressions));
            int index = 0;
            foreach (Expression exp in ((IEnumerable)block.Expressions))
                Assert.Same(exp, values[index++]);
        }
开发者ID:SGuyGe,项目名称:corefx,代码行数:13,代码来源:ParameterBlockTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ConstantValue类代码示例发布时间:2022-05-24
下一篇:
C# Constant类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap