fix(common): change assert to raise in Array2D

This commit is contained in:
Anthony Berg 2025-06-24 21:17:13 +02:00
parent d1df00267a
commit b8836f4fb0
3 changed files with 15 additions and 11 deletions

View File

@ -37,3 +37,13 @@ class BaseArray2D(object):
if np.isfortran(cpu_data):
raise TypeError("Wrong datatype (Fortran, expected C)")
def check(self, x, y, nx, ny, cpu_data):
if nx != cpu_data.shape[1]:
raise ValueError
if ny != cpu_data.shape[0]:
raise ValueError
if x + nx > self.nx + 2 * self.x_halo:
raise ValueError
if y + ny > self.ny + 2 * self.y_halo:
raise ValueError

View File

@ -58,10 +58,7 @@ class CudaArray2D(BaseArray2D):
# Non-pagelocked: cpu_data = np.empty((ny, nx), dtype=np.float32)
# cpu_data = self.memorypool.allocate((ny, nx), dtype=np.float32)
assert nx == cpu_data.shape[1]
assert ny == cpu_data.shape[0]
assert x + nx <= self.nx + 2 * self.x_halo
assert y + ny <= self.ny + 2 * self.y_halo
self.check(x, y, nx, ny, cpu_data)
# Create a copy object from device to host
copy = cuda.Memcpy2D()
@ -93,10 +90,7 @@ class CudaArray2D(BaseArray2D):
else:
x, y, nx, ny = extent
assert (nx == cpu_data.shape[1])
assert (ny == cpu_data.shape[0])
assert (x + nx <= self.nx + 2 * self.x_halo)
assert (y + ny <= self.ny + 2 * self.y_halo)
self.check(x, y, nx, ny, cpu_data)
# Create a copy object from device to host
copy = cuda.Memcpy2D()