MCPcopy Create free account
hub / github.com/NanoComp/meep / get_total_weight

Function get_total_weight

python/binary_partition_utils.py:52–76  ·  view source on GitHub ↗

Computes the total weights contained within a BinaryPartition subtree. Args: partition: a BinaryPartition subtree to compute the associated weights for weights_by_proc_id: a list of weights associated with each proc_id Returns: The sum of all weights for each proc_id enco

(
    partition: mp.BinaryPartition, weights_by_proc_id: List[float]
)

Source from the content-addressed store, hash-verified

50
51
52def get_total_weight(
53 partition: mp.BinaryPartition, weights_by_proc_id: List[float]
54) -> float:
55 """Computes the total weights contained within a BinaryPartition subtree.
56
57 Args:
58 partition: a BinaryPartition subtree to compute the associated weights for
59 weights_by_proc_id: a list of weights associated with each proc_id
60
61 Returns:
62 The sum of all weights for each proc_id encountered in the subtree.
63
64 Raises:
65 ValueError: if sim.chunk_layout includes nodes with duplicate proc_ids
66 """
67 if partition_has_duplicate_proc_ids(partition):
68 raise ValueError("Duplicate proc_ids found in chunk_layout!")
69 if partition.proc_id is not None:
70 return weights_by_proc_id[partition.proc_id]
71 elif partition.left is not None and partition.right is not None:
72 left_weight = get_total_weight(partition.left, weights_by_proc_id)
73 right_weight = get_total_weight(partition.right, weights_by_proc_id)
74 return left_weight + right_weight
75 else:
76 raise ValueError("Partition missing proc_id or left, right attributes!")
77
78
79def get_left_right_total_weights(

Callers 1

Calls 1

Tested by

no test coverage detected