January 2020
Intermediate to advanced
532 pages
13h 31m
English
The Omega.jl package implements its own memoization cache. Interestingly, it ensures proper return type from the cache lookup using the Core.Compiler.return_type function. It is done to avoid type instability problems. In The barrier function pattern section later in this chapter, we will discuss more the problem of type instability and how to deal with the issue. Check out the following code example:
@inline function memapl(rv::RandVar, mω::TaggedΩ) if dontcache(rv) ppapl(rv, proj(mω, rv)) elseif haskey(mω.tags.cache, rv.id) mω.tags.cache[rv.id]::(Core.Compiler).return_type(rv, typeof((mω.taggedω,))) else mω.tags.cache[rv.id] = ppapl(rv, proj(mω, rv)) endend
Read now
Unlock full access