-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
zeros
/ones
/fill
may accept arbitrary axes that are supported by…
… `similar` (#53965) 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 in `zeros` as long as there's a corresponding `similar` method that is defined for the axes. Packages therefore would only need to define `similar`, and would get `zeros`/`ones` and `fill` for free. For example, the following will work after this: ```julia julia> using StaticArrays julia> zeros(SOneTo(2), 2) 2×2 Matrix{Float64}: 0.0 0.0 0.0 0.0 julia> zeros(SOneTo(2), Base.OneTo(2)) 2×2 Matrix{Float64}: 0.0 0.0 0.0 0.0 ``` Neither of these work on the current master, as `StaticArrays` doesn't define `zeros` for these combinations, even though it does define `similar`. One may argue for these methods to be added to `StaticArrays`, but this seems to be adding redundancy. The flip side is that `OffsetArrays` defines exactly these methods, so adding them to `Base` 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 in `OffsetArrays` if this PR is merged. On the face of it, `trues` and `falses` should also work similarly, but currently these seem to be bypassing `similar` and constructing a `BitArray` explicitly. I have not added the corresponding methods for these functions, but they may be added as well.
- Loading branch information
Showing
5 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters