Questions related to -0.0 and 0.0

I’m using PCHIPInterpolation to do some interpolation.
itp = Interpolator(xs, ys);

This program absolutely does not allow any values in its x to be duplicates. I now have some values like the below in my data sets:
xs = [-5.0, -0.0, 0.0, 10.0, 19.0];

The interpolation would stop and give an error: “xs must be stricly increasing”. I tried to fix this issue by first using the unique function, but unique actually think they are different.

Is there a better way to address this issue?

See Is this a bug of the Julia function "unique"? - #29 by leon The next patch release of 1.6, and 1.7.0 will both fix this.

TLDR is that unique currently and incorrectly uses == instead of isequal

3 Likes

Thanks, Oscar. I started the other thread too :slight_smile:

I’m just hoping to find an alternative solution to address the issue, so that I don’t have to wait for the next version of Julia before I can process my data.

For the NaN issue. I have decided to fill it up with some identical numerical values to get it working.

you could always perform minor type piracy and redefine Base.unique to do the thing it will do as of the next release. It’s not a great solution, but it will work.

julia> xs = [-5.0, -0.0, 0.0, 10.0, 19.0];

julia> unique(t → t == 0 ? 0.0 : t, xs)
4-element Vector{Float64}:
-5.0
-0.0
10.0
19.0

1 Like

Thanks. Unfortunately, I got the below error when testing:

UndefVarError: t not defined
Stacktrace:
 [1] top-level scope
   @ In[129]:3
 [2] eval
   @ ./boot.jl:360 [inlined]
 [3] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
   @ Base ./loading.jl:1116

No need to wait, you can just use the 1.7 release candidate

1 Like

I think the JuliaMono font fooled my copy and paste. That arrow really should be ->.

1 Like

I don’t think that will solve @leon’s problem? Since isequal(0.0, -0.0) == false the values returned by unique will still include 0.0 and -0.0…

Actually if unique is currently using == I don’t understand why both are included in the result, since

julia> 0.0 == -0.0
true
1 Like

It is working now! Thank you so much.

BTW, is there a way I can find the index of the elements that remained? I have another set of data y that goes with the x.

Ind = …
y = y[Ind];