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
pycodegen
pystencils
Commits
a3025645
Commit
a3025645
authored
4 months ago
by
Richard Angersbach
Browse files
Options
Downloads
Patches
Plain Diff
Fix min/max reductions
parent
bb984679
No related branches found
No related tags found
1 merge request
!438
Reduction Support
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/pystencils/backend/kernelcreation/freeze.py
+9
-7
9 additions, 7 deletions
src/pystencils/backend/kernelcreation/freeze.py
with
9 additions
and
7 deletions
src/pystencils/backend/kernelcreation/freeze.py
+
9
−
7
View file @
a3025645
...
@@ -193,29 +193,31 @@ class FreezeExpressions:
...
@@ -193,29 +193,31 @@ class FreezeExpressions:
assert
isinstance
(
rhs
,
PsExpression
)
assert
isinstance
(
rhs
,
PsExpression
)
assert
isinstance
(
lhs
,
PsSymbolExpr
)
assert
isinstance
(
lhs
,
PsSymbolExpr
)
# match for reduction operation and set neutral init_val and new rhs (similar to augmented assignment)
new_rhs
:
PsExpression
match
expr
.
op
:
match
expr
.
op
:
case
"
+
"
:
case
"
+
"
:
op
=
add
init_val
=
PsConstant
(
0
)
init_val
=
PsConstant
(
0
)
new_rhs
=
add
(
lhs
.
clone
(),
rhs
)
case
"
-
"
:
case
"
-
"
:
op
=
sub
init_val
=
PsConstant
(
0
)
init_val
=
PsConstant
(
0
)
new_rhs
=
sub
(
lhs
.
clone
(),
rhs
)
case
"
*
"
:
case
"
*
"
:
op
=
mul
init_val
=
PsConstant
(
1
)
init_val
=
PsConstant
(
1
)
# TODO: unsure if sp.Min & sp.Max are mapped by map_Min/map_Max afterwards
new_rhs
=
mul
(
lhs
.
clone
(),
rhs
)
case
"
min
"
:
case
"
min
"
:
op
=
sp
.
Min
init_val
=
PsCall
(
PsMathFunction
(
NumericLimitsFunctions
.
Min
),
[])
init_val
=
PsCall
(
PsMathFunction
(
NumericLimitsFunctions
.
Min
),
[])
new_rhs
=
PsCall
(
PsMathFunction
(
MathFunctions
.
Min
),
[
lhs
.
clone
(),
rhs
])
case
"
max
"
:
case
"
max
"
:
op
=
sp
.
Max
init_val
=
PsCall
(
PsMathFunction
(
NumericLimitsFunctions
.
Max
),
[])
init_val
=
PsCall
(
PsMathFunction
(
NumericLimitsFunctions
.
Max
),
[])
new_rhs
=
PsCall
(
PsMathFunction
(
MathFunctions
.
Max
),
[
lhs
.
clone
(),
rhs
])
case
_
:
case
_
:
raise
FreezeError
(
f
"
Unsupported reduced assignment:
{
expr
.
op
}
.
"
)
raise
FreezeError
(
f
"
Unsupported reduced assignment:
{
expr
.
op
}
.
"
)
# set reduction symbol property in context
self
.
_ctx
.
add_reduction_to_symbol
(
lhs
.
symbol
,
ReductionSymbolProperty
(
expr
.
op
,
init_val
))
self
.
_ctx
.
add_reduction_to_symbol
(
lhs
.
symbol
,
ReductionSymbolProperty
(
expr
.
op
,
init_val
))
return
PsAssignment
(
lhs
,
op
(
lhs
.
clone
(),
rhs
)
)
return
PsAssignment
(
lhs
,
new_
rhs
)
def
map_Symbol
(
self
,
spsym
:
sp
.
Symbol
)
->
PsSymbolExpr
:
def
map_Symbol
(
self
,
spsym
:
sp
.
Symbol
)
->
PsSymbolExpr
:
symb
=
self
.
_ctx
.
get_symbol
(
spsym
.
name
)
symb
=
self
.
_ctx
.
get_symbol
(
spsym
.
name
)
...
...
This diff is collapsed.
Click to expand it.
Frederik Hennig
@da15siwa
mentioned in commit
4e688b86
·
2 weeks ago
mentioned in commit
4e688b86
mentioned in commit 4e688b867339c90a6fba3ad12c383d1e59211ed9
Toggle commit list
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