Commit ddb86435 authored by Martin Bauer's avatar Martin Bauer
Browse files

Merge branch 'FieldShapeSymbol-FieldStrideSymbol-strictly-positive' into 'master'

Declare FieldShapeSymbol and FieldStrideSymbol as strictly positive

See merge request pycodegen/pystencils!16
parents 8b30de1d d4c0c47e
......@@ -105,8 +105,8 @@ class TypedSymbol(sp.Symbol):
obj = TypedSymbol.__xnew_cached_(cls, *args, **kwds)
return obj
def __new_stage2__(cls, name, dtype):
obj = super(TypedSymbol, cls).__xnew__(cls, name)
def __new_stage2__(cls, name, dtype, *args, **kwargs):
obj = super(TypedSymbol, cls).__xnew__(cls, name, *args, **kwargs)
try:
obj._dtype = create_type(dtype)
except (TypeError, ValueError):
......@@ -143,6 +143,13 @@ class TypedSymbol(sp.Symbol):
return super().is_positive
@property
def is_nonnegative(self):
if self.is_negative is False:
return True
else:
return super().is_nonnegative
@property
def is_real(self):
if hasattr(self.dtype, 'numpy_dtype'):
......
......@@ -30,7 +30,7 @@ class FieldStrideSymbol(TypedSymbol):
def __new_stage2__(cls, field_name, coordinate):
name = "_stride_{name}_{i}".format(name=field_name, i=coordinate)
obj = super(FieldStrideSymbol, cls).__xnew__(cls, name, STRIDE_DTYPE)
obj = super(FieldStrideSymbol, cls).__xnew__(cls, name, STRIDE_DTYPE, positive=True)
obj.field_name = field_name
obj.coordinate = coordinate
return obj
......@@ -55,7 +55,7 @@ class FieldShapeSymbol(TypedSymbol):
def __new_stage2__(cls, field_names, coordinate):
names = "_".join([field_name for field_name in field_names])
name = "_size_{names}_{i}".format(names=names, i=coordinate)
obj = super(FieldShapeSymbol, cls).__xnew__(cls, name, SHAPE_DTYPE)
obj = super(FieldShapeSymbol, cls).__xnew__(cls, name, SHAPE_DTYPE, positive=True)
obj.field_names = tuple(field_names)
obj.coordinate = coordinate
return obj
......
Markdown is supported
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