{"record":{"id":"f22a9e57d72f8cb9","repo":"tracel-ai/burn","slug":"todo-grid-sample-2d-with-mode-is-not-implem","errorCode":null,"errorMessage":"todo!(\"grid_sample_2d with {:?} mode is not implemented\", options.mode)","messagePattern":"todo!\\(\"grid_sample_2d with (.+?) mode is not implemented\", options\\.mode\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-ndarray/src/ops/grid_sample.rs","lineNumber":31,"sourceCode":"///\n/// # Arguments\n///\n/// * `tensor` - The tensor being sampled from, must be contiguous with shape (N, C, H_in, W_in)\n/// * `grid` - A tensor of locations, with shape (N, H_out, W_out, 2). Values are [-1, 1].\n///   A [x = -1, y = -1] means top-left, and [x = 1, y = 1] means bottom-right\n/// * `options` - Grid sampling options (mode, padding_mode, align_corners)\n///\n/// # Returns\n///\n/// A tensor with shape (N, C, H_out, W_out)\npub(crate) fn grid_sample_2d<E: FloatNdArrayElement>(\n    tensor: SharedArray<E>,\n    grid: SharedArray<E>,\n    options: GridSampleOptions,\n) -> SharedArray<E> {\n    match options.mode {\n        InterpolateMode::Bilinear => (),\n        _ => todo!(\n            \"grid_sample_2d with {:?} mode is not implemented\",\n            options.mode\n        ),\n    }\n\n    let tensor = tensor.into_dimensionality::<ndarray::Ix4>().unwrap();\n    let grid = grid.into_dimensionality::<ndarray::Ix4>().unwrap();\n\n    let (batch_size, channels, height_in, width_in) = tensor.dim();\n    let (b, height_out, width_out, d) = grid.dim();\n    assert!(batch_size == b);\n    assert!(2 == d);\n\n    let mut output = Array4::zeros((batch_size, channels, height_out, width_out));\n    let unsafe_shared_out = UnsafeSharedRef::new(&mut output);\n\n    let sample_count = batch_size * channels * height_out * width_out;\n    let strides = (","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-ndarray/src/ops/grid_sample.rs#L13-L49","documentation":"grid_sample_2d in the ndarray backend (crates/burn-ndarray/src/ops/grid_sample.rs:31) only implements InterpolateMode::Bilinear; any other interpolation mode (e.g. Nearest, Bicubic) hits a todo! panic. The grid itself is prepared, but the mode gate runs before any computation.","triggerScenarios":"Calling Tensor::grid_sample (grid_sample_2d) with GridSampleOptions whose mode is anything other than Bilinear while using the NdArray backend.","commonSituations":"Porting a model that uses nearest-neighbor grid sampling (common in segmentation/stylization models) to CPU/ndarray; code that works on CUDA/WGPU backends panics on ndarray.","solutions":["Switch GridSampleOptions to InterpolateMode::Bilinear if acceptable for your model.","Use a backend with full grid_sample support (e.g. cubecl/CUDA) for this op.","Implement nearest mode in burn-ndarray's grid_sample and upstream a PR."],"exampleFix":"// before\nlet opts = GridSampleOptions::new(InterpolateMode::Nearest, PaddingMode::Zeros);\nlet out = grid.grid_sample(opts);\n// after\nlet opts = GridSampleOptions::new(InterpolateMode::Bilinear, PaddingMode::Zeros);\nlet out = grid.grid_sample(opts);","handlingStrategy":"validation","validationCode":"assert!(matches!(options.mode, InterpolateMode::Bilinear), \"ndarray backend grid_sample only supports Bilinear\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use InterpolateMode::Bilinear when grid-sampling on the ndarray backend.","Gate model code on backend capabilities when porting from GPU backends.","Add a config check that rejects non-bilinear grid_sample modes for CPU targets."],"tags":["rust","burn","ndarray","grid-sample","unimplemented"],"backgroundTag":"op-not-implemented-for-backend","analyzedSha":"d16f7ba2ed0d41408189384044cc886fb4c8f957","analyzedAt":"2026-09-05T13:19:14.260Z","contentChangedAt":"2026-09-05T13:19:14.260Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}