Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't merge, just for troubleshooting CI #44

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion derivative/differentiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,10 @@ def _restore_axes(dX: NDArray, axis: int, orig_shape: tuple[int, ...]) -> NDArra
return dX.flatten()
else:
# order of operations coupled with _align_axes
extra_dims = tuple(length for ax, length in enumerate(orig_shape) if ax != axis)
orig_diff_axis = range(len(orig_shape))[axis] # to handle negative axis args
extra_dims = tuple(
length for ax, length in enumerate(orig_shape) if ax != orig_diff_axis
)
moved_shape = (orig_shape[axis],) + extra_dims
dX = np.moveaxis(dX.T.reshape((moved_shape)), 0, axis)
return dX
6 changes: 5 additions & 1 deletion derivative/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
else:
from importlib.metadata import entry_points

hyperparam_algorithms = entry_points(group="derivative.hyperparam_opt")
try:
hyperparam_algorithms = entry_points(group="derivative.hyperparam_opt")
except TypeError as exc:
import sys
raise TypeError(f"Oops, no 'group' kwarg. function imported from {entry_points.__module__}")


def _load_hyperparam_func(func_key):
Expand Down
9 changes: 6 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "derivative"
version = "0.6.1"
version = "0.6.2"
description = "Numerical differentiation in python."
repository = "https://github.com/andgoldschmidt/derivative"
documentation = "https://derivative.readthedocs.io/"
Expand All @@ -20,6 +20,9 @@ numpy = "^1.18.3"
scipy = "^1.4.1"
scikit-learn = "^1"

# third-party access to the functionality of importlib.metadata
importlib-metadata = "^7.1.0"

# docs
sphinx = {version = "^5", optional = true}
nbsphinx = {version = "^0.6.1", optional = true}
Expand All @@ -32,12 +35,12 @@ matplotlib = {version = "^3.2.1", optional = true}
pytest = {version = "^7", optional = true}

[tool.poetry.extras]
docs = ["sphinx", "nbsphinx", "ipykernel", "jupyter_client", "matplotlib", "pandoc"]
docs = ["sphinx", "nbsphinx", "ipykernel", "jupyter_client", "matplotlib"]
dev = ["pytest"]

[build-system]
requires = ["poetry-core>=1.1.0"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.plugins.'derivative.hyperparam_opt']
[tool.poetry.plugins."derivative.hyperparam_opt"]
"kalman.default" = "derivative.utils:_default_kalman"
10 changes: 9 additions & 1 deletion tests/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,12 @@ def test_hyperparam_entrypoint():
func = utils._load_hyperparam_func("kalman.default")
expected = 1
result = func(None, None)
assert result == expected
assert result == expected


def test_negative_axis():
t = np.arange(3)
x = np.ones((2, 3, 2))
axis = -2
dx = dxdt(x, t, kind='finite_difference', axis=axis, k=1)
assert x.shape == dx.shape
Loading