Commit 1fed118
Fix nested Compose map_items in forward and inverse paths (Project-MONAI#8787)
## Summary
Fixes Project-MONAI#7932, Project-MONAI#7565
When a child `Compose` has a different `map_items` setting than its
parent, the parent's `apply_transform` would expand list/tuple data
before the child ever sees it — silently overriding the child's
`map_items`.
This PR makes three coordinated changes so the child's `map_items` is
respected:
- **Forward path** (`apply_transform`): Skip list expansion when the
transform is a `Compose` instance, letting it handle expansion via its
own `map_items` in `execute_compose`.
- **Inverse path** (`_inverse_one` helper): Delegate directly to
`Compose.inverse()` for nested `Compose` objects (including
`RandomOrder` and `SomeOf`) instead of routing through
`apply_transform(t.inverse, ...)`.
- **`flatten()`**: Only inline nested `Compose` objects that share the
same `map_items` as the parent. Children with a different `map_items`
are preserved as-is.
## Test plan
- [x] `test_child_map_items_false_receives_list` — parent
`map_items=True`, child `map_items=False`: child receives list as-is
- [x] `test_inverse_respects_child_map_items` — inverse roundtrip with
nested Compose
- [x] `test_parent_no_map_child_map` — parent `map_items=False`, child
`map_items=True`: child maps over items
- [x] `test_flatten_preserves_different_map_items` — `flatten()` does
not merge children with different `map_items`
---------
Signed-off-by: Soumya Snigdha Kundu <soumya_snigdha.kundu@kcl.ac.uk>
Co-authored-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>1 parent d1a8557 commit 1fed118
3 files changed
Lines changed: 209 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
40 | 65 | | |
41 | 66 | | |
42 | 67 | | |
| |||
315 | 340 | | |
316 | 341 | | |
317 | 342 | | |
318 | | - | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
319 | 349 | | |
320 | 350 | | |
321 | 351 | | |
322 | 352 | | |
323 | 353 | | |
324 | 354 | | |
325 | 355 | | |
326 | | - | |
| 356 | + | |
327 | 357 | | |
328 | 358 | | |
329 | 359 | | |
330 | 360 | | |
331 | | - | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
332 | 369 | | |
333 | 370 | | |
334 | 371 | | |
| |||
365 | 402 | | |
366 | 403 | | |
367 | 404 | | |
368 | | - | |
369 | | - | |
370 | | - | |
| 405 | + | |
371 | 406 | | |
372 | 407 | | |
373 | 408 | | |
| |||
622 | 657 | | |
623 | 658 | | |
624 | 659 | | |
625 | | - | |
626 | | - | |
627 | | - | |
| 660 | + | |
628 | 661 | | |
629 | 662 | | |
630 | 663 | | |
| |||
789 | 822 | | |
790 | 823 | | |
791 | 824 | | |
792 | | - | |
793 | | - | |
794 | | - | |
| 825 | + | |
795 | 826 | | |
796 | 827 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
150 | 153 | | |
151 | 154 | | |
152 | 155 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
775 | 775 | | |
776 | 776 | | |
777 | 777 | | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
778 | 937 | | |
779 | 938 | | |
780 | 939 | | |
| |||
0 commit comments