Skip to content

Commit

Permalink
Merge pull request #136 from abacusorg/ruff-format
Browse files Browse the repository at this point in the history
Apply ruff format
  • Loading branch information
lgarrison authored May 9, 2024
2 parents 94283f3 + 9b43bec commit 89049f9
Show file tree
Hide file tree
Showing 49 changed files with 6,257 additions and 3,055 deletions.
14 changes: 5 additions & 9 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: Tests

on:
push:
branches:
- main
pull_request:
schedule:
# Run weekly, Friday at 7:15 EST.
Expand Down Expand Up @@ -64,7 +66,7 @@ jobs:
}}
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v4
Expand All @@ -76,17 +78,11 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install -U pip
pip install numpy
pip install 'setuptools' 'wheel' 'numpy>=1.19.0' 'Cython>=0.29.21,<3' # for classy
pip install --no-build-isolation classy
- name: Install package from source
if: ${{ env.PUBLISH != 'true' }}
run: |
pip install -U .[test]
pip install -U pip
pip install -vU .[test]
make -C pipe_asdf
- name: Fetch wheel
Expand Down
4 changes: 1 addition & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ repos:
rev: "v0.4.3"
hooks:
- id: ruff
# TODO: turning off line length check
# When ruff formatting is available, use that to auto-fix
args: [--fix, --exit-non-zero-on-fix, --ignore=E501]
args: [--fix]
- id: ruff-format
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
Expand Down
97 changes: 49 additions & 48 deletions abacusnbody/analysis/cic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import numba
from numba import njit


@numba.vectorize
def rightwrap(x, L):
if x >= L:
Expand All @@ -18,18 +19,18 @@ def cic_serial(positions, density, boxsize, weights=None):
gy = np.uint32(density.shape[1])
gz = np.uint32(density.shape[2])
threeD = gz != 1
W = 1.
W = 1.0
have_W = weights is not None

for n in range(len(positions)):
if have_W:
W = weights[n]

# convert to a position in the grid
px = (positions[n,0]/boxsize)*gx # used to say boxsize+0.5
py = (positions[n,1]/boxsize)*gy # used to say boxsize+0.5
px = (positions[n, 0] / boxsize) * gx # used to say boxsize+0.5
py = (positions[n, 1] / boxsize) * gy # used to say boxsize+0.5
if threeD:
pz = (positions[n,2]/boxsize)*gz # used to say boxsize+0.5
pz = (positions[n, 2] / boxsize) * gz # used to say boxsize+0.5

# round to nearest cell center
ix = np.int32(round(px))
Expand All @@ -44,81 +45,81 @@ def cic_serial(positions, density, boxsize, weights=None):
dz = iz - pz

# find the tsc weights for each dimension
wx = 1. - np.abs(dx)
if dx > 0.: # on the right of the center ( < )
wx = 1.0 - np.abs(dx)
if dx > 0.0: # on the right of the center ( < )
wxm1 = dx
wxp1 = 0.
else: # on the left of the center
wxp1 = 0.0
else: # on the left of the center
wxp1 = -dx
wxm1 = 0.
wy = 1. - np.abs(dy)
if dy > 0.:
wxm1 = 0.0
wy = 1.0 - np.abs(dy)
if dy > 0.0:
wym1 = dy
wyp1 = 0.
wyp1 = 0.0
else:
wyp1 = -dy
wym1 = 0.
wym1 = 0.0
if threeD:
wz = 1. - np.abs(dz)
if dz > 0.:
wz = 1.0 - np.abs(dz)
if dz > 0.0:
wzm1 = dz
wzp1 = 0.
wzp1 = 0.0
else:
wzp1 = -dz
wzm1 = 0.
wzm1 = 0.0
else:
wz = 1.
wz = 1.0

# find the wrapped x,y,z grid locations of the points we need to change
# negative indices will be automatically wrapped
ixm1 = rightwrap(ix - 1, gx)
ixw = rightwrap(ix , gx)
ixw = rightwrap(ix, gx)
ixp1 = rightwrap(ix + 1, gx)
iym1 = rightwrap(iy - 1, gy)
iyw = rightwrap(iy , gy)
iyw = rightwrap(iy, gy)
iyp1 = rightwrap(iy + 1, gy)
if threeD:
izm1 = rightwrap(iz - 1, gz)
izw = rightwrap(iz , gz)
izw = rightwrap(iz, gz)
izp1 = rightwrap(iz + 1, gz)
else:
izw = np.uint32(0)

# change the 9 or 27 cells that the cloud touches
density[ixm1, iym1, izw ] += wxm1*wym1*wz *W
density[ixm1, iyw , izw ] += wxm1*wy *wz *W
density[ixm1, iyp1, izw ] += wxm1*wyp1*wz *W
density[ixw , iym1, izw ] += wx *wym1*wz *W
density[ixw , iyw , izw ] += wx *wy *wz *W
density[ixw , iyp1, izw ] += wx *wyp1*wz *W
density[ixp1, iym1, izw ] += wxp1*wym1*wz *W
density[ixp1, iyw , izw ] += wxp1*wy *wz *W
density[ixp1, iyp1, izw ] += wxp1*wyp1*wz *W
density[ixm1, iym1, izw] += wxm1 * wym1 * wz * W
density[ixm1, iyw, izw] += wxm1 * wy * wz * W
density[ixm1, iyp1, izw] += wxm1 * wyp1 * wz * W
density[ixw, iym1, izw] += wx * wym1 * wz * W
density[ixw, iyw, izw] += wx * wy * wz * W
density[ixw, iyp1, izw] += wx * wyp1 * wz * W
density[ixp1, iym1, izw] += wxp1 * wym1 * wz * W
density[ixp1, iyw, izw] += wxp1 * wy * wz * W
density[ixp1, iyp1, izw] += wxp1 * wyp1 * wz * W

if threeD:
density[ixm1, iym1, izm1] += wxm1*wym1*wzm1*W
density[ixm1, iym1, izp1] += wxm1*wym1*wzp1*W
density[ixm1, iym1, izm1] += wxm1 * wym1 * wzm1 * W
density[ixm1, iym1, izp1] += wxm1 * wym1 * wzp1 * W

density[ixm1, iyw , izm1] += wxm1*wy *wzm1*W
density[ixm1, iyw , izp1] += wxm1*wy *wzp1*W
density[ixm1, iyw, izm1] += wxm1 * wy * wzm1 * W
density[ixm1, iyw, izp1] += wxm1 * wy * wzp1 * W

density[ixm1, iyp1, izm1] += wxm1*wyp1*wzm1*W
density[ixm1, iyp1, izp1] += wxm1*wyp1*wzp1*W
density[ixm1, iyp1, izm1] += wxm1 * wyp1 * wzm1 * W
density[ixm1, iyp1, izp1] += wxm1 * wyp1 * wzp1 * W

density[ixw , iym1, izm1] += wx *wym1*wzm1*W
density[ixw , iym1, izp1] += wx *wym1*wzp1*W
density[ixw, iym1, izm1] += wx * wym1 * wzm1 * W
density[ixw, iym1, izp1] += wx * wym1 * wzp1 * W

density[ixw , iyw , izm1] += wx *wy *wzm1*W
density[ixw , iyw , izp1] += wx *wy *wzp1*W
density[ixw, iyw, izm1] += wx * wy * wzm1 * W
density[ixw, iyw, izp1] += wx * wy * wzp1 * W

density[ixw , iyp1, izm1] += wx *wyp1*wzm1*W
density[ixw , iyp1, izp1] += wx *wyp1*wzp1*W
density[ixw, iyp1, izm1] += wx * wyp1 * wzm1 * W
density[ixw, iyp1, izp1] += wx * wyp1 * wzp1 * W

density[ixp1, iym1, izm1] += wxp1*wym1*wzm1*W
density[ixp1, iym1, izp1] += wxp1*wym1*wzp1*W
density[ixp1, iym1, izm1] += wxp1 * wym1 * wzm1 * W
density[ixp1, iym1, izp1] += wxp1 * wym1 * wzp1 * W

density[ixp1, iyw , izm1] += wxp1*wy *wzm1*W
density[ixp1, iyw , izp1] += wxp1*wy *wzp1*W
density[ixp1, iyw, izm1] += wxp1 * wy * wzm1 * W
density[ixp1, iyw, izp1] += wxp1 * wy * wzp1 * W

density[ixp1, iyp1, izm1] += wxp1*wyp1*wzm1*W
density[ixp1, iyp1, izp1] += wxp1*wyp1*wzp1*W
density[ixp1, iyp1, izm1] += wxp1 * wyp1 * wzm1 * W
density[ixp1, iyp1, izp1] += wxp1 * wyp1 * wzp1 * W
Loading

0 comments on commit 89049f9

Please sign in to comment.