<commit_before>#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION

#include <Python.h>
#include <numpy/arrayobject.h>

#include "face.h"

struct ModuleState {
    PyObject *error;
};

#if PY_MAJOR_VERSION >= 3
#define GET_STATE(module) ((struct ModuleState*)PyModule_GetState(module))
#else
#define GET_STATE(module) (&_state)
static struct ModuleState _state;
#endif

static PyObject* _get_face(PyObject *self, PyObject *args) {
    PyArrayObject *mean_shape=NULL, *principal_components=NULL,
                  *pc_deviations=NULL, *coefficients=NULL,
                  *result=NULL;

    if (!PyArg_ParseTuple(args, "O!O!O!O!",
                &PyArray_Type, &mean_shape,
                &PyArray_Type, &principal_components,
                &PyArray_Type, &pc_deviations,
                &PyArray_Type, &coefficients)) {
        return NULL;
    }

    npy_intp* dims = malloc(sizeof(npy_intp)*2);
    dims[0] = PyArray_SIZE(mean_shape);
    dims[1] = 1;
    result = (PyArrayObject*)PyArray_ZEROS(2, dims, NPY_FLOAT, 0);

    get_face(
         PyArray_DATA(mean_shape),
         PyArray_DATA(principal_components),
         PyArray_DATA(pc_deviations),
         PyArray_DATA(coefficients),
         PyArray_DATA(result),
         PyArray_SIZE(coefficients),
         PyArray_SIZE(mean_shape));

    return PyArray_Return(result);
}

static PyMethodDef face_methods[] = {
    { "get_face", _get_face,
      METH_VARARGS,
      "Get normalized normal vectors for each vertex.\n\n"
      "Normal vector of each vertex is average normal vector\n"
      "of triangles connected by this vertex."},
    {NULL, NULL, 0, NULL}
};

#if PY_MAJOR_VERSION >= 3

static int face_traverse(PyObject *m, visitproc visit, void *arg) {
    Py_VISIT(GET_STATE(m)->error);
    return 0;
}

static int face_clear(PyObject *m) {
    Py_CLEAR(GET_STATE(m)->error);
    return 0;
}

#define INITERROR return NULL

static struct PyModuleDef face_module = {
    PyModuleDef_HEAD_INIT,
    "face",
    "Normal vectors processing.",
    sizeof(struct ModuleState),
    face_methods,
    NULL,
    face_traverse,
    face_clear,<commit_msg>Wrapped row getting C function<commit_after>#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION

#include <Python.h>
#include <numpy/arrayobject.h>

#include "face.h"

struct ModuleState {
    PyObject *error;
};

#if PY_MAJOR_VERSION >= 3
#define GET_STATE(module) ((struct ModuleState*)PyModule_GetState(module))
#else
#define GET_STATE(module) (&_state)
static struct ModuleState _state;
#endif

static PyObject* _get_face(PyObject *self, PyObject *args) {
    PyArrayObject *mean_shape=NULL, *principal_components=NULL,
                  *pc_deviations=NULL, *coefficients=NULL,
                  *result=NULL;

    if (!PyArg_ParseTuple(args, "O!O!O!O!",
                &PyArray_Type, &mean_shape,
                &PyArray_Type, &principal_components,
                &PyArray_Type, &pc_deviations,
                &PyArray_Type, &coefficients)) {
        return NULL;
    }

    npy_intp* dims = malloc(sizeof(npy_intp)*2);
    dims[0] = PyArray_SIZE(mean_shape);
    dims[1] = 1;
    result = (PyArrayObject*)PyArray_ZEROS(2, dims, NPY_FLOAT, 0);

    get_face(
         PyArray_DATA(mean_shape),
         PyArray_DATA(principal_components),
         PyArray_DATA(pc_deviations),
         PyArray_DATA(coefficients),
         PyArray_DATA(result),
         PyArray_SIZE(coefficients),
         PyArray_SIZE(mean_shape));

    return PyArray_Return(result);
}

static PyObject* _get_row(PyObject *self, PyObject *args) {
    PyArrayObject *principal_components=NULL, *pc_deviations=NULL,
                  *face=NULL;
    Py_ssize_t row;
    float coefficient_difference;

    if (!PyArg_ParseTuple(args, "O!O!fnO!",
                &PyArray_Type, &principal_components,
                &PyArray_Type, &pc_deviations,
                &coefficient_difference,
                &row,
                &PyArray_Type, &face)) {
        return NULL;
    }

    get_row(
         PyArray_DATA(principal_components),
         PyArray_DATA(pc_deviations),
         coefficient_difference,
         row,
         PyArray_DATA(face),
         PyArray_SIZE(pc_deviations),
         PyArray_SIZE(face));

    Py_INCREF(Py_None);
    return Py_None;
}

static PyMethodDef face_methods[] = {
    { "get_face", _get_face,
      METH_VARARGS,
      ""},
    { "get_row", _get_row,
      METH_VARARGS,
      ""},
    {NULL, NULL, 0, NULL}
};

#if PY_MAJOR_VERSION >= 3

static int face_traverse(PyObject *m, visitproc visit, void *arg) {
    Py_VISIT(GET_STATE(m)->error);
    return 0;
}

static int face_clear(PyObject *m) {
    Py_CLEAR(GET_STATE(m)->error);
    return 0;
}

#define INITERROR return NULL

static struct PyModuleDef face_module = {
    PyModuleDef_HEAD_INIT,
    "face",
    "Normal vectors processing.",
    sizeof(struct ModuleState),
    face_methods,
    NULL,
    face_traverse,
    face_clear,
{'fraction_non_alphanumeric': 0.10916853018906282, 'fraction_numerical': 0.005285627159991868, 'mean_word_length': 3.069478908188586, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '4839548', 'n_tokens_mistral': 1717, 'n_tokens_neox': 1664, 'n_words': 318}