Skip to content

Commit

Permalink
Updating gh-pages from be6befd
Browse files Browse the repository at this point in the history
  • Loading branch information
axch committed Nov 14, 2023
1 parent 7e1d306 commit 9a1853e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 40 deletions.
8 changes: 4 additions & 4 deletions examples/bfgs.html
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,8 @@
</span></div></div><div class="cell"><div class="code-block"><span class="code-span">%time<span class="whitespace">
</span><span class="code-span"><span class="code-span"><span class="code-span"><span class="code-span"><span class="code-span"><span class="code-span"><span class="code-span-leaf">bfgs_minimize</span><span class="whitespace"> </span><span class="code-span"><span class="code-span-leaf"></span>rosenbrock<span class="whitespace"> </span></span></span><span class="code-span"><span class="code-span-leaf"></span>[<span class="code-span-leaf">10<span class="symbol">.</span></span><span class="symbol">,</span><span class="whitespace"> </span><span class="code-span-leaf">10<span class="symbol">.</span></span>]<span class="whitespace"> </span></span></span><span class="code-span"><span class="code-span-leaf"></span>eye<span class="whitespace"> </span></span></span><span class="code-span"><span class="code-span-leaf"></span>(<span class="code-span"><span class="symbol">\</span><span class="code-span-leaf">f</span><span class="symbol">.</span><span class="whitespace"> </span><span class="code-span"><span class="code-span"><span class="code-span-leaf">backtracking_line_search</span><span class="whitespace"> </span><span class="code-span"><span class="code-span-leaf"></span>15<span class="whitespace"> </span></span></span><span class="code-span"><span class="code-span-leaf"></span>f</span></span></span>)<span class="whitespace"> </span></span></span><span class="code-span"><span class="code-span-leaf"></span>0<span class="symbol">.</span>001<span class="whitespace"> </span></span></span><span class="code-span"><span class="code-span-leaf"></span>100</span></span><span class="whitespace">
</span></span></div><div class="result-block">BFGSresults(1.741236e-11, [0.9999971, 0.9999939], 0.0001280856, 46)</div><div class="result-block">
Compile time: 1.501 s
Run time: 239.000 us </div></div><div class="cell"><div class="code-block"><span class="whitespace">
Compile time: 863.250 ms
Run time: 120.400 us </div></div><div class="cell"><div class="code-block"><span class="whitespace">
</span></div></div><div class="cell"><div class="code-block"><span class="code-span"><span class="code-span"><span class="symbol">@</span>noinline<span class="whitespace">
</span><span class="keyword">def</span><span class="whitespace"> </span>multiclass_logistic_loss(<span class="code-span"><span class="code-span-leaf">xs</span><span class="code-span-leaf"><span class="symbol">:</span></span><span class="whitespace"> </span><span class="code-span"><span class="code-span-leaf">n</span><span class="code-span-leaf"><span class="symbol">=&gt;</span></span><span class="code-span"><span class="code-span-leaf">d</span><span class="code-span-leaf"><span class="symbol">=&gt;</span></span><span class="code-span-leaf"><span class="type-name">Float</span></span></span></span></span><span class="symbol">,</span><span class="whitespace"> </span><span class="code-span"><span class="code-span-leaf">ys</span><span class="code-span-leaf"><span class="symbol">:</span></span><span class="whitespace"> </span><span class="code-span"><span class="code-span-leaf">n</span><span class="code-span-leaf"><span class="symbol">=&gt;</span></span><span class="code-span-leaf">m</span></span></span><span class="symbol">,</span><span class="whitespace"> </span><span class="code-span"><span class="code-span-leaf">w</span><span class="code-span-leaf"><span class="symbol">:</span></span><span class="whitespace"> </span><span class="code-span"><span class="code-span">(<span class="code-span-leaf">d</span><span class="symbol">,</span><span class="whitespace"> </span><span class="code-span-leaf">m</span>)</span><span class="code-span-leaf"><span class="symbol">=&gt;</span></span><span class="code-span-leaf"><span class="type-name">Float</span></span></span></span>)<span class="whitespace"> </span><span class="symbol">-&gt;</span><span class="whitespace"> </span><span class="code-span-leaf"><span class="type-name">Float</span></span><span class="whitespace"> </span><span class="keyword">given</span><span class="whitespace"> </span>(<span class="code-span"><span class="code-span-leaf">n</span><span class="code-span-leaf"><span class="symbol">|</span></span><span class="code-span-leaf"><span class="type-name">Ix</span></span></span><span class="symbol">,</span><span class="whitespace"> </span><span class="code-span"><span class="code-span-leaf">d</span><span class="code-span-leaf"><span class="symbol">|</span></span><span class="code-span-leaf"><span class="type-name">Ix</span></span></span><span class="symbol">,</span><span class="whitespace"> </span><span class="code-span"><span class="code-span-leaf">m</span><span class="code-span-leaf"><span class="symbol">|</span></span><span class="code-span-leaf"><span class="type-name">Ix</span></span></span>)<span class="whitespace"> </span><span class="symbol">=</span><span class="whitespace">
</span><span class="code-span"><span class="code-span-leaf">w_arr</span><span class="whitespace"> </span><span class="symbol">=</span><span class="whitespace"> </span><span class="code-span"><span class="keyword">for</span><span class="whitespace"> </span><span class="code-span"><span class="code-span-leaf">i</span><span class="code-span-leaf"><span class="symbol">:</span></span><span class="code-span-leaf">d</span></span><span class="symbol">.</span><span class="whitespace"> </span><span class="code-span"><span class="keyword">for</span><span class="whitespace"> </span><span class="code-span"><span class="code-span-leaf">j</span><span class="code-span-leaf"><span class="symbol">:</span></span><span class="code-span-leaf">m</span></span><span class="symbol">.</span><span class="whitespace"> </span><span class="code-span"><span class="code-span-leaf">w</span><span class="code-span">[<span class="code-span">(<span class="code-span-leaf">i</span><span class="symbol">,</span><span class="whitespace"> </span><span class="code-span-leaf">j</span>)</span>]</span></span></span></span></span><span class="whitespace">
Expand Down Expand Up @@ -554,5 +554,5 @@
</span></div></div><div class="cell"><div class="code-block"><span class="code-span">%time<span class="whitespace">
</span><span class="code-span"><span class="code-span"><span class="code-span"><span class="code-span"><span class="code-span"><span class="code-span-leaf">multiclass_logreg</span><span class="whitespace"> </span><span class="code-span"><span class="code-span-leaf"></span>xs<span class="whitespace"> </span></span></span><span class="code-span"><span class="code-span-leaf"></span>ys<span class="whitespace"> </span></span></span><span class="code-span"><span class="code-span-leaf"></span>maxiter<span class="whitespace"> </span></span></span><span class="code-span"><span class="code-span-leaf"></span>maxls<span class="whitespace"> </span></span></span><span class="code-span"><span class="code-span-leaf"></span>tol</span></span><span class="whitespace">
</span></span></div><div class="result-block">1.609437</div><div class="result-block">
Compile time: 7.656 s
Run time: 835.600 us </div></div></div></body></html>
Compile time: 2.779 s
Run time: 391.700 us </div></div></div></body></html>
16 changes: 8 additions & 8 deletions examples/levenshtein-distance.html
Original file line number Diff line number Diff line change
Expand Up @@ -373,17 +373,17 @@
</span></div></div><div class="cell"><div class="code-block"><span class="code-span">%time<span class="whitespace">
</span><span class="code-span"><span class="code-span"><span class="code-span-leaf">levenshtein_table</span><span class="whitespace"> </span><span class="code-span"><span class="code-span-leaf"></span>[<span class="code-span-leaf">&#39;k&#39;</span><span class="symbol">,</span><span class="whitespace"> </span><span class="code-span-leaf">&#39;i&#39;</span><span class="symbol">,</span><span class="whitespace"> </span><span class="code-span-leaf">&#39;t&#39;</span><span class="symbol">,</span><span class="whitespace"> </span><span class="code-span-leaf">&#39;t&#39;</span><span class="symbol">,</span><span class="whitespace"> </span><span class="code-span-leaf">&#39;e&#39;</span><span class="symbol">,</span><span class="whitespace"> </span><span class="code-span-leaf">&#39;n&#39;</span>]<span class="whitespace"> </span></span></span><span class="code-span"><span class="code-span-leaf"></span>[<span class="code-span-leaf">&#39;s&#39;</span><span class="symbol">,</span><span class="whitespace"> </span><span class="code-span-leaf">&#39;i&#39;</span><span class="symbol">,</span><span class="whitespace"> </span><span class="code-span-leaf">&#39;t&#39;</span><span class="symbol">,</span><span class="whitespace"> </span><span class="code-span-leaf">&#39;t&#39;</span><span class="symbol">,</span><span class="whitespace"> </span><span class="code-span-leaf">&#39;i&#39;</span><span class="symbol">,</span><span class="whitespace"> </span><span class="code-span-leaf">&#39;n&#39;</span><span class="symbol">,</span><span class="whitespace"> </span><span class="code-span-leaf">&#39;g&#39;</span>]</span></span><span class="whitespace">
</span></span></div><div class="result-block">[[0, 1, 2, 3, 4, 5, 6, 7], [1, 1, 2, 3, 4, 5, 6, 7], [2, 2, 1, 2, 3, 4, 5, 6], [3, 3, 2, 1, 2, 3, 4, 5], [4, 4, 3, 2, 1, 2, 3, 4], [5, 5, 4, 3, 2, 2, 3, 4], [6, 6, 5, 4, 3, 3, 2, 3]]</div><div class="result-block">
Compile time: 619.673 ms
Run time: 309.000 us </div></div><div class="cell"><div class="code-block"><span class="whitespace">
Compile time: 351.624 ms
Run time: 143.100 us </div></div><div class="cell"><div class="code-block"><span class="whitespace">
</span></div></div><div class="cell"><div class="prose-block"><p>The actual distance is of course just the last element of the table.</p>
</div></div><div class="cell"><div class="code-block"><span class="code-span"><span class="code-span"><span class="keyword">def</span><span class="whitespace"> </span>levenshtein(<span class="code-span"><span class="code-span-leaf">xs</span><span class="code-span-leaf"><span class="symbol">:</span></span><span class="whitespace"> </span><span class="code-span"><span class="code-span-leaf">n</span><span class="code-span-leaf"><span class="symbol">=&gt;</span></span><span class="code-span-leaf">a</span></span></span><span class="symbol">,</span><span class="whitespace"> </span><span class="code-span"><span class="code-span-leaf">ys</span><span class="code-span-leaf"><span class="symbol">:</span></span><span class="whitespace"> </span><span class="code-span"><span class="code-span-leaf">m</span><span class="code-span-leaf"><span class="symbol">=&gt;</span></span><span class="code-span-leaf">a</span></span></span>)<span class="whitespace"> </span><span class="symbol">-&gt;</span><span class="whitespace"> </span><span class="code-span-leaf"><span class="type-name">Nat</span></span><span class="whitespace"> </span><span class="keyword">given</span><span class="whitespace"> </span>(<span class="code-span"><span class="code-span-leaf">n</span><span class="code-span-leaf"><span class="symbol">|</span></span><span class="code-span-leaf"><span class="type-name">Ix</span></span></span><span class="symbol">,</span><span class="whitespace"> </span><span class="code-span"><span class="code-span-leaf">m</span><span class="code-span-leaf"><span class="symbol">|</span></span><span class="code-span-leaf"><span class="type-name">Ix</span></span></span><span class="symbol">,</span><span class="whitespace"> </span><span class="code-span"><span class="code-span-leaf">a</span><span class="code-span-leaf"><span class="symbol">|</span></span><span class="code-span-leaf"><span class="type-name">Eq</span></span></span>)<span class="whitespace"> </span><span class="symbol">=</span><span class="whitespace">
</span><span class="code-span"><span class="code-span"><span class="code-span"><span class="code-span-leaf">levenshtein_table</span><span class="code-span">(<span class="code-span-leaf">xs</span><span class="symbol">,</span><span class="whitespace"> </span><span class="code-span-leaf">ys</span>)</span></span><span class="code-span">[<span class="code-span-leaf">last_ix</span><span class="symbol">,</span><span class="whitespace"> </span><span class="code-span-leaf">last_ix</span>]</span></span></span></span><span class="whitespace">
</span></span></div></div><div class="cell"><div class="code-block"><span class="whitespace">
</span></div></div><div class="cell"><div class="code-block"><span class="code-span">%time<span class="whitespace">
</span><span class="code-span"><span class="code-span"><span class="code-span-leaf">levenshtein</span><span class="whitespace"> </span><span class="code-span"><span class="code-span-leaf"></span>(<span class="code-span"><span class="code-span-leaf">iota</span><span class="whitespace"> </span><span class="code-span-leaf"><span class="symbol">$</span></span><span class="whitespace"> </span><span class="code-span"><span class="code-span-leaf"><span class="type-name">Fin</span></span><span class="whitespace"> </span><span class="code-span"><span class="code-span-leaf"></span>100</span></span></span>)<span class="whitespace"> </span></span></span><span class="code-span"><span class="code-span-leaf"></span>(<span class="code-span"><span class="code-span-leaf">iota</span><span class="whitespace"> </span><span class="code-span-leaf"><span class="symbol">$</span></span><span class="whitespace"> </span><span class="code-span"><span class="code-span-leaf"><span class="type-name">Fin</span></span><span class="whitespace"> </span><span class="code-span"><span class="code-span-leaf"></span>100</span></span></span>)</span></span><span class="whitespace">
</span></span></div><div class="result-block">0</div><div class="result-block">
Compile time: 294.183 ms
Run time: 163.000 us </div></div><div class="cell"><div class="code-block"><span class="whitespace">
Compile time: 177.136 ms
Run time: 53.300 us </div></div><div class="cell"><div class="code-block"><span class="whitespace">
</span></div></div><div class="cell"><div class="prose-block"><h2>Speed</h2>
</div></div><div class="cell"><div class="prose-block"><p>To check that we don't embarrass ourselves on performance, let's run
the Sountsov benchmark: Compute Levenshtein distances for all pairs of
Expand All @@ -396,8 +396,8 @@
</span><span class="code-span"><span class="code-span"><span class="code-span"><span class="code-span-leaf">levenshtein</span><span class="whitespace"> </span><span class="code-span"><span class="code-span-leaf"></span>(<span class="code-span"><span class="code-span-leaf">iota</span><span class="whitespace"> </span><span class="code-span-leaf"><span class="symbol">$</span></span><span class="whitespace"> </span><span class="code-span"><span class="code-span-leaf"><span class="type-name">Fin</span></span><span class="whitespace"> </span><span class="code-span"><span class="code-span-leaf"></span>iint</span></span></span>)<span class="whitespace"> </span></span></span><span class="code-span"><span class="code-span-leaf"></span>(<span class="code-span"><span class="code-span-leaf">iota</span><span class="whitespace"> </span><span class="code-span-leaf"><span class="symbol">$</span></span><span class="whitespace"> </span><span class="code-span"><span class="code-span-leaf"><span class="type-name">Fin</span></span><span class="whitespace"> </span><span class="code-span"><span class="code-span-leaf"></span>jint</span></span></span>)</span></span></span></span></span></span></span><span class="whitespace">
</span></span></div><div class="result-block">
Sountsov Benchmark
Compile time: 142.499 ms
Run time: 78.456 ms (based on 26 runs)</div></div><div class="cell"><div class="code-block"><span class="code-span"><span class="code-span"><span class="code-span-leaf">sum</span><span class="code-span">(<span class="code-span"><span class="code-span-leaf">sum</span><span class="code-span">(<span class="code-span-leaf">answer</span>)</span></span>)</span></span><span class="whitespace">
Compile time: 76.633 ms
Run time: 38.838 ms (based on 52 runs)</div></div><div class="cell"><div class="code-block"><span class="code-span"><span class="code-span"><span class="code-span-leaf">sum</span><span class="code-span">(<span class="code-span"><span class="code-span-leaf">sum</span><span class="code-span">(<span class="code-span-leaf">answer</span>)</span></span>)</span></span><span class="whitespace">
</span></span></div><div class="result-block">333300</div></div><div class="cell"><div class="code-block"><span class="whitespace">
</span></div></div><div class="cell"><div class="prose-block"><p>The straightforward C++ program for this takes about 35ms on my
workstation, so Dex performance is in the right ballpark. (And we
Expand All @@ -418,8 +418,8 @@
</span></div></div><div class="cell"><div class="code-block"><span class="code-span">%time<span class="whitespace">
</span><span class="code-span"><span class="code-span-leaf">closest_word</span><span class="whitespace"> </span><span class="code-span"><span class="code-span-leaf"></span>&quot;hello&quot;</span></span><span class="whitespace">
</span></span></div><div class="result-block">&quot;hello&quot;</div><div class="result-block">
Compile time: 325.490 ms
Run time: 165.681 ms </div></div><div class="cell"><div class="code-block"><span class="whitespace">
Compile time: 194.843 ms
Run time: 74.451 ms </div></div><div class="cell"><div class="code-block"><span class="whitespace">
</span></div></div><div class="cell"><div class="code-block"><span class="code-span"><span class="code-span"><span class="code-span-leaf">closest_word</span><span class="whitespace"> </span><span class="code-span"><span class="code-span-leaf"></span>&quot;kitttens&quot;</span></span><span class="whitespace">
</span></span></div><div class="result-block">&quot;kittens&quot;</div></div><div class="cell"><div class="code-block"><span class="code-span"><span class="code-span"><span class="code-span-leaf">closest_word</span><span class="whitespace"> </span><span class="code-span"><span class="code-span-leaf"></span>&quot;functor&quot;</span></span><span class="whitespace">
</span></span></div><div class="result-block">&quot;function&quot;</div></div><div class="cell"><div class="code-block"><span class="code-span"><span class="code-span"><span class="code-span-leaf">closest_word</span><span class="whitespace"> </span><span class="code-span"><span class="code-span-leaf"></span>&quot;applicative&quot;</span></span><span class="whitespace">
Expand Down
Loading

0 comments on commit 9a1853e

Please sign in to comment.