Skip to content

Commit 4a7c1fe

Browse files
BartMasseyclaude
andcommitted
ripped KaTeX rustdoc support back out
Reverting the rustdoc-LaTeX wiring added in 167367d. The machinery (custom katex.html header, Cargo.toml rustdoc-args, $...$ in docstrings) ended up costing more than it bought: - No per-package scoping for `--html-in-header` means local `cargo doc` can't render math without breaking on dep crates, and the workarounds (cargo aliases, --no-deps) push the burden onto users who shouldn't have to know. - Adopting mathru's "docs.rs only" pattern leaves local users staring at raw $...$, which isn't a good answer either. - rustdoc itself is moving toward first-class math support (rust-lang/rfcs#3958); waiting for that beats maintaining a brittle CDN-dependent shim. Removed: docs/katex.html, the rustdoc-args metadata in Cargo.toml, and the $...$ delimiters in src/lib.rs (reverted to ASCII / Unicode-subscript math, matching the rest of the docstrings). Markdown LaTeX in README.md and INTERNALS.md stays — GitHub renders that natively with no per-crate plumbing required. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 26a0bee commit 4a7c1fe

4 files changed

Lines changed: 28 additions & 85 deletions

File tree

.cargo/config.toml

Lines changed: 0 additions & 5 deletions
This file was deleted.

Cargo.toml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,5 @@ path = "src/lib.rs"
6363
# docs.rs builds the published crate with default features only by
6464
# default. Build with all features so users browsing the rendered
6565
# docs see both `std` and `libm` configurations documented.
66-
#
67-
# `--html-in-header docs/katex.html` injects a KaTeX bootstrap into
68-
# every page so $...$ / $$...$$ in rustdoc renders as math (the
69-
# library has enough Beta / order-statistic / Gamma-ratio formulae
70-
# to warrant it). For local `cargo doc`, the same flag is set in
71-
# `.cargo/config.toml`'s `rustdocflags`.
7266
[package.metadata.docs.rs]
7367
all-features = true
74-
rustdoc-args = ["--html-in-header", "docs/katex.html"]

docs/katex.html

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/lib.rs

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Sequential Importance Sampling (SIS) primitives — multinomial
2-
//! sampling with replacement, in $O(n)$ time.
2+
//! sampling with replacement, in O(n) time.
33
//!
44
//! See `README.md` for a tutorial introduction and `INTERNALS.md` for
55
//! the algorithm specification, math proofs, and floating-point
@@ -8,21 +8,20 @@
88
//! # API at a glance
99
//!
1010
//! - [`sample_indices`] — the main entry point. Returns an iterator
11-
//! yielding $n$ indices into `weights` iid with replacement, each
11+
//! yielding `n` indices into `weights` iid with replacement, each
1212
//! with probability proportional to its weight. Output is in
1313
//! ascending order. Streaming: one `powf` call per yielded index.
1414
//! - [`sample_indices_buffered`] — buffered variant, typically
1515
//! ~1.32× faster on x86 (more on hardware with a slow `powf`).
1616
//! Takes an `&mut [u32]` buffer rather than returning an iterator
1717
//! (it uses the buffer as f32 scratch).
18-
//! - [`SortedUniforms`] — iterator yielding $n$ $\mathrm{Uniform}(0, 1)$
19-
//! variates in ascending order in $O(n)$ time. Useful in its own
20-
//! right outside sampling (e.g. inverse-CDF sampling where you
21-
//! want sorted output).
18+
//! - [`SortedUniforms`] — iterator yielding `n` Uniform(0, 1) variates
19+
//! in ascending order in O(n) time. Useful in its own right outside
20+
//! sampling (e.g. inverse-CDF sampling where you want sorted
21+
//! output).
2222
//! - [`first_uniform`] — low-level per-step primitive used by
23-
//! [`SortedUniforms`]. Samples $\min(U_1, \ldots, U_k)$ for $k$
24-
//! iid $\mathrm{Uniform}(0, 1)$ (equivalently, $\mathrm{Beta}(1, k)$).
25-
//! Most callers won't touch this directly.
23+
//! [`SortedUniforms`]. Samples the minimum of `k` iid Uniform(0, 1)
24+
//! draws (≡ `Beta(1, k)`). Most callers won't touch this directly.
2625
//!
2726
//! Indices are yielded/written as `u32`, not `usize`, so the API has
2827
//! the same layout on every platform. Callers cast to `usize` at the
@@ -69,13 +68,12 @@ use rand_distr::{Distribution, Exp1};
6968
// first_uniform
7069
// ---------------------------------------------------------------------------
7170

72-
/// Draw a sample distributed as $\min(U_1, \ldots, U_k)$ for $k$
73-
/// iid $\mathrm{Uniform}(0, 1)$ variates (equivalently,
74-
/// $\mathrm{Beta}(1, k)$ in standard notation).
71+
/// Draw a sample distributed as the minimum of `k` iid Uniform(0, 1)
72+
/// variates (equivalently, `Beta(1, k)` in standard notation).
7573
///
7674
/// Computed in closed form via the inverse CDF
77-
/// $F^{-1}(u) = 1 - (1 - u)^{1/k}$. One `powf` call per invocation;
78-
/// constant time in $k$.
75+
/// `F⁻¹(u) = 1 (1 u)^(1/k)`. One `powf` call per invocation;
76+
/// constant time in `k`.
7977
///
8078
/// This is the per-step primitive driving the order-statistic
8179
/// recurrence in [`SortedUniforms`]. Most callers won't need this
@@ -104,18 +102,17 @@ pub fn first_uniform<R: Rng + ?Sized>(rng: &mut R, k: u32) -> f32 {
104102
// SortedUniforms
105103
// ---------------------------------------------------------------------------
106104

107-
/// Streaming iterator yielding $n$ $\mathrm{Uniform}(0, 1)$ variates
108-
/// in ascending order in $O(n)$ time.
105+
/// Streaming iterator yielding `n` Uniform(0, 1) variates in ascending
106+
/// order in O(n) time.
109107
///
110108
/// The yielded values are distributed exactly as the order statistics
111-
/// $U_{(1)} \le U_{(2)} \le \cdots \le U_{(n)}$ of $n$ iid
112-
/// $\mathrm{Uniform}(0, 1)$ draws — i.e. the same as drawing $n$ iid
109+
/// of `n` iid Uniform(0, 1) draws — i.e. the same as drawing `n` iid
113110
/// uniforms and sorting them, but produced one at a time without a
114111
/// sort. Internally uses the Bentley–Saxe spacings recurrence
115-
/// $U_{(i)} = U_{(i-1)} + (1 - U_{(i-1)}) \cdot Z$ with
116-
/// $Z \sim \mathrm{Beta}(1, n - i + 1)$ supplied by [`first_uniform`].
112+
/// `U_(i) = U_(i-1) + (1 U_(i-1)) · Z` with `Z ~ Beta(1, n − i + 1)`
113+
/// supplied by [`first_uniform`].
117114
///
118-
/// Holds a mutable reference to the RNG. Yields exactly $n$ values,
115+
/// Holds a mutable reference to the RNG. Yields exactly `n` values,
119116
/// then `None` thereafter.
120117
///
121118
/// See `INTERNALS.md` §3.1 / §5.1 for the algorithm and its
@@ -193,15 +190,15 @@ fn kahan_add(sum: &mut f32, c: &mut f32, x: f32) {
193190
*sum = t;
194191
}
195192

196-
/// Build an iterator yielding $n$ indices into `weights`, each
193+
/// Build an iterator yielding `n` indices into `weights`, each
197194
/// drawn iid (with replacement) with probability proportional to
198195
/// its weight ("multinomial sampling"). Indices are yielded in
199196
/// ascending order; collect into a `Vec` and shuffle afterward if
200197
/// you need them in random order.
201198
///
202-
/// Streaming variant: runs in $O(m + n)$ total (where
203-
/// $m$ = `weights.len()`), allocates nothing, and uses one
204-
/// [`first_uniform`] call (one `powf`) per yielded index.
199+
/// Streaming variant: runs in O(`weights.len()` + `n`) total,
200+
/// allocates nothing, and uses one [`first_uniform`] call (one
201+
/// `powf`) per yielded index.
205202
///
206203
/// # Preconditions
207204
/// - `weights` is nonempty.
@@ -307,16 +304,12 @@ impl<'a, R: Rng + ?Sized> FusedIterator for SampleIndices<'a, R> {}
307304
/// hardware with a slow `powf`).
308305
///
309306
/// Generates sorted uniforms via the Gamma-ratio identity
310-
///
311-
/// $$
312-
/// U_{(i)} = \frac{E_1 + \cdots + E_i}{E_1 + \cdots + E_{n+1}},
313-
/// \qquad E_j \sim \mathrm{Exp}(1) \text{ iid}
314-
/// $$
315-
///
316-
/// rather than via [`first_uniform`], avoiding the per-element
317-
/// `powf`. Internally repurposes `out` as scratch (each `u32` slot
318-
/// temporarily holds the f32 bit pattern of an $E_j$ draw via
319-
/// [`f32::to_bits`], later overwritten with the output index).
307+
/// (`U_(i) = (E_1 + ... + E_i) / (E_1 + ... + E_(n+1))` for `E_j`
308+
/// iid Exp(1)) rather than via [`first_uniform`], avoiding the
309+
/// per-element `powf`. Internally repurposes `out` as scratch
310+
/// (each `u32` slot temporarily holds the f32 bit pattern of an
311+
/// `E_j` draw via [`f32::to_bits`], later overwritten with the
312+
/// output index).
320313
///
321314
/// See `INTERNALS.md` §4.4 for the algorithm and §5.2 for the
322315
/// `target.min(total)` clip that keeps the merge bounded.

0 commit comments

Comments
 (0)