MCPcopy
hub / github.com/dmlc/dgl / save_tensors

Function save_tensors

python/dgl/data/tensor_serialize.py:13–43  ·  view source on GitHub ↗

Save dict of tensors to file Parameters ---------- filename : str File name to store dict of tensors. tensor_dict: dict of dgl NDArray or backend tensor Python dict using string as key and tensor as value Returns ---------- status : bool Ret

(filename, tensor_dict)

Source from the content-addressed store, hash-verified

11
12
13def save_tensors(filename, tensor_dict):
14 """
15 Save dict of tensors to file
16
17 Parameters
18 ----------
19 filename : str
20 File name to store dict of tensors.
21 tensor_dict: dict of dgl NDArray or backend tensor
22 Python dict using string as key and tensor as value
23
24 Returns
25 ----------
26 status : bool
27 Return whether save operation succeeds
28 """
29 nd_dict = {}
30 is_empty_dict = len(tensor_dict) == 0
31 for key, value in tensor_dict.items():
32 if not isinstance(key, str):
33 raise Exception("Dict key has to be str")
34 if F.is_tensor(value):
35 nd_dict[key] = F.zerocopy_to_dgl_ndarray(value)
36 elif isinstance(value, NDArray):
37 nd_dict[key] = value
38 else:
39 raise Exception(
40 "Dict value has to be backend tensor or dgl ndarray"
41 )
42
43 return _CAPI_SaveNDArrayDict(filename, nd_dict, is_empty_dict)
44
45
46def load_tensors(filename, return_dgl_ndarray=False):

Callers 5

partition_graphFunction · 0.85
saveFunction · 0.85
libra_partitionFunction · 0.85
test_serialize_tensorsFunction · 0.85

Calls 1

itemsMethod · 0.45

Tested by 2

test_serialize_tensorsFunction · 0.68