BreakPoint

cancel
Showing results for 
Search instead for 
Did you mean: 

Rube Goldberg Code

(seen here)

 

So we have a front panel with six tiny icon images, each with an apparent size of 48x48 pixels. Peanuts, right? Wrong!

 

So why is the VI 3.6+ MB??? Each of the six (identical) images is actually 2448x2048 resized to 48x48 (try right-click...original size). That's a lot of hot air!

 

Actual: 30 megapixels

Effective: 14 kilopixels (2000+ times less!)

 

Message 1841 of 2,571
(12,446 Views)

@altenbach wrote:

@jwscs wrote:

my very own (very small) rube goldberg

 


They are probably about equally good. It is likely that the "transpose" is actually not carried out at all, but the output data flagged internally to index the other way. 


Effectively, yes, but fewer blocks means easier to read code. 🙂

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 1842 of 2,571
(12,360 Views)

(seen here in subVI "modbus responce.vi" (sic))

 

Like the guy behind the deli counter, some users think that thinly slicing a 1D array one element at a time is a good idea. For better inplaceness, i would probably use index array and maybe take the subset at the very end.

 

DeliCounter.png

 

 

 

Also, if we don't wire the size of "delete from array", we get a single element as scalar, so code like seen above is overly complicated.

 

These two code fragments do the same thing!

 

DeleteOneElement.png

Message 1843 of 2,571
(12,356 Views)

If you ever want to see a literal translation of a text based program into "LabVIEW" (quotes are intentional!) ...

 

... have a look at the just posted example program to calculate the LCM (Least Common Multiplier) of an array of integers. Well, it seems to work, but why does it need:

 

  • Four stacked sequences
  • A couple of dozens local variables
  • In fact, except for the two boolean controls show, all other terminals are lined up disconnected in the first outer sequence frame ( bottom picture)
  • Every singe calculation reads from local variables and writes to other local variables.

This looks like an Aztec pyramid!

 

AztecPyramid.png

 

DefineVariables.png

 

I was able to rewrite the entire thing as simple flat code of 20% of the size (and probably 1% of the complexity!) without any local variables and only a single sequence structure (for timing measurement. Try it!)

Message 1844 of 2,571
(12,285 Views)

@altenbach wrote:

 

I was able to rewrite the entire thing as simple flat code ..;.


Posting a quick version here (LV 2013). Several optimizations are still possible, but I intentionally simplified certain things for clarity. There still needs to be verification (the input array cannot be zero) and error handling (if the solution is larger than the valid U64 range) and such. (there could be bugs, of course ;))

 

 

LCMCA.png

 

 

0 Kudos
Message 1845 of 2,571
(12,247 Views)

(seen here)

 

To create an array of four reference some think we need a FOR loop with four iterations, a case structure with four cases, an initialize array, shift register, "replace array subset", five reference (one in duplicate), all combined in a lot of code....

 

Rube Goldberg array of referencesRube Goldberg array of references

 

.... or we could just use "build array". 😄

Message 1846 of 2,571
(12,068 Views)

@altenbach wrote:

(seen here)

 

To create an array of four reference some think we need a FOR loop with four iterations, a case structure with four cases, an initialize array, shift register, "replace array subset", five reference (one in duplicate), all combined in a lot of code....

 

Rube Goldberg array of referencesRube Goldberg array of references

 

.... or we could just use "build array". 😄



I suppose that if we got up to 25 refs on the BD, then this code would be smaller and the compiler would probably compile it out the same so it could save space?

CLD; LabVIEW since 8.0, Currently have LabVIEW 2015 SP1, 2018SP1 & 2020 installed
0 Kudos
Message 1847 of 2,571
(12,022 Views)

@James_W wrote:

@altenbach wrote:

(seen here)

 

To create an array of four reference some think we need a FOR loop with four iterations, a case structure with four cases, an initialize array, shift register, "replace array subset", five reference (one in duplicate), all combined in a lot of code....

 

Rube Goldberg array of referencesRube Goldberg array of references

 

.... or we could just use "build array". 😄



I suppose that if we got up to 25 refs on the BD, then this code would be smaller and the compiler would probably compile it out the same so it could save space?


Even if you want to use a FOR loop, you would just keep the case structure and auto-index at the output tunnel. All that "Initialize array, shift register, and replace array subset, etc". adds significant extra bulk for no reason at all.

 

However, once you have  a case structure with 25 cases, things are not easy to maintain or debug. There is a significant chance of mistakes.

 

As an alternative, you could simply get an array of all controls, autoindex on a FOR loop,  then filter it e.g. based on label using a conditional output tunnel.

0 Kudos
Message 1848 of 2,571
(12,017 Views)

(seen here)

 

So we get 400 bytes of flattened little endian SGL data via UDP. Apparently the impression is that we need a screenfull of loop code with shrinking and growing arrays and such, duplicate local variables, incorrectly initialized shift registers, sequence structures, etc.  ....

 

All we need is code the size of a postage stamp (the ptbypt filter is placed in a subVI here for simplicity)

 

UnflattenFromUDPRube.png

Message 1849 of 2,571
(11,982 Views)

Ah, the classical C to LV with variable declaration and all, the epitome of Localitis and Sequentitis. 🙂

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 1850 of 2,571
(11,866 Views)