Skip to content

adding == for structured matrices (split off of #29724) #30108

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

Merged
merged 1 commit into from
Dec 11, 2018

Conversation

mcognetta
Copy link
Contributor

This is the completed half of #29724

The logic I implemented in #29724 is flawed for isapprox and several new methods (specifically norms) need to be implemented. This PR contains just the exact equality code for structured matrices. It also includes a bug fix for comparing two Bidiagonal matrices when they have different uplo, which shouldn't be held up by the other PR.

The Bidiagonal bug:

julia> x = rand(3)
3-element Array{Float64,1}:
 0.7279081769922535
 0.8949580887222155
 0.7781661021218007

julia> Bu = Bidiagonal(x, zeros(2), 'U')
3×3 Bidiagonal{Float64,Array{Float64,1}}:
 0.727908  0.0        ⋅      
  ⋅        0.894958  0.0     
  ⋅         ⋅        0.778166

julia> Bl = Bidiagonal(x, zeros(2), 'L')
3×3 Bidiagonal{Float64,Array{Float64,1}}:
 0.727908   ⋅         ⋅      
 0.0       0.894958   ⋅      
  ⋅        0.0       0.778166

julia> Bu == Bl
false

julia> Matrix(Bu) == Matrix(Bl)
true

This PR

julia> x = rand(3)
3-element Array{Float64,1}:
 0.3172029052612273 
 0.8635761133663176 
 0.17013855660697486

julia> Bu = Bidiagonal(x, zeros(2), 'U')
3×3 Bidiagonal{Float64,Array{Float64,1}}:
 0.317203  0.0        ⋅      
  ⋅        0.863576  0.0     
  ⋅         ⋅        0.170139

julia> Bl = Bidiagonal(x, zeros(2), 'L')
3×3 Bidiagonal{Float64,Array{Float64,1}}:
 0.317203   ⋅         ⋅      
 0.0       0.863576   ⋅      
  ⋅        0.0       0.170139

julia> Bu == Bl
true

julia> Matrix(Bu) == Matrix(Bl)
true

Some timings (these are pessimal cases):
v1.0

julia> D=Diagonal(zeros(1000));B=Bidiagonal(zeros(1000), zeros(999), 'U');T=Tridiagonal(zeros(999), zeros(1000), zeros(999))

julia> @time D == B
  0.636254 seconds (4 allocations: 160 bytes)
true

julia> @time D == T
  0.008160 seconds (4 allocations: 160 bytes)
true

julia> @time B == T
  0.629008 seconds (4 allocations: 160 bytes)
true

This PR

julia> D=Diagonal(zeros(1000));B=Bidiagonal(zeros(1000), zeros(999), 'U');T=Tridiagonal(zeros(999), zeros(1000), zeros(999))

julia> @time D == B
  0.000007 seconds (4 allocations: 160 bytes)
true

julia> @time D == T
  0.000005 seconds (4 allocations: 160 bytes)
true

julia> @time B == T
  0.000012 seconds (4 allocations: 160 bytes)
true

@mcognetta
Copy link
Contributor Author

The CI failure seems erroneous. Also, should this be back ported since the Bidiagonal bug appears in 1.0 and previous versions?

@StefanKarpinski
Copy link
Member

I've restarted the macOS CI run.

@fredrikekre
Copy link
Member

I've restarted the macOS CI run.

#30111

@StefanKarpinski
Copy link
Member

Yeah, I hadn't seen that it was a repeat issue at this point. At least it fails fast.

@andreasnoack andreasnoack merged commit 2460301 into JuliaLang:master Dec 11, 2018
KristofferC pushed a commit that referenced this pull request Dec 12, 2018
@KristofferC KristofferC mentioned this pull request Dec 12, 2018
52 tasks
@mcognetta mcognetta deleted the add_structured_equals branch November 19, 2024 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linear algebra Linear algebra performance Must go faster
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants