Distributive brackets result in parse error:
danielkelshaw opened this issue · 2 comments
danielkelshaw commented
Hi Florian,
I've been looking into this library after finding it last night -- looks super cool so far!
I was trying to run this snippet:
x = np.ones((4, 8))
y = np.ones((8, 5))
print(einx.dot("a [b->c]", x, y, graph=True))
from here but I seem to get a parse error:
...
File [~/coding/tmp_einx/.venv/lib/python3.11/site-packages/einx/op/util.py:196](http://localhost:8888/~/coding/tmp_einx/.venv/lib/python3.11/site-packages/einx/op/util.py#line=195), in <listcomp>(.0)
194 def _clean_description_and_parameters(description, parameters):
195 # Remove parameters that are not used in the description
--> 196 exprs = [einx.expr.stage1.parse(d) for d in description.split("->") for d in d.split(",")]
197 axis_names = {axis.name for root in exprs for axis in root.all() if isinstance(axis, einx.expr.stage1.NamedAxis)}
198 parameters = {k: v for k, v in parameters.items() if k in axis_names}
File [~/coding/tmp_einx/.venv/lib/python3.11/site-packages/einx/expr/stage1.py:385](http://localhost:8888/~/coding/tmp_einx/.venv/lib/python3.11/site-packages/einx/expr/stage1.py#line=384), in parse(text)
383 stack[-1].append(token)
384 if len(stack) > 1:
--> 385 raise ParseError(text, stack[-1][0].begin_pos, f"Unclosed parenthesis '{stack[-1][0].text}'")
386 expression = parse(stack[0], 0)
388 # Semantic check: Choice must be inside marker
ParseError: Unclosed parenthesis '['
Here: a [b
Any idea how to fix this, or if this is a known bug?
Thanks!
(I'm on python 3.11.6, and einx==0.1.3
)
fferflo commented
Hi Daniel, glad you find it useful!
I hadn't pushed the latest version with the distributive brackets feature to pypi, but docs already included it. It should work after updating now:
pip install --upgrade einx
danielkelshaw commented
That’s great, thanks!