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

C# Variable类代码示例

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

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



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

示例1: Clone

        public void Clone()
        {
            var x = new Variable<int>("x")
                {
                    Values = {1, 2, 3},
                    Unit = new Unit("distance", "m"),
                    ExtrapolationType = ExtrapolationType.Constant,
                    InterpolationType = InterpolationType.Linear
                };

            var clone = (IVariable<int>)x.Clone();

            //Assert.IsTrue(clone.Values.SequenceEqual(new[] {1, 2, 3}));
            Assert.AreEqual(x.Name, clone.Name);
            Assert.AreNotEqual(x, clone);
            Assert.AreNotEqual(x.Store, clone.Store); // clone creates a new deep copy of the variable (in-memory)

            x.Values
                .Should("values must be copied").Have.SameSequenceAs(new[] { 1, 2, 3 });
            Assert.AreEqual(x.ExtrapolationType, clone.ExtrapolationType);
            Assert.AreEqual(x.InterpolationType, clone.InterpolationType);
            Assert.AreNotSame(x.Unit, clone.Unit);
            Assert.AreEqual(x.Unit.Name, clone.Unit.Name);
            Assert.AreEqual(x.Unit.Symbol, clone.Unit.Symbol);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:25,代码来源:VariableTest.cs


示例2: VerifyPropertiesOfVariableOfTypeShort

        public void VerifyPropertiesOfVariableOfTypeShort()
        {
            Type declaredType = typeof(short);
            Variable<short> vInt = new Variable<short>(Guid.Empty);

            Assert.Equal(declaredType, vInt.DataType);
        }
开发者ID:BgRva,项目名称:Blob1,代码行数:7,代码来源:VariableFixture.cs


示例3: Procedure

 public Procedure(string name, VariableSequence valArgs, Variable resultArg, StatementSequence statements)
 {
     AddChild(valArgs);
     AddChild(resultArg);
     AddChild(statements);
     _name = name;
 }
开发者ID:einaregilsson,项目名称:While-Language,代码行数:7,代码来源:Procedure.cs


示例4: ShouldSolveSystemWith1EquationAnd2Variables

        public void ShouldSolveSystemWith1EquationAnd2Variables()
        {
            //x+y=10    x=6; y=4
            //x-y=2
            var variableX = new Variable("x");
            var variableY = new Variable("y");

            var left1FirstEq = new Expression(1, variableX);
            var left2FirstEq = new Expression(1, variableY);
            var rightFirstEq = new Expression(10, Variable.NULL);

            var left1SecondEq = new Expression(1, variableX);
            var left2SecondEq = new Expression(-1, variableY);
            var rightSecondEq = new Expression(2, Variable.NULL);

            var firstEquation = new Equation(new List<Expression>() { left1FirstEq, left2FirstEq }, rightFirstEq);
            var secondEquation = new Equation(new List<Expression>() {left1SecondEq, left2SecondEq}, rightSecondEq);

            var target = new SystemOfEquations(new List<Equation>() {firstEquation, secondEquation});
            target.Solve();
            var resultX = variableX.Value;
            var resultY = variableY.Value;

            Assert.AreEqual(1, resultX.Count);
            Assert.AreEqual(1, resultY.Count);
            Assert.AreEqual(Variable.NULL, resultX.First().Variable);
            Assert.AreEqual(6, resultX.First().Coefficient);
            Assert.AreEqual(Variable.NULL, resultY.First().Variable);
            Assert.AreEqual(4, resultY.First().Coefficient);
        }
开发者ID:qqudesnik,项目名称:Gauss,代码行数:30,代码来源:SystemOfEquationsTests.cs


示例5: VerifyPropertiesOfVariableOfTypeBool

        public void VerifyPropertiesOfVariableOfTypeBool()
        {
            Type declaredType = typeof(bool);
            Variable<bool> vInt = new Variable<bool>(Guid.Empty);

            Assert.Equal(declaredType, vInt.DataType);
        }
开发者ID:BgRva,项目名称:Blob1,代码行数:7,代码来源:VariableFixture.cs


示例6: Test_Double_Variable_Value_Set

 public void Test_Double_Variable_Value_Set()
 {
     Variable<double> testVar = new Variable<double>("testVar", default(double), false);
     testVar.SetValue(11.15623);
     double value = testVar.Value;
     Assert.AreEqual(11.15623, value, "Value setter does not work properly.<Double>");
 }
开发者ID:EBIA,项目名称:CompilatorScript,代码行数:7,代码来源:DoubleTests.cs


示例7: LinkVariableAction

 public LinkVariableAction(VariableInfo variableInfo, Variable linkedVariable)
 {
     VariableInfo = variableInfo;
     OldLink = variableInfo.Variable.Linked;
     OldValue = variableInfo.Value;
     NewLink = linkedVariable;
 }
开发者ID:jbatonnet,项目名称:flowtomator,代码行数:7,代码来源:LinkVariable.cs


示例8: Add

 /// <summary>
 /// Добавляет переменную в окружение
 /// </summary>
 /// <param name="var">Переменная</param>
 /// <param name="name">Имя переменной</param>
 public void Add(Variable var, string name)
 {
     EnvironsStuct es = new EnvironsStuct();
     es.name = name;
     es.value = var;
     enviroment.Add(es);
 }
开发者ID:ushim,项目名称:PascalCompile,代码行数:12,代码来源:Environment.cs


示例9: VisitCall

        /// <summary>
        /// Visits the call.
        /// </summary>
        /// <param name="destination">The destination.</param>
        /// <param name="receiver">The receiver.</param>
        /// <param name="callee">The callee.</param>
        /// <param name="arguments">The arguments.</param>
        /// <param name="isVirtualCall">if set to <c>true</c> [is virtual call].</param>
        /// <param name="programContext">The program context.</param>
        /// <param name="stateBeforeInstruction">The state before instruction.</param>
        /// <param name="stateAfterInstruction">The state after instruction.</param>
        public override void VisitCall(
            Variable destination, 
            Variable receiver, 
            Method callee, 
            ExpressionList arguments, 
            bool isVirtualCall, 
            Microsoft.Fugue.IProgramContext programContext, 
            Microsoft.Fugue.IExecutionState stateBeforeInstruction, 
            Microsoft.Fugue.IExecutionState stateAfterInstruction)
        {
            if ((callee.DeclaringType.GetRuntimeType() == typeof(X509ServiceCertificateAuthentication) ||
                 callee.DeclaringType.GetRuntimeType() == typeof(X509ClientCertificateAuthentication)) &&
                 (callee.Name.Name.Equals("set_CertificateValidationMode", StringComparison.InvariantCultureIgnoreCase)))
            {
                IAbstractValue value = stateBeforeInstruction.Lookup((Variable)arguments[0]);
                IIntValue intValue = value.IntValue(stateBeforeInstruction);

                if (intValue != null)
                {
                    X509CertificateValidationMode mode = (X509CertificateValidationMode)intValue.Value;
                    if (mode != X509CertificateValidationMode.ChainTrust)
                    {
                        Resolution resolution = base.GetResolution(mode.ToString(), 
                            X509CertificateValidationMode.ChainTrust.ToString());
                        Problem problem = new Problem(resolution, programContext);
                        base.Problems.Add(problem);
                    }
                }
            }

            base.VisitCall(destination, receiver, callee, arguments, isVirtualCall, programContext, stateBeforeInstruction, stateAfterInstruction);
        }
开发者ID:Phidiax,项目名称:open-wssf-2015,代码行数:43,代码来源:CertificateValidationMode.cs


示例10: UpdateHelper

        private double UpdateHelper(Message<GaussianDistribution> message1, Message<GaussianDistribution> message2,
            Variable<GaussianDistribution> variable1, Variable<GaussianDistribution> variable2)
        {
            GaussianDistribution message1Value = message1.Value.Clone();
            GaussianDistribution message2Value = message2.Value.Clone();

            GaussianDistribution marginal1 = variable1.Value.Clone();
            GaussianDistribution marginal2 = variable2.Value.Clone();

            double a = _Precision/(_Precision + marginal2.Precision - message2Value.Precision);

            GaussianDistribution newMessage = GaussianDistribution.FromPrecisionMean(
                a*(marginal2.PrecisionMean - message2Value.PrecisionMean),
                a*(marginal2.Precision - message2Value.Precision));

            GaussianDistribution oldMarginalWithoutMessage = marginal1/message1Value;

            GaussianDistribution newMarginal = oldMarginalWithoutMessage*newMessage;

            /// Update the message and marginal

            message1.Value = newMessage;
            variable1.Value = newMarginal;

            /// Return the difference in the new marginal
            return newMarginal - marginal1;
        }
开发者ID:vmendi,项目名称:UnusualEngine,代码行数:27,代码来源:GaussianLikelihoodFactor.cs


示例11: TestAsArgument

        public void TestAsArgument()
        {
            IVariable<IFeatureLocation> a = new Variable<IFeatureLocation>("argument");
            IVariable<double> c1 = new Variable<double>("value");
            IVariable<string> c2 = new Variable<string>("description");

            // f = (a, p)(h)
            IFunction f = new Function("rating curve");
            f.Arguments.Add(a);
            f.Components.Add(c1);
            f.Components.Add(c2);

            SimpleFeature simpleFeature = new SimpleFeature(10.0);
            IFeatureLocation featureLocation = new FeatureLocation { Feature = simpleFeature };

            // value based argument referencing.
            f[featureLocation] = new object[] { 1.0, "jemig de pemig" };

            IMultiDimensionalArray<double> c1Value = f.GetValues<double>(new ComponentFilter(f.Components[0]),
                                                                         new VariableValueFilter<IFeatureLocation>(
                                                                             f.Arguments[0],
                                                                             new FeatureLocation
                                                                                 {Feature = simpleFeature}));

            Assert.AreEqual(1.0, c1Value[0], 1.0e-6);

            //IMultiDimensionalArray<string> c2Value = f.GetValues<string>(new ComponentFilter(f.Components[1]),
            //                                                             new VariableValueFilter<IFeatureLocation>(
            //                                                                 f.Arguments[0], featureLocation));

            //Assert.AreEqual("jemig de pemig", c2Value[0]);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:32,代码来源:FeatureLocationTest.cs


示例12: TryGetMember

 public override bool TryGetMember(GetMemberBinder binder, out object result)
 {
     try
     {
         Variable variable;
         if(!variables.TryGetValue(binder.Name, out variable))
         {
             int idx = GetGlobalVarIndexByName(binder.Name);
             var ptr = GetAddressOfGlobalVar(idx);
             if(ptr == IntPtr.Zero)
             {
                 result = null;
                 return true;
             }
             int tid;
             GetGlobalVar(idx, out tid);
             var instance = ScriptEngine.GetVariable(ptr, tid);
             variables[binder.Name] = variable = new Variable(instance, ptr, tid);
         }
         result = ScriptEngine.GetVariable(variable.Address, variable.TypeId, variable.Instance);
         return true;
     }
     catch(Exception ex)
     {
         ScriptEngine.Log ("Exception caught while fetching '{0}' variable of module '{1}': {2}.", binder.Name, Name, ex.Message);
         result = null;
         return false;
     }
 }
开发者ID:wladimiiir,项目名称:vault112,代码行数:29,代码来源:ScriptModule.cs


示例13: Window1

		public Window1()
		{
			InitializeComponent();

			//------------------------
			// The model
			//------------------------
			// c represents the position of the car
			c = Variable.DiscreteUniform(3).Named("Car");
			// p represents the pick. This will be observed
			p = Variable.DiscreteUniform(3).Named("Pick");
			// h represents the host pick.
			h = Variable.New<int>().Named("Host");
			// Whether the host is observed
			hostIsObserved = Variable.Observed<bool>(false);

			for (int a = 0; a < 3; a++) for (int b = 0; b < 3; b++)
				{
					double[] probs = { 1, 1, 1 };
					for (int ps = 0; ps < 3; ps++) if (ps == a || ps == b) probs[ps] = 0;
					using (Variable.Case(p, a)) using (Variable.Case(c, b)) h.SetTo(Variable.Discrete(probs));
				}
			using (Variable.If(hostIsObserved))
				Variable.ConstrainFalse(h == c);

			// Compile the model
			getProbs(h);

			OnReset();
		}
开发者ID:xornand,项目名称:Infer.Net,代码行数:30,代码来源:Window1.xaml.cs


示例14: ComputeAndConstrainScores

        /// <summary>
        /// Compute score for vectors, and constrain the score require to be the maximum 
        /// for the class inferred in model results
        /// </summary>
        protected void ComputeAndConstrainScores(Variable<Vector>[] variableVector)
        {
            using (Variable.ForEach(this.range))
            {
                var score = new Variable<double>[numOfClasses];
                var scorePlusNoise = new Variable<double>[numOfClasses];

                for (int i = 0; i < numOfClasses; i++)
                {
                    score[i] = Variable.InnerProduct(variableVector[i], this.featureVectors[this.range]);
                    scorePlusNoise[i] = Variable.GaussianFromMeanAndPrecision(score[i], Noise);
                }

                this.modelOutput[this.range] = Variable.DiscreteUniform(numOfClasses);

                for (int j = 0; j < numOfClasses; j++)
                {
                    using (Variable.Case(this.modelOutput[this.range], j))
                    {
                        for (int k = 0; k < scorePlusNoise.Length; k++)
                        {
                            if (k != j)
                            {
                                Variable.ConstrainPositive(scorePlusNoise[j] - scorePlusNoise[k]);
                            }
                        }
                    }
                }
            }
        }
开发者ID:yoroto,项目名称:BayesPointMachines,代码行数:34,代码来源:VectorsTestModel.cs


示例15: HandleFailure

 private void HandleFailure(Variable failure)
 {
     var defaultPair = DefaultPrivacyProvider.DefaultPair;
     var time = Group.EngineTimeData;
     Response = new ReportMessage(
         Request.Version,
         new Header(
             new Integer32(Request.MessageId()),
             new Integer32(Messenger.MaxMessageSize),
             0), // no need to encrypt.
         new SecurityParameters(
             Group.EngineId,
             new Integer32(time[0]),
             new Integer32(time[1]),
             Request.Parameters.UserName,
             defaultPair.AuthenticationProvider.CleanDigest,
             defaultPair.Salt),
         new Scope(
             Group.EngineId,
             OctetString.Empty,
             new ReportPdu(
                 Request.RequestId(),
                 ErrorCode.NoError,
                 0,
                 new List<Variable>(1) { failure })),
         defaultPair,
         null);
     if (TooBig)
     {
         GenerateTooBig();
     }
 }
开发者ID:bleissem,项目名称:sharpsnmplib,代码行数:32,代码来源:SecureSnmpContext.cs


示例16: ConvertOneArgumentOfTwoDimensionalFunction

        public void ConvertOneArgumentOfTwoDimensionalFunction()
        {
            IFunction func = new Function();
            IVariable<int> x = new Variable<int>("x");
            IVariable<DateTime> t = new Variable<DateTime>("t");
            var fx = new Variable<int>();
            func.Arguments.Add(x);
            func.Arguments.Add(t);
            func.Components.Add(fx);
            DateTime t0 = DateTime.Now;
            func[10,t0] = 4;

            IFunction convertedFunction = new ConvertedFunction<string, int>(func, x, Convert.ToInt32, Convert.ToString);
            //notice both argument and component are converted
            Assert.IsTrue(convertedFunction.Arguments[0] is IVariable<string>);
            Assert.IsTrue(convertedFunction.Components[0] is IVariable<int>);
            //notice the argument has been converted to a string variable
            Assert.AreEqual(4, convertedFunction["10",t0]);
            Assert.AreEqual(4, convertedFunction.Components[0].Values[0,0]);
            //arguments of components are converted as well :)
            Assert.AreEqual(4, convertedFunction.Components[0]["10",t0]);
            convertedFunction["30",t0] = 10;
            IMultiDimensionalArray<string> strings = (IMultiDimensionalArray<string>)convertedFunction.Arguments[0].Values;
            Assert.IsTrue(new[] { "10", "30" }.SequenceEqual(strings));
            
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:26,代码来源:ConvertedFunctionsTest.cs


示例17: SetDateTime

 public void SetDateTime()
 {
     IVariable<DateTime> var = new Variable<DateTime>();
     DateTime to = DateTime.Now;
     var.Values.Add(to);
     Assert.IsTrue(var.Values.Contains(to));
 }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:7,代码来源:VariableTest.cs


示例18: GetArgumentDependentVariables

        public void GetArgumentDependentVariables()
        {
            IFunction f = new Function();
            IVariable c1 = new Variable<int>("c1");
            IVariable c2 = new Variable<int>("c2");
            IVariable x = new Variable<int>("x");
            
            f.Components.Add(c1);
            f.Components.Add(c2);

            IDictionary<IVariable, IEnumerable<IVariable>> dependentVariables = MemoryFunctionStoreHelper.GetDependentVariables(f.Store.Functions);
            
            //no argument dependencies yet
            Assert.AreEqual(2, dependentVariables.Count);
            Assert.AreEqual(new IVariable[0],dependentVariables[c1].ToArray());
            Assert.AreEqual(new IVariable[0], dependentVariables[c2].ToArray());
            
            f.Arguments.Add(x);
            
            dependentVariables = MemoryFunctionStoreHelper.GetDependentVariables(f.Store.Functions);

            Assert.AreEqual(3, dependentVariables.Count);
            Assert.AreEqual(2, dependentVariables[x].Count());
            Assert.AreEqual(new[]{c1,c2},dependentVariables[x]);
            //Assert.IsTrue(dependentVariables[x].Contains(c1));
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:26,代码来源:MemoryFunctionStoreHelperTest.cs


示例19: SeriesChangesWhenFunctionBindingListChanges

        public void SeriesChangesWhenFunctionBindingListChanges()
        {
            IFunction function = new Function();
            IVariable yVariable = new Variable<double>("y");
            IVariable xVariable = new Variable<double>("x");
            function.Arguments.Add(xVariable);
            function.Components.Add(yVariable);
            
            function[1.0] = 2.0;
            function[2.0] = 5.0;
            function[3.0] = 1.0;

            ILineChartSeries ls = ChartSeriesFactory.CreateLineSeries();
            ls.YValuesDataMember = function.Components[0].DisplayName;
            ls.XValuesDataMember = function.Arguments[0].DisplayName;

            var synchronizeObject = new Control();
            synchronizeObject.Show();

            var functionBindingList = new FunctionBindingList(function) { SynchronizeInvoke = synchronizeObject };
            ls.DataSource = functionBindingList;
            
            //a change in the function should change the series
            function[1.0] = 20.0;

            while(functionBindingList.IsProcessing)
            {
                Application.DoEvents();
            }
            
            Assert.AreEqual(20, ls.YValues[0]);
            
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:33,代码来源:SeriesTest.cs


示例20: ArrayAssignment

 public ArrayAssignment(int lineNumber, Variable array, Variable index, Variable value)
     : base(lineNumber)
 {
     this.array = array;
     this.index = index;
     this.value = value;
 }
开发者ID:dbremner,项目名称:dotnet-testability-explorer,代码行数:7,代码来源:ArrayAssignment.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# VariableDeclaration类代码示例发布时间:2022-05-24
下一篇:
C# VarVec类代码示例发布时间: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