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


C# IEnumerable.Sum方法代码示例

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


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

示例1: Pearson

        public static double Pearson(IEnumerable<long> v1, IEnumerable<long> v2)
        {
            var sum1 = v1.Sum();
            var sum2 = v2.Sum();

            // Sum of the squares
            var sum1Sq = v1.Sum(v => m.Pow(v, 2));
            var sum2Sq = v2.Sum(v => m.Pow(v, 2));

            // Sum of the products
            var l1 = v1.ToArray();
            var l2 = v2.ToArray();

            if (l1.Length != l2.Length)
                throw new ApplicationException("Input data should contain the equal number of items");

            long pSum = Enumerable.Range(0, l1.Length)
                .Select(i => l1[i] * l2[i])
                .Sum();

            // Calculate r (Pearson score)
            var num = pSum - (sum1 * sum2 / l1.Length);
            var den =
                m.Sqrt((sum1Sq - m.Pow(sum1, 2)/l1.Length)*(sum2Sq - m.Pow(sum2, 2)/l2.Length));

            if (den == 0)
                return 0;

            return 1.0 - num /den;
        }
开发者ID:Klaudit,项目名称:inbox2_desktop,代码行数:30,代码来源:Clustering.cs

示例2: Run

 public Run(IEnumerable<Assembly> assemblies) : base(assemblies.Cast<SpecificationContainer>())
 {
   _assemblies = assemblies;
   _totalAssemblies = assemblies.Count();
   _totalConcerns = assemblies.Sum(x => x.TotalConcerns);
   _totalContexts = assemblies.Sum(x => x.TotalContexts);
 }
开发者ID:benlovell,项目名称:machine.specifications,代码行数:7,代码来源:Run.cs

示例3: Report

        public void Report(IEnumerable<SuiteRunResult> executed)
        {
            var totalPasses = executed.Sum(x => x.Passes);
            var totalFailures = executed.Sum(x => x.Failures);
            var total = totalPasses + totalFailures;

            _output.WriteLine("Loaded: {0}".FormatWith(executed.Select(s => s.Name).Join(", ")));
            _output.WriteLine("  {0} {1} loaded.".FormatWith(
                total,
                "test".Pluralize(total)));
            _output.WriteLine("  {0}/{1} {2} passed ({3} {4}).".FormatWith(
                totalPasses,
                total,
                "test".Pluralize(total),
                totalFailures,
                "failure".Pluralize(totalFailures)));

            if (totalFailures > 0)
                _output.WriteLine("Failures: ");
            executed.Each(suiteResult => suiteResult
                .Results
                .Where(containerResult => containerResult.Results.Any(r => !r.Pass))
                .Each(f =>
                {
                    _output.WriteLine("  {0}.{1} contained {2} failures.".FormatWith(suiteResult.Name, f.Name, f.Failures));
                    f.Results.Where(r => !r.Pass).Each(r => _output.WriteLine("    {0} failed. [{1}]".FormatWith(r.Name, r.Message)));
                }));

            _output.Flush();
        }
开发者ID:jonfuller,项目名称:class,代码行数:30,代码来源:TextReporter.cs

示例4: SpecificationContainer

 protected SpecificationContainer(IEnumerable<SpecificationContainer> specificationContainers)
 {
   _totalSpecifications = specificationContainers.Sum(x => x.TotalSpecifications);
   _passingSpecifications = specificationContainers.Sum(x => x.PassingSpecifications);
   _failingSpecifications = specificationContainers.Sum(x => x.FailingSpecifications);
   _notImplementedSpecifications = specificationContainers.Sum(x => x.NotImplementedSpecifications);
 }
开发者ID:jayhill,项目名称:machine.specifications,代码行数:7,代码来源:SpecificationContainer.cs

示例5: Run

 public Run(IEnumerable<Assembly> assemblies) : base(assemblies.Cast<SpecificationContainer>())
 {
   Meta = new Meta { GeneratedAt = DateTime.Now };
   _assemblies = assemblies.OrderBy(x => x.Name);
   _totalAssemblies = assemblies.Count();
   _totalConcerns = assemblies.Sum(x => x.TotalConcerns);
   _totalContexts = assemblies.Sum(x => x.TotalContexts);
 }
开发者ID:hennys,项目名称:machine.specifications,代码行数:8,代码来源:Run.cs

示例6: RiskResult

 public RiskResult(IEnumerable<StationPath> path, double radius)
 {
     Radius = radius;
     Path = path;
     TotalRisk = path.Sum(x => x.Risk);
     TotalDistance = path.Sum(x => x.Distance);
     TotalDistanceRatio = TotalDistance / (Math.PI * radius);
 }
开发者ID:ungood,项目名称:puzzles,代码行数:8,代码来源:RiskResult.cs

示例7: getAverageColor

        private static CieLabColor getAverageColor(IEnumerable<CieLabColor> colors)
        {
            double colorCount = colors.Count();
            double l = colors.Sum(color => color.L) / colorCount;
            double a = colors.Sum(color => color.A) / colorCount;
            double b = colors.Sum(color => color.B) / colorCount;

            return new CieLabColor((float)l, (float)a, (float)b);
        }
开发者ID:Banane9,项目名称:Quads,代码行数:9,代码来源:ColorAverage.cs

示例8: WeightingDensity

        public double WeightingDensity(IEnumerable<MaterialDensityCalculationItem> items)
        {
            //错误输入验证代码后续

            double[] tmpValue = new double[items.Count()];
            double sum = items.Sum(i => i.MoleWeight * i.At);
            double weightingDensity = items.Sum(i => i.At * i.MoleWeight / sum * i.Density);

            return weightingDensity;
        }
开发者ID:newlifechou,项目名称:PMS,代码行数:10,代码来源:MaterialDensityCalculation.cs

示例9: SlopeOfPoints

        /// <summary>
        /// Gets the slope for a set of points using the formula:
        /// m = SUM(x-AVG(x)(y-AVG(y)) / SUM(x-AVG(x))^2
        /// </summary>
        /// <param name="points">Points to calculate the Slope from</param>
        /// <returns>SlopeOfPoints</returns>
        private static float SlopeOfPoints(IEnumerable<PointF> points)
        {
            float avgX = points.Average(p => p.X);
            float avgY = points.Average(p => p.Y);

            float dividend = points.Sum(p => (p.X - avgX) * (p.Y - avgY));
            float divisor = (float)points.Sum(p => Math.Pow(p.X - avgX, 2));

            return dividend / divisor;
        }
开发者ID:worstward,项目名称:rlviewer,代码行数:16,代码来源:LinearLeastSquares.cs

示例10: CardStatsByRarity

        public CardStatsByRarity(string rarity, IEnumerable<CardInCollection> cards)
        {
            Rarity = rarity;
            TotalAmount = cards.Select(c => c.MaxAmountInCollection)
                .Sum();
            PlayerHas = cards.Sum(c => c.AmountNonGolden);
            PlayerHasGolden = cards.Sum(c => c.AmountGolden);

            OpenGoldenOdds = CalculateOpeningOdds(cards, card => card.MaxAmountInCollection - card.AmountGolden, GoldenCardProbabilities);
            OpenNonGoldenOdds = CalculateOpeningOdds(cards, card => card.MaxAmountInCollection - card.AmountNonGolden, CardProbabilities);
        }
开发者ID:red2910,项目名称:Hearthstone-Collection-Tracker,代码行数:11,代码来源:SetDetailInfoViewModel.cs

示例11: BenchmarkResultList

        public BenchmarkResultList(IEnumerable<BenchmarkResult> results)
        {
            _results = results.ToArray();

            var totalTicks = _results.Sum(r => r.Time.Ticks);
            _totalTime = TimeSpan.FromTicks(totalTicks);
            _totalIterations = _results.Sum(r => r.Iterations);

            if (_totalIterations > 0)
                _average = TimeSpan.FromTicks(totalTicks/_totalIterations);
        }
开发者ID:MrAntix,项目名称:Testing,代码行数:11,代码来源:BenchmarkResultList.cs

示例12: Order

        public Order(IEnumerable<Outcome> outcomes, List<OrderLine> orderLines)
            : this()
        {
            Lines = orderLines;
            orderLines.ForEach(ol => ol.Order = this);

            Summ = outcomes.Sum(o => o.Summ);
            SummWithDiscount = outcomes.Sum(o => o.SummWithDiscount);
            Profit = outcomes.Sum(o => o.Profit);
            DiscountSumm = outcomes.Sum(o => o.DiscountSumm);
        }
开发者ID:kilonet,项目名称:elfam,代码行数:11,代码来源:Order.cs

示例13: InterfaceDefinitionsGenerator

 public InterfaceDefinitionsGenerator(IEnumerable<TypeScriptModule> modules, GeneratorOptions options)
 {
     _modules = modules;
       _sb = new IndentedStringBuilder(modules.Sum(m => m.ModuleMembers.Count) * 256, options.CodeGenerationOptions.IndentationCharacter, options.CodeGenerationOptions.IndentationIncrementAmount);
       _options = options;
       _propertyCommenter = new PropertyCommenter(options);
 }
开发者ID:omeaart,项目名称:CSTS,代码行数:7,代码来源:InterfaceDefinitionsGenerator.cs

示例14: CalculatePrice

        public Decimal CalculatePrice(IEnumerable<PotterBook> products)
        {
            Decimal summaryPrice;
            var bookCount = products.Count();
            summaryPrice = products.Sum(x => x.Price);
            switch (bookCount)
            {
                case 2:
                    summaryPrice = summaryPrice * 0.95m;
                    break;
                case 3:
                    summaryPrice = summaryPrice * 0.9m;
                    break;
                case 4:
                    summaryPrice = summaryPrice * 0.8m;
                    break;
                case 5:
                    summaryPrice = summaryPrice * 0.75m;
                    break;
                case 1:
                default:
                    break;
            }

            return summaryPrice;
        }
开发者ID:ciatrf,项目名称:TDD-HomeWork2,代码行数:26,代码来源:PotterShoppingCart.cs

示例15: HarmonicMean

        /// <summary>
        /// Calculates the harmonic mean of the given numbers.
        /// The harmonic mean is defined as zero if at least one of the numbers is zero.
        /// </summary>
        /// <param name="numbers">The numbers whose harmonic mean is to be calculated.</param>
        /// <returns>The harmonic mean of the given numbers.</returns>
        /// <exception cref="System.InvalidOperationException">
        /// The specified collection must not contain negative numbers and must not be empty.
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        /// The specified collection must not be null.
        /// </exception>
        public static double HarmonicMean(IEnumerable<double> numbers)
        {
            if (numbers == null)
            {
                throw ArgumentNullException;
            }

            if (!numbers.Any())
            {
                throw EmptyNumbersCollectionException;
            }

            if (numbers.Any(number => number < 0))
            {
                throw CollectionContainingNegativeNumbersException;
            }

            if (numbers.Contains(0))
            {
                // If one of the values strives against zero the limiting value of the harmonic mean does, too.
                // Therefore, it is sensible to define the harmonic mean as being zero if at least one of the values is zero.
                return 0;
            }

            double sumOfReciprocalValues = numbers.Sum(number => 1.0 / number);
            double harmonicMean = numbers.Count() / sumOfReciprocalValues;

            return harmonicMean;
        }
开发者ID:mariusschulz,项目名称:NAverage,代码行数:41,代码来源:HarmonicMeanCalculator.cs


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