Comments (6)
mmh, ok but maybe returning nothing
could a bit better anyway? It would be easy in this case
function iterate(r::OrdinalRange{T}, i) where {T}
@inline
i >= last(r) && return nothing # >= instead of ==
next = convert(T, i + step(r))
(next, next)
end
from julia.
What iterate
does after nothing
has been returned is more or less arbitrary.
from julia.
I think that anyway the docstring should say that in this case the returned value is arbitrary
from julia.
Actually the previous implementation wasn't totally correct because of decreasing ranges, this would return nothing
whenever the state is outside the range:
function iterate(r::OrdinalRange{T}, i) where {T}
@inline
rf, rl = first(r), last(r)
rf < rl && (i < rf || i >= rl) && return nothing
rf >= rl && (i <= rl || i > rf) && return nothing
next = convert(T, i + step(r))
(next, next)
end
I would have assumed that this is more costly and so probably not worth it but I see on 1.10 and 1.11 this:
julia> function f(x)
s = 0
for i in 1:x
s += rand() < 0.5 ? 1 : 2
end
end
f (generic function with 1 method)
julia> @btime f(1000) # before
581.742 ns (0 allocations: 0 bytes)
julia> @btime f(1000) # after
489.426 ns (0 allocations: 0 bytes)
which indicates the opposite, does someone know why?
from julia.
ok sorry I wasn't returning s
, now I see same performance
from julia.
but it is fighting a losing battle trying to make this safer without compromising performance, e.g. still a step greater than 1 should be taken care of
from julia.
Related Issues (20)
- push!, append! AbstractVector implementations no longer work on Julia 1.11+
- 'make test' fails for julia-1.11.0-rc2 HOT 2
- `JULIA_NUM_THREADS` ignored when embedding Julia on a Windows system HOT 1
- Segmentation fault in Hermitian `eigen`/`eigvals` on nightly HOT 30
- Add ErrorHints stdlib HOT 5
- Load stdlib JLLs by path
- Consider dropping bfloat16 demotion pass HOT 1
- "Inferrable" `stdin` for use with trimmed programs
- `@test`'s use of kwargs is confusing and limits extensibility HOT 1
- Julia fails to build on a clean system due to memory error (in curl?) HOT 5
- Allow uplo='F' for Symmetric and Hermitian wrappers? HOT 2
- Shipped Windows binaries with new codesigning need `.ji` checksums updated HOT 3
- Emit OSC 9;9 escape sequences on Windows HOT 1
- Ambiguous behavior of Tuple constructor with mismatched array length HOT 2
- RetentionParameterEstimator hits incorrect assert in emit_masked_bits_compare
- Monorepo Packages via Submodules/Subpackages: Support in Pkg and Julia Compiler HOT 14
- Circular dependency detected for Symbolics.jl on Julia 1.11.0-rc2 HOT 6
- [REPL] Autocompletion of `ModuleName.@macro_name` is broken
- [REPL] Autocompletion of `@benchmark A .= A setup=(A=` is broken
- Deadlock doing I/O on a foreign thread while the main thread is blocked HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from julia.