pre-commit: Add codespell and other checks (#263)

This commit is contained in:
Christian Clauss
2022-05-06 23:23:14 +02:00
committed by GitHub
parent 990b0b2797
commit fadb4a67e7
9 changed files with 69 additions and 28 deletions

View File

@@ -1,5 +1,3 @@
from typing import Tuple
import numpy as np
from numpy.polynomial import Polynomial
@@ -14,7 +12,7 @@ def mandelbrot(
max_iterations: int = 100
) -> np.array:
"""
From https://www.learnpythonwithrune.org/numpy-compute-mandelbrot-set-by-vectorization/.
https://www.learnpythonwithrune.org/numpy-compute-mandelbrot-set-by-vectorization
"""
# To make navigation easier we calculate these values
x_width, y_height = 1.5, 1.5 * height / width
@@ -56,7 +54,7 @@ def julia(
max_iterations: int = 100
) -> np.array:
"""
From https://www.learnpythonwithrune.org/numpy-calculate-the-julia-set-with-vectorization/.
https://www.learnpythonwithrune.org/numpy-calculate-the-julia-set-with-vectorization
"""
# To make navigation easier we calculate these values
x_width, y_height = 1.5, 1.5 * height / width
@@ -84,7 +82,7 @@ def julia(
return div_time
Range = Tuple[float, float]
Range = tuple[float, float]
def newton(
@@ -96,7 +94,7 @@ def newton(
xr: Range = (-2.5, 1),
yr: Range = (-1, 1),
max_iterations: int = 100
) -> (np.array, np.array):
) -> tuple[np.array, np.array]:
""" """
# To make navigation easier we calculate these values
x_from, x_to = xr

File diff suppressed because one or more lines are too long

View File

@@ -42,7 +42,7 @@
<p>
Currently the <code>&gt;</code> symbol is being imported incorrectly as <code>&ampgt;</code> into the REPL's.
In this app the <code>&gt;</code> symbol has been replaced with <code>().__gt__()</code> so you can run the code
without issue. Ex: intead of <code>a &gt; b</code>, you will see <code>(a).__gt__(b)</code> instead. <br>
without issue. Ex: instead of <code>a &gt; b</code>, you will see <code>(a).__gt__(b)</code> instead. <br>
</p>
<p>
<py-script>import js; js.document.getElementById('python-status').innerHTML = 'Python is now ready. You may proceed.'</py-script>

View File

@@ -8,7 +8,7 @@ import numpy as np
# cell
from micrograd.engine import Value
from micrograd.nn import MLP, Layer, Neuron
from micrograd.nn import MLP
print_statements = []
@@ -43,7 +43,8 @@ def micrograd_demo(*args, **kwargs):
random.seed(1337)
# cell
# An adaptation of sklearn's make_moons function https://scikit-learn.org/stable/modules/generated/sklearn.datasets.make_moons.html
# An adaptation of sklearn's make_moons function
# https://scikit-learn.org/stable/modules/generated/sklearn.datasets.make_moons.html
def make_moons(n_samples=100, noise=None):
n_samples_out, n_samples_in = n_samples, n_samples
@@ -102,7 +103,7 @@ def micrograd_demo(*args, **kwargs):
data_loss = sum(losses) * (1.0 / len(losses))
# L2 regularization
alpha = 1e-4
reg_loss = alpha * sum((p * p for p in model.parameters()))
reg_loss = alpha * sum(p * p for p in model.parameters())
total_loss = data_loss + reg_loss
# also get accuracy
@@ -120,7 +121,7 @@ def micrograd_demo(*args, **kwargs):
for k in range(20): # was 100
# forward
total_loss, acc = loss()
total_loss, _ = loss()
# backward
model.zero_grad()
@@ -146,7 +147,7 @@ def micrograd_demo(*args, **kwargs):
Z = np.array([(s.data).__gt__(0) for s in scores])
Z = Z.reshape(xx.shape)
fig = plt.figure()
_ = plt.figure()
plt.contourf(xx, yy, Z, cmap=plt.cm.Spectral, alpha=0.8)
plt.scatter(X[:, 0], X[:, 1], c=y, s=40, cmap=plt.cm.Spectral)
plt.xlim(xx.min(), xx.max())

View File

@@ -1,6 +1,5 @@
from datetime import datetime as dt
from js import console
from utils import add_class, remove_class
tasks = []
@@ -27,7 +26,8 @@ def add_task(*ags, **kws):
tasks.append(task)
# add the task element to the page as new node in the list by cloning from a template
# add the task element to the page as new node in the list by cloning from a
# template
task_html = task_template.clone(task_id, to=task_list)
task_html_content = task_html.select("p")
task_html_content.element.innerText = task["content"]