Fill Forward cupy / cudf

173 views Asked by At

should be possible execute a fill forward with cupy/cudf? the idea is execute a schimitt trigger function, something like:

# pandas version
df = some_random_vector
on_off = (df>.3)*1 + (df<.3)*-1
on_off[on_off==0) = np.nan
on_off = on_off.fillna(method='ffill').fillna(0)

i was trying this one but cupy don't have accumulate ufunc:

def schmitt_trigger(x, th_lo, th_hi, initial = False):
    on_off = ((x >= th_hi)*1 + (x <= th_lo)*-1).astype(cp.int8)
    mask = (on_off==0)
    idx = cp.where(~mask, cp.arange(start=0, stop=mask.shape[0], step=1), 0)
    cp.maximum.accumulate(idx,axis=1, out=idx)
    out = on_off[cp.arange(idx.shape[0])[:,None], idx]
    return out

any idea? thanks!

1

There are 1 answers

0
TaureanDyerNV On

Sadly, RAPIDS currently doesn't have that feature in cudf and may not for 0.16 either. There is the feature request in github for it. https://github.com/rapidsai/cudf/issues/1361

Would love for you to chime in on the request so that the devs can know its highly desired.

As for the Schmitt Trigger, I'll look into it and your code and edit this post if I get any progress.