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

RuntimeWarning: invalid value encountered in intersection on M1 Mac #2045

Open
emlys opened this issue May 1, 2024 · 5 comments
Open

RuntimeWarning: invalid value encountered in intersection on M1 Mac #2045

emlys opened this issue May 1, 2024 · 5 comments

Comments

@emlys
Copy link

emlys commented May 1, 2024

Expected behavior and actual behavior.

intersection unexpectedly raises a RuntimeWarning.
This script:

import shapely
a = shapely.from_wkt('POLYGON ((110 110, 110 100, 100 100, 100 110, 110 110))')
b = shapely.from_wkt('LINESTRING (100 -100, 100 100)')
print(a.intersection(b))

should print POINT (100 100) without warnings. This works as expected on Intel macs. On M1 macs, the result is correct but I get a warning:

/Users/runner/micromamba/envs/env/lib/python3.12/site-packages/shapely/set_operations.py:131: RuntimeWarning: invalid value encountered in intersection
  return lib.intersection(a, b, **kwargs)
POINT (100 100)

Steps to reproduce the problem.

Full example here. The test runs on Github Actions on macos-13 (Intel) and macos-14 (M1) (https://github.com/emlys/demos/actions/runs/8913541967/job/24479230749).

Operating system

Mac OSX 14.4.1

Shapely version and provenance

2.0.4 from conda-forge

@jorisvandenbossche
Copy link
Member

We have had several of such reports in the past (eg #1709, #1345 for some context). Most of them have been fixed in the meantime, and also typically involved some special case such as empty geometries as input or as result.

Now, for this specific example, I can't reproduce this on Linux (Ubuntu), also using shapely 2.0.4 from conda-forge (using GEOS 3.12.1).

@martinfleis
Copy link
Contributor

I can reproduce that on M1.

@jorisvandenbossche
Copy link
Member

Hmm, then we will need someone with a (M1) Mac to debug this ..

In the past, what I did to debug such warnings is building GEOS locally with the following snippet added somewhere:

#include <fenv.h>

feenableexcept(FE_INVALID);

(although now I am writing this, I am wondering if that would also work if you add that to ufuncs.c in shapely itself with a released build from GEOS, which would be easier).

Now, that might be something gcc specific and not work with clang: https://stackoverflow.com/questions/37819235/how-do-you-enable-floating-point-exceptions-for-clang-in-os-x

@martinfleis
Copy link
Contributor

I did try to include the code above in shapely but it won't compile. And stuff that comes via Google search or that SO link is way beyond my understanding. The warning is reproducible in GitHub Actions but I understand that it is not the fastest way of development...

@theroggy
Copy link
Contributor

theroggy commented May 6, 2024

Hmm... I've had some unit tests failing in another project since last week for macos with small differences in results for union,... operations. Apparently it is since macos-latest switched to macos14 on arm64 that they started failing, so it seems there are more differences that can be expected...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants