Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Stephan Seitz
pystencils
Commits
f4ba5448
Commit
f4ba5448
authored
Jul 14, 2020
by
Stephan Seitz
Browse files
Fix #23: Make Field.Access NotIterable
parent
558b9f81
Pipeline
#26898
passed with stage
in 9 minutes and 51 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
pystencils/field.py
View file @
f4ba5448
...
...
@@ -676,6 +676,7 @@ class Field(AbstractField):
>>> central_y_component.at_index(0) # change component
v_C^0
"""
_iterable
=
False
# see https://i10git.cs.fau.de/pycodegen/pystencils/-/merge_requests/166#note_10680
def
__new__
(
cls
,
name
,
*
args
,
**
kwargs
):
obj
=
Field
.
Access
.
__xnew_cached_
(
cls
,
name
,
*
args
,
**
kwargs
)
...
...
@@ -756,11 +757,6 @@ class Field(AbstractField):
def
__getitem__
(
self
,
*
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
def
field
(
self
)
->
'Field'
:
"""Field that the Access points to"""
...
...
pystencils_tests/test_field_access_poly.py
0 → 100644
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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment