Hi Oleg, Sorry for the late answer.
I think this is an excellent suggestion! Since it is a typical "reduce" operation, I suggest having "reduce" in the name. We can imagine having three different versions depending if we start the reduction from the top outputs, the bottom outputs, or in parallel. import("stdfaust.lib"); // parallel reduce: starts reductions in parallel on both halves parReduce(op,1) = si.bus(outputs(op)); parReduce(op,2) = op; parReduce(op,n) = parReduce(op,int(n/2)), parReduce(op,n-int(n/2)) : op; // top reduce, starts reductions from the top outputs topReduce(op,1) = si.bus(outputs(op)); topReduce(op,2) = op; topReduce(op,n) = topReduce(op,n-1), si.bus(inputs(op)-outputs(op)) : op; // bottom reduce: starts reductions from the bottom outputs botReduce(op,1) = si.bus(outputs(op)); botReduce(op,2) = op; botReduce(op,n) = si.bus(inputs(op)-outputs(op)), botReduce(op,n-1) : op; // examples pmax(n) = par(i, n, (i,_)) : parReduce(op,n) with { op(i1,v1,i2,v2) = select2(v2>v1,i1,i2), max(v1,v2); }; tmax(n) = par(i, n, (i,_)) : topReduce(op,n) with { op(i1,v1,i2,v2) = select2(v2>v1,i1,i2), max(v1,v2); }; bmax(n) = par(i, n, (i,_)) : botReduce(op,n) with { op(i1,v1,i2,v2) = select2(v2>v1,i1,i2), max(v1,v2); }; process = pmax(16); Cheers, Yann Le jeu. 25 mai 2023 à 15:04, Oleg Nesterov <o...@redhat.com> a écrit : > Hello, > > I am wondering if it makes any sense to generalize ba.parallelOp, > something like > > parallelOp(op,1) = si.bus(outputs(op)); > parallelOp(op,2) = op; > parallelOp(op,n) = parallelOp(op,n-1), > si.bus(inputs(op)-outputs(op)) : op; > > then we can do > > i_max(n) = par(i,n, (i,_)) : parallelOp(op,n) with { > op(i1,v1,i2,v2) = select2(v2>v1,i1,i2), max(v1,v2); > }; > > for example > > process = 3,2,4,6,2 : i_max(5); > > outputs > > output0[i0] = FAUSTFLOAT(3); // index > output1[i0] = FAUSTFLOAT(6); // maximum > > probably not. > > Oleg. > > On 05/25, Yann Orlarey wrote: > > > > Hi Daz, > > > > You did nothing wrong! I could compile it with the command line compiler, > > but I should have also tested it with the IDE. > > > > Here is a better and faster solution because, instead of a tree of depth > N, > > it creates a more balanced tree of depth log(N): > > > > foo(n) = f(n,n-1) with { > > f(1,c) = c,_; > > f(2,c) = c-1,_,c,_ : major; > > f(n,c) = f(n1,c-n2), f(n2,c) : major with { > > n1 = int(n/2); > > n2 = n-n1; > > }; > > major(c1,v1,c2,v2) = select2(v1>v2, c2, c1), max(v1,v2); > > }; > > > > Cheers > > > > Yann > > > > > > > > Le jeu. 25 mai 2023 à 02:29, Daz Man <dazd...@hotmail.com> a écrit : > > > > > Hi Yann, > > > > > > Easier for some than others... 🙂 But... > > > > > > That code produces errors from "too much recursion" or "stack overflow" > > > when run in the Faust online editor or in FaustLive. Did I perhaps use > it > > > wrongly? > > > > > > I did receive another reply from Bart, pointing to this slightly > different > > > function that I appear to have working, after changing my input and > output > > > formats to suit: > > > > > > > https://github.com/magnetophon/faustExperiments/blob/0d2735bc4900dc4e51da24fb8ee05e49d44eb73c/acor.dsp#L76 > > > > > > Thanks, > > > Daz > > > > > > ------------------------------ > > > *From:* Yann Orlarey <orla...@grame.fr> > > > *Sent:* Thursday, 25 May 2023 8:45 AM > > > *To:* Daz Man <dazd...@hotmail.com> > > > *Subject:* Re: [Faudiostream-users] Find N of greatest input > > > > > > Hi Daz, > > > > > > Such a function is not difficult to write: > > > > > > foo(1) = 0,_; > > > foo(n) = foo(n-1), n-1,_ : major with { > > > major(c1,v1,c2,v2) = ba.if(v1>v2, c1, c2), max(v1,v2); > > > }; > > > > > > Cheers > > > > > > Yann > > > > > > > > > Le mar. 23 mai 2023 à 19:29, Daz Man <dazd...@hotmail.com> a écrit : > > > > > > Hi all, > > > > > > I need a function that compares 257 parallel inputs and returns the > input > > > N with the greatest positive value. (ie: which input has the biggest > > > amplitude) > > > What's the best way to do this? > > > I looked at parallelMax, but it doesn't appear to return which of the N > > > inputs was used for the max. > > > > > > Thanks, > > > Daz > > > _______________________________________________ > > > Faudiostream-users mailing list > > > Faudiostream-users@lists.sourceforge.net > > > https://lists.sourceforge.net/lists/listinfo/faudiostream-users > > > > > > > > > > _______________________________________________ > > Faudiostream-users mailing list > > Faudiostream-users@lists.sourceforge.net > > https://lists.sourceforge.net/lists/listinfo/faudiostream-users > > >
_______________________________________________ Faudiostream-users mailing list Faudiostream-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/faudiostream-users