Mea culpa! John Randall wrote:
Mikl: I see that with all the timing debate, your question never got answered. My solution on this part was no good: I used ] i: 1:, which gives O(n^2) behavior. Mike Day's solution appears to find the minimum of each box, even though you know it is the first element. Here is a modification which just replicates the first element of each box. pred=:1,}.<}: NB. predicate: use whatever is best fill=:1 : ';(# # {.)&.> (u y) <;.1 y' NB. adverb pred fill d 10 7 5 5 5 1 1 8 2 2 Best wishes, John Mikl Kurkov wrote:I see that several functions that I need have similar pattern: Let x - boolean vector (result of some predicate) and y - vector of some data, where #x = #y then result of function f is f(0) = y(0) f(i) = if x(i) = 1 then y(i) else f(i-1) so I wrote function c1p0 (stands for "copy for 1 previous for 0") c1p0 =: (-~i.@:#) @: ; @: (< @: i. @: # ;. 1)@[ { ] with it if I have predicate function p and data function g I can use it as (p c1p0 g) data it can be used for closest local minimum and maximum too locmin =: (1, }.<}:) c1p0 ] locmax =: (1, }.>}:) c1p0 ] It perform not as well as your suggestions but it can be used for other cases. Now I wonder if it can be improved in terms of time? -- Mikl ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
