Troubleshooting
nonnull() does not return size of the empty vector UPD: fixed (kinda)
Started by Endorfinity on .
Sign in or create an account to join the conversation.
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
[img]https://i.imgur.com/6n9STIY.png[/img]
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?
[img]https://i.imgur.com/I491DOX.png[/img]
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
[img]https://i.imgur.com/6n9STIY.png[/img]
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?
[img]https://i.imgur.com/I491DOX.png[/img]
Subject: Re: nonnull() does not return size of the empty vector
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().Subject: Re: nonnull() does not return size of the empty vector
that's great suggestion, thanks!Phil999 wrote: 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().
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?
Subject: Re: nonnull() does not return size of the empty vector
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
Yet I would really prefer if nonnull() functions as expectednonnull(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