@matthijscox
Scientific Software Engineer
A scientific software developer with over a decade of experience in academia, startups and industry. My mission is to turn you into an elite numerical computing professional.
Nothing here yet.
Hi Wolf, not sure what you are testing. Note that the timing depends on how you test it. The any(x -> x < 3, numbers) might look slow if you use @time , but that's because the anonymous function keeps getting recompiled for every call. Maybe that's what you mean? You can easily bypass this by placing it inside another function. Also you can use BenchmarkTools.@btime instead to ignore the compilation time. julia> numbers = [ 1 , 2 , 3 , 4 , 5 ]; julia> @time any(x -> x < 3 , numbers) 0.006801 seconds ( 2.74 k allocations: 183.680 KiB, 99.01 % compilation time) true julia> @time any(numbers .< 3 ) 0.000012 seconds ( 3 allocations: 128 bytes) true julia> any_less(numbers, value) = any(x -> x < value, numbers) any_less (generic function with 1 method) julia> @time any_less(numbers, 3 ) # first call compiles the `any_less` 0.009657 seconds ( 6.90 k allocations: 456.047 KiB, 99.76 % compilation time) true julia> @time any_less(numbers, 3 ) # now it's fast 0.000005 seconds true But perhaps you are talking about something else?
After reading these discussions, I may have interpreted :compact in the wrong way, it's not intended for switching between single-line and multi-line displaying. Also the philosophy of the 2-argument show(io::IO, t::MyType) is that it always returns an expression that can be evaluated, kinda like the constructor. You do not want compact mode to accidentally switch it to a multi-line printing.
Found another summary of all show/print options, which will be added to the Julia docs: https://discourse.julialang.org/t/how-to-display-a-sparse-array-on-the-repl/113565/5 And this discussion: https://discourse.julialang.org/t/print-vs-two-argument-show-repr-vs-three-argument-show-repr-with-mime-text-plain/117790