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

filter alters input values in arrays #33974

Closed
jtackm opened this issue Nov 28, 2019 · 5 comments · Fixed by #34005
Closed

filter alters input values in arrays #33974

jtackm opened this issue Nov 28, 2019 · 5 comments · Fixed by #34005
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@jtackm
Copy link

jtackm commented Nov 28, 2019

Under julia 1.3, filter produces wrong output in the following example (see the tail of vals_filt):

n = 12000000
k = 257000000
vals = vcat(fill(0.5, n), fill(NaN, k))
vals_filt = filter(x -> x[2] < 1.0, collect(enumerate(vals)))

[Out]:
12000000-element Array{Tuple{Int64,Float64},1}:
 (1, 0.5) 
 (2, 0.5) 
 (3, 0.5) 
 (4, 0.5) 
 (5, 0.5) 
 (6, 0.5) 
 (7, 0.5) 
 (8, 0.5) 
 (9, 0.5) 
 (10, 0.5)
 (11, 0.5)
 (12, 0.5)
 (13, 0.5)
         
 (0, 0.0) 
 (0, 0.0) 
 (0, 0.0) 
 (0, 0.0) 
 (0, 0.0) 
 (0, 0.0) 
 (0, 0.0) 
 (0, 0.0) 
 (0, 0.0) 
 (0, 0.0) 
 (0, 0.0) 
 (0, 0.0) 

In contrast, the equivalent

vals_filt_lc = [x for x in collect(enumerate(vals)) if x[2] < 1.0]

[Out]:
12000000-element Array{Tuple{Int64,Float64},1}:
 (1, 0.5)       
 (2, 0.5)       
 (3, 0.5)       
 (4, 0.5)       
 (5, 0.5)       
 (6, 0.5)       
 (7, 0.5)       
 (8, 0.5)       
 (9, 0.5)       
 (10, 0.5)      
 (11, 0.5)      
 (12, 0.5)      
 (13, 0.5)      
               
 (11999989, 0.5)
 (11999990, 0.5)
 (11999991, 0.5)
 (11999992, 0.5)
 (11999993, 0.5)
 (11999994, 0.5)
 (11999995, 0.5)
 (11999996, 0.5)
 (11999997, 0.5)
 (11999998, 0.5)
 (11999999, 0.5)
 (12000000, 0.5)

works correctly.

Versioninfo (path information manually removed):

Julia Version 1.3.0
Commit 46ce4d7933 (2019-11-26 06:09 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU E7- 4870  @ 2.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, westmere)
Environment:
  JULIA_PKGDIR = <removed>
  JULIA_WORKER_TIMEOUT = 3600
  JULIA_HOME = <removed>
  JULIA_NUM_THREADS = 40

If I do any of the following, the bug disappears:

  • replace the NaNs with regular floats
  • reduce the input array size, e.g. by setting n to 11000000 and/or k to 256000000
  • run the code on julia 1.2
@KristofferC
Copy link
Member

KristofferC commented Nov 28, 2019

Something with #31929 maybe?

@KristofferC
Copy link
Member

KristofferC commented Nov 28, 2019

It has something to do with the sizehint! at

sizehint!(b, length(b))

Before the sizehint the 6 last elements are

6-element Array{Tuple{Int64,Float64},1}:
 (11999995, 0.5)
 (11999996, 0.5)
 (11999997, 0.5)
 (11999998, 0.5)
 (11999999, 0.5)
 (12000000, 0.5)

after

6-element Array{Tuple{Int64,Float64},1}:
 (0, 0.0)
 (0, 0.0)
 (0, 0.0)
 (0, 0.0)
 (0, 0.0)
 (0, 0.0)

Could it be something with #26201?

@KristofferC KristofferC added the bug Indicates an unexpected problem or unintended behavior label Nov 28, 2019
@KristofferC KristofferC changed the title filter alters input values in arrays with NaNs filter alters input values in arrays Nov 28, 2019
@KristofferC
Copy link
Member

The NaN is a red herring

vals = vcat(fill(0.5, n), fill(1.5, k))

has the same bug

@jtackm
Copy link
Author

jtackm commented Nov 28, 2019

I see, in my testing I replaced NaNs with a value that satisfied the predicate. Thanks for having a look!

@KristofferC
Copy link
Member

KristofferC commented Nov 28, 2019

Reverting #26201 does fix it. (which perhaps isn't so strange since it basically turns it into a noop for this case)

@JeffBezanson JeffBezanson self-assigned this Dec 2, 2019
KristofferC pushed a commit that referenced this issue Dec 3, 2019
fredrikekre pushed a commit that referenced this issue Dec 3, 2019
KristofferC pushed a commit that referenced this issue Dec 4, 2019
fredrikekre pushed a commit that referenced this issue Dec 11, 2019
vtjnash pushed a commit that referenced this issue Oct 29, 2020
Implement shrinking of small arrays

Refs #33974, #26201, #2879
Fixes #33902
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants