<jupyter_start><jupyter_text>Test performance<jupyter_code>#test function

@jit(nopython=True)
def vdpi(t,y):
    return np.array([y[1],(1-y[0]**2)*y[1]-y[0]])


def vdpin(t,y):
    return np.array([y[1],(1-y[0]**2)*y[1]-y[0]])
from RK2 import *
from RK3 import *
from RK4 import *
from RKDP import *
from euler import *

from RK2n import *
from RK3n import *
from RK4n import *
from RKDPn import *
from eulern import *

eulerD,eulernD,RK2D,RK2nD,RK3D,RK3nD,RK4D,RK4nD,RKDPD,RKDPnD = {},{},{},{},{},{},{},{},{},{}


t = [ [[]]*4 for i in range(15)]

for i in range(5):
    
    
    h=10**-(i+1)

    print('h=',h)
    
    #Numba
    t[0][i] = %timeit -o t,y=euler(vdpi,ics=np.array([2,0]),h=h,span=np.array([0,20]),degree =2)
    t[1][i] = %timeit -o t,y=RK2(vdpi,ics=np.array([2,0]),h=h,span=np.array([0,20]),degree =2)
    t[2][i] = %timeit -o t,y=RK3(vdpi,ics=np.array([2,0]),h=h,span=np.array([0,20]),degree =2)
    t[3][i] = %timeit -o t,y=RK4(vdpi,ics=np.array([2,0]),h=h,span=np.array([0,20]),degree =2)
    t[4][i] = %timeit -o t,y=RKDP(vdpi,ics=np.array([2,0]),h=h,span=np.array([0,20]),degree =2)

    #numpy
    t[5][i] = %timeit -o t,y=eulern(vdpin,ics=np.array([2,0]),h=h,span=np.array([0,20]),degree =2)
    t[6][i] = %timeit -o t,y=RK2n(vdpin,ics=np.array([2,0]),h=h,span=np.array([0,20]),degree =2)
    t[7][i] = %timeit -o t,y=RK3n(vdpin,ics=np.array([2,0]),h=h,span=np.array([0,20]),degree =2)
    t[8][i] = %timeit -o t,y=RK4n(vdpin,ics=np.array([2,0]),h=h,span=np.array([0,20]),degree =2)
    t[9][i] = %timeit -o t,y=RKDPn(vdpin,ics=np.array([2,0]),h=h,span=np.array([0,20]),degree =2)

matlab=    [
    [0.0008,    0.0079,    0.0806,    0.8443],
    [0.0016,    0.0139,    0.1281,    1.3238],
    [0.0019,    0.0183,    0.1776,    1.7806],
    [0.0027,    0.0224,    0.2269,    2.2611],
    [0.0034,    0.0322,    0.3242,    3.3330]
    ]
# tc=t.copy()
# for i,itemi in enumerate(tc):
#     for j,itemj in enumerate(itemi):
#         tc[i][j] = itemj.average
#         print(itemj)
times = np.array(t[:-5])
alltimes= np.concatenate((times,matlab),axis=0)
###Matplotlib styles
from matplotlib import ticker
formatter = ticker.ScalarFormatter(useMathText=True)
formatter.set_scientific(True) 


import matplotlib as mpl
mpl.rcParams.update({
    "text.usetex": False,
    "font.family": "sans-serif",
    "font.sans-serif": ["Helvetica"]})

# mpl.rcParams['figure.dpi'] = 100
mpl.rcParams.update({'font.size': 16})
mpl.rcParams['axes.linewidth'] = 2

np.savetxt("numpynumbamatlabode.csv", alltimes, delimiter=",")
alltimes
alltimes[:][0]
plt.figure(figsize=(15,20))

plt.subplot(5,1,1)

plt.loglog([0.1,0.01,0.001,0.0001],alltimes[0,:],linewidth=3)
plt.loglog([0.1,0.01,0.001,0.0001],alltimes[5,:],linewidth=3)
plt.loglog([0.1,0.01,0.001,0.0001],alltimes[10,:],linewidth=3)
plt.title('euler')
plt.ylabel('execution time');
plt.legend(['Accelerated' , 'Numpy','matlab'])

plt.subplot(5,1,2)
plt.loglog([0.1,0.01,0.001,0.0001],alltimes[1,:],linewidth=3)
plt.loglog([0.1,0.01,0.001,0.0001],alltimes[6,:],linewidth=3)
plt.loglog([0.1,0.01,0.001,0.0001],alltimes[11,:],linewidth=3)
plt.title('RK2')
plt.ylabel('execution time');
plt.legend(['Accelerated' , 'Numpy','matlab'])

plt.subplot(5,1,3)
plt.loglog([0.1,0.01,0.001,0.0001],alltimes[2,:],linewidth=3)
plt.loglog([0.1,0.01,0.001,0.0001],alltimes[7,:],linewidth=3)
plt.loglog([0.1,0.01,0.001,0.0001],alltimes[12,:],linewidth=3)
plt.title('RK3')
plt.ylabel('execution time');
plt.legend(['Accelerated' , 'Numpy','matlab'])

plt.subplot(5,1,4)
plt.loglog([0.1,0.01,0.001,0.0001],alltimes[3,:],linewidth=3)
plt.loglog([0.1,0.01,0.001,0.0001],alltimes[8,:],linewidth=3)
plt.loglog([0.1,0.01,0.001,0.0001],alltimes[13,:],linewidth=3)
plt.title('RK4')
plt.ylabel('execution time');
plt.legend(['Accelerated' , 'Numpy','matlab'])

plt.subplot(5,1,5)
plt.loglog([0.1,0.01,0.001,0.0001],alltimes[4,:],linewidth=3)
plt.loglog([0.1,0.01,0.001,0.0001],alltimes[9,:],linewidth=3)
plt.loglog([0.1,0.01,0.001,0.0001],alltimes[14,:],linewidth=3)
plt.title('RKDP')
plt.ylabel('execution time');
plt.legend(['Accelerated' , 'Numpy','matlab'])
plt.xlabel('step size')

plt.xticks([0.1,0.01,0.001,0.0001])
np.average(alltimes[10:15,:] / alltimes[0:5,:],axis =1 )<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.25848256361922717, 'fraction_numerical': 0.11875589066918002, 'mean_word_length': 5.422087745839637, 'pattern_counts': {'":': 3, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '113765', 'license': 'MIT', 'n_tokens_mistral': 2313, 'n_tokens_neox': 2052, 'n_words': 228, 'path': 'ACCELERATED ODE SOLVERS.ipynb', 'repo_name': 'ASEM000/Accelerated-N-dimensional-ODE-solvers', 'size': '4244'}