artiq/artiq/language/scan.py

41 lines
865 B
Python
Raw Normal View History

from random import Random, shuffle
from artiq.language.core import *
2015-07-19 01:26:41 +08:00
class LinearScan:
def __init__(self, min, max, npoints):
self.min = min
self.max = max
self.npoints = npoints
@portable
2015-07-19 01:26:41 +08:00
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
2015-07-19 01:26:41 +08:00
def __iter__(self):
return self._gen()
class RandomScan:
def __init__(self, min, max, npoints, seed=0):
self.sequence = list(LinearScan(min, max, npoints))
shuffle(self.sequence, Random(seed).random)
2015-07-19 01:26:41 +08:00
@portable
2015-07-19 01:26:41 +08:00
def __iter__(self):
return iter(self.sequence)
class ExplicitScan:
def __init__(self, sequence):
self.sequence = sequence
@portable
def __iter__(self):
return iter(self.sequence)