Skip to content

Conversation

ThatcherT
Copy link
Contributor

@ThatcherT ThatcherT commented Jul 18, 2021

This is my first contribution! I've made an effort to follow the instructions given in CONTRIBUTING.md. I added a test to show what was breaking before this fix.

Fixes #25516.

@dkarrasch
Copy link
Member

Thanks @ThatcherT, and welcome to the Julia community. Could you please add another test that returns true (when it should) for a non-strided array?

@dkarrasch dkarrasch added the linear algebra Linear algebra label Jul 19, 2021
@ThatcherT
Copy link
Contributor Author

Thanks for the feedback! I will implement. @dkarrasch

@ThatcherT
Copy link
Contributor Author

@dkarrasch I added a positive test for a non-strided array.

test/numbers.jl Outdated
@test !isone(zeros(Int, 5, 5))
@test isone(Matrix(1I, 5, 5))
@test !isone(view(rand(5,5), [1,3,4], :))
@test isone(view(Diagonal([1,1, 1]), [1,2], 1:2))
Copy link
Member

Choose a reason for hiding this comment

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

It appears that this was working before, but it was doing effectively x == one(x), which created a whole dense copy in memory. So the new feature with this PR is that in most cases (except for things like AbstractQ from the qrs) the isone-check is now allocation-free. So we should actually test that as well:

Suggested change
@test isone(view(Diagonal([1,1, 1]), [1,2], 1:2))
Dv = view(Diagonal([1,1, 1]), [1,2], 1:2)
@test isone(Dv)
@test (@allocated isone(Dv)) == 0

The last test fails currently.

@ThatcherT
Copy link
Contributor Author

ThatcherT commented Jul 22, 2021

I've implemented the changes you suggested, including asserting isone is now allocation-free. @dkarrasch

@dkarrasch
Copy link
Member

Sorry for the delay. Thank you for your contribution!

@dkarrasch dkarrasch merged commit d245c68 into JuliaLang:master Jul 30, 2021
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.

isone(A) throws error when A is not a StridedMatrix
2 participants