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:
- Return type:
- Returns:
The converted data in the target memory type
- Raises:
ValueError – If source_type or target_type is invalid
MemoryConversionError – If conversion fails
- detect_memory_type(data)[source]
Detect the memory type of data using framework config.
- Parameters:
data (
Any) – The data to detect- Return type:
- 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:
- Return type:
- Returns:
The converted data in the target memory type
- Raises:
ValueError – If source_type or target_type is invalid
MemoryConversionError – If conversion fails
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:
- 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'