From deaa492566d09470ceb2b69c9a46b7e02a6a53a5 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sat, 18 Jul 2015 19:26:41 +0200 Subject: [PATCH] language: add scan iterators --- artiq/language/scan.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 artiq/language/scan.py diff --git a/artiq/language/scan.py b/artiq/language/scan.py new file mode 100644 index 000000000..fc20d98fc --- /dev/null +++ b/artiq/language/scan.py @@ -0,0 +1,34 @@ +from random import Random + + +class LinearScan: + def __init__(self, min, max, npoints): + self.min = min + self.max = max + self.npoints = npoints + + def _gen(self): + r = self.max - self.min + d = self.npoints - 1 + for i in range(self.npoints): + yield r*i/d + self.min + + 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 + + def __iter__(self): + return self._gen()