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

pre-commit.ci: update pre-commit hooks #467

Merged
merged 2 commits into from
Jan 7, 2025
Merged
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
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ repos:
args:
- --strict
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.1
rev: v0.8.6
hooks:
- id: ruff
- id: ruff-format
Expand All @@ -48,7 +48,7 @@ repos:
hooks:
- id: toml-sort-fix
- repo: https://github.com/rbubley/mirrors-prettier
rev: v3.4.1
rev: v3.4.2
hooks:
- id: prettier
- repo: https://github.com/igorshubovych/markdownlint-cli
Expand All @@ -62,11 +62,11 @@ repos:
hooks:
- id: forbid-tabs
- repo: https://github.com/rhysd/actionlint
rev: v1.7.4
rev: v1.7.6
hooks:
- id: actionlint
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.13.0
rev: v1.14.1
hooks:
- id: mypy
files: ^glass/
Expand Down
2 changes: 1 addition & 1 deletion glass/core/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def trapezoid_product(
y = np.interp(x, *f)
for f_ in ff:
y *= np.interp(x, *f_)
return np.trapezoid(y, x, axis=axis) # type: ignore[no-any-return]
return np.atleast_1d(np.trapezoid(y, x, axis=axis))


def cumulative_trapezoid(
Expand Down
6 changes: 3 additions & 3 deletions glass/points.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def effective_bias(

"""
norm = np.trapezoid(w.wa, w.za)
return trapezoid_product((z, bz), (w.za, w.wa)) / norm
return (trapezoid_product((z, bz), (w.za, w.wa)) / norm).astype(np.float64)


def linear_bias(
Expand All @@ -107,7 +107,7 @@ def linear_bias(
The density contrast after biasing.

"""
return b * delta
return (b * delta).astype(np.float64)


def loglinear_bias(
Expand Down Expand Up @@ -413,6 +413,6 @@ def position_weights(
densities = densities / np.sum(densities, axis=0)
# apply bias after normalisation
if bias is not None:
densities = densities * bias
densities = (densities * bias).astype(np.float64)
# densities now contains the relative contribution with bias applied
return densities
17 changes: 9 additions & 8 deletions glass/shells.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ def tophat_windows(
ws = []
for zmin, zmax in itertools.pairwise(zbins):
n = max(round((zmax - zmin) / dz), 2)
z = np.linspace(zmin, zmax, n)
w = wht(z)
z = np.linspace(zmin, zmax, n, dtype=np.float64)
w = np.asarray(wht(z), dtype=np.float64)
zeff = np.trapezoid(w * z, z) / np.trapezoid(w, z)
ws.append(RadialWindow(z, w, zeff))
return ws
Expand Down Expand Up @@ -410,7 +410,7 @@ def restrict(
z_ = np.compress(np.greater(z, w.za[0]) & np.less(z, w.za[-1]), z)
zr = np.union1d(w.za, z_)
fr = ndinterp(zr, z, f, left=0.0, right=0.0) * ndinterp(zr, w.za, w.wa)
return zr, fr
return zr.astype(np.float64), fr.astype(np.float64)


def partition(
Expand Down Expand Up @@ -565,7 +565,7 @@ def partition_lstsq(
# compute the union of all given redshift grids
zp = z
for w in shells:
zp = np.union1d(zp, w.za)
zp = np.union1d(zp, w.za).astype(np.float64)

# get extra leading axes of fz
*dims, _ = np.shape(fz)
Expand Down Expand Up @@ -629,7 +629,7 @@ def partition_nnls(
# compute the union of all given redshift grids
zp = z
for w in shells:
zp = np.union1d(zp, w.za)
zp = np.union1d(zp, w.za).astype(np.float64)

# get extra leading axes of fz
*dims, _ = np.shape(fz)
Expand Down Expand Up @@ -673,7 +673,8 @@ def partition_nnls(
# for each dim, find non-negative weights x such that y == r @ x
x = np.empty([len(shells), *dims])
for i in np.ndindex(*dims):
x[(..., *i)] = nnls(r, y[i])
index = (slice(None),) + i # noqa: RUF005
x[index] = nnls(r, y[i])

# all done
return x
Expand Down Expand Up @@ -740,9 +741,9 @@ def _uniform_grid(

"""
if step is not None and num is None:
return np.arange(start, np.nextafter(stop + step, stop), step)
return np.arange(start, np.nextafter(stop + step, stop), step, dtype=np.float64)
if step is None and num is not None:
return np.linspace(start, stop, num + 1)
return np.linspace(start, stop, num + 1, dtype=np.float64)
msg = "exactly one of grid step size or number of steps must be given"
raise ValueError(msg)

Expand Down
Loading