Describe the bug
The MFD hydrology functions validate that secondary/companion rasters are 2-D DataArrays, but they never check that the companion raster's shape matches the primary MFD grid shape (H, W). Pass a mismatched companion raster and the CPU kernel reads out of bounds and returns uninitialized garbage instead of raising.
Reproduced with an (8, 3, 3) MFD flow-direction grid and a (1, 1) start_points raster:
import numpy as np, xarray as xr
from xrspatial.hydro import flow_path_mfd
fr = xr.DataArray(np.zeros((8, 3, 3)), dims=('d', 'y', 'x'))
sp = xr.DataArray(np.array([[5.0]]), dims=('y', 'x'))
out = flow_path_mfd(fr, sp) # no error; returns garbage
The same missing-shape-check shows up in:
flow_path_mfd (start_points)
watershed_mfd (pour_points)
hand_mfd (flow_accum, elevation)
stream_order_mfd (flow_accum)
stream_link_mfd (flow_accum)
Expected behavior
Each function should check that the companion raster shape matches the primary grid (H, W) and raise a clear ValueError before any kernel indexing happens.
Additional context
Follow-up to #1425, which added _validate_raster on the secondary args but only checked type and ndim, not shape.
Describe the bug
The MFD hydrology functions validate that secondary/companion rasters are 2-D DataArrays, but they never check that the companion raster's shape matches the primary MFD grid shape (H, W). Pass a mismatched companion raster and the CPU kernel reads out of bounds and returns uninitialized garbage instead of raising.
Reproduced with an (8, 3, 3) MFD flow-direction grid and a (1, 1) start_points raster:
The same missing-shape-check shows up in:
flow_path_mfd(start_points)watershed_mfd(pour_points)hand_mfd(flow_accum, elevation)stream_order_mfd(flow_accum)stream_link_mfd(flow_accum)Expected behavior
Each function should check that the companion raster shape matches the primary grid (H, W) and raise a clear ValueError before any kernel indexing happens.
Additional context
Follow-up to #1425, which added
_validate_rasteron the secondary args but only checked type and ndim, not shape.