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
1a454a09
Commit
1a454a09
authored
May 01, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove the use of array initialize in groupby
parent
83b11bc0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
12 deletions
+13
-12
aggregate.pyx
alphamind/aggregate.pyx
+1
-1
impl.pyx
alphamind/portfolio/impl.pyx
+7
-5
rankbuilder.py
alphamind/portfolio/rankbuilder.py
+5
-6
No files found.
alphamind/aggregate.pyx
View file @
1a454a09
...
...
@@ -51,7 +51,7 @@ cpdef list groupby(long[:] groups):
deref(it).second.push_back(i)
for v in group_ids.values():
res.append(
array(v, dtype=np.int64)
)
res.append(
v
)
return res
...
...
alphamind/portfolio/impl.pyx
View file @
1a454a09
...
...
@@ -13,20 +13,22 @@ cimport cython
@cython.boundscheck(False)
@cython.wraparound(False)
@cython.initializedcheck(False)
cpdef void set_value_bool(unsigned char[:, :] mat, l
ong long[:, :] index
):
cpdef void set_value_bool(unsigned char[:, :] mat, l
ist index, long long[:, :] used_level
):
cdef size_t length =
index
.shape[0]
cdef size_t width =
index
.shape[1]
cdef size_t length =
used_level
.shape[0]
cdef size_t width =
used_level
.shape[1]
cdef size_t i
cdef size_t j
cdef unsigned char* mat_ptr = &mat[0, 0]
cdef long long*
index_ptr = &index
[0, 0]
cdef long long*
used_level_ptr = &used_level
[0, 0]
cdef size_t k
cdef size_t l
for i in range(length):
k = i * width
for j in range(width):
mat_ptr[index_ptr[k + j] * width + j] = True
l = index[used_level_ptr[k + j]]
mat_ptr[l * width + j] = True
@cython.boundscheck(False)
...
...
alphamind/portfolio/rankbuilder.py
View file @
1a454a09
...
...
@@ -21,15 +21,16 @@ def rank_build(er: np.ndarray, use_rank: int, groups: np.ndarray=None) -> np.nda
weights
=
zeros
((
length
,
1
))
if
groups
is
not
None
:
group_ids
=
groupby
(
groups
)
masks
=
zeros
(
length
,
dtype
=
bool
)
masks
=
zeros
(
(
length
,
1
)
,
dtype
=
bool
)
for
current_index
in
group_ids
:
current_ordering
=
neg_er
[
current_index
]
.
argsort
()
masks
[
current_index
[
current_ordering
[:
use_rank
]]]
=
True
current_ordering
.
shape
=
-
1
,
1
set_value_bool
(
masks
.
view
(
dtype
=
np
.
uint8
),
current_index
,
current_ordering
[:
use_rank
])
weights
[
masks
]
=
1.
else
:
ordering
=
neg_er
.
argsort
()
weights
[
ordering
[:
use_rank
]]
=
1.
return
weights
return
weights
.
reshape
(
er
.
shape
)
else
:
length
=
er
.
shape
[
0
]
width
=
er
.
shape
[
1
]
...
...
@@ -41,9 +42,7 @@ def rank_build(er: np.ndarray, use_rank: int, groups: np.ndarray=None) -> np.nda
masks
=
zeros
((
length
,
width
),
dtype
=
bool
)
for
current_index
in
group_ids
:
current_ordering
=
neg_er
[
current_index
]
.
argsort
(
axis
=
0
)
total_index
=
current_index
[
current_ordering
[:
use_rank
]]
set_value_bool
(
masks
.
view
(
dtype
=
np
.
uint8
),
total_index
)
set_value_bool
(
masks
.
view
(
dtype
=
np
.
uint8
),
current_index
,
current_ordering
[:
use_rank
])
for
j
in
range
(
width
):
weights
[
masks
[:,
j
],
j
]
=
1.
else
:
...
...
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