comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: Re: for loop is killing me

Re: for loop is killing me
type: item
description: On Nov 6, 1:31 am, tarequea...@gmail.com wrote: > Hello all, > > help me! I am running a code 'infested' with for loops.And as u can > guess, its painfully slow. The part of my code with loop looks like > the following: > > jump1: > > ;Setting up the Green functions array which will have the same number > of elements as of amp_vec > > G=fltarr(n_elements(amp_vec),n_elements(amp_vec)) > G_phi=fltarr(n_elements(amp_vec)) > G_rp=fltarr(n_elements(amp_vec)) > G_r=fltarr(n_elements(amp_vec)) > G_in=fltarr(n_elements(amp_vec)) > G_out=fltarr(n_elements(amp_vec)) > G_p=fltarr(n_elements(amp_vec)) > G_h=fltarr(n_elements(amp_vec)) > gp=fltarr(n_elements(amp_vec)) > gh=fltarr(n_elements(amp_vec)) > G_in_msum = fltarr(n_elements(amp_vec)) > G_out_msum = fltarr(n_elements(amp_vec)) > G_in_phisum = fltarr(n_elements(amp_vec)) > G_out_phisum = fltarr(n_elements(amp_vec)) > > if ignore_realdata eq 1. then begin > amp_vec= abs(randomn(0.5,n_radial_points,/double)) > a=1. > ;print,' amp_vec is',amp_vec > endif > > do_u_like_to_start_with_rp_loop = 0 ; Set 1 if YES,0 if NO > > if do_u_like_to_start_with_rp_loop eq 1. then BEGIN > PRINT,' WE ARE USING rp PREFERED LOOP' > goto,jump2 > > ENDIF > > PRINT,' WE ARE USING r PREFERED LOOP' > for i_r= 0,n_radial_points-1 do begin > > loop_time = systime(1) > > if ignore_realdata eq 1. then begin > > r_scld=( i_r*2.)/(n_radial_points -1) ;---------> We took off > trap radius from here for scaling purpose,see note > > ;---------> Also note the use of factor 2. This is because, we > want to get values outside > ;----------> the cylinder. But this is just for demonstration purpose!!!! > > endif else begin > > r_scld=( i_r)/(n_radial_points -1) ; took off the factor 2 > > endelse > ;r_scld = 2. > > ;print,'r_scld value is ',r_scld > > for i_rp= 0,n_radial_points-1 do begin > > if ignore_realdata eq 1. then begin > > rp_mat = randomn(1,n_radial_points,/double) > ;print,'rp_mat is',rp_mat > > rp_scld = rp_mat(i_rp) > > endif else begin > > ;rp_scld…
creator: Conor
date: 2007-11-06T13:13:50-00:00

Re: for loop is killing me
type: item
description: On Nov 6, 1:31 am, tarequea...@gmail.com wrote: > Hello all, > > help me! I am running a code 'infested' with for loops.And as u can > guess, its painfully slow. The part of my code with loop looks like > the following: > > jump1: > > ;Setting up the Green functions array which will have the same number > of elements as of amp_vec > > G=fltarr(n_elements(amp_vec),n_elements(amp_vec)) > G_phi=fltarr(n_elements(amp_vec)) > G_rp=fltarr(n_elements(amp_vec)) > G_r=fltarr(n_elements(amp_vec)) > G_in=fltarr(n_elements(amp_vec)) > G_out=fltarr(n_elements(amp_vec)) > G_p=fltarr(n_elements(amp_vec)) > G_h=fltarr(n_elements(amp_vec)) > gp=fltarr(n_elements(amp_vec)) > gh=fltarr(n_elements(amp_vec)) > G_in_msum = fltarr(n_elements(amp_vec)) > G_out_msum = fltarr(n_elements(amp_vec)) > G_in_phisum = fltarr(n_elements(amp_vec)) > G_out_phisum = fltarr(n_elements(amp_vec)) > > if ignore_realdata eq 1. then begin > amp_vec= abs(randomn(0.5,n_radial_points,/double)) > a=1. > ;print,' amp_vec is',amp_vec > endif > > do_u_like_to_start_with_rp_loop = 0 ; Set 1 if YES,0 if NO > > if do_u_like_to_start_with_rp_loop eq 1. then BEGIN > PRINT,' WE ARE USING rp PREFERED LOOP' > goto,jump2 > > ENDIF > > PRINT,' WE ARE USING r PREFERED LOOP' > for i_r= 0,n_radial_points-1 do begin > > loop_time = systime(1) > > if ignore_realdata eq 1. then begin > > r_scld=( i_r*2.)/(n_radial_points -1) ;---------> We took off > trap radius from here for scaling purpose,see note > > ;---------> Also note the use of factor 2. This is because, we > want to get values outside > ;----------> the cylinder. But this is just for demonstration purpose!!!! > > endif else begin > > r_scld=( i_r)/(n_radial_points -1) ; took off the factor 2 > > endelse > ;r_scld = 2. > > ;print,'r_scld value is ',r_scld > > for i_rp= 0,n_radial_points-1 do begin > > if ignore_realdata eq 1. then begin > > rp_mat = randomn(1,n_radial_points,/double) > ;print,'rp_mat is',rp_mat > > rp_scld = rp_mat(i_rp) > > endif else begin > > ;rp_scld…
creator: Conor
date: 2007-11-06T13:23:45-00:00

Re: for loop is killing me
type: item
description: On Nov 6, 8:13 am, Conor <cmanc...@gmail.com> wrote: > On Nov 6, 1:31 am, tarequea...@gmail.com wrote: > >> Hello all, > >> help me! I am running a code 'infested' with for loops.And as u can >> guess, its painfully slow. The part of my code with loop looks like >> the following: > >> jump1: > >> ;Setting up the Green functions array which will have the same number >> of elements as of amp_vec > >> G=fltarr(n_elements(amp_vec),n_elements(amp_vec)) >> G_phi=fltarr(n_elements(amp_vec)) >> G_rp=fltarr(n_elements(amp_vec)) >> G_r=fltarr(n_elements(amp_vec)) >> G_in=fltarr(n_elements(amp_vec)) >> G_out=fltarr(n_elements(amp_vec)) >> G_p=fltarr(n_elements(amp_vec)) >> G_h=fltarr(n_elements(amp_vec)) >> gp=fltarr(n_elements(amp_vec)) >> gh=fltarr(n_elements(amp_vec)) >> G_in_msum = fltarr(n_elements(amp_vec)) >> G_out_msum = fltarr(n_elements(amp_vec)) >> G_in_phisum = fltarr(n_elements(amp_vec)) >> G_out_phisum = fltarr(n_elements(amp_vec)) > >> if ignore_realdata eq 1. then begin >> amp_vec= abs(randomn(0.5,n_radial_points,/double)) >> a=1. >> ;print,' amp_vec is',amp_vec >> endif > >> do_u_like_to_start_with_rp_loop = 0 ; Set 1 if YES,0 if NO > >> if do_u_like_to_start_with_rp_loop eq 1. then BEGIN >> PRINT,' WE ARE USING rp PREFERED LOOP' >> goto,jump2 > >> ENDIF > >> PRINT,' WE ARE USING r PREFERED LOOP' >> for i_r= 0,n_radial_points-1 do begin > >> loop_time = systime(1) > >> if ignore_realdata eq 1. then begin > >> r_scld=( i_r*2.)/(n_radial_points -1) ;---------> We took off >> trap radius from here for scaling purpose,see note > >> ;---------> Also note the use of factor 2. This is because, we >> want to get values outside >> ;----------> the cylinder. But this is just for demonstration purpose!!!! > >> endif else begin > >> r_scld=( i_r)/(n_radial_points -1) ; took off the factor 2 > >> endelse >> ;r_scld = 2. > >> ;print,'r_scld value is ',r_scld > >> for i_rp= 0,n_radial_points-1 do begin > >> if ignore_realdata eq 1. then begin > >> rp_mat = randomn(1,n_radial…
creator: tarequeaziz
date: 2007-11-06T15:24:45-00:00

Re: for loop is killing me
type: item
description: On Nov 6, 8:23 am, Conor <cmanc...@gmail.com> wrote: > On Nov 6, 1:31 am, tarequea...@gmail.com wrote: > >> Hello all, > >> help me! I am running a code 'infested' with for loops.And as u can >> guess, its painfully slow. The part of my code with loop looks like >> the following: > >> jump1: > >> ;Setting up the Green functions array which will have the same number >> of elements as of amp_vec > >> G=fltarr(n_elements(amp_vec),n_elements(amp_vec)) >> G_phi=fltarr(n_elements(amp_vec)) >> G_rp=fltarr(n_elements(amp_vec)) >> G_r=fltarr(n_elements(amp_vec)) >> G_in=fltarr(n_elements(amp_vec)) >> G_out=fltarr(n_elements(amp_vec)) >> G_p=fltarr(n_elements(amp_vec)) >> G_h=fltarr(n_elements(amp_vec)) >> gp=fltarr(n_elements(amp_vec)) >> gh=fltarr(n_elements(amp_vec)) >> G_in_msum = fltarr(n_elements(amp_vec)) >> G_out_msum = fltarr(n_elements(amp_vec)) >> G_in_phisum = fltarr(n_elements(amp_vec)) >> G_out_phisum = fltarr(n_elements(amp_vec)) > >> if ignore_realdata eq 1. then begin >> amp_vec= abs(randomn(0.5,n_radial_points,/double)) >> a=1. >> ;print,' amp_vec is',amp_vec >> endif > >> do_u_like_to_start_with_rp_loop = 0 ; Set 1 if YES,0 if NO > >> if do_u_like_to_start_with_rp_loop eq 1. then BEGIN >> PRINT,' WE ARE USING rp PREFERED LOOP' >> goto,jump2 > >> ENDIF > >> PRINT,' WE ARE USING r PREFERED LOOP' >> for i_r= 0,n_radial_points-1 do begin > >> loop_time = systime(1) > >> if ignore_realdata eq 1. then begin > >> r_scld=( i_r*2.)/(n_radial_points -1) ;---------> We took off >> trap radius from here for scaling purpose,see note > >> ;---------> Also note the use of factor 2. This is because, we >> want to get values outside >> ;----------> the cylinder. But this is just for demonstration purpose!!!! > >> endif else begin > >> r_scld=( i_r)/(n_radial_points -1) ; took off the factor 2 > >> endelse >> ;r_scld = 2. > >> ;print,'r_scld value is ',r_scld > >> for i_rp= 0,n_radial_points-1 do begin > >> if ignore_realdata eq 1. then begin > >> rp_mat = randomn(1,n_radial…
creator: tarequeaziz
date: 2007-11-06T15:29:07-00:00

Re: for loop is killing me
type: item
description: Also, you might find this website handy: http://www.dfanning.com/tips/rebin_magic.html In general what I've done can be extended into 3 dimensions to eliminate another for loop, but at some point you start to run into issues with filling up your memory with gigantic arrays.
creator: Conor
date: 2007-11-08T15:29:01-00:00