From 88c110a8fe8f7d1a9faf74270704398dafcd6ac7 Mon Sep 17 00:00:00 2001 From: Joost van Zwieten Date: Thu, 21 Nov 2024 10:42:23 +0100 Subject: [PATCH] test GitHub discussion 889 --- .github/workflows/test.yaml | 158 +------------------------------- nutils/types.py | 2 +- tests/test_gh_discussion_889.py | 43 +++++++++ 3 files changed, 46 insertions(+), 157 deletions(-) create mode 100644 tests/test_gh_discussion_889.py diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 937ddc46e..5d489b8f2 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -5,6 +5,7 @@ on: branches: - master - release/* + - test-* defaults: run: shell: bash @@ -109,159 +110,4 @@ jobs: - name: Test env: COVERAGE_ID: ${{ matrix.name }} - run: python -um devtools.gha.unittest - - name: Upload coverage artifact - uses: actions/upload-artifact@v4 - with: - name: _coverage_${{ matrix.name }} - path: target/coverage/ - if-no-files-found: error - process-coverage: - if: ${{ always() }} - needs: test - name: 'Test coverage' - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Download coverage artifacts - uses: actions/download-artifact@v4 - with: - pattern: _coverage_* - path: target/coverage - merge-multiple: true - - name: Generate summary - run: python -um devtools.gha.report_coverage - - name: Upload lcov artifact - uses: actions/upload-artifact@v4 - with: - name: coverage - path: target/coverage/coverage.info - - name: Delete temporary coverage artifacts - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: python -um devtools.gha.delete_coverage_artifacts - test-examples: - needs: build-python-package - name: 'Test examples ${{ matrix.os }}' - runs-on: ${{ matrix.os }}-latest - strategy: - matrix: - os: [ubuntu, macos, windows] - fail-fast: false - env: - _wheel: ${{ needs.build-python-package.outputs.wheel }} - NUTILS_MATRIX: scipy - NUTILS_NPROCS: 1 - NUTILS_DEBUG: all - OMP_NUM_THREADS: 1 - VECLIB_MAXIMUM_THREADS: 1 - PYTHONHASHSEED: 0 - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Move nutils directory - run: mv nutils _nutils - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: "3.12" - - name: Download Python package artifact - uses: actions/download-artifact@v4 - with: - name: python-package - path: dist/ - - name: Install Nutils and dependencies - id: install - run: | - python -um pip install --upgrade --upgrade-strategy eager wheel - # Install Nutils from `dist` dir created in job `build-python-package`. - python -um pip install "$_wheel[matrix_scipy,export_mpl]" - - name: Test - run: python -um unittest discover -b -q -t . -s examples - test-sphinx: - name: Test building docs - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: "3.12" - - name: Install dependencies - run: | - python -um pip install setuptools wheel - python -um pip install --upgrade --upgrade-strategy eager .[docs] - - name: Build docs - run: python -um sphinx -n -W --keep-going docs build/sphinx/html - build-and-test-container-image: - name: Build container image - needs: build-python-package - runs-on: ubuntu-latest - env: - # Fixes https://github.com/actions/virtual-environments/issues/3080 - STORAGE_OPTS: overlay.mount_program=/usr/bin/fuse-overlayfs - _wheel: ${{ needs.build-python-package.outputs.wheel }} - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Download Python package artifact - uses: actions/download-artifact@v4 - with: - name: python-package - path: dist/ - - name: Get base and image tags - id: tags - run: python3 -um devtools.gha.get_base_and_image_tags - - name: Pull container base image - env: - _base: ${{ env.official_container_repository }}:${{ steps.tags.outputs.base }} - run: podman pull "docker://$_base" - - name: Build container image - id: build - env: - _base: ${{ env.official_container_repository }}:${{ steps.tags.outputs.base }} - _name: ${{ env.official_container_repository }}:${{ steps.tags.outputs.image }} - run: python3 -um devtools.container.build --revision "$GITHUB_SHA" --wheel "$_wheel" --examples examples --name "$_name" --base "$_base" - - name: Test examples/laplace.py - env: - _image: ${{ steps.build.outputs.id }} - run: | - mkdir /tmp/log - podman run --pull=never --rm -v /tmp/log:/log:rw "$_image" laplace - if [ ! -e /tmp/log/log.html ]; then - echo ::error ::"log file not generated" - exit 1 - fi - - name: Run unit tests - env: - _image: ${{ steps.build.outputs.id }} - run: podman run --pull=never --rm -v "$PWD/tests:/app/tests:ro" -v "$PWD/examples:/app/examples:ro" --env NUTILS_DEBUG=all "$_image" -m unittest -bq - - name: Push image to container registry - if: ${{ github.event_name == 'push' }} - env: - _username: ${{ secrets.DOCKER_USERNAME }} - _password: ${{ secrets.DOCKER_PASSWORD }} - _repository: ${{ secrets.DOCKER_REPOSITORY }} - _image_id: ${{ steps.build.outputs.id }} - _tag: ${{ steps.tags.outputs.image }} - run: | - # Push the image to the official container repository if this - # workflow is triggered from the official git repository, otherwise - # use the `DOCKER_REPOSITORY` secret. - case "$GITHUB_REPOSITORY" in - evalf/nutils) - _repository="$official_container_repository" - ;; - *) - if [ -z "$_repository" ]; then - echo ::error ::"Github secret DOCKER_REPOSITORY is empty" - exit 1 - fi - ;; - esac - # Login without exposing the password via the command line as recommended by GitHub - # (https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets#using-encrypted-secrets-in-a-workflow). - printenv _password | podman login --username "$_username" --password-stdin "${_repository%%/*}" - podman push "$_image_id" "docker://$_repository:$_tag" + run: python -um unittest -v tests.test_gh_discussion_889 diff --git a/nutils/types.py b/nutils/types.py index f69fb8d43..9ba09006a 100644 --- a/nutils/types.py +++ b/nutils/types.py @@ -389,7 +389,7 @@ def __new__(cls, arg): return arg array = numpy.asarray(arg) dtype = dict(b=bool, u=int, i=int, f=float, c=complex)[array.dtype.kind] - return super().__new__(cls, dtype, array.shape, array.astype(dtype, copy=False).tobytes()) + return super().__new__(cls, dtype, array.shape, array.astype(dtype, copy=False, casting='safe').tobytes()) def reshape(self, *shape): if numpy.prod(shape) != numpy.prod(self.shape): diff --git a/tests/test_gh_discussion_889.py b/tests/test_gh_discussion_889.py new file mode 100644 index 000000000..5e1d50daa --- /dev/null +++ b/tests/test_gh_discussion_889.py @@ -0,0 +1,43 @@ +import numpy +from nutils import function, mesh +from nutils.testing import TestCase + +class gh_discussion_889(TestCase): + + def test_mul_f64(self): + + domain, geom = mesh.rectilinear([numpy.linspace(0, 1, 2), numpy.linspace(0, 1, 2)]) + + x,y = geom + x = (x*1.02)-0.51 + y = (y*1.02)-0.51 + + domain.trim(-x/2 + y*2.7755575615628914e-17, maxrefine=4) + + def test_div_large_int(self): + + domain, geom = mesh.rectilinear([numpy.linspace(0, 1, 2), numpy.linspace(0, 1, 2)]) + + x,y = geom + x = (x*1.02)-0.51 + y = (y*1.02)-0.51 + + domain.trim(-x/2 + y/36028797018963968, maxrefine=4) + + def test_numpy_array_large_number(self): + numpy.array(36028797018963968, dtype=int) + + def test_array_cast_large_number(self): + function.Array.cast(36028797018963968) + + def test_evaluable(self): + + domain, geom = mesh.rectilinear([numpy.linspace(0, 1, 2), numpy.linspace(0, 1, 2)]) + + x,y = geom + x = (x*1.02)-0.51 + y = (y*1.02)-0.51 + + f = y / 36028797018963968 + + print(domain.sample('gauss', 0)(f).as_evaluable_array.asciitree())