-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instantiation mode
"partial"
to "callable"
. Return the _target_
…
… component as-is when in `_mode_="callable"` and no kwargs are specified (#7413) ### Description A `_target_` component with `_mode_="partial"` will still be wrapped in `functools.partial` even when no kwargs are passed: `functool.partial(component)`. In such cases, the component can just be returned as-is. If you agree with this, I will add tests for it. Thank you! ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: Ibrahim Hadzic <[email protected]>
- Loading branch information
Showing
6 changed files
with
16 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,7 +72,6 @@ def case_pdb_inst(sarg=None): | |
|
||
|
||
class TestClass: | ||
|
||
@staticmethod | ||
def compute(a, b, func=lambda x, y: x + y): | ||
return func(a, b) | ||
|
@@ -127,7 +126,6 @@ def __call__(self, a, b): | |
|
||
|
||
class TestConfigParser(unittest.TestCase): | ||
|
||
def test_config_content(self): | ||
test_config = {"preprocessing": [{"_target_": "LoadImage"}], "dataset": {"_target_": "Dataset"}} | ||
parser = ConfigParser(config=test_config) | ||
|
@@ -183,7 +181,7 @@ def test_function(self, config): | |
parser = ConfigParser(config=config, globals={"TestClass": TestClass}) | ||
for id in config: | ||
if id in ("compute", "cls_compute"): | ||
parser[f"{id}#_mode_"] = "partial" | ||
parser[f"{id}#_mode_"] = "callable" | ||
func = parser.get_parsed_content(id=id) | ||
self.assertTrue(id in parser.ref_resolver.resolved_content) | ||
if id == "error_func": | ||
|
@@ -279,7 +277,7 @@ def test_lambda_reference(self): | |
|
||
def test_non_str_target(self): | ||
configs = { | ||
"fwd": {"_target_": "[email protected]", "x": "$torch.rand(1, 3, 256, 256)", "_mode_": "partial"}, | ||
"fwd": {"_target_": "[email protected]", "x": "$torch.rand(1, 3, 256, 256)", "_mode_": "callable"}, | ||
"model": {"_target_": "monai.networks.nets.resnet.resnet18", "pretrained": False, "spatial_dims": 2}, | ||
} | ||
self.assertTrue(callable(ConfigParser(config=configs).fwd)) | ||
|