是否可以使用cupy/cudf执行一次向前填充?这个想法是执行一个schimitt触发器函数,类似于:
# 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)我正在尝试这个,但是cupy没有积累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有什么想法吗?谢谢!
发布于 2020-10-06 06:57:59
遗憾的是,急流目前在cudf中没有这个功能,在0.16版本中也可能没有。在github中有对它的功能请求。https://github.com/rapidsai/cudf/issues/1361
我希望你能加入这个请求,这样开发人员就可以知道它的高度期望。
至于施密特触发器,我会研究它和你的代码,如果有任何进展,我会编辑这篇文章。
https://stackoverflow.com/questions/64197834
复制相似问题