Advanced Python for Data Science Assignment 8

  1. Use your knowledge of Numba to convert the nbody_opt.py program you wrote in Assignment 3 into a Numba program. Pay particular attention to the following:

    • Add @jit decorators to all funcitons
    • Add function signatures to all funcitons

    Place the resulting code in a file called nbody_numba.py and check that it produces the same results as the original program.

    When you are satisfied that your program is working, commit it to the same repository you used in Assignment 3

  2. Add a vectorized ufunc to the nbody_numba.py program called vec_deltas that takes two NumPy arrays of floats and returns the difference between each element. For example:

    a = np.arange(0, 3, 1, dtype=np.float64)
    b = np.arange(3, 1, -1, dtype=np.float64)
    c = vec_deltas(a, b)
    

    This would result in the array:

    array([-3.0, -1.0, 1.0])
    

    Modify your nbody_numba.py program so that it uses vec_deltas rather than the compute_deltas function. Hint: This will require making changes to BODIES so that the first element of each tuple is a NumPy array rather than a list, and the necessary changes to the code in order to support this.

    Place the resulting code in nbody_numba.py and check that it produces the same results as the original program.

    When you are satisfied that your program is working, commit it to the same repository you used in Assignment 3.