forked from M-Labs/artiq
1
0
Fork 0

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

View File

@ -4,12 +4,14 @@ from fractions import Fraction
import numpy as np import numpy as np
from artiq.language.units import *
from artiq.management import pyon from artiq.management import pyon
_pyon_test_object = { _pyon_test_object = {
(1, 2): [(3, 4.2), (2, )], (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
} }