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 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. """ def _is_supported_array_type(a): return isinstance(a, ideep.mdarray) or ideep.check_type([a]) 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([_is_supported_array_type(a) for a in inputs]))
def inputs_all_ready(inputs, supported_ndim=(2, 4)): """Checks if input arrays are supported for an iDeep primitive. Before calling an iDeep primitive (e.g., ``ideep4py.linear.Forward``), you need to make sure that all input arrays are ready for the primitive by calling this function. Information to be checked includes array types, dimesions and data types. The function checks ``inputs`` info and ``supported_ndim``. Inputs to be tested can be any of ``Variable``, ``numpy.ndarray`` or ``ideep4py.mdarray``. However, all inputs to iDeep primitives must be ``ideep4py.mdarray``. Callers of iDeep primitives are responsible of converting all inputs to ``ideep4py.mdarray``. Args: inputs (sequence of arrays or variables): Inputs to be checked. supported_ndim (tuple of ints): Supported ndim values for the iDeep primitive. Returns: bool: ``True`` if all conditions meet. """ def _is_supported_array_type(a): return isinstance(a, ideep.mdarray) or ideep.check_type([a]) if not is_ideep_available(): 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([_is_supported_array_type(a) for a in inputs]))
def inputs_all_ready(inputs, supported_ndim=(2, 4)): """Checks if input arrays are supported for an iDeep primitive. Before calling an iDeep primitive (e.g., ``ideep4py.linear.Forward``), you need to make sure that all input arrays are ready for the primitive by calling this function. Information to be checked includes array types, dimesions and data types. The function checks ``inputs`` info and ``supported_ndim``. Inputs to be tested can be any of ``Variable``, ``numpy.ndarray`` or ``ideep4py.mdarray``. However, all inputs to iDeep primitives must be ``ideep4py.mdarray``. Callers of iDeep primitives are responsible of converting all inputs to ``ideep4py.mdarray``. Args: inputs (sequence of arrays or variables): Inputs to be checked. supported_ndim (tuple of ints): Supported ndim values for the iDeep primitive. Returns: bool: ``True`` if all conditions meet. """ def _is_supported_array_type(a): return isinstance(a, ideep.mdarray) or ideep.check_type([a]) if not is_ideep_available(): 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([_is_supported_array_type(a) for a in inputs]))