Converters Module

Memory conversion public API for OpenHCS.

convert_memory(data, source_type, target_type, gpu_id)[source]

Convert data between memory types using the unified converter infrastructure.

Parameters:
  • data (Any) – The data to convert

  • source_type (str) – The source memory type (e.g., “numpy”, “torch”)

  • target_type (str) – The target memory type (e.g., “cupy”, “jax”)

  • gpu_id (int) – The target GPU device ID

Return type:

Any

Returns:

The converted data in the target memory type

Raises:
detect_memory_type(data)[source]

Detect the memory type of data using framework config.

Parameters:

data (Any) – The data to detect

Return type:

str

Returns:

The detected memory type string (e.g., “numpy”, “torch”)

Raises:

ValueError – If memory type cannot be detected

Main Functions

convert_memory

convert_memory(data, source_type, target_type, gpu_id)[source]

Convert data between memory types using the unified converter infrastructure.

Parameters:
  • data (Any) – The data to convert

  • source_type (str) – The source memory type (e.g., “numpy”, “torch”)

  • target_type (str) – The target memory type (e.g., “cupy”, “jax”)

  • gpu_id (int) – The target GPU device ID

Return type:

Any

Returns:

The converted data in the target memory type

Raises:

detect_memory_type

detect_memory_type(data)[source]

Detect the memory type of data using framework config.

Parameters:

data (Any) – The data to detect

Return type:

str

Returns:

The detected memory type string (e.g., “numpy”, “torch”)

Raises:

ValueError – If memory type cannot be detected

Examples

Basic Conversion

from arraybridge import convert_memory
import numpy as np

data = np.array([1, 2, 3])
result = convert_memory(data, 'numpy', 'torch', gpu_id=0)

Type Detection

from arraybridge import detect_memory_type
import numpy as np

data = np.array([1, 2, 3])
mem_type = detect_memory_type(data)
print(mem_type)  # 'numpy'