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 findmin/findmax behavior match min/max (fix #23209) #23227

Merged
merged 15 commits into from
Aug 31, 2017
Merged

make findmin/findmax behavior match min/max (fix #23209) #23227

merged 15 commits into from
Aug 31, 2017

Conversation

KlausC
Copy link
Contributor

@KlausC KlausC commented Aug 12, 2017

url: #23209

Same issue for sparse matrices not yet included - will follow.

ai, s = next(a, s)
i += 1
ai != ai && continue # assume x != x => x is a NaN
if m != m || isless(m, ai)
if ai != ai || isless(m, ai)
Copy link
Member

Choose a reason for hiding this comment

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

In the ai != ai case this can short-circuit, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if ai != ai I expect isless is not called. That shall cover the NaN- case. This can occur at most once, since the next loop circle is broken by the m != m condition few lines before.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, yes, I didn't notice the m != m && break check previously.


zero2(t::Type) = zero(t)
zero2(::Type{T}) where T<:Number = zero(T)
zero2(::Type{T}) where T<:AbstractString = ""
Copy link
Contributor

Choose a reason for hiding this comment

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

requiring this is a bit of a red flag, is there any way to avoid needing this?

Copy link
Member

Choose a reason for hiding this comment

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

The way is not to rely on zero behavior at all, but to use the first slice as the start value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

let me improve this!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The definition of zero2 will be removed in the next commit, it is not required any longer.
I guess the red flag is risen, because a bug fix shall not introduce new Base features?

Copy link
Member

Choose a reason for hiding this comment

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

As long as this isn't exported, it's not a feature addition. It just seems fishy to need a function like zero but for which "" is the answer for strings. (Nevermind that "" is a reasonable 1 value for strings; there is no zero value unless you embed strings into regular patterns, in which case the empty pattern is the zero value – but it's not a string.)

@rfourquet rfourquet changed the title make fmin/fmax behavior match min/max (fix #23209) make findmin/findmax behavior match min/max (fix #23209) Aug 16, 2017
@KlausC
Copy link
Contributor Author

KlausC commented Aug 16, 2017

Tests failed because of buggy _findz in sparse/sparsematrix.jl:1831. Will investigate with @inboundsremoved.

@@ -3,6 +3,10 @@
# Run the distributed test outside of the main driver since it needs its own
# set of dedicated workers.

using Base.Test

@test open("distributed_exec.jl") do io; true end
Copy link
Contributor

Choose a reason for hiding this comment

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

what happened here, how is this related?

@KlausC
Copy link
Contributor Author

KlausC commented Aug 17, 2017

This change is not related to the issue to solve. All test runs on the ci platforms errored during the Base.runtest("all") at distributed with "no tests found". Therefore I thought it worth to make this modification, just to see, if my own tests would finish.
Probably I have a wrong understanding of the work-flow. Maybe you can help me out.

@tkelman
Copy link
Contributor

tkelman commented Aug 17, 2017

The "No tests" is a consequence of #20362, not related. The failure was actually in offsetarray, but we seem to be having a problem in our testsystem right now where it isn't showing the actual backtrace of failures. It might work better if you run locally and only do make test-offsetarray, when it's running only a single test file the execution is a little less complicated.

@KlausC
Copy link
Contributor Author

KlausC commented Aug 19, 2017

Fix complete. Please review.

((2,), reshape([6.0,5.0], 2, 1), reshape([5,2], 2, 1)),
((1,2), fill(6.0,1,1),fill(5,1,1))]
@test findmax(A, tup) == (rval, rind)
@test findmax!(similar(rval), similar(rind), A) == (rval, rind)
@test string(maximum(A, tup)) == string(rval)
Copy link
Contributor

Choose a reason for hiding this comment

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

why are you comparing all of these as strings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The comparisons using == do not work, when the result collections contain NaN, because NaN != NaN. Comparison with === does not compare array elements.
And I wanted to be able to identify the failed tests by the test values. With a specialized compare function that was not the case ( @test eq1(maximum(A, tup), rval) prints its line literally).

Copy link
Member

Choose a reason for hiding this comment

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

Can't you use isequal for these cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I did it. Actually it revealed some differences between Array{T,2} 2x1 and Array{T,1} with equal contents.

@KlausC
Copy link
Contributor Author

KlausC commented Aug 24, 2017

Are there more changes to do for this fix?

@mbauman mbauman added needs news A NEWS entry is required for this change breaking This change will break code arrays [a, r, r, a, y, s] labels Aug 24, 2017
@mbauman
Copy link
Member

mbauman commented Aug 24, 2017

Very nice work! This is definitely needed. I took the liberty of removing the unrelated change in tests/distributed.jl. My only question is if we want to deprecate this behavior first. It's a little tricky (especially in the case of all-nan elements), but I think it should be doable.

@StefanKarpinski StefanKarpinski added this to the 1.0 milestone Aug 24, 2017
@KlausC
Copy link
Contributor Author

KlausC commented Aug 26, 2017

Is there anything, I should or could do about that question?

@StefanKarpinski
Copy link
Member

Your call @mbauman – I'm not sure if it's worth it, but if you think so, go for it.

@mbauman mbauman removed the needs news A NEWS entry is required for this change label Aug 28, 2017
[ci skip]
@mbauman
Copy link
Member

mbauman commented Aug 28, 2017

On balance, I think we should just leave this as a breaking change. I've added a NEWS.md bullet point.

@StefanKarpinski StefanKarpinski merged commit 6210e24 into JuliaLang:master Aug 31, 2017
@StefanKarpinski
Copy link
Member

Thank you so much @KlausC for seeing this through!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s] breaking This change will break code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants