Skip to content

Commit

Permalink
compiler: Edit _C_ctype property of PETScFunction to utilise CustomDtype
Browse files Browse the repository at this point in the history
  • Loading branch information
ZoeLeibowitz committed Dec 22, 2023
1 parent 1d821de commit 544ea95
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
12 changes: 4 additions & 8 deletions devito/types/petsc.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from devito.tools import (dtype_to_petsctype, CustomDtype,
dtype_to_ctype)
from devito.tools import dtype_to_petsctype, CustomDtype
from devito.types import LocalObject
from devito.types.array import ArrayBasic
from ctypes import POINTER
import numpy as np


Expand Down Expand Up @@ -77,11 +75,9 @@ def __dtype_setup__(cls, **kwargs):
@property
def _C_ctype(self):
petsc_type = dtype_to_petsctype(self.dtype)
ctype = dtype_to_ctype(self.dtype)
r = type(petsc_type, (ctype,), {})
for n in range(len(self.dimensions)):
r = POINTER(r)
return r
modifier = '*' * len(self.dimensions)
customtype = CustomDtype(petsc_type, modifier=modifier)
return customtype

@property
def _C_name(self):
Expand Down
10 changes: 5 additions & 5 deletions tests/test_petsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def test_petsc_functions():

expr = DummyExpr(ptr0.indexed[x, y], ptr1.indexed[x, y] + 1)

assert str(defn0) == 'PetscScalar **restrict ptr0;'
assert str(defn1) == 'const PetscScalar **restrict ptr1;'
assert str(defn2) == 'const PetscScalar **restrict ptr2;'
assert str(defn3) == 'PetscInt **restrict ptr3;'
assert str(defn4) == 'const PetscInt **restrict ptr4;'
assert str(defn0) == 'PetscScalar**restrict ptr0;'
assert str(defn1) == 'const PetscScalar**restrict ptr1;'
assert str(defn2) == 'const PetscScalar**restrict ptr2;'
assert str(defn3) == 'PetscInt**restrict ptr3;'
assert str(defn4) == 'const PetscInt**restrict ptr4;'
assert str(expr) == 'ptr0[x][y] = ptr1[x][y] + 1;'

0 comments on commit 544ea95

Please sign in to comment.