Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3d6f55104b07
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: fbd3db5753c3
Choose a head ref
  • 4 commits
  • 2 files changed
  • 1 contributor

Commits on May 22, 2016

  1. pyon: use dtype.str

    * contains endianess, makes this portable
    * it's shorter
    * it's what the numpy array interfaces uses
    * this is otherwise backwards and forwards compatible
    jordens committed May 22, 2016
    Copy the full SHA
    a9434d2 View commit details
  2. pyon: ship ndarray data as bytes

    this is about 3 times faster and since the encapsulating nparray() already
    breaks json-compatibility, using a unicode string for json compatibility
    is not necessary
    jordens committed May 22, 2016
    Copy the full SHA
    9e68159 View commit details
  3. Copy the full SHA
    0857cfd View commit details
  4. Copy the full SHA
    fbd3db5 View commit details
Showing with 17 additions and 12 deletions.
  1. +15 −10 artiq/protocols/pyon.py
  2. +2 −2 artiq/tools.py
25 changes: 15 additions & 10 deletions artiq/protocols/pyon.py
Original file line number Diff line number Diff line change
@@ -58,6 +58,14 @@
_encode_map[getattr(numpy, _t)] = "npscalar"


_str_translation = {
ord("\""): "\\\"",
ord("\\"): "\\\\",
ord("\n"): "\\n",
ord("\r"): "\\r",
}


class _Encoder:
def __init__(self, pretty):
self.pretty = pretty
@@ -80,11 +88,7 @@ def encode_number(self, x):

def encode_str(self, x):
# Do not use repr() for JSON compatibility.
tt = {
ord("\""): "\\\"", ord("\\"): "\\\\",
ord("\n"): "\\n", ord("\r"): "\\r"
}
return "\"" + x.translate(tt) + "\""
return "\"" + x.translate(_str_translation) + "\""

def encode_bytes(self, x):
return repr(x)
@@ -140,22 +144,23 @@ def encode_ordereddict(self, x):
def encode_nparray(self, x):
r = "nparray("
r += self.encode(x.shape) + ", "
r += self.encode(str(x.dtype)) + ", "
r += self.encode(base64.b64encode(x).decode())
r += self.encode(x.dtype.str) + ", "
r += self.encode(base64.b64encode(x.data))
r += ")"
return r

def encode_npscalar(self, x):
r = "npscalar("
r += "\"" + type(x).__name__ + "\", "
r += self.encode(base64.b64encode(x).decode())
r += self.encode(x.dtype.str) + ", "
r += self.encode(base64.b64encode(x.data))
r += ")"
return r

def encode(self, x):
ty = _encode_map.get(type(x), None)
if ty is None:
raise TypeError(repr(x) + " is not PYON serializable")
raise TypeError("`{!r}` ({}) is not PYON serializable"
.format(x, type(x)))
return getattr(self, "encode_" + ty)(x)


4 changes: 2 additions & 2 deletions artiq/tools.py
Original file line number Diff line number Diff line change
@@ -58,9 +58,9 @@ def short_format(v):
if v is None:
return "None"
t = type(v)
if t is bool or np.issubdtype(t, int) or np.issubdtype(t, float):
if np.issubdtype(t, np.number) or np.issubdtype(t, np.bool_):
return str(v)
elif t is str:
elif np.issubdtype(t, np.unicode_):
return "\"" + elide(v, 50) + "\""
else:
r = t.__name__