<commit_before>cdef extern from "arrayobject.h":
    cdef enum NPY_TYPES:
        NPY_BOOL
        NPY_BYTE
        NPY_UBYTE
        NPY_SHORT
        NPY_USHORT
        NPY_INT
        NPY_UINT
        NPY_LONG
        NPY_ULONG
        NPY_LONGLONG
        NPY_ULONGLONG
        NPY_FLOAT
        NPY_DOUBLE
        NPY_LONGDOUBLE
        NPY_CFLOAT
        NPY_CDOUBLE
        NPY_CLONGDOUBLE
        NPY_OBJECT
        NPY_STRING
        NPY_UNICODE
        NPY_VOID
        NPY_NTYPES
        NPY_NOTYPE

    ctypedef int npy_intp

    ctypedef extern class numpy.ndarray [object PyArrayObject]:
        cdef char *data
        cdef int nd
        cdef npy_intp *dimensions
        cdef npy_intp *strides
        cdef int flags

    object PyArray_SimpleNewFromData(int nd, npy_intp* dims, int typenum,
            void* data)
    void import_array()

cdef extern from "torus.h":
    int c_TorusEOMS "TorusEOMS"(double t, double x[8], double f[8], void *params)

def TorusEOMS(t, x, params):
    assert len(x) == 8
    assert len(params) == 3
    from numpy import zeros
    f = zeros(8, dtype="double")
    cdef double *c_x, *c_f, *c_params
    cdef int n
    numpy2c_double_inplace(x, &c_x, &n)
    numpy2c_double_inplace(f, &c_f, &n)
    numpy2c_double_inplace(params, &c_params, &n)
    r = c_TorusEOMS(t, c_x, c_f, c_params)
    assert r == 0
    return f

_AA = None

cdef api void numpy2c_int_inplace(object A_n, int **A_c, int *n):
    """
    Returns the C array, that points to the numpy array (inplace).

    Only if strides != sizeof(int), the data get copied first.

    Important note: you need to use the A_c array immediately after calling
    this function in C, otherwise numpy could deallocate the array, especially
    if the _AA global variable was deallocated.
    """
    cdef ndarray A = A_n
    if not (A.nd == 1 and A.strides[0] == sizeof(int)):
        from numpy import array
        A = array(A.flat, dtype="int32")
        # this is needed so that numpy doesn't dealocate the arrays
        global _AA
        _AA = A
    n[0] = len(A)
    A_c[0] = <int *>(A.data)

cdef api void numpy2c_double_inplace(object A_n, double **A_c, int *n):
    """
    Returns the C array, that points to the numpy array (inplace).

    Only if strides != sizeof(double), the data get copied first.

    Important note: you need to use the A_c array immediately after calling
    this function in C, otherwise numpy could deallocate the array, especially
    if the _AA global variable was deallocated.
    """
    cdef ndarray A = A_n
    if not (A.nd == 1 and A.strides[0] == sizeof(double)):
        from numpy import array
        A = array(A.flat, dtype="double")
        # this is needed so that numpy doesn't dealocate the arrays
        global _AA
        _AA = A
    n[0] = len(A)
    A_c[0] = <double *>(A.data)<commit_msg>Don't generate the C api for _torus<commit_after>cdef extern from "arrayobject.h":
    cdef enum NPY_TYPES:
        NPY_BOOL
        NPY_BYTE
        NPY_UBYTE
        NPY_SHORT
        NPY_USHORT
        NPY_INT
        NPY_UINT
        NPY_LONG
        NPY_ULONG
        NPY_LONGLONG
        NPY_ULONGLONG
        NPY_FLOAT
        NPY_DOUBLE
        NPY_LONGDOUBLE
        NPY_CFLOAT
        NPY_CDOUBLE
        NPY_CLONGDOUBLE
        NPY_OBJECT
        NPY_STRING
        NPY_UNICODE
        NPY_VOID
        NPY_NTYPES
        NPY_NOTYPE

    ctypedef int npy_intp

    ctypedef extern class numpy.ndarray [object PyArrayObject]:
        cdef char *data
        cdef int nd
        cdef npy_intp *dimensions
        cdef npy_intp *strides
        cdef int flags

    object PyArray_SimpleNewFromData(int nd, npy_intp* dims, int typenum,
            void* data)
    void import_array()

cdef extern from "torus.h":
    int c_TorusEOMS "TorusEOMS"(double t, double x[8], double f[8], void *params)

def TorusEOMS(t, x, params):
    assert len(x) == 8
    assert len(params) == 3
    from numpy import zeros
    f = zeros(8, dtype="double")
    cdef double *c_x, *c_f, *c_params
    cdef int n
    numpy2c_double_inplace(x, &c_x, &n)
    numpy2c_double_inplace(f, &c_f, &n)
    numpy2c_double_inplace(params, &c_params, &n)
    r = c_TorusEOMS(t, c_x, c_f, c_params)
    assert r == 0
    return f

_AA = None

cdef void numpy2c_int_inplace(object A_n, int **A_c, int *n):
    """
    Returns the C array, that points to the numpy array (inplace).

    Only if strides != sizeof(int), the data get copied first.

    Important note: you need to use the A_c array immediately after calling
    this function in C, otherwise numpy could deallocate the array, especially
    if the _AA global variable was deallocated.
    """
    cdef ndarray A = A_n
    if not (A.nd == 1 and A.strides[0] == sizeof(int)):
        from numpy import array
        A = array(A.flat, dtype="int32")
        # this is needed so that numpy doesn't dealocate the arrays
        global _AA
        _AA = A
    n[0] = len(A)
    A_c[0] = <int *>(A.data)

cdef void numpy2c_double_inplace(object A_n, double **A_c, int *n):
    """
    Returns the C array, that points to the numpy array (inplace).

    Only if strides != sizeof(double), the data get copied first.

    Important note: you need to use the A_c array immediately after calling
    this function in C, otherwise numpy could deallocate the array, especially
    if the _AA global variable was deallocated.
    """
    cdef ndarray A = A_n
    if not (A.nd == 1 and A.strides[0] == sizeof(double)):
        from numpy import array
        A = array(A.flat, dtype="double")
        # this is needed so that numpy doesn't dealocate the arrays
        global _AA
        _AA = A
    n[0] = len(A)
    A_c[0] = <double *>(A.data)
{'fraction_non_alphanumeric': 0.0792789639481974, 'fraction_numerical': 0.007350367518375919, 'mean_word_length': 2.355842630651791, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 7, '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': '5025287', 'n_tokens_mistral': 2007, 'n_tokens_neox': 1968, 'n_words': 637}