Skip to content

Commit

Permalink
Add Python 3.10 test and replace generator_jit with overload
Browse files Browse the repository at this point in the history
  • Loading branch information
bennahugo committed Mar 26, 2024
1 parent 8e609b9 commit f31661f
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8"]
python-version: ["3.8", "3.9", "3.10"]

steps:
- name: Set up Python ${{ matrix.python-version }}
Expand Down
11 changes: 11 additions & 0 deletions Jenkinsfile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ TEST_DATA_DIR="$WORKSPACE/../../../test-data"
# build
docker build -f ${WORKSPACE_ROOT}/projects/tricolour/docker/python36.docker -t tricolour.1804.py36:${BUILD_NUMBER} ${WORKSPACE_ROOT}/projects/tricolour/
docker build -f ${WORKSPACE_ROOT}/projects/tricolour/docker/python38.docker -t tricolour.2004.py38:${BUILD_NUMBER} ${WORKSPACE_ROOT}/projects/tricolour/
docker build -f ${WORKSPACE_ROOT}/projects/tricolour/docker/python310.docker -t tricolour.2204.py310:${BUILD_NUMBER} ${WORKSPACE_ROOT}/projects/tricolour/

#run tests
tar xvf $TEST_DATA_DIR/acceptance_test_data.tar.gz -C $TEST_OUTPUT_DIR
Expand All @@ -38,4 +39,14 @@ docker run \
--workdir /code \
--entrypoint /bin/sh \
tricolour.2004.py38:${BUILD_NUMBER} \
-c "python3 -m pytest --flake8 -s -vvv ."

# test 3.10
docker run \
--rm \
-v $TEST_OUTPUT_DIR:/testdata \
--env TRICOLOUR_TEST_MS=/testdata/$TEST_MS_REL \
--workdir /code \
--entrypoint /bin/sh \
tricolour.2204.py310:${BUILD_NUMBER} \
-c "python3 -m pytest --flake8 -s -vvv ."
22 changes: 22 additions & 0 deletions docker/python310.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM ubuntu:22.04

ENV DEBIAN_FRONTEND noninteractive
ENV DEBIAN_PRIORITY critical

# Install base requirements
RUN apt update && apt install -y python3-pip \
build-essential \
cmake \
casacore-dev \
python3-numpy \
python3-setuptools \
libboost-python-dev \
libcfitsio-dev \
wcslib-dev

RUN pip3 install --upgrade pip setuptools
ADD . /code
WORKDIR /code

# Install base + testing packages
RUN pip3 install .[testing]
4 changes: 1 addition & 3 deletions docker/python36.docker
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@ ADD . /code
WORKDIR /code

# Install base + testing packages
RUN pip3 install .[testing]

RUN python3 -m pytest --flake8 -s -vvv .
RUN pip3 install .[testing]
4 changes: 1 addition & 3 deletions docker/python38.docker
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@ ADD . /code
WORKDIR /code

# Install base + testing packages
RUN pip3 install .[testing]

RUN python3 -m pytest --flake8 -s -vvv .
RUN pip3 install .[testing]
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
requirements = [
'dask[array] >= 2021.2.0, <=2024.3.1',
'donfig >= 0.4.0, <0.8.2',
'numpy >= 1.14.0, <= 1.22.0', # breakage in newer numpy + numerical errors
'numpy >= 1.14.0, <= 1.22.0',
'numba >= 0.43.0, <= 0.59.1',
'scipy >= 1.2.0, <=1.12.0',
'threadpoolctl >= 1.0.0, <=3.4.0',
Expand All @@ -21,7 +21,7 @@

extras_require = {'testing': ['pytest',
'pytest-flake8',
'flake8 >= 4.0.0, <5.0.0',
"flake8 >= 4.0.0, <5.0.0",
'requests', 'gdown']}

setup(
Expand Down
16 changes: 14 additions & 2 deletions tricolour/flagging.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
""" # noqa


@numba.njit(nogil=True, cache=True)
@numba.jit(nopython=True, nogil=True, cache=True)
def flag_nans_and_zeros(vis_windows, flag_windows):
"""
Flag nan and zero visibilities.
Expand Down Expand Up @@ -190,8 +190,20 @@ def _as_min_dtype(value):
return np.array(value, dtype)


@numba.generated_jit(nopython=True, nogil=True, cache=True)
@numba.jit(nopython=True, nogil=True, cache=True)
def _asbool(data):
return _asbool_impl(data)


def _asbool_impl(data):
if data.dtype.itemsize == 1:
return data.view(np.bool_)
else:
return data.astype(np.bool_)


@numba.extending.overload(_asbool_impl, nopython=True, nogil=True, cache=True)
def _asbool_impl_jit(data):
"""Create a boolean array with the same values as `data`.
The `data` contain only 0's and 1's. If possible, a view is returned,
Expand Down

0 comments on commit f31661f

Please sign in to comment.