Skip to content

Commit

Permalink
Define car and cdr for lists
Browse files Browse the repository at this point in the history
The `Apply` node of multiple output Ops return a list of output. To
allow callers to etuplize this list and later evaluate the expression
tuple back to this list we define the behavior of `car` and `cdr` in
terms of `cons`.
  • Loading branch information
rlouf committed Sep 29, 2022
1 parent 32e1e90 commit 5efbbde
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion aesara/graph/rewriting/unify.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from typing import Callable, Dict, Optional, Tuple, Union

import numpy as np
from cons.core import ConsError, _car, _cdr
from cons.core import ConsError, _car, _cdr, cons
from etuples import apply, etuple, etuplize
from etuples.core import ExpressionTuple, etuple
from etuples.dispatch import etuplize_fn
Expand Down Expand Up @@ -73,6 +73,21 @@ def __repr__(self):
return f"{type(self).__name__}({repr(self.constraint)}, {self.token})"


def car_list(x: list):
return cons


_car.add((list,), car_list)


def cdr_list(x: list):
x_e = etuple(_car(x), *x, [], evaled_obj=x)
return x_e[1:]


_cdr.add((list,), cdr_list)


class OpExpressionTuple(ExpressionTuple):
r"""Etuple form for `Op`s.
Expand Down

0 comments on commit 5efbbde

Please sign in to comment.