MCPcopy
hub / github.com/hpcaitech/Open-Sora / writeFloat

Function writeFloat

tools/frame_interpolation/utils/utils.py:273–296  ·  view source on GitHub ↗
(name, data)

Source from the content-addressed store, hash-verified

271
272
273def writeFloat(name, data):
274 f = open(name, "wb")
275
276 dim = len(data.shape)
277 if dim > 3:
278 raise Exception("bad float file dimension: %d" % dim)
279
280 f.write(("float\n").encode("ascii"))
281 f.write(("%d\n" % dim).encode("ascii"))
282
283 if dim == 1:
284 f.write(("%d\n" % data.shape[0]).encode("ascii"))
285 else:
286 f.write(("%d\n" % data.shape[1]).encode("ascii"))
287 f.write(("%d\n" % data.shape[0]).encode("ascii"))
288 for i in range(2, dim):
289 f.write(("%d\n" % data.shape[i]).encode("ascii"))
290
291 data = data.astype(np.float32)
292 if dim == 2:
293 data.tofile(f)
294
295 else:
296 np.transpose(data, (2, 0, 1)).tofile(f)
297
298
299def check_dim_and_resize(tensor_list):

Callers 1

writeFunction · 0.85

Calls 1

encodeMethod · 0.45

Tested by

no test coverage detected