mirror of
https://github.com/smyalygames/FiniteVolumeGPU.git
synced 2025-09-14 11:12:17 +02:00
fix(common): change assert to raise in Array2D
This commit is contained in:
parent
d1df00267a
commit
b8836f4fb0
@ -36,4 +36,14 @@ class BaseArray2D(object):
|
||||
raise ValueError("Wrong size of data type")
|
||||
|
||||
if np.isfortran(cpu_data):
|
||||
raise TypeError("Wrong datatype (Fortran, expected C)")
|
||||
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
|
||||
|
@ -25,4 +25,4 @@ class ArakawaA2D(BaseArakawaA2D):
|
||||
+ f"has average {var_sum / (gpu_variable.nx * gpu_variable.ny)}")
|
||||
|
||||
if np.isnan(var_sum):
|
||||
raise ValueError("Data contains NaN values!")
|
||||
raise ValueError("Data contains NaN values!")
|
||||
|
@ -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()
|
||||
@ -113,4 +107,4 @@ class CudaArray2D(BaseArray2D):
|
||||
copy.width_in_bytes = int(nx) * cpu_data.itemsize
|
||||
copy.height = int(ny)
|
||||
|
||||
copy(stream)
|
||||
copy(stream)
|
||||
|
Loading…
x
Reference in New Issue
Block a user