03-09-2020 11:14 AM
Hi guys,
I would like to do this operation with the elements in my 1D array.
Given array:
a
b
c
d
what i would obtain in a new array:
a
a+b
a+b+c
a+b+c+d
could you show me how to do?
03-09-2020 11:22 AM
I would something like this:
03-09-2020 11:27 AM
03-09-2020 12:05 PM
I use this, but save it as a VIM. (Note it will not catch overflow errors for integer types).
mcduff
03-09-2020 01:56 PM - edited 03-09-2020 02:02 PM
Well, since the question is a bit vague, here's an alternative interpretation 😄
(... and yes I know there are much more efficient ways ...;)
(well, the subject says "sum", but who knows? ;))
03-09-2020 03:32 PM
03-09-2020 04:06 PM
Here's a method that operates completely in-place, which can be turned into a VIM also.
@terickson wrote:
Neat implementation, but slow for big arrays.
mcduff
03-09-2020 06:43 PM
@mcduff wrote:
Here's a method that operates completely in-place, which can be turned into a VIM also.
Don't underestimate the compiler. Mine (above) has the same number of array buffer allocations. 😉
If you really want to use the IPE, I think having an extra scalar (below) probably compensates for your operating on two array elements with each iteration. Of course you have one fewer iterations, which could make a difference for extremely small arrays.
Not tested, just guessing of course. 😄
03-09-2020 07:26 PM
@altenbach wrote:
Don't underestimate the compiler. Mine (above) has the same number of array buffer allocations. 😉
+1. This is why I said the VI operates totally in-place. The screen shots below are LabVIEW 2019, using the "Profile Buffer Allocations Tool"
Profile Tool only records 1 buffer
Using the VI from the earlier post, which is a bit faster, I see this
Profile Tool records two buffers
It's possible the first buffer in the second screen shot is erased immediately after execution; this is @rolfk territory, so in effect 1 buffer. But at least according to NI's tools, there are 2 buffer allocations.
@altenbach wrote:
If you really want to use the IPE, I think having an extra scalar (below) probably compensates for your operating on two array elements with each iteration. Of course you have one fewer iterations, which could make a difference for extremely small arrays.
Not tested, just guessing of course. 😄
Besides complex numbers I thought you liked to do things in parallel. 🙂
mcduff
03-10-2020 10:07 AM