-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
2.0: Don't iterate Matrix
#51043
Comments
Wouldn't this be really annoying for writing generic functions? The boilerplate seems awful. For example, a function like function mysum(x)
s = zero(eltype(x))
for xx in x
s += xx
end
return s
end would need the extra methods mysum(x::AbstractArray) = mysum(vec(x))
mysum(x::AbstractVector) = invoke(mysum, Tuple{Any}, x) just to be sure that an Without some really compelling arguments, I think we're better off leaving it to the user to remember to |
What's 2.0? |
Explicitly creating an iterator shouldn't require any more cost than doing it implicitly. If
sum(m::AbstractArray) = reduce(+, eachval(m)) |
This would need a larger philosophy of "what's an array" around it for motivation, I'd think. Currently, our arrays are collections of their items, and that's the rationale that underpins many of their behaviors (including this as well as other things like linear indexing and JuliaLang/LinearAlgebra.jl#42). In any case, "what's 2.0?" is the best question here. :) |
I assume "2.0" refers to this as a proposal for Julia v2.0 since this is obviously breaking. I could see this making sense if we divorced the linear-algebraic concepts of "vectors, matrices, and tensors" from "n-dimensional arrays." Linear algebraic objects would likely just be trivial wrappers over n-dimensional arrays, but their behavior would diverge. For example, linear indexing into a 2-dimensional array can maybe make sense but linear indexing into (or iterating) a "matrix" does not. The multiplication of two matrices is defined but two arrays should either implement the element-wise product or no product at all (although still permitting |
One of the many uses of linear iteration for B = [f(x) for x in A] result in an array the same shape as |
I really don't think this is a good idea; for one, it would break 99% of the code in JuliaImages. Should this really be on the 2.0 milestone? Or even remain open? |
Almost always when I iterate a matrix it's a typo for
eachrow(m)
oreachcol(m)
. If I want to do it on purpose, I'd prefer to use a non-allocating iterator denotedvec(m)
oreachval(m)
.The text was updated successfully, but these errors were encountered: