-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
Matrix identity not calling one() ? #659
Comments
|
Thank but it was not a discourse question, what you said prooved me it's a bug (in the way not mathematicaly consistent). As I said A is created with zero() which is correct. But s.λ was not init with one(T) therefore it does not contain the correct value: s.λ shall be one(MP{Float64}) = 0.0 = false. Look: julia> UniformScaling{MP{Float64}}(one(MP{Float64}))
UniformScaling{MP{Float64}}
0.0*I and the doc says: |
PS: May I rephrase to be clear. When you said
But I disagree when:
|
@fredrikekre, @andreasnoack I'm sorry to disturb you again (this will be my last comment, up to you to take into account) but reading a little more the code and comments I comfort myself that: https://github.com/JuliaLang/julia/blob/cd16f6e74cdb23f9986a387aef29b2f0631f5653/stdlib/LinearAlgebra/src/uniformscaling.jl#L49 is not good idea. By the way: codes I know max-plus algebra is disturbing: we can confuse between MP(1) = 1 (coming from MP(true)) and one() = MP(zero(T)) = 0 named %1 which is neutral for operators + and * in this algebra. But also zero() = MP(typemin(T)) = -Inf named %0 neutral for opertor+. So ideally it should be # Copy constructor
MP{T}(x::MP) where T = MP{T}(x.val)
# and similar to uniformscaling.jl:
const J=UniformScaling(one(MP{Float64}))
# Now working
Matrix{MP{Float64}}(J, 2,2)
2×2 Array{MP{Float64},2}:
0.0 -Inf
-Inf 0.0 My idea would be: is it not possible to change Thx! |
It’s unclear what your objection is here. Can you clarify what the actual problem is? |
We’re fairly familiar with unusual algebras like max-plus: https://dspace.mit.edu/bitstream/handle/1721.1/115964/JuliaSemiring_HPEC2013_Paper%281%29.pdf |
The inconsistency is that in It might not be @Lecrapouille's preferred solution but it would be more consistent. Notice, that you are actually telling Julia to convert
The docs you are reading must be for a more recent version of Julia. The operations were only introduced in the just released version 1.2. |
Alternatively, |
@StefanKarpinski ok I try to clarify Identity matrices for max-plus (for example the case of a 2x2 matrix) are:
Julia 0.4.7, But Julia >= 1.03 (>= 0.7 ?) returns an incorrect answer:
So this is clearly a regression. From an algebra point of view:
And with your API:
In the current Julia implementation zero(T) are called correctly but one(T) is not called correctly. Thanks to @fredrikekre who gave me the line of code which looks incorrect to me (still point of view of the algebra):
Now, let suppose to replace it by:
Unfortunatly, this line does not compile because of missing T. But just let suppose it compiles. For boolean: So finally the code:
will produce for Bool, Int, Float correct values: For @andreasnoack, @fredrikekre concerning your proposal of fixes concerning:
@fredrikekre @andreasnoack My proposalI.λ shall contain the correct value and therefore init with one(T) of the correct type. Using Bool by default is not good. So the problem is how to write a compilable version of Anyway the fix for my case is the follow code:
|
Close since this code is fixing it:
|
Hi, I'm trying to implement the max-plus semiring algebra in Julia 1.0.3 like the follow code:
The following code gives the expected behavior :
But the following code does not gives the expected behavior :
What I was expected:
I think
Matrix{MP{Float64}}(I, 2, 2)
creates a matrix initialized byBase.zero(MP{Float64})
callingMP(typemin(Float64))
giving-Inf
but theI
does not create the diagonal initialized byone(MP{Float64})
which would calledMP(zero(Float64))
giving 0.0.I followed this link JuliaLang/julia#30298 so fortunatly I can fix by writting code like this:
Is it because
I
useBool
that I have this behavior ? And how to replace code0I
byone(MP{Float64})I
? I really think that Julia shall implementI
callingone()
and without giving Type::T callsone(Bool)
.I'm starting learning julia! Thx!
The text was updated successfully, but these errors were encountered: