Skip to content

Commit ba1adea

Browse files
waltsimsclaude
andcommitted
Use .shape[-1] instead of len([0]) for source flag values
Safer for both 1-D and 2-D source arrays and communicates intent more clearly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c5b35b7 commit ba1adea

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

kwave/solvers/cpp_simulation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,11 @@ def _write_hdf5(self, filepath):
198198
# NOTE: Despite the name "*_source_flag", the C++ binary expects
199199
# the number of time points in the source signal (not a boolean).
200200
# 0 = no source, >0 = number of time steps in the source signal.
201-
"p_source_flag": len(source.p[0]) if has_p else 0,
201+
"p_source_flag": np.asarray(source.p).shape[-1] if has_p else 0,
202202
"p0_source_flag": int(has_p0),
203-
"ux_source_flag": len(source.ux[0]) if has_ux else 0,
204-
"uy_source_flag": len(source.uy[0]) if has_uy else 0,
205-
"uz_source_flag": len(source.uz[0]) if has_uz else 0,
203+
"ux_source_flag": np.asarray(source.ux).shape[-1] if has_ux else 0,
204+
"uy_source_flag": np.asarray(source.uy).shape[-1] if has_uy else 0,
205+
"uz_source_flag": np.asarray(source.uz).shape[-1] if has_uz else 0,
206206
"sxx_source_flag": 0,
207207
"syy_source_flag": 0,
208208
"szz_source_flag": 0,

0 commit comments

Comments
 (0)