comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: adding sparse arrays
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: adding sparse arrays [message #54435 is a reply to message #54295] Fri, 08 June 2007 00:42 Go to previous message
Paolo Grigis is currently offline  Paolo Grigis
Messages: 171
Registered: December 2003
Senior Member
nivedita.raghunath@gmail.com wrote:
> [...]
> I just typed out a long reply, and it didn't post it to the board...
> so trying again.
>
> Here is a piece of my code:
>
> ; img- 3d image, tmat- set of transformation matrices
>
> sz=size(img,/dimensions)
> tmat_sz=size(tmat,/dimensions)
> sz1=sz[0]*sz[1]
> npix=sz1*sz[2]
>
> stan_pts=transpose([[lindgen(npix) mod sz[0]],[lindgen(npix)/sz[0] mod
> sz[1]],[lindgen(npix)/sz1], [replicate(1l,npix)]])
> stan_indx=long(stan_pts[0,*]+stan_pts[1,*]*sz[0]+stan_pts[2, *]*sz1)
>
> img_est=fltarr(sz[0],sz[1],sz[2])
>
> for j=0,tmat_sz[2]=1 do begin
> mat=tmat[*,*,j]
> rp=mat#stan_pts
> res_indx=round(rp[0,*])+round(rp[1,*])*sz[0]+round(rp[2,*])* sz1
> valid_indx=where(res_indx ge 0 and res_indx lt npix)
>
>
> tij=sprsin(stan_indx[valid_indx],res_indx[valid_indx],replic ate(1.,n_elements(valid_indx)),npix)
>
> /*THIS IS WHAT I WANT TO DO BUT CANNOT DO*/

Why don't you keep track of the indices you are using (stan_indx, res_indx) in each
iteration? In the next iteration you can compare the new row & column indices with
the old ones: if they are different, add the new indices & values to the old list,
if they are equal, add the new value to the corresponding old value.

You can then use sprsin only once at the end.

Ciao,
Paolo


>
> tijsum = tijsum+tij
>
> endfor
>
> So basically I want to add the tij matrices for all transformations
> tmat[*,*,j]. But I cannot do tijsum = tijsum+tij for the foll.
> reasons:
>
> - Can't initialize tijsum since I don't know the size (size varies
> with each iteration). Besides, initializing w/ create_struct doesn't
> seem to work (I think a sparse array structure created using sprsin is
> different from a structure created using create_struct)
>
> - tijsum+tij doesn't work since structures can't be directly added.
>
> I would like to avoid loops since my arrays are really huge. ANy
> ideas?
>
>
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Executable files
Next Topic: scaling idlGrAxis ticks?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Thu Oct 09 23:08:08 PDT 2025

Total time taken to generate the page: 0.00184 seconds