404

[ Avaa Bypassed ]




Upload:

Command:

elspacio@18.118.151.112: ~ $
"""
Functions in the ``as*array`` family that promote array-likes into arrays.

`require` fits this category despite its name not matching this pattern.
"""
from .overrides import (
    array_function_dispatch,
    set_array_function_like_doc,
    set_module,
)
from .multiarray import array, asanyarray


__all__ = ["require"]


POSSIBLE_FLAGS = {
    'C': 'C', 'C_CONTIGUOUS': 'C', 'CONTIGUOUS': 'C',
    'F': 'F', 'F_CONTIGUOUS': 'F', 'FORTRAN': 'F',
    'A': 'A', 'ALIGNED': 'A',
    'W': 'W', 'WRITEABLE': 'W',
    'O': 'O', 'OWNDATA': 'O',
    'E': 'E', 'ENSUREARRAY': 'E'
}


@set_array_function_like_doc
@set_module('numpy')
def require(a, dtype=None, requirements=None, *, like=None):
    """
    Return an ndarray of the provided type that satisfies requirements.

    This function is useful to be sure that an array with the correct flags
    is returned for passing to compiled code (perhaps through ctypes).

    Parameters
    ----------
    a : array_like
       The object to be converted to a type-and-requirement-satisfying array.
    dtype : data-type
       The required data-type. If None preserve the current dtype. If your
       application requires the data to be in native byteorder, include
       a byteorder specification as a part of the dtype specification.
    requirements : str or sequence of str
       The requirements list can be any of the following

       * 'F_CONTIGUOUS' ('F') - ensure a Fortran-contiguous array
       * 'C_CONTIGUOUS' ('C') - ensure a C-contiguous array
       * 'ALIGNED' ('A')      - ensure a data-type aligned array
       * 'WRITEABLE' ('W')    - ensure a writable array
       * 'OWNDATA' ('O')      - ensure an array that owns its own data
       * 'ENSUREARRAY', ('E') - ensure a base array, instead of a subclass
    ${ARRAY_FUNCTION_LIKE}

        .. versionadded:: 1.20.0

    Returns
    -------
    out : ndarray
        Array with specified requirements and type if given.

    See Also
    --------
    asarray : Convert input to an ndarray.
    asanyarray : Convert to an ndarray, but pass through ndarray subclasses.
    ascontiguousarray : Convert input to a contiguous array.
    asfortranarray : Convert input to an ndarray with column-major
                     memory order.
    ndarray.flags : Information about the memory layout of the array.

    Notes
    -----
    The returned array will be guaranteed to have the listed requirements
    by making a copy if needed.

    Examples
    --------
    >>> x = np.arange(6).reshape(2,3)
    >>> x.flags
      C_CONTIGUOUS : True
      F_CONTIGUOUS : False
      OWNDATA : False
      WRITEABLE : True
      ALIGNED : True
      WRITEBACKIFCOPY : False

    >>> y = np.require(x, dtype=np.float32, requirements=['A', 'O', 'W', 'F'])
    >>> y.flags
      C_CONTIGUOUS : False
      F_CONTIGUOUS : True
      OWNDATA : True
      WRITEABLE : True
      ALIGNED : True
      WRITEBACKIFCOPY : False

    """
    if like is not None:
        return _require_with_like(
            like,
            a,
            dtype=dtype,
            requirements=requirements,
        )

    if not requirements:
        return asanyarray(a, dtype=dtype)

    requirements = {POSSIBLE_FLAGS[x.upper()] for x in requirements}

    if 'E' in requirements:
        requirements.remove('E')
        subok = False
    else:
        subok = True

    order = 'A'
    if requirements >= {'C', 'F'}:
        raise ValueError('Cannot specify both "C" and "F" order')
    elif 'F' in requirements:
        order = 'F'
        requirements.remove('F')
    elif 'C' in requirements:
        order = 'C'
        requirements.remove('C')

    arr = array(a, dtype=dtype, order=order, copy=False, subok=subok)

    for prop in requirements:
        if not arr.flags[prop]:
            return arr.copy(order)
    return arr


_require_with_like = array_function_dispatch()(require)

Filemanager

Name Type Size Permission Actions
__pycache__ Folder 0755
include Folder 0755
lib Folder 0755
tests Folder 0755
__init__.py File 5.64 KB 0644
__init__.pyi File 126 B 0644
_add_newdocs.py File 204.07 KB 0644
_add_newdocs_scalars.py File 11.82 KB 0644
_asarray.py File 3.79 KB 0644
_asarray.pyi File 1.06 KB 0644
_dtype.py File 10.36 KB 0644
_dtype_ctypes.py File 3.59 KB 0644
_exceptions.py File 5.25 KB 0644
_internal.py File 27.68 KB 0644
_internal.pyi File 1.01 KB 0644
_machar.py File 11.29 KB 0644
_methods.py File 8.41 KB 0644
_multiarray_tests.cpython-311-x86_64-linux-gnu.so File 171.4 KB 0755
_multiarray_umath.cpython-311-x86_64-linux-gnu.so File 6.64 MB 0755
_operand_flag_tests.cpython-311-x86_64-linux-gnu.so File 16.55 KB 0755
_rational_tests.cpython-311-x86_64-linux-gnu.so File 58.29 KB 0755
_simd.cpython-311-x86_64-linux-gnu.so File 2.47 MB 0755
_string_helpers.py File 2.79 KB 0644
_struct_ufunc_tests.cpython-311-x86_64-linux-gnu.so File 16.65 KB 0755
_type_aliases.py File 7.36 KB 0644
_type_aliases.pyi File 404 B 0644
_ufunc_config.py File 13.62 KB 0644
_ufunc_config.pyi File 1.04 KB 0644
_umath_tests.cpython-311-x86_64-linux-gnu.so File 41.01 KB 0755
arrayprint.py File 62.12 KB 0644
arrayprint.pyi File 4.32 KB 0644
cversions.py File 347 B 0644
defchararray.py File 71.89 KB 0644
defchararray.pyi File 9 KB 0644
einsumfunc.py File 50.65 KB 0644
einsumfunc.pyi File 4.75 KB 0644
fromnumeric.py File 125.8 KB 0644
fromnumeric.pyi File 22.96 KB 0644
function_base.py File 19.37 KB 0644
function_base.pyi File 4.61 KB 0644
generate_numpy_api.py File 7.47 KB 0644
getlimits.py File 25.26 KB 0644
getlimits.pyi File 82 B 0644
memmap.py File 11.5 KB 0644
memmap.pyi File 55 B 0644
multiarray.py File 54.78 KB 0644
multiarray.pyi File 24.19 KB 0644
numeric.py File 75.21 KB 0644
numeric.pyi File 13.9 KB 0644
numerictypes.py File 17.67 KB 0644
numerictypes.pyi File 3.19 KB 0644
overrides.py File 6.93 KB 0644
records.py File 36.65 KB 0644
records.pyi File 5.56 KB 0644
setup.py File 47.05 KB 0644
setup_common.py File 16.68 KB 0644
shape_base.py File 29.05 KB 0644
shape_base.pyi File 2.71 KB 0644
umath.py File 1.99 KB 0644
umath_tests.py File 389 B 0644