-
-
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
Broadcasting UniformScaling Operations #23197
Comments
Between this and #23156, is there a need for an identity matrix struct that is a subtype of struct IdentityMatrix{T} <: AbstractMatrix{T}
size::Int
end
IdentityMatrix(size::Int) = IdentityMatrix{Float64}(size)
Base.size(A::IdentityMatrix) = (A.size, A.size)
function Base.getindex(A::IdentityMatrix{T}, i::Int, j::Int) where {T}
@boundscheck checkbounds(A, i, j)
ifelse(i == j, one(T), zero(T))
end julia> IdentityMatrix(4) .- zeros(4, 4)
4×4 Array{Float64,2}:
1.0 0.0 0.0 0.0
0.0 1.0 0.0 0.0
0.0 0.0 1.0 0.0
0.0 0.0 0.0 1.0 |
I don't think we need to give up on making |
What would |
Hopefully |
It would make the implementation a bit more cumbersome, but I can give it a shot. |
The current meaning here is now deprecated, so we have space to implement broadcasting as you expected in the future: julia> I .- ones(4,4)
┌ Warning: broadcast will default to iterating over its arguments in the future. Wrap arguments of
│ type `x::UniformScaling{Bool}` with `Ref(x)` to ensure they broadcast as "scalar" elements.
│ caller = ip:0x0
└ @ Core :-1
4×4 Array{Float64,2}:
0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 |
* Remove scalar .= deprecation * Remove to_index(::Bool) deprecation * broadcasting now falls back to iteration (fixes JuliaLang#23197, fixes JuliaLang#23746)
Let's re-open this to track the possibility of actually supporting |
Bump! Anyone have an idea on how to do this? |
💯. This came up on Slack today. I wanted to tell someone to write |
bump again. @mbauman any ideas on how to do this? |
I started poking at this earlier this week in https://github.com/JuliaLang/julia/tree/mb/I%2Cbroadcast. That's not quite right; I'm still brainstorming other ways to go about it. |
Another bump, apparently this is an issue that often pops up. What is currently blocking? |
Someone implementing it I think. |
@mbauman do you remember what was not quite right about this? |
Oooh, I don't remember. Should have left better notes for myself. I see I have a TODO about ensuring that the size is square, and looking at the diff now makes me think there may be some holes around heterogeneous combinations with scalar and 0-dim arguments, but I'm not sure. |
bump! :) this comes up often, and kinda defeats the purpose of having a lazy identity matrix |
+1, i ran into this recently as well. |
I contemplated taking a slightly different approach, but I can't say if it was necessarily better:
|
Broadcasting is not only super convenient, but it also gives new features. For example, broadcasted operations can generate GPU kernels with GPUArrays.jl. So it's really nice to be able to broadcast operations... but this one seems missing. I can't seem to do:
If you try to do something similar with broadcast, it's incorrect:
It would be nice if broadcast worked on the UniformScaling operator.
The text was updated successfully, but these errors were encountered: