本文整理汇总了C#中System.Function.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# Function.Clear方法的具体用法?C# Function.Clear怎么用?C# Function.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Function
的用法示例。
在下文中一共展示了Function.Clear方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClearFunctionThatIsBoundToDecorator
public void ClearFunctionThatIsBoundToDecorator()
{
IFunction function = new Function("time series");
function.Arguments.Add(new Variable<DateTime>("time"));
function.Components.Add(new Variable<double>("water_discharge"));
// set initial values
DateTime time1 = DateTime.Now;
DateTime time2 = time1.AddMinutes(1);
DateTime time3 = time2.AddMinutes(1);
function[time1] = 0.0;
function[time2] = 1.0;
function[time3] = 2.0;
ILineChartSeries lineChartSeries = ChartSeriesFactory.CreateLineSeries();
lineChartSeries.XValuesDataMember = function.Arguments[0].DisplayName;
lineChartSeries.YValuesDataMember = function.Components[0].DisplayName;
var control = new Control();
WindowsFormsTestHelper.Show(control);
var functionBindingList = new FunctionBindingList(function) { SynchronizeInvoke = control };
lineChartSeries.DataSource = functionBindingList;
function.Clear();
while(functionBindingList.IsProcessing)
{
Application.DoEvents();
}
}
示例2: UpdateGridValues
/// <summary>
/// Fills gridvalues function with profiledata based on profileline over the grid
/// </summary>
/// <param name="function"></param>
/// <param name="grid"></param>
/// <param name="polyline"></param>
public static void UpdateGridValues(Function function, IRegularGridCoverage grid, ILineString polyline)
{
function.Clear();
double offset = 0;
double step = polyline.Length / 100;
foreach (ICoordinate coordinate in GetGridProfileCoordinates(polyline, step))
{
function[offset] = grid.Evaluate(coordinate);
offset += step;
}
}
示例3: CheckFunctionValuesChangedConsistency
public void CheckFunctionValuesChangedConsistency()
{
//assert we only get a FunctionValuesChanged event when the function is consistent.
IFunction func = new Function();
IVariable x = new Variable<int>("x");
IVariable y = new Variable<int>("y");
func.Arguments.Add(x);
func.Components.Add(y);
func[0] = 2;
func.Store.FunctionValuesChanged += delegate
{
Assert.IsTrue(func.Components[0].Values.Count == func.Arguments[0].Values.Count);
};
func.Clear();
}
示例4: Clear
public void Clear()
{
IVariable<double> x = new Variable<double>("x");
IVariable<double> y = new Variable<double>("y");
IFunction f = new Function();
f.Arguments.Add(x);
f.Components.Add(y);
f.SetValues(new[] {100.0, 200.0, 300.0}, new VariableValueFilter<double>(x, new[] {1.0, 2.0, 3.0}));
IList values = f.GetValues();
Assert.AreEqual(3, values.Count);
f.Clear();
Assert.AreEqual(0, values.Count);
}
示例5: AddManyFunctionValuesWithBindingListShouldBeFast
public void AddManyFunctionValuesWithBindingListShouldBeFast()
{
var f = new Function
{
Arguments = {new Variable<double>("x")},
Components = {new Variable<double>("y")}
};
var values = Enumerable.Range(0, 1000).Select(i => (double)i);
// first time is slower so we add/clear values a few times first
f.SetValues(values, new VariableValueFilter<double>(f.Arguments[0], values));
f.Clear();
f.SetValues(values, new VariableValueFilter<double>(f.Arguments[0], values));
f.Clear();
// measure overhead (add values to function)
var stopwatch = new Stopwatch();
stopwatch.Start();
AddValuesWithoutBindingList(f, values);
stopwatch.Stop();
var overhead = stopwatch.ElapsedMilliseconds;
log.DebugFormat("Added 1000 values to function in {0} ms", overhead);
f.Clear();
// add values with FunctionBindingList
new FunctionBindingList(f);
stopwatch.Reset();
stopwatch.Start();
AddValuesWithBindingList(f, values);
stopwatch.Stop();
log.DebugFormat("Added 1000 values to function wrapped with a binding list in {0} ms, {1}x slower", stopwatch.ElapsedMilliseconds, (stopwatch.ElapsedMilliseconds / (double)overhead));
(stopwatch.ElapsedMilliseconds - overhead)
.Should("Updating binding list should be fast").Be.LessThan(50);
(stopwatch.ElapsedMilliseconds / (double)overhead)
.Should("Setting values to function with function binding list should be almost as fast as without it")
.Be.LessThan(4);
}
示例6: ClearSourceFunctionShouldClearFilteredBindingList
public void ClearSourceFunctionShouldClearFilteredBindingList()
{
IFunction function = new Function
{
Arguments = { new Variable<int>("x")},
Components = { new Variable<int>("f") }
};
function[1] = 1;
function[2] = 4;
var filteredFunction = function.Filter(new VariableValueFilter<int>(function.Arguments[0], new[] { 1 }));
IFunctionBindingList functionBindingList = new FunctionBindingList { Function = filteredFunction };
functionBindingList.Count
.Should().Be.EqualTo(1);
function.Clear();
functionBindingList.Count
.Should().Be.EqualTo(0);
}
示例7: ClearSourceFunctionShouldClearBindingList
public void ClearSourceFunctionShouldClearBindingList()
{
IFunction function = new Function
{
Arguments = { new Variable<int>("x") },
Components = { new Variable<int>("f") }
};
function[1] = 1;
function[2] = 4;
var functionBindingList = new FunctionBindingList {Function = function};
functionBindingList.Count
.Should().Be.EqualTo(2);
function.Clear();
// wait until binding list is actually cleared.
WaitUntilLastOperationIsFinished(functionBindingList);
functionBindingList.Count
.Should().Be.EqualTo(0);
}
示例8: ClearFunction_ShouldNotClearAttributes
public void ClearFunction_ShouldNotClearAttributes()
{
// setup
IVariable<double> x = new Variable<double>("x");
IVariable<double> y = new Variable<double>("y");
IFunction f = new Function();
f.Arguments.Add(x);
f.Components.Add(y);
string kie = "kie";
string expected = "veljoe";
f.Attributes[kie] = expected;
f.Components[0].Attributes[kie] = expected;
f.SetValues(new[] { 100.0, 200.0, 300.0 }, new VariableValueFilter<double>(x, new[] { 1.0, 2.0, 3.0 }));
// call
f.Clear();
// check
Assert.AreEqual(0, f.GetValues().Count);
var funcVal = f.Attributes[kie];
Assert.AreEqual(expected,funcVal);
var val = f.Components[0].Attributes[kie];
Assert.AreEqual(expected,val);
}
示例9: UpdateProfileFunctionValues
/// <summary>
/// Fills gridvalues function with profiledata based on profileline over the grid
/// </summary>
/// <param name="function"></param>
/// <param name="coverage"></param>
/// <param name="polyline"></param>
/// <param name="resolution">Defines the sample resolution along <paramref name="polyline"/> (each resolution step a sample).
/// Null will cause 101 samples to be take along the line uniformly.</param>
/// <exception cref="ArgumentException">When <paramref name="resolution"/> is 0.0 or less.</exception>
public static void UpdateProfileFunctionValues(Function function, ICoverage coverage, ILineString polyline, DateTime? time, double? resolution = null)
{
// when coverage is empty (has no times), we cannot call Evaluate below...
if (time != null && time.Equals(default(DateTime))) return;
function.Clear();
double offset = 0;
double step = resolution ?? polyline.Length / 100;
var gridProfileCoordinates = GetGridProfileCoordinates(polyline, step).ToArray();
foreach (ICoordinate coordinate in gridProfileCoordinates)
{
var value = time != null ? coverage.Evaluate(coordinate, time.Value) : coverage.Evaluate(coordinate);
if (value == null)
{
offset += step;
continue;
}
function[offset] = value;
offset += step;
}
}