LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Array Split / Replace Subarrays

maxnoder1995_0-1741943551511.png

I have a two-dimensional array.

  • At the top, I want to replace the values in the eleventh column with the lowercase version of the corresponding values from the fifth column.
  • At the bottom, I want to replace the values in the eleventh column with the lowercase version of the corresponding values from the fifth column, but only if the value in the fifth column is 'A'.

I understand that using Array Split / Replace Subarrays is recommended for this task. My questions are:

  1. Am I using these functions correctly?
  2. Is there a better or alternative approach to achieve this?

Thanks in advance!

0 Kudos
Message 1 of 12
(328 Views)

Hi Max,

 


@maxnoder1995 wrote:
  • At the top, I want to replace the values in the eleventh column with the lowercase version of the corresponding values from the fifth column.
  • At the bottom, I want to replace the values in the eleventh column with the lowercase version of the corresponding values from the fifth column, but only if the value in the fifth column is 'A'.

  • I would use a pair of IndexArray/ReplaceArraySubset when I need to handle just one specific column. (like your "lower" code versions)
  • In the "bottom" task either your task description or your implementation is wrong:
    replace the values in the eleventh column with the lowercase version of the corresponding values from the fifth column, but only if the value in the fifth column is 'A'.
    When I read the description it seems you only want to transfer lowercase "a" from 5th to 11th column…
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 12
(296 Views)

Thank you for your feedback!

 

IPE modifies the array directly in memory, it avoids unnecessary data copies and improves efficiency, especially for large datasets.

What do you think about using IPE for this situation? Would it be a better choice than your suggested method?



Regarding my "bottom" task, I see where the confusion comes from. My intent is:

  • If the value in the fifth column is 'A', then the corresponding value in the eleventh column should be replaced with its lowercase version ('a').
  • Other values in the eleventh column should remain unchanged.

Given this requirement, what do you think is the best way to implement it efficiently?

0 Kudos
Message 3 of 12
(273 Views)

Hi Max,

 


@maxnoder1995 wrote:

Given this requirement, what do you think is the best way to implement it efficiently?


Please define "efficiently": execution speed, memory consumption, code size, code readability, …

(Usually you cannot get them all together.)

 

What is your typical array size?

Do your array elements contain just a single char or larger strings?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 12
(271 Views)

By "efficiently," I primarily mean execution speed and memory consumption, as I want to avoid unnecessary copies of the array. Code readability is also important, but performance is my main concern.

My typical array size is 10,000 × 12 (10,000 rows, 12 columns).
Each element contains a single character.


0 Kudos
Message 5 of 12
(264 Views)

Hi Max,

 


@maxnoder1995 wrote:

My typical array size is 10,000 × 12 (10,000 rows, 12 columns).
Each element contains a single character.


So your data are 120000 chars, kept in a 2D array of strings of one char each!?

 

To make it more efficient you might keep your data in a 1D array of U8…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 12
(260 Views)

I understand your point about optimizing data storage, but my question is not about how to store the data more efficiently. The array size I mentioned was just an example to illustrate a large dataset.

My main question is about the use of Array Split / Replace Subarrays inside the In-Place Element Structure (IPE). Based on the image I shared, do you think this is the correct way to implement what I described? Or is there a better way to achieve this using IPE?

0 Kudos
Message 7 of 12
(255 Views)

I think that for a modern PC, 10,000 rows is nothing; it will take just a few milliseconds to execute. You could potentially make it faster in theory if you wrapped this code into a C DLL (perhaps twice as fast), but you would introduce additional dependencies. Additionally, you could perform parallel processing with the help of a parallel for loop, but this would not make it much faster because there isn't much computation involved here. My recommendation is: don't worry too much, do it as most convenient for you. Or do you have very strict timing requirements and here is the bottleneck?

0 Kudos
Message 8 of 12
(250 Views)

Hi Max,

 


@maxnoder1995 wrote:

My main question is about the use of Array Split / Replace Subarrays inside the In-Place Element Structure (IPE). Based on the image I shared, do you think this is the correct way to implement what I described? Or is there a better way to achieve this using IPE?


The compiler most often is smart enough to handle pairs of IndexArray/ReplaceArraySubset nicely. Using the IPE most often makes no difference…

 


@maxnoder1995 wrote:

I understand your point about optimizing data storage, but my question is not about how to store the data more efficiently. The array size I mentioned was just an example to illustrate a large dataset.


It's not about data storage alone!

  • LabVIEW handles 1D arrays more efficiently than 2D (or higher dimension) arrays.
  • As long as your strings all contain only one char you can easily switch over to U8 arrays.
  • Numeric comparisons/operations tend to be faster than string operations.
  • A string is a pointer to a memory block (of string size & string content) in LabVIEW, so your 2D array is a large collection of pointers to strings which uses way more memory than just 120000 bytes. A 1D array of U8 is just one block of memory…

So when it comes to "efficiency of code execution" it often helps to (re-)organize the data to allow more efficient data handling!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 12
(242 Views)

Just one more thing — if you can reorganize the data to 12x10000 (12 rows, 10000 columns), then read/replacing characters in one row instead of a column will be definitely faster, because you will not get massive cache misses on access to the chars.

Message 10 of 12
(235 Views)