本文整理汇总了C#中Variable.GetValues方法的典型用法代码示例。如果您正苦于以下问题:C# Variable.GetValues方法的具体用法?C# Variable.GetValues怎么用?C# Variable.GetValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Variable
的用法示例。
在下文中一共展示了Variable.GetValues方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFilteredValuesFrom2DFunction
public void GetFilteredValuesFrom2DFunction()
{
var x = new Variable<int>();
var y = new Variable<int>();
var z = new Variable<double> { Arguments = { x, y } };
z[0, 0] = 1.0;
z[0, 1] = 2.0;
z[1, 0] = 3.0;
z[1, 1] = 4.0;
var xFilter = new VariableValueFilter<int>(x, 0);
var yFilter = new VariableValueFilter<int>(y, 1);
var values = z.GetValues(xFilter, yFilter);
values.Count
.Should("query values using 2 filters").Be.EqualTo(1);
values[0]
.Should("query values using 2 filters").Be.EqualTo(2.0);
}
示例2: Implicit1DAccess
public void Implicit1DAccess()
{
//m = F(x,t)
IVariable<int> measurement = new Variable<int>();
IVariable<int> time = new Variable<int>();
IVariable<int> space = new Variable<int>();
time.SetValues(new[] {1, 2, 3});
space.SetValues(new[] {10, 20, 30});
measurement.Arguments.Add(time);
measurement.Arguments.Add(space);
Assert.AreEqual(9, measurement.GetValues().Count);
measurement[2, 10] = 200;
//select one location and expect a singe dimensional array
IMultiDimensionalArray<int> values = measurement.GetValues(new VariableValueFilter<int>(space, 10));
Assert.AreEqual(3, values.Count);
//do you really want this?
Assert.AreEqual(200, values[1]);
}
示例3: GetValuesGeneric
public void GetValuesGeneric()
{
IVariable<double> x = new Variable<double>("x");
IVariable<double> y = new Variable<double>("y");
IVariable<double> fx = new Variable<double>("fx");
IVariable<double> fy = new Variable<double>("fy");
IFunction f = new Function();
f.Arguments.Add(x);
f.Arguments.Add(y);
f.Components.Add(fx);
f.Components.Add(fy);
// set (fx, fy) values to (100.0, 200.0) for a combination of x and y values.
f.SetValues(
new[] {100.0, 200.0},
new VariableValueFilter<double>(x, new[] {1.0, 2.0}),
new VariableValueFilter<double>(y, new[] { 10.0, 20.0 }));
IMultiDimensionalArray<double> values = fx.GetValues();
int expectedValuesCount = 4;
Assert.AreEqual(expectedValuesCount, values.Count);
Assert.AreEqual(expectedValuesCount, x.Values.Count*y.Values.Count);
double expectedFxValue = 100.0;
double expectedFyValue = 200.0;
Assert.AreEqual(expectedFxValue, fx.Values[0, 0]);
Assert.AreEqual(expectedFyValue, fy.Values[0, 0]);
}
示例4: GetValues
public void GetValues()
{
IVariable x = new Variable<double>("x");
IVariable y = new Variable<double>("y");
IVariable fx = new Variable<double>("fx");
IVariable fy = new Variable<double>("fy");
IFunction f = new Function();
f.Arguments.Add(x);
f.Arguments.Add(y);
f.Components.Add(fx);
f.Components.Add(fy);
Assert.AreEqual(2,fy.Values.Rank);
// set values of the x, y arguments, fx, fy components will be set to their default values.
x.SetValues(new[] {1.0, 2.0});
y.SetValues(new[] {10.0, 20.0});
// get values, all values equal DefaultValue
IMultiDimensionalArray values = fx.GetValues();
Assert.AreEqual(4, values.Count, "number of values after argument values are set");
Assert.AreEqual(fx.DefaultValue, values[0, 0], "default value");
// set value using indexes.
int i = 1;
int j = 1;
fx.Values[i, j] = 111.0;
fy.Values[i, j] = 222.0;
// ... and it is also the same as (accessing component variables directly):
f.Components[0].Values[i, j] = 111.0;
f.Components[1].Values[i, j] = 222.0;
// ... you can also assign *all* values in the following way
var array2d = new[,] {{fx.DefaultValue, fx.DefaultValue}, {111.0, 111.0}};
fx.SetValues(array2d);
array2d = new[,] {{fy.DefaultValue, fy.DefaultValue}, {222.0, 222.0}};
fy.SetValues(array2d);
fx[2.0, 10.0] = 111.0;
fy[2.0, 20.0] = 222.0;
// we can also get a single value in this way
Assert.AreEqual(111.0, (double) fx[2.0, 10.0]);
Assert.AreEqual(222.0, (double) fy[2.0, 20.0]);
// a single value can not be asked using indexes of the arguments.
// now you have to find the values via the arguments
var value = (double) fx.Values[i, j];
Assert.AreEqual(111.0, value);
}
示例5: SetValuesUsingJaggerdArrayAndCheckToStringResults
public void SetValuesUsingJaggerdArrayAndCheckToStringResults()
{
var values = new[,]
{
{1, 2, 3},
{4, 5, 6}
};
var x = new Variable<int>("x");
var y = new Variable<int>("y");
var f = new Variable<int>("f");
// TODO: arguments are added in a different way compare to array, refactor!
f.Arguments.Add(y);
f.Arguments.Add(x);
x.SetValues(new[] {0, 1, 2});
y.SetValues(new[] {0, 1});
f.SetValues(values);
f.GetValues().ToString().Should().Be.EqualTo("{{1, 2, 3}, {4, 5, 6}}");
}
示例6: DeleteTimeStepTest
public void DeleteTimeStepTest()
{
//waterLevel = f(cell,time)
IFeatureCoverage waterLevelCoverage = new FeatureCoverage("WaterLevelCoverage");
IVariable<int> timeVariable = new Variable<int>("timestep");
IVariable<SimpleFeature> boundariesVariable = new Variable<SimpleFeature>("cell");
IVariable<float> waterLevelVariable = new Variable<float>("Level");
waterLevelCoverage.Arguments.Add(timeVariable);
waterLevelCoverage.Arguments.Add(boundariesVariable);
waterLevelCoverage.Components.Add(waterLevelVariable);
waterLevelCoverage.Features = (IList)boundaries;
for (int i = 0; i < 12; i++)
{
waterLevelCoverage.SetValues(new[] { (i * 10) + 1.0f, (i * 10) + 2.0f, (i * 10) + 3.0f,
(i * 10) + 4.0f, (i * 10) + 5.0f, (i * 10) + 6.0f } ,
new VariableValueFilter<int>(timeVariable, i));
}
// content should be now:
// t=0 : 1.0 2.0 3.0 4.0 5.0 6.0
// t=1 : 11.0 12.0 13.0 14.0 15.0 16.0
// ..
// ..
// t=11 :111.0 112.0 113.0 114.0 115.0 116.0
IList<float> values = waterLevelVariable.GetValues();
Assert.AreEqual(6 * 12, values.Count);
Assert.AreEqual(14.0, values[9]);
Assert.AreEqual(114.0, values[69]);
values = waterLevelVariable.GetValues(new VariableValueFilter<int>(timeVariable, 5));
Assert.AreEqual(6, values.Count);
Assert.AreEqual(51, values[0]);
Assert.AreEqual(56, values[5]);
// Remove values at t=2
timeVariable.Values.Remove(2);
values = waterLevelVariable.GetValues();
Assert.AreEqual(6 * 11, values.Count);
timeVariable.Values.Remove(3);
timeVariable.Values.Remove(4);
IList argumentValues = waterLevelCoverage.Arguments[0].Values;
Assert.AreEqual(9, argumentValues.Count);
Assert.AreEqual(11, argumentValues[8]);
timeVariable.Values.Remove(5);
timeVariable.Values.Remove(6);
timeVariable.Values.Remove(7);
argumentValues = waterLevelCoverage.Arguments[0].Values;
Assert.AreEqual(6, argumentValues.Count);
Assert.AreEqual(11, argumentValues[5]);
waterLevelCoverage.RemoveValues(new VariableValueFilter<int>(timeVariable, new [] { 0, 1, 8, 9, 10, 11 }));
values = waterLevelVariable.GetValues();
Assert.AreEqual(0, values.Count);
argumentValues = waterLevelCoverage.Arguments[0].Values;
Assert.AreEqual(0, argumentValues.Count);
}