Skip to content

Commit

Permalink
Merge pull request #33 from shoyer/no-thunk
Browse files Browse the repository at this point in the history
Remove 'thunk' jargon from PythonExecutor
  • Loading branch information
rabernat committed Jul 27, 2020
2 parents 721c601 + ee0f28a commit 3434bf6
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions rechunker/executors/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
from functools import partial
import math

from typing import Any, Callable, Iterable
from typing import Callable, Iterable

from rechunker.types import CopySpec, StagedCopySpec, Executor


Thunk = Callable[[], None]
# PythonExecutor represents delayed execution tasks as functions that require
# no arguments.
Task = Callable[[], None]


class PythonExecutor(Executor[Thunk]):
class PythonExecutor(Executor[Task]):
"""An execution engine based on Python loops.
Supports copying between any arrays that implement ``__getitem__`` and
Expand All @@ -19,14 +21,14 @@ class PythonExecutor(Executor[Thunk]):
Execution plans for PythonExecutor are functions that accept no arguments.
"""

def prepare_plan(self, specs: Iterable[StagedCopySpec]) -> Thunk:
def prepare_plan(self, specs: Iterable[StagedCopySpec]) -> Task:
tasks = []
for staged_copy_spec in specs:
for copy_spec in staged_copy_spec.stages:
tasks.append(partial(_direct_copy_array, copy_spec))
return partial(_execute_all, tasks)

def execute_plan(self, plan: Thunk):
def execute_plan(self, plan: Task):
plan()


Expand All @@ -40,6 +42,6 @@ def _direct_copy_array(copy_spec: CopySpec) -> None:
target_array[key] = source_array[key]


def _execute_all(tasks: Iterable[Callable[[], Any]]) -> None:
def _execute_all(tasks: Iterable[Task]) -> None:
for task in tasks:
task()

0 comments on commit 3434bf6

Please sign in to comment.