def save(self, dirname: str): os.makedirs(dirname, exist_ok=True) for max_texture_size, (descriptor, constant_bytes) in self.data_dict.items(): with open(path.join(dirname, f"graph_{self.backend_suffix}_{max_texture_size}.json"), "w") as f: json.dump(descriptor, f, indent=2) with open(path.join(dirname, f"weight_{self.backend_suffix}_{max_texture_size}.bin"), "wb") as f: f.write(constant_bytes)
def test_dump_with_native_object(): with tempfile.TemporaryDirectory() as tmpdir: filepath = path.join(tmpdir, "tmp.json") with open(filepath, "w") as f: json.dump([1, True, None], f) with open(filepath) as f: res = f.read() assert res == "[1, true, null]", res
def clean_up_callback(cls): if len(cls.cases) == 0: return with open(path.join(cls.OUTPUT_ROOT, "./master.json"), "w") as f: json.dump(cls.cases, f) if cls.use_separate_data: with open(path.join(cls.OUTPUT_ROOT, "./master.json.bin"), "wb") as f: f.write(cls.concatenated_data)
def save(self, dirname: str): os.makedirs(dirname, exist_ok=True) with open(path.join(dirname, "graph_{}.json".format(self.backend_suffix)), "w") as f: json.dump(self.descriptor, f, indent=2) with open(path.join(dirname, "kernels_{}.cpp".format(self.backend_suffix)), "w") as f: f.write(self.descriptor.concat_kernel_sources()) with open(path.join(dirname, "weight_{}.bin".format(self.backend_suffix)), "wb") as f: f.write(self.constants) self._compile(dirname) self._compile_fallback_asmjs(dirname)