def forward(self, x, sldj, reverse=False, condition_embd=None): if reverse: if self.next is not None: x = squeeze(x) x, x_split = x.chunk(2, dim=1) x, sldj = self.next(x, sldj, reverse, condition_embd=condition_embd) x = torch.cat((x, x_split), dim=1) x = unsqueeze(x) if self.checkers: x = checkerboard(x) for flow in reversed(self.checkers): x, sldj = flow(x, sldj, reverse, condition_embd=condition_embd) x = checkerboard(x, reverse=True) if self.channels: x = channelwise(x) for flow in reversed(self.channels): x, sldj = flow(x, sldj, reverse, condition_embd=condition_embd) x = channelwise(x, reverse=True) else: if self.channels: x = channelwise(x) for flow in self.channels: x, sldj = flow(x, sldj, reverse, condition_embd=condition_embd) x = channelwise(x, reverse=True) if self.checkers: x = checkerboard(x) for flow in self.checkers: x, sldj = flow(x, sldj, reverse, condition_embd=condition_embd) x = checkerboard(x, reverse=True) if self.next is not None: x = squeeze(x) x, x_split = x.chunk(2, dim=1) x, sldj = self.next(x, sldj, reverse, condition_embd=condition_embd) x = torch.cat((x, x_split), dim=1) x = unsqueeze(x) return x, sldj
def post(self): """Handles a post request to create a blog entry.""" title = self.request.get('title').strip() title = util.squeeze(title, string.whitespace) text = self.request.get('text').strip() text = util.squeeze(text, string.whitespace) blog = Blog(user=self.user.key, title=title, text=text) try: blog.put() except ndb.TransactionFailedError: # TODO: Handle error return self.redirect('/') else: return self.redirect('/blog/%s' % blog.key.urlsafe())
def post(self): """Handles a post request to create a blog entry.""" # TODO: verify request is made in session context title = self.request.get('title').strip() title = util.squeeze(title, string.whitespace) text = self.request.get('text').strip() text = util.squeeze(text, string.whitespace) blog = models.Blog(user=self.user, title=title, text=text) try: blog.put() except ndb.TransactionFailedError: # TODO: Handle error return self.redirect('/') else: return self.redirect('/blog/%s' % blog.key.urlsafe())
def post(self, urlkey): """Stores comment in the DB.""" blog = self.db_resource text = self.json_read()['text'] text = util.squeeze(text.strip(), string.whitespace) comment = Comment(blog=blog.key, user=self.user.key, text=text) try: comment.put() except ndb.TransactionFailedError: # TODO: handle error as internal server error pass context = {'user_key': self.user.key, 'comment': comment} msg = self.render_str(context, 'comment.html') return self.json_write({'id': urlkey, 'comment': msg})
def post(self, urlkey): """Stores comment in the DB.""" key = ndb.Key(urlsafe=urlkey) text = self.json_read()['text'] text = util.squeeze(text.strip(), string.whitespace) comment = models.BlogComment(blog=key, user=self.user, comment=text) try: comment.put() except ndb.TransactionFailedError: # TODO: handle error as internal server error pass context = {'user': self.user, 'comment': comment} msg = self.render_str(context, 'comment.html') return self.json_write({'id': urlkey, 'comment': msg})
class Food: _func = squeeze(-50, 50) def on_collision(self, obj): if isinstance(obj, Consumer): obj.consume(self.get_value()) self.env.remove(self) def get_value(self): return Food._func(self.get_area() / 10) def get_area(self): return 0
def test_util_squeeze_starts_with_slash(): expect = "/hoge/huga/com" actual = util.squeeze("///hoge/huga//com", "/") assert (actual == expect)
def test_util_squeeze_ends_with_slash(): expect = "/h/o/g/e/huga/com/" actual = util.squeeze("///h//o/g/e/huga//com///", "/") assert (actual == expect)
def __init__(self, base_key, **kwargs): self.etcd = etcd3.client(**kwargs) self.base_key = squeeze("/" + base_key, "/")
def _build_key(self, key): return squeeze(self.base_key + "/" + key, "/")