Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
km3io
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
km3py
km3io
Merge requests
!31
Resolve "Best way to get number of hit DOMs"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "Best way to get number of hit DOMs"
46-best-way-to-get-number-of-hit-doms
into
master
Overview
0
Commits
2
Pipelines
3
Changes
2
Merged
Tamas Gal
requested to merge
46-best-way-to-get-number-of-hit-doms
into
master
4 years ago
Overview
0
Commits
2
Pipelines
3
Changes
2
Expand
Closes
#46 (closed)
Edited
4 years ago
by
Tamas Gal
0
0
Merge request reports
Viewing commit
226b5a21
Prev
Next
Show latest version
2 files
+
105
−
1
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
226b5a21
Add unique and uniquecount
· 226b5a21
Tamas Gal
authored
4 years ago
km3io/tools.py
+
45
−
0
Options
#!/usr/bin/env python3
import
numba
as
nb
import
numpy
as
np
import
uproot
# 110 MB based on the size of the largest basket found so far in km3net
BASKET_CACHE_SIZE
=
110
*
1024
**
2
BASKET_CACHE
=
uproot
.
cache
.
ThreadSafeArrayCache
(
BASKET_CACHE_SIZE
)
@@ -40,3 +43,45 @@ def to_num(value):
except
(
ValueError
,
TypeError
):
pass
return
value
@nb.jit
(
nopython
=
True
)
def
unique
(
array
,
dtype
=
np
.
int64
):
"""
Return the unique elements of an array with a given dtype.
The performance is better for pre-sorted input arrays.
"""
n
=
len
(
array
)
out
=
np
.
empty
(
n
,
dtype
)
last
=
array
[
0
]
entry_idx
=
0
out
[
entry_idx
]
=
last
for
i
in
range
(
1
,
n
):
current
=
array
[
i
]
if
current
==
last
:
# shortcut for sorted arrays
continue
already_present
=
False
for
j
in
range
(
entry_idx
+
1
):
if
current
==
out
[
j
]:
already_present
=
True
break
if
not
already_present
:
entry_idx
+=
1
out
[
entry_idx
]
=
current
last
=
current
return
out
[:
entry_idx
+
1
]
@nb.jit
(
nopython
=
True
)
def
uniquecount
(
array
,
dtype
=
np
.
int64
):
"""
Count the number of unique elements in a jagged Awkward1 array.
"""
n
=
len
(
array
)
out
=
np
.
empty
(
n
,
dtype
)
for
i
in
range
(
n
):
sub_array
=
array
[
i
]
if
len
(
sub_array
)
==
0
:
out
[
i
]
=
0
else
:
out
[
i
]
=
len
(
unique
(
sub_array
))
return
out
Loading