LabVIEW Idea Exchange

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

Extend Array Functions to Mirror OpenG

Status: New

I've already made a post on extending File I/O operations so I figured why not make a post on my most commonly used OpenG palette, the array palette.

 

There are so many good nuggets of Array manipulation code in OpenG.  This stuff isn't perfect, and could be optimized, but the convenience of it makes sense especially when you realize there is so many things you can do with arrays.  Lets start with the Index Array, one of the most commonly used functions.

 

index.png

 

Here we see the native function allows for an N dimensional array to be indexed.  The OpenG function only supports 1D and 2D arrays.  And when using a 2D array, the OpenG function must specify both a row and a column, you can't index an entire column or row.  Both of those are very useful features of the native index, but there is something the OpenG function does, that the native doesn't, and that is index multiple indices.  You can pass in an array of indices and pull them all out in the order defined.  This can be used as a reorder function that takes an array and scrambles it the way you like.  Adding this feature is already on the idea exchange.

 

Delete.png

 

Again when it comes to polymorphism the native function beats OpenG.  The native delete supports deleting from N dimensions where OpenG is just 1D or 2D.  But OpenG allows for deleting multiple indices from an array, and if it is a 2D array you can specify if you want to delete rows or columns.  This would be a nice addition to the native function.

 

cond index.png

 

A conditional auto index function doesn't exist natively in LabVIEW.  You can perform a similar function with the conditional auto index tunnel on a for loop but having a single function would be useful.  This idea is on the exchange in multiple places, Link 1, Link 2.

 

Remove filter.png

Ever need to remove duplicates from an array?  Or remove all zeros or NaNs from an array?  These two functions do just that and on the forums all the time are requests for functions like this with no direct replacement on the native palette.  A nice feature of the remove and filter are they output the indices that were removed.  Combined with the fact that the delete, and index accept multiple indices make these very useful.  Also the items to filter for the filter can be a scalar or array which is nice.

 

sort.png

Ever want to sort an array and know how it was sorted?  This OpenG function can do that along with specifying what order, ascending or descending to use.  The OpenG sort also supports 2D arrays where you can specify if you want to sort on rows, or on columns.

12 Comments
Hooovahh
Proven Zealot

Well using OpenG sorting a 2D array on a column, or sorting an array of clusters based on an element would be quite trivial (3 or so functions).  Without OpenG it is of course possible, and actually the native implementation is probably more efficient, but if OpenG array functions were native I'd hope that some optomization could take place.  I mean these VIs were first made in version 5.x or so when inlining, conditional indexing terminals, and other programming techniques weren't available.

 

BTW here is code to perform the two functions you mentioned in OpenG and with native code.

 

Example_VI_BD.png

Hooovahh
Proven Zealot

Since VIMs have become official I took the opportunity to make a new set of Array VIMs that I think covers most of the things we talked about here.  I re-wrote several of the OpenG functions to be more efficient, and to take advantage of newer programming techniques like conditional tunnels.  I also added a few new features like Foreign Key Sort, Forcing Array Size, Finding Sub Arrays and a couple others.  And now that they are VIMs they work with all data types instead of being polymorphic.