zeros
/ones
/fill
may accept arbitrary axes that are supported by similar
#53965
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 idea is that functions like
zeros
are essentially constructing a container and filling it with a value.similar
seems perfectly placed to construct such a container, so we may accept arbitrary axes inzeros
as long as there's a correspondingsimilar
method that is defined for the axes. Packages therefore would only need to definesimilar
, and would getzeros
/ones
andfill
for free. For example, the following will work after this:Neither of these work on the current master, as
StaticArrays
doesn't definezeros
for these combinations, even though it does definesimilar
. One may argue for these methods to be added toStaticArrays
, but this seems to be adding redundancy.The flip side is that
OffsetArrays
defines exactly these methods, so adding them toBase
would break precompilation for the package. However,OffsetArrays
really shouldn't be defining these methods, as this is type-piracy. The methods may be version-limited inOffsetArrays
if this PR is merged.On the face of it,
trues
andfalses
should also work similarly, but currently these seem to be bypassingsimilar
and constructing aBitArray
explicitly. I have not added the corresponding methods for these functions, but they may be added as well.