public static GenerateByIndex ( Func, generator ) : IEnumerable |
||
generator | Func, | |
Результат | IEnumerable |
public IEnumerable <NeuralNetwork> BuildNetworks() { while (true) { var graph = new AdjacencyGraph <INeuron, Connection>(); var inputs = MoreEnumerable.GenerateByIndex(_ => new NeuronWithInput()).Take(_inputSize).ToArray(); var mid = MoreEnumerable.GenerateByIndex(_ => new BasicNeuron(new ThFunction())) .Take(_random.Next(_outputSize, _inputSize)) .ToArray(); var outputs = MoreEnumerable.GenerateByIndex(_ => new BasicNeuron(new ThFunction())).Take(_outputSize).ToArray(); foreach (var i in inputs) { foreach (var m in mid) { var weight = _random.NextDouble(); graph.AddVerticesAndEdge(new Connection(i, m, weight)); } } foreach (var m in mid) { foreach (var o in outputs) { var weight = _random.NextDouble(); graph.AddVerticesAndEdge(new Connection(m, o, weight)); } } yield return(new NeuralNetwork(graph, inputs, outputs)); } }
public object SolveGenerateByIndex() { // using MoreLinq GenerateByIndex var sum = MoreEnumerable.GenerateByIndex(x => (x % 3 == 0) || (x % 5 == 0) ? x : 0).Take(1000).Sum(); return(sum); }
private void test() { DateTime startDate = DateTime.Now.AddDays(-29); DateTime endDate = DateTime.Now.AddDays(1); using (var dc = new DataContext()) { //get database sales from 29 days ago at midnight to the end of today var salesForPeriod = dc.Orders.Where(b => b.OrderDateTime > startDate.Date && b.OrderDateTime <= endDate.Date); var allDays = MoreEnumerable.GenerateByIndex(i => startDate.AddDays(i)).Take(30); var salesByDay = from s in salesForPeriod group s by s.OrderDateTime.Date into g select new {Day = g.Key, totalSales = g.Sum(x=>(decimal)x.OrderPrice}; var query = from d in allDays join s in salesByDay on s.Day equals d select new {Day = s.Day , totalSales = (s != null) ? s.totalSales : 0m; foreach (var item in query) { Response.Write("Date: " +item.Day.ToString() " Sales: " + String.Format("{0:0.00}", item.totalSales) + "<br>"); } } } }
private void test() { DateTime startDate = DateTime.Now.AddDays(-29); DateTime endDate = DateTime.Now.AddDays(1); using (var dc = new DataContext()) { //get database sales from 29 days ago at midnight to the end of today var salesForPeriod = dc.Orders.Where(b => b.OrderDateTime > startDate.Date && b.OrderDateTime <= endDate.Date); var allDays = MoreEnumerable.GenerateByIndex(i => startDate.AddDays(i)).Take(30); var salesByDay = from s in salesForPeriod group s by s.OrderDateTime.Date into g select new {Day = g.Key, totalSales = g.Sum(x=>(decimal)x.OrderPrice}; var query = from d in allDays join s in salesByDay on s.Day equals d into j select (s != null) ? s.totalSales : 0m; } } }
public void GenerateByIndex() { var sequence = MoreEnumerable.GenerateByIndex(x => x.ToString()).Take(3); sequence.AssertSequenceEqual("0", "1", "2"); }
public void GenerateByIndexWithNullGenerator() { MoreEnumerable.GenerateByIndex <int>(null); }
public void GenerateByIndexIsLazy() { MoreEnumerable.GenerateByIndex(BreakingFunc.Of <int, int>()); }
public void GenerateByIndexWithNullGenerator() { Assert.ThrowsArgumentNullException("generator", () => MoreEnumerable.GenerateByIndex <int>(null)); }