Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pystencils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stephan Seitz
pystencils
Commits
d8e498fa
Commit
d8e498fa
authored
6 years ago
by
Martin Bauer
Browse files
Options
Downloads
Patches
Plain Diff
Workaround for sympy bug in placeholder_function
see
https://github.com/sympy/sympy/issues/16662
parent
27a131fb
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pystencils/placeholder_function.py
+3
-2
3 additions, 2 deletions
pystencils/placeholder_function.py
pystencils/sympyextensions.py
+7
-0
7 additions, 0 deletions
pystencils/sympyextensions.py
with
10 additions
and
2 deletions
pystencils/placeholder_function.py
+
3
−
2
View file @
d8e498fa
...
...
@@ -2,6 +2,7 @@ import sympy as sp
from
typing
import
List
from
pystencils.assignment
import
Assignment
from
pystencils.astnodes
import
Node
from
pystencils.sympyextensions
import
is_constant
from
pystencils.transformations
import
generic_visit
...
...
@@ -37,11 +38,11 @@ def to_placeholder_function(expr, name):
assignments
=
[
Assignment
(
sp
.
Symbol
(
name
),
expr
)]
assignments
+=
[
Assignment
(
symbol
,
derivative
)
for
symbol
,
derivative
in
zip
(
derivative_symbols
,
derivatives
)
if
not
derivative
.
is_constant
()]
if
not
is_constant
(
derivative
)]
def
fdiff
(
_
,
index
):
result
=
derivatives
[
index
-
1
]
return
result
if
result
.
is_constant
()
else
derivative_symbols
[
index
-
1
]
return
result
if
is_constant
(
result
)
else
derivative_symbols
[
index
-
1
]
func
=
type
(
name
,
(
sp
.
Function
,
PlaceholderFunction
),
{
'
fdiff
'
:
fdiff
,
...
...
This diff is collapsed.
Click to expand it.
pystencils/sympyextensions.py
+
7
−
0
View file @
d8e498fa
...
...
@@ -172,6 +172,13 @@ def fast_subs(expression: T, substitutions: Dict,
return
visit
(
expression
)
def
is_constant
(
expr
):
"""
Simple version of checking if a sympy expression is constant.
Works also for piecewise defined functions - sympy
'
s is_constant() has a problem there, see:
https://github.com/sympy/sympy/issues/16662
"""
return
len
(
expr
.
free_symbols
)
==
0
def
subs_additive
(
expr
:
sp
.
Expr
,
replacement
:
sp
.
Expr
,
subexpression
:
sp
.
Expr
,
required_match_replacement
:
Optional
[
Union
[
int
,
float
]]
=
0.5
,
required_match_original
:
Optional
[
Union
[
int
,
float
]]
=
None
)
->
sp
.
Expr
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment