def inputs_all_ready(inputs, supported_ndim=(2, 4)): """Checks if input arrays are supported for ideep optimization. Information to be checked includes array types, dimesions and data types. The function checks ``inputs`` info and ``supported_ndim``. Args: inputs (sequence of arrays or variables``): Inputs to be checked. supported_ndim (tuple of ints): Supported ndim values. iDeep supports array dimension in either 2 or 4 only. Returns: bool: ``True`` if all conditions meet. """ if _ideep_version is None: return False inputs = [ x.data if isinstance(x, chainer.variable.Variable) else x for x in inputs ] return (ideep.check_ndim(inputs, supported_ndim) and (all([isinstance(a, ideep.mdarray) for a in inputs]) or ideep.check_type(inputs)))
def all_ready(inputs, supported_ndim=(2, 4)): """Check inputs and configuration supported for ideep optimization. The function checks :func:`chainer.ia.should_use_ideep`, ``inputs`` info and ``supported_ndim``. Args: inputs (numpy.ndarray, cupy.ndarray, ideep.mdarray): ``inputs`` to be checked including array type, dimension and data type. supported_ndim: A tuple of ndim. ideep supports array dimension in either 2 or 4 only. Returns: bool: ``True`` if all conditions meet. """ if not ideep_enabled: return False _inputs = [ x.data if isinstance(x, chainer.variable.Variable) else x for x in inputs ] if ideep4py.check_ndim(_inputs, supported_ndim) is False: return False elif isinstance(_inputs[0], mdarray): return True else: return ideep4py.check_type(_inputs) and \ should_use_ideep('>=auto')
def _is_supported_array_type(a): return isinstance(a, ideep.mdarray) or ideep.check_type([a])