From 937ca853aabe956d748662be24979ffdfadfe740 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sun, 19 Jul 2015 11:36:52 +0200 Subject: [PATCH] language/scan: fix random scan, add explicit scan, specify what runs on host/device --- artiq/language/scan.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/artiq/language/scan.py b/artiq/language/scan.py index fc20d98fc..522321a16 100644 --- a/artiq/language/scan.py +++ b/artiq/language/scan.py @@ -1,4 +1,6 @@ -from random import Random +from random import Random, shuffle + +from artiq.language.core import * class LinearScan: @@ -7,28 +9,32 @@ class LinearScan: self.max = max self.npoints = npoints + @portable def _gen(self): r = self.max - self.min d = self.npoints - 1 for i in range(self.npoints): yield r*i/d + self.min + @portable def __iter__(self): return self._gen() class RandomScan: def __init__(self, min, max, npoints, seed=0): - self.min = min - self.max = max - self.npoints = npoints - self.seed = 0 - - def _gen(self): - prng = Random(self.seed) - r = self.max - self.min - for i in range(self.npoints): - yield prng.random()*r + self.min + self.sequence = list(LinearScan(min, max, npoints)) + shuffle(self.sequence, Random(seed).random) + @portable def __iter__(self): - return self._gen() + return iter(self.sequence) + + +class ExplicitScan: + def __init__(self, sequence): + self.sequence = sequence + + @portable + def __iter__(self): + return iter(self.sequence)