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

cancel
Showing results for 
Search instead for 
Did you mean: 

All possible permutations (with repetition) of a 1D array given a new array size

Solved!
Go to solution

@altenbach wrote:


Define "better". 🙂 We are dealing with small numbers, so that loop completes in nanoseconds, basically for free. Power of x requires floating point, thus requiring two coercions (first at the function input and later wired to N) and math on twice as many bytes. Seems ugly. 🙂

 

Of course you also need to ensure that the loop output is correct for strange inputs. Mine is correct for 0 to the power of 0 equal 1, for example. Of course it will not work for negative powers or anything that uses or results in fractions, etc.


Better, as in performance while scaling to larger data sets, as I assume was (part of) the purpose of this exercise.  The coercion ugliness I saw right away, but wasn't sure of the cost at a "large" scale, mostly because I have no idea what is going on inside that function.  The inputs would need to be constrained regardless.

 

Not that I have much room for argument since my recursive solution would not exactly be "high performance" code at a large scale.  In my defense, I knew there was an easy way to do it, if not the exact solution.  I just chose recursion for fun.

 

(That's my excuse and I'm sticking to it.):smileyhappy:

0 Kudos
Message 21 of 23
(644 Views)

Even on 64bit LabVIEW, FOR loops are limited to the range of I32, same for array sizes. You get there very quickly with unreasonable inputs. 🙂 You bang into the same limit with the power function, so you need to validate the inputs anyway. 

0 Kudos
Message 22 of 23
(641 Views)

It was really a curiosity on my part.  I know you are very good at finding the simplest solution, so it confused me a bit that you would build a loop to do the calculation when there is an existing function.Smiley Happy

0 Kudos
Message 23 of 23
(636 Views)