def __split_apply(self, func_y_lt_f, func_y_gt_f, func_f_lt_0, y, f):
# Make sure all arrays are of a compatible type
y, f = np.broadcast_arrays(y, f)
y = y.astype(float, copy=False)
f = f.astype(float, copy=False)
if any(y < 0):
raise ValueError("y has to be > 0!")
# get indicators of which likelihoods to apply where
y_lt_f = np.logical_and(y <= f, f > 0)
y_gt_f = np.logical_and(y > f, f > 0)
f_lt_0 = f <= 0
result = np.zeros_like(y)
result[y_lt_f] = func_y_lt_f(y[y_lt_f], f[y_lt_f])
result[y_gt_f] = func_y_gt_f(y[y_gt_f], f[y_gt_f])
result[f_lt_0] = func_f_lt_0(y[f_lt_0], f[f_lt_0])
return result
评论列表
文章目录