Skip to content
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

Support structured array types #223

Open
putianyi889 opened this issue Mar 18, 2023 · 7 comments
Open

Support structured array types #223

putianyi889 opened this issue Mar 18, 2023 · 7 comments

Comments

@putianyi889
Copy link
Contributor

Since JuliaLang/julia#222 , fill +/- loses support for most structured arrays.

julia> s=Symmetric(rand(3,3))
3×3 Symmetric{Float64, Matrix{Float64}}:
 0.110199  0.379641  0.536482
 0.379641  0.518226  0.384931
 0.536482  0.384931  0.955319

julia> s+Zeros(3,3)
3×3 Matrix{Float64}:
 0.110199  0.379641  0.536482
 0.379641  0.518226  0.384931
 0.536482  0.384931  0.955319

It's not practical to list the types since ToeplitzMatrices, LazyArrays, StaticArrays, etc., are not dependencies. This could be solved in Julia 1.9 using package extensions.

@jishnub
Copy link
Member

jishnub commented Mar 19, 2023

See JuliaLang/LinearAlgebra.jl#993 for a different approach.

In general, perhaps this should be done through broadcast styles?

@putianyi889
Copy link
Contributor Author

putianyi889 commented Mar 19, 2023

In general, perhaps this should be done through broadcast styles?

That's true, but I don't know how broadcast works. Will broadcasting not be affected by ambiguity? StaticArrays uses map so will be fine, but what about general cases?

@putianyi889
Copy link
Contributor Author

Prior to 1.9, can we have mini packages that resolve the ambiguities? For example, FillArraysXStaticArrays.jl

@putianyi889
Copy link
Contributor Author

one could use fill_add to work around for now.

@dlfivefifty
Copy link
Member

dlfivefifty commented Mar 22, 2023

I think broadcasting is the right approach. I believe if there's an ambiguity in broadcasting it falls back to the default behaviour.

That is: we should overload BroadcastStyle and do intelligent broadcasting there.

@dlfivefifty
Copy link
Member

Note Symmetric addition is handled at the +:

julia> S .+ S
5×5 Matrix{Float64}:
 -1.90614    2.27016   -0.412719   0.331858   3.62299
  2.27016   -1.48817    0.456745   2.18015    0.599337
 -0.412719   0.456745   4.30436   -2.37771    0.431586
  0.331858   2.18015   -2.37771    0.966284   0.971221
  3.62299    0.599337   0.431586   0.971221  -1.9591

julia> S + S
5×5 Symmetric{Float64, Matrix{Float64}}:
 -1.90614    2.27016   -0.412719   0.331858   3.62299
  2.27016   -1.48817    0.456745   2.18015    0.599337
 -0.412719   0.456745   4.30436   -2.37771    0.431586
  0.331858   2.18015   -2.37771    0.966284   0.971221
  3.62299    0.599337   0.431586   0.971221  -1.9591

So I'm inclined not to bother atm

@jishnub
Copy link
Member

jishnub commented Mar 28, 2023

It appears that the fzeros approach isn't sufficient here, as

julia> typeof(s)
Symmetric{Float64, Matrix{Float64}}

julia> Broadcast.BroadcastStyle(typeof(s))
Base.Broadcast.DefaultArrayStyle{2}()

Perhaps Symmetric should define its own broadcast style in LinearAlgebra

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants