From a672ba62e268f6fa0af47ad6324e0941b6d61f0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Birke?= Date: Fri, 6 Oct 2017 16:37:59 +0200 Subject: [PATCH 1/2] fix parameters of mapreduce_block_ranges calls Change the order of positional arguments to mapreduce_block_ranges --- Notebooks/blocksci/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Notebooks/blocksci/__init__.py b/Notebooks/blocksci/__init__.py index 1cdb4e2a..f781f5a0 100644 --- a/Notebooks/blocksci/__init__.py +++ b/Notebooks/blocksci/__init__.py @@ -48,14 +48,14 @@ def mapreduce_blocks(chain, mapFunc, reduceFunc, init, start=None, end=None, cpu """ def mapRangeFunc(blocks): return reduce(reduceFunc, (mapFunc(block) for block in blocks), init) - return mapreduce_block_ranges(chain, mapRangeFunc, start, end, reduceFunc, init, cpu_count) + return mapreduce_block_ranges(chain, mapRangeFunc, reduceFunc, init, start, end, cpu_count) def mapreduce_txes(chain, mapFunc, reduceFunc, init, start=None, end=None, cpu_count=psutil.cpu_count()): """Initialized multithreaded map reduce function over a stream of transactions """ def mapRangeFunc(blocks): return reduce(reduceFunc, (mapFunc(tx) for block in blocks for tx in block)) - return mapreduce_block_ranges(chain, mapRangeFunc, start, end, reduceFunc, init, cpu_count) + return mapreduce_block_ranges(chain, mapRangeFunc, reduceFunc, init, start, end, cpu_count) def map_blocks(self, blockFunc, start = None, end = None, cpu_count=psutil.cpu_count()): From 1c80619281141d415a80cc2dfd1fa04c061a18a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Birke?= Date: Fri, 6 Oct 2017 16:57:14 +0200 Subject: [PATCH 2/2] fix return of mapreduce_block_ranges when on single-core The mapFunc passed to mapreduce_block_ranges expects a list of blocks (see the inline definitions of mapFunc in mapreduce_blocks, map_blocks, filter_blocks and so on). If on a single-core processor, the list cannot be preprocessed and has to be passed as a whole. --- Notebooks/blocksci/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notebooks/blocksci/__init__.py b/Notebooks/blocksci/__init__.py index f781f5a0..ac025c74 100644 --- a/Notebooks/blocksci/__init__.py +++ b/Notebooks/blocksci/__init__.py @@ -32,7 +32,7 @@ def mapreduce_block_ranges(chain, mapFunc, reduceFunc, init, start=None, end=No end = blocks[-1].height if cpu_count == 1: - return reduce(reduceFunc, (mapFunc(block) for block in chain[start:end])) + return mapFunc(chain[start:end]) segments = chain.segment(start, end, cpu_count) with Pool(cpu_count - 1) as p: