@@ -0,0 +1,1478 @@
+from numpy import prod%0A%0A%0Aclass Params(object):%0A    def __init__(self, ops, size=128):%0A        if size %3C 0:%0A            raise ValueError(%22TODO error re negative size %25d%22 %25 size)%0A        self.ops = ops%0A        self._mem = self.ops.allocate((1, size))%0A        self._offsets = %7B%7D%0A        self._i = 0%0A%0A    def get(self, name):%0A        if name.startswith('d_'):%0A            name = name%5B2:%5D%0A            if self._mem.shape%5B0%5D == 1:%0A                self._alloc_gradients()%0A            col = 1%0A        else:%0A            col = 0%0A        if name not in self._offsets:%0A            return None%0A        offset, shape = self._offsets%5Bname%5D%0A        return self._mem%5Bcol, offset : offset + prod(shape)%5D.reshape(shape)%0A%0A    def add(self, name, shape):%0A        self._offsets%5Bname%5D = (self._i, shape)%0A        blob = self._get_blob(prod(shape))%0A        return blob.reshape(shape)%0A%0A    def _get_blob(self, nr_req):%0A        nr_avail = self._mem.shape%5B1%5D - self._i%0A        if nr_avail %3C nr_req:%0A            self._realloc((self._mem.shape%5B1%5D + nr_req) * 2)%0A        blob = self._mem%5B:, self._i : self._i + nr_req%5D%0A        self._i += nr_req%0A        return blob%0A%0A    def _alloc_gradients(self):%0A        new_mem = self.ops.allocate((2, self._mem.shape%5B1%5D))%0A        new_mem%5B0%5D = self._mem%5B0%5D%0A        self._mem = new_mem%0A%0A    def _realloc(self, new_size):%0A        new_mem = self.ops.allocate((self._mem.shape%5B0%5D, new_size))%0A        new_mem%5B:, :self._i+1%5D = self._mem%5B:, :self._i+1%5D%0A        self._mem = new_mem%0A

Make Params pass tests.