Skip to content

Commit

Permalink
Deploying to gh-pages from @ d571ed6 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudo-rnd-thoughts committed Oct 12, 2024
1 parent 8e4f03e commit 35db002
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion main/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: f1b0e61f71c829ea379aa85a1bed8bf6
config: 08e0168e0cb3d9e88a33479fd0227a03
tags: d77d1c0d9ca2f4c8421862c7c5a0d620
Binary file not shown.
Binary file not shown.
18 changes: 9 additions & 9 deletions main/_modules/gymnasium/wrappers/numpy_to_torch/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -403,25 +403,25 @@ <h1>Source code for gymnasium.wrappers.numpy_to_torch</h1><div class="highlight"

<span class="nd">@torch_to_numpy</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">numbers</span><span class="o">.</span><span class="n">Number</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">_number_to_numpy</span><span class="p">(</span><span class="n">value</span><span class="p">:</span> <span class="n">numbers</span><span class="o">.</span><span class="n">Number</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Any</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Convert a python number (int, float, complex) to a numpy array.&quot;&quot;&quot;</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Convert a python number (int, float, complex) to a NumPy array.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>


<span class="nd">@torch_to_numpy</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">torch</span><span class="o">.</span><span class="n">Tensor</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">_torch_to_numpy</span><span class="p">(</span><span class="n">value</span><span class="p">:</span> <span class="n">torch</span><span class="o">.</span><span class="n">Tensor</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Any</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Convert a torch.Tensor to a numpy array.&quot;&quot;&quot;</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Convert a torch.Tensor to a NumPy array.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">value</span><span class="o">.</span><span class="n">numpy</span><span class="p">(</span><span class="n">force</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>


<span class="nd">@torch_to_numpy</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">abc</span><span class="o">.</span><span class="n">Mapping</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">_mapping_torch_to_numpy</span><span class="p">(</span><span class="n">value</span><span class="p">:</span> <span class="n">Mapping</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Any</span><span class="p">])</span> <span class="o">-&gt;</span> <span class="n">Mapping</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Any</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Converts a mapping of PyTorch Tensors into a Dictionary of Jax Array.&quot;&quot;&quot;</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Converts a mapping of PyTorch Tensors into a Dictionary of NumPy Array.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="nb">type</span><span class="p">(</span><span class="n">value</span><span class="p">)(</span><span class="o">**</span><span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">torch_to_numpy</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">value</span><span class="o">.</span><span class="n">items</span><span class="p">()})</span>


<span class="nd">@torch_to_numpy</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">abc</span><span class="o">.</span><span class="n">Iterable</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">_iterable_torch_to_numpy</span><span class="p">(</span><span class="n">value</span><span class="p">:</span> <span class="n">Iterable</span><span class="p">[</span><span class="n">Any</span><span class="p">])</span> <span class="o">-&gt;</span> <span class="n">Iterable</span><span class="p">[</span><span class="n">Any</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Converts an Iterable from PyTorch Tensors to an iterable of Jax Array.&quot;&quot;&quot;</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Converts an Iterable from PyTorch Tensors to an iterable of NumPy Array.&quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="s2">&quot;_make&quot;</span><span class="p">):</span>
<span class="c1"># namedtuple - underline used to prevent potential name conflicts</span>
<span class="c1"># noinspection PyProtectedMember</span>
Expand All @@ -432,7 +432,7 @@ <h1>Source code for gymnasium.wrappers.numpy_to_torch</h1><div class="highlight"

<span class="nd">@functools</span><span class="o">.</span><span class="n">singledispatch</span>
<span class="k">def</span> <span class="nf">numpy_to_torch</span><span class="p">(</span><span class="n">value</span><span class="p">:</span> <span class="n">Any</span><span class="p">,</span> <span class="n">device</span><span class="p">:</span> <span class="n">Device</span> <span class="o">|</span> <span class="kc">None</span> <span class="o">=</span> <span class="kc">None</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Any</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Converts a Jax Array into a PyTorch Tensor.&quot;&quot;&quot;</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Converts a NumPy Array into a PyTorch Tensor.&quot;&quot;&quot;</span>
<span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span>
<span class="sa">f</span><span class="s2">&quot;No known conversion for NumPy type (</span><span class="si">{</span><span class="nb">type</span><span class="p">(</span><span class="n">value</span><span class="p">)</span><span class="si">}</span><span class="s2">) to PyTorch registered. Report as issue on github.&quot;</span>
<span class="p">)</span>
Expand All @@ -441,7 +441,7 @@ <h1>Source code for gymnasium.wrappers.numpy_to_torch</h1><div class="highlight"
<span class="nd">@numpy_to_torch</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">numbers</span><span class="o">.</span><span class="n">Number</span><span class="p">)</span>
<span class="nd">@numpy_to_torch</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">_numpy_to_torch</span><span class="p">(</span><span class="n">value</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">device</span><span class="p">:</span> <span class="n">Device</span> <span class="o">|</span> <span class="kc">None</span> <span class="o">=</span> <span class="kc">None</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">torch</span><span class="o">.</span><span class="n">Tensor</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Converts a Jax Array into a PyTorch Tensor.&quot;&quot;&quot;</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Converts a NumPy Array into a PyTorch Tensor.&quot;&quot;&quot;</span>
<span class="k">assert</span> <span class="n">torch</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>
<span class="n">tensor</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">tensor</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
<span class="k">if</span> <span class="n">device</span><span class="p">:</span>
Expand All @@ -453,15 +453,15 @@ <h1>Source code for gymnasium.wrappers.numpy_to_torch</h1><div class="highlight"
<span class="k">def</span> <span class="nf">_numpy_mapping_to_torch</span><span class="p">(</span>
<span class="n">value</span><span class="p">:</span> <span class="n">Mapping</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Any</span><span class="p">],</span> <span class="n">device</span><span class="p">:</span> <span class="n">Device</span> <span class="o">|</span> <span class="kc">None</span> <span class="o">=</span> <span class="kc">None</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Mapping</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Any</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Converts a mapping of Jax Array into a Dictionary of PyTorch Tensors.&quot;&quot;&quot;</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Converts a mapping of NumPy Array into a Dictionary of PyTorch Tensors.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="nb">type</span><span class="p">(</span><span class="n">value</span><span class="p">)(</span><span class="o">**</span><span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">numpy_to_torch</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">device</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">value</span><span class="o">.</span><span class="n">items</span><span class="p">()})</span>


<span class="nd">@numpy_to_torch</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">abc</span><span class="o">.</span><span class="n">Iterable</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">_numpy_iterable_to_torch</span><span class="p">(</span>
<span class="n">value</span><span class="p">:</span> <span class="n">Iterable</span><span class="p">[</span><span class="n">Any</span><span class="p">],</span> <span class="n">device</span><span class="p">:</span> <span class="n">Device</span> <span class="o">|</span> <span class="kc">None</span> <span class="o">=</span> <span class="kc">None</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Iterable</span><span class="p">[</span><span class="n">Any</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Converts an Iterable from Jax Array to an iterable of PyTorch Tensors.&quot;&quot;&quot;</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Converts an Iterable from NumPy Array to an iterable of PyTorch Tensors.&quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="s2">&quot;_make&quot;</span><span class="p">):</span>
<span class="c1"># namedtuple - underline used to prevent potential name conflicts</span>
<span class="c1"># noinspection PyProtectedMember</span>
Expand Down Expand Up @@ -508,7 +508,7 @@ <h1>Source code for gymnasium.wrappers.numpy_to_torch</h1><div class="highlight"
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Wrapper class to change inputs and outputs of environment to PyTorch tensors.</span>

<span class="sd"> Args:</span>
<span class="sd"> env: The Jax-based environment to wrap</span>
<span class="sd"> env: The NumPy-based environment to wrap</span>
<span class="sd"> device: The device the torch Tensors should be moved to</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">gym</span><span class="o">.</span><span class="n">utils</span><span class="o">.</span><span class="n">RecordConstructorArgs</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">device</span><span class="o">=</span><span class="n">device</span><span class="p">)</span>
Expand Down
2 changes: 1 addition & 1 deletion main/api/wrappers/misc_wrappers/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ <h2>Data Conversion Wrappers<a class="headerlink" href="#data-conversion-wrapper
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>env</strong> – The Jax-based environment to wrap</p></li>
<li><p><strong>env</strong> – The NumPy-based environment to wrap</p></li>
<li><p><strong>device</strong> – The device the torch Tensors should be moved to</p></li>
</ul>
</dd>
Expand Down

0 comments on commit 35db002

Please sign in to comment.