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
Package registry
Model registry
Operate
Environments
Terraform modules
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
Jean-Noël Grad
pystencils
Commits
1bb35b83
Commit
1bb35b83
authored
3 years ago
by
Markus Holzer
Committed by
Jan Hönig
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Bug fix simplification
parent
69ec458c
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pystencils/sympyextensions.py
+5
-2
5 additions, 2 deletions
pystencils/sympyextensions.py
pystencils_tests/test_timeloop.py
+3
-1
3 additions, 1 deletion
pystencils_tests/test_timeloop.py
with
8 additions
and
3 deletions
pystencils/sympyextensions.py
+
5
−
2
View file @
1bb35b83
...
@@ -235,6 +235,9 @@ def subs_additive(expr: sp.Expr, replacement: sp.Expr, subexpression: sp.Expr,
...
@@ -235,6 +235,9 @@ def subs_additive(expr: sp.Expr, replacement: sp.Expr, subexpression: sp.Expr,
normalized_replacement_match
=
normalize_match_parameter
(
required_match_replacement
,
len
(
subexpression
.
args
))
normalized_replacement_match
=
normalize_match_parameter
(
required_match_replacement
,
len
(
subexpression
.
args
))
if
isinstance
(
subexpression
,
sp
.
Number
):
return
expr
.
subs
({
replacement
:
subexpression
})
def
visit
(
current_expr
):
def
visit
(
current_expr
):
if
current_expr
.
is_Add
:
if
current_expr
.
is_Add
:
expr_max_length
=
max
(
len
(
current_expr
.
args
),
len
(
subexpression
.
args
))
expr_max_length
=
max
(
len
(
current_expr
.
args
),
len
(
subexpression
.
args
))
...
@@ -263,7 +266,7 @@ def subs_additive(expr: sp.Expr, replacement: sp.Expr, subexpression: sp.Expr,
...
@@ -263,7 +266,7 @@ def subs_additive(expr: sp.Expr, replacement: sp.Expr, subexpression: sp.Expr,
return
current_expr
return
current_expr
else
:
else
:
if
current_expr
.
func
==
sp
.
Mul
and
Zero
()
in
param_list
:
if
current_expr
.
func
==
sp
.
Mul
and
Zero
()
in
param_list
:
return
Zero
(
)
return
sp
.
simplify
(
current_expr
)
else
:
else
:
return
current_expr
.
func
(
*
param_list
,
evaluate
=
False
)
return
current_expr
.
func
(
*
param_list
,
evaluate
=
False
)
...
@@ -359,7 +362,7 @@ def remove_higher_order_terms(expr: sp.Expr, symbols: Sequence[sp.Symbol], order
...
@@ -359,7 +362,7 @@ def remove_higher_order_terms(expr: sp.Expr, symbols: Sequence[sp.Symbol], order
if
velocity_factors_in_product
(
expr
)
<=
order
:
if
velocity_factors_in_product
(
expr
)
<=
order
:
return
expr
return
expr
else
:
else
:
return
sp
.
Rational
(
0
,
1
)
return
Zero
(
)
if
type
(
expr
)
!=
Add
:
if
type
(
expr
)
!=
Add
:
return
expr
return
expr
...
...
This diff is collapsed.
Click to expand it.
pystencils_tests/test_timeloop.py
+
3
−
1
View file @
1bb35b83
...
@@ -59,4 +59,6 @@ def test_timeloop():
...
@@ -59,4 +59,6 @@ def test_timeloop():
timeloop
.
run_time_span
(
seconds
=
seconds
)
timeloop
.
run_time_span
(
seconds
=
seconds
)
end
=
time
.
perf_counter
()
end
=
time
.
perf_counter
()
np
.
testing
.
assert_almost_equal
(
seconds
,
end
-
start
,
decimal
=
2
)
# This test case fails often due to time measurements. It is not a good idea to assert here
# np.testing.assert_almost_equal(seconds, end - start, decimal=2)
print
(
"
timeloop:
"
,
seconds
,
"
own meassurement:
"
,
end
-
start
)
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