LabVIEW Idea Exchange

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

initialize array size input accept array

Status: Declined

Any idea that has received less than 3 kudos within 3 years after posting will be automatically declined.

Hi,

 

A pretty simple request that would help to save some time and diagram space. 

I would like to see initialize array have a size input that also accepts arrays when defining the dimension.

 

updated function.png

I find when working with images or 2d arrays and doing some manipulation I often end up with array size wired into index array wired into intialise array. 

 

currentworkflow.png 

 

Brett

7 Comments
jcarmody
Trusted Enthusiast

snip.png

 

I've seen this before, I think.

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

RavensFan
Knight of NI

I don't think it would be possible to do what you are showing in your first image.

 

The number of dimensions in the initialized array would be determined by the number of elements in the 1-D array going into the array size input.  Because that 1-D array can contain any number of elements during the operation of the VI, only at run-time can the size of the output array be determined.

 

(And what would the output array be if that 1-D array is empty?)

 

However, the number of dimensions of the output array must be determined at compile time.  It can't be a 1-D array this time it runs, and a 4-D array the next time it runs.

 

This conflict of run-time vs. compile time would prevent this idea from being able to be implemented.

fabric
Active Participant

I've also wanted simpler syntax for initialising multi-dimensional arrays, but RavensFan makes a valid point about compile time ambiguity.

 

So what about this alternative:

initarray.png

Manzolli
Active Participant

@jcarmody: If you are sure that there are only numbers in the source array, fine, but it will not work if the source array has NaN, -Inf or Inf.

André Manzolli

Mechanical Engineer
Certified LabVIEW Developer - CLD
LabVIEW Champion
Curitiba - PR - Brazil
AristosQueue (NI)
NI Employee (retired)

Fabric: Accepting a cluster solves the run time issue, but still would require multiple nodes -- the Array Size followed by an Array To Cluster node. You haven't saved anything from Brett's original problem.

 

The only thing that might solve Brett's original problem is an Index Array that produced the individual values instead of an array of values or the promotion of fixed-size array data types (which exist today only on FPGA targets). A fixed-size array is known at edit time (as part of its data type) how many elements it has. Such an array could wire into Initialize without creating ambiguity.

For the record, I *think* the following *should* have the same performance as the Initialize Array. If you just need to compute one array from an existing array, the two For Loops will take care of doing the allocation for the output tunnel once. I know it works for a 1D array... I think it works for a 2D also.

snip.png

This may be a better approach than using Initialize Array anyway since often you do the initialization in order to then go popuplate the array, which you do with a pair of For Loops typically.

Brett_J
Member

Hi all,

 

Thanks for the responses. A bit more detail on the use case: I have a cropped image that I am displaying in a pict control or intensity graph. The cropped image size is generally around 480x480 for example but can vary. I am centreing the cropped image in a full resolution image 512x512 to keep the display consistent.

So I need a couple of images at 512x512. One a mask with some value to highlight the outside of the image. The other just zeros for displaying the cropped image.

 

So why not just use constants for initializing the array? We have the ability to switch image size to 1024 or 2048 so I need to be able to have the corresponding blank images. In my case it is always 2D, but I do understand the issue with run time vs comiple time thanks RavensFan

 

I will do some testing to see which of the ideas suggested by AristosQueue and jcarmody works best for me.

 

Darren
Proven Zealot
Status changed to: Declined

Any idea that has received less than 3 kudos within 3 years after posting will be automatically declined.