Movatterモバイル変換


[0]ホーム

URL:



This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofResolved status.

793.discrete_distribution missing constructor

Section: 29.5.9.6.1[rand.dist.samp.discrete]Status:ResolvedSubmitter: P.J. PlaugerOpened: 2008-02-09Last modified: 2016-01-28

Priority:Not Prioritized

View all otherissues in [rand.dist.samp.discrete].

View all issues withResolved status.

Discussion:

discrete_distribution should have a constructor like:

template<class _Fn>  discrete_distribution(result_type _Count, double _Low, double _High,                        _Fn& _Func);

(Makes it easier to fill a histogram with function values over a range.)

[Bellevue:]

How do you specify the function so that it does not return negativevalues? If you do it is a bad construction. This requirement is alreadythere. Where in each bin does one evaluate the function? In the middle.Need to revisit tomorrow.

[Sophia Antipolis:]

Bill is not requesting this.

Marc Paterno:_Fn cannot return negative values at the points where thefunction is sampled. It is sampled in the middle of each bin._Fn cannotreturn 0 everywhere it is sampled.

Jens: lambda expressions are rvalues

Add a library issue to provide aninitializer_list<double> constructor fordiscrete_distribution.

Marc Paterno: dislikes reference for_Fn parameter. Make it pass-by-value (to use lambda),usestd::ref to wrap giant-state function objects.

Daniel: Seerandom_shuffle, pass-by-rvalue-reference.

Daniel to draft wording.

[Pre San Francisco, Daniel provided wording:]

The here proposed changes of the WP refer to the current state ofN2691.During the Sophia Antipolis meeting two different proposals came upregarding the functor argument type, either by value or by rvalue-reference.For consistence with existing conventions (state-free algorithms and thegeneral_pdf_distribution c'tor signature) the author decided to propose afunction argument that is provided by value. If severe concerns exists thatstateful functions would be of dominant relevance, it should be possible toreplace the two occurrences ofFunc byFunc&& in this proposal as partof an editorial process.

Proposed resolution:

Non-concept version of the proposed resolution

  1. In 29.5.9.6.1[rand.dist.samp.discrete]/1, classdiscrete_distribution, justbefore the member declaration

    explicit discrete_distribution(const param_type& parm);

    insert:

    template<typename Func>discrete_distribution(result_type nf, double xmin, double xmax, Func fw);
  2. Between p.4 and p.5 insert a series of new paragraphs as part of thenew member description::

    template<typename Func>discrete_distribution(result_type nf, double xmin, double xmax, Func fw);

    Complexity: Exactly nf invocations of fw.

    Requires:

    1. fw shall be callable with one argument of type double, and shallreturn values of a type convertible to double;
    2. If nf > 0, the relationxmin <xmax shall hold, and for all sample valuesxk, fw(xk) shall return a weight valuewk that is non-negative, non-NaN,and non-infinity;
    3. The following relations shall hold: nf ≥ 0, and 0 < S =w0+. . .+wn-1.

    Effects:

    1. If nf == 0, sets n = 1 and lets the sequence w have length n = 1 and consist of the single valuew0 = 1.
    2. Otherwise, sets n = nf, deltax = (xmax -xmin)/n andxcent =xmin + 0.5 * deltax.

      For each k = 0, . . . ,n-1, calculates:

      xk =xcent + k * deltaxwk = fw(xk)

    3. Constructs a discrete_distribution object with probabilities:

      pk =wk/S for k = 0, . . . , n-1.

Concept version of the proposed resolution

  1. In 29.5.9.6.1[rand.dist.samp.discrete]/1, classdiscrete_distribution, justbefore the member declaration

    explicit discrete_distribution(const param_type& parm);

    insert:

    template<Callable<auto, double> Func> requires Convertible<Func::result_type, double>discrete_distribution(result_type nf, double xmin, double xmax, Func fw);
  2. Between p.4 and p.5 insert a series of new paragraphs as part of thenew member description::

    template<Callable<auto, double> Func> requires Convertible<Func::result_type, double>discrete_distribution(result_type nf, double xmin, double xmax, Func fw);

    Complexity: Exactly nf invocations of fw.

    Requires:

    1. If nf > 0, the relationxmin <xmax shall hold, and for all sample valuesxk, fw(xk) shall return a weight valuewk that is non-negative, non-NaN,and non-infinity;
    2. The following relations shall hold: nf ≥ 0, and 0 < S =w0+. . .+wn-1.

    Effects:

    1. If nf == 0, sets n = 1 and lets the sequence w have length n = 1 and consist of the single valuew0 = 1.
    2. Otherwise, sets n = nf, deltax = (xmax -xmin)/n andxcent =xmin + 0.5 * deltax.

      For each k = 0, . . . ,n-1, calculates:

      xk =xcent + k * deltaxwk = fw(xk)

    3. Constructs a discrete_distribution object with probabilities:

      pk =wk/S for k = 0, . . . , n-1.

Rationale:

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


[8]ページ先頭

©2009-2026 Movatter.jp