-
-
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
similar
should accept a type as first parameter
#17124
Comments
The new |
In the long-term, the fallback should likely go the other way: similar{CT}(::CT, specs...) = similar(CT, specs...) |
We also need to support this type of call: similar(dims->zeros(Int, dims), shape) which allocates an all-zero array (lower-case array, not |
The function
similar
accepts a container as first parameter, but not a container type, in the same way as e.g.eltype
. (Ifdims
is not specified, it should then construct an empty container.)In some cases, for example in distributed computing, one wants to allocate a container to hold the result of a
map
-like calculation, without having access to the original container. However, the type of the original container is known, as well as the element type of the result. In this case, the interface offered bysimilar
is insufficient -- it does not allow allocating a new container without creating an empty dummy container from the type.A fall-back definition that could be added to Base is
although I assume that many container types will want to provide a more specialized version that avoid creating an empty container.
The text was updated successfully, but these errors were encountered: