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

Make getindex for Bidiagonal O(1) in the worst-case #32329

Merged
merged 1 commit into from
Jul 6, 2019

Conversation

mcognetta
Copy link
Contributor

@mcognetta mcognetta commented Jun 15, 2019

This is similar to #32328, but I separated them since that is a bug fix and this is just an edge case optimization.

In the worst case, getindex for Bidiagonal matrices is O(n). This PR makes it O(1).

The worst case is a Bidiagonal where the off diagonal is zero. In the worst case, iszero (which is O(n)) is called twice (once in istriu and once in istril).

This only really comes into play for large matrices, but this pr doesn't slow down getindex for small matrices, so it seems like a net win.


Here are some timings:

Master:

julia> B = Bidiagonal(rand(100000), zeros(99999), 'U')

julia> @time B[100000, 99999]
  0.000379 seconds (5 allocations: 176 bytes)
0.0

julia> @time B[99999, 100000]
  0.000008 seconds (5 allocations: 176 bytes)
0.0

This PR:

julia> B = Bidiagonal(rand(100000), zeros(99999), 'U')

julia> @time B[99999, 100000]
  0.000003 seconds (5 allocations: 176 bytes)
0.0

julia> @time B[100000, 99999]
  0.000007 seconds (5 allocations: 176 bytes)
0.0

@mcognetta
Copy link
Contributor Author

CI Failure seem unrelated to this PR. Same with #32328

Copy link
Member

@dkarrasch dkarrasch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is how it should be.

@mcognetta
Copy link
Contributor Author

Bump (and #32328)

@StefanKarpinski StefanKarpinski merged commit 1261a25 into JuliaLang:master Jul 6, 2019
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

Successfully merging this pull request may close these issues.

3 participants