Fix the constructor of DiscreteNonParametric
#1908
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The constructor of
DiscreteNonParametric
always sorts the support, but this can change the type of the inputs - which means that the constructor either has to lie about the type of the constructed object or (as done currently) has to try to convert them back to the type of the input arguments. The latter fails e.g. forSubArray
s.IMO an inner constructor should generally not sort inputs but only check whether they are sorted. Therefore this PR removes sorting from the inner constructor and moves it to the outer constructor, and a check for whether the support vector is sorted is added to the inner constructor.
Additionally, to make construction more efficient the PR
AbstractUnitRange
but this could be refactored into astatic_issorted(::AbstractVector)
function if more types show up)issorted_allunique
that checks efficiently whether a vector is sorted and contains only unique elements (ie its elements are strictly monotonically increasing) (forAbstractUnitRange
issorted_allunique
just returnstrue
, so is a no-op).Fixes #1084.
Fixes #1832.
Fixes #1878 (but no test is added since it would require an additional dependency on RecursiveArrayTools).