<commit_before>#------------------------------------------------------------------------------

cdef extern from "Python.h":
    int is_list   "PyList_Check" (object)
    int is_tuple  "PyTuple_Check" (object)

cdef extern from "Python.h":
    int PyIndex_Check(object)
    int PySequence_Check(object)
    object PyNumber_Index(object)
    Py_ssize_t PySequence_Size(object) except -1

cdef inline int is_integral(object ob):
    if not PyIndex_Check(ob): return 0
    if not PySequence_Check(ob): return 1
    try: PySequence_Size(ob)
    except: pass
    else: return 0
    try: PyNumber_Index(ob)
    except: return 0
    else: return 1

cdef inline int is_buffer(object ob):
    if PY3:
        return PyObject_CheckBuffer(ob)
    else:
        return PyObject_CheckBuffer(ob) or _Py2_IsBuffer(ob)

cdef inline int is_gpu_buffer(object ob):
    return Py_CheckGPUBuffer(ob)

cdef inline int is_datatype(object ob):
    if isinstance(ob, Datatype): return 1
    if PY3:
        if isinstance(ob, unicode): return 1
    else:
        if isinstance(ob, bytes): return 1
    return 0

#------------------------------------------------------------------------------

cdef extern from *:
    int INT_MAX

cdef inline int downcast(MPI_Aint value) except? -1:
    if value > <MPI_Aint>INT_MAX:
        raise OverflowError("integer %d does not fit in 'int'" % value)
    else:
        return <int>value

cdef inline int clipcount(MPI_Aint value):
    if value > <MPI_Aint>INT_MAX:
        return INT_MAX
    else:
        return <int>value

#------------------------------------------------------------------------------

cdef object __BOTTOM__   = <MPI_Aint>MPI_BOTTOM

cdef object __IN_PLACE__ = <MPI_Aint>MPI_IN_PLACE


cdef inline bint is_BOTTOM(object obj):
    if PYPY: return type(obj) is type(__BOTTOM__) and obj == __BOTTOM__
    else:    return obj is __BOTTOM__

cdef inline bint is_IN_PLACE(object obj):
    if PYPY: return type(obj) is type(__IN_PLACE__) and obj == __IN_PLACE__
    else:    return obj is __IN_PLACE__

#------------------------------------------------------------------------------

@cython.final
@cython.internal
cdef class _p_message:
    cdef memory buf
    cdef object count
    cdef object displ
    cdef Datatype type

cdef _p_message message_basic(object o_buf,
                              object o_type,
                              bint readonly,
                              #
                              void        **baddr,
                              MPI_Aint     *bsize,
                              MPI_Datatype *btype,<commit_msg>MPI: Use subtypes of int for BOTTOM and IN_PLACE constants<commit_after>#------------------------------------------------------------------------------

cdef extern from "Python.h":
    int is_list   "PyList_Check" (object)
    int is_tuple  "PyTuple_Check" (object)

cdef extern from "Python.h":
    int PyIndex_Check(object)
    int PySequence_Check(object)
    object PyNumber_Index(object)
    Py_ssize_t PySequence_Size(object) except -1

cdef inline int is_integral(object ob):
    if not PyIndex_Check(ob): return 0
    if not PySequence_Check(ob): return 1
    try: PySequence_Size(ob)
    except: pass
    else: return 0
    try: PyNumber_Index(ob)
    except: return 0
    else: return 1

cdef inline int is_buffer(object ob):
    if PY3:
        return PyObject_CheckBuffer(ob)
    else:
        return PyObject_CheckBuffer(ob) or _Py2_IsBuffer(ob)

cdef inline int is_gpu_buffer(object ob):
    return Py_CheckGPUBuffer(ob)

cdef inline int is_datatype(object ob):
    if isinstance(ob, Datatype): return 1
    if PY3:
        if isinstance(ob, unicode): return 1
    else:
        if isinstance(ob, bytes): return 1
    return 0

#------------------------------------------------------------------------------

cdef extern from *:
    int INT_MAX

cdef inline int downcast(MPI_Aint value) except? -1:
    if value > <MPI_Aint>INT_MAX:
        raise OverflowError("integer %d does not fit in 'int'" % value)
    else:
        return <int>value

cdef inline int clipcount(MPI_Aint value):
    if value > <MPI_Aint>INT_MAX:
        return INT_MAX
    else:
        return <int>value

#------------------------------------------------------------------------------

@cython.final
@cython.internal
cdef class Bottom(int):
    """
    Type of `BOTTOM`
    """

    def __cinit__(self):
        cdef MPI_Aint a = self, b = <MPI_Aint>MPI_BOTTOM
        if a != b : raise ValueError("cannot create instance")

    def __repr__(self):
        return 'BOTTOM'


@cython.final
@cython.internal
cdef class InPlace(int):
    """
    Type of `IN_PLACE`
    """

    def __cinit__(self):
        cdef MPI_Aint a = self, b = <MPI_Aint>MPI_IN_PLACE
        if a != b : raise ValueError("cannot create instance")

    def __repr__(self):
        return 'IN_PLACE'


cdef object __BOTTOM__   = Bottom(<MPI_Aint>MPI_BOTTOM)

cdef object __IN_PLACE__ = InPlace(<MPI_Aint>MPI_IN_PLACE)


cdef inline bint is_BOTTOM(object obj):
    if PYPY: return type(obj) is type(__BOTTOM__) and obj == __BOTTOM__
    else:    return obj is __BOTTOM__

cdef inline bint is_IN_PLACE(object obj):
    if PYPY: return type(obj) is type(__IN_PLACE__) and obj == __IN_PLACE__
    else:    return obj is __IN_PLACE__

#------------------------------------------------------------------------------

@cython.final
@cython.internal
cdef class _p_message:
    cdef memory buf
    cdef object count
    cdef object displ
    cdef Datatype type

cdef _p_message message_basic(object o_buf,
                              object o_type,
                              bint readonly,
                              #
                              void        **baddr,
                              MPI_Aint     *bsize,
                              MPI_Datatype *btype,
{'fraction_non_alphanumeric': 0.17570125623816898, 'fraction_numerical': 0.004818447771467906, 'mean_word_length': 1.7466918714555766, 'pattern_counts': {'":': 4, '<': 17, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3685429', 'n_tokens_mistral': 1807, 'n_tokens_neox': 1769, 'n_words': 502}