<commit_before>#include <Python.h>

static int
RawFilter2(const PyArrayObject *b, const PyArrayObject *a,
	   const PyArrayObject *x, const PyArrayObject *zi,
	   const PyArrayObject *zf, PyArrayObject *y, int axis,
	   BasicFilterFunction *filter_func);

/*
 * XXX: Error checking not done yet
 */
static PyObject *
sigtools_linear_filter2(PyObject * dummy, PyObject * args)
{
	PyObject *b, *a, *X, *Vi;
	PyArrayObject *arY, *arb, *ara, *arX, *arVi, *arVf;
	int axis, typenum, theaxis;
	char *ara_ptr, input_flag = 0, *azero;
	intp na, nb, nal;
	BasicFilterFunction *basic_filter;

        axis = -1;
        Vi = NULL;
	if (!PyArg_ParseTuple(args, "OOO|iO", &b, &a, &X, &axis, &Vi)) {
		return NULL;
	}

	typenum = PyArray_ObjectType(b, 0);
	typenum = PyArray_ObjectType(a, typenum);
	typenum = PyArray_ObjectType(X, typenum);
	if (Vi != NULL) {
		typenum = PyArray_ObjectType(Vi, typenum);
	}

	arY = arVf = arVi = NULL;
	ara = (PyArrayObject *) PyArray_ContiguousFromObject(a, typenum, 1, 1);
	arb = (PyArrayObject *) PyArray_ContiguousFromObject(b, typenum, 1, 1);
	arX = (PyArrayObject *) PyArray_FromObject(X, typenum, 0, 0);
        /* XXX: fix failure handling here */
	if (ara == NULL || arb == NULL || arX == NULL) {
		goto fail;
	}

	if (axis < -arX->nd || axis > arX->nd - 1) {
		PyErr_SetString(PyExc_ValueError,
				"selected axis is out of range");
		goto fail;
	}
	if (axis < 0) {
		theaxis = arX->nd + axis;
	} else {
		theaxis = axis;
	}

	if (Vi != NULL) {
                Py_ssize_t nvi;
		arVi = (PyArrayObject *) PyArray_FromObject(Vi, typenum,
							    arX->nd, arX->nd);
		if (arVi == NULL)
			goto fail;

                nvi = PyArray_Size((PyObject *) arVi);
                if (nvi > 0) {
                        input_flag = 1;
                } else {
                        input_flag = 0;
                        Py_DECREF(arVi);
                        arVi = NULL;
                }
	}

	arY = (PyArrayObject *) PyArray_SimpleNew(arX->nd,
						  arX->dimensions, typenum);
	if (arY == NULL) {
		goto fail;
	}

	if (input_flag) {
		arVf = (PyArrayObject *) PyArray_SimpleNew(arVi->nd,
							   arVi->dimensions,
						           typenum);
	}

	basic_filter = BasicFilterFunctions[(int) (arX->descr->type_num)];
	if (basic_filter == NULL) {
		PyErr_SetString(PyExc_ValueError,
				"linear_filter not available for this type");
		goto fail;
	}

	/* Skip over leading zeros in vector representing denominator (a) */
	/* XXX: handle this correctly */
	azero = PyArray_Zero(ara);
	ara_ptr = ara->data;
        nal = PyArray_ITEMSIZE(ara);
	if (memcmp(ara_ptr, azero, nal) == 0) {
		PyErr_SetString(PyExc_ValueError,
				"BUG: filter coefficient a[0] == 0 not supported yet");
                goto fail;
	}
	PyDataMem_FREE(azero);

	na = PyArray_SIZE(ara);
	nb = PyArray_SIZE(arb);
	if (input_flag) {
		if (arVi->dimensions[theaxis] != (na > nb ? na : nb) - 1) {
			PyErr_SetString(PyExc_ValueError,
					"The number of initial conditions must be max([len(a),len(b)]) - 1");
			goto fail;
		}
	}

	RawFilter2(arb, ara, arX, arVi, arVf, arY, theaxis, basic_filter);

	Py_XDECREF(ara);
	Py_XDECREF(arb);
	Py_XDECREF(arX);
	Py_XDECREF(arVi);

	if (!input_flag) {
		return PyArray_Return(arY);
	} else {
		return Py_BuildValue("(NN)", arY, arVf);
	}


fail:
	Py_XDECREF(ara);
	Py_XDECREF(arb);
	Py_XDECREF(arX);
	Py_XDECREF(arVi);<commit_msg>Handle failure when calling RawFilter2 to propagate exception.<commit_after>#include <Python.h>

static int
RawFilter2(const PyArrayObject *b, const PyArrayObject *a,
	   const PyArrayObject *x, const PyArrayObject *zi,
	   const PyArrayObject *zf, PyArrayObject *y, int axis,
	   BasicFilterFunction *filter_func);

/*
 * XXX: Error checking not done yet
 */
static PyObject *
sigtools_linear_filter2(PyObject * dummy, PyObject * args)
{
	PyObject *b, *a, *X, *Vi;
	PyArrayObject *arY, *arb, *ara, *arX, *arVi, *arVf;
	int axis, typenum, theaxis, st;
	char *ara_ptr, input_flag = 0, *azero;
	intp na, nb, nal;
	BasicFilterFunction *basic_filter;

        axis = -1;
        Vi = NULL;
	if (!PyArg_ParseTuple(args, "OOO|iO", &b, &a, &X, &axis, &Vi)) {
		return NULL;
	}

	typenum = PyArray_ObjectType(b, 0);
	typenum = PyArray_ObjectType(a, typenum);
	typenum = PyArray_ObjectType(X, typenum);
	if (Vi != NULL) {
		typenum = PyArray_ObjectType(Vi, typenum);
	}

	arY = arVf = arVi = NULL;
	ara = (PyArrayObject *) PyArray_ContiguousFromObject(a, typenum, 1, 1);
	arb = (PyArrayObject *) PyArray_ContiguousFromObject(b, typenum, 1, 1);
	arX = (PyArrayObject *) PyArray_FromObject(X, typenum, 0, 0);
        /* XXX: fix failure handling here */
	if (ara == NULL || arb == NULL || arX == NULL) {
		goto fail;
	}

	if (axis < -arX->nd || axis > arX->nd - 1) {
		PyErr_SetString(PyExc_ValueError,
				"selected axis is out of range");
		goto fail;
	}
	if (axis < 0) {
		theaxis = arX->nd + axis;
	} else {
		theaxis = axis;
	}

	if (Vi != NULL) {
                Py_ssize_t nvi;
		arVi = (PyArrayObject *) PyArray_FromObject(Vi, typenum,
							    arX->nd, arX->nd);
		if (arVi == NULL)
			goto fail;

                nvi = PyArray_Size((PyObject *) arVi);
                if (nvi > 0) {
                        input_flag = 1;
                } else {
                        input_flag = 0;
                        Py_DECREF(arVi);
                        arVi = NULL;
                }
	}

	arY = (PyArrayObject *) PyArray_SimpleNew(arX->nd,
						  arX->dimensions, typenum);
	if (arY == NULL) {
		goto fail;
	}

	if (input_flag) {
		arVf = (PyArrayObject *) PyArray_SimpleNew(arVi->nd,
							   arVi->dimensions,
						           typenum);
	}

	basic_filter = BasicFilterFunctions[(int) (arX->descr->type_num)];
	if (basic_filter == NULL) {
		PyErr_SetString(PyExc_ValueError,
				"linear_filter not available for this type");
		goto fail;
	}

	/* Skip over leading zeros in vector representing denominator (a) */
	/* XXX: handle this correctly */
	azero = PyArray_Zero(ara);
	ara_ptr = ara->data;
        nal = PyArray_ITEMSIZE(ara);
	if (memcmp(ara_ptr, azero, nal) == 0) {
		PyErr_SetString(PyExc_ValueError,
				"BUG: filter coefficient a[0] == 0 not supported yet");
                goto fail;
	}
	PyDataMem_FREE(azero);

	na = PyArray_SIZE(ara);
	nb = PyArray_SIZE(arb);
	if (input_flag) {
		if (arVi->dimensions[theaxis] != (na > nb ? na : nb) - 1) {
			PyErr_SetString(PyExc_ValueError,
					"The number of initial conditions must be max([len(a),len(b)]) - 1");
			goto fail;
		}
	}

	st = RawFilter2(arb, ara, arX, arVi, arVf, arY, theaxis, basic_filter);
	if (st) {
		goto fail;
	}

	Py_XDECREF(ara);
	Py_XDECREF(arb);
	Py_XDECREF(arX);
	Py_XDECREF(arVi);

	if (!input_flag) {
		return PyArray_Return(arY);
	} else {
		return Py_BuildValue("(NN)", arY, arVf);
	}


fail:
	Py_XDECREF(ara);
	Py_XDECREF(arb);
	Py_XDECREF(arX);
	Py_XDECREF(arVi);
{'fraction_non_alphanumeric': 0.1391941391941392, 'fraction_numerical': 0.006593406593406593, 'mean_word_length': 2.936562860438293, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 37, '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': '4294255', 'n_tokens_mistral': 2805, 'n_tokens_neox': 2602, 'n_words': 616}