Skip to content
Snippets Groups Projects
Commit f4ba5448 authored by Stephan Seitz's avatar Stephan Seitz
Browse files

Fix #23: Make Field.Access NotIterable

parent 558b9f81
No related merge requests found
...@@ -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"""
......
#
# 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)
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment