From 36b93ff126c98e2bf8df212f29b106c169153405 Mon Sep 17 00:00:00 2001 From: qmac Date: Tue, 3 Apr 2018 16:14:54 -0500 Subject: [PATCH] added some comments to batch caching --- pliers/transformers/base.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pliers/transformers/base.py b/pliers/transformers/base.py index aaddca9e..440f80a9 100644 --- a/pliers/transformers/base.py +++ b/pliers/transformers/base.py @@ -240,10 +240,13 @@ def _iterate(self, stims, validation='strict', *args, **kwargs): non_cached = [] for stim in batch: key = hash((hash(self), hash(stim))) + # If using the cache, only transform stims that aren't in the + # cache and haven't already appeared in the batch if not (use_cache and (key in _cache or key in target_inds)): target_inds[key] = len(non_cached) non_cached.append(stim) + # _transform will likely fail if given an empty list if len(non_cached) > 0: batch_results = self._transform(non_cached, *args, **kwargs) else: @@ -251,6 +254,7 @@ def _iterate(self, stims, validation='strict', *args, **kwargs): for i, stim in enumerate(batch): key = hash((hash(self), hash(stim))) + # Use the target index to get the result from batch_results if key in target_inds: result = batch_results[target_inds[key]] result = _log_transformation(stim, result, self) @@ -260,6 +264,7 @@ def _iterate(self, stims, validation='strict', *args, **kwargs): result = list(result) _cache[key] = result results.append(result) + # Otherwise, the result should be in the cache else: results.append(_cache[key]) return results