Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dgl
Commits
c577dc9f
Unverified
Commit
c577dc9f
authored
May 28, 2022
by
Quan (Andy) Gan
Committed by
GitHub
May 28, 2022
Browse files
add sanity check (#4050)
parent
7ec165c2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
2 deletions
+35
-2
src/array/cpu/spmat_op_impl_csr.cc
src/array/cpu/spmat_op_impl_csr.cc
+19
-2
tests/compute/test_heterograph.py
tests/compute/test_heterograph.py
+16
-0
No files found.
src/array/cpu/spmat_op_impl_csr.cc
View file @
c577dc9f
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
#include <vector>
#include <vector>
#include <unordered_set>
#include <unordered_set>
#include <numeric>
#include <numeric>
#include <atomic>
#include "array_utils.h"
#include "array_utils.h"
namespace
dgl
{
namespace
dgl
{
...
@@ -380,6 +381,10 @@ CSRMatrix CSRSliceRows(CSRMatrix csr, NDArray rows) {
...
@@ -380,6 +381,10 @@ CSRMatrix CSRSliceRows(CSRMatrix csr, NDArray rows) {
std
::
vector
<
IdType
>
sums
;
std
::
vector
<
IdType
>
sums
;
std
::
atomic_flag
err_flag
=
ATOMIC_FLAG_INIT
;
bool
err
=
false
;
std
::
stringstream
err_msg_stream
;
// Perform two-round parallel prefix sum using OpenMP
// Perform two-round parallel prefix sum using OpenMP
#pragma omp parallel
#pragma omp parallel
{
{
...
@@ -398,8 +403,16 @@ CSRMatrix CSRSliceRows(CSRMatrix csr, NDArray rows) {
...
@@ -398,8 +403,16 @@ CSRMatrix CSRSliceRows(CSRMatrix csr, NDArray rows) {
#pragma omp for schedule(static) nowait
#pragma omp for schedule(static) nowait
for
(
int64_t
i
=
0
;
i
<
len
;
++
i
)
{
for
(
int64_t
i
=
0
;
i
<
len
;
++
i
)
{
int64_t
rid
=
rows_data
[
i
];
int64_t
rid
=
rows_data
[
i
];
sum
+=
indptr_data
[
rid
+
1
]
-
indptr_data
[
rid
];
if
(
rid
>=
csr
.
num_rows
)
{
ret_indptr_data
[
i
+
1
]
=
sum
;
if
(
!
err_flag
.
test_and_set
())
{
err_msg_stream
<<
"expect row ID "
<<
rid
<<
" to be less than number of rows "
<<
csr
.
num_rows
;
err
=
true
;
}
}
else
{
sum
+=
indptr_data
[
rid
+
1
]
-
indptr_data
[
rid
];
ret_indptr_data
[
i
+
1
]
=
sum
;
}
}
}
sums
[
tid
+
1
]
=
sum
;
sums
[
tid
+
1
]
=
sum
;
#pragma omp barrier
#pragma omp barrier
...
@@ -417,6 +430,10 @@ CSRMatrix CSRSliceRows(CSRMatrix csr, NDArray rows) {
...
@@ -417,6 +430,10 @@ CSRMatrix CSRSliceRows(CSRMatrix csr, NDArray rows) {
for
(
int64_t
i
=
0
;
i
<
len
;
++
i
)
for
(
int64_t
i
=
0
;
i
<
len
;
++
i
)
ret_indptr_data
[
i
+
1
]
+=
offset
;
ret_indptr_data
[
i
+
1
]
+=
offset
;
}
}
if
(
err
)
{
LOG
(
FATAL
)
<<
err_msg_stream
.
str
();
return
ret
;
}
// After the prefix sum, the last element of ret_indptr_data holds the
// After the prefix sum, the last element of ret_indptr_data holds the
// sum of all elements
// sum of all elements
...
...
tests/compute/test_heterograph.py
View file @
c577dc9f
...
@@ -427,6 +427,22 @@ def test_empty_query(idtype):
...
@@ -427,6 +427,22 @@ def test_empty_query(idtype):
assert
F
.
shape
(
g
.
in_degrees
([]))
==
(
0
,)
assert
F
.
shape
(
g
.
in_degrees
([]))
==
(
0
,)
assert
F
.
shape
(
g
.
out_degrees
([]))
==
(
0
,)
assert
F
.
shape
(
g
.
out_degrees
([]))
==
(
0
,)
g
=
dgl
.
graph
(([],
[]),
idtype
=
idtype
,
device
=
F
.
ctx
())
error_thrown
=
True
try
:
g
.
in_degrees
([
0
])
fail
=
False
except
:
pass
assert
error_thrown
error_thrown
=
True
try
:
g
.
out_degrees
([
0
])
fail
=
False
except
:
pass
assert
error_thrown
@
unittest
.
skipIf
(
F
.
_default_context_str
==
'gpu'
,
reason
=
"GPU does not have COO impl."
)
@
unittest
.
skipIf
(
F
.
_default_context_str
==
'gpu'
,
reason
=
"GPU does not have COO impl."
)
def
_test_hypersparse
():
def
_test_hypersparse
():
N1
=
1
<<
50
# should crash if allocated a CSR
N1
=
1
<<
50
# should crash if allocated a CSR
...
...
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