Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
A
alpha-mind
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dr.李
alpha-mind
Commits
1c62292b
Commit
1c62292b
authored
Apr 29, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed memory leak issue
parent
fcf8ce97
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
4 deletions
+10
-4
aggregate.pyx
alphamind/aggregate.pyx
+10
-4
No files found.
alphamind/aggregate.pyx
View file @
1c62292b
...
@@ -16,11 +16,14 @@ from libc.stdlib cimport free
...
@@ -16,11 +16,14 @@ from libc.stdlib cimport free
np.import_array()
np.import_array()
cdef extern from "numpy/arrayobject.h":
void PyArray_ENABLEFLAGS(np.ndarray arr, int flags)
@cython.boundscheck(False)
@cython.boundscheck(False)
@cython.wraparound(False)
@cython.wraparound(False)
@cython.initializedcheck(False)
@cython.initializedcheck(False)
cdef
int
max_groups(long* groups, size_t length) nogil:
cdef
long
max_groups(long* groups, size_t length) nogil:
cdef long curr_max = 0
cdef long curr_max = 0
cdef size_t i
cdef size_t i
cdef long curr
cdef long curr
...
@@ -151,9 +154,9 @@ cdef double* agg_std(long* groups, double* x, size_t length, size_t width, long
...
@@ -151,9 +154,9 @@ cdef double* agg_std(long* groups, double* x, size_t length, size_t width, long
cpdef np.ndarray[double, ndim=2] transform(long[:] groups, double[:, :] x, str func):
cpdef np.ndarray[double, ndim=2] transform(long[:] groups, double[:, :] x, str func):
cdef size_t length = x.shape[0]
cdef size_t length = x.shape[0]
cdef size_t width = x.shape[1]
cdef size_t width = x.shape[1]
cdef double[:, :] res_data = zeros((length, width))
cdef double* res_data_ptr = <double*>calloc(length*width, sizeof(double))
cdef double* res_data_ptr = &res_data[0, 0]
cdef double* value_data_ptr
cdef double* value_data_ptr
cdef np.ndarray[double, ndim=2] res
cdef size_t i
cdef size_t i
cdef size_t j
cdef size_t j
cdef size_t loop_idx1
cdef size_t loop_idx1
...
@@ -176,7 +179,9 @@ cpdef np.ndarray[double, ndim=2] transform(long[:] groups, double[:, :] x, str f
...
@@ -176,7 +179,9 @@ cpdef np.ndarray[double, ndim=2] transform(long[:] groups, double[:, :] x, str f
for j in range(width):
for j in range(width):
res_data_ptr[loop_idx1 + j] = value_data_ptr[loop_idx2 + j]
res_data_ptr[loop_idx1 + j] = value_data_ptr[loop_idx2 + j]
free(value_data_ptr)
free(value_data_ptr)
return asarray(res_data)
res = np.PyArray_SimpleNewFromData(2, [length, width], np.NPY_FLOAT64, res_data_ptr)
PyArray_ENABLEFLAGS(res, np.NPY_OWNDATA)
return res
@cython.boundscheck(False)
@cython.boundscheck(False)
...
@@ -199,4 +204,5 @@ cpdef np.ndarray[double, ndim=2] aggregate(long[:] groups, double[:, :] x, str f
...
@@ -199,4 +204,5 @@ cpdef np.ndarray[double, ndim=2] aggregate(long[:] groups, double[:, :] x, str f
value_data_ptr = agg_abssum(&groups[0], &x[0, 0], length, width)
value_data_ptr = agg_abssum(&groups[0], &x[0, 0], length, width)
res = np.PyArray_SimpleNewFromData(2, [max_g+1, width], np.NPY_FLOAT64, value_data_ptr)
res = np.PyArray_SimpleNewFromData(2, [max_g+1, width], np.NPY_FLOAT64, value_data_ptr)
PyArray_ENABLEFLAGS(res, np.NPY_OWNDATA)
return res
return res
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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