mirror of https://github.com/python/cpython
gh-102839: remove AC for math.log (GH-102863)
This commit is contained in:
parent
41ef502d74
commit
d1a89ce515
|
@ -0,0 +1 @@
|
||||||
|
Improve performance of :func:`math.log` arguments handling by removing the argument clinic.
|
|
@ -186,49 +186,6 @@ exit:
|
||||||
return return_value;
|
return return_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyDoc_STRVAR(math_log__doc__,
|
|
||||||
"log(x, [base=math.e])\n"
|
|
||||||
"Return the logarithm of x to the given base.\n"
|
|
||||||
"\n"
|
|
||||||
"If the base not specified, returns the natural logarithm (base e) of x.");
|
|
||||||
|
|
||||||
#define MATH_LOG_METHODDEF \
|
|
||||||
{"log", (PyCFunction)math_log, METH_VARARGS, math_log__doc__},
|
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
math_log_impl(PyObject *module, PyObject *x, int group_right_1,
|
|
||||||
PyObject *base);
|
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
math_log(PyObject *module, PyObject *args)
|
|
||||||
{
|
|
||||||
PyObject *return_value = NULL;
|
|
||||||
PyObject *x;
|
|
||||||
int group_right_1 = 0;
|
|
||||||
PyObject *base = NULL;
|
|
||||||
|
|
||||||
switch (PyTuple_GET_SIZE(args)) {
|
|
||||||
case 1:
|
|
||||||
if (!PyArg_ParseTuple(args, "O:log", &x)) {
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
if (!PyArg_ParseTuple(args, "OO:log", &x, &base)) {
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
group_right_1 = 1;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
PyErr_SetString(PyExc_TypeError, "math.log requires 1 to 2 arguments");
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
return_value = math_log_impl(module, x, group_right_1, base);
|
|
||||||
|
|
||||||
exit:
|
|
||||||
return return_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
PyDoc_STRVAR(math_log2__doc__,
|
PyDoc_STRVAR(math_log2__doc__,
|
||||||
"log2($module, x, /)\n"
|
"log2($module, x, /)\n"
|
||||||
"--\n"
|
"--\n"
|
||||||
|
@ -954,4 +911,4 @@ math_ulp(PyObject *module, PyObject *arg)
|
||||||
exit:
|
exit:
|
||||||
return return_value;
|
return return_value;
|
||||||
}
|
}
|
||||||
/*[clinic end generated code: output=899211ec70e4506c input=a9049054013a1b77]*/
|
/*[clinic end generated code: output=a6437a3ba18c486a input=a9049054013a1b77]*/
|
||||||
|
|
|
@ -2284,33 +2284,22 @@ loghelper(PyObject* arg, double (*func)(double))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*[clinic input]
|
/* AC: cannot convert yet, see gh-102839 and gh-89381, waiting
|
||||||
math.log
|
for support of multiple signatures */
|
||||||
|
|
||||||
x: object
|
|
||||||
[
|
|
||||||
base: object(c_default="NULL") = math.e
|
|
||||||
]
|
|
||||||
/
|
|
||||||
|
|
||||||
Return the logarithm of x to the given base.
|
|
||||||
|
|
||||||
If the base not specified, returns the natural logarithm (base e) of x.
|
|
||||||
[clinic start generated code]*/
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
math_log_impl(PyObject *module, PyObject *x, int group_right_1,
|
math_log(PyObject *module, PyObject * const *args, Py_ssize_t nargs)
|
||||||
PyObject *base)
|
|
||||||
/*[clinic end generated code: output=7b5a39e526b73fc9 input=0f62d5726cbfebbd]*/
|
|
||||||
{
|
{
|
||||||
PyObject *num, *den;
|
PyObject *num, *den;
|
||||||
PyObject *ans;
|
PyObject *ans;
|
||||||
|
|
||||||
num = loghelper(x, m_log);
|
if (!_PyArg_CheckPositional("log", nargs, 1, 2))
|
||||||
if (num == NULL || base == NULL)
|
return NULL;
|
||||||
|
|
||||||
|
num = loghelper(args[0], m_log);
|
||||||
|
if (num == NULL || nargs == 1)
|
||||||
return num;
|
return num;
|
||||||
|
|
||||||
den = loghelper(base, m_log);
|
den = loghelper(args[1], m_log);
|
||||||
if (den == NULL) {
|
if (den == NULL) {
|
||||||
Py_DECREF(num);
|
Py_DECREF(num);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -2322,6 +2311,10 @@ math_log_impl(PyObject *module, PyObject *x, int group_right_1,
|
||||||
return ans;
|
return ans;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PyDoc_STRVAR(math_log_doc,
|
||||||
|
"log(x, [base=math.e])\n\
|
||||||
|
Return the logarithm of x to the given base.\n\n\
|
||||||
|
If the base not specified, returns the natural logarithm (base e) of x.");
|
||||||
|
|
||||||
/*[clinic input]
|
/*[clinic input]
|
||||||
math.log2
|
math.log2
|
||||||
|
@ -4045,7 +4038,7 @@ static PyMethodDef math_methods[] = {
|
||||||
{"lcm", _PyCFunction_CAST(math_lcm), METH_FASTCALL, math_lcm_doc},
|
{"lcm", _PyCFunction_CAST(math_lcm), METH_FASTCALL, math_lcm_doc},
|
||||||
MATH_LDEXP_METHODDEF
|
MATH_LDEXP_METHODDEF
|
||||||
{"lgamma", math_lgamma, METH_O, math_lgamma_doc},
|
{"lgamma", math_lgamma, METH_O, math_lgamma_doc},
|
||||||
MATH_LOG_METHODDEF
|
{"log", _PyCFunction_CAST(math_log), METH_FASTCALL, math_log_doc},
|
||||||
{"log1p", math_log1p, METH_O, math_log1p_doc},
|
{"log1p", math_log1p, METH_O, math_log1p_doc},
|
||||||
MATH_LOG10_METHODDEF
|
MATH_LOG10_METHODDEF
|
||||||
MATH_LOG2_METHODDEF
|
MATH_LOG2_METHODDEF
|
||||||
|
|
Loading…
Reference in New Issue