-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Add allequal
#43354
Add allequal
#43354
Conversation
Adding to triage to decide if we want this. |
Very much in favor, and this was just on my todo list. This is a feature which is requested from time to time and easy to get wrong. For example, on a zulip thread, the OP thought |
I'm opposed to growing our exports for essentially trivial functions. |
I don't personally care whether
Of course the "users might implement it inefficiently" argument could be used for lots of different functions, so it's probably not a very strong argument. |
There are some errors in the CI tests. It seems like they're not related to the unit tests that I added, but I can't tell for sure. |
What about not exporting it, then? For me, |
Actually, there are scenarios where you might reasonably want julia> x = [missing, missing];
julia> all(isequal(first(x)), x)
true
julia> all(==(first(x)), x)
missing If you're looking to use three-valued logic, then you expect julia> y = [NaN, NaN];
julia> all(isequal(first(y)), y)
true
julia> all(==(first(y)), y)
false I used |
I should have have used |
slightly against, the justification for julia> @benchmark allunique(x) setup=(x = rand(1:10, 100))
BenchmarkTools.Trial: 10000 samples with 962 evaluations.
Range (min … max): 83.630 ns … 2.047 μs ┊ GC (min … max): 0.00% … 93.80%
Time (median): 102.137 ns ┊ GC (median): 0.00%
Time (mean ± σ): 118.439 ns ± 166.812 ns ┊ GC (mean ± σ): 12.62% ± 8.44%
▁▁▁▄▃▅▆█▅▆▄▂▁
▁▂▃▄▆█████████████▇▇▆▄▄▄▃▃▂▂▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▃
83.6 ns Histogram: frequency by time 171 ns <
Memory estimate: 400 bytes, allocs estimate: 4.
julia> @benchmark length(unique(x))==length(x) setup=(x = rand(1:10, 100))
BenchmarkTools.Trial: 10000 samples with 183 evaluations.
Range (min … max): 558.109 ns … 11.964 μs ┊ GC (min … max): 0.00% … 93.17%
Time (median): 592.109 ns ┊ GC (median): 0.00%
Time (mean ± σ): 632.985 ns ± 566.994 ns ┊ GC (mean ± σ): 5.22% ± 5.48%
▁▄▃▅▅██▆▄▃▂
▁▂▄████████████▆▅▄▄▃▂▂▂▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▃
558 ns Histogram: frequency by time 769 ns <
Memory estimate: 880 bytes, allocs estimate: 7.
|
Have certainly written naive versions of both of these quite a few times. It is tidy to have shared verbs so you don't have to invent a name, or figure out someone else's -- like Re timing
Edit: that's now #43375. |
Triage is in favor. Personally I like simple utilities like this that save you a bit of cognitive load, provided the meaning is really obvious which I think it is in this case. |
2f55060
to
eb1cb25
Compare
eb1cb25
to
837e9e9
Compare
I added a NEWS.md entry and updated the docstrings, including a compat entry for the |
@oscardssmith Can this be merged before the 1.8 deadline? |
LGTM |
If anyone is listening, this should be good to merge before the 1.8 deadline tomorrow. (I don't have merge rights.) |
Fixes #43353.