-
-
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
add zeros!
and ones!
, mutating versions of zeros
and ones
#40614
base: master
Are you sure you want to change the base?
Conversation
The current alternative is to use `fill!(x, 0)`, but this does not always work, when `convert(eltype(x), 0)` is not defined, for example when `x` is an array of `DateTime` objects.
24d8a23
to
f57d29d
Compare
zeros!
and ones
, mutating versions of zeros
and ones
zeros!
and ones!
, mutating versions of zeros
and ones
Your second proposal of |
If there is a (semantically) well-defined zero object for a type, then shouldn't the (Not commenting on the utility of the proposed functions in general, just that one part of the motivation.) |
Yes, I was just wondering about the case where constructing a zero is not cheap (
I'm not sure that it makes sense for all objects defining |
Doesn't this hold equally for Splitting hairs a bit here because I think this is the type of semantics that need to be very well documented for corner cases / counterintuitive behavior. 😄 |
xref #19912 |
The current alternative is to use
fill!(x, 0)
, but this does not alwayswork, when
convert(eltype(x), 0)
is not defined, for examplewhen
x
is an array ofDateTime
objects.Another benefit of introducing
zeros!
is that in some cases, the zeroelement can't be known from the
eltype
alone, but rather from the values.In this case, package can define their own appropriate method.
For example, we could define in
Base
azeros!(::AbstractArray{<:AbstractArray})
which replaces each value
v
byzero(v)
.