forked from M-Labs/artiq
1
0
Fork 0

language: support setting slices of data in mutate_dataset

This commit is contained in:
Sebastien Bourdeauducq 2016-06-12 12:56:12 +08:00
parent 9dcd43fb0d
commit 77280a75d9
2 changed files with 14 additions and 2 deletions

View File

@ -291,7 +291,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)."""
if self.__parent is not None:
self.__parent.mutate_dataset(key, index, value)
if self.__dataset_mgr is None:

View File

@ -1,3 +1,4 @@
from operator import setitem
from collections import OrderedDict
import importlib
import logging
@ -169,7 +170,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: