Skip to content

Commit

Permalink
Use array type in cache key instead of element type
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Stagner committed Aug 29, 2016
1 parent 6347096 commit f787edd
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/cache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ end

Base.copy(cache::JacobianCache) = JacobianCache(copy(cache.duals), cache.seeds)

@eval function multithread_jacobian_cachefetch!{N}(x, chunk::Chunk{N}, usecache::Bool,
@eval function multithread_jacobian_cachefetch!{T<:AbstractArray, N}(x::T, chunk::Chunk{N}, usecache::Bool,
alt::Bool = false)
T, xlen = eltype(x), length(x)
S, xlen = eltype(x), length(x)
if usecache
result = get!(JACOBIAN_CACHE, (xlen, N, T, alt)) do
construct_jacobian_caches(x, chunk)
end
else
result = construct_jacobian_caches(x, chunk)
end
return result::NTuple{$NTHREADS,JacobianCache{N,T,jacobian_dual_type(x, chunk)}}
return result::NTuple{$NTHREADS,JacobianCache{N,S,jacobian_dual_type(x, chunk)}}
end

jacobian_cachefetch!(args...) = multithread_jacobian_cachefetch!(args...)[compat_threadid()]
Expand Down Expand Up @@ -87,16 +87,16 @@ end

Base.copy(cache::HessianCache) = HessianCache(copy(cache.duals), cache.inseeds, cache.outseeds)

@eval function multithread_hessian_cachefetch!{N}(x, chunk::Chunk{N}, usecache::Bool)
T = eltype(x)
@eval function multithread_hessian_cachefetch!{T<:AbstractArray,N}(x::T, chunk::Chunk{N}, usecache::Bool)
S = eltype(x)
if usecache
result = get!(HESSIAN_CACHE, (N, T)) do
construct_hessian_caches(x, chunk)
end
else
result = construct_hessian_caches(x, chunk)
end
return result::NTuple{$NTHREADS,HessianCache{N,T,hessian_dual_type(x, chunk)}}
return result::NTuple{$NTHREADS,HessianCache{N,S,hessian_dual_type(x, chunk)}}
end

hessian_cachefetch!(args...) = multithread_hessian_cachefetch!(args...)[compat_threadid()]
Expand Down

0 comments on commit f787edd

Please sign in to comment.