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

[InMemoryDataset redesign] fill_hyperspace() #371

Merged
merged 4 commits into from
Sep 16, 2024

Conversation

crusaderky
Copy link
Collaborator

@crusaderky crusaderky commented Sep 10, 2024

This is a partial PR that breaks down #370 into digestible chunks - see #370 (comment)

This PR adds a single new utility function, fill_hyperspace, that for the time being remains unused and will be later used by #370.

# Note: Py_ssize_t is always the same as np.intp
assert np.intp().nbytes == _py_ssize_t_nbytes

if cython.compiled: # pragma: nocover
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

One of the many things I love about cython pure python mode: you can just disable cythonization and run coverage on it!

Copy link
Collaborator

Choose a reason for hiding this comment

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

As an only occasional cython user, this seems incredibly useful! Lately I've been discovering more reasons to use cython for compiled extensions...add this to the list. It seems like the only downside is that for cython-only code you can't run coverage on it - but that's still a big improvement, since the rest of the module is covered!

@@ -0,0 +1 @@
hyperspace.py
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a symlink hack to make meson compile a pure-python cython module

# To generate HTML compilation reports:
# (First double check that flags below match those above)
#
# cythonize -3 -a -X infer_types=True -X initializedcheck=False -X boundscheck=False -X wraparound=False -X cdivision=True versioned_hdf5/{hyperspace,subchunk_map}.py
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This line is incorrect until the next PR that will add the same flags to subchunk_map.py

# instead of its compiled form. This fails in CI, as Cython is not a runtime dependency,
# and regardless would cause a lot of type-checking normally performed by Cython to be
# skipped so it is to be avoided.
from . import hyperspace # noqa: F401
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This will later be replaced by a proper import of functionality

Copy link
Collaborator

Choose a reason for hiding this comment

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

Understood. Maybe the later revision will address this, but

  1. we can also make cython a test dependency if needed, and
  2. I don't think we have any doctests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hyperspace.py has two doctests.
Making cython a test dependency would be a bad idea because, while it would fix the CI failure, it would cause ALL tests to use the pure-python version of hyperspace.py, which is much more lenient in terms of typing than the cythonized version, thus potentially hiding breaking bugs completely until someone manually tries using it.

crusaderky added a commit to crusaderky/versioned-hdf5 that referenced this pull request Sep 12, 2024
crusaderky added a commit to crusaderky/versioned-hdf5 that referenced this pull request Sep 12, 2024
Copy link
Collaborator

@peytondmurray peytondmurray left a comment

Choose a reason for hiding this comment

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

This first addition looks great. Thank you especially for the very thorough documentation, because _hyperrectangles_between would be quite hard to follow without it! 🚀

# Note: Py_ssize_t is always the same as np.intp
assert np.intp().nbytes == _py_ssize_t_nbytes

if cython.compiled: # pragma: nocover
Copy link
Collaborator

Choose a reason for hiding this comment

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

As an only occasional cython user, this seems incredibly useful! Lately I've been discovering more reasons to use cython for compiled extensions...add this to the list. It seems like the only downside is that for cython-only code you can't run coverage on it - but that's still a big improvement, since the rest of the module is covered!

assert np.intp().nbytes == _py_ssize_t_nbytes

if cython.compiled: # pragma: nocover
from cython.cimports.cpython import array # type: ignore
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, I guess types are are not supplied by cython?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't follow, what types?

versioned_hdf5/hyperspace.py Outdated Show resolved Hide resolved
versioned_hdf5/hyperspace.py Show resolved Hide resolved
versioned_hdf5/hyperspace.py Outdated Show resolved Hide resolved
# instead of its compiled form. This fails in CI, as Cython is not a runtime dependency,
# and regardless would cause a lot of type-checking normally performed by Cython to be
# skipped so it is to be avoided.
from . import hyperspace # noqa: F401
Copy link
Collaborator

Choose a reason for hiding this comment

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

Understood. Maybe the later revision will address this, but

  1. we can also make cython a test dependency if needed, and
  2. I don't think we have any doctests?

@crusaderky crusaderky merged commit f98e5f4 into deshaw:master Sep 16, 2024
8 checks passed
@crusaderky crusaderky deleted the hyperspace branch September 16, 2024 08:25
crusaderky added a commit to crusaderky/versioned-hdf5 that referenced this pull request Oct 15, 2024
peytondmurray pushed a commit that referenced this pull request Oct 15, 2024
* Revert #371

* Salvage changes
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.

2 participants