Skip to content

Commit

Permalink
[GraphBolt] Move get_attributes utils. (#7601)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfbalin authored Jul 28, 2024
1 parent 0af92c2 commit 781cc50
Showing 5 changed files with 38 additions and 31 deletions.
8 changes: 6 additions & 2 deletions python/dgl/graphbolt/impl/ondisk_dataset.py
Original file line number Diff line number Diff line change
@@ -19,11 +19,15 @@
calculate_dir_hash,
check_dataset_change,
copy_or_convert_data,
get_attributes,
read_data,
read_edges,
)
from ..internal_utils import download, extract_archive, gb_warning
from ..internal_utils import (
download,
extract_archive,
gb_warning,
get_attributes,
)
from ..itemset import HeteroItemSet, ItemSet
from ..sampling_graph import SamplingGraph
from .fused_csc_sampling_graph import (
2 changes: 1 addition & 1 deletion python/dgl/graphbolt/impl/sampled_subgraph_impl.py
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
import torch

from ..base import CSCFormatBase, etype_str_to_tuple
from ..internal import get_attributes
from ..internal_utils import get_attributes
from ..sampled_subgraph import SampledSubgraph

__all__ = ["SampledSubgraphImpl"]
26 changes: 0 additions & 26 deletions python/dgl/graphbolt/internal/utils.py
Original file line number Diff line number Diff line change
@@ -144,32 +144,6 @@ def copy_or_convert_data(
save_data(data, output_path, output_format)


def get_nonproperty_attributes(_obj) -> list:
"""Get attributes of the class except for the properties."""
attributes = [
attribute
for attribute in dir(_obj)
if not attribute.startswith("__")
and (
not hasattr(type(_obj), attribute)
or not isinstance(getattr(type(_obj), attribute), property)
)
and not callable(getattr(_obj, attribute))
]
return attributes


def get_attributes(_obj) -> list:
"""Get attributes of the class."""
attributes = [
attribute
for attribute in dir(_obj)
if not attribute.startswith("__")
and not callable(getattr(_obj, attribute))
]
return attributes


def read_edges(dataset_dir, edge_fmt, edge_path):
"""Read egde data from numpy or csv."""
assert edge_fmt in [
26 changes: 26 additions & 0 deletions python/dgl/graphbolt/internal_utils.py
Original file line number Diff line number Diff line change
@@ -151,6 +151,32 @@ def recursive_apply_reduce_all(data, fn, *args, **kwargs):
return fn(data, *args, **kwargs)


def get_nonproperty_attributes(_obj) -> list:
"""Get attributes of the class except for the properties."""
attributes = [
attribute
for attribute in dir(_obj)
if not attribute.startswith("__")
and (
not hasattr(type(_obj), attribute)
or not isinstance(getattr(type(_obj), attribute), property)
)
and not callable(getattr(_obj, attribute))
]
return attributes


def get_attributes(_obj) -> list:
"""Get attributes of the class."""
attributes = [
attribute
for attribute in dir(_obj)
if not attribute.startswith("__")
and not callable(getattr(_obj, attribute))
]
return attributes


def download(
url,
path=None,
7 changes: 5 additions & 2 deletions python/dgl/graphbolt/minibatch.py
Original file line number Diff line number Diff line change
@@ -6,8 +6,11 @@
import torch

from .base import CSCFormatBase, etype_str_to_tuple, expand_indptr
from .internal import get_attributes, get_nonproperty_attributes
from .internal_utils import recursive_apply
from .internal_utils import (
get_attributes,
get_nonproperty_attributes,
recursive_apply,
)
from .sampled_subgraph import SampledSubgraph

__all__ = ["MiniBatch"]

0 comments on commit 781cc50

Please sign in to comment.