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

Allow readonly arrays in numba jit signature #23

Merged
merged 3 commits into from
Feb 12, 2023

Conversation

jvdd
Copy link
Contributor

@jvdd jvdd commented Jan 29, 2023

This PR is a continuation of the work contributed in PR #13

Contributions of this PR:

  • allow readonly arrays in the numba jit signature
    -> this was an issue for sample_entropy and detrended_fluctuation
  • minor refactoring of the tests - moving duplicate code to a utils.py file
  • adding 2 additional tests that test whether non-writable (i.e., readonly) arrays can be used as input for a range of datatypes

Other contribution:

  • set nopython to True for the _higuchi_fd function - this was the only @jit decorated function for which this flag was not set.

Illustration of the issue that this PR tackles:

In [1]: import antropy as ant; import numpy as np

In [2]: ant.__version__
Out[2]: '0.1.5'

In [3]: x = np.random.randn(3_000).astype("float32")
   ...: x.flags.writeable = False
   ...: ant.detrended_fluctuation(x)
Out[3]: 0.5552594723035992

In [4]: x = np.random.randn(3_000).astype("float64")
   ...: x.flags.writeable = False
   ...: ant.detrended_fluctuation(x)
---------------------------------------------------------------------------
TypeError
    ...
TypeError: No matching definition for argument type(s) readonly array(float64, 1d, C)

In [5]: x = np.random.rand(3_000).astype("float32")
   ...: x.flags.writeable = False
   ...: ant.sample_entropy(x)
Out[5]: 2.17591547251706

In [6]: x = np.random.rand(3_000).astype("float64")
   ...: x.flags.writeable = False
   ...: ant.sample_entropy(x)
---------------------------------------------------------------------------
TypeError
    ...
TypeError: No matching definition for argument type(s) readonly array(float64, 1d, C), int64, float64

@jvdd
Copy link
Contributor Author

jvdd commented Jan 29, 2023

Should be ready for review! @raphaelvallat :)

Copy link
Owner

@raphaelvallat raphaelvallat left a comment

Choose a reason for hiding this comment

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

Beautiful work 🚀 Merging now! Thanks again :)

@raphaelvallat raphaelvallat merged commit e76a8c7 into raphaelvallat:master Feb 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants