Skip to content

Commit

Permalink
Address warnings (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjperkins authored Jan 30, 2024
1 parent af82d12 commit 034b3ce
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 53 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,17 @@ jobs:
with:
fetch-depth: 1

- name: Create a .env file
run: |
touch .env
echo "NUMBA_NRT_STATS=1" >> .env
echo "NUMBA_CAPTURED_ERRORS='new_style'" >> .env
- name: Install base codex-africanus
run: pipenv install .[testing]

- name: Run base test suite
run: pipenv run NUMBA_NRT_STATS=1 py.test -s -vvv africanus/
run: pipenv run py.test -s -vvv africanus/

- name: List the measures directory
run: curl ftp://ftp.astron.nl/outgoing/Measures/ > measures_dir.txt
Expand All @@ -67,19 +73,16 @@ jobs:
echo "measures.directory: ~/measures" > ~/.casarc
- name: Install complete codex-africanus
# Need pyyaml for dask 2.17.0
# See https://github.com/dask/dask/issues/6221
run: >
pipenv install
.[complete]
pyyaml
git+https://gitlab.mpcdf.mpg.de/ift/nifty_gridder.git#egg=nifty-gridder
- name: Log installed package versions
run: pipenv graph

- name: Run complete test suite
run: pipenv run NUMBA_NRT_STATS=1 py.test -s -vvv africanus/
run: pipenv run py.test -s -vvv africanus/

deploy:
needs: [test]
Expand All @@ -94,7 +97,7 @@ jobs:
- name: Set up Python 3.10
uses: actions/[email protected]
with:
python-version: 3.10
python-version: '3.10'

- name: Install latest setuptools, wheel, pip
run: python3 -m pip install -U pip setuptools wheel
Expand Down
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ History

X.Y.Z (YYYY-MM-DD)
------------------
* Address warnings (:pr:`292`)
* Update github action versions (:pr:`291`)
* Deprecate python 3.8 support (:pr:`290`)
* Use pre-commit hooks for auto-linting (:pr:`290`)
Expand Down
8 changes: 4 additions & 4 deletions africanus/averaging/tests/test_time_and_channel_averaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,25 @@ def interval():
@pytest.fixture
def weight(time):
shape = (time.shape[0], ncorr)
return np.arange(np.product(shape), dtype=np.float64).reshape(shape)
return np.arange(np.prod(shape), dtype=np.float64).reshape(shape)


@pytest.fixture
def sigma(time):
shape = (time.shape[0], ncorr)
return np.arange(np.product(shape), dtype=np.float64).reshape(shape)
return np.arange(np.prod(shape), dtype=np.float64).reshape(shape)


@pytest.fixture
def weight_spectrum(time):
shape = (time.shape[0], nchan, ncorr)
return np.arange(np.product(shape), dtype=np.float64).reshape(shape)
return np.arange(np.prod(shape), dtype=np.float64).reshape(shape)


@pytest.fixture
def sigma_spectrum(time):
shape = (time.shape[0], nchan, ncorr)
return np.arange(np.product(shape), dtype=np.float64).reshape(shape)
return np.arange(np.prod(shape), dtype=np.float64).reshape(shape)


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion africanus/experimental/rime/fused/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def rime(*args):
def rime_impl(*args):
raise NotImplementedError

@overload(rime_impl, jit_options=JIT_OPTIONS)
@overload(rime_impl, jit_options=JIT_OPTIONS, prefer_literal=True)
def nb_rime(*args):
if not len(args) > 0:
raise TypeError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def policy(uvw, ra0, dec0, ra, dec, policy_type):
pass


@overload(policy, inline="always")
@overload(policy, inline="always", prefer_literal=True)
def policy_impl(uvw, ra0, dec0, ra, dec, policy_type):
if policy_type.literal_value == "None":
return uvw_norotate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def policy(
pass


@overload(policy, inline="always")
@overload(policy, inline="always", prefer_literal=True)
def policy_impl(
scaled_u,
scaled_v,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def policy(vis, uvw, lambdas, ra0, dec0, ra, dec, policy_type, phasesign=1.0):
pass


@overload(policy, inline="always")
@overload(policy, inline="always", prefer_literal=True)
def policy_impl(vis, uvw, lambdas, ra0, dec0, ra, dec, policy_type, phasesign=1.0):
if policy_type.literal_value == "None" or policy_type.literal_value is None:
return phase_norotate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def stokes2corr(vis_in, vis_out, policy_type):
pass


@overload(stokes2corr, inline="always")
@overload(stokes2corr, inline="always", prefer_literal=True)
def stokes2corrimpl(vis_in, vis_out, policy_type):
if policy_type.literal_value == "XXYY_FROM_I":

Expand Down Expand Up @@ -143,7 +143,7 @@ def corr2stokes(vis_in, policy_type):
pass


@overload(corr2stokes, inline="always")
@overload(corr2stokes, inline="always", prefer_literal=True)
def corr2stokesimpl(vis_in, policy_type):
if policy_type.literal_value == "I_FROM_XXYY":
return lambda vis_in, policy_type: (vis_in[0] + vis_in[1]) * 0.5
Expand Down Expand Up @@ -183,7 +183,7 @@ def ncorr_out(policy_type):
pass


@overload(ncorr_out, inline="always")
@overload(ncorr_out, inline="always", prefer_literal=True)
def ncorr_outimpl(policy_type):
if policy_type.literal_value == "XXYY_FROM_I":
return lambda policy_type: 2
Expand Down
4 changes: 2 additions & 2 deletions africanus/model/coherency/tests/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ def visibility_factory(vis_shape, input_shape, in_type, backend="numpy", **kwarg
shape = vis_shape + input_shape

if backend == "numpy":
vis = np.arange(1.0, np.product(shape) + 1.0)
vis = np.arange(1.0, np.prod(shape) + 1.0)
vis = vis.reshape(shape)
elif backend == "dask":
da = pytest.importorskip("dask.array")
vis = da.arange(1.0, np.product(shape) + 1.0, chunks=np.product(shape))
vis = da.arange(1.0, np.prod(shape) + 1.0, chunks=np.prod(shape))
vis = vis.reshape(shape)
vis = vis.rechunk(kwargs["vis_chunks"] + input_shape)
else:
Expand Down
53 changes: 24 additions & 29 deletions africanus/model/shape/shapelets.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,21 @@ def factorial(n):


@numba.jit(nogil=True, nopython=True, cache=True)
def basis_function(n, xx, beta, fourier=False, delta_x=-1):
if fourier:
x = 2 * np.pi * xx
scale = 1.0 / beta
else:
x = xx
scale = beta
def real_basis_function(n, xx, beta, delta_x=-1):
basis_component = 1.0 / np.sqrt(2.0**n * np.sqrt(np.pi) * factorial(n) * beta)
exponential_component = hermite(n, xx / beta) * np.exp(-(xx**2) / (2.0 * beta**2))
return basis_component * exponential_component


@numba.jit(nogil=True, nopython=True, cache=True)
def complex_basis_function(n, xx, beta, delta_x=-1):
x = 2 * np.pi * xx
scale = 1.0 / beta
basis_component = 1.0 / np.sqrt(2.0**n * np.sqrt(np.pi) * factorial(n) * scale)
exponential_component = hermite(n, x / scale) * np.exp(-(x**2) / (2.0 * scale**2))
if fourier:
return (
1.0j**n
* basis_component
* exponential_component
* np.sqrt(2 * np.pi)
/ delta_x
)
else:
return basis_component * exponential_component
return (
1.0j**n * basis_component * exponential_component * np.sqrt(2 * np.pi) / delta_x
)


@numba.jit(nogil=True, nopython=True, cache=True)
Expand Down Expand Up @@ -96,8 +92,8 @@ def shapelet(coords, frequency, coeffs, beta, delta_lm, dtype=np.complex128):
0
if coeffs[src][n1, n2] == 0
else coeffs[src][n1, n2]
* basis_function(n1, fu, beta_u, True, delta_x=delta_l)
* basis_function(n2, fv, beta_v, True, delta_x=delta_m)
* complex_basis_function(n1, fu, beta_u, delta_x=delta_l)
* complex_basis_function(n2, fv, beta_v, delta_x=delta_m)
)
out_shapelets[row, chan, src] = tmp_shapelet
return out_shapelets
Expand Down Expand Up @@ -145,8 +141,8 @@ def shapelet_with_w_term(
0
if coeffs[src][n1, n2] == 0
else coeffs[src][n1, n2]
* basis_function(n1, fu, beta_u, True, delta_x=delta_l)
* basis_function(n2, fv, beta_v, True, delta_x=delta_m)
* complex_basis_function(n1, fu, beta_u, delta_x=delta_l)
* complex_basis_function(n2, fv, beta_v, delta_x=delta_m)
)
w_term = phase_steer_and_w_correct((u, v, w), (l, m), frequency[chan])
out_shapelets[row, chan, src] = tmp_shapelet * w_term
Expand Down Expand Up @@ -183,17 +179,16 @@ def shapelet_1d(u, coeffs, fourier, delta_x=1, beta=1.0):
if delta_x is None:
raise ValueError("You have to pass in a value for delta_x in Fourier mode")
out = np.zeros(nrow, dtype=np.complex128)
for row, ui in enumerate(u):
for n, c in enumerate(coeffs):
out[row] += c * complex_basis_function(n, ui, beta, delta_x=delta_x)
else:
out = np.zeros(nrow, dtype=np.float64)
for row, ui in enumerate(u):
for n, c in enumerate(coeffs):
out[row] += c * basis_function(
n, ui, beta, fourier=fourier, delta_x=delta_x
)
return out
for row, ui in enumerate(u):
for n, c in enumerate(coeffs):
out[row] += c * real_basis_function(n, ui, beta, delta_x=delta_x)


# @numba.jit(nogil=True, nopython=True, cache=True)
return out


def shapelet_2d(u, v, coeffs_l, fourier, delta_x=None, delta_y=None, beta=1.0):
Expand Down
2 changes: 1 addition & 1 deletion africanus/rime/zernike.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def zernike_dde(
npoly = coeffs.shape[-1]

# Flatten correlation dimensions for numba function
fcorrs = np.product(corr_shape)
fcorrs = np.prod(corr_shape)
ddes = np.empty((sources, times, ants, chans, fcorrs), coeffs.dtype)

coeffs = coeffs.reshape((ants, chans, fcorrs, npoly))
Expand Down
6 changes: 3 additions & 3 deletions africanus/util/nvcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import ast
import contextlib
import importlib.resources
import logging
import os
import re
Expand All @@ -12,7 +13,6 @@
import tempfile

from os.path import join as pjoin
from pkg_resources import resource_filename

import distutils
from distutils import errors
Expand Down Expand Up @@ -486,8 +486,8 @@ def compile_using_nvcc(source, options=None, arch=None, filename="kern.cu"):

options += ["-cubin"]

cupy_path = resource_filename("cupy", pjoin("core", "include"))
settings["include_dirs"].append(cupy_path)
cupy_path = importlib.resources.files("cupy") / "core" / "include"
settings["include_dirs"].append(str(cupy_path))

with _tempdir() as tmpdir:
tmpfile = pjoin(tmpdir, filename)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ exclude = docs
test = pytest

[tool:pytest]
collect_ignore = ['setup.py']
addopts = --ignore=setup.py

[pycodestyle]
ignore = E121,E123,E126,E133,E226,E241,E242,E704,W503,W504,E741

0 comments on commit 034b3ce

Please sign in to comment.