<div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif">Thanks again. Can you confirm that a range with onset greater than n-1 should be empty, and not a range with just the (n-1) item? I'm building some abstractions with these, and I want range behavior to be consistent with those in the [array] objects.</div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif">Thanks!</div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif">M</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 11, 2015 at 7:50 PM, Miller Puckette <span dir="ltr"><<a href="mailto:msp@ucsd.edu" target="_blank">msp@ucsd.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I think it's correct to output negative infinity as the maximum value of the<br>
empty set, since if A is a subset of B, max(A) <= max(B), so the max of the<br>
empty set should be less than any number.  Hovever, using "1e30" for infinity<br>
is stupid and arbitrary - I do that sort of thing only because it's so<br>
poisonous in a real-time context when actual "inf" values start getting around<br>
the objects...<br>
<br>
The second thing you brought up is a mistake.  OTOH on revisiting this, I<br>
think the empty set should result in an output of (the impossible) -1 so<br>
that it can be easily checked for using select.  Also using "firstitem"<br>
would give a bad result if used on an array of structs with more than one<br>
member - so a but more surgery is needed here...<br>
<br>
more soon, off to a party to welcome the excellent Natacha Diels to our<br>
department :)<br>
<span class="HOEnZb"><font color="#888888"><br>
M<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On Fri, Sep 11, 2015 at 04:14:47PM -0400, Matt Barber wrote:<br>
> Thanks for the fix in 0.46.7. There are a couple more subtle problems<br>
> having to do with bounds checking (one of which may be there by design).<br>
> Bounds checking occurs in the function array_rangeop_getrange() starting<br>
> line 536:<br>
><br>
>     firstitem = x->x_onset;<br>
>     if (firstitem < 0)<br>
>         firstitem = 0;<br>
>     else if (firstitem > a->a_n)<br>
>         firstitem = a->a_n;<br>
>     if (x->x_n < 0)<br>
>         nitem = a->a_n - firstitem;<br>
>     else<br>
>     {<br>
>         nitem = x->x_n;<br>
>         if (nitem + firstitem > a->a_n)<br>
>             nitem = a->a_n - firstitem;<br>
>     }<br>
><br>
><br>
> So unlike tabread which clips indices from 0 to n-1, this clips the onset<br>
> from 0 to n, which means an onset greater than (n-1) gets a range with 0<br>
> items. I think this might be by design, but I wanted to check because a<br>
> range with 0 items does something funny in the min/max array objects.<br>
><br>
> So first off, in these lines (starting line 746):<br>
><br>
>     for (i = 0, besti = 0, bestf= -1e30, itemp = firstitem;<br>
>         i < nitem; i++, itemp += stride)<br>
>             if (*(t_float *)itemp > bestf)<br>
>                 bestf = *(t_float *)itemp, besti = i;<br>
><br>
> If the input range has 0 items (i.e. if nitems is set to zero manually, or<br>
> if the onset is greater than n-1), the for-loop condition i < nitem is<br>
> never true, so the value output is going to be the bestf init value -1e30<br>
> (likewise with +1e30 in the min function). Since this a value that doesn't<br>
> point to anything in the array, I wonder if it would be better not to<br>
> output anything (or maybe a bang) in those cases.<br>
><br>
><br>
> Second, the value x->x_rangeop.x_onset is not bounds checked, so when you<br>
> do this (line 750):<br>
><br>
>     outlet_float(x->x_out2, besti + x->x_rangeop.x_onset);<br>
><br>
><br>
> if x_rangeop.x_onset iss out of range, you're going to output an erroneous<br>
> index value, which could be negative or greater than n. firstitem is<br>
> bounds-checked from the onset by array_rangeop_getrange() -- would it be<br>
> possible to use that instead?<br>
><br>
><br>
> This suite is really a wonderful addition to Pd, and adds so much new<br>
> functionality to vanilla.<br>
> Many cheers!<br>
><br>
> Matt<br>
><br>
><br>
> On Fri, Sep 4, 2015 at 8:11 PM, Miller Puckette <<a href="mailto:msp@ucsd.edu">msp@ucsd.edu</a>> wrote:<br>
><br>
> > Yep :)<br>
> ><br>
> > M<br>
> ><br>
> > On Fri, Sep 04, 2015 at 07:46:30PM -0400, Matt Barber wrote:<br>
> > > Thanks.<br>
> > ><br>
> > > I meant to say that there was the same problem in [array min], but you<br>
> > > probably caught it in your fix.<br>
> > ><br>
> > > Best,<br>
> > ><br>
> > > Matt<br>
> > ><br>
> > > On Fri, Sep 4, 2015 at 7:19 PM, Miller Puckette <<a href="mailto:msp@ucsd.edu">msp@ucsd.edu</a>> wrote:<br>
> > ><br>
> > > > Yep... thanks.  Fixed in git - may take some time for me to get out a<br>
> > new<br>
> > > > compiled version (other stuff to fix too :)<br>
> > > ><br>
> > > > M<br>
> > > ><br>
> > > ><br>
> > > > On Fri, Sep 04, 2015 at 05:51:15PM -0400, Matt Barber wrote:<br>
> > > > > Hi list,<br>
> > > > ><br>
> > > > > I've been playing around with the new(ish) [array] object suite in<br>
> > > > vanilla<br>
> > > > > 0.46.6. Forgive me if this is already a known issue, but it looks<br>
> > like<br>
> > > > the<br>
> > > > > min and max arguments aren't working properly.<br>
> > > > ><br>
> > > > > The second inlet (setting the number of points to search) works as<br>
> > > > > expected. The first inlet doesn't update: it seems to be set to 0 no<br>
> > > > matter<br>
> > > > > what (although the index outlet is updated, but not as expected).<br>
> > > > ><br>
> > > > > I think I see the problem in x_array.c<br>
> > > > ><br>
> > > > > The max object is defined line 723:<br>
> > > > ><br>
> > > > > typedef struct _array_max<br>
> > > > > {<br>
> > > > >     t_array_rangeop x_rangeop;<br>
> > > > >     t_outlet *x_out1;       /* value */<br>
> > > > >     t_outlet *x_out2;       /* index */<br>
> > > > >     int x_onset;            /* search onset */<br>
> > > > > } t_array_max;<br>
> > > > ><br>
> > > > ><br>
> > > > > And the bang and float methods starting 740:<br>
> > > > ><br>
> > > > > static void array_max_bang(t_array_max *x)<br>
> > > > > {<br>
> > > > >     char *itemp, *firstitem;<br>
> > > > >     int stride, nitem, i, besti;<br>
> > > > >     t_float bestf;<br>
> > > > >     if (!array_rangeop_getrange(&x->x_rangeop, &firstitem, &nitem,<br>
> > > > &stride))<br>
> > > > >         return;<br>
> > > > >     for (i = 0, besti = 0, bestf= -1e30, itemp = firstitem;<br>
> > > > >         i < nitem; i++, itemp += stride)<br>
> > > > >             if (*(t_float *)itemp > bestf)<br>
> > > > >                 bestf = *(t_float *)itemp, besti = i;<br>
> > > > >     outlet_float(x->x_out2, besti+x->x_onset);<br>
> > > > >     outlet_float(x->x_out1, bestf);<br>
> > > > > }<br>
> > > > ><br>
> > > > > static void array_max_float(t_array_max *x, t_floatarg f)<br>
> > > > > {<br>
> > > > >     x->x_onset = f;<br>
> > > > >     array_max_bang(x);<br>
> > > > > }<br>
> > > > ><br>
> > > > ><br>
> > > > > In the float method it looks like the onset is never actually<br>
> > assigned in<br>
> > > > > the x_rangeop member of the t_array_max struct, so<br>
> > array_rangeop_getrange<br>
> > > > > can't set the firstitem pointer to anything but its init value.<br>
> > > > ><br>
> > > > ><br>
> > > > > Thanks,<br>
> > > > ><br>
> > > > > Matt<br>
> > > ><br>
> > > > > _______________________________________________<br>
> > > > > <a href="mailto:Pd-list@lists.iem.at">Pd-list@lists.iem.at</a> mailing list<br>
> > > > > UNSUBSCRIBE and account-management -><br>
> > > > <a href="http://lists.puredata.info/listinfo/pd-list" rel="noreferrer" target="_blank">http://lists.puredata.info/listinfo/pd-list</a><br>
> > > ><br>
> > > ><br>
> ><br>
> > > _______________________________________________<br>
> > > <a href="mailto:Pd-list@lists.iem.at">Pd-list@lists.iem.at</a> mailing list<br>
> > > UNSUBSCRIBE and account-management -><br>
> > <a href="http://lists.puredata.info/listinfo/pd-list" rel="noreferrer" target="_blank">http://lists.puredata.info/listinfo/pd-list</a><br>
> ><br>
> ><br>
</div></div></blockquote></div><br></div>