I am trying to write a cuDF-UDF which computes the pearson auto correlation with lag==1 of a cuDF series.
I have defined the following UDF:
import cupy as cp
def cuda_corr(x):
xx=x[:-1]
yy=x[1:]
coef=cp.corrcoef(xx,y=yy, rowvar=False)
return coef[0,1]
And then taking a series and apply the rolling window to the function.
cdf=cudf.from_pandas(df['ex_col'])
cdf.rolling(window=3, min_periods=3, center=False).apply(cuda_corr)
Then I am facing the error:
LoweringError: Failed in nopython mode pipeline (step: nopython mode backend)
Unknown attribute 'corrcoef' of type Module(<module 'cupy' from '/home/idanre1/miniconda3/envs/rapids-21.10/lib/python3.8/site-packages/cupy/__init__.py'>)
Following pandas code is working:
autocorr_window = 3
lag=1
x=df['ex_col']
acorr=x.rolling(
window=autocorr_window,
min_periods=autocorr_window,
center=False).apply(lambda x: x.autocorr(lag=lag), raw=False)
I am using rapids-21.10 on python 3.8.12