mephisto/mephisto.cpp
/**
 * @brief Function to calculate only the edges of the bins used by the histogram function.
 *
 * @see https://numpy.org/doc/stable/reference/generated/numpy.histogram_bin_edges.html
 * @see https://github.com/numpy/numpy/blob/v1.18.1/numpy/lib/histograms.py#L473-L672
 *
 * @param self
 * @param args
 * @return PyObject*
 */
@brief Function to calculate only the edges of the bins used by the histogram function.

@param self
@param args
@return PyObject
@brief Function to calculate only the edges of the bins used by the histogram function . @param self @param args @return PyObject
static PyObject*
histogram_bin_edges(PyObject *self, PyObject *args, PyObject *kwds) {
    PyObject *a = nullptr;
    PyObject *bins = nullptr;
    double range_lower = -std::numeric_limits< double >::infinity();
    double range_upper = std::numeric_limits< double >::infinity();
    PyObject *weights = nullptr;
    static char *kwlist[] = {"a", "bins", "range", "weights", NULL};
    PyArrayObject *bin_edges = nullptr;
    PyArrayObject *a_np = nullptr;
    PyArrayObject *weights_np = nullptr;
    bool bin_edges_arg = false;
    bool status = true;
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O(ff)O", kwlist, &a, &bins, &range_lower, &range_upper, &weights))
        goto fail;
    if (range_lower != -std::numeric_limits< double >::infinity() || range_upper != std::numeric_limits< double >::infinity() || weights)
    {
        PyErr_SetString(PyExc_NotImplementedError, "Supported arguments: (a, bins)");
        goto fail;
    }
    a_np = reinterpret_cast< PyArrayObject* >(PyArray_FROM_OTF(a, NPY_DOUBLE, NPY_ARRAY_C_CONTIGUOUS | NPY_ARRAY_ALIGNED));
    if (!a_np)
        goto fail;
    status = histogram_bin_edges_impl(a_np, bins, range_lower, range_upper, weights_np,
                                      &bin_edges, &bin_edges_arg);
    if (!status)
        goto fail;
    goto success;
success:
    Py_DECREF(a_np);
    return Py_BuildValue("N", bin_edges);
fail:
    Py_XDECREF(a_np);
    Py_XDECREF(bin_edges);
    return NULL;
}
static PyObject * histogram_bin_edges ( PyObject * self , PyObject * args , PyObject * kwds ) { PyObject * a = nullptr ; PyObject * bins = nullptr ; double range_lower = - std :: numeric_limits < double > :: infinity ( ) ; double range_upper = std :: numeric_limits < double > :: infinity ( ) ; PyObject * weights = nullptr ; static char * kwlist [ ] = { " " , " " , " " , " " , NULL } ; PyArrayObject * bin_edges = nullptr ; PyArrayObject * a_np = nullptr ; PyArrayObject * weights_np = nullptr ; bool bin_edges_arg = false ; bool status = true ; if ( ! PyArg_ParseTupleAndKeywords ( args , kwds , " " , kwlist , & a , & bins , & range_lower , & range_upper , & weights ) ) goto fail ; if ( range_lower != - std :: numeric_limits < double > :: infinity ( ) || range_upper != std :: numeric_limits < double > :: infinity ( ) || weights ) { PyErr_SetString ( PyExc_NotImplementedError , " " ) ; goto fail ; } a_np = reinterpret_cast < PyArrayObject * > ( PyArray_FROM_OTF ( a , NPY_DOUBLE , NPY_ARRAY_C_CONTIGUOUS | NPY_ARRAY_ALIGNED ) ) ; if ( ! a_np ) goto fail ; status = histogram_bin_edges_impl ( a_np , bins , range_lower , range_upper , weights_np , & bin_edges , & bin_edges_arg ) ; if ( ! status ) goto fail ; goto success ; success : Py_DECREF ( a_np ) ; return Py_BuildValue ( " " , bin_edges ) ; fail : Py_XDECREF ( a_np ) ; Py_XDECREF ( bin_edges ) ; return NULL ; }
@brief Function to calculate only the edges of the bins used by the histogram function.
@brief Function to calculate only the edges of the bins used by the histogram function .
/* input */ /* output */ /* helpers */ /* argument parsing */ /* obtain ndarray behind `a` */ // TODO not necessary when bins is present as array