pub struct Uniform<F, D> { /* private fields */ }Expand description
Options for uniform sampling graphs of function ℝ → ℝ.
See Sampling::uniform.
Implementations§
Source§impl<F, Y, D> Uniform<F, D>
impl<F, Y, D> Uniform<F, D>
Sourcepub fn n(self, n: usize) -> Self
pub fn n(self, n: usize) -> Self
Set the maximum number of evaluations of the function
to build the sampling. Panic if n < 2. An initial
exploration of the function always uses at least 10
evaluations so, for n < 10, this is the number of
evaluations performed.
Examples found in repository?
6fn main() -> Result<(), Box<dyn Error>> {
7 let path = "/tmp/latex_speed.tex";
8 let mut fh = File::create(path)?;
9 write!(fh, "\\documentclass[12pt,a4paper]{{article}}\n\
10 \\usepackage{{tikz}}\n\
11 \\begin{{document}}\n\
12 \\begin{{tikzpicture}}\n")?;
13 let n = 40_000;
14 println!("Run \"latex {}\" measure LaTeX speed with {} points.\n",
15 path, n);
16 let s = Sampling::uniform(f64::sin, -6., 6.).n(n).build();
17 s.latex().write(&mut fh)?;
18 write!(fh, "\\end{{tikzpicture}}\n\
19 \\end{{document}}")?;
20 Ok(())
21}Sourcepub fn viewport(self, vp: BoundingBox) -> Self
pub fn viewport(self, vp: BoundingBox) -> Self
Set the zone of interest for the sampling. Segments that end up outside this box will not be refined.
Sourcepub fn init<'a, I>(self, ts: I) -> Selfwhere
I: IntoIterator<Item = &'a f64>,
pub fn init<'a, I>(self, ts: I) -> Selfwhere
I: IntoIterator<Item = &'a f64>,
Add initial values of t such that f(t) (see [Sampling :: uniform]) must be included into the sampling in addition to
the n evaluations. Only the values between a and
b are taken into account (other values are ignored).
Sourcepub fn init_pt<I>(self, pts: I) -> Selfwhere
I: IntoIterator<Item = (f64, Y)>,
pub fn init_pt<I>(self, pts: I) -> Selfwhere
I: IntoIterator<Item = (f64, Y)>,
Add initial points (t, f(t)) to include into the
sampling in addition to the n evaluations. This
allows you to use previous evaluations of f. Only
the couples with first coordinate t between a and
b (see [Sampling :: uniform]) are considered (other values are ignored).
Source§impl<F, Y, D> Uniform<F, D>
impl<F, Y, D> Uniform<F, D>
Sourcepub fn build(self) -> Sampling<D>
pub fn build(self) -> Sampling<D>
Return a uniform sampling of the function.
Examples found in repository?
6fn main() -> Result<(), Box<dyn Error>> {
7 let path = "/tmp/latex_speed.tex";
8 let mut fh = File::create(path)?;
9 write!(fh, "\\documentclass[12pt,a4paper]{{article}}\n\
10 \\usepackage{{tikz}}\n\
11 \\begin{{document}}\n\
12 \\begin{{tikzpicture}}\n")?;
13 let n = 40_000;
14 println!("Run \"latex {}\" measure LaTeX speed with {} points.\n",
15 path, n);
16 let s = Sampling::uniform(f64::sin, -6., 6.).n(n).build();
17 s.latex().write(&mut fh)?;
18 write!(fh, "\\end{{tikzpicture}}\n\
19 \\end{{document}}")?;
20 Ok(())
21}More examples
7fn main() -> Result<(), Box<dyn Error>> {
8 let s = Sampling::from_iter([[0., 0.], [1., 1.], [f64::NAN, f64::NAN],
9 [1., 1.], [3., -1.]]);
10 s.latex().arrow_pos(0.3).write(&mut File::create("/tmp/arrow0.tex")?)?;
11
12 let s = Sampling::uniform(|x| -0.7 * (x - 1.).powi(2), 0., 2.5).build();
13 s.latex().arrow_pos(0.6).write(&mut File::create("/tmp/arrow1.tex")?)?;
14
15
16 File::create("/tmp/arrows.tex")?.write_all(
17 r"\documentclass{article}
18\usepackage{tikz}
19\begin{document}
20\begin{tikzpicture}[x=3cm, y=3cm]
21 \draw[->] (-1.2, 0) -- (3.2, 0);
22 \draw[->] (0, -1.2) -- (0, 1.7);
23 \foreach \x in {-1, -0.5, 0.5, 1, 1.5,..., 3}{
24 \draw (\x, 3pt) -- (\x, -3pt) node[below]{$\scriptstyle \x$};
25 }
26 \foreach \y in {-1, -0.5, 0.5, 1, 1.5}{
27 \draw (3pt, \y) -- (-3pt, \y) node[left]{$\scriptstyle \y$};
28 }
29 \begin{scope}[color=blue, line width=1pt]
30 \input{arrow0.tex}
31 \end{scope}
32 \begin{scope}[color=orange, line width=1pt]
33 \input{arrow1.tex}
34 \end{scope}
35\end{tikzpicture}
36\end{document}".as_bytes())?;
37
38 std::env::set_current_dir("/tmp")?;
39 Command::new("pdflatex")
40 .args(["-interaction=batchmode", "arrows.tex"]).output()?;
41 Ok(())
42}