11from typing import Union
22
3- from kwave .options .simulation_execution_options import SimulationExecutionOptions
4-
53try :
64 import cupy as cp
75 from cupy import fft as cp_fft
@@ -50,7 +48,7 @@ def get_array_module(verbose: bool = False):
5048 ngpus = cp .cuda .runtime .getDeviceCount ()
5149 if ngpus > 0 :
5250 return cp , True
53- except Exception :
51+ except Exception ( ImportError , RuntimeError , cp . cuda . runtime . CUDARuntimeError ) :
5452 pass
5553
5654 # Fallback (cupy but no gpu) to numpy
@@ -73,7 +71,7 @@ def dotdict_to_gpu(obj, verbose: bool = False):
7371 if isinstance (val , np .ndarray ):
7472 if verbose :
7573 print (f"Converting { name } to cupy array" )
76- setattr ( obj , name , cp .asarray (val ) )
74+ obj [ name ] = cp .asarray (val )
7775 return obj
7876
7977
@@ -86,7 +84,7 @@ def dotdict_to_cpu(obj, verbose: bool = False):
8684 if isinstance (val , cp .ndarray ):
8785 if verbose :
8886 print (f"Converting { name } to numpy array" )
89- setattr ( obj , name , val .get () )
87+ obj [ name ] = val .get ()
9088 return obj
9189
9290
@@ -514,7 +512,7 @@ def kspace_first_order_1D(kgrid: kWaveGrid,
514512
515513
516514 # add in the velocity source term
517- if (k_sim .source_ux is not False and t_index < xp . shape ( source .ux ) [1 ]):
515+ if (k_sim .source_ux is not False and t_index < source .ux . shape [1 ]):
518516 if k_sim .source_ux >= t_index :
519517 match source .u_mode :
520518 case 'dirichlet' :
@@ -564,7 +562,7 @@ def kspace_first_order_1D(kgrid: kWaveGrid,
564562
565563
566564 # add in the pre-scaled pressure source term as a mass source
567- if (k_sim .source_p is not False and t_index < xp . shape ( k_sim .source .p ) [1 ]):
565+ if (k_sim .source_p is not False and t_index < k_sim .source .p . shape [1 ]):
568566 match k_sim .source .p_mode :
569567 case 'dirichlet' :
570568 # enforce source values as a dirichlet boundary condition
0 commit comments