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

Restrict LinearAlgebra.onedefined to concrete number types #52632

Closed
wants to merge 1 commit into from

Conversation

jishnub
Copy link
Contributor

@jishnub jishnub commented Dec 26, 2023

This makes onedefined more conservative, so that now

julia> LinearAlgebra.onedefined(Number)
false

julia> LinearAlgebra.onedefined(Union{Float64,ComplexF64})
false

In general, we cannot guarantee that oneunit works with abstract or union types. After this, the following contrived example works correctly instead of throwing an error:

julia> using Symbolics

julia> @variables x
1-element Vector{Num}:
 x

julia> A = Bidiagonal{Real}([1,2], [x], :U)
2×2 Bidiagonal{Real, Vector{Real}}:
 1  x
   2

julia> A \ [1,2]
2-element Vector{Any}:
 1 - x
     1.0

This change widens certain inferred types. E.g., on master:

julia> Bidiagonal{Number}(ones(4), ones(3), :U) \ ones(4)
4-element Vector{Float64}:
 0.0
 1.0
 0.0
 1.0

whereas, in this PR, this returns a Vector{Any}. This may be acceptable, though, if one starts with abstract types.

@jishnub jishnub added the linear algebra Linear algebra label Dec 26, 2023
@dkarrasch
Copy link
Member

I guess this would be obsolete after #52464?

@jishnub
Copy link
Contributor Author

jishnub commented Dec 30, 2023

Yes, I'll close this for now

@jishnub jishnub closed this Dec 30, 2023
@jishnub jishnub deleted the jishnub/linalgoneel branch December 30, 2023 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linear algebra Linear algebra
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants