| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
59 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -75,6 +75,7 @@ Include/internal/pycore_opcode.h generated | |||
| 75 | 75 | Include/internal/pycore_opcode_metadata.h generated | |
| 76 | 76 | Include/internal/pycore_*_generated.h generated | |
| 77 | 77 | Include/opcode.h generated | |
| 78 | + Include/opcode_ids.h generated | ||
| 78 | 79 | Include/token.h generated | |
| 79 | 80 | Lib/_opcode_metadata.py generated | |
| 80 | 81 | Lib/keyword.py generated | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -161,10 +161,14 @@ a buffer, see :c:func:`PyObject_GetBuffer`. | |||
| 161 | 161 | If it is ``0``, :c:member:`~Py_buffer.buf` points to a single item representing | |
| 162 | 162 | a scalar. In this case, :c:member:`~Py_buffer.shape`, :c:member:`~Py_buffer.strides` | |
| 163 | 163 | and :c:member:`~Py_buffer.suboffsets` MUST be ``NULL``. | |
| 164 | + The maximum number of dimensions is given by :c:macro:`PyBUF_MAX_NDIM`. | ||
| 164 | 165 | ||
| 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. | ||
| 168 | 172 | ||
| 169 | 173 | .. c:member:: Py_ssize_t *shape | |
| 170 | 174 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -147,7 +147,7 @@ Quick Reference | |||
| 147 | 147 | +------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+ | |
| 148 | 148 | | :c:member:`~PyTypeObject.tp_vectorcall` | :c:type:`vectorcallfunc` | | | | | | | |
| 149 | 149 | +------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+ | |
| 150 | - | [:c:member:`~PyTypeObject.tp_watched`] | char | | | | | | | ||
| 150 | + | [:c:member:`~PyTypeObject.tp_watched`] | unsigned char | | | | | | | ||
| 151 | 151 | +------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+ | |
| 152 | 152 | ||
| 153 | 153 | .. [#slots] | |
@@ -2141,7 +2141,7 @@ and :c:data:`PyType_Type` effectively act as defaults.) | |||
| 2141 | 2141 | .. versionadded:: 3.9 (the field exists since 3.8 but it's only used since 3.9) | |
| 2142 | 2142 | ||
| 2143 | 2143 | ||
| 2144 | - .. c:member:: char PyTypeObject.tp_watched | ||
| 2144 | + .. c:member:: unsigned char PyTypeObject.tp_watched | ||
| 2145 | 2145 | ||
| 2146 | 2146 | Internal. Do not use. | |
| 2147 | 2147 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -82,5 +82,5 @@ typedef struct _typeobject { | |||
| 82 | 82 | vectorcallfunc tp_vectorcall; | |
| 83 | 83 | ||
| 84 | 84 | /* bitset of which type-watchers care about this type */ | |
| 85 | - char tp_watched; | ||
| 85 | + unsigned char tp_watched; | ||
| 86 | 86 | } PyTypeObject; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -397,21 +397,39 @@ have specific values relative to the predefined levels. If you define a level | |||
| 397 | 397 | with the same numeric value, it overwrites the predefined value; the predefined | |
| 398 | 398 | name is lost. | |
| 399 | 399 | ||
| 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 | + +-----------------------+---------------+-------------------------------------+ | ||
| 415 | 433 | ||
| 416 | 434 | ||
| 417 | 435 | .. _handler: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -922,6 +922,10 @@ of applications in statistics. | |||
| 922 | 922 | :class:`NormalDist` Examples and Recipes | |
| 923 | 923 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| 924 | 924 | ||
| 925 | + | ||
| 926 | + Classic probability problems | ||
| 927 | + **************************** | ||
| 928 | + | ||
| 925 | 929 | :class:`NormalDist` readily solves classic probability problems. | |
| 926 | 930 | ||
| 927 | 931 | For example, given `historical data for SAT exams | |
@@ -947,6 +951,10 @@ Find the `quartiles <https://en.wikipedia.org/wiki/Quartile>`_ and `deciles | |||
| 947 | 951 | >>> list(map(round, sat.quantiles(n=10))) | |
| 948 | 952 | [810, 896, 958, 1011, 1060, 1109, 1162, 1224, 1310] | |
| 949 | 953 | ||
| 954 | + | ||
| 955 | + Monte Carlo inputs for simulations | ||
| 956 | + ********************************** | ||
| 957 | + | ||
| 950 | 958 | To estimate the distribution for a model than isn't easy to solve | |
| 951 | 959 | analytically, :class:`NormalDist` can generate input samples for a `Monte | |
| 952 | 960 | Carlo simulation <https://en.wikipedia.org/wiki/Monte_Carlo_method>`_: | |
@@ -963,6 +971,9 @@ Carlo simulation <https://en.wikipedia.org/wiki/Monte_Carlo_method>`_: | |||
| 963 | 971 | >>> quantiles(map(model, X, Y, Z)) # doctest: +SKIP | |
| 964 | 972 | [1.4591308524824727, 1.8035946855390597, 2.175091447274739] | |
| 965 | 973 | ||
| 974 | + Approximating binomial distributions | ||
| 975 | + ************************************ | ||
| 976 | + | ||
| 966 | 977 | Normal distributions can be used to approximate `Binomial | |
| 967 | 978 | distributions <https://mathworld.wolfram.com/BinomialDistribution.html>`_ | |
| 968 | 979 | 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? | |||
| 1000 | 1011 | >>> mean(trial() <= k for i in range(10_000)) | |
| 1001 | 1012 | 0.8398 | |
| 1002 | 1013 | ||
| 1014 | + | ||
| 1015 | + Naive bayesian classifier | ||
| 1016 | + ************************* | ||
| 1017 | + | ||
| 1003 | 1018 | Normal distributions commonly arise in machine learning problems. | |
| 1004 | 1019 | ||
| 1005 | 1020 | 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 | |||
| 1054 | 1069 | 'female' | |
| 1055 | 1070 | ||
| 1056 | 1071 | ||
| 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 | + | ||
| 1057 | 1114 | .. | |
| 1058 | 1115 | # This modelines must appear within the last ten lines of the file. | |
| 1059 | 1116 | kate: indent-width 3; remove-trailing-space on; replace-tabs on; encoding utf-8; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1576,7 +1576,7 @@ Changes in the Python API | |||
| 1576 | 1576 | 1,13-1,17: FSTRING_MIDDLE ' end' | |
| 1577 | 1577 | 1,17-1,18: FSTRING_END '"' | |
| 1578 | 1578 | ||
| 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 | ||
| 1580 | 1580 | changes required to support :pep:`701`. Some of these changes include: | |
| 1581 | 1581 | ||
| 1582 | 1582 | * The ``type`` attribute of the tokens emitted when tokenizing some invalid Python | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -227,7 +227,7 @@ struct _typeobject { | |||
| 227 | 227 | vectorcallfunc tp_vectorcall; | |
| 228 | 228 | ||
| 229 | 229 | /* bitset of which type-watchers care about this type */ | |
| 230 | - char tp_watched; | ||
| 230 | + unsigned char tp_watched; | ||
| 231 | 231 | }; | |
| 232 | 232 | ||
| 233 | 233 | /* This struct is used by the specializer | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -381,7 +381,7 @@ extern PyObject *_PyType_NewManagedObject(PyTypeObject *type); | |||
| 381 | 381 | ||
| 382 | 382 | extern PyTypeObject* _PyType_CalculateMetaclass(PyTypeObject *, PyObject *); | |
| 383 | 383 | 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); | ||
| 385 | 385 | ||
| 386 | 386 | extern int _PyObject_InitializeDict(PyObject *obj); | |
| 387 | 387 | int _PyObject_InitInlineValues(PyObject *obj, PyTypeObject *tp); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments