Page 1 of 1
nonnull() does not return size of the empty vector UPD: fixed (kinda)
Posted: 04 Apr 2025 20:16
by Endorfinity
Is this expected behaviour or bug?
as it is now, nonnull() won't let you tell empty (all null items) vector from the vector with first (index = 0) non-null item
I have a vector {0,6,7,0,4,1,0,6,6,0}. When counting indexes of non-null items nonnull() function works as expected
but in case of empty vector {0,0,0,0,0,0,0,0,0,0} nonnull() should retrun size of the vector (10) but unfortunately it's not. what's going on here?

Re: nonnull() does not return size of the empty vector
Posted: 05 Apr 2025 06:08
by Phil999
yes that's strange. In the case of zeros, nonnull() does not behave as described in the manual. But I assume that this is an error in the manual, not in Lemur itself. One may find a workaround with firstof().
Re: nonnull() does not return size of the empty vector
Posted: 06 Apr 2025 13:04
by Endorfinity
Phil999 wrote: ↑05 Apr 2025 06:08
yes that's strange. In the case of zeros, nonnull() does not behave as described in the manual. But I assume that this is an error in the manual, not in Lemur itself. One may find a workaround with firstof().
that's great suggestion, thanks!
problem in my case that the output from 3x13 note grid will be essentialy monophonic. I can however break 3 x 13 note grid into 3 seperate note lines, but I'd like to simplify my interface. EDIT bit later: or use
nonnull() together with conditional check of
firstof().
the more I think about it, the more I'm convinced that this is the bug, because by looking at the output you really can't tell if it is [array with all null items] or [array with first non-null item]. this bug in relation to edge cases renders some interface ideas useless.
@midikinetics, what do you think?
Re: nonnull() does not return size of the empty vector
Posted: 06 Apr 2025 15:19
by Endorfinity
ok, here's the fix. in order to get round this bug you have to create expression and use it instead of nonnull()
nonnull_fixed(x) = nonnull(x) + (sizeof(x) * max(0, sign(firstof(x) - sizeof(x))))
which perfectly fits the description of the function
nonnull(array) : returns the positions of non-null items in an array
nonnull({0,1,1,0})={1,2}
note: if the vector only contains null items, the function returns the size of the vector
nonnull({0,0,0}) = 3
Yet I would really prefer if nonnull() functions as expected
