MCPcopy Create free account
hub / github.com/apple/ml-pointersect / _write_info

Method _write_info

cdslib/core/data/chunked_memmap.py:106–136  ·  view source on GitHub ↗

Write the info to info_filename.

(self)

Source from the content-addressed store, hash-verified

104 self.chunk_filename_dict = self._determine_memmap_filenames(self.working_dir, self.chunk_idxs)
105
106 def _write_info(self):
107 """Write the info to info_filename."""
108 if isinstance(self.chunk_idxs, np.ndarray):
109 self.chunk_idxs = self.chunk_idxs.tolist()
110 if isinstance(self.chunk_local_idxs, np.ndarray):
111 self.chunk_local_idxs = self.chunk_local_idxs.tolist()
112
113 info_dict = dict()
114 for key in [
115 "dtype",
116 "itemsize",
117 "chunk_idxs",
118 "chunk_local_idxs",
119 ]:
120 info_dict[key] = getattr(self, key)
121
122 # make sure dict keys are str
123 for key in [
124 "chunk_offsets_dict",
125 "chunk_sample_shapes_dict",
126 "chunk_shape_dict",
127 ]:
128 tmp_dict = dict()
129 for chunk_idx in getattr(self, key):
130 tmp_dict[str(chunk_idx)] = getattr(self, key)[chunk_idx]
131 info_dict[key] = tmp_dict
132
133 folder = os.path.dirname(self.info_filename)
134 os.makedirs(folder, exist_ok=True)
135 with open(self.info_filename, "w") as outfile:
136 json.dump(info_dict, outfile, indent=4, cls=NumpyJsonEncoder)
137
138 def __len__(self):
139 if self.chunk_idxs is None:

Callers 1

add_all_samplesMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected