Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/09/14 11:25:57 (10 years ago)
Author:
mkommend
Message:

#2259: Added includeEnd paramter to ValueGenerator.GenerateSteps and removed overloads that take a Func for value transformation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/ValueGenerator.cs

    r11434 r11435  
    3737    /// <param name="end">The largest and last value of the sequence.</param>
    3838    /// <param name="stepWidth">The step size between subsequent values.</param>
     39    /// <param name="includeEnd">Determines if the end should be included in the sequence regardless if the end is divisible by the stepwidth.</param>
    3940    /// <returns>A sequence of values from start to end (inclusive)</returns>
    4041    [Obsolete("It is recommended to use the decimal overload to achieve a higher numerical accuracy.")]
    41     public static IEnumerable<double> GenerateSteps(double start, double end, double stepWidth) {
     42    public static IEnumerable<double> GenerateSteps(double start, double end, double stepWidth, bool includeEnd = false) {
    4243      //mkommend: IEnumerable.Cast fails due to boxing and unboxing of the involved types
    4344      // http://referencesource.microsoft.com/#System.Core/System/Linq/Enumerable.cs#27bb217a6d5457ec
    4445      // http://blogs.msdn.com/b/ericlippert/archive/2009/03/19/representation-and-identity.aspx     
    4546
    46       return GenerateSteps((decimal)start, (decimal)end, (decimal)stepWidth).Select(x => (double)x);
     47      return GenerateSteps((decimal)start, (decimal)end, (decimal)stepWidth, includeEnd).Select(x => (double)x);
    4748    }
    4849
     
    5354    /// <param name="end">The largest and last value of the sequence.</param>
    5455    /// <param name="stepWidth">The step size between subsequent values.</param>
     56    /// /// <param name="includeEnd">Determines if the end should be included in the sequence regardless if the end is divisible by the stepwidth.</param>
    5557    /// <returns>A sequence of values from start to end</returns>
    56     public static IEnumerable<decimal> GenerateSteps(decimal start, decimal end, decimal stepWidth) {
     58    public static IEnumerable<decimal> GenerateSteps(decimal start, decimal end, decimal stepWidth, bool includeEnd = false) {
    5759      if (stepWidth == 0)
    5860        throw new ArgumentException("The step width cannot be zero.");
     
    6769        x += stepWidth;
    6870      }
    69     }
    70 
    71     /// <summary>
    72     /// Generates a sequence of points between start and end according to given transformation
    73     /// </summary>
    74     /// <param name="start">The smallest and first value of the sequence.</param>
    75     /// <param name="end">The largest and last value of the sequence.</param>
    76     /// <param name="stepWidth">The step size between subsequent values (before transform)</param>
    77     /// <param name="transform">The transform function</param>
    78     /// <returns></returns>
    79     [Obsolete("It is recommended to use the decimal overload to achieve a higher numerical accuracy.")]
    80     public static IEnumerable<double> GenerateSteps(double start, double end, double stepWidth, Func<double, double> transform) {
    81       return GenerateSteps(start,end, stepWidth).Select(transform);
    82     }
    83 
    84     /// <summary>
    85     /// Generates a sequence of points between start and end according to given transformation
    86     /// </summary>
    87     /// <param name="start">The smallest and first value of the sequence.</param>
    88     /// <param name="end">The largest and last value of the sequence.</param>
    89     /// <param name="stepWidth">The step size between subsequent values (before transform)</param>
    90     /// <param name="transform">The transform function</param>
    91     /// <returns></returns>
    92     public static IEnumerable<decimal> GenerateSteps(decimal start, decimal end, decimal stepWidth, Func<decimal, decimal> transform) {
    93       return GenerateSteps(start, end, stepWidth).Select(transform);
     71      if (x - stepWidth < end && includeEnd) yield return end;
    9472    }
    9573
Note: See TracChangeset for help on using the changeset viewer.