-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP/RFC: allow resize! to initialize new elements #16769
base: master
Are you sure you want to change the base?
Conversation
Makes sense. Though that signature would conflict with #16737, so if we want both we need to find an alternative somewhere. |
Maybe the |
Probably. |
👍. The version without |
Is |
[Sorry for the long post, cf. conclusion at the end] Concerning "arrays that don't have efficient linear indexing": would it make sense to have an
Again, I'm not sure about the fact that In conclusion, I propose to leave
|
This makes
resize!(A, n, default)
initialize new elements with adefault
value in case of (positive) growth. A more general versionresize(filler, A, n)
is also introduced which initializesA[i]
withfiller(i)
. This can be useful in particular when the default values must be distinct objects (e.g.resize!(_->Int[], Vector{Vector{Int}}(), 2)
).For reference, the corresponding resize function in C++ accepts such a default value (and also rust apparently).
I implemented this by adding a method to
fill!
, but I'm not sure it's the right solution:fill!(filler, A::AbstractArray, start::Integer, stop::Integer)
.If this becomes public API, it would then makes sense to have default values for
start/stop
:fill!(filler, A::AbstractArray)
, but then there could be ambiguity withfill!(A::AbstractArray, default)
ifdefault
is of typeAbstractArray
.I can simply rename this method to
_fill!
to postpone the discussion of an extendedfill!
API.If the idea receives support, I will write docs/tests and a similar version for
BitArray{1}
should also probably exist.