From d1f438e17faa343991349b28de59a3064113f510 Mon Sep 17 00:00:00 2001 From: Laura Mendoza Date: Mon, 6 Jan 2020 18:02:49 +0100 Subject: [PATCH 1/4] speeding up new calc --- tofu/geom/_GG.pyx | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tofu/geom/_GG.pyx b/tofu/geom/_GG.pyx index 7143e078f..7f3919bea 100644 --- a/tofu/geom/_GG.pyx +++ b/tofu/geom/_GG.pyx @@ -2988,13 +2988,18 @@ def LOS_calc_signal(func, double[:,::1] ray_orig, double[:,::1] ray_vdir, res, # Integrate if n_imode == 0: # "sum" integration mode # .. integrating function .......................................... - for ii in range(nlos): - if ii > 0: - sig[:,ii] = np.sum(val_2d[:, ind_arr[ii-1]:ind_arr[ii]], - axis=-1) * reseff_arr[ii] - else: - sig[:,0] = np.sum(val_2d[:, 0:ind_arr[0]], - axis=-1) * reseff_arr[0] + #reseff = np.copy(np.asarray(reseff_arr[0])) + reseff_mv = reseff + indices = np.copy(np.asarray(ind_arr).astype(int)) + sig = np.add.reduceat(val_2d, np.r_[0, indices], + axis=-1)*reseff_mv[None, :] + # for ii in range(nlos): + # if ii > 0: + # sig[:,ii] = np.sum(val_2d[:, ind_arr[ii-1]:ind_arr[ii]], + # axis=-1) * reseff_arr[ii] + # else: + # sig[:,0] = np.sum(val_2d[:, 0:ind_arr[0]], + # axis=-1) * reseff_arr[0] # Cleaning up... free(coeff_ptr[0]) free(coeff_ptr) From 70e63e0394ab80744386d0a431b194cff2702f96 Mon Sep 17 00:00:00 2001 From: "Laura S. Mendoza" Date: Mon, 6 Jan 2020 19:02:15 +0100 Subject: [PATCH 2/4] [enhacement] defined res and indices the right way, erased old code --- tofu/geom/_GG.pyx | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/tofu/geom/_GG.pyx b/tofu/geom/_GG.pyx index 7f3919bea..6ed2f1a10 100644 --- a/tofu/geom/_GG.pyx +++ b/tofu/geom/_GG.pyx @@ -2988,18 +2988,10 @@ def LOS_calc_signal(func, double[:,::1] ray_orig, double[:,::1] ray_vdir, res, # Integrate if n_imode == 0: # "sum" integration mode # .. integrating function .......................................... - #reseff = np.copy(np.asarray(reseff_arr[0])) - reseff_mv = reseff - indices = np.copy(np.asarray(ind_arr).astype(int)) + reseffs = np.copy(np.asarray(reseff_arr)) + indices = np.copy(np.asarray(ind_arr).astype(int)) sig = np.add.reduceat(val_2d, np.r_[0, indices], - axis=-1)*reseff_mv[None, :] - # for ii in range(nlos): - # if ii > 0: - # sig[:,ii] = np.sum(val_2d[:, ind_arr[ii-1]:ind_arr[ii]], - # axis=-1) * reseff_arr[ii] - # else: - # sig[:,0] = np.sum(val_2d[:, 0:ind_arr[0]], - # axis=-1) * reseff_arr[0] + axis=-1)*reseffs[None, :] # Cleaning up... free(coeff_ptr[0]) free(coeff_ptr) From e332b2a4ec1c6f0414b8e88626a8d8268c596640 Mon Sep 17 00:00:00 2001 From: Laura Mendoza Date: Tue, 7 Jan 2020 15:17:32 +0100 Subject: [PATCH 3/4] fixed f-contiguous error --- tofu/geom/_GG.pyx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tofu/geom/_GG.pyx b/tofu/geom/_GG.pyx index 6ed2f1a10..ea918a178 100644 --- a/tofu/geom/_GG.pyx +++ b/tofu/geom/_GG.pyx @@ -2982,16 +2982,19 @@ def LOS_calc_signal(func, double[:,::1] ray_orig, double[:,::1] ray_vdir, res, num_threads) # .................................................................. if ani: - val_2d = func(pts, t=t, vect=-usbis, **fkwdargs) + val_arr = func(pts, t=t, vect=-usbis, **fkwdargs) else: - val_2d = func(pts, t=t, **fkwdargs) + val_arr = func(pts, t=t, **fkwdargs) + val_2d = val_arr # Integrate if n_imode == 0: # "sum" integration mode # .. integrating function .......................................... reseffs = np.copy(np.asarray(reseff_arr)) indices = np.copy(np.asarray(ind_arr).astype(int)) - sig = np.add.reduceat(val_2d, np.r_[0, indices], - axis=-1)*reseffs[None, :] + sig = np.asfortranarray(np.add.reduceat(val_arr, + np.r_[0, indices], + axis=-1) + * reseffs[None, :]) # Cleaning up... free(coeff_ptr[0]) free(coeff_ptr) From e1f483816b360c9c0b55d767418aba2a22f05bd8 Mon Sep 17 00:00:00 2001 From: Laura Mendoza Date: Tue, 7 Jan 2020 16:56:45 +0100 Subject: [PATCH 4/4] only keeping memory view --- tofu/geom/_GG.pyx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tofu/geom/_GG.pyx b/tofu/geom/_GG.pyx index ea918a178..e2ce85d88 100644 --- a/tofu/geom/_GG.pyx +++ b/tofu/geom/_GG.pyx @@ -2982,16 +2982,16 @@ def LOS_calc_signal(func, double[:,::1] ray_orig, double[:,::1] ray_vdir, res, num_threads) # .................................................................. if ani: - val_arr = func(pts, t=t, vect=-usbis, **fkwdargs) + val_2d = func(pts, t=t, vect=-usbis, **fkwdargs) else: - val_arr = func(pts, t=t, **fkwdargs) - val_2d = val_arr + val_2d = func(pts, t=t, **fkwdargs) + # Integrate if n_imode == 0: # "sum" integration mode # .. integrating function .......................................... reseffs = np.copy(np.asarray(reseff_arr)) indices = np.copy(np.asarray(ind_arr).astype(int)) - sig = np.asfortranarray(np.add.reduceat(val_arr, + sig = np.asfortranarray(np.add.reduceat(val_2d, np.r_[0, indices], axis=-1) * reseffs[None, :])