-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Documenter.jl
committed
Jul 2, 2024
1 parent
718457f
commit def3aca
Showing
10 changed files
with
34 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"documenter":{"julia_version":"1.10.4","generation_timestamp":"2024-06-27T18:24:59","documenter_version":"1.5.0"}} | ||
{"documenter":{"julia_version":"1.10.4","generation_timestamp":"2024-07-02T14:44:20","documenter_version":"1.5.0"}} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>Usage from Python · RationalFunctionApproximation.jl</title><meta name="title" content="Usage from Python · RationalFunctionApproximation.jl"/><meta property="og:title" content="Usage from Python · RationalFunctionApproximation.jl"/><meta property="twitter:title" content="Usage from Python · RationalFunctionApproximation.jl"/><meta name="description" content="Documentation for RationalFunctionApproximation.jl."/><meta property="og:description" content="Documentation for RationalFunctionApproximation.jl."/><meta property="twitter:description" content="Documentation for RationalFunctionApproximation.jl."/><meta property="og:url" content="https://complexvariables.github.io/RationalFunctionApproximation.jl/python/"/><meta property="twitter:url" content="https://complexvariables.github.io/RationalFunctionApproximation.jl/python/"/><link rel="canonical" href="https://complexvariables.github.io/RationalFunctionApproximation.jl/python/"/><script data-outdated-warner src="../assets/warner.js"></script><link href="https://cdnjs.cloudflare.com/ajax/libs/lato-font/3.0.0/css/lato-font.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/juliamono/0.050/juliamono.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/fontawesome.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/solid.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/brands.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.8/katex.min.css" rel="stylesheet" type="text/css"/><script>documenterBaseURL=".."</script><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" data-main="../assets/documenter.js"></script><script src="../search_index.js"></script><script src="../siteinfo.js"></script><script src="../../versions.js"></script><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/catppuccin-mocha.css" data-theme-name="catppuccin-mocha"/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/catppuccin-macchiato.css" data-theme-name="catppuccin-macchiato"/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/catppuccin-frappe.css" data-theme-name="catppuccin-frappe"/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/catppuccin-latte.css" data-theme-name="catppuccin-latte"/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/documenter-dark.css" data-theme-name="documenter-dark" data-theme-primary-dark/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/documenter-light.css" data-theme-name="documenter-light" data-theme-primary/><script src="../assets/themeswap.js"></script></head><body><div id="documenter"><nav class="docs-sidebar"><div class="docs-package-name"><span class="docs-autofit"><a href="../">RationalFunctionApproximation.jl</a></span></div><button class="docs-search-query input is-rounded is-small is-clickable my-2 mx-auto py-1 px-2" id="documenter-search-query">Search docs (Ctrl + /)</button><ul class="docs-menu"><li><a class="tocitem" href="../">Walkthrough</a></li><li><a class="tocitem" href="../convergence/">Convergence</a></li><li><a class="tocitem" href="../minimax/">Minimax</a></li><li><a class="tocitem" href="../domains/">Domains</a></li><li><a class="tocitem" href="../mode/">Discrete vs. continuous</a></li><li class="is-active"><a class="tocitem" href>Usage from Python</a><ul class="internal"><li><a class="tocitem" href="#Installation"><span>Installation</span></a></li><li><a class="tocitem" href="#Usage"><span>Usage</span></a></li><li><a class="tocitem" href="#Passing-Python-functions"><span>Passing Python functions</span></a></li></ul></li><li><a class="tocitem" href="../functions/">Function API</a></li></ul><div class="docs-version-selector field has-addons"><div class="control"><span class="docs-label button is-static is-size-7">Version</span></div><div class="docs-selector control is-expanded"><div class="select is-fullwidth is-size-7"><select id="documenter-version-selector"></select></div></div></div></nav><div class="docs-main"><header class="docs-navbar"><a class="docs-sidebar-button docs-navbar-link fa-solid fa-bars is-hidden-desktop" id="documenter-sidebar-button" href="#"></a><nav class="breadcrumb"><ul class="is-hidden-mobile"><li class="is-active"><a href>Usage from Python</a></li></ul><ul class="is-hidden-tablet"><li class="is-active"><a href>Usage from Python</a></li></ul></nav><div class="docs-right"><a class="docs-navbar-link" href="https://github.com/complexvariables/RationalFunctionApproximation.jl" title="View the repository on GitHub"><span class="docs-icon fa-brands"></span><span class="docs-label is-hidden-touch">GitHub</span></a><a class="docs-navbar-link" href="https://github.com/complexvariables/RationalFunctionApproximation.jl/blob/main/docs/src/python.md#" title="Edit source on GitHub"><span class="docs-icon fa-solid"></span></a><a class="docs-settings-button docs-navbar-link fa-solid fa-gear" id="documenter-settings-button" href="#" title="Settings"></a><a class="docs-article-toggle-button fa-solid fa-chevron-up" id="documenter-article-toggle-button" href="javascript:;" title="Collapse all docstrings"></a></div></header><article class="content" id="documenter-page"><h1 id="Calling-from-Python"><a class="docs-heading-anchor" href="#Calling-from-Python">Calling from Python</a><a id="Calling-from-Python-1"></a><a class="docs-heading-anchor-permalink" href="#Calling-from-Python" title="Permalink"></a></h1><p>You can call the functions in this package from Python using the <a href="https://juliapy.github.io/PythonCall.jl/stable/"><code>PythonCall</code>/<code>JuliaCall</code></a> package. </p><h2 id="Installation"><a class="docs-heading-anchor" href="#Installation">Installation</a><a id="Installation-1"></a><a class="docs-heading-anchor-permalink" href="#Installation" title="Permalink"></a></h2><p>It's recommended to create a new virtual environment to try this out. In Python, you need to install <code>juliacall</code> via</p><pre><code class="language-bash hljs">pip install juliacall</code></pre><p>Then you start Python and run:</p><pre><code class="language-python hljs">from juliacall import Main as jl</code></pre><p>This will download and initialize a copy of Julia. Finally, you need to install this package in that Julia environment:</p><pre><code class="language-python hljs">jl.seval('using Pkg; Pkg.add("RationalFunctionApproximation")')</code></pre><p>That should be all you need in the Python environment.</p><h2 id="Usage"><a class="docs-heading-anchor" href="#Usage">Usage</a><a id="Usage-1"></a><a class="docs-heading-anchor-permalink" href="#Usage" title="Permalink"></a></h2><p>In each new Python session, you need to load the packages:</p><pre><code class="language-python hljs">from juliacall import Main as jl | ||
jl.seval('using RationalFunctionApproximation, PythonCall')</code></pre><p>All the functions and constants exposed to Julia by this package are available using the <code>jl</code> object. For example, to use the discrete AAA algorithm:</p><pre><code class="language-python hljs">import numpy as np # if installed in Python | ||
x = np.linspace(-1, 1, 1000) | ||
y = np.tanh(5 * (x - 0.2)) | ||
r = jl.aaa(x, y) | ||
print(r)</code></pre><pre><code class="nohighlight hljs">Barycentric rational function of type (11,11)</code></pre><p>This will return a wrapped Julia object that you can use in Python as if it were a Python object. For example, you can evaluate the approximation at a point:</p><pre><code class="language-python hljs">r(0.5)</code></pre><pre><code class="nohighlight hljs">0.9051482536448658</code></pre><p>If you want to apply the function at multiple points, you can use comprehensions or vectorize it in numpy:</p><pre><code class="language-python hljs">rv = np.vectorize(r) | ||
rv(np.array([0.5, 0.6, 0.7]))</code></pre><pre><code class="nohighlight hljs">array([0.90514825, 0.96402758, 0.9866143 ])</code></pre><p>You can get information about the approximation using any documented function in the package, e.g.:</p><pre><code class="language-python hljs">print(jl.poles(r)) # returns wrapped Julia type</code></pre><pre><code class="nohighlight hljs">ComplexF64[0.20000000000544785 - 0.31415926535542893im, 0.20000000000544788 + 0.31415926535542893im, 0.20000207991810143 - 0.942477292594254im, 0.20000207991810143 + 0.9424772925942541im, 0.20308324780986833 - 1.5724812056318853im, 0.20308324780986833 + 1.5724812056318853im, 0.29268586746842673 - 2.3408220889660796im, 0.29268586746842673 + 2.34082208896608im, 0.9695028397625358 + 4.390786420000105im, 0.969502839762536 - 4.390786420000105im, 21.59156666159181 + 0.0im]</code></pre><pre><code class="language-python hljs">print(np.array(jl.residues(r))) # converts to numpy array</code></pre><pre><code class="nohighlight hljs">[ 0.2 +2.72029915e-11j 0.2 -2.72031942e-11j | ||
0.19999893+6.55140711e-06j 0.19999893-6.55140637e-06j | ||
0.20352821+4.86975387e-03j 0.20352821-4.86975387e-03j | ||
0.33454619+6.91112099e-02j 0.33454619-6.91112099e-02j | ||
1.25164001-5.59634589e-01j 1.25164001+5.59634589e-01j | ||
-32.51419889+0.00000000e+00j]</code></pre><h2 id="Passing-Python-functions"><a class="docs-heading-anchor" href="#Passing-Python-functions">Passing Python functions</a><a id="Passing-Python-functions-1"></a><a class="docs-heading-anchor-permalink" href="#Passing-Python-functions" title="Permalink"></a></h2><p>To use continuous approximation, you can pass a Python function to the <code>approximate</code> function.</p><pre><code class="language-python hljs">def f(x): | ||
return np.tanh(5 * (x - 0.2)) | ||
|
||
r = jl.approximate(f, jl.unit_interval) | ||
r(.5)</code></pre><pre><code class="nohighlight hljs">0.9051482536448647</code></pre></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../mode/">« Discrete vs. continuous</a><a class="docs-footer-nextpage" href="../functions/">Function API »</a><div class="flexbox-break"></div><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="auto">Automatic (OS)</option><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option><option value="catppuccin-latte">catppuccin-latte</option><option value="catppuccin-frappe">catppuccin-frappe</option><option value="catppuccin-macchiato">catppuccin-macchiato</option><option value="catppuccin-mocha">catppuccin-mocha</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.5.0 on <span class="colophon-date" title="Tuesday 2 July 2024 14:44">Tuesday 2 July 2024</span>. Using Julia version 1.10.4.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html> |
Large diffs are not rendered by default.
Oops, something went wrong.