-
Notifications
You must be signed in to change notification settings - Fork 32
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
#121 - Replace 'IterTools.product' -> 'Iterators.product' #519
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in 0.7,
julia> using LazySets
[ Info: Recompiling stale cache file /Users/mforets/.julia/compiled/v0.7/LazySets/NjrGc.ji for LazySets [b4f0291d-fe17-52bc-9479-3d1a343d9043]
julia> H2 = Hyperrectangle(rand(2), rand(2))
Hyperrectangle{Float64}([0.11199, 0.300178], [0.726638, 0.382507])
julia> vertices_list(H2)
ERROR: MethodError: no method matching Array{Array{Float64,1},1}(::Array{Array{Float64,1},2})
Closest candidates are:
Array{Array{Float64,1},1}(::AbstractArray{S,N}) where {T, N, S} at array.jl:497
Array{Array{Float64,1},1}(::Any) where T<:AbstractArray at abstractarray.jl:22
Array{Array{Float64,1},1}() where T at boot.jl:413
...
Stacktrace:
[1] Array{Array{Float64,1},1}(::Array{Array{Float64,1},2}) at ./abstractarray.jl:22
[2] convert(::Type{Array{Array{Float64,1},1}}, ::Array{Array{Float64,1},2}) at ./array.jl:489
[3] vertices_list(::Hyperrectangle{Float64}) at /Users/mforets/.julia/dev/LazySets/src/AbstractHyperrectangle.jl:54
[4] top-level scope at none:0
the problem is that the return types of IterTools.product
and Iterators.product
are different iirc
i had this idea, that works both on 0.6 and 0.7: function vk(H::AbstractHyperrectangle{N})::Vector{Vector{N}} where {N<:Real}
R = Iterators.repeated(N[1, -1], dim(H))
vlist = Vector{Vector{N}}(undef, 2^dim(H))
c, r = center(H), radius_hyperrectangle(H)
@inbounds for (i, si) in enumerate(Iterators.product(R...))
vlist[i] = c .+ si[1] .* r
end
return vlist
end but (??) in 0.6 this version is much slower than the current one but in 0.7 it takes the same time in 0.6 julia> H5 = Hyperrectangle(rand(5), rand(5));
julia> @btime vertices_list($H5);
43.424 μs (239 allocations: 19.38 KiB)
julia> @btime vertices_list($H10);
1.416 ms (7188 allocations: 809.72 KiB)
julia> @btime vk($H5);
1.432 ms (2105 allocations: 110.47 KiB)
julia> @btime vk($H10);
54.450 ms (99642 allocations: 12.59 MiB) in 0.7 julia> @btime vk($H5);
39.413 μs (329 allocations: 19.39 KiB) |
55d2501
to
84d2a5a
Compare
84d2a5a
to
d873e81
Compare
d873e81
to
b61e886
Compare
My new solution is easier and more efficient (do not ask why, I just tried out). v0.6: julia> @btime vk($H5);
804.768 μs (2105 allocations: 110.47 KiB)
julia> @btime vertices_list($H5);
4.009 μs (53 allocations: 5.72 KiB) v0.7: julia> @btime vk($H5);
23.813 μs (329 allocations: 19.39 KiB)
julia> @btime vertices_list($H5);
1.940 μs (45 allocations: 5.53 KiB) |
this was neat, well done |
See #121.
In v0.7 we could drop the dependency on
IterTools.jl
, but for now we still have it for v0.6.