Skip to content

Commit

Permalink
Merge pull request #731 from StingraySoftware/simplify_numba_mock
Browse files Browse the repository at this point in the history
Simplify numba mocking functions and improve docs
  • Loading branch information
matteobachetti committed May 23, 2023
2 parents 1c85c6b + 55ee6e0 commit 900d81a
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 32 deletions.
1 change: 1 addition & 0 deletions docs/changes/731.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Simplify numba mocking code, and possibly improve code coverage estimate
57 changes: 51 additions & 6 deletions docs/install.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,53 @@
Dependencies
============
A **minimal installation** of Stingray requires the following dependencies:

+ astropy>=4.0
+ numpy>=1.17.0
+ scipy>=1.1.0
+ matplotlib>=3.0,!=3.4.0

In **typical** uses, requiring input/output, caching of results, and faster processing, we **recommend the following dependencies**:

+ numba (**highly** recommended)
+ tbb (needed by numba)
+ tqdm (for progress bars, always useful)
+ pyfftw (for the fastest FFT in the West)
+ h5py (for input/output)
+ pyyaml (for input/output)
+ emcee (for MCMC analysis, e.g. for PSD fitting)
+ corner (for the plotting of MCMC results)
+ statsmodels (for some statistical analysis)

For **pulsar searches and timing**, we recommend installing

+ pint-pulsar

Some of the dependencies are available in ``conda``, the others via ``pip``.
To install all required and recommended dependencies in a recent installation, you should be good running the following command:

$ pip install astropy scipy matplotlib numpy h5py tqdm numba pint-pulsar emcee corner statsmodels pyfftw tbb

For development work, you will need the following extra libraries:

+ pytest
+ pytest-astropy
+ tox
+ jinja2<=3.0.0
+ docutils
+ sphinx-astropy
+ nbsphinx>=0.8.3,!=0.8.8
+ pandoc
+ ipython
+ jupyter
+ notebook
+ towncrier<22.12.0
+ black

Which can be installed with the following command:

$ pip install pytest pytest-astropy jinja2<=3.0.0 docutils sphinx-astropy nbsphinx pandoc ipython jupyter notebook towncrier<22.12.0 tox black

Downloading and Installing Stingray
===================================

Expand Down Expand Up @@ -37,12 +87,7 @@ source (it *will* have bugs; you've been warned!), first clone

$ git clone --recursive https://github.com/StingraySoftware/stingray.git

Now ``cd`` into the newly created ``stingray`` directory and install the necessary
dependencies: ::

$ cd stingray
$ pip install astropy scipy matplotlib numpy pytest pytest-astropy h5py tqdm

Now ``cd`` into the newly created ``stingray`` directory.
Finally, install ``stingray`` itself: ::

$ pip install -e "."
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ python_requires = >=3.8
setup_requires = setuptools_scm
install_requires =
astropy>=4.0
six
numpy>=1.17.0
scipy>=1.1.0
; Matplotlib 3.4.0 is incompatible with Astropy
Expand Down
21 changes: 21 additions & 0 deletions stingray/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,3 +406,24 @@ def test_is_sorted_no_array():
input_array = 1.0

assert utils.is_sorted(input_array)


@utils.njit()
def bla_1():
return


@utils.njit
def bla_2():
return


@utils.vectorize(["float64(float64)"])
def bla_3(j):
return j


def test_numba_compiled_or_mocked():
bla_1()
bla_2()
bla_3(1.0)
38 changes: 13 additions & 25 deletions stingray/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

# If numba is installed, import jit. Otherwise, define an empty decorator with
# the same name.
HAS_NUMBA = False
try:
from numba import jit

Expand All @@ -49,36 +48,25 @@
from numba.core.errors import NumbaValueError
except ImportError:
warnings.warn("Numba not installed. Faking it")
HAS_NUMBA = False
NumbaValueError = Exception

class jit(object):
def __init__(self, *args, **kwargs):
pass
def njit(f=None, *args, **kwargs):
def decorator(func, *a, **kw):
return func

def __call__(self, func):
def wrapped_f(*args, **kwargs):
return func(*args, **kwargs)

return wrapped_f

class njit(object):
def __init__(self, *args, **kwargs):
pass

def __call__(self, func):
def wrapped_f(*args, **kwargs):
return func(*args, **kwargs)

return wrapped_f
if callable(f):
return f
else:
return decorator

class vectorize(object):
def __init__(self, *args, **kwargs):
pass
jit = njit

def __call__(self, func):
wrapped_f = np.vectorize(func)
def vectorize(*args, **kwargs):
def decorator(func, *a, **kw):
return np.vectorize(func)

return wrapped_f
return decorator

def generic(x, y=None):
return None
Expand Down

0 comments on commit 900d81a

Please sign in to comment.