首页 > 解决方案 > 向前填充cupy / cudf

问题描述

应该可以用cupy/cudf执行填充吗?这个想法是执行一个施密特触发器函数,比如:

# 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

任何想法?谢谢!

标签: cupycudf

解决方案


遗憾的是,RAPIDS 目前没有该功能,cudf0.16 也可能没有。github中有功能请求。https://github.com/rapidsai/cudf/issues/1361

希望您能提出要求,以便开发人员知道它的高度需求。

至于施密特触发器,如果​​我有任何进展,我会研究它和你的代码并编辑这篇文章。


推荐阅读