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

Home » Public Forums » archive » Re: Best way to generate arrays of coordinates for hypersurface calculations?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Best way to generate arrays of coordinates for hypersurface calculations? [message #70403] Thu, 08 April 2010 04:01
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
> I'd like to add a few more features: mainly, the ability to make
> floating point arrays with a range that is smaller than the number of
> elements, like a 100x100x100 unit cube for instance.  I think this
> would make the function quite a bit more complicated, but also a lot
> more complete.  I'm also still uneasy about calculating functions this
> way.  It seems like a huge waste of memory, but I can't think of any
> other way to do it without using many loops!
>
> James Preiss

In these cases, on occasion the loops win out. In particular, if the
volume is smaller along one dimension, it might pay to loop over that
dimension (and vectorize the other dimensions as you're doing).
Depends how much memory is actually required - as long as you're
within the physical memory of the machine, the vectorized approach
will win out, but once you get beyond that it may be worth adding a
loop. If you wanted to be clever, you could have your function
evaluation code check to see how much memory would be required to
create the index array and decide what method to use based on that -
but I'd run some timing tests first to make sure that you know where
the crossover is.

-Jeremy.
Re: Best way to generate arrays of coordinates for hypersurface calculations? [message #70405 is a reply to message #70403] Wed, 07 April 2010 16:20 Go to previous message
James[2] is currently offline  James[2]
Messages: 44
Registered: November 2009
Member
I've been working with this problem some more, and I found some
dimensional juggling info on David Fanning's website that helped me
make these arrays in a more straightforward, and flexible, way. I
just create a one-dimensional vector for each axis and pad it out with
a bunch of empty dimensions using REFORM. Then, I can stretch out the
1D vector using REBIN to occupy the entire multidimensional space.

I wrote a program to make these coordinate arrays, which I've posted
here: http://pastebin.com/KVew8M0g . This program includes error
checking on the max/min arguments and type argument. The "meat" is
actually quite brief, however:

function coordinates, mins, maxes, type
...error checking...

sizes = maxes - mins + 1
out = ptrarr(dims)

for i=0, dims[0]-1 do begin
;make a 1D vector containing the indices for this dimension
out[i] = ptr_new(make_array(sizes[i], /index, type=type))
;shift index vector it contains values from min to max,
inclusive
*out[i] +=+ mins[i]
;make a vector to feed into reform for dimensional juggling
rvec = replicate(1,i+1)
;place the index vector into the proper dimension
rvec[i] = sizes[i]
;replicate the index vector across all dimensions
*out[i] = rebin(reform(*out[i], rvec), sizes)
endfor
return, out
end

I'd like to add a few more features: mainly, the ability to make
floating point arrays with a range that is smaller than the number of
elements, like a 100x100x100 unit cube for instance. I think this
would make the function quite a bit more complicated, but also a lot
more complete. I'm also still uneasy about calculating functions this
way. It seems like a huge waste of memory, but I can't think of any
other way to do it without using many loops!

James Preiss
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Is there a way to plot with axis breaks in IDL?
Next Topic: Vectorized versions of MAP_2POINTS and LL_ARC_DISTANCE

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

Current Time: Wed Oct 08 11:43:55 PDT 2025

Total time taken to generate the page: 0.00393 seconds