Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
Generic OpaqueType, use static instance mat_dtype, and remove the cla…
Browse files Browse the repository at this point in the history
…ss PetscMatType()
  • Loading branch information
pbrubeck committed Sep 28, 2023
1 parent e5d74f2 commit 21a8200
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 32 deletions.
6 changes: 3 additions & 3 deletions pyop2/codegen/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
PreUnpackInst, Product, RuntimeIndex,
Sum, Symbol, UnpackInst, Variable,
When, Zero)
from pyop2.datatypes import IntType, PetscMatType
from pyop2.datatypes import IntType, mat_dtype
from pyop2.op2 import (ALL, INC, MAX, MIN, ON_BOTTOM, ON_INTERIOR_FACETS,
ON_TOP, READ, RW, WRITE)
from pyop2.utils import cached_property
Expand Down Expand Up @@ -871,7 +871,7 @@ def add_argument(self, arg):
pack = MixedDatPack(packs, access, dtype,
interior_horizontal=interior_horizontal)
elif isinstance(arg, MatKernelArg):
argument = Argument((), PetscMatType(), pfx="mat")
argument = Argument((), mat_dtype, pfx="mat")
maps = tuple(self._add_map(m, arg.unroll)
for m in arg.maps)
pack = arg.pack(argument, access, maps,
Expand All @@ -881,7 +881,7 @@ def add_argument(self, arg):
elif isinstance(arg, MixedMatKernelArg):
packs = []
for a in arg:
argument = Argument((), PetscMatType(), pfx="mat")
argument = Argument((), mat_dtype, pfx="mat")
maps = tuple(self._add_map(m, a.unroll)
for m in a.maps)

Expand Down
31 changes: 4 additions & 27 deletions pyop2/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,34 +71,11 @@ def dtype_limits(dtype):
return info.min, info.max


class PetscObjectType(lp.types.OpaqueType):
def __init__(self, name="PetscObject"):
class OpaqueType(lp.types.OpaqueType):
def __init__(self, name):
super().__init__(name=name)

def __repr__(self):
return type(self).__name__
return self.name


class PetscISType(PetscObjectType):
def __init__(self):
super().__init__(name="IS")


class PetscVecType(PetscObjectType):
def __init__(self):
super().__init__(name="Vec")


class PetscMatType(PetscObjectType):
def __init__(self):
super().__init__(name="Mat")


class PetscPCType(PetscObjectType):
def __init__(self):
super().__init__(name="PC")


class PetscKSPType(PetscObjectType):
def __init__(self):
super().__init__(name="KSP")
mat_dtype = OpaqueType("Mat")
2 changes: 1 addition & 1 deletion pyop2/op2.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import atexit

from pyop2.configuration import configuration
from pyop2.datatypes import PetscISType, PetscVecType, PetscMatType, PetscPCType, PetscKSPType # noqa: F401
from pyop2.datatypes import mat_dtype # noqa: F401
from pyop2.logger import debug, info, warning, error, critical, set_log_level
from pyop2.mpi import MPI, COMM_WORLD, collective

Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_direct_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def test_passthrough_mat(self):
petsc_mat.setValues([0, 2, 4], [0, 2, 4], np.zeros((3, 3), dtype=PETSc.ScalarType))
petsc_mat.assemble()

arg = op2.PassthroughArg(op2.PetscMatType(), petsc_mat.handle)
arg = op2.PassthroughArg(op2.mat_dtype, petsc_mat.handle)
op2.par_loop(kernel, iterset, arg)
petsc_mat.assemble()

Expand Down

0 comments on commit 21a8200

Please sign in to comment.