Skip to content

Commit

Permalink
Operator, Plot, Audio
Browse files Browse the repository at this point in the history
  • Loading branch information
gto76 committed Nov 27, 2024
1 parent bfb81f1 commit 5b21977
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2168,7 +2168,7 @@ with <lock>: # Enters the block by calling acq

Operator
--------
**Module of functions that provide the functionality of operators. Functions are ordered by operator precedence, starting with least binding.**
**Module of functions that provide the functionality of operators. Functions are ordered and grouped by operator precedence from least to most binding. Logical and arithmetic operators in rows 1, 3 and 5 are also ordered by precedence within a group.**
```python
import operator as op
```
Expand Down Expand Up @@ -2419,9 +2419,9 @@ import matplotlib.pyplot as plt
plt.plot/bar/scatter(x_data, y_data [, label=<str>]) # Also plt.plot(y_data).
plt.legend() # Adds a legend.
plt.title/xlabel/ylabel(<str>) # Adds a title or label.
plt.savefig(<path>) # Saves the figure.
plt.show() # Displays the figure.
plt.clf() # Clears the figure.
plt.savefig(<path>) # Saves the plot.
plt.show() # Displays the plot.
plt.clf() # Clears the plot.
```


Expand Down Expand Up @@ -2876,7 +2876,7 @@ import wave
<int> = <Wave>.getnchannels() # Returns number of samples per frame.
<int> = <Wave>.getsampwidth() # Returns number of bytes per sample.
<tuple> = <Wave>.getparams() # Returns namedtuple of all parameters.
<bytes> = <Wave>.readframes(nframes) # Returns next n frames. All if -1.
<bytes> = <Wave>.readframes(nframes) # Returns next n frames (-1 returns all).
```

```python
Expand Down Expand Up @@ -2913,7 +2913,7 @@ def read_wav_file(filename):
p = file.getparams()
frames = file.readframes(-1)
bytes_samples = (frames[i : i + p.sampwidth] for i in range(0, len(frames), p.sampwidth))
return [get_int(b) / pow(2, p.sampwidth * 8 - 1) for b in bytes_samples], p
return [get_int(b) / pow(2, (p.sampwidth * 8) - 1) for b in bytes_samples], p
```

### Write Float Samples to WAV File
Expand All @@ -2922,7 +2922,7 @@ def write_to_wav_file(filename, samples_f, p=None, nchannels=1, sampwidth=2, fra
def get_bytes(a_float):
a_float = max(-1, min(1 - 2e-16, a_float))
a_float += p.sampwidth == 1
a_float *= pow(2, p.sampwidth * 8 - 1)
a_float *= pow(2, (p.sampwidth * 8) - 1)
return int(a_float).to_bytes(p.sampwidth, 'little', signed=(p.sampwidth != 1))
if p is None:
p = wave._wave_params(nchannels, sampwidth, framerate, 0, 'NONE', 'not compressed')
Expand Down
14 changes: 7 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1775,7 +1775,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
<li><strong>Exceptions that happen inside threads are raised when map iterator's next() or Future's result() are called. Future's exception() method returns exception object or None.</strong></li>
<li><strong>ProcessPoolExecutor provides true parallelism but: everything sent to/from workers must be <a href="#pickle">pickable</a>, queues must be sent using executor's 'initargs' and 'initializer' parameters, and executor should only be reachable via <code class="python hljs"><span class="hljs-string">'if __name__ == "__main__": ...'</span></code>.</strong></li>
</ul>
<div><h2 id="operator"><a href="#operator" name="operator">#</a>Operator</h2><p><strong>Module of functions that provide the functionality of operators. Functions are ordered by operator precedence, starting with least binding.</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> operator <span class="hljs-keyword">as</span> op
<div><h2 id="operator"><a href="#operator" name="operator">#</a>Operator</h2><p><strong>Module of functions that provide the functionality of operators. Functions are ordered and grouped by operator precedence from least to most binding. Logical and arithmetic operators in rows 1, 3 and 5 are also ordered by precedence within a group.</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> operator <span class="hljs-keyword">as</span> op
</code></pre></div>


Expand Down Expand Up @@ -1979,9 +1979,9 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
plt.plot/bar/scatter(x_data, y_data [, label=&lt;str&gt;]) <span class="hljs-comment"># Also plt.plot(y_data).</span>
plt.legend() <span class="hljs-comment"># Adds a legend.</span>
plt.title/xlabel/ylabel(&lt;str&gt;) <span class="hljs-comment"># Adds a title or label.</span>
plt.savefig(&lt;path&gt;) <span class="hljs-comment"># Saves the figure.</span>
plt.show() <span class="hljs-comment"># Displays the figure.</span>
plt.clf() <span class="hljs-comment"># Clears the figure.</span>
plt.savefig(&lt;path&gt;) <span class="hljs-comment"># Saves the plot.</span>
plt.show() <span class="hljs-comment"># Displays the plot.</span>
plt.clf() <span class="hljs-comment"># Clears the plot.</span>
</code></pre></div>

<div><h2 id="table"><a href="#table" name="table">#</a>Table</h2><div><h4 id="printsacsvspreadsheettotheconsole">Prints a CSV spreadsheet to the console:</h4><pre><code class="python language-python hljs"><span class="hljs-comment"># $ pip3 install tabulate</span>
Expand Down Expand Up @@ -2342,7 +2342,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
&lt;int&gt; = &lt;Wave&gt;.getnchannels() <span class="hljs-comment"># Returns number of samples per frame.</span>
&lt;int&gt; = &lt;Wave&gt;.getsampwidth() <span class="hljs-comment"># Returns number of bytes per sample.</span>
&lt;tuple&gt; = &lt;Wave&gt;.getparams() <span class="hljs-comment"># Returns namedtuple of all parameters.</span>
&lt;bytes&gt; = &lt;Wave&gt;.readframes(nframes) <span class="hljs-comment"># Returns next n frames. All if -1.</span>
&lt;bytes&gt; = &lt;Wave&gt;.readframes(nframes) <span class="hljs-comment"># Returns next n frames (-1 returns all).</span>
</code></pre>
<pre><code class="python language-python hljs">&lt;Wave&gt; = wave.open(<span class="hljs-string">'&lt;path&gt;'</span>, <span class="hljs-string">'wb'</span>) <span class="hljs-comment"># Creates/truncates a file for writing.</span>
&lt;Wave&gt;.setframerate(&lt;int&gt;) <span class="hljs-comment"># Pass 44100 for CD, 48000 for video.</span>
Expand Down Expand Up @@ -2374,14 +2374,14 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
p = file.getparams()
frames = file.readframes(<span class="hljs-number">-1</span>)
bytes_samples = (frames[i : i + p.sampwidth] <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">0</span>, len(frames), p.sampwidth))
<span class="hljs-keyword">return</span> [get_int(b) / pow(<span class="hljs-number">2</span>, p.sampwidth * <span class="hljs-number">8</span> - <span class="hljs-number">1</span>) <span class="hljs-keyword">for</span> b <span class="hljs-keyword">in</span> bytes_samples], p
<span class="hljs-keyword">return</span> [get_int(b) / pow(<span class="hljs-number">2</span>, (p.sampwidth * <span class="hljs-number">8</span>) - <span class="hljs-number">1</span>) <span class="hljs-keyword">for</span> b <span class="hljs-keyword">in</span> bytes_samples], p
</code></pre></div>

<div><h3 id="writefloatsamplestowavfile">Write Float Samples to WAV File</h3><pre><code class="python language-python hljs"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">write_to_wav_file</span><span class="hljs-params">(filename, samples_f, p=<span class="hljs-keyword">None</span>, nchannels=<span class="hljs-number">1</span>, sampwidth=<span class="hljs-number">2</span>, framerate=<span class="hljs-number">44100</span>)</span>:</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_bytes</span><span class="hljs-params">(a_float)</span>:</span>
a_float = max(<span class="hljs-number">-1</span>, min(<span class="hljs-number">1</span> - <span class="hljs-number">2e-16</span>, a_float))
a_float += p.sampwidth == <span class="hljs-number">1</span>
a_float *= pow(<span class="hljs-number">2</span>, p.sampwidth * <span class="hljs-number">8</span> - <span class="hljs-number">1</span>)
a_float *= pow(<span class="hljs-number">2</span>, (p.sampwidth * <span class="hljs-number">8</span>) - <span class="hljs-number">1</span>)
<span class="hljs-keyword">return</span> int(a_float).to_bytes(p.sampwidth, <span class="hljs-string">'little'</span>, signed=(p.sampwidth != <span class="hljs-number">1</span>))
<span class="hljs-keyword">if</span> p <span class="hljs-keyword">is</span> <span class="hljs-keyword">None</span>:
p = wave._wave_params(nchannels, sampwidth, framerate, <span class="hljs-number">0</span>, <span class="hljs-string">'NONE'</span>, <span class="hljs-string">'not compressed'</span>)
Expand Down
8 changes: 1 addition & 7 deletions parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ const CONSTRUCTOR_OVERLOADING =
' <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self, a=<span class="hljs-keyword">None</span>)</span>:</span>\n' +
' self.a = a\n';

const DATACLASS =
'&lt;class&gt; = make_dataclass(<span class="hljs-string">\'&lt;class_name&gt;\'</span>, &lt;coll_of_attribute_names&gt;)\n' +
'&lt;class&gt; = make_dataclass(<span class="hljs-string">\'&lt;class_name&gt;\'</span>, &lt;coll_of_tuples&gt;)\n' +
'&lt;tuple&gt; = (<span class="hljs-string">\'&lt;attr_name&gt;\'</span>, &lt;type&gt; [, &lt;default_value&gt;])';

const SHUTIL_COPY =
'shutil.copy(from, to) <span class="hljs-comment"># Copies the file. \'to\' can exist or be a dir.</span>\n' +
'shutil.copy2(from, to) <span class="hljs-comment"># Also copies creation and modification time.</span>\n' +
Expand Down Expand Up @@ -221,7 +216,7 @@ const AUDIO_1 =
' <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_bytes</span><span class="hljs-params">(a_float)</span>:</span>\n' +
' a_float = max(<span class="hljs-number">-1</span>, min(<span class="hljs-number">1</span> - <span class="hljs-number">2e-16</span>, a_float))\n' +
' a_float += p.sampwidth == <span class="hljs-number">1</span>\n' +
' a_float *= pow(<span class="hljs-number">2</span>, p.sampwidth * <span class="hljs-number">8</span> - <span class="hljs-number">1</span>)\n' +
' a_float *= pow(<span class="hljs-number">2</span>, (p.sampwidth * <span class="hljs-number">8</span>) - <span class="hljs-number">1</span>)\n' +
' <span class="hljs-keyword">return</span> int(a_float).to_bytes(p.sampwidth, <span class="hljs-string">\'little\'</span>, signed=(p.sampwidth != <span class="hljs-number">1</span>))\n' +
' <span class="hljs-keyword">if</span> p <span class="hljs-keyword">is</span> <span class="hljs-keyword">None</span>:\n' +
' p = wave._wave_params(nchannels, sampwidth, framerate, <span class="hljs-number">0</span>, <span class="hljs-string">\'NONE\'</span>, <span class="hljs-string">\'not compressed\'</span>)\n' +
Expand Down Expand Up @@ -843,7 +838,6 @@ function fixHighlights() {
$(`code:contains(@debug(print_result=True))`).html(PARAMETRIZED_DECORATOR);
$(`code:contains(print/str/repr([<obj>]))`).html(REPR_USE_CASES);
$(`code:contains((self, a=None):)`).html(CONSTRUCTOR_OVERLOADING);
//$(`code:contains(make_dataclass(\'<class_name>\')`).html(DATACLASS);
$(`code:contains(shutil.copy)`).html(SHUTIL_COPY);
$(`code:contains(os.rename)`).html(OS_RENAME);
$(`code:contains(\'<n>s\')`).html(STRUCT_FORMAT);
Expand Down

0 comments on commit 5b21977

Please sign in to comment.