forked from M-Labs/artiq
pyon: unit support
This commit is contained in:
parent
e814da1ba3
commit
597fe57fb3
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue