Skip to content

Commit 62b9dea

Browse files
committed
Added detailed cache note
1 parent b2dbebd commit 62b9dea

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

stumpy/cache.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,15 @@ def save():
252252
253253
Notes
254254
-----
255-
The cache is never cleared before saving/overwriting and may be explicitly
256-
cleared by calling `cache.clear()` before saving.
255+
The cache is never cleared before saving/overwriting and may be explicitly cleared
256+
by calling `cache.clear()` before saving. If `cache.save()` is called for the first
257+
time (before any `njit` function is called) then only the `.nbi` files (i.e., the
258+
"cache index") for all `njit` functions are saved. As each `njit` function (and
259+
sub-functions) is called then their corresponding `.nbc` file (i.e., "object code")
260+
is saved. Each `.nbc` file will only be saved after its `njit` function is called
261+
once. However, subsequent calls to `cache.save()` (after clearing the cache via
262+
`cache.clear()`) will automatically save BOTH the `.nbi` files as well as the `.nbc`
263+
files as long as their `njit` function has been called at least once.
257264
"""
258265
if numba.config.DISABLE_JIT:
259266
msg = "Could not save/cache function because NUMBA JIT is disabled"

tests/test_cache.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ def test_cache_save_after_clear():
1616
cache_dir = "stumpy/__pycache__"
1717

1818
cache.clear(cache_dir)
19-
cache.save()
19+
cache.save() # Saves nbi files only until njit funcs are called for the first time
2020

21-
stump(T, m)
21+
stump(T, m) # Saves nbc files, subsequent saves will write both nbi and nbc files
2222
ref_cache = cache._get_cache(cache_dir)
2323

2424
if numba.config.DISABLE_JIT:
@@ -28,9 +28,8 @@ def test_cache_save_after_clear():
2828

2929
cache.clear(cache_dir)
3030
assert len(cache._get_cache(cache_dir)) == 0
31-
cache.save()
31+
cache.save() # Save both nbi and nbc files without needing to call `stump` function
3232

33-
# stump(T, m)
3433
comp_cache = cache._get_cache(cache_dir)
3534

3635
assert sorted(ref_cache) == sorted(comp_cache)

0 commit comments

Comments
 (0)