Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lamdifying max/min with constants is broken #25660

Open
asmeurer opened this issue Sep 8, 2023 Discussed in #25659 · 1 comment
Open

Lamdifying max/min with constants is broken #25660

asmeurer opened this issue Sep 8, 2023 Discussed in #25659 · 1 comment

Comments

@asmeurer
Copy link
Member

asmeurer commented Sep 8, 2023

Discussed in #25659

Originally posted by younesStrittmatter September 8, 2023
Lambdifying max and min with a constant doesn't work but works as expected with variables:

x = sympy.Symbol('x')
sympy_expr = sympy.sympify('max(3, x)')
f = sympy.lambdify(x, sympy_expr, 'numpy')
f([1,2,3])
-> 
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.

y = sympy.Symbol('y')
sympy_expr = sympy.sympify('max(x, y)')
f = sympy.lambdify([x, y], sympy_expr, 'numpy')
f([1,2,3], [3,2,1])
->
[3,2,3]
```</div>
@asmeurer
Copy link
Member Author

asmeurer commented Sep 8, 2023

This looks like an instance of the problem described at #5642. At least for the case where constant is part of the original expression, it should be possible for the printer to detect this and print something else (it is printing amax((3, x), axis=0))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant