From 5ace1691f0bdd971c45ed9b45d9bada54ea7d4a4 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Wed, 27 Mar 2024 23:54:33 +0530 Subject: [PATCH 1/5] DOC: Add `jupyterlite-pyodide-kernel` to deps --- doc/source/dev/toolchain.rst | 23 ++++++++++++----------- environment.yml | 1 + 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/doc/source/dev/toolchain.rst b/doc/source/dev/toolchain.rst index 29c28965f377..10df74c19d7c 100644 --- a/doc/source/dev/toolchain.rst +++ b/doc/source/dev/toolchain.rst @@ -409,17 +409,18 @@ asv (airspeed velocity) Recent https://asv.readthedocs.io/ Building the Documentation -------------------------- -==================== ================================================= - Tool Version -==================== ================================================= -Sphinx Whatever recent versions work. >= 5.0. -PyData Sphinx theme Whatever recent versions work. >= 0.15.2. -Sphinx-Design Whatever recent versions work. >= 0.4.0. -numpydoc Whatever recent versions work. >= 1.5.0. -matplotlib Generally suggest >= 3.5. -MyST-NB Whatever recent versions work. >= 0.17.1 -jupyterlite-sphinx Whatever recent versions work. >= 0.12.0 -==================== ================================================= +============================ ================================================= + Tool Version +==================== ================================================= +Sphinx Whatever recent versions work. >= 5.0. +PyData Sphinx theme Whatever recent versions work. >= 0.15.2. +Sphinx-Design Whatever recent versions work. >= 0.4.0. +numpydoc Whatever recent versions work. >= 1.5.0. +matplotlib Generally suggest >= 3.5. +MyST-NB Whatever recent versions work. >= 0.17.1 +jupyterlite-sphinx Whatever recent versions work. >= 0.13.1 +jupyterlite-pyodide-kernel Whatever recent versions work. >= 0.1.0 +============================ ================================================= .. note:: diff --git a/environment.yml b/environment.yml index 24d6ef7e763d..f7dd03025229 100644 --- a/environment.yml +++ b/environment.yml @@ -45,6 +45,7 @@ dependencies: - jupytext - myst-nb - jupyterlite-sphinx>=0.13.1 + - jupyterlite-pyodide-kernel # Some optional test dependencies - mpmath - gmpy2 From 1b6ed41638c516a17b5b4030fb03b6f138c8aea3 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Wed, 27 Mar 2024 23:54:58 +0530 Subject: [PATCH 2/5] DOC: Add reST-based `.. try_examples::` --- doc/source/tutorial/stats/sampling.md | 29 ++++++++++++++++++--------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/doc/source/tutorial/stats/sampling.md b/doc/source/tutorial/stats/sampling.md index 279d351aa2f4..8b6d678c19bc 100644 --- a/doc/source/tutorial/stats/sampling.md +++ b/doc/source/tutorial/stats/sampling.md @@ -142,19 +142,21 @@ samples from the given distribution. An example of this interface is shown below: -```python +```{eval-rst} +.. try_examples:: + >>> from scipy.stats.sampling import TransformedDensityRejection >>> from math import exp - >>> + ... >>> class StandardNormal: ... def pdf(self, x: float) -> float: ... # note that the normalization constant isn't required ... return exp(-0.5 * x*x) ... def dpdf(self, x: float) -> float: ... return -x * exp(-0.5 * x*x) - ... + ... >>> dist = StandardNormal() - >>> + ... >>> urng = np.random.default_rng() >>> rng = TransformedDensityRejection(dist, random_state=urng) ``` @@ -188,7 +190,11 @@ In the above example, we have set up an object of the standard normal distribution. Now, we can start sampling from our distribution by calling the `rvs` method: -```python +```{eval-rst} +.. try_examples:: + + >>> from scipy.stats.sampling import TransformedDensityRejection + >>> rng = TransformedDensityRejection(dist, domain=(-1, 1), random_state=urng) >>> rng.rvs() -1.526829048388144 >>> rng.rvs((5, 3)) @@ -213,15 +219,15 @@ mystnb: >>> from scipy.stats import norm >>> from scipy.stats.sampling import TransformedDensityRejection >>> from math import exp - >>> + >>> >>> class StandardNormal: ... def pdf(self, x: float) -> float: ... # note that the normalization constant isn't required ... return exp(-0.5 * x*x) ... def dpdf(self, x: float) -> float: ... return -x * exp(-0.5 * x*x) - ... - >>> + ... + >>> >>> dist = StandardNormal() >>> urng = np.random.default_rng() >>> rng = TransformedDensityRejection(dist, random_state=urng) @@ -258,7 +264,7 @@ mystnb: {class}`~.stats.sampling.TransformedDensityRejection` would not be the same even for the same `random_state`: - ```python + ```{eval-rst} >>> from scipy.stats.sampling import norm, TransformedDensityRejection >>> from copy import copy >>> dist = StandardNormal() @@ -274,7 +280,10 @@ mystnb: We can pass a `domain` parameter to truncate the distribution: -```python +```{eval-rst} +.. try_examples:: + + >>> from scipy.stats.sampling import TransformedDensityRejection >>> rng = TransformedDensityRejection(dist, domain=(-1, 1), random_state=urng) >>> rng.rvs((5, 3)) array([[-0.99865691, 0.38104014, 0.31633526], From 7e11f6f38064428f13c9bdbba87475608d57cf42 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Thu, 28 Mar 2024 00:27:20 +0530 Subject: [PATCH 3/5] DOC: temporarily display button [docs only] --- doc/source/try_examples.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/source/try_examples.json b/doc/source/try_examples.json index f5429194157b..a27e34261568 100644 --- a/doc/source/try_examples.json +++ b/doc/source/try_examples.json @@ -1,4 +1,3 @@ { - "min_height": "400px", - "ignore_patterns": [".*"] + "min_height": "400px" } From 608d9a5be1a9d1c3d1c1821763a0c3a68b98e614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Melissa=20Weber=20Mendon=C3=A7a?= Date: Tue, 2 Apr 2024 19:16:48 -0300 Subject: [PATCH 4/5] DOC: Fix toolchain table syntax --- doc/source/dev/toolchain.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/dev/toolchain.rst b/doc/source/dev/toolchain.rst index 10df74c19d7c..51aab9b25682 100644 --- a/doc/source/dev/toolchain.rst +++ b/doc/source/dev/toolchain.rst @@ -411,7 +411,7 @@ Building the Documentation ============================ ================================================= Tool Version -==================== ================================================= +============================ ================================================= Sphinx Whatever recent versions work. >= 5.0. PyData Sphinx theme Whatever recent versions work. >= 0.15.2. Sphinx-Design Whatever recent versions work. >= 0.4.0. From 9f91c9141f344ec54ed39e483cf1114daf138c78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Melissa=20Weber=20Mendon=C3=A7a?= Date: Tue, 2 Apr 2024 19:17:23 -0300 Subject: [PATCH 5/5] DOC: Fix toolchain table syntax --- doc/source/dev/toolchain.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/dev/toolchain.rst b/doc/source/dev/toolchain.rst index 51aab9b25682..7777157c7a7c 100644 --- a/doc/source/dev/toolchain.rst +++ b/doc/source/dev/toolchain.rst @@ -411,7 +411,7 @@ Building the Documentation ============================ ================================================= Tool Version -============================ ================================================= +============================ ================================================= Sphinx Whatever recent versions work. >= 5.0. PyData Sphinx theme Whatever recent versions work. >= 0.15.2. Sphinx-Design Whatever recent versions work. >= 0.4.0.