Skip to content

Conversation

@mkitti
Copy link
Member

@mkitti mkitti commented May 10, 2024

This pull request adds more tests including randomly generated ChainVectors of Int, Float64, and Rational, incorporates #98 .

Functions fixed

  • argmin (Already fixed)
  • argmax
  • findmin (Already fixed)
  • findmax
  • findXwithfirst

Fixed #101

@mkitti mkitti mentioned this pull request May 10, 2024
@Seelengrab
Copy link

Ah yes, the inconsistency of argmax(x) vs argmax(foo, x) strikes again... I'll have to get around to rebasing JuliaLang/julia#41339

@mkitti mkitti changed the title Expanding testing Expanding testing, fix argmin, argmax, findmin, findmax, findXwithfirst May 10, 2024
@mkitti mkitti marked this pull request as ready for review May 10, 2024 08:41
@codecov
Copy link

codecov bot commented Jun 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.73%. Comparing base (fa840f9) to head (3a6f915).
Report is 4 commits behind head on main.

Current head 3a6f915 differs from pull request most recent head 750cb8f

Please upload reports for the commit 750cb8f to get more accurate results.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #99      +/-   ##
==========================================
- Coverage   94.82%   94.73%   -0.10%     
==========================================
  Files           5        5              
  Lines        1043     1044       +1     
==========================================
  Hits          989      989              
- Misses         54       55       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

mkitti and others added 2 commits June 8, 2024 10:53
Co-authored-by: Milan Bouchet-Valat <nalimilan@club.fr>
@mkitti mkitti changed the title Expanding testing, fix argmin, argmax, findmin, findmax, findXwithfirst Fix argmax, findmax, findXwithfirst, and expand testing Jun 16, 2024

# Pairs of test vectors
# Some were inspired by https://github.com/JuliaData/SentinelArrays.jl/issues/97
int_vectors = [
Copy link

Choose a reason for hiding this comment

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

Instead of a hard-coded set of test vectors, could a few 1000 be generated when the test runs? That might catch a few more edge cases.

Also, I think it would be clearer to only test Int here, to avoid NaN and floating point rounding.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that is part of @Seelengrab 's Supposition.jl is supposed to do. I'm just trying to get this pull request through before I start messing with adding test dependencies, but we seem to be stuck here.

@mkitti
Copy link
Member Author

mkitti commented Jun 16, 2024

With == the failing tests in eee286e are

  (x, y) = ([-8.5, -1.2, -3.8, 7.5, 8.2, 7.5, -5.3, -2.7, 0.6, -6.2, 6.1, 1.4], [-8.5, -1.2, -3.8, 7.5, 8.2, 7.5, -5.3, -2.7, 0.6, -6.2, 6.1, 1.4])                                                                                                                                                           |   32     1     33  1.3s
  (x, y) = ([-7.2, 8.1, 2.3, 7.5, -8.4, -5.7], [-7.2, 8.1, 2.3, 7.5, -8.4, -5.7])                                                                                                                                                                                                                             |   32     1     33  0.0s
  (x, y) = ([-3.7, 7.8, -5.0, 0.1, 5.0, -4.1, -1.6, -0.9, 8.7, -7.8], [-3.7, 7.8, -5.0, 0.1, 5.0, -4.1, -1.6, -0.9, 8.7, -7.8])                                                                                                                                                                               |   32     1     33  0.0s
  (x, y) = ([8.6, -2.0, 8.0, 3.4, 3.3, 1.0, 5.4, -2.6, -4.7, 4.4, 4.4, 7.9], [8.6, -2.0, 8.0, 3.4, 3.3, 1.0, 5.4, -2.6, -4.7, 4.4, 4.4, 7.9])                                                                                                                                                                 |   32     1     33  0.0s
  (x, y) = ([7.6, 5.9, 7.9, -8.8, -1.5, -0.4, 6.0, -5.1, -0.4, 4.4, 7.3], [7.6, 5.9, 7.9, -8.8, -1.5, -0.4, 6.0, -5.1, -0.4, 4.4, 7.3])                                                                                                                                                                       |   32     1     33  0.0s
  (x, y) = ([3.2, -3.2, 1.2, -1.2, -2.1, 0.5, 6.2, 2.9, -8.1, 5.8, 4.8, -3.4, -3.1], [3.2, -3.2, 1.2, -1.2, -2.1, 0.5, 6.2, 2.9, -8.1, 5.8, 4.8, -3.4, -3.1])                                                                                                                                                 |   32     1     33  0.0s
  (x, y) = ([-7.5, -1.5, -5.8, 8.4, -8.4, -1.9, 2.3, -0.8, -8.5, 0.2, 0.5, -7.4, 2.1, -3.9], [-7.5, -1.5, -5.8, 8.4, -8.4, -1.9, 2.3, -0.8, -8.5, 0.2, 0.5, -7.4, 2.1, -3.9])                                                                                                                                 |   32     1     33  0.0s

@mkitti
Copy link
Member Author

mkitti commented Jun 16, 2024

Wait... why is sum failing?

y = ChainedVector([[-8.5, -1.2, -3.8, 7.5], [8.2, 7.5, -5.3], [-2.7, 0.6, -6.2, 6.1, 1.4]])
x = collect(y)

julia> sum(y) == sum(x)
false

Should mapreduce be defined like this?

Base.mapreduce(f::F, op::OP, x::ChainedVector) where {F, OP} = reduce(op, (mapreduce(f, op, y) for y in x.arrays))

Why not just use Iterators.flatten?

julia> Base.mapreduce(f::F, op::OP, x::ChainedVector) where {F, OP} = mapreduce(f, op, Iterators.flatten(x.arrays))

julia> sum(y) == sum(x)
true

Copy link

@nhz2 nhz2 left a comment

Choose a reason for hiding this comment

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

These changes look good. I think sum is allowed to perform the reduction in any order, so it's fine if it is only approximately equal.

@mkitti
Copy link
Member Author

mkitti commented Jun 16, 2024

Currently thinking about

       function Base.mapreduce(f::F, op::OP, x::ChainedVector) where {F, OP}
           init = mapreduce(f, op, first(x.arrays))
           foreach(@view x.arrays[begin+1:end]) do a
               init = mapreduce(f, op, a; init)
           end
           return init
       end

This may be another pull request though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

findmax is broken for repeated values

6 participants