#NEWLINE# def get_device( * args ) : #NEWLINE# #INDENT# 'Gets the device from an ID integer or an array object.\n\n    This is a convenient utility to select a correct device if the type of\n    ``arg`` is unknown (i.e., one can use this function on arrays that may be\n    on CPU or GPU). The returned device object supports the context management\n    protocol of Python for the *with* statement.\n\n    Args:\n        args: Values to specify a GPU device. :class:`numpy.ndarray` objects\n            are skipped. If all arguments are :class:`numpy.ndarray` objects,\n            it returns a dummy device object. Otherwise, the first\n            non-:mod:`numpy` object is used to select a device. If it is a\n            :class:`cupy.ndarray` object, its device is returned. Otherwise,\n            the argument is passed to the initializer of\n            :class:`~cupy.cuda.Device` and it is returned.\n\n    Returns:\n        Device object specified by given ``args``.\n\n    .. seealso::\n       See :class:`cupy.cuda.Device` for the device selection not by arrays.\n\n    ' #NEWLINE# for arg in arg : #NEWLINE# #INDENT# if ( arg is None ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( not isinstance ( arg , numpy . ndarray ) ) : #NEWLINE# #INDENT# check_cuda_available ( ) #NEWLINE# if isinstance ( arg , cupy . ndarray ) : #NEWLINE# #INDENT# if ( arg . device is None ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# return arg . device #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return Device ( arg ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return DummyDevice