- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 35
          Specialize diag(::Diagonal)
          #1158
        
          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
base: master
Are you sure you want to change the base?
Conversation
| Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@            Coverage Diff             @@
##           master    #1158      +/-   ##
==========================================
- Coverage   91.84%   91.83%   -0.01%     
==========================================
  Files          34       34              
  Lines       15357    15358       +1     
==========================================
  Hits        14104    14104              
- Misses       1253     1254       +1     ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
 | 
| I'm unsure if  Diagonal(A::AbstractMatrix) = Diagonal(_diagcopy(A))
Diagonal{T}(A::AbstractMatrix) where T = Diagonal{T}(_diagcopy(A))
Diagonal{T,V}(A::AbstractMatrix) where {T,V<:AbstractVector{T}} = Diagonal{T,V}(_diagcopy(A))
_diagcopy(D) = diag(D)
_diagcopy(D::Diagonal) = copy(D.diag)with this, julia> oftype(D2,D1)
5×5 Diagonal{Float64, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}:
 1.0   ⋅    ⋅    ⋅    ⋅ 
  ⋅   2.0   ⋅    ⋅    ⋅ 
  ⋅    ⋅   3.0   ⋅    ⋅ 
  ⋅    ⋅    ⋅   4.0   ⋅ 
  ⋅    ⋅    ⋅    ⋅   5.0We may still want this, but let's be sure that it isn't for a quick fix. | 
| Maybe zero-step ranges could be returned as substitutions of  | 
| I think JuliaLang/julia#51475 may help with that | 
| 
 sort of. We need zero ranges with different lengths here. | 
| #1424 would offer an alternative to this. | 
The current implementation
diag(::Diagonal, k=0), for the sake of type stability, returns aVectoreven whenD.diagis lazy.This can cause bugs when one does want the result to be lazy: