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

Numpy 1.24 compatibility #1012

Merged
merged 7 commits into from
Dec 21, 2022
Merged

Numpy 1.24 compatibility #1012

merged 7 commits into from
Dec 21, 2022

Conversation

hsinfan1996
Copy link
Contributor

No description provided.

@hsinfan1996 hsinfan1996 linked an issue Dec 21, 2022 that may be closed by this pull request
@coveralls
Copy link

coveralls commented Dec 21, 2022

Pull Request Test Coverage Report for Build 3751636306

  • 9 of 9 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.003%) to 97.528%

Totals Coverage Status
Change from base Build 3734529097: 0.003%
Covered Lines: 4852
Relevant Lines: 4975

💛 - Coveralls

Copy link
Contributor

@nikfilippas nikfilippas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, good. In core.py, I'd personally get rid of the extra check for the numpy integer and floating types, particularly as those are generic superclasses.

pyccl/__init__.py Outdated Show resolved Hide resolved
@hsinfan1996
Copy link
Contributor Author

hsinfan1996 commented Dec 21, 2022

Ok, good. In core.py, I'd personally get rid of the extra check for the numpy integer and floating types, particularly as those are generic superclasses.

isinstance(np.float(1.), np.floating) will evaluate to False, because np.float is identical to python float, which is not part of np.floating. Same problem with np.int and int.

@nikfilippas
Copy link
Contributor

isinstance(np.float(1.), np.floating) will evaluate to False, because np.float is identical to python float, which is not part of np.floating. Same problem with np.int and int.

As does isinstance(1., np.floating). AFAIK numpy's floating is a generic superclass which is only there for some lower-level stuff. We can't create instances of np.floating so the check isinstance(v, np.floating) that was there before is a bug.
Also, the class is so generic I'd argue it is akin to checking if something is an instance of object.

@hsinfan1996
Copy link
Contributor Author

isinstance(np.float(1.), np.floating) will evaluate to False, because np.float is identical to python float, which is not part of np.floating. Same problem with np.int and int.

As does isinstance(1., np.floating). AFAIK numpy's floating is a generic superclass which is only there for some lower-level stuff. We can't create instances of np.floating so the check isinstance(v, np.floating) that was there before is a bug. Also, the class is so generic I'd argue it is akin to checking if something is an instance of object.

Oh I see what you meant.

pyccl/__init__.py Outdated Show resolved Hide resolved
@hsinfan1996
Copy link
Contributor Author

Just did some tests
isinstance(np.float64(1.), float) evaluates to True
isinstance(np.float32(1.), float) evaluates to False
isinstance(np.float32(1.), float) evaluates to False
isinstance(np.float32(1.), np.floating) evaluates to True
Are those what we expected?

@nikfilippas
Copy link
Contributor

nikfilippas commented Dec 21, 2022

Just did some tests
isinstance(np.float64(1.), float) evaluates to True
isinstance(np.float32(1.), float) evaluates to False
isinstance(np.float32(1.), float) evaluates to False
isinstance(np.float32(1.), np.floating) evaluates to True
Are those what we expected?

Yes, when writing the yaml file we essentially check the type of the arguments passed in ccl.Cosmology. They will be ints, floats, lists, dicts, or strings. By default, the built-in float and int types match your computer's architecture, so by the output I can tell you work on a 64-bit machine. The rest is just details. And we don't want to involve the np.floating and np.integer superclasses I think, it will just complicate things more.

pyccl/__init__.py Outdated Show resolved Hide resolved
@hsinfan1996 hsinfan1996 merged commit d7c40d4 into master Dec 21, 2022
@hsinfan1996 hsinfan1996 deleted the numpy_1.24_compatibility branch December 21, 2022 18:50
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

Successfully merging this pull request may close these issues.

Numpy 1.24 compatibility
3 participants