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

Method chunk

pointersect/inference/structures.py:1341–1384  ·  view source on GitHub ↗

Chunk the PointersectRecord at the given dimension. As pytorch, the resulted tensors are views to the original ones.

(self, chunks: int, dim: int)

Source from the content-addressed store, hash-verified

1339 return PointersectRecord(**out)
1340
1341 def chunk(self, chunks: int, dim: int) -> T.List['PointersectRecord']:
1342 """
1343 Chunk the PointersectRecord at the given dimension.
1344 As pytorch, the resulted tensors are views to the original ones.
1345 """
1346
1347 attr_names = [
1348 'intersection_xyz_w', 'intersection_surface_normal_w', 'intersection_rgb',
1349 'blending_weights', 'neighbor_point_idxs', 'neighbor_point_valid_len',
1350 'ray_t', 'ray_hit', 'ray_hit_logit', 'model_attn_weights',
1351 'refined_ray_hit',
1352 'intersection_plane_normals_w',
1353 'geometry_weights',
1354 'valid_neighbor_idx_mask',
1355 'valid_plane_normal_mask',
1356 ]
1357
1358 actual_chunks = None
1359 out = dict()
1360 for name in attr_names:
1361 arr = getattr(self, name, None)
1362 if arr is None:
1363 out[name] = None
1364 else:
1365 out[name] = arr.chunk(chunks=chunks, dim=dim)
1366 if actual_chunks is None:
1367 actual_chunks = len(out[name])
1368 else:
1369 assert len(out[name]) == actual_chunks
1370
1371 results = []
1372 for i in range(actual_chunks):
1373 tmp_dict = dict()
1374 for name in attr_names:
1375 arr_list = out[name]
1376 if arr_list is None:
1377 tmp_dict[name] = None
1378 else:
1379 tmp_dict[name] = arr_list[i]
1380 tmp_dict['model_info'] = self.model_info
1381 p = PointersectRecord(**tmp_dict)
1382 results.append(p)
1383
1384 return results
1385
1386 @staticmethod
1387 def aggregate(records: T.List['PointersectRecord']) -> 'PointersectRecord':

Callers

nothing calls this directly

Calls 2

PointersectRecordClass · 0.85
chunkMethod · 0.45

Tested by

no test coverage detected