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

Add multiplication for RectDiagonal #107

Open
dlfivefifty opened this issue Jul 16, 2020 · 1 comment
Open

Add multiplication for RectDiagonal #107

dlfivefifty opened this issue Jul 16, 2020 · 1 comment

Comments

@dlfivefifty
Copy link
Member

This is inconsistent:

julia> 2Eye(10)
10×10 Diagonal{Float64,Fill{Float64,1,Tuple{Base.OneTo{Int64}}}}:
 2.0                                    
     2.0                                
         2.0                            
             2.0                        
                 2.0                    
                     2.0                
                         2.0            
                             2.0        
                                 2.0    
                                     2.0

julia> 2Eye(10,10)
10×10 Array{Float64,2}:
 2.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  2.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  2.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  2.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  2.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  2.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  2.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  2.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  2.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  2.0
@Wu-Chenyang
Copy link

Currently, scalar multiplication of RectDiagonal{<:Number,<:AbstractFill} results in RectDiagonal{<:Number,<:Vector}. For example,

julia> 2Eye(10,10)
2Eye(10,10)
10×10 FillArrays.RectDiagonal{Float64, Vector{Float64}, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}:
 2.0                                    
     2.0                                
         2.0                            
             2.0                        
                 2.0                    
                     2.0                
                         2.0            
                             2.0        
                                 2.0    
                                     2.0

This can be easily fixed by adding the following two methods:

Base.:*(a::FillArrays.RectDiagonal{<:Number, <:FillArrays.AbstractFill}, b::Number) = FillArrays.RectDiagonal(a.diag * b, a.axes)
Base.:*(a::Number, b::FillArrays.RectDiagonal{<:Number, <:FillArrays.AbstractFill}) = FillArrays.RectDiagonal(a * b.diag, b.axes)

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

2 participants