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

Removing requirement for promotions from 0,1 in lufact #22146

Merged
merged 3 commits into from
Jun 2, 2017

Conversation

arghhhh
Copy link
Contributor

@arghhhh arghhhh commented May 30, 2017

@KristofferC
Copy link
Member

KristofferC commented May 30, 2017

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.

@ararslan ararslan added linear algebra Linear algebra needs tests Unit tests are required for this change labels May 30, 2017
@@ -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))
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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

@@ -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
Copy link
Member

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"?

Copy link
Contributor Author

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.


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)
Copy link
Member

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?

Copy link
Contributor Author

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 + )

Copy link
Member

Choose a reason for hiding this comment

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

Yes :).


# Needed for pivoting:
Base.abs( a::ModInt{n} ) where {n} = a
Base.:<( a::ModInt{n}, b::ModInt{n} ) where {n} = a.k < b.k
Copy link
Member

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?

b = [ ModInt{2}(1), ModInt{2}(0) ]

@test A * (A\b) == b
@test_nowarn lufact( A, Val{true} )
Copy link
Member

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? :)

# Issue 22042
# Minimal modulo number type - but not subclassing Number
struct ModInt{n}
k
Copy link
Contributor

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

@andreasnoack andreasnoack merged commit a692b2a into JuliaLang:master Jun 2, 2017
@tkelman tkelman removed the needs tests Unit tests are required for this change label Jun 2, 2017
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
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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} )
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

No worries :)

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.

8 participants