Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
iObs
WP2
Task 2.3
netatmoqc
Commits
d3209a92
Commit
d3209a92
authored
Jul 12, 2021
by
Paulo Medeiros
Browse files
Fix a few warnings
parent
9c7271f1
Changes
2
Hide whitespace changes
Inline
Side-by-side
netatmoqc/hollow_symmetric_matrix.py
View file @
d3209a92
...
...
@@ -164,7 +164,7 @@ def _to_dense(data, n, dtype):
"""
dense
=
np
.
zeros
(
shape
=
(
n
,
n
),
dtype
=
dtype
)
for
idata
in
prange
(
len
(
data
)):
for
idata
in
prange
(
len
(
data
)):
# pylint: disable=not-an-iterable
i
,
j
=
_data_index_to_matrix_index
(
n
,
idata
,
check_bounds
=
False
)
data_value
=
data
[
idata
]
dense
[
i
,
j
]
=
data_value
...
...
@@ -195,7 +195,7 @@ def _to_compact(dense, dtype):
n
=
dense
.
shape
[
0
]
n_indep
=
(
n
**
2
-
n
)
//
2
compact
=
np
.
zeros
(
n_indep
,
dtype
=
dtype
)
for
idata
in
prange
(
len
(
compact
)):
for
idata
in
prange
(
len
(
compact
)):
# pylint: disable=not-an-iterable
i
,
j
=
_data_index_to_matrix_index
(
n
,
idata
,
check_bounds
=
False
)
compact
[
idata
]
=
dense
[
i
,
j
]
return
compact
...
...
@@ -617,7 +617,7 @@ class HollowSymmetricMatrix(np.lib.mixins.NDArrayOperatorsMixin):
"""Return (i, j) such that self.data[data_i] == self[i, j]."""
return
_data_index_to_matrix_index
(
self
.
order
,
data_i
)
def
__array__
(
self
,
dtype
=
None
,
copy
=
False
,
order
=
None
):
def
__array__
(
self
,
*
args
,
**
kwargs
):
# See <https://numpy.org/devdocs/user/basics.dispatch.html>
# TODO: Remove the ".astype(np.float64)" when possible.
# HDBSCAN requires that the result of np.array(self) to have
...
...
@@ -702,9 +702,9 @@ class HollowSymmetricMatrix(np.lib.mixins.NDArrayOperatorsMixin):
def
__setitem__
(
self
,
ij_tuple
,
value
):
try
:
boolean_indexing
=
ij_tuple
.
dtype
==
np
.
bool
boolean_indexing
=
ij_tuple
.
dtype
==
bool
except
AttributeError
:
boolean_indexing
=
np
.
array
(
ij_tuple
).
dtype
==
np
.
bool
boolean_indexing
=
np
.
array
(
ij_tuple
).
dtype
==
bool
if
boolean_indexing
:
if
isinstance
(
ij_tuple
,
type
(
self
)):
...
...
tests/test_hollow_symmetric_matrix.py
View file @
d3209a92
...
...
@@ -28,9 +28,7 @@ def gen_random_hsm(n):
def
gen_random_bool_mask_triu
(
n
):
"""Return a random numpy.triu matrix with dtype numpy.bool."""
return
np
.
triu
(
np
.
random
.
randint
(
n
,
size
=
n
*
n
).
reshape
(
n
,
n
)).
astype
(
np
.
bool
)
return
np
.
triu
(
np
.
random
.
randint
(
n
,
size
=
n
*
n
).
reshape
(
n
,
n
)).
astype
(
bool
)
def
gen_random_bool_mask_tril
(
n
):
...
...
@@ -119,7 +117,7 @@ class TestsSetitem:
# A single diagonal element as (int, int)
lambda
n
:
tuple
(
np
.
repeat
(
np
.
random
.
randint
(
n
),
2
)),
# All diag elements as boolean array
lambda
n
:
np
.
eye
(
n
).
astype
(
np
.
bool
),
lambda
n
:
np
.
eye
(
n
).
astype
(
bool
),
],
)
def
test_setitem_enforces_hollow
(
self
,
random_hsm
,
gen_indices
):
...
...
Write
Preview
Supports
Markdown
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