Skip to content

Commit 9c7b71f

Browse files
authored
2885 2899 Add support to support subclass of Tensor or numpy array (#2900)
* [DLMED] fix type issue Signed-off-by: Nic Ma <[email protected]> * [DLMED] fix test Signed-off-by: Nic Ma <[email protected]> * [DLMED] simplify the change Signed-off-by: Nic Ma <[email protected]> * [DLMED] fix flake8 Signed-off-by: Nic Ma <[email protected]>
1 parent 245ab94 commit 9c7b71f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

monai/utils/type_conversion.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,14 @@ def convert_data_type(
171171
Returns:
172172
modified data, orig_type, orig_device
173173
"""
174-
orig_type = type(data)
174+
orig_type: Any
175+
if isinstance(data, torch.Tensor):
176+
orig_type = torch.Tensor
177+
elif isinstance(data, np.ndarray):
178+
orig_type = np.ndarray
179+
else:
180+
orig_type = type(data)
181+
175182
orig_device = data.device if isinstance(data, torch.Tensor) else None
176183

177184
output_type = output_type or orig_type

0 commit comments

Comments
 (0)