Commit ba92c8ad authored by csongor's avatar csongor

running but not tested for speed

parent 96005917
......@@ -17,6 +17,12 @@ cpdef np.ndarray[np.float64_t, ndim=1] apply_kernel_along_array(np.ndarray[np.fl
# No smoothing requested, just return the input array.
return power[startindex:endindex]
#excluded_power = np.array([])
#if (exclude > 0):
# distances = distances[exclude:]
# excluded_power = np.copy(power[:exclude])
# power = power[exclude:]
if (smooth_length is None) or (smooth_length < 0):
smooth_length = distances[1]-distances[0]
......@@ -26,7 +32,8 @@ cpdef np.ndarray[np.float64_t, ndim=1] apply_kernel_along_array(np.ndarray[np.fl
l = max(i-int(2*smooth_length)-1,0)
u = min(i+int(2*smooth_length)+2,len(p_smooth))
p_smooth[i-startindex] = GaussianKernel(power[l:u], distances[l:u], distances[i], smooth_length)
#if (exclude > 0):
# p_smooth = np.r_[excluded_power,p_smooth]
return p_smooth
def getShape(a):
......@@ -55,7 +62,9 @@ cpdef np.ndarray[np.float64_t, ndim=1] apply_along_axis(np.int_t axis, np.ndarra
cdef np.int_t Ntot = np.product(outshape)
cdef np.ndarray[np.int_t, ndim=1] holdshape = outshape
slicedArr = arr[tuple(i.tolist())]
res = apply_kernel_along_array(slicedArr, startindex, endindex, distances, smooth_length)
print "WHUT"
res = apply_kernel_along_array(slicedArr, startindex, endindex, distances[0], smooth_length)
print "Here", res
outshape = np.asarray(getShape(arr))
outshape[axis] = endindex - startindex
outarr = np.zeros(outshape, dtype=np.float64)
......@@ -71,7 +80,7 @@ cpdef np.ndarray[np.float64_t, ndim=1] apply_along_axis(np.int_t axis, np.ndarra
n -= 1
i.put(indlist, ind)
slicedArr = arr[tuple(i.tolist())]
res = apply_kernel_along_array(slicedArr, startindex, endindex, distances, smooth_length)
res = apply_kernel_along_array(slicedArr, startindex, endindex, distances[k], smooth_length)
outarr[tuple(i.tolist())] = res
k += 1
......
import pyximport; pyximport.install()
import extended
import numpy as np
print "///////////////////////////////////////First thing ////////////////////////"
arr = np.ones(5, dtype=np.float)
arr[2] = 10.0
mk = np.arange(5, dtype=np.float)
mi = 3.0
smooth = 1.0
a = extended.GaussianKernel(arr,mk,mi,smooth)
print a
print "///////////////////////////////////////Second thing ////////////////////////"
n=12
ksq=np.sqrt(np.arange(n), dtype=np.float)
kk=np.arange(n, dtype=np.float)
power = np.ones(n, dtype=np.float)
# power[0][4][4]=1000
# power[1][4][4]=1000
# power[2][4][4]=1000
# power[3][4][4]=1000
power[n/2]=100
# power[5][4][4]=1000
# power[6][4][4]=1000
# power[7][4][4]=1000
k = kk
sigma=k[1]-k[0]
mirrorsize=7
startindex=mirrorsize/2
endindex=n-mirrorsize/2
print power, k, power.shape
smooth = extended.apply_kernel_along_array(power, startindex, endindex, k, sigma)
print smooth
print "///////////////////////////////////////Third thing ////////////////////////"
n=10
ksq=np.sqrt(np.arange(n))
kk=[np.arange(0,1,1.0/n)]*n**2
power = np.ones(n**3).reshape((n,n,n))
# power[0][4][4]=1000
# power[1][4][4]=1000
# power[2][4][4]=1000
# power[3][4][4]=1000
power[n/2][n/2][n/2]=10000
# power[5][4][4]=1000
# power[6][4][4]=1000
# power[7][4][4]=1000
distances = np.asarray(kk,dtype=np.float64)
sigma=k[1]-k[0]
mirrorsize=5
startindex=mirrorsize/2
endindex=n-mirrorsize/2
print k, power, power.shape
# smooth = extended.smooth_something(datablock=power, axis=(2),
# startindex=startindex, endindex=endindex,
# kernelfunction=extended.GaussianKernel, k=k,
# sigma=sigma)
smooth = extended.apply_along_axis(2, power,
startindex, endindex, distances,
sigma)
print "Smoooooth", smooth
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment