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

Method aggregate

pointersect/inference/structures.py:1387–1448  ·  view source on GitHub ↗

Aggregate a list of PointersectRecord of the same shape. Note that it will set many attributes to None.

(records: T.List['PointersectRecord'])

Source from the content-addressed store, hash-verified

1385
1386 @staticmethod
1387 def aggregate(records: T.List['PointersectRecord']) -> 'PointersectRecord':
1388 """
1389 Aggregate a list of PointersectRecord of the same shape.
1390 Note that it will set many attributes to None.
1391 """
1392 out = dict()
1393 # simple average
1394 for name in [
1395 'intersection_xyz_w', 'intersection_rgb',
1396 'ray_t', 'ray_hit', 'ray_hit_logit', 'model_attn_weights',
1397 'refined_ray_hit',
1398 ]:
1399 arr = [getattr(r, name, None) for r in records]
1400 arr = [a for a in arr if a is not None]
1401 if len(arr) == 0:
1402 out[name] = None
1403 else:
1404 out[name] = sum(arr) / len(arr)
1405
1406 # set to be the first
1407 for name in [
1408 'blending_weights', 'neighbor_point_idxs', 'neighbor_point_valid_len',
1409 'model_attn_weights',
1410 'geometry_weights',
1411 'valid_neighbor_idx_mask',
1412 ]:
1413 arr = [getattr(r, name, None) for r in records]
1414 if len(arr) == 0:
1415 out[name] = None
1416 else:
1417 out[name] = arr[0]
1418
1419 # sum -> normalize to unit norm
1420 for name in [
1421 'intersection_surface_normal_w',
1422 'intersection_plane_normals_w',
1423 ]:
1424 arr = [getattr(r, name, None) for r in records]
1425 arr = [a for a in arr if a is not None]
1426 if len(arr) == 0:
1427 out[name] = None
1428 else:
1429 out[name] = sum(arr)
1430 out[name] = torch.nn.functional.normalize(out[name], p=2, dim=-1)
1431
1432 # set to be and
1433 for name in [
1434 'valid_plane_normal_mask'
1435 ]:
1436 arr = [getattr(r, name, None) for r in records]
1437 arr = [a for a in arr if a is not None]
1438 if len(arr) == 0:
1439 out[name] = None
1440 else:
1441 out[name] = arr[0]
1442 for i in range(1, len(arr)):
1443 out[name] = torch.logical_and(out[name], arr[i])
1444

Calls 1

PointersectRecordClass · 0.85

Tested by

no test coverage detected