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

Andrew add tests to test operator 2194 #2207

Merged
Next Next commit
compiler: Simplify SubFunction
  • Loading branch information
FabioLuporini authored and mloubout committed Sep 8, 2023
commit cb919a6cbaa0cb12ffd68fc3e378955c56316398
18 changes: 4 additions & 14 deletions devito/types/dense.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from devito.finite_differences import Differentiable, generate_fd_shortcuts
from devito.tools import (ReducerMap, as_tuple, c_restrict_void_p, flatten, is_integer,
memoized_meth, dtype_to_ctype, humanbytes)
from devito.types.dimension import Dimension
from devito.types.dimension import Dimension, DynamicDimension
from devito.types.args import ArgProvider
from devito.types.caching import CacheManager
from devito.types.basic import AbstractFunction, Size
Expand Down Expand Up @@ -1449,16 +1449,10 @@ class SubFunction(Function):
"""
A Function bound to a "parent" DiscreteFunction.

A SubFunction hands control of argument binding and halo exchange to its
parent DiscreteFunction.
A SubFunction hands control of argument binding and halo exchange to the
DiscreteFunction it's bound to.
"""

__rkwargs__ = Function.__rkwargs__ + ('parent',)

def __init_finalize__(self, *args, **kwargs):
super(SubFunction, self).__init_finalize__(*args, **kwargs)
self._parent = kwargs['parent']

def __padding_setup__(self, **kwargs):
# SubFunctions aren't expected to be used in time-consuming loops
return tuple((0, 0) for i in range(self.ndim))
Expand All @@ -1470,12 +1464,8 @@ def _arg_values(self, **kwargs):
if self.name in kwargs:
raise RuntimeError("`%s` is a SubFunction, so it can't be assigned "
"a value dynamically" % self.name)
else:
return self._parent._arg_defaults(alias=self._parent).reduce_all()

@property
def parent(self):
return self._parent
return self._arg_defaults(alias=self)

@property
def origin(self):
Expand Down
23 changes: 16 additions & 7 deletions devito/types/sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,15 @@ class PrecomputedSparseTimeFunction(AbstractSparseTimeFunction,
PrecomputedSparseFunction.__rkwargs__))


# *** MatrixSparse*Function API
# This is mostly legacy stuff which often escapes the devito's modus operandi

class DynamicSubFunction(SubFunction):

def _arg_defaults(self, **kwargs):
return {}


class MatrixSparseTimeFunction(AbstractSparseTimeFunction):
"""
A specialised type of SparseTimeFunction where the interpolation is externally
Expand Down Expand Up @@ -1378,7 +1387,7 @@ def __init_finalize__(self, *args, **kwargs):
else:
nnz_size = 1

self._mrow = SubFunction(
self._mrow = DynamicSubFunction(
name='mrow_%s' % self.name,
dtype=np.int32,
dimensions=(self.nnzdim,),
Expand All @@ -1387,7 +1396,7 @@ def __init_finalize__(self, *args, **kwargs):
parent=self,
allocator=self._allocator,
)
self._mcol = SubFunction(
self._mcol = DynamicSubFunction(
name='mcol_%s' % self.name,
dtype=np.int32,
dimensions=(self.nnzdim,),
Expand All @@ -1396,7 +1405,7 @@ def __init_finalize__(self, *args, **kwargs):
parent=self,
allocator=self._allocator,
)
self._mval = SubFunction(
self._mval = DynamicSubFunction(
name='mval_%s' % self.name,
dtype=self.dtype,
dimensions=(self.nnzdim,),
Expand All @@ -1413,8 +1422,8 @@ def __init_finalize__(self, *args, **kwargs):
self.par_dim_to_nnz_dim = DynamicDimension('par_dim_to_nnz_%s' % self.name)

# This map acts as an indirect sort of the sources according to their
# position along the parallelisation Dimension
self._par_dim_to_nnz_map = SubFunction(
# position along the parallelisation dimension
self._par_dim_to_nnz_map = DynamicSubFunction(
name='par_dim_to_nnz_map_%s' % self.name,
dtype=np.int32,
dimensions=(self.par_dim_to_nnz_dim,),
Expand All @@ -1423,7 +1432,7 @@ def __init_finalize__(self, *args, **kwargs):
space_order=0,
parent=self,
)
self._par_dim_to_nnz_m = SubFunction(
self._par_dim_to_nnz_m = DynamicSubFunction(
name='par_dim_to_nnz_m_%s' % self.name,
dtype=np.int32,
dimensions=(self._par_dim,),
Expand All @@ -1432,7 +1441,7 @@ def __init_finalize__(self, *args, **kwargs):
space_order=0,
parent=self,
)
self._par_dim_to_nnz_M = SubFunction(
self._par_dim_to_nnz_M = DynamicSubFunction(
name='par_dim_to_nnz_M_%s' % self.name,
dtype=np.int32,
dimensions=(self._par_dim,),
Expand Down
1 change: 0 additions & 1 deletion tests/test_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,6 @@ def test_msf_interpolate():

eqn_inject = sf.inject(field=u, expr=sf)
op2 = Operator(eqn_inject)

op2(time_m=0, time_M=4)

# There should be 4 points touched for each source point
Expand Down