-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Removing requirement for promotions from 0,1 in lufact #22146
Conversation
Thanks for the PR! Could you perhaps also add a test that would fail before this PR? This is good so that this will keep working in the future. |
base/linalg/generic.jl
Outdated
@@ -957,7 +957,7 @@ true | |||
function istriu(A::AbstractMatrix) | |||
m, n = size(A) | |||
for j = 1:min(n,m-1), i = j+1:m | |||
if A[i,j] != 0 | |||
if A[i,j] != zero(eltype(A)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, !iszero(A[i,j])
should be preferred: It may avoid creation of a zero instance (e.g. for BigInt
) and furthermore, there are types T
for which zero(T)
is not defined although iszero(x::T)
is (e.g. matrices).
Applies again below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know about iszero
- it doesn't seem to be in the documentation.
But this is good. I will update it to use iszero
.
Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its new for the upcoming 0.6 release (#19950) so it is only in the latest docs: https://docs.julialang.org/en/latest/stdlib/numbers.html#Base.iszero
test/linalg/generic.jl
Outdated
@@ -310,3 +310,33 @@ end | |||
@test [[1, 2], [3, 4]] ≈ [[1.0-eps(), 2.0+eps()], [3.0+2eps(), 4.0-1e8eps()]] | |||
@test [[1, 2], [3, 4]] ≉ [[1.0-eps(), 2.0+eps()], [3.0+2eps(), 4.0-1e9eps()]] | |||
@test [[1,2, [3,4]], 5.0, [6im, [7.0, 8.0]]] ≈ [[1,2, [3,4]], 5.0, [6im, [7.0, 8.0]]] | |||
|
|||
# Issue 22042 | |||
# Minimal modulo number type - but not subclassing Number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps "subtyping" rather than "subclassing"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I knew I had the wrong word there! OK.
test/linalg/generic.jl
Outdated
|
||
Base.:+(a::ModInt{n}, b::ModInt{n}) where {n} = ModInt{n}(a.k+b.k) | ||
Base.:-(a::ModInt{n}, b::ModInt{n}) where {n} = ModInt{n}(a.k-b.k) | ||
Base.:*(a::ModInt{n}, b::ModInt{n}) where {n} = ModInt{n}(a.k*b.k) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces surrounding the operators might make these statements easier on wetware parsers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this what you mean?
Base.:+(a::ModInt{n}, b::ModInt{n}) where {n} = ModInt{n}(a.k + b.k)
(extra spaces around the infix +
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes :).
test/linalg/generic.jl
Outdated
|
||
# Needed for pivoting: | ||
Base.abs( a::ModInt{n} ) where {n} = a | ||
Base.:<( a::ModInt{n}, b::ModInt{n} ) where {n} = a.k < b.k |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps remove the extraneous spaces surrounding arguments in the method signatures?
test/linalg/generic.jl
Outdated
b = [ ModInt{2}(1), ModInt{2}(0) ] | ||
|
||
@test A * (A\b) == b | ||
@test_nowarn lufact( A, Val{true} ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra spaces here as well? :)
test/linalg/generic.jl
Outdated
# Issue 22042 | ||
# Minimal modulo number type - but not subclassing Number | ||
struct ModInt{n} | ||
k |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 space indent is the standard for this repo
A = [ ModInt{2}(1) ModInt{2}(0) ; ModInt{2}(1) ModInt{2}(1) ] | ||
b = [ ModInt{2}(1), ModInt{2}(0) ] | ||
|
||
@test A*(A\b) == b |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not actually call lufact
(since istril(A) == true
), wasn't that the purpose of this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is true that I haven't succeed in my original goal, but we are closer. If you make my test matrix not lower triangular, it fails! I think there needs to be a third option for pivoting - where the pivot is chosen by !iszero(..) and not by magnitude. Ultimately I'd like to be able to delete
Base.abs(a::ModInt{n}) where {n} = a
Base.:<(a::ModInt{n}, b::ModInt{n}) where {n} = a.k < b.k
from my test, but this requires a bigger discussion. One suggestion has been to have a symbol as the parameter value instead of the Bool pivot = true or false.
I'm not sure how to proceed - do I open up a new issue or PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
b = [ ModInt{2}(1), ModInt{2}(0) ] | ||
|
||
@test A*(A\b) == b | ||
@test_nowarn lufact( A, Val{true} ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This errored before this PR. Why test for warning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure of the correct way to handle this. It seemed strange to call the function and then return true, since the real test was the function call compiled and returned something successfully.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries :)
Issue JuliaLang/LinearAlgebra.jl#431