Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions monai/csrc/ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,20 @@ PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {

// resample bound mode
py::enum_<monai::BoundType>(m, "BoundType")
.value("replicate", monai::BoundType::Replicate)
.value("dct1", monai::BoundType::DCT1)
.value("dct2", monai::BoundType::DCT2)
.value("dst1", monai::BoundType::DST1)
.value("dst2", monai::BoundType::DST2)
.value("dft", monai::BoundType::DFT)
.value("sliding", monai::BoundType::Sliding)
.value("zero", monai::BoundType::Zero)
.value("replicate", monai::BoundType::Replicate, "a a a | a b c d | d d d")
.value("nearest", monai::BoundType::Replicate, "a a a | a b c d | d d d")
.value("dct1", monai::BoundType::DCT1, "d c b | a b c d | c b a")
.value("mirror", monai::BoundType::DCT1, "d c b | a b c d | c b a")
.value("dct2", monai::BoundType::DCT2, "c b a | a b c d | d c b")
.value("reflect", monai::BoundType::DCT2, "c b a | a b c d | d c b")
.value("dst1", monai::BoundType::DST1, "-b -a 0 | a b c d | 0 -d -c")
.value("antimirror", monai::BoundType::DST1, "-b -a 0 | a b c d | 0 -d -c")
.value("dst2", monai::BoundType::DST2, "-c -b -a | a b c d | -d -c -b")
.value("antireflect", monai::BoundType::DST2, "-c -b -a | a b c d | -d -c -b")
.value("dft", monai::BoundType::DFT, "b c d | a b c d | a b c")
.value("wrap", monai::BoundType::DFT, "b c d | a b c d | a b c")
// .value("sliding", monai::BoundType::Sliding)
.value("zero", monai::BoundType::Zero, "0 0 0 | a b c d | 0 0 0")
.export_values();

// resample interpolation mode
Expand Down
22 changes: 13 additions & 9 deletions monai/csrc/resample/pushpull.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ at::Tensor grid_pull(
CHECK_STRIDED(grid_opt)
CHECK_SAME_DEVICE(input_opt, grid_opt)
CHECK_SAME_DTYPE(input_opt, grid_opt)
CHECK_SPATIAL_2D_OR_3D(input)
CHECK_SPATIAL_2D_OR_3D(grid)
CHECK_SPATIAL_1D_2D_OR_3D(input)
CHECK_SPATIAL_1D_2D_OR_3D(grid)
CHECK_GRID_COMPONENT(grid, grid.dim())
CHECK_SPATIAL_NOT_EMPTY(input)
CHECK_SPATIAL_NOT_EMPTY(grid)
Expand Down Expand Up @@ -165,8 +165,8 @@ at::Tensor grid_push(
CHECK_STRIDED(grid_opt)
CHECK_SAME_DEVICE(input_opt, grid_opt)
CHECK_SAME_DTYPE(input_opt, grid_opt)
CHECK_SPATIAL_2D_OR_3D(input)
CHECK_SPATIAL_2D_OR_3D(grid)
CHECK_SPATIAL_1D_2D_OR_3D(input)
CHECK_SPATIAL_1D_2D_OR_3D(grid)
CHECK_GRID_COMPONENT(grid, grid.dim())
CHECK_SPATIAL_NOT_EMPTY(input)
CHECK_SPATIAL_NOT_EMPTY(grid)
Expand All @@ -175,7 +175,10 @@ at::Tensor grid_push(
CHECK_VEC_NOT_EMPTY(interpolation_mode);

if (source_size.empty()) {
auto size = c10::IntArrayRef({input.size(2), input.size(3), input.dim() == 5 ? input.size(4) : 1});
auto size = c10::IntArrayRef(
{input.dim() >= 3 ? input.size(2) : 1,
input.dim() >= 4 ? input.size(3) : 1,
input.dim() >= 5 ? input.size(4) : 1});
if (input.is_cuda())
#ifdef WITH_CUDA
return cuda::pushpull(
Expand Down Expand Up @@ -295,14 +298,15 @@ at::Tensor grid_count(
CHECK_DEFINED(grid)
auto grid_opt = grid.options();
CHECK_STRIDED(grid_opt)
CHECK_SPATIAL_2D_OR_3D(grid)
CHECK_SPATIAL_1D_2D_OR_3D(grid)
CHECK_GRID_COMPONENT(grid, grid.dim())
CHECK_SPATIAL_NOT_EMPTY(grid)
CHECK_VEC_NOT_EMPTY(bound_mode);
CHECK_VEC_NOT_EMPTY(interpolation_mode);

if (source_size.empty()) {
auto size = c10::IntArrayRef({grid.size(1), grid.size(2), grid.dim() == 5 ? grid.size(3) : 1});
auto size = c10::IntArrayRef(
{grid.dim() >= 3 ? grid.size(2) : 1, grid.dim() >= 4 ? grid.size(3) : 1, grid.dim() >= 5 ? grid.size(4) : 1});
if (grid.is_cuda())
#ifdef WITH_CUDA
return cuda::pushpull(
Expand Down Expand Up @@ -422,8 +426,8 @@ at::Tensor grid_grad(
CHECK_STRIDED(grid_opt)
CHECK_SAME_DEVICE(input_opt, grid_opt)
CHECK_SAME_DTYPE(input_opt, grid_opt)
CHECK_SPATIAL_2D_OR_3D(input)
CHECK_SPATIAL_2D_OR_3D(grid)
CHECK_SPATIAL_1D_2D_OR_3D(input)
CHECK_SPATIAL_1D_2D_OR_3D(grid)
CHECK_GRID_COMPONENT(grid, grid.dim())
CHECK_SPATIAL_NOT_EMPTY(input)
CHECK_SPATIAL_NOT_EMPTY(grid)
Expand Down
Loading