Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid runtime warnings #355

Merged
merged 5 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 66 additions & 46 deletions psydac/api/ast/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
from sympy import Basic, Expr
from sympy import AtomicExpr, S
from sympy import Function
from sympy import Mul,Integer
from sympy.core.singleton import Singleton
from sympy.core.containers import Tuple
from sympy import Mul, Integer
from sympy.core.singleton import Singleton
from sympy.core.containers import Tuple
from sympy.utilities.iterables import iterable as is_iterable

from sympde.old_sympy_utilities import with_metaclass

from sympde.topology import element_of
Expand Down Expand Up @@ -1145,13 +1147,14 @@ class StencilMatrixLocalBasis(MatrixNode):
"""
def __new__(cls, u, v, pads, tag=None, dtype='real'):

if not isinstance(pads, (list, tuple, Tuple)):
if not is_iterable(pads):
raise TypeError('Expecting an iterable')

pads = Tuple(*pads)
rank = 2*len(pads)
tag = tag or random_string( 6 )
rank = 2 * len(pads)
name = (u, v)
tag = tag or random_string(6)

return Basic.__new__(cls, pads, rank, name, tag, dtype)

@property
Expand Down Expand Up @@ -1180,13 +1183,15 @@ class StencilMatrixGlobalBasis(MatrixNode):
used to describe local dof over an element as a stencil matrix
"""
def __new__(cls, u, v, pads, tag=None, dtype='real'):
if not isinstance(pads, (list, tuple, Tuple)):

if not is_iterable(pads):
raise TypeError('Expecting an iterable')

pads = Tuple(*pads)
rank = 2*len(pads)
tag = tag or random_string( 6 )
rank = 2 * len(pads)
name = (u, v)
tag = tag or random_string(6)

return Basic.__new__(cls, pads, rank, name, tag, dtype)

@property
Expand Down Expand Up @@ -1215,13 +1220,15 @@ class StencilVectorLocalBasis(MatrixNode):
used to describe local dof over an element as a stencil vector
"""
def __new__(cls, v, pads, tag=None, dtype='real'):
if not isinstance(pads, (list, tuple, Tuple)):

if not is_iterable(pads):
raise TypeError('Expecting an iterable')

pads = Tuple(*pads)
rank = len(pads)
tag = tag or random_string( 6 )
name = v
tag = tag or random_string(6)

return Basic.__new__(cls, pads, rank, name, tag, dtype)

@property
Expand Down Expand Up @@ -1250,13 +1257,15 @@ class StencilVectorGlobalBasis(MatrixNode):
used to describe local dof over an element as a stencil vector
"""
def __new__(cls, v, pads, tag=None, dtype='real'):
if not isinstance(pads, (list, tuple, Tuple)):

if not is_iterable(pads):
raise TypeError('Expecting an iterable')

pads = Tuple(*pads)
rank = len(pads)
tag = tag or random_string( 6 )
name = v
tag = tag or random_string(6)

return Basic.__new__(cls, pads, rank, name, tag, dtype)

@property
Expand Down Expand Up @@ -1299,9 +1308,10 @@ def __new__(cls, trials, tests, expr, dim, tag=None, outer=None,
pads = Pads(tests, trials, tests_degree, trials_degree,
tests_multiplicity, trials_multiplicity)

rank = 2*dim
tag = tag or random_string( 6 )
obj = Basic.__new__(cls, pads, rank, trials_multiplicity, tag, expr, dtype)
rank = 2 * dim
tag = tag or random_string(6)

obj = Basic.__new__(cls, pads, rank, trials_multiplicity, tag, expr, dtype)
obj._trials = trials
obj._tests = tests
obj._outer = outer
Expand Down Expand Up @@ -1350,13 +1360,15 @@ class BlockStencilMatrixGlobalBasis(BlockLinearOperatorNode):
used to describe local dof over an element as a block stencil matrix
"""
def __new__(cls, trials, tests, pads, multiplicity, expr, tag=None, dtype='real'):
if not isinstance(pads, (list, tuple, Tuple)):

if not is_iterable(pads):
raise TypeError('Expecting an iterable')

pads = Tuple(*pads)
rank = 2*len(pads)
tag = tag or random_string( 6 )
obj = Basic.__new__(cls, pads, multiplicity, rank, tag, expr, dtype)
rank = 2 * len(pads)
tag = tag or random_string(6)

obj = Basic.__new__(cls, pads, multiplicity, rank, tag, expr, dtype)
obj._trials = trials
obj._tests = tests
return obj
Expand Down Expand Up @@ -1400,14 +1412,16 @@ class BlockStencilVectorLocalBasis(BlockLinearOperatorNode):
used to describe local dof over an element as a block stencil matrix
"""
def __new__(cls,tests, pads, expr, tag=None, dtype='real'):
if not isinstance(pads, (list, tuple, Tuple)):

if not is_iterable(pads):
raise TypeError('Expecting an iterable')

pads = Tuple(*pads)
rank = len(pads)
tag = tag or random_string( 6 )
obj = Basic.__new__(cls, pads, rank, tag, expr, dtype)
obj._tests = tests
tag = tag or random_string(6)

obj = Basic.__new__(cls, pads, rank, tag, expr, dtype)
obj._tests = tests
return obj

@property
Expand Down Expand Up @@ -1445,14 +1459,16 @@ class BlockStencilVectorGlobalBasis(BlockLinearOperatorNode):
used to describe local dof over an element as a block stencil matrix
"""
def __new__(cls, tests, pads, multiplicity, expr, tag=None, dtype='real'):
if not isinstance(pads, (list, tuple, Tuple)):

if not is_iterable(pads):
raise TypeError('Expecting an iterable')

pads = Tuple(*pads)
rank = len(pads)
tag = tag or random_string( 6 )
obj = Basic.__new__(cls, pads, multiplicity, rank, tag, expr, dtype)
obj._tests = tests
tag = tag or random_string(6)

obj = Basic.__new__(cls, pads, multiplicity, rank, tag, expr, dtype)
obj._tests = tests
return obj

@property
Expand Down Expand Up @@ -1494,8 +1510,10 @@ class ScalarLocalBasis(ScalarNode):
This is used to describe scalar dof over an element
"""
def __new__(cls, u=None, v=None, tag=None, dtype='real'):
tag = tag or random_string( 6 )
obj = Basic.__new__(cls, tag, dtype)

tag = tag or random_string(6)

obj = Basic.__new__(cls, tag, dtype)
obj._test = v
obj._trial = u
return obj
Expand All @@ -1515,14 +1533,16 @@ def trial(self):
@property
def test(self):
return self._test

#==============================================================================
class BlockScalarLocalBasis(ScalarNode):
"""
This is used to describe a block of scalar dofs over an element
"""
def __new__(cls, trials=None, tests=None, expr=None, tag=None, dtype='real'):

tag = tag or random_string( 6 )
tag = tag or random_string(6)

obj = Basic.__new__(cls, tag, dtype)
obj._tests = tests
obj._trials = trials
Expand Down Expand Up @@ -1587,12 +1607,14 @@ class LocalSpanArray(SpanArray):
"""
_rank = 1
_positions = {index_element: 0}

#==============================================================================
class GlobalThreadSpanArray(SpanArray):
"""
This represents the global span array of each thread
"""
_rank = 1

#==============================================================================
class GlobalThreadStarts(ArrayNode):
"""
Expand Down Expand Up @@ -2111,22 +2133,19 @@ def __new__(cls, iterable, index, *, stmts=None, mask=None,
private=None, firstprivate=None, lastprivate=None,
reduction=None):
# ...
if not( isinstance(iterable, (list, tuple, Tuple)) ):
if not is_iterable(iterable):
iterable = [iterable]

iterable = Tuple(*iterable)
# ...

# ... replace GeometryExpressions by a list of expressions
others = [i for i in iterable if not isinstance(i, GeometryExpressions)]
geos = [i.expressions for i in iterable if isinstance(i, GeometryExpressions)]

iterable = others + flatten(geos)
iterable = Tuple(*iterable)
iterable = Tuple(*others, *flatten(geos))
# ...

# ...
if not( isinstance(index, IndexNode) ):
if not isinstance(index, IndexNode):
raise TypeError('Expecting an index node')
# ...

Expand All @@ -2135,7 +2154,7 @@ def __new__(cls, iterable, index, *, stmts=None, mask=None,
iterator = []
generator = []
for a in iterable:
i,g = construct_itergener(a, index)
i, g = construct_itergener(a, index)
iterator.append(i)
generator.append(g)
# ...
Expand All @@ -2147,8 +2166,7 @@ def __new__(cls, iterable, index, *, stmts=None, mask=None,
# ...
if stmts is None:
stmts = []

elif not isinstance(stmts, (tuple, list, Tuple)):
elif not is_iterable(stmts):
stmts = [stmts]

stmts = Tuple(*stmts)
Expand Down Expand Up @@ -2263,10 +2281,10 @@ class ProductIteration(BaseNode):

def __new__(cls, iterator, generator):
# ...
if not( isinstance(iterator, ProductIterator) ):
if not isinstance(iterator, ProductIterator):
raise TypeError('Expecting an ProductIterator')

if not( isinstance(generator, ProductGenerator) ):
if not isinstance(generator, ProductGenerator):
raise TypeError('Expecting a ProductGenerator')
# ...

Expand All @@ -2285,11 +2303,12 @@ class SplitArray(BaseNode):
"""
"""
def __new__(cls, target, positions, lengths):
if not isinstance(positions, (list, tuple, Tuple)):

if not is_iterable(positions):
positions = [positions]
positions = Tuple(*positions)

if not isinstance(lengths, (list, tuple, Tuple)):
if not is_iterable(lengths):
lengths = [lengths]
lengths = Tuple(*lengths)

Expand Down Expand Up @@ -2391,10 +2410,11 @@ class Block(Basic):

"""
def __new__(cls, body):
if not isinstance(body, (list, tuple, Tuple)):
body = [body]

if not is_iterable(body):
body = [body]
body = Tuple(*body)

return Basic.__new__(cls, body)

@property
Expand Down
Loading
Loading