Repository: einsteinpy/einsteinpy

Issue:
Leverage numba jit
<!--

WELCOME ABOARD!

Hi and welcome to the poliastro project. We appreciate bug reports, questions
about documentation, and suggestions for new features.

IMPORTANT: If you are reporting a problem with poliastro, please follow the
template below. If it's a suggestion, a possible new addition to the library,
or just want to say "Thank you!", you can remove all this text and start
from scratch.

-->
<!--- Provide a general summary of the issue in the Title above -->

🐞 **Problem**

As of now, very simple computations take a lot of time to run. We can use `@jit` decorator provided by numba.
<!--- Provide a detailed description of the problem you have -->
<!---

If you can provide some short code to reproduce the issue
and copy the complete traceback, it will make it easier for us to fix it.
We will ask you for your installation details in the following sections.

-->

🎯 **Goal**

<!--- Why is this change important to you? How would you use it? -->
<!--- How can it benefit other users? -->
Make einsteinpy faster.

💡 **Possible solutions**

http://numba.pydata.org/numba-doc/latest/user/jit.html

<!--- Not obligatory, but suggest an idea for implementing addition or change -->

📋  **Steps to solve the problem**

 * Comment below about what you've started working on.
 * Add, commit, push your changes
 * Submit a pull request and add this in comments - `Addresses #<put issue number here>`
 * Ask for a review in comments section of pull request
 * Celebrate your contribution to this project 🎉


Comments:

Patch:
diff --git a/docs/source/api/plotting/geodesics.rst b/docs/source/api/plotting/geodesics_static.rst
similarity index 52%
rename from docs/source/api/plotting/geodesics.rst
rename to docs/source/api/plotting/geodesics_static.rst
index d09d445..cff12c0 100644
--- a/docs/source/api/plotting/geodesics.rst
+++ b/docs/source/api/plotting/geodesics_static.rst
@@ -1,8 +1,8 @@
-Geodesics module
-================
+Static 2D Plotting module
+=========================
 
 This module contains the basic classes for static plottings in
 2-dimensions for scatter and line:
 
-.. automodule:: einsteinpy.plotting.geodesics
+.. automodule:: einsteinpy.plotting.geodesics_static
     :members:
diff --git a/docs/source/api/plotting/plotting_index.rst b/docs/source/api/plotting/plotting_index.rst
index c08e0fa..d8dce95 100644
--- a/docs/source/api/plotting/plotting_index.rst
+++ b/docs/source/api/plotting/plotting_index.rst
@@ -7,4 +7,4 @@ This module contains the basic classes for static and interactive
 .. toctree::
     :maxdepth: 2
 
-    geodesics
+    geodesics_static
diff --git a/src/einsteinpy/ijit.py b/src/einsteinpy/ijit.py
new file mode 100644
index 0000000..0b85935
--- /dev/null
+++ b/src/einsteinpy/ijit.py
@@ -0,0 +1,36 @@
+"""Just-in-time compiler.
+
+Wraps numba if it is available as a module, uses an identity
+decorator instead.
+
+"""
+import inspect
+import warnings
+
+
+def ijit(first=None, *args, **kwargs):
+    """Identity JIT, returns unchanged function.
+
+    """
+
+    def _jit(f):
+        return f
+
+    if inspect.isfunction(first):
+        return first
+    else:
+        return _jit
+
+
+try:
+    import numba
+
+    jit = numba.njit
+except ImportError:
+    warnings.warn(
+        "Could not import numba package. All einsteinpy "
+        "functions will work properly but the CPU intensive "
+        "algorithms will be slow. Consider installing numba to "
+        "boost performance."
+    )
+    jit = ijit
diff --git a/src/einsteinpy/plotting/__init__.py b/src/einsteinpy/plotting/__init__.py
index 9dce831..9a44108 100644
--- a/src/einsteinpy/plotting/__init__.py
+++ b/src/einsteinpy/plotting/__init__.py
@@ -1,1 +1,1 @@
-from .geodesics import ScatterGeodesicPlotter, StaticGeodesicPlotter
+from .geodesics_static import ScatterGeodesicPlotter, StaticGeodesicPlotter


Test patch:
diff --git a/src/einsteinpy/plotting/geodesics.py b/src/einsteinpy/plotting/geodesics_static.py
similarity index 100%
rename from src/einsteinpy/plotting/geodesics.py
rename to src/einsteinpy/plotting/geodesics_static.py
diff --git a/src/einsteinpy/tests/test_plotting/test_scattergeodesicplotter.py b/src/einsteinpy/tests/test_plotting/test_scattergeodesicplotter.py
index c34f626..4fc3714 100644
--- a/src/einsteinpy/tests/test_plotting/test_scattergeodesicplotter.py
+++ b/src/einsteinpy/tests/test_plotting/test_scattergeodesicplotter.py
@@ -27,7 +27,9 @@ def test_plot_attractor_is_called_only_once(dummy_data):
     assert cl._attractor_present == True
 
 
-@mock.patch("einsteinpy.plotting.geodesics.ScatterGeodesicPlotter._plot_attractor")
+@mock.patch(
+    "einsteinpy.plotting.geodesics_static.ScatterGeodesicPlotter._plot_attractor"
+)
 def test_plot_calls_plot_attractor(mock_plot_attractor):
     r = [306 * u.m, np.pi / 2 * u.rad, np.pi / 2 * u.rad]
     v = [0 * u.m / u.s, 0 * u.rad / u.s, 951.0 * u.rad / u.s]
@@ -39,7 +41,7 @@ def test_plot_calls_plot_attractor(mock_plot_attractor):
     mock_plot_attractor.assert_called_with()
 
 
-@mock.patch("einsteinpy.plotting.geodesics.plt.show")
+@mock.patch("einsteinpy.plotting.geodesics_static.plt.show")
 def test_plot_show_shows_plot(mock_show):
     r = [306 * u.m, np.pi / 2 * u.rad, np.pi / 2 * u.rad]
     v = [0 * u.m / u.s, 0 * u.rad / u.s, 951.0 * u.rad / u.s]
diff --git a/src/einsteinpy/tests/test_plotting/test_staticgeodesicplotter.py b/src/einsteinpy/tests/test_plotting/test_staticgeodesicplotter.py
index 980b9a6..e421105 100644
--- a/src/einsteinpy/tests/test_plotting/test_staticgeodesicplotter.py
+++ b/src/einsteinpy/tests/test_plotting/test_staticgeodesicplotter.py
@@ -29,7 +29,7 @@ def test_staticgeodesicplotter_has_axes(dummy_data):
     assert cl._attractor_present is False
 
 
-@mock.patch("einsteinpy.plotting.geodesics.StaticGeodesicPlotter.plot_attractor")
+@mock.patch("einsteinpy.plotting.geodesics_static.StaticGeodesicPlotter.plot_attractor")
 def test_plot_calls_plot_attractor(mock_plot_attractor):
     r = [306 * u.m, np.pi / 2 * u.rad, np.pi / 2 * u.rad]
     v = [0 * u.m / u.s, 0 * u.rad / u.s, 951.0 * u.rad / u.s]