本文整理匯總了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]);
}