Here're some snippet of code.
def rbf(r):
rsq = r ** 2.0
if rsq == 0.0:
return 0.0
val = rsq * np.log(rsq)
if np.isnan(val):
return 0.0
return val
for i in range(449):
for j, row in enumerate(p):
res[j] += w[i] * rbf(r=np.linalg.norm(p[i] - row))
return res
Here p represents an array with shape (4448^2, 3), res represents an array with shape (4448^2, ). This process of in-place addition cosumes too much time. I tried another way as following.
def rbf(r):
rsq = r ** 2.0
if rsq == 0.0:
return 0.0
val = rsq * np.log(rsq)
if np.isnan(val):
return 0.0
return val
def func(elem, row):
summand = sum([w[j]
* rbf(r=np.linalg.norm(p[j] - row))
for j in range(449)])
return summand + elem
dst_res = np.array([func(elem=elem, row=row)
for elem, row in zip(res, p)])
return dst_res
But I still failed to see any progress. Any advice for improving performance ?
w? Can you express this as a pure function with inputs (w,p?) and outputs? Why449? What does that have to do with4448^2? Please provide a proper MCVE that can be run in the terminal with no additional typing.