MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / ToCupy

Class ToCupy

monai/transforms/utility/array.py:526–550  ·  view source on GitHub ↗

Converts the input data to CuPy array, can support list or tuple of numbers, NumPy and PyTorch Tensor. Args: dtype: data type specifier. It is inferred from the input by default. if not None, must be an argument of `numpy.dtype`, for more details: https://do

Source from the content-addressed store, hash-verified

524
525
526class ToCupy(Transform):
527 """
528 Converts the input data to CuPy array, can support list or tuple of numbers, NumPy and PyTorch Tensor.
529
530 Args:
531 dtype: data type specifier. It is inferred from the input by default.
532 if not None, must be an argument of `numpy.dtype`, for more details:
533 https://docs.cupy.dev/en/stable/reference/generated/cupy.array.html.
534 wrap_sequence: if `False`, then lists will recursively call this function, default to `True`.
535 E.g., if `False`, `[1, 2]` -> `[array(1), array(2)]`, if `True`, then `[1, 2]` -> `array([1, 2])`.
536
537 """
538
539 backend = [TransformBackends.CUPY]
540
541 def __init__(self, dtype: np.dtype | None = None, wrap_sequence: bool = True) -> None:
542 super().__init__()
543 self.dtype = dtype
544 self.wrap_sequence = wrap_sequence
545
546 def __call__(self, data: NdarrayOrTensor):
547 """
548 Create a CuPy array from `data` and make it contiguous
549 """
550 return convert_to_cupy(data, dtype=self.dtype, wrap_sequence=self.wrap_sequence)
551
552
553class ToPIL(Transform):

Callers 11

__init__Method · 0.90
get_label_ccpFunction · 0.90
test_cupy_inputMethod · 0.90
test_cupy_input_dtypeMethod · 0.90
test_numpy_inputMethod · 0.90
test_tensor_inputMethod · 0.90
test_list_tupleMethod · 0.90

Calls

no outgoing calls

Tested by 9

test_cupy_inputMethod · 0.72
test_cupy_input_dtypeMethod · 0.72
test_numpy_inputMethod · 0.72
test_tensor_inputMethod · 0.72
test_list_tupleMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…