robijn Posted June 6, 2007 Report Share Posted June 6, 2007 I've always missed the possibility to use an array of indexes to index a single element of a multi-dim array. Just like having an array with sequential indexes that you just described, this could also be very convenient. It prevents quite a bit of wiring. But these features are conflicting. (although there's a way to have both by having the behaviour selectableby an option and a change in the node appearance.) I think with polymorphism appearing everywhere in LV having a multi-dim index in an array becomes more and more an interesting feature. I'v so far built my own functions to use a 1D array as an N-dim array by converting the indexes to 1D. Talking about indexes, I've always found the Array size node a bit strange. On a 1D array it gives a scalar, but on a multi-dim array an 1D array. This sounds ok, because there are not many reasons to have a 1D array with only one element. But a collection of scalars would be nice too (preventing an index array node). Why does the node not resize to the amount of dims ? Is this line of thought also what you meant, Mike ? Joris Quote Link to comment
gb119 Posted June 6, 2007 Report Share Posted June 6, 2007 QUOTE(Aristos Queue @ Jun 4 2007, 11:46 PM) I think you're thinking of a *while* loop. In a For Loop, since we know at the start how many elements will be needed, the output array can be allocated right away. With a while loop, it gets reallocated on each iteration to grow as needed. Does the while loop actually do the allocation on every iteration ? - I thought I'd read somewhere that it allocates in chunks of increasing size and then deallocates anything left over when the loop finishes. Did I totally dream that ? Is the compiler intelligent enough when looking at a loop to work out if the iterator terminal is unwired to not bother generating code to produce the iterator output, or would that explain why the array operation is faster ? On the original topic, what would be very handy would be if index array and friends took in a cluster of n-numerics to index a n-dimension array. Particularly handy for working with 2D arrays of images if one could wire in 'points' and 'bounds' type clusters to pull out points and subsets. Hmm, maybe my next XNode project Quote Link to comment
Gary Rubin Posted June 6, 2007 Author Report Share Posted June 6, 2007 QUOTE(Aristos Queue @ Jun 4 2007, 02:23 PM) Try putting the random number generation node *outside* the loop and then wire it through the loop tunnel. That should give comperable results to wiring the array directly. Yes, when I do that they run at the same speed, which was what got me confused again about why I thought I remembered reading that there's a performance difference between operations inside loops vs. operating on arrays. I'm beginning to think that I must have missed a distinction between always avoiding operations inside loops vs. avoiding operations inside loops that result in extra memory allocations. Either that or I'm thinking back to LV5-era guidelines that no longer apply. Quote Link to comment
eaolson Posted June 6, 2007 Report Share Posted June 6, 2007 QUOTE(Aristos Queue @ Jun 4 2007, 05:46 PM) I think you're thinking of a *while* loop. In a For Loop, since we know at the start how many elements will be needed, the output array can be allocated right away. With a while loop, it gets reallocated on each iteration to grow as needed. I can't find the example, but I was pretty sure it used a For loop. On the other hand, I may be getting mixed up with the explicit vs. implicit type coercion on this http://www.ni.com/pdf/custed/us/sample_clad_exam.pdf' target="_blank">old sample CLAD exam. Explicitly looping vs. using the array version of an operation does seem to make a difference of about a factor of 2, at least for casting a double to an I32. Wow, for casting from a U32 to an I32 (I thought maybe the change in size of the data was having an effect) getting rid of the For loop had a big effect. 80 ms down to 5 ms. Quote Link to comment
Gary Rubin Posted June 6, 2007 Author Report Share Posted June 6, 2007 QUOTE(eaolson @ Jun 5 2007, 11:18 AM) I can't find the example, but I was pretty sure it used a For loop. I'm glad that you seem to have the same recollection that I do. I'm away from my office right now, but I'll have to look hard for that document when I get back. Quote Link to comment
eaolson Posted June 6, 2007 Report Share Posted June 6, 2007 QUOTE(Gary Rubin @ Jun 5 2007, 11:22 AM) I'm glad that you seem to have the same recollection that I do. I'm away from my office right now, but I'll have to look hard for that document when I get back. The closest I can find is Application Note 168, "LabVIEW Performance and Memory Management," where it says a DBL-to-SGL conversion on an array is done better inside the For loop, rather than outside (page 15). This App Note came with my 7.1 distribution, but I can't find it on the NI website anymore. Quote Link to comment
Gary Rubin Posted June 6, 2007 Author Report Share Posted June 6, 2007 QUOTE(eaolson @ Jun 5 2007, 04:48 PM) The closest I can find is Application Note 168, "LabVIEW Performance and Memory Management," where it says a DBL-to-SGL conversion on an array is done better inside the For loop, rather than outside (page 15). This App Note came with my 7.1 distribution, but I can't find it on the NI website anymore. That sounds familiar. Does it have other examples of operations inside and outside loops? Quote Link to comment
Aristos Queue Posted June 7, 2007 Report Share Posted June 7, 2007 QUOTE(Gavin Burnell @ Jun 5 2007, 07:06 AM) Does the while loop actually do the allocation on every iteration ? - I thought I'd read somewhere that it allocates in chunks of increasing size and then deallocates anything left over when the loop finishes. Did I totally dream that ? Amortized growing vs allocating on every iteration... I don't actually know which one the while loop does... I'd assume its the smarter of the two. But the details weren't really relevant to my point -- it doesn't have oracular abilities, so there's reallocation at some point regularly during the execution of a while loop. Even the smarter of the two algorithms is still less efficient than the For Loop and would account for the recollection of user eaolson. QUOTE Is the compiler intelligent enough when looking at a loop to work out if the iterator terminal is unwired to not bother generating code to produce the iterator output, or would that explain why the array operation is faster ? Yes. QUOTE On the original topic, what would be very handy would be if index array and friends took in a cluster of n-numerics to index a n-dimension array. Particularly handy for working with 2D arrays of images if one could wire in 'points' and 'bounds' type clusters to pull out points and subsets. At first I thought you just wanted the functionality of the "Cluster to Array" primitive. But you're actually talking about being able to index the cluster, not necessarily convert it to an array. An interesting idea. Quote Link to comment
Rolf Kalbermatter Posted June 13, 2007 Report Share Posted June 13, 2007 QUOTE(Aristos Queue @ Jun 4 2007, 05:46 PM) With a while loop, it gets reallocated on each iteration to grow as needed. Actually I think LabVIEW is smarter than that! If I remember correctly LabVIEW is reallocating the output array on While Loops in 2^x steps, meaning it doubles the array size each time it gets to small and resizes it one last time at the end. Otherwise a While Loop with auto-indexing would have little or no advantage over one with a Build Array primitive inside. QUOTE(eaolson @ Jun 5 2007, 03:48 PM) The closest I can find is Application Note 168, "LabVIEW Performance and Memory Management," where it says a DBL-to-SGL conversion on an array is done better inside the For loop, rather than outside (page 15). This App Note came with my 7.1 distribution, but I can't find it on the NI website anymore. This is mainly about memory consumption. The earlier example won't really make any difference here as they both will require a complete buffer for the floating point array and integer array at the same time. But if you have a loop that produces somehow lets say a double precision number (the random generator) and you want to have an integer instead, converting inside the loop will only use 8 bytes + the output integer array while converting it outside will first generate a complete double precision array before converting it to an integer array. This is not so much about execution speed, probably only a little difference, as more about memory consumption. Rolf Kalbermatter Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.