nonnull() does not return size of the empty vector UPD: fixed (kinda)

Discuss problems and solutions.
Post Reply
Endorfinity
Newbie
Posts: 13
Joined: 26 Feb 2025 17:15
Location: Moskva

nonnull() does not return size of the empty vector UPD: fixed (kinda)

Post 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

Image

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?

Image
Attachments
nonnull.jzml
(1.34 KiB) Downloaded 10 times
Last edited by Endorfinity on 09 Apr 2025 19:04, edited 3 times in total.
Phil999
Regular
Posts: 944
Joined: 11 Jan 2012 01:53

Re: nonnull() does not return size of the empty vector

Post 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().
Formant+Eurorack, PPG wave 2.2, Korg MS-20, etc., EWI 4000s, QuNeo, etc., Mixbus32c, u-he, MadronaLabs, Samplemodeling, NI, etc., iPad2/4/Pro
Endorfinity
Newbie
Posts: 13
Joined: 26 Feb 2025 17:15
Location: Moskva

Re: nonnull() does not return size of the empty vector

Post 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?
Last edited by Endorfinity on 06 Apr 2025 16:23, edited 3 times in total.
Endorfinity
Newbie
Posts: 13
Joined: 26 Feb 2025 17:15
Location: Moskva

Re: nonnull() does not return size of the empty vector

Post 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 :D
Attachments
nonnull_fix.jzml
(3.95 KiB) Downloaded 13 times
Post Reply