RFC: Support getindex for Repeated and Take iterators #15988
Closed
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.
This allows using
repeated()
to create a vector-like object.The goal of this PR is to allow using
repeated(1, N)
as a more general solution to the idea of aOnes
type (see JuliaStats/StatsBase.jl#135). The idea is to always write algorithms in their most general form accepting numeric weights, and make the non-weighted form use a special object returning only unit weights.If I'm correct, with proper inlining,
repeated(1, N)
will/can be as efficient as asOnes
type for which the return value is known at compile time. Though even if that doesn't work, this PR makes sense for other use cases.I've marked it as RFC because I wonder whether it wouldn't be better to make
repeated(::Any, ::Integer)
return a newNRepeated
type which would be a subtype ofAbstractVector
. Indeed, even if I addedgetindex
methods,Take{Repeated}}
objects can't be passed to functions expecting a vector, which could be annoying. Comments welcome!