Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ift
NIFTy
Commits
96005917
Commit
96005917
authored
Oct 19, 2016
by
csongor
Browse files
partial but running solution
parent
1e1feb44
Changes
1
Hide whitespace changes
Inline
Side-by-side
nifty/operators/smoothing_operator/Cython/extended.pyx
View file @
96005917
...
...
@@ -17,12 +17,6 @@ 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
]
...
...
@@ -32,39 +26,41 @@ 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
):
return
tuple
(
a
.
shape
)
cpdef
np
.
ndarray
[
np
.
float64_t
,
ndim
=
1
]
apply_along_axis
(
tuple
axis
,
np
.
ndarray
[
np
.
float64_t
]
arr
,
np
.
int_t
startindex
,
np
.
int_t
endindex
,
np
.
ndarray
[
np
.
float64_t
,
ndim
=
1
]
distances
,
np
.
float64_t
smooth_length
):
cdef
tuple
nd
=
arr
.
ndim
cpdef
np
.
ndarray
[
np
.
float64_t
,
ndim
=
1
]
apply_along_axis
(
np
.
int_t
axis
,
np
.
ndarray
arr
,
np
.
int_t
startindex
,
np
.
int_t
endindex
,
np
.
ndarray
distances
,
np
.
float64_t
smooth_length
):
cdef
np
.
int_t
nd
=
arr
.
ndim
if
axis
<
0
:
axis
+=
nd
if
(
axis
>=
nd
):
raise
ValueError
(
"axis must be less than arr.ndim; axis=%d, rank=%d."
%
(
axis
,
nd
))
cdef
np
.
ndarray
[
np
.
int_t
,
ndim
=
1
]
ind
=
np
.
zeros
(
nd
-
1
)
cdef
np
.
ndarray
[
np
.
int_t
,
ndim
=
1
]
i
=
np
.
zeros
(
nd
,
'O'
)
cdef
np
.
ndarray
[
np
.
int_t
,
ndim
=
1
]
ind
=
np
.
zeros
(
nd
-
1
,
dtype
=
np
.
int
)
cdef
np
.
ndarray
i
=
np
.
zeros
(
nd
,
dtype
=
object
)
cdef
tuple
shape
=
getShape
(
arr
)
cdef
np
.
ndarray
[
np
.
int_t
,
ndim
=
1
]
indlist
=
list
(
range
(
nd
))
indlist
.
remove
(
axis
)
cdef
np
.
ndarray
[
np
.
int_t
,
ndim
=
1
]
indlist
=
np
.
asarray
(
range
(
nd
))
indlist
=
np
.
delete
(
indlist
,
axis
)
i
[
axis
]
=
slice
(
None
,
None
)
cdef
np
.
ndarray
[
np
.
int_t
,
ndim
=
1
]
outshape
=
np
.
asarray
(
shape
).
take
(
indlist
)
cdef
np
.
ndarray
[
np
.
int_t
,
ndim
=
1
]
outshape
=
np
.
asarray
(
shape
).
take
(
indlist
)
i
.
put
(
indlist
,
ind
)
cdef
np
.
ndarray
[
np
.
float64_t
,
ndim
=
1
]
slicedArr
=
arr
[
tuple
(
i
.
tolist
())]
cdef
np
.
ndarray
[
np
.
float64_t
,
ndim
=
1
]
res
=
apply_kernel_along_array
(
slicedArr
,
startindex
,
endindex
,
distances
,
smooth_length
)
'''
Ntot = np.product(outshape)
holdshape = outshape
outshape = list(arr.shape)
outshape[axis] = len(res)
outarr = np.zeros(outshape, np.asarray(res).dtype)
cdef
np
.
ndarray
[
np
.
float64_t
,
ndim
=
1
]
slicedArr
cdef
np
.
ndarray
[
np
.
float64_t
,
ndim
=
1
]
res
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
)
outshape
=
np
.
asarray
(
getShape
(
arr
))
outshape
[
axis
]
=
endindex
-
startindex
outarr
=
np
.
zeros
(
outshape
,
dtype
=
np
.
float64
)
outarr
[
tuple
(
i
.
tolist
())]
=
res
k = 1
cdef
np
.
int_t
n
,
k
=
1
while
k
<
Ntot
:
# increment the index
ind
[
-
1
]
+=
1
...
...
@@ -74,9 +70,9 @@ cpdef np.ndarray[np.float64_t, ndim=1] apply_along_axis(tuple axis, np.ndarray[n
ind
[
n
]
=
0
n
-=
1
i
.
put
(
indlist
,
ind
)
res = apply_kernel_along_array(arr[tuple(i.tolist())], startindex=startindex, endindex=endindex, distances=distances, smooth_length=smooth_length)
slicedArr
=
arr
[
tuple
(
i
.
tolist
())]
res
=
apply_kernel_along_array
(
slicedArr
,
startindex
,
endindex
,
distances
,
smooth_length
)
outarr
[
tuple
(
i
.
tolist
())]
=
res
k
+=
1
return
outarr
'''
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment