diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml new file mode 100644 index 0000000..2105a4b --- /dev/null +++ b/.github/workflows/tox.yml @@ -0,0 +1,25 @@ +name: tox + +on: + - push + - pull_request + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.11'] + + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install tox tox-gh-actions + - name: Run tox + run: tox diff --git a/.gitignore b/.gitignore index bee8a64..3fafd07 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ __pycache__ +*.egg-info diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..b07773d --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,9 @@ +[tool.black] +line-length = 120 + +[build-system] +requires = [ + "setuptools>=42", + "wheel" +] +build-backend = "setuptools.build_meta" diff --git a/pyrightconfig.json b/pyrightconfig.json index 40d4ae3..6b262cd 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -1,3 +1,3 @@ { - "extraPaths": ["python"] + "extraPaths": ["src"] } diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..a3bec93 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,29 @@ +[metadata] +name = micrograd-pp +version = 0.1 +author = Parsiad Azimzadeh +author_email = parsiad.azimzadeh@gmail.com +description = A minimalistic wrapper around NumPy which adds support for automatic differentiation. +long_description = file: README.md +long_description_content_type = text/markdown +url = https://github.com/parsiad/micrograd-pp +project_urls = + Bug Tracker = https://github.com/parsiad/micrograd-pp/issues +classifiers = + Programming Language :: Python :: 3 + License :: OSI Approved :: MIT License + Operating System :: OS Independent + +[options] +install_requires = + tabulate +package_dir = + = src +packages = find: +python_requires = >= 3.6 + +[options.packages.find] +where = src + +[pylint.FORMAT] +max-line-length=120 diff --git a/python/micrograd_pp/__init__.py b/src/micrograd_pp/__init__.py similarity index 100% rename from python/micrograd_pp/__init__.py rename to src/micrograd_pp/__init__.py diff --git a/python/micrograd_pp/_expr.py b/src/micrograd_pp/_expr.py similarity index 97% rename from python/micrograd_pp/_expr.py rename to src/micrograd_pp/_expr.py index 71c9ce4..1519619 100644 --- a/python/micrograd_pp/_expr.py +++ b/src/micrograd_pp/_expr.py @@ -379,11 +379,7 @@ def func() -> npt.NDArray: dim = tuple( [ self.ndim - 1 - i - for i, (m, n) in enumerate( - itertools.zip_longest( - reversed(self._a.shape), reversed(self.shape) - ) - ) + for i, (m, n) in enumerate(itertools.zip_longest(reversed(self._a.shape), reversed(self.shape))) if m is None or m != n ] ) @@ -470,9 +466,7 @@ def __init__(self, a: Expr, pow: int | float) -> None: self._pow = pow def _backward(self, grad: npt.NDArray) -> None: - self._a.update_grad( - lambda: grad * self._pow * self._a._value ** (self._pow - 1) - ) + self._a.update_grad(lambda: grad * self._pow * self._a._value ** (self._pow - 1)) class _ReLU(Expr): diff --git a/python/micrograd_pp/_nn.py b/src/micrograd_pp/_nn.py similarity index 100% rename from python/micrograd_pp/_nn.py rename to src/micrograd_pp/_nn.py diff --git a/python/micrograd_pp/_opt.py b/src/micrograd_pp/_opt.py similarity index 100% rename from python/micrograd_pp/_opt.py rename to src/micrograd_pp/_opt.py diff --git a/python/micrograd_pp/datasets/__init__.py b/src/micrograd_pp/datasets/__init__.py similarity index 100% rename from python/micrograd_pp/datasets/__init__.py rename to src/micrograd_pp/datasets/__init__.py diff --git a/python/micrograd_pp/datasets/_mnist.py b/src/micrograd_pp/datasets/_mnist.py similarity index 100% rename from python/micrograd_pp/datasets/_mnist.py rename to src/micrograd_pp/datasets/_mnist.py diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..96ebe0a --- /dev/null +++ b/tox.ini @@ -0,0 +1,9 @@ +[tox] +envlist = py311 + +[testenv] +deps = + numpy + pytest +commands = + pytest tests/