Skip to content

Commit a65689e

Browse files
Slightly improve performance in engines/utils.py (#8747)
### Description This change probably improves performance slightly (unforetunately, I don't have a local instance of MONAI installed in order to test this, but I'm pretty sure from looking at the code that using [], {} and kwargs_[k] = _get_data(v) should be semantically the same and probably slightly better in performance, see also #1423 (credits to @de-sh for the nice fix 👍 ) where at least [] and {} were changed as a refactoring and kwargs_[k] = _get_data(v) just seems better to me becuase I think that this saves some time due to dictionary lookups and temporary objects, but I'm not quite sure because it wasn't tested, so please correct me if I'm mistaken). A few sentences describing the changes proposed in this pull request. ### 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: Benedikt Johannes <benedikt.johannes.hofer@gmail.com>
1 parent 55c724f commit a65689e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

monai/engines/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ def __call__(
219219
`kwargs` supports other args for `Tensor.to()` API.
220220
"""
221221
image, label = default_prepare_batch(batchdata, device, non_blocking, **kwargs)
222-
args_ = list()
223-
kwargs_ = dict()
222+
args_ = []
223+
kwargs_ = {}
224224

225225
def _get_data(key: str) -> torch.Tensor:
226226
data = batchdata[key]

0 commit comments

Comments
 (0)