Skip to content

Commit

Permalink
m
Browse files Browse the repository at this point in the history
  • Loading branch information
zoomlogo committed Apr 16, 2022
2 parents 9ce6a36 + 4d42c0d commit 568c17b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
41 changes: 29 additions & 12 deletions flax/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,38 +617,48 @@
"ᵟ˝": attrdict(
condition=lambda links: links and links[0].arity,
qlink=lambda links, outermost_links, i: [
attrdict(arity=2, call=lambda w, x: fold(links, w, x, right=True, initial=True))
attrdict(
arity=2, call=lambda w, x: fold(links, w, x, right=True, initial=True)
)
],
),
"ᵟᵂ": attrdict(
condition=lambda links: len(links) == 2,
qlink=lambda links, outermost_links, i: [
attrdict(
arity=max(arities(links)),
call=lambda w=None, x=None: while_loop(links[0], links[1], (w, x), cumulative=True),
call=lambda w=None, x=None: while_loop(
links[0], links[1], (w, x), cumulative=True
),
)
],
),
"ᵟᵍ": attrdict(
condition=lambda links: links,
qlink=lambda links, outermost_links, i: [
attrdict(
arity=links[0].arity or 1, call=lambda w, x=None: ffilter(links, w, x, permutation=True)
arity=links[0].arity or 1,
call=lambda w, x=None: ffilter(links, w, x, permutation=True),
)
],
),
"ᵟᶠ": attrdict(
condition=lambda links: links,
qlink=lambda links, outermost_links, i: [
attrdict(
arity=links[0].arity or 1, call=lambda w, x=None: ffilter(links, w, x, inverse=True, permutation=True)
arity=links[0].arity or 1,
call=lambda w, x=None: ffilter(
links, w, x, inverse=True, permutation=True
),
)
],
),
"ᵟ‶": attrdict(
condition=lambda links: links and links[0].arity,
qlink=lambda links, outermost_links, i: [
attrdict(arity=2, call=lambda w, x: scan(links, w, x, right=True, initial=True))
attrdict(
arity=2, call=lambda w, x: scan(links, w, x, right=True, initial=True)
)
],
),
"ᵟⁿ": attrdict(
Expand All @@ -668,7 +678,8 @@
condition=lambda links: links,
qlink=lambda links, outermost_links, i: [
attrdict(
arity=links[0].arity or 1, call=lambda w, x=None: ffilter(links, w, x, inverse=True)
arity=links[0].arity or 1,
call=lambda w, x=None: ffilter(links, w, x, inverse=True),
)
],
),
Expand All @@ -678,18 +689,22 @@
qlink=lambda links, outermost_links, i: [
attrdict(
arity=2,
call=lambda w, x: [variadic_link(links[0], (w, e)) for e in iterable(x)]
call=lambda w, x: [
variadic_link(links[0], (w, e)) for e in iterable(x)
],
)
]
],
),
"’": attrdict(
condition=lambda links: links,
qlink=lambda links, outermost_links, i: [
attrdict(
arity=2,
call=lambda w, x: [variadic_link(links[0], (e, x)) for e in iterable(w)]
call=lambda w, x: [
variadic_link(links[0], (e, x)) for e in iterable(w)
],
)
]
],
),
"‶": attrdict(
condition=lambda links: links and links[0].arity,
Expand Down Expand Up @@ -733,8 +748,10 @@
"⁶": attrdict(
condition=lambda links: len(links) == True,
qlink=lambda links, outermost_links, i: [
create_chain(outermost_links[links[0].call() % len(outermost_links)], links[1].call())
]
create_chain(
outermost_links[links[0].call() % len(outermost_links)], links[1].call()
)
],
),
"⁷": attrdict(
condition=lambda links: links,
Expand Down
2 changes: 1 addition & 1 deletion flax/chains.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def composed(links, w, x):
monads = links[:-1]

if dyad.arity != 2:
error("Expected dyad for \"\"")
error('Expected dyad for "ᐣ"')

monads = [monad.call for monad in monads]
composed_monads = functools.reduce(lambda f, g: lambda w: f(g(w)), monads)
Expand Down
2 changes: 2 additions & 0 deletions flax/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@
"where",
]


def boolify(fn):
# boolify: return a function which returns a int bool (0/1)
return lambda *args: int(fn(*args))


def depth(x):
# depth: returns the depth of x
return 0 if type(x) != list else (1 if not x else max([depth(a) for a in x]) + 1)
Expand Down

0 comments on commit 568c17b

Please sign in to comment.