Conversation
this isn't directly related to all and isn't a composition, especially for collections of collections
R also has a `duplicated` function where `anyduplicated` is equivalent to the composition `any(duplicated(x))`
|
I also tried to point out that there is a further issue with #15914: >> r = linspace(1.0, nextfloat(1.0), 10)
>> allunique(r)
true
>> allunique(collect(r))
falseIs this not a problem? |
|
That might be an issue. Any suggestions for how to fix it? That doesn't really have a bearing on what to name it though. |
|
You're right about that last point, but I see you did some code changes too, I thought I might bring it up. I don't know if this is iron clad, since I haven't thought of many tests, but: function hasduplicates{T<:AbstractFloat}(r::Range{T})
if step(r) == 0
return length(r) > 1
elseif step(r) > 0
return last(r) < nextfloat(first(r), length(r) - 1)
else
return last(r) > nextfloat(first(r), -length(r) + 1)
end
endI'm not sure what happens when you have weird steps like for >> r = linspace(1,2,0)
linspace(1.0,2.0,0)
>> step(r)
NaN
Furthermore, I wonder whether it shouldn't be |
|
Hmm, maybe this should cover it for floats? function hasduplicates{T<:AbstractFloat}(r::Range{T})
length(r) <= 1 && return false
step(r) == 0 && return true
r_ = nextfloat(first(r), flipsign(length(r)-1, step(r)))
return flipsign(last(r) - r_, step(r)) < 0
end |
|
Tests should include !hasduplicates(linspace(1.0, nextfloat(1.0), 2))
hasduplicates(linspace(1.0, nextfloat(1.0, 1), 3))
!hasduplicates(linspace(1.0, nextfloat(1.0, -10), 11))
hasduplicates(linspace(1.0, nextfloat(1.0, -10), 12))
!hasduplicates(linspace(1.0, 1.0, 0))The last one has step() = NaN, which might conceivably trip up some implementations. |
|
Here's another one that fails with the current code, but works with the one I suggested: |
|
Hmmm. This one fails, though: There are some pretty hairy edge cases with |
|
Why not, if that would be a more efficient version of a (possible) any(duplicated(x)). @okvs I think you should open a separate issue, that's a complex enough problem. |
|
It seemed like a pretty easy fix, when the code was being changed anyway. But now it looks like a rabbit hole, I think it even touches on some problems with |
|
With this proposal, to determine whether a collection consists entirely of unique elements you need Personally I prefer |
|
Yes this would be flipping the sense in addition to the different name. Sounds like there are 3 against, 2 or maybe 3 for this. I dislike having that "all" in the name, but not enough people spoke up here with a straight +1 or -1 for it to be conclusive one way or the other. |
ref #15803 and #15914 -
alluniqueseems to me like it implies compositionall(unique(x))which isn't what this does, theanyduplicatedname has precedent in R (where it is doing composition, we don't have aduplicatedfunction in Julia right now but we conceivably could).(I don't think this has been on master under its current name for long enough to warrant a deprecation)