You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While optimizing some of my code (a ChainedVector type implementation) I encountered something that I think is an issue.
import Base.getindex, Base.setindex!, Base.size, Base.strides, Base.stride, Base.show, Base.similar, Base.print_matrix
type ChainedVector{T} <: AbstractVector{T}
chain::Vector{Vector{T}}
sizes::Vector{Int}
sz::Int
function ChainedVector(arr::Vector{T}...)
sizes = [ length(v) for v in arr ]
new([v for v in arr], sizes, sum(sizes))
end
end
size{T}(cv::ChainedVector{T}) = cv.sz
function _get_vec_pos{T}(cv::ChainedVector{T}, ind::Integer)
cidx = 1
while(ind > cv.sizes[cidx]); ind -= cv.sizes[cidx]; cidx += 1; end
(cidx, ind)
end
function getindex{T}(cv::ChainedVector{T}, ind::Integer)
cidx = 1
while(ind > cv.sizes[cidx]); ind -= cv.sizes[cidx]; cidx += 1; end
(cv.chain[cidx])[ind]
end
#function getindex{T}(cv::ChainedVector{T}, ind::Integer)
# cidx, ind = _get_vec_pos(cv, ind)
# (cv.chain[cidx])[ind]
#end
function time_cv()
cv = ChainedVector{Int}(zeros(Int, 1024*1024*32), zeros(Int, 1024*1024*32))
cv_time = @elapsed begin
i = 1
x = 0
l = length(cv)
while(i < l)
x += cv[i]
i+=1
end
println(x)
end
println("ChainedVector: $cv_time")
end
Unmodified, the above code gives:
julia> time_cv()
0
ChainedVector: 0.541100287
With the getindex functions swapped with the commented one, it gives:
julia> time_cv()
0
ChainedVector: 8.385757686
Is this an inlining problem?
Thanks
Tanmay
The text was updated successfully, but these errors were encountered:
What would be nice is to have warning flags. This is a case where it would be nice to have an explicit inline keyword, and a compiler warning if inlining did not happen.
Hi,
While optimizing some of my code (a ChainedVector type implementation) I encountered something that I think is an issue.
Unmodified, the above code gives:
With the getindex functions swapped with the commented one, it gives:
Is this an inlining problem?
Thanks
Tanmay
The text was updated successfully, but these errors were encountered: