eaolson Posted September 27, 2007 Report Share Posted September 27, 2007 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. Quote Link to comment
Kevin P Posted September 27, 2007 Report Share Posted September 27, 2007 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. Quote Link to comment
Grampa_of_Oliva_n_Eden Posted September 27, 2007 Report Share Posted September 27, 2007 QUOTE(Kevin P @ Sep 26 2007, 03:21 PM) ...I'm sure someone will correct me if I'm wrong...-Kevin P. All of my anacdotal observations confirm that theory. Ben Quote Link to comment
eaolson Posted September 27, 2007 Author Report Share Posted September 27, 2007 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}. Quote Link to comment
shoneill Posted September 28, 2007 Report Share Posted September 28, 2007 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. Quote Link to comment
Kevin P Posted September 28, 2007 Report Share Posted September 28, 2007 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. Quote Link to comment
Yair Posted September 28, 2007 Report Share Posted September 28, 2007 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. Quote Link to comment
eaolson Posted September 28, 2007 Author Report Share Posted September 28, 2007 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. Quote Link to comment
Gabi1 Posted September 28, 2007 Report Share Posted September 28, 2007 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 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.