(type_obj: Any)
return my_dtype, my_ctype
Given a type name string (or an object having a __name__ attribute), return matching Numpy and ctypes types that have the same size in bytes.
Given a type name string (or an object having a __name__ attribute), return matching Numpy and ctypes types that have the same size in bytes.
Given a type name string ( or an object having a __name__ attribute ) return matching Numpy and ctypes types that have the same size in bytes .
def get_dtype_and_ctype(type_obj: Any) -> Tuple[np.dtype, Any]:
    """Given a type name string (or an object having a __name__ attribute), return matching Numpy and ctypes types that have the same size in bytes."""
    type_str = None

    if isinstance(type_obj, str):
        type_str = type_obj
    elif hasattr(type_obj, "__name__"):
        type_str = type_obj.__name__
    elif hasattr(type_obj, "name"):
        type_str = type_obj.name
    else:
        raise RuntimeError("Cannot infer type name from input")

    assert type_str in _str_to_ctype.keys()

    my_dtype = np.dtype(type_str)
    my_ctype = _str_to_ctype[type_str]

    assert my_dtype.itemsize == ctypes.sizeof(my_ctype)

    return my_dtype, my_ctype
def get_dtype_and_ctype ( type_obj : Any ) -> Tuple [ np . dtype , Any ] : type_str = None if isinstance ( type_obj , str ) : type_str = type_obj elif hasattr ( type_obj , "__name__" ) : type_str = type_obj . __name__ elif hasattr ( type_obj , "name" ) : type_str = type_obj . name else : raise RuntimeError ( "Cannot infer type name from input" ) assert type_str in _str_to_ctype . keys ( ) my_dtype = np . dtype ( type_str ) my_ctype = _str_to_ctype [ type_str ] assert my_dtype . itemsize == ctypes . sizeof ( my_ctype ) return my_dtype , my_ctype