Jump to content
Sign in to follow this  
eaolson

Auto-indexing tunnel that appends rather than builds an array

Recommended Posts

The addition of auto-indexing to While and For loops was great. Sometimes, however, I have multiple nested loops and auto-indexing makes a 2D or 3D array, which is not necessarily what I want. It would be nice to have an auto-indexing tunnel that has a "auto-append" option rather than only the default "build array" behavior. Much like how the Build Array function has the "Concatinate Inputs" option. I guess this really makes the most sense for 1D arrays.

Share this post


Link to post
Share on other sites

In the meantime, there's a fairly efficient workaround. You can use "Reshape Array" to morph the 2D back into 1D. If I'm not mistaken, this can be done without additional data copying. The values are already stored in contiguous memory in the desired concatenation-like order. As I understand it, a Reshape just transfers ownership of that memory chunk over to the (1D) output array wire.

I'm sure someone will correct me if I'm wrong...

-Kevin P.

Share this post


Link to post
Share on other sites

QUOTE(Kevin P @ Sep 26 2007, 02:21 PM)

In the meantime, there's a fairly efficient workaround. You can use "Reshape Array" to morph the 2D back into 1D. If I'm not mistaken, this can be done without additional data copying. The values are already stored in contiguous memory in the desired concatenation-like order. As I understand it, a Reshape just transfers ownership of that memory chunk over to the (1D) output array wire.

Yes, that works, but only if the loop adds the same number of elements each time. It wouldn't work for this (pardon for not doing this in LV):

array a = {}; for (i = 1; i <= 3; i++) {	for (j = 1; j <= i; j++) {	   append j to a;	} }

This creates the array, a = {1, 1, 2, 1, 2, 3}.

Share this post


Link to post
Share on other sites

QUOTE(eaolson @ Sep 26 2007, 09:40 PM)

Yes, that works, but only if the loop adds the same number of elements each time. It wouldn't work for this (pardon for not doing this in LV):

array a = {};  for (i = 1; i <= 3; i++) {	 for (j = 1; j <= i; j++) {		append j to a;	 }  }

This creates the array, a = {1, 1, 2, 1, 2, 3}.

Aaargh, there's some strange enscriptions there. I know they mean something...... Just... Can't... Figure... it.... out.....

Seriously, it's certainly a difference if the size of each iteration is different...... Good catch.

Shane.

Share this post


Link to post
Share on other sites

Ok, I see your point. You'd want to do this with While loops as well. I didn't think of those -- I try to avoid auto-indexed outputs on While loops whenever practical. I'm not using 8.5 but I suppose the new For-Loop-With-Break would present a similar situation.

Your suggestion is the more universal approach. Good idea!

-Kevin P.

Share this post


Link to post
Share on other sites

Good idea. You should probably submit it through the product suggestion center.

If I remember correctly, someone posted an Xnode which does this, but you can also create a simple LV2 global to do this - input the array and a boolean reset input and just build the array inside the subVI. Not as efficient memory-wise, but makes the diagram cleaner.

Share this post


Link to post
Share on other sites

QUOTE(yen @ Sep 27 2007, 01:07 PM)

Good idea. You should probably submit it through the product suggestion center.

I've already done so. :) In fact, I included a link to this thread.

Share this post


Link to post
Share on other sites

QUOTE(yen @ Sep 27 2007, 08:07 PM)

you can also create a simple LV2 global to do this .

yep. thats the way i do it, when i get too many shift registers...it looks always a little mistical too :)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.