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
Sebastian Bindgen
pystencils
Commits
f4ba5448
Commit
f4ba5448
authored
4 years ago
by
Stephan Seitz
Browse files
Options
Downloads
Patches
Plain Diff
Fix
#23
: Make Field.Access NotIterable
parent
558b9f81
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pystencils/field.py
+1
-5
1 addition, 5 deletions
pystencils/field.py
pystencils_tests/test_field_access_poly.py
+29
-0
29 additions, 0 deletions
pystencils_tests/test_field_access_poly.py
with
30 additions
and
5 deletions
pystencils/field.py
+
1
−
5
View file @
f4ba5448
...
@@ -676,6 +676,7 @@ class Field(AbstractField):
...
@@ -676,6 +676,7 @@ class Field(AbstractField):
>>>
central_y_component
.
at_index
(
0
)
# change component
>>>
central_y_component
.
at_index
(
0
)
# change component
v_C
^
0
v_C
^
0
"""
"""
_iterable
=
False
# see https://i10git.cs.fau.de/pycodegen/pystencils/-/merge_requests/166#note_10680
def
__new__
(
cls
,
name
,
*
args
,
**
kwargs
):
def
__new__
(
cls
,
name
,
*
args
,
**
kwargs
):
obj
=
Field
.
Access
.
__xnew_cached_
(
cls
,
name
,
*
args
,
**
kwargs
)
obj
=
Field
.
Access
.
__xnew_cached_
(
cls
,
name
,
*
args
,
**
kwargs
)
...
@@ -756,11 +757,6 @@ class Field(AbstractField):
...
@@ -756,11 +757,6 @@ class Field(AbstractField):
def
__getitem__
(
self
,
*
idx
):
def
__getitem__
(
self
,
*
idx
):
return
self
.
__call__
(
*
idx
)
return
self
.
__call__
(
*
idx
)
def
__iter__
(
self
):
"""
This is necessary to work with parts of sympy that test if an object is iterable (e.g. simplify).
The __getitem__ would make it iterable
"""
raise
TypeError
(
"
Field access is not iterable
"
)
@property
@property
def
field
(
self
)
->
'
Field
'
:
def
field
(
self
)
->
'
Field
'
:
"""
Field that the Access points to
"""
"""
Field that the Access points to
"""
...
...
This diff is collapsed.
Click to expand it.
pystencils_tests/test_field_access_poly.py
0 → 100644
+
29
−
0
View file @
f4ba5448
#
# Copyright © 2020 Stephan Seitz <stephan.seitz@fau.de>
#
# Distributed under terms of the GPLv3 license.
"""
"""
from
pystencils.session
import
*
from
sympy
import
poly
def
test_field_access_poly
():
dh
=
ps
.
create_data_handling
((
20
,
20
))
ρ
=
dh
.
add_array
(
'
rho
'
)
rho
=
ρ
.
center
a
=
poly
(
rho
+
0.5
,
rho
)
print
(
a
)
def
test_field_access_piecewise
():
dh
=
ps
.
create_data_handling
((
20
,
20
))
ρ
=
dh
.
add_array
(
'
rho
'
)
pw
=
sp
.
Piecewise
((
0
,
1
<
sp
.
Max
(
-
0.5
,
ρ
.
center
+
0.5
)),
(
1
,
True
))
a
=
sp
.
simplify
(
pw
)
print
(
a
)
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