FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Merge remote-tracking branch 'cpython/main' into gh-89240 · zooba/cpython@a3eb90b · GitHub

Repository navigation

Commit a3eb90b

Browse files
committed
Merge remote-tracking branch 'cpython/main' into pythongh-89240
2 parents b9113f5 + 6fbaba5 commit a3eb90b

59 files changed

Lines changed: 1381 additions & 391 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.gitattributes‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Include/internal/pycore_opcode.h generated
7575
Include/internal/pycore_opcode_metadata.h generated
7676
Include/internal/pycore_*_generated.h generated
7777
Include/opcode.h generated
78+
Include/opcode_ids.h generated
7879
Include/token.h generated
7980
Lib/_opcode_metadata.py generated
8081
Lib/keyword.py generated

‎Doc/c-api/buffer.rst‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,14 @@ a buffer, see :c:func:`PyObject_GetBuffer`.
161161
If it is ``0``, :c:member:`~Py_buffer.buf` points to a single item representing
162162
a scalar. In this case, :c:member:`~Py_buffer.shape`, :c:member:`~Py_buffer.strides`
163163
and :c:member:`~Py_buffer.suboffsets` MUST be ``NULL``.
164+
The maximum number of dimensions is given by :c:macro:`PyBUF_MAX_NDIM`.
164165

165-
The macro :c:macro:`PyBUF_MAX_NDIM` limits the maximum number of dimensions
166-
to 64. Exporters MUST respect this limit, consumers of multi-dimensional
167-
buffers SHOULD be able to handle up to :c:macro:`PyBUF_MAX_NDIM` dimensions.
166+
.. :c:macro:: PyBUF_MAX_NDIM
167+
168+
The maximum number of dimensions the memory represents.
169+
Exporters MUST respect this limit, consumers of multi-dimensional
170+
buffers SHOULD be able to handle up to :c:macro:`!PyBUF_MAX_NDIM` dimensions.
171+
Currently set to 64.
168172
169173
.. c:member:: Py_ssize_t *shape
170174

‎Doc/c-api/typeobj.rst‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ Quick Reference
147147
+------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+
148148
| :c:member:`~PyTypeObject.tp_vectorcall` | :c:type:`vectorcallfunc` | | | | | |
149149
+------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+
150-
| [:c:member:`~PyTypeObject.tp_watched`] | char | | | | | |
150+
| [:c:member:`~PyTypeObject.tp_watched`] | unsigned char | | | | | |
151151
+------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+
152152

153153
.. [#slots]
@@ -2141,7 +2141,7 @@ and :c:data:`PyType_Type` effectively act as defaults.)
21412141
.. versionadded:: 3.9 (the field exists since 3.8 but it's only used since 3.9)
21422142

21432143

2144-
.. c:member:: char PyTypeObject.tp_watched
2144+
.. c:member:: unsigned char PyTypeObject.tp_watched
21452145
21462146
Internal. Do not use.
21472147

‎Doc/includes/typestruct.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,5 @@ typedef struct _typeobject {
8282
vectorcallfunc tp_vectorcall;
8383

8484
/* bitset of which type-watchers care about this type */
85-
char tp_watched;
85+
unsigned char tp_watched;
8686
} PyTypeObject;

‎Doc/library/kde_example.png‎

324 KB
LoadingViewer requires iframe.

‎Doc/library/logging.rst‎

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -397,21 +397,39 @@ have specific values relative to the predefined levels. If you define a level
397397
with the same numeric value, it overwrites the predefined value; the predefined
398398
name is lost.
399399

400-
+-----------------------+---------------+
401-
| Level | Numeric value |
402-
+=======================+===============+
403-
| .. py:data:: CRITICAL | 50 |
404-
+-----------------------+---------------+
405-
| .. py:data:: ERROR | 40 |
406-
+-----------------------+---------------+
407-
| .. py:data:: WARNING | 30 |
408-
+-----------------------+---------------+
409-
| .. py:data:: INFO | 20 |
410-
+-----------------------+---------------+
411-
| .. py:data:: DEBUG | 10 |
412-
+-----------------------+---------------+
413-
| .. py:data:: NOTSET | 0 |
414-
+-----------------------+---------------+
400+
+-----------------------+---------------+-------------------------------------+
401+
| Level | Numeric value | What it means / When to use it |
402+
+=======================+===============+=====================================+
403+
| .. py:data:: NOTSET | 0 | When set on a logger, indicates that|
404+
| | | ancestor loggers are to be consulted|
405+
| | | to determine the effective level. |
406+
| | | If that still resolves to |
407+
| | | :const:`!NOTSET`, then all events |
408+
| | | are logged. When set on a handler, |
409+
| | | all events are handled. |
410+
+-----------------------+---------------+-------------------------------------+
411+
| .. py:data:: DEBUG | 10 | Detailed information, typically only|
412+
| | | of interest to a developer trying to|
413+
| | | diagnose a problem. |
414+
+-----------------------+---------------+-------------------------------------+
415+
| .. py:data:: INFO | 20 | Confirmation that things are working|
416+
| | | as expected. |
417+
+-----------------------+---------------+-------------------------------------+
418+
| .. py:data:: WARNING | 30 | An indication that something |
419+
| | | unexpected happened, or that a |
420+
| | | problem might occur in the near |
421+
| | | future (e.g. 'disk space low'). The |
422+
| | | software is still working as |
423+
| | | expected. |
424+
+-----------------------+---------------+-------------------------------------+
425+
| .. py:data:: ERROR | 40 | Due to a more serious problem, the |
426+
| | | software has not been able to |
427+
| | | perform some function. |
428+
+-----------------------+---------------+-------------------------------------+
429+
| .. py:data:: CRITICAL | 50 | A serious error, indicating that the|
430+
| | | program itself may be unable to |
431+
| | | continue running. |
432+
+-----------------------+---------------+-------------------------------------+
415433

416434

417435
.. _handler:

‎Doc/library/statistics.rst‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,10 @@ of applications in statistics.
922922
:class:`NormalDist` Examples and Recipes
923923
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
924924

925+
926+
Classic probability problems
927+
****************************
928+
925929
:class:`NormalDist` readily solves classic probability problems.
926930

927931
For example, given `historical data for SAT exams
@@ -947,6 +951,10 @@ Find the `quartiles <https://en.wikipedia.org/wiki/Quartile>`_ and `deciles
947951
>>> list(map(round, sat.quantiles(n=10)))
948952
[810, 896, 958, 1011, 1060, 1109, 1162, 1224, 1310]
949953

954+
955+
Monte Carlo inputs for simulations
956+
**********************************
957+
950958
To estimate the distribution for a model than isn't easy to solve
951959
analytically, :class:`NormalDist` can generate input samples for a `Monte
952960
Carlo simulation <https://en.wikipedia.org/wiki/Monte_Carlo_method>`_:
@@ -963,6 +971,9 @@ Carlo simulation <https://en.wikipedia.org/wiki/Monte_Carlo_method>`_:
963971
>>> quantiles(map(model, X, Y, Z)) # doctest: +SKIP
964972
[1.4591308524824727, 1.8035946855390597, 2.175091447274739]
965973

974+
Approximating binomial distributions
975+
************************************
976+
966977
Normal distributions can be used to approximate `Binomial
967978
distributions <https://mathworld.wolfram.com/BinomialDistribution.html>`_
968979
when the sample size is large and when the probability of a successful
@@ -1000,6 +1011,10 @@ probability that the Python room will stay within its capacity limits?
10001011
>>> mean(trial() <= k for i in range(10_000))
10011012
0.8398
10021013

1014+
1015+
Naive bayesian classifier
1016+
*************************
1017+
10031018
Normal distributions commonly arise in machine learning problems.
10041019

10051020
Wikipedia has a `nice example of a Naive Bayesian Classifier
@@ -1054,6 +1069,48 @@ The final prediction goes to the largest posterior. This is known as the
10541069
'female'
10551070

10561071

1072+
Kernel density estimation
1073+
*************************
1074+
1075+
It is possible to estimate a continuous probability density function
1076+
from a fixed number of discrete samples.
1077+
1078+
The basic idea is to smooth the data using `a kernel function such as a
1079+
normal distribution, triangular distribution, or uniform distribution
1080+
<https://en.wikipedia.org/wiki/Kernel_(statistics)#Kernel_functions_in_common_use>`_.
1081+
The degree of smoothing is controlled by a single
1082+
parameter, ``h``, representing the variance of the kernel function.
1083+
1084+
.. testcode::
1085+
1086+
import math
1087+
1088+
def kde_normal(sample, h):
1089+
"Create a continous probability density function from a sample."
1090+
# Smooth the sample with a normal distribution of variance h.
1091+
kernel_h = NormalDist(0.0, math.sqrt(h)).pdf
1092+
n = len(sample)
1093+
def pdf(x):
1094+
return sum(kernel_h(x - x_i) for x_i in sample) / n
1095+
return pdf
1096+
1097+
`Wikipedia has an example
1098+
<https://en.wikipedia.org/wiki/Kernel_density_estimation#Example>`_
1099+
where we can use the ``kde_normal()`` recipe to generate and plot
1100+
a probability density function estimated from a small sample:
1101+
1102+
.. doctest::
1103+
1104+
>>> sample = [-2.1, -1.3, -0.4, 1.9, 5.1, 6.2]
1105+
>>> f_hat = kde_normal(sample, h=2.25)
1106+
>>> xarr = [i/100 for i in range(-750, 1100)]
1107+
>>> yarr = [f_hat(x) for x in xarr]
1108+
1109+
The points in ``xarr`` and ``yarr`` can be used to make a PDF plot:
1110+
1111+
.. image:: kde_example.png
1112+
:alt: Scatter plot of the estimated probability density function.
1113+
10571114
..
10581115
# This modelines must appear within the last ten lines of the file.
10591116
kate: indent-width 3; remove-trailing-space on; replace-tabs on; encoding utf-8;

‎Doc/whatsnew/3.12.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1576,7 +1576,7 @@ Changes in the Python API
15761576
1,13-1,17: FSTRING_MIDDLE ' end'
15771577
1,17-1,18: FSTRING_END '"'
15781578

1579-
Additionally, there may be some minor behavioral changes as a consecuence of the
1579+
Additionally, there may be some minor behavioral changes as a consequence of the
15801580
changes required to support :pep:`701`. Some of these changes include:
15811581

15821582
* The ``type`` attribute of the tokens emitted when tokenizing some invalid Python

‎Include/cpython/object.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ struct _typeobject {
227227
vectorcallfunc tp_vectorcall;
228228

229229
/* bitset of which type-watchers care about this type */
230-
char tp_watched;
230+
unsigned char tp_watched;
231231
};
232232

233233
/* This struct is used by the specializer

‎Include/internal/pycore_object.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ extern PyObject *_PyType_NewManagedObject(PyTypeObject *type);
381381

382382
extern PyTypeObject* _PyType_CalculateMetaclass(PyTypeObject *, PyObject *);
383383
extern PyObject* _PyType_GetDocFromInternalDoc(const char *, const char *);
384-
extern PyObject* _PyType_GetTextSignatureFromInternalDoc(const char *, const char *);
384+
extern PyObject* _PyType_GetTextSignatureFromInternalDoc(const char *, const char *, int);
385385

386386
extern int _PyObject_InitializeDict(PyObject *obj);
387387
int _PyObject_InitInlineValues(PyObject *obj, PyTypeObject *tp);

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL