def get_data_address(x):
    """Returns memory address where a numpy or cupy array's data is stored."""
    if hasattr(x, '__array_interface__'):
        ptr_x = x.__array_interface__['data'][0]
    elif hasattr(x, '__cuda_array_interface__'):
        ptr_x = x.__cuda_array_interface__['data'][0]
    else:
        raise ValueError(
            'Input must have an __array_interface__ or __cuda_array_interface__ attribute.'
            )
    return ptr_x
