本文整理汇总了C#中Variable.SetValues方法的典型用法代码示例。如果您正苦于以下问题:C# Variable.SetValues方法的具体用法?C# Variable.SetValues怎么用?C# Variable.SetValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Variable
的用法示例。
在下文中一共展示了Variable.SetValues方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FilterIndependend
public void FilterIndependend()
{
IVariable<int> x = new Variable<int>();
x.SetValues(new[]{1,2,3,4,5,6,7,8,9,10});
//select two ranges ..from [1..3] and [7..9]
IList<Pair<int, int>> indexRanges= new List<Pair<int, int>>();
indexRanges.Add(new Pair<int, int>(0,2));
indexRanges.Add(new Pair<int, int>(6,8));
IVariable<int> filteredX = (IVariable<int>) x.Filter(new VariableIndexRangesFilter(x, indexRanges));
Assert.AreEqual(6, filteredX.Values.Count);
Assert.IsTrue(new[]{1,2,3,7,8,9}.SequenceEqual(filteredX.Values));
}
示例2: VariableValueRanges
public void VariableValueRanges()
{
IVariable<int> x = new Variable<int>();
x.SetValues(new[]{1,2,3,4,5,6,7,8,9,10});
//select two ranges ..from [1..3] and [7.8]
IList<Pair<int,int>> ranges = new List<Pair<int, int>>();
ranges.Add(new Pair<int, int>(1,3));
ranges.Add(new Pair<int, int>(7,8));
x = (IVariable<int>)x.Filter(new VariableValueRangesFilter<int>(x,ranges));
Assert.AreEqual(5, x.Values.Count);
Assert.AreEqual(new[] { 1, 2, 3, 7, 8}, x.Values.ToArray());
}
示例3: EmptyFilter
public void EmptyFilter()
{
IVariable<double> y = new Variable<double>("y");
IVariable<double> x = new Variable<double>("x");
y.Arguments.Add(x);
x.SetValues(new[] { 1.0, 2.0, 3.0 });
y.SetValues(new[] { 10.0, 20.0, 30.0 });
var filtered = y.Filter();
Assert.AreEqual(3, filtered.Arguments[0].Values.Count);
}
示例4: FilterDependendVariable
public void FilterDependendVariable()
{
//int sa = componentArrays.Aggregate(1, (product, item) => (product *= item.Count));
IVariable<double> y = new Variable<double>("y");
IVariable<double> x = new Variable<double>("x");
y.Arguments.Add(x);
x.SetValues(new[] { 1.0, 2.0, 3.0 });
y.SetValues(new[] { 10.0, 20.0, 30.0 });
var filtered = y.Filter(x.CreateValueFilter(2.0));
Assert.AreEqual(1, filtered.Components[0].Values.Count);
Assert.AreEqual(20, filtered.Values[0]);
}
示例5: ReduceFitlterShouldPassIsEditableProperty
public void ReduceFitlterShouldPassIsEditableProperty()
{
IVariable<int> x = new Variable<int>("x"){IsEditable = false};
IVariable<int> y = new Variable<int>("y");
IVariable<int> fx = new Variable<int>("fx");
fx.Arguments.Add(x);
fx.Arguments.Add(y);
x.SetValues(new[] { 1, 2, 3 });
y.SetValues(new[] { 1 });
fx[3, 1] = 20;
var reducedFunction = fx.Filter(new VariableReduceFilter(y));
Assert.AreEqual(1, reducedFunction.Arguments.Count);
Assert.AreEqual("x", reducedFunction.Arguments[0].Name);
Assert.IsFalse(reducedFunction.Arguments[0].IsEditable);
}
示例6: SimpleReduce
public void SimpleReduce()
{
IVariable<int> x = new Variable<int>("x");
IVariable<int> y = new Variable<int>("y");
IVariable<int> fx = new Variable<int>("fx");
fx.Arguments.Add(x);
fx.Arguments.Add(y);
x.SetValues(new[] {1, 2, 3});
y.SetValues(new[] {1});
fx[3, 1] = 20;
var reducedFunction = fx.Filter(new VariableValueFilter<int>(y, 1), new VariableReduceFilter(y));
Assert.AreEqual(1, reducedFunction.Arguments.Count);
Assert.AreEqual(3, reducedFunction.Values.Count);
Assert.AreEqual(20, reducedFunction.Values[2]);
}
示例7: FilterDependend
public void FilterDependend()
{
IVariable<int> y = new Variable<int>();
IVariable<int> x = new Variable<int>();
y.Arguments.Add(x);
x.SetValues(new[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
y[2] = 10;
y[8] = 10;
//select two ranges ..from [1..3] and [7..9]
IList<Pair<int, int>> indexRanges = new List<Pair<int, int>>();
indexRanges.Add(new Pair<int, int>(0, 2));
indexRanges.Add(new Pair<int, int>(6, 8));
IVariable<int> filteredY = (IVariable<int>) y.Filter(new VariableIndexRangesFilter(x, indexRanges));
Assert.AreEqual(6, filteredY.Values.Count);
Assert.IsTrue(new[] {0, 10, 0, 0, 10, 0}.SequenceEqual(filteredY.Values));
}
示例8: CreateFunction
public void CreateFunction()
{
var index1Variable = new Variable<int>("index1") { Values = {0, 1, 2} };
var index2Variable = new Variable<int>("index2") { Values = {0, 1} };
var xVariable = new Variable<double>("x") { Arguments = { index1Variable, index2Variable } };
var yVariable = new Variable<double>("y") { Arguments = { index1Variable, index2Variable } };
var valuesVariable = new Variable<double>("value") { Arguments = { index1Variable, index2Variable } };
xVariable.SetValues(new[,]
{
{1.0, 2.0, 3.0},
{4.0, 5.0, 6.0}
});
yVariable.SetValues(new[,]
{
{1.0, 2.0, 3.0},
{4.0, 5.0, 6.0}
});
valuesVariable.SetValues(new[,]
{
{1.0, 2.0, 3.0},
{4.0, 5.0, 6.0}
});
var variables = new IVariable[] { index1Variable, index2Variable, xVariable, yVariable, valuesVariable };
var builder = new DiscreteGridPointCoverageBuilder
{
Index1VariableName = "index1",
Index2VariableName = "index2",
XVariableName = "x",
YVariableName = "y",
ValuesVariableName = "value"
};
var coverage = (IDiscreteGridPointCoverage)builder.CreateFunction((variables));
Assert.AreEqual(3, coverage.Index1.Values.Count);
Assert.AreEqual(2, coverage.Index2.Values.Count);
Assert.AreEqual(6, coverage.X.Values.Count);
Assert.AreEqual(6, coverage.Y.Values.Count);
Assert.AreEqual(5.0, coverage.Evaluate<double>(5.0, 5.0));
}
示例9: FilterFunction
public void FilterFunction()
{
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);
x.SetValues(new[] { 1.0, 2.0, 3.0 });
y.SetValues(new[] { 10.0, 20.0 });
f.Components[0].Values[1, 1] = 100.0;
f.Components[1].Values[1, 1] = 200.0;
// fx 10.0 20.0
// ------------
// 1.0 | 0.0 0.0
// 2.0 | 0.0 100.0
// 3.0 | 0.0 0.0
//
// fy 10.0 20.0
// ------------
// 1.0 | 0.0 0.0
// 2.0 | 0.0 200.0
// 3.0 | 0.0 0.0
var filteredFunction = f.Filter(x.CreateValueFilter(2.0), y.CreateValueFilter(20.0));
Assert.AreEqual(2, filteredFunction.Components.Count);
Assert.AreEqual(2, filteredFunction.Arguments.Count);
Assert.AreEqual(1, filteredFunction.Arguments[0].Values.Count);
Assert.AreEqual(1, filteredFunction.Arguments[1].Values.Count);
Assert.AreEqual(1, filteredFunction.Components[0].Values.Count);
Assert.AreEqual(1, filteredFunction.Components[1].Values.Count);
Assert.AreEqual(100.0, filteredFunction.Components[0].Values[0]);
Assert.AreEqual(200.0, filteredFunction.Components[1].Values[0]);
}
示例10: VelocityFieldFunction
public void VelocityFieldFunction()
{
var x = new Variable<double> { Name = "x", Values = { 1, 2 } };
var y = new Variable<double> { Name = "y", Values = { 1, 2, 3 } };
var vx = new Variable<double> { Name = "vx" };
var vy = new Variable<double> { Name = "vy" };
var velocity = new Function { Components = { vx, vy }, Arguments = { x, y } };
vx.SetValues(new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 });
vy.SetValues(new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 });
velocity.Components[0].Should().Be.EqualTo(vx);
velocity.Components[1].Should().Be.EqualTo(vy);
velocity.Arguments[0].Should().Be.EqualTo(x);
velocity.Arguments[1].Should().Be.EqualTo(y);
vx.Values.Should().Have.SameSequenceAs(new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 });
vy.Values.Should().Have.SameSequenceAs(new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 });
}
示例11: WriteTwoDimensionalFunctionUsingIndexFilters
public void WriteTwoDimensionalFunctionUsingIndexFilters()
{
//writing index based now only works for adding slices..
var flow = new Variable<int>();
var x = new Variable<int>();
var y = new Variable<int>();
flow.Arguments.Add(x);
flow.Arguments.Add(y);
x.AddValues(new[] {1, 2, 3});
y.AddValues(new[] {10, 20, 30});
//we now have 3x3 array for flow..write the last 'slice'
var xIndex = new VariableIndexRangeFilter(x, 2);
var yIndex = new VariableIndexRangeFilter(y, 0, 2);
flow.SetValues(new[] {1, 2, 3}, new[] {xIndex, yIndex});
Assert.AreEqual(9, flow.Values.Count);
Assert.AreEqual(3, flow.Values[8]);
}
示例12: FilterFilteredFunction
public void FilterFilteredFunction()
{
IVariable<int> x = new Variable<int>();
x.SetValues(new[] { 1, 2, 3, 4, 5 });
var filtered = x.Filter(x.CreateValuesFilter(new[] { 2, 3, 4 }));
var filtered2 = filtered.Filter(x.CreateValueFilter(3));
Assert.AreEqual(3, filtered.Values.Count);
Assert.IsTrue(filtered.Values.Cast<int>().SequenceEqual(new[] { 2, 3, 4 }));
Assert.AreEqual(1, filtered2.Values.Count);
Assert.AreEqual(3, filtered2.Values[0]);
// change filters
((IVariableValueFilter)filtered2.Filters[0]).Values.Add(5);
((IVariableValueFilter)filtered2.Filters[0]).Values.Add(4);
Assert.AreEqual(2, filtered2.Values.Count);
// expanding filter in the "filtered" will also expand "filtered2"
((IVariableValueFilter)filtered.Filters[0]).Values.Add(5);
Assert.AreEqual(4, filtered.Values.Count);
Assert.AreEqual(3, filtered2.Values.Count);
}
示例13: AddFilter
public void AddFilter()
{
IVariable<int> x = new Variable<int>();
x.SetValues(new[] { 1, 2, 3, 4, 5 });
x.Filters.Add(x.CreateValuesFilter(new[] { 2, 3, 4 }));
Assert.IsTrue(x.Values.SequenceEqual(new[] { 2, 3, 4 }));
}
示例14: Set10kFunctionValues2D_SetFirstDimensionAsLast
public void Set10kFunctionValues2D_SetFirstDimensionAsLast()
{
var f = new Function();
IVariable<double> component = new Variable<double>();
IVariable<double> x = new Variable<double>();
IVariable<double> y = new Variable<double>();
f.Components.Add(component);
f.Arguments.Add(x);
f.Arguments.Add(y);
const int valuesToAddCount = 100;
var doubles = new List<double>();
for (var i = 0; i < valuesToAddCount; i++)
{
doubles.Add(i);
}
var t = DateTime.Now; // measure time
y.SetValues(doubles);
x.SetValues(doubles); // sets 10000 values for function
var dt = DateTime.Now.Subtract(t).TotalMilliseconds;
log.DebugFormat("Added {0} values in {1} ms", valuesToAddCount * valuesToAddCount, dt);
Assert.Less(dt, 150);
}
示例15: GetUniformInterpolatedValue
public void GetUniformInterpolatedValue()
{
IVariable<double> x = new Variable<double>("x");
IVariable<double> y = new Variable<double>("y");
IVariable<double> f1 = new Variable<double>("f1");
f1.Arguments.Add(x);
f1.Arguments.Add(y);
var xValues = new[] { 1.0, 2.0 };
var yValues = new[] { 1.0, 2.0 };
var fValues = new[,]
{
{100.0, 100.0},
{100.0, 100.0}
};
f1.SetValues(fValues,
new VariableValueFilter<double>(x, xValues),
new VariableValueFilter<double>(y, yValues));
var value = f1.Evaluate<double>(
new VariableValueFilter<double>(x, 1.5),
new VariableValueFilter<double>(y, 1.5));
Assert.AreEqual(100,value);
}