本文整理汇总了C#中System.Function.Aggregate方法的典型用法代码示例。如果您正苦于以下问题:C# Function.Aggregate方法的具体用法?C# Function.Aggregate怎么用?C# Function.Aggregate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Function
的用法示例。
在下文中一共展示了Function.Aggregate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Aggregate
public void Aggregate()
{
var f = new Function("f");
var x = new Variable<float>("x");
var y = new Variable<float>("y");
var z = new Variable<float>("z");
var t = new Variable<DateTime>("t");
f.Arguments.Add(x);
f.Arguments.Add(y);
f.Arguments.Add(t);
f.Components.Add(z);
var t1 = new DateTime(2009, 1, 1);
f[0.0f, 0.0f, t1] = 0.0;
f[0.0f, 1.0f, t1] = 1.0;
f[0.0f, 2.0f, t1] = 2.0;
f[1.0f, 0.0f, t1] = 3.0;
f[1.0f, 1.0f, t1] = 4.0;
f[1.0f, 2.0f, t1] = 5.0;
var t2 = new DateTime(2009, 1, 2);
f[0.0f, 0.0f, t2] = 0.0;
f[0.0f, 1.0f, t2] = 1.0;
f[0.0f, 2.0f, t2] = 2.0;
f[1.0f, 0.0f, t2] = 3.0;
f[1.0f, 1.0f, t2] = 4.0;
f[1.0f, 2.0f, t2] = 5.0;
Func<double, double, double> aggregationFunc = (seed, value) => value > 4.0 ? seed + 1 : seed;
// TODO: implement function aggregation in generic way, NOT IMPLEMENTED YET
var fAggregated = f.Aggregate(t, 0.0,aggregationFunc);
Assert.AreEqual(2, fAggregated.Arguments.Count);
Assert.AreEqual(2, fAggregated.Components[0].Values[1, 2]);
Assert.AreEqual(0, fAggregated.Components[0].Values[0, 0]);
}