Title
Missing initializer_list constructor for piecewise_constant_distribution
Status
resolved
Section
[rand.dist.samp.pconst]
Submitter
Daniel Krügler

Created on 2008-08-22.00:00:00 last changed 169 months ago

Messages

Date: 2011-03-05.21:44:45

Rationale:

Addressed by N2836 "Wording Tweaks for Concept-enabled Random Number Generation in C++0X".

Date: 2010-10-21.18:28:33

Proposed resolution:

Non-concept version of the proposed resolution

  1. In [rand.dist.samp.pconst]/1, class piecewise_constant_distribution, just before the member declaration

    explicit piecewise_constant_distribution(const param_type& parm);
    

    insert

    template<typename Func>
    piecewise_constant_distribution(initializer_list<RealType> bl, Func fw);
    
  2. Between p.4 and p.5 of the same section insert a series of new paragraphs nominated below as [p5_1], [p5_2], and [p5_3] as part of the new member description:

    template<typename Func>
    piecewise_constant_distribution(initializer_list<RealType> bl, Func fw);
    

    [p5_1] Complexity: Exactly nf = max(bl.size(), 1) - 1 invocations of fw.

    [p5_2] Requires:

    1. fw shall be callable with one argument of type RealType, and shall return values of a type convertible to double;
    2. The relation 0 < S = w0+. . .+wn-1 shall hold. For all sampled values xk defined below, fw(xk) shall return a weight value wk that is non-negative, non-NaN, and non-infinity;
    3. If nf > 0 let bk = *(bl.begin() + k), k = 0, . . . , bl.size()-1 and the following relations shall hold for k = 0, . . . , nf-1: bk < bk+1.

    [p5_3] Effects:

    1. If nf == 0,

      1. lets the sequence w have length n = 1 and consist of the single value w0 = 1, and
      2. lets the sequence b have length n+1 with b0 = 0 and b1 = 1.
    2. Otherwise,

      1. sets n = nf, and [bl.begin(), bl.end()) shall form the sequence b of length n+1, and
      2. lets the sequences w have length n and for each k = 0, . . . ,n-1, calculates:

        xk = 0.5*(bk+1 + bk) wk = fw(xk)

    3. Constructs a piecewise_constant_distribution object with the above computed sequence b as the interval boundaries and with the probability densities:

      ρk = wk/(S * (bk+1 - bk)) for k = 0, . . . , n-1.

Concept version of the proposed resolution

  1. In [rand.dist.samp.pconst]/1, class piecewise_constant_distribution, just before the member declaration

    explicit piecewise_constant_distribution(const param_type& parm);
    

    insert

    template<Callable<auto, RealType> Func>
     requires Convertible<Func::result_type, double>
    piecewise_constant_distribution(initializer_list<RealType> bl, Func fw);
    
  2. Between p.4 and p.5 of the same section insert a series of new paragraphs nominated below as [p5_1], [p5_2], and [p5_3] as part of the new member description:

    template<Callable<auto, RealType> Func>
     requires Convertible<Func::result_type, double>
    piecewise_constant_distribution(initializer_list<RealType> bl, Func fw);
    

    [p5_1] Complexity: Exactly nf = max(bl.size(), 1) - 1 invocations of fw.

    [p5_2] Requires:

    1. The relation 0 < S = w0+. . .+wn-1 shall hold. For all sampled values xk defined below, fw(xk) shall return a weight value wk that is non-negative, non-NaN, and non-infinity;
    2. If nf > 0 let bk = *(bl.begin() + k), k = 0, . . . , bl.size()-1 and the following relations shall hold for k = 0, . . . , nf-1: bk < bk+1.

    [p5_3] Effects:

    1. If nf == 0,

      1. lets the sequence w have length n = 1 and consist of the single value w0 = 1, and
      2. lets the sequence b have length n+1 with b0 = 0 and b1 = 1.
    2. Otherwise,

      1. sets n = nf, and [bl.begin(), bl.end()) shall form the sequence b of length n+1, and
      2. lets the sequences w have length n and for each k = 0, . . . ,n-1, calculates:

        xk = 0.5*(bk+1 + bk) wk = fw(xk)

    3. Constructs a piecewise_constant_distribution object with the above computed sequence b as the interval boundaries and with the probability densities:

      ρk = wk/(S * (bk+1 - bk)) for k = 0, . . . , n-1.

Date: 2008-08-22.00:00:00

During the Sophia Antipolis meeting it was decided to separate from 794 a subrequest that adds initializer list support to piecewise_constant_distribution, specifically, the issue proposed to add a c'tor taking a initializer_list<double> and a Callable to evaluate weight values. For consistency with the remainder of this class and the remainder of the initializer_list-aware library the author decided to change the list argument type to the template parameter RealType instead. For the reasoning to use Func instead of Func&& as c'tor function argument see issue 793.

History
Date User Action Args
2010-12-05 14:14:49adminsetstatus: nad editorial -> resolved
2010-10-21 18:28:33adminsetmessages: + msg4149
2010-10-21 18:28:33adminsetmessages: + msg4148
2008-08-22 00:00:00admincreate