From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
ouadji

Search xD Array

Status: New

                         panel.jpg

 

                        NI does not need to worry about the code, I provide it, it's a proposal plug&play  Smiley Happy

 

mensa.jpg

23 Comments
wiebe@CARYA
Knight of NI

Have you benchmarked it? Seems to me Copying\Rebuilding\Reshaping that array could be expensive! Not sure if the reshape can be avoided.

 

The Build Array just so Get Array Size returns an array can be avoided. Simply get the size of the array (returns scalar or 1D array) and concatenate with an empty 1D array (or an array with 1 constant to get the same result).

ouadji
Trusted Enthusiast

"The Build Array just so Get Array Size returns an array can be avoided. Simply get the size of the array (returns scalar or 1D array) and concatenate with an empty 1D array (or an array with 1 constant to get the same result)."

 

well done, very good comment.

wiebe@CARYA
Knight of NI

I'll kudo the idea for some version of this .vim.

 

At some point, some of those .vim's need to be moved to a sub palette (Additional Array Functions, like the string palette)!

AristosQueue (NI)
NI Employee (retired)

Because of the performance problems of Reshape Array, I would advise users against using this function. I definitely would not support shipping it with LabVIEW -- even if it works for some users in small array cases, library functions have to consider their behavior at all scales, and this one fails quickly -- anything with multiple dimensions is tending toward large even for small dimensions (3x3x3... 4x4x4... gets big fast). The data movement would be substantial, and possibly full copies if the input isn't available for modification -- a bad thing in a function that should not be modifying the data.

 

Overall, in my opinion, it would be misleading to put a function into the palettes that looks general purpose but is actually very limited use.

 

Any app that needs a search of an N-dimensional array would be far better served by dropping N-1 For Loops around Search 1D Array. Also, the output could then be a cluster -- generally more useful syntax for multiple indexes.

wiebe@CARYA
Knight of NI

@AQ:

Would you vote for it if it did scale up?

AristosQueue (NI)
NI Employee (retired)

> Would you vote for it if it did scale up?


Yes. But at the moment, the only way I know to write this function efficiently is as a primitive. LabVIEW's VIMs don't allow recursion. There's some fun things we could do if they were recursive, if only we could detect infinite recursion before it killed LabVIEW.

Untitled.png

Detecting "recursion is infinite" runs smack into the Turing halting problem, and even special cases become intractable if you start nesting VIMs. There's probably some things we could do to make many (most?) of the useful cases viable, but we haven't put effort into that at this time. It's on the research backlog.

AristosQueue (NI)
NI Employee (retired)

PS: For anyone looking at my previous post and wondering "What is that weird structure node is that looks like a cross between a case structure and a diagram disable structure with the four colored boxes in the selection ring?" ... that's an unreleased feature of LV 2017 that we were experimenting with that is actually productized in LV 2018 called the Type Specialization structure. You can find it on a couple of 2017 block diagrams. It's execution behavior is stable in 2017 (which is why we could use it in a couple small cases), but it's editor behavior is not and it has some issues with nested VIMs, so play with it at your own risk. It'll all be cleaned up in 2018 if you wait a few months.

ouadji
Trusted Enthusiast

benchmark :

 

Array 4D - 50x51x52x53 = 7027800 elements

"True" is positioned at the location "11x21x31x41" (= 5516711 after reshape 1D)

my "search xD Array" = 7,7/9 ms

 

Array 1D - 7027800 elements

"True" is is positioned at the location 5516711

the native function search 1D Array = 5,3/6 ms

 

AristosQueue (NI)
NI Employee (retired)

ouadji -- that's an array of numerics, I'm guessing. Try an array of non-empty strings (or paths/objects/waveforms/clusters of arrays). I had a similar VI optimization problem recently where the complex types introduced a 1000x performance hit on the reshape vs the direct access.

ouadji
Trusted Enthusiast

" Try an array of non-empty strings "

 

Array 4D of strings, no empty strings, word of 4 letters

4D - 50x51x52x53 = 7027800 strings of 4 letters (random)

"abcd" is positioned at the location "11x21x31x41" (= 5516711 after reshape 1D)

my "search xD Array" = 440 ms

 

Array 1D - 7027800 strings of 4 letters

"abcd" is positioned at the location 5516711 (only "one" "abcd")

the native function search 1D Array = 28 ms

 

440/28 = 15.7

you're right, it's very interesting, I did not realize that.

 

"or paths/objects/waveforms/clusters of arrays"

Sorry, I don't have time to do all this !