当前位置: 首页>>代码示例>>C#>>正文


C# Tuple.SelectMany方法代码示例

本文整理汇总了C#中Tuple.SelectMany方法的典型用法代码示例。如果您正苦于以下问题:C# Tuple.SelectMany方法的具体用法?C# Tuple.SelectMany怎么用?C# Tuple.SelectMany使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tuple的用法示例。


在下文中一共展示了Tuple.SelectMany方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetForces

            private static double[][] GetForces(double[][] positions, Tuple<int, int, double>[] desiredDistances, double mult)
            {
                // Calculate forces
                Tuple<int, double[]>[] forces = desiredDistances.
                    //AsParallel().     //TODO: if distances.Length > threshold, do this in parallel
                    SelectMany(o => GetForces_Calculate(o.Item1, o.Item2, o.Item3, positions, mult)).
                    ToArray();

                // Give them a very slight pull toward the origin so that the cloud doesn't drift away
                double[] center = MathND.GetCenter(positions);
                double centerMult = mult * -5;

                double[] centerPullForce = MathND.Multiply(center, centerMult);

                // Group by item
                var grouped = forces.
                    GroupBy(o => o.Item1).
                    OrderBy(o => o.Key);

                return grouped.
                    Select(o =>
                    {
                        double[] retVal = centerPullForce.ToArray();        // clone the center pull force

                        foreach (var force in o)
                        {
                            retVal = MathND.Add(retVal, force.Item2);
                        }

                        return retVal;
                    }).
                    ToArray();
            }
开发者ID:charlierix,项目名称:AsteroidMiner,代码行数:33,代码来源:MathND.cs

示例2: UnresolvedModule

        /// <param name="path">Application relative path to the module directory.</param>
        /// <param name="resources">All the unresolved resources found in the module.</param>
        /// <param name="isResourceOrderFixed">When true, the resources will not be sorted by their dependency ordering.</param>
        public UnresolvedModule(string path, UnresolvedResource[] resources, string location, bool isResourceOrderFixed)
        {
            this.path = path;
            this.location = location;

            var pathsInModule = new HashSet<string>(resources.Select(resource => resource.Path));
            partition = PartitionResourceReferences(resources, pathsInModule);
            // Store all the references to external resources.
            this.externalReferences = partition.SelectMany(p => p.Item2).Distinct().ToArray();
            // The resources now only contain references found in this module.
            var resolvedResources = partition.Select(p => p.Item1).ToArray();
            if (isResourceOrderFixed)
            {
                this.resources = resolvedResources;
            }
            else
            {
                this.resources = OrderScriptsByDependency(resolvedResources);
            }
        }
开发者ID:ryansroberts,项目名称:knapsack,代码行数:23,代码来源:UnresolvedModule.cs

示例3: TrainAsync

            private static Task<Tuple<long, TrainedNework_Simple>> TrainAsync(Tuple<string, EncogOCR_SketchData[]>[] sketches, long token, bool shouldGenerateGarbage, CancellationTokenSource cancel)
            {
                CancellationToken cancelToken = cancel.Token;

                return Task.Run(() =>
                {
                    string[] outputMap = sketches.
                        Select(o => o.Item1).
                        ToArray();

                    int inputSize = sketches[0].Item2[0].NNInput.Length;

                    #region Training Data

                    List<double[]> inputs = new List<double[]>();
                    List<double[]> outputs = new List<double[]>();

                    int groupIndex = 0;
                    foreach (var group in sketches)
                    {
                        double[] output = Enumerable.Range(0, outputMap.Length).
                            Select((o, i) => i == groupIndex ? 1d : 0d).
                            ToArray();

                        foreach (var input in group.Item2)
                        {
                            inputs.Add(input.NNInput);
                            outputs.Add(output);
                        }

                        groupIndex++;
                    }

                    if (shouldGenerateGarbage)
                    {
                        GenerateGarbageData(sketches.SelectMany(o => o.Item2).ToArray(), outputMap.Length, inputs, outputs);
                    }

                    #endregion

                    //NOTE: If there is an exception, the network couldn't be trained
                    BasicNetwork network = null;
                    try
                    {
                        network = UtilityEncog.GetTrainedNetwork2(inputs.ToArray(), outputs.ToArray(), 20, 300, cancelToken).NetworkOrNull;
                    }
                    catch (Exception) { }

                    var returnProps = new TrainedNework_Simple()
                    {
                        InputSize = inputSize,
                        Outputs = outputMap,
                        Network = network,
                    };

                    return Tuple.Create(token, returnProps);
                }, cancelToken);
            }
开发者ID:charlierix,项目名称:AsteroidMiner,代码行数:58,代码来源:EncogOCR.xaml.cs

示例4: GetChainsSprtFragments

                private static Chain[] GetChainsSprtFragments(List<Tuple<int, int>> segments, Tuple<int, int>[] pointCounts)
                {
                    List<int> ends = pointCounts.SelectMany(o => Enumerable.Repeat(o.Item1, o.Item2)).ToList();

                    List<Chain> retVal = new List<Chain>();

                    while (ends.Count > 0)
                    {
                        Chain chain = GetChainsSprtSingle(segments, ends[0], ends.Where(o => o != ends[0]).ToArray());

                        ends.Remove(chain.Points[0]);
                        ends.Remove(chain.Points[chain.Points.Length - 1]);

                        retVal.Add(chain);
                    }

                    return retVal.ToArray();
                }
开发者ID:charlierix,项目名称:AsteroidMiner,代码行数:18,代码来源:ShadowsWindow.xaml.cs

示例5: AssertThatWeWontDuplicateQueueNames

        private void AssertThatWeWontDuplicateQueueNames()
        {
            var queueCounts = new Tuple<string, Type>[0]
                .Union(CommandTypes.Select(t => new Tuple<string, Type>(PathFactory.QueuePathFor(t), t)))
                .Union(RequestTypes.Select(t => new Tuple<string, Type>(PathFactory.QueuePathFor(t), t)))
                .Union(EventTypes.Select(t => new Tuple<string, Type>(PathFactory.TopicPathFor(t), t)))
                .GroupBy(queue => queue.Item1)
                .Where(dupe => dupe.Count() > 1).ToArray();


            if (queueCounts.None())
                return;

            var badTypes = queueCounts.SelectMany(dupe => dupe.Select( d => d.Item2.Name));
            var message = "Your message types {0} will result in a duplicate queue name.".FormatWith(string.Join(", ", badTypes));

            throw new BusException(message);

        }
开发者ID:nhuhuynh,项目名称:Nimbus,代码行数:19,代码来源:AssemblyScanningTypeProvider.cs


注:本文中的Tuple.SelectMany方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。