From 7dff44693251fade4aa652274f7071da45502dd3 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sun, 12 Jun 2016 12:56:12 +0800 Subject: [PATCH] language: support setting slices of data in mutate_dataset --- artiq/language/environment.py | 7 ++++++- artiq/master/worker_db.py | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/artiq/language/environment.py b/artiq/language/environment.py index 102c684e6..b7b10052b 100644 --- a/artiq/language/environment.py +++ b/artiq/language/environment.py @@ -286,7 +286,12 @@ class HasEnvironment: a given position in a NumPy array) If the dataset was created in broadcast mode, the modification is - immediately transmitted.""" + immediately transmitted. + + If the index is a tuple of integers, it is interpreted as + ``slice(*index)``. + If the index is a tuple of tuples, each sub-tuple is interpreted + as ``slice(*sub_tuple)`` (multi-dimensional slicing).""" self.__dataset_mgr.mutate(key, index, value) def get_dataset(self, key, default=NoDefault): diff --git a/artiq/master/worker_db.py b/artiq/master/worker_db.py index 45c5e657f..350b87522 100644 --- a/artiq/master/worker_db.py +++ b/artiq/master/worker_db.py @@ -1,3 +1,4 @@ +from operator import setitem from collections import OrderedDict import importlib import logging @@ -194,7 +195,13 @@ class DatasetManager: target = self.broadcast[key][1] if target is None: raise KeyError("Cannot mutate non-existing dataset") - target[index] = value + + if isinstance(index, tuple): + if isinstance(index[0], tuple): + index = tuple(slice(*e) for e in index) + else: + index = slice(*index) + setitem(target, index, value) def get(self, key): if key in self.local: