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
fcf8ce97
Commit
fcf8ce97
authored
Apr 29, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added abs sum function
parent
813e4f76
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
0 deletions
+26
-0
aggregate.pyx
alphamind/aggregate.pyx
+26
-0
No files found.
alphamind/aggregate.pyx
View file @
fcf8ce97
...
...
@@ -10,6 +10,7 @@ from numpy import zeros
from numpy import asarray
cimport cython
from libc.math cimport sqrt
from libc.math cimport fabs
from libc.stdlib cimport calloc
from libc.stdlib cimport free
...
...
@@ -52,6 +53,27 @@ cdef double* agg_sum(long* groups, double* x, size_t length, size_t width) nogil
return res_ptr
@cython.boundscheck(False)
@cython.wraparound(False)
@cython.cdivision(True)
@cython.initializedcheck(False)
cdef double* agg_abssum(long* groups, double* x, size_t length, size_t width) nogil:
cdef long max_g = max_groups(groups, length)
cdef double* res_ptr = <double*>calloc((max_g+1)*width, sizeof(double))
cdef size_t i
cdef size_t j
cdef size_t loop_idx1
cdef size_t loop_idx2
cdef long curr
for i in range(length):
loop_idx1 = i*width
loop_idx2 = groups[i]*width
for j in range(width):
res_ptr[loop_idx2 + j] += fabs(x[loop_idx1 + j])
return res_ptr
@cython.boundscheck(False)
@cython.wraparound(False)
@cython.cdivision(True)
...
...
@@ -144,6 +166,8 @@ cpdef np.ndarray[double, ndim=2] transform(long[:] groups, double[:, :] x, str f
value_data_ptr = agg_std(&groups[0], &x[0, 0], length, width, ddof=1)
elif func == 'sum':
value_data_ptr = agg_sum(&groups[0], &x[0, 0], length, width)
elif func =='abssum':
value_data_ptr = agg_abssum(&groups[0], &x[0, 0], length, width)
with nogil:
for i in range(length):
...
...
@@ -171,6 +195,8 @@ cpdef np.ndarray[double, ndim=2] aggregate(long[:] groups, double[:, :] x, str f
value_data_ptr = agg_std(&groups[0], &x[0, 0], length, width, ddof=1)
elif func == 'sum':
value_data_ptr = agg_sum(&groups[0], &x[0, 0], length, width)
elif func =='abssum':
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)
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