2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-28 20:53:35 +08:00

pyon: unit support

This commit is contained in:
Sebastien Bourdeauducq 2014-12-09 10:48:47 +08:00
parent e814da1ba3
commit 597fe57fb3
2 changed files with 11 additions and 1 deletions

View File

@ -23,6 +23,8 @@ from fractions import Fraction
import numpy
from artiq.language.units import Quantity
_encode_map = {
type(None): "none",
@ -34,6 +36,7 @@ _encode_map = {
list: "list",
dict: "dict",
Fraction: "fraction",
Quantity: "quantity",
numpy.ndarray: "nparray"
}
@ -100,6 +103,10 @@ class _Encoder:
return "Fraction({}, {})".format(encode(x.numerator),
encode(x.denominator))
def encode_quantity(self, x):
return "Quantity({}, {})".format(encode(x.amount),
encode(x.unit))
def encode_nparray(self, x):
r = "nparray("
r += encode(x.shape) + ", "
@ -133,6 +140,7 @@ _eval_dict = {
"true": True,
"Fraction": Fraction,
"Quantity": Quantity,
"nparray": _nparray
}

View File

@ -4,12 +4,14 @@ from fractions import Fraction
import numpy as np
from artiq.language.units import *
from artiq.management import pyon
_pyon_test_object = {
(1, 2): [(3, 4.2), (2, )],
Fraction(3, 4): np.linspace(5, 10, 1)
Fraction(3, 4): np.linspace(5, 10, 1),
"frequency": 10*GHz
}