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)
- `checked_rem` and `checked_mod` don't follow the same promotion rules as regular rem and mod
- `@doc` (`MD` object) doesn't print with horizontal bars between methods, which can mislead the reader.
- support syntax `macro OtherPackage.theirmacro(args...) ... end`
- Feature request: Non allocating sort for tuple HOT 1
- suboptimal return type inference for `reverse(::Tuple)` on v1.11 and master HOT 3
- Multi index `Base.setindex` HOT 6
- Remove `Dates.value(::Date)` HOT 1
- `escape_string` doesn't appear to be able to keep double-quotes. HOT 5
- infinite loop in C code when trying to add a method HOT 7
- Regression: Eigenvalue computation returns empty results for large symmetric matrices in Julia 1.11.0-beta1 HOT 4
- Fuzzy search in MethodError for incorrect keyword arguments
- The AllocOptPass is potentially slow (and runs too often) in some cases HOT 3
- Huge virtual memory usage on Windows HOT 5
- Lacking document of `:` on docs.julialang.org HOT 1
- `Base.MainInclude` regressions in v1.11, `eval` and `include` HOT 1
- Broken linkerscript, julia fails to link with modern lld versions HOT 2
- Documentation bug: `MainInclude`
- Confusing error when defining a method within nested testsets
- [FEATURE] Using Right Arrow Key to Auto Complete Virtual Text?
- should matrix-vector mul! also protect against aliasing? HOT 2
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.