Skip to content

Commit fd3352b

Browse files
committed
work on kgcnn.io.file
1 parent d299c47 commit fd3352b

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

kgcnn/data/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class MemoryGraphList(list):
2020
r"""Class to store a list of graph dictionaries in memory.
2121
2222
Inherits from a python list. The graph properties are defined by tensor-like (numpy) arrays
23-
for indices, attributes, labels, symbol etc. in :obj:`GraphDict`, which are the items of the list.
23+
for indices, attributes, labels, symbol etc. in :obj:`GraphDict` , which are the items of the list.
2424
Access to items via `[]` indexing operator.
2525
2626
A python list of a single named property can be obtained from each :obj:`GraphDict` in :obj:`MemoryGraphList` via
@@ -68,7 +68,7 @@ def validate(self):
6868
self[i] = GraphDict(x)
6969

7070
def assign_property(self, key: str, value: list):
71-
"""Assign a list of numpy arrays of a property to :obj:`GraphDict` s in this list.
71+
"""Assign a list of numpy arrays of a property to the respective :obj:`GraphDict` s in this list.
7272
7373
Args:
7474
key (str): Name of the property.
@@ -81,7 +81,7 @@ def assign_property(self, key: str, value: list):
8181
# We could also here remove the key from all graphs.
8282
return self
8383
if not isinstance(value, list):
84-
raise TypeError("Expected type 'list' to assign graph properties.")
84+
raise TypeError("Expected type `list` to assign graph properties.")
8585
if len(self) == 0:
8686
self.empty(len(value))
8787
if len(self) != len(value):
@@ -123,7 +123,7 @@ def __getitem__(self, item) -> Union[GraphDict, List]:
123123

124124
def __setitem__(self, key, value):
125125
if not isinstance(value, GraphDict):
126-
raise TypeError("Require a GraphDict as list item.")
126+
raise TypeError("Require a `GraphDict` as list item.")
127127
super(MemoryGraphList, self).__setitem__(key, value)
128128

129129
def __repr__(self):

kgcnn/io/file.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import os.path
2+
13
import numpy as np
24
import h5py
35
from typing import List, Union
46

57

6-
class RaggedArrayNumpyFile:
8+
class RaggedTensorNumpyFile:
79

810
def __init__(self, file_path: str, compressed: bool = False):
911
self.file_path = file_path
@@ -30,7 +32,7 @@ def __getitem__(self, item):
3032
raise NotImplementedError("Not implemented for file reference load.")
3133

3234

33-
class RaggedArrayHDFile:
35+
class RaggedTensorHDFile:
3436

3537
def __init__(self, file_path: str, compressed: bool = None):
3638
self.file_path = file_path
@@ -100,4 +102,13 @@ def append_multiple(self, items: list):
100102
file["row_splits"].shape[0] + new_len, axis=0
101103
)
102104
file["row_splits"][-new_len:] = split_last + new_splits
103-
file["values"][split_last:+split_last+new_splits[-1]] = new_values
105+
file["values"][split_last:+split_last+new_splits[-1]] = new_values
106+
107+
def __len__(self):
108+
with h5py.File(self.file_path, "r") as file:
109+
num_row_splits = file["row_splits"].shape[0]
110+
# length is num_row_splits - 1
111+
return num_row_splits-1
112+
113+
def exists(self):
114+
return os.path.exists(self.file_path)

0 commit comments

Comments
 (0)