Skip to content

Commit

Permalink
Merge branch 'master' into python3.13
Browse files Browse the repository at this point in the history
  • Loading branch information
fjosw committed Aug 19, 2024
2 parents 210f77d + 84c42fb commit f684894
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 70 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ jobs:
#- ruff
- package
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5.1.1
with:
python-version: '3.10'
- name: Install build tools
run: |
python -m pip install tox wheel
- name: Run ${{ matrix.env }}
run: tox -e ${{ matrix.env }}
run: python -m tox -e ${{ matrix.env }}
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5.1.1
with:
python-version: '3.10'
- name: Install build tools
Expand Down
17 changes: 8 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,28 @@ jobs:
- macos-latest
- windows-latest
python-version:
- '3.7'
- '3.8'
- '3.9'
- '3.10'
- '3.11'
- pypy-3.7
- pypy-3.8
- '3.12'
- pypy-3.9
- pypy-3.10
# TODO: bring this back later
exclude:
- { platform: windows-latest, python-version: pypy-3.7 }
- platform: windows-latest
python-version: 'pypy-3.10'
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5.1.1
with:
python-version: ${{ matrix.python-version }}
- name: Install Python build tools
run: python -m pip install tox wheel
- name: Run tests
run: tox run -e py
run: python -m tox run -e py
- name: Install Scipy prerequisites for Ubuntu
if: startsWith(matrix.platform, 'ubuntu')
run: sudo apt-get install libopenblas-dev
- name: Run tests with scipy
if: startsWith(matrix.platform, 'ubuntu') || startsWith(matrix.python-version, 'pypy') != true
run: tox run -e py-scipy
run: python -m tox run -e py-scipy
2 changes: 0 additions & 2 deletions MANIFEST.in

This file was deleted.

10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
__Note: Autograd is still being maintained but is no longer actively developed.
The main developers (Dougal Maclaurin, David Duvenaud, Matt Johnson, and Jamie
Townsend) are now working on [JAX](https://github.com/google/jax), with Dougal and Matt
working on it full-time. JAX combines a new version of Autograd with extra
features such as jit compilation.__
__Note (updated May 2024): Autograd is not currently maintained, and the
authors do not plan to respond to future issues or pull requests. Those looking
for a similar user experience (with powerful additional features) can consider
using [JAX](https://github.com/google/jax), a successor to Autograd designed by
the same authors.__

# Autograd [![Checks status][checks-badge]][checks-url] [![Tests status][tests-badge]][tests-url] [![Publish status][publish-badge]][publish-url] [![asv][asv-badge]](#)

Expand Down
12 changes: 6 additions & 6 deletions autograd/builtins.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from six import with_metaclass
from .util import subvals
from .extend import (Box, primitive, notrace_primitive, VSpace, vspace,
SparseObject, defvjp, defvjp_argnum, defjvp, defjvp_argnum)
Expand Down Expand Up @@ -86,24 +85,25 @@ def fwd_grad_make_sequence(argnum, g, ans, seq_type, *args, **kwargs):
defjvp_argnum(make_sequence, fwd_grad_make_sequence)


class TupleMeta(type_):
class TupleMeta(type(tuple_)):
def __instancecheck__(self, instance):
return isinstance(instance, tuple_)
class tuple(with_metaclass(TupleMeta, tuple_)):

class tuple(tuple_, metaclass=TupleMeta):
def __new__(cls, xs):
return make_sequence(tuple_, *xs)

class ListMeta(type_):
def __instancecheck__(self, instance):
return isinstance(instance, list_)
class list(with_metaclass(ListMeta, list_)):
class list(list_, metaclass=ListMeta):
def __new__(cls, xs):
return make_sequence(list_, *xs)
return make_sequence(list_, *xs)

class DictMeta(type_):
def __instancecheck__(self, instance):
return isinstance(instance, dict_)
class dict(with_metaclass(DictMeta, dict_)):
class dict(dict_, metaclass=DictMeta):
def __new__(cls, *args, **kwargs):
result = dict_(*args, **kwargs)
if result:
Expand Down
8 changes: 7 additions & 1 deletion autograd/numpy/numpy_boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ def __hash__(self): return id(self)
# Flatten has no function, only a method.
setattr(ArrayBox, 'flatten', anp.__dict__['ravel'])

if np.__version__ >= '1.25':
if np.lib.NumpyVersion(np.__version__) >= '2.0.0':
SequenceBox.register(np.linalg._linalg.EigResult)
SequenceBox.register(np.linalg._linalg.EighResult)
SequenceBox.register(np.linalg._linalg.QRResult)
SequenceBox.register(np.linalg._linalg.SlogdetResult)
SequenceBox.register(np.linalg._linalg.SVDResult)
elif np.__version__ >= '1.25':
SequenceBox.register(np.linalg.linalg.EigResult)
SequenceBox.register(np.linalg.linalg.EighResult)
SequenceBox.register(np.linalg.linalg.QRResult)
Expand Down
4 changes: 3 additions & 1 deletion autograd/numpy/numpy_jvps.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import numpy as onp
from . import numpy_wrapper as anp
from .numpy_vjps import (untake, balanced_eq, match_complex, replace_zero,
dot_adjoint_0, dot_adjoint_1, tensordot_adjoint_0,
Expand Down Expand Up @@ -210,7 +211,8 @@ def fwd_grad_sort(g, ans, x, axis=-1, kind='quicksort', order=None):
sort_perm = anp.argsort(x, axis, kind, order)
return g[sort_perm]
defjvp(anp.sort, fwd_grad_sort)
defjvp(anp.msort, lambda g, ans, x: fwd_grad_sort(g, ans, x, axis=0))
if onp.lib.NumpyVersion(onp.__version__) < '2.0.0':
defjvp(anp.msort, lambda g, ans, x: fwd_grad_sort(g, ans, x, axis=0))

def fwd_grad_partition(g, ans, x, kth, axis=-1, kind='introselect', order=None):
partition_perm = anp.argpartition(x, kth, axis, kind, order)
Expand Down
6 changes: 3 additions & 3 deletions autograd/numpy/numpy_vjps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from __future__ import absolute_import
from six import string_types
from functools import partial
import numpy as onp
from ..util import func
Expand Down Expand Up @@ -560,7 +559,8 @@ def grad_sort(ans, x, axis=-1, kind='quicksort', order=None):
sort_perm = anp.argsort(x, axis, kind, order)
return lambda g: unpermuter(g, sort_perm)
defvjp(anp.sort, grad_sort)
defvjp(anp.msort, grad_sort) # Until multi-D is allowed, these are the same.
if onp.lib.NumpyVersion(onp.__version__) < '2.0.0':
defvjp(anp.msort, grad_sort) # Until multi-D is allowed, these are the same.

def grad_partition(ans, x, kth, axis=-1, kind='introselect', order=None):
#TODO: Cast input with np.asanyarray()
Expand Down Expand Up @@ -588,7 +588,7 @@ def grad_einsum(argnum, ans, operands_, kwargs):
result_meta = anp.metadata(operands_[argnum])
def vjp(g):
operands = operands_
if isinstance(operands[0], string_types): # using "ijk" convention.
if isinstance(operands[0], str): # using "ijk" convention.
in_subs, out_subs, _ = anp.parse_einsum_input(*operands)
string, operands = operands[0], operands[1:]

Expand Down
16 changes: 14 additions & 2 deletions autograd/numpy/numpy_vspaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class ArrayVSpace(VSpace):
def __init__(self, value):
value = np.array(value, copy=False)
value = np.asarray(value)
self.shape = value.shape
self.dtype = value.dtype

Expand Down Expand Up @@ -66,7 +66,19 @@ def _covector(self, x):
ComplexArrayVSpace.register(type_)


if np.__version__ >= '1.25':
if np.lib.NumpyVersion(np.__version__) >= '2.0.0':
class EigResultVSpace(NamedTupleVSpace): seq_type = np.linalg._linalg.EigResult
class EighResultVSpace(NamedTupleVSpace): seq_type = np.linalg._linalg.EighResult
class QRResultVSpace(NamedTupleVSpace): seq_type = np.linalg._linalg.QRResult
class SlogdetResultVSpace(NamedTupleVSpace): seq_type = np.linalg._linalg.SlogdetResult
class SVDResultVSpace(NamedTupleVSpace): seq_type = np.linalg._linalg.SVDResult

EigResultVSpace.register(np.linalg._linalg.EigResult)
EighResultVSpace.register(np.linalg._linalg.EighResult)
QRResultVSpace.register(np.linalg._linalg.QRResult)
SlogdetResultVSpace.register(np.linalg._linalg.SlogdetResult)
SVDResultVSpace.register(np.linalg._linalg.SVDResult)
elif np.__version__ >= '1.25':
class EigResultVSpace(NamedTupleVSpace): seq_type = np.linalg.linalg.EigResult
class EighResultVSpace(NamedTupleVSpace): seq_type = np.linalg.linalg.EighResult
class QRResultVSpace(NamedTupleVSpace): seq_type = np.linalg.linalg.QRResult
Expand Down
6 changes: 3 additions & 3 deletions autograd/scipy/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from autograd.extend import primitive, defvjp

from numpy.lib.stride_tricks import as_strided
from six import iteritems


@primitive
def convolve(A, B, axes=None, dot_axes=[(),()], mode='full'):
Expand Down Expand Up @@ -79,8 +79,8 @@ def parse_axes(A_shape, B_shape, conv_axes, dot_axes, mode):
'conv' : tuple(range(i2, i3))}
conv_shape = (compute_conv_size(A_shape[i], B_shape[j], mode)
for i, j in zip(axes['A']['conv'], axes['B']['conv']))
shapes = {'A' : {s : (A_shape[i] for i in ax) for s, ax in iteritems(axes['A'])},
'B' : {s : (B_shape[i] for i in ax) for s, ax in iteritems(axes['B'])}}
shapes = {'A': {s: tuple(A_shape[i] for i in ax) for s, ax in axes['A'].items()},
'B': {s: tuple(B_shape[i] for i in ax) for s, ax in axes['B'].items()}}
shapes['out'] = {'ignore_A' : shapes['A']['ignore'],
'ignore_B' : shapes['B']['ignore'],
'conv' : conv_shape}
Expand Down
5 changes: 3 additions & 2 deletions conda_recipe/conda.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ source:
requirements:
build:
- python
- setuptools
- hatch
- hatchling
- future
- numpy >=1.9

Expand All @@ -24,7 +25,7 @@ requirements:
- numpy >=1.9

build:
script: python setup.py build && python setup.py install
script: pip install . --no-deps

test:
# Python imports
Expand Down
3 changes: 0 additions & 3 deletions examples/data_mnist.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from __future__ import absolute_import
from __future__ import print_function
import sys
if sys.version < "3":
from future.standard_library import install_aliases
install_aliases()

import os
import gzip
Expand Down
38 changes: 15 additions & 23 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[build-system]
requires = ["setuptools>=44"]
build-backend = "setuptools.build_meta"
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "autograd"
version = "1.6.3"
description = "Efficiently computes derivatives of numpy code."
requires-python = ">=3.8"
description = "Efficiently computes derivatives of NumPy code."
readme = "README.md"
license = {file = "license.txt"}
authors = [
Expand All @@ -16,22 +17,20 @@ authors = [
]
maintainers = [
{name = "Jamie Townsend", email = "j.h.n.townsend@uva.nl"},
{name = "Fabian Joswig", email = "fabian.joswig@uni-muenster.de"},
{name = "Agriya Khetarpal", email = "agriyakhetarpal@outlook.com"},
]
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Information Technology",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Scientific/Engineering",
]
keywords = [
"Automatic differentiation",
Expand All @@ -41,14 +40,16 @@ keywords = [
"optimization",
"neural networks",
"Python",
"Numpy",
"Scipy",
"NumPy",
"SciPy",
]
dependencies = [
"numpy>=1.12",
"six",
"future>=0.15.2; python_version < '3'",
"numpy",
]
# dynamic = ["version"]

[project.urls]
Source = "https://github.com/HIPS/autograd"

[project.optional-dependencies]
scipy = [
Expand All @@ -69,12 +70,3 @@ extend-exclude = []
extend-ignore = ["E731"]
extend-select = ["I", "W"]
line-length = 109

[tool.setuptools]
packages=[
"autograd",
"autograd.numpy",
"autograd.scipy",
"autograd.scipy.stats",
"autograd.misc",
]
6 changes: 5 additions & 1 deletion tests/test_linalg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import absolute_import
from builtins import range
import itertools
import numpy as onp
import autograd.numpy as np
import autograd.numpy.random as npr
from autograd.test_util import check_grads
Expand Down Expand Up @@ -94,7 +95,10 @@ def test_solve_arg1_3d():
D = 4
A = npr.randn(D+1, D, D) + 5*np.eye(D)
B = npr.randn(D+1, D)
fun = lambda A: np.linalg.solve(A, B)
if onp.lib.NumpyVersion(onp.__version__) < '2.0.0':
fun = lambda A: np.linalg.solve(A, B)
else:
fun = lambda A: np.linalg.solve(A, B[..., None])[..., 0]
check_grads(fun)(A)

def test_solve_arg1_3d_3d():
Expand Down
6 changes: 4 additions & 2 deletions tests/test_systematic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import absolute_import
import numpy as onp
import autograd.numpy.random as npr
import autograd.numpy as np
import operator as op
Expand Down Expand Up @@ -43,7 +44,7 @@ def test_log1p(): unary_ufunc_check(np.log1p, lims=[0.2, 2.0])
def test_log2(): unary_ufunc_check(np.log2, lims=[0.2, 2.0])
def test_rad2deg(): unary_ufunc_check(lambda x : np.rad2deg(x)/50.0, test_complex=False)
def test_radians(): unary_ufunc_check(np.radians, test_complex=False)
def test_sign(): unary_ufunc_check(np.sign)
def test_sign(): unary_ufunc_check(np.sign, test_complex=False)
def test_sin(): unary_ufunc_check(np.sin)
def test_sinh(): unary_ufunc_check(np.sinh)
def test_sqrt(): unary_ufunc_check(np.sqrt, lims=[1.0, 3.0])
Expand Down Expand Up @@ -155,7 +156,8 @@ def test_fmin(): combo_check(np.fmin, [0, 1])(
[R(1), R(1,4), R(3, 4)])

def test_sort(): combo_check(np.sort, [0])([R(1), R(7)])
def test_msort(): combo_check(np.msort, [0])([R(1), R(7)])
if onp.lib.NumpyVersion(onp.__version__) < '2.0.0':
def test_msort(): combo_check(np.msort, [0])([R(1), R(7)])
def test_partition(): combo_check(np.partition, [0])(
[R(7), R(14)], kth=[0, 3, 6])

Expand Down
6 changes: 4 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Tox (https://tox.wiki/) - run tests in isolation using virtualenv.
# Also contains config settings for tools that don't look into pyproject.toml.

# TODO: Migrate to tool.hatch.run or noxfile.py

[tox]
envlist =
ruff
Expand Down Expand Up @@ -33,10 +35,10 @@ deps = pyclean
commands = pyclean {posargs:. --debris --erase junit-report.xml --yes}

[testenv:ruff]
description = Lightening-fast linting for Python
description = Lightning-fast linting for Python
skip_install = true
deps = ruff
commands = ruff {posargs:.}
commands = ruff check {posargs:.} # TODO: Fix style failures

[testenv:package]
description = Build package and check metadata (or upload package)
Expand Down

0 comments on commit f684894

Please sign in to comment.