MCPcopy Create free account
hub / github.com/BioinfoMachineLearning/FlowDock / segment_mean

Function segment_mean

flowdock/utils/model_utils.py:129–146  ·  view source on GitHub ↗

Computes the mean value of each segment in a tensor.

(src, dst_idx, dst_size)

Source from the content-addressed store, hash-verified

127
128
129def segment_mean(src, dst_idx, dst_size):
130 """Computes the mean value of each segment in a tensor."""
131 out = torch.zeros(
132 dst_size,
133 *src.shape[1:],
134 dtype=src.dtype,
135 device=src.device,
136 ).index_add_(0, dst_idx, src)
137 denom = (
138 torch.zeros(
139 dst_size,
140 *src.shape[1:],
141 dtype=src.dtype,
142 device=src.device,
143 ).index_add_(0, dst_idx, torch.ones_like(src))
144 + 1e-8
145 )
146 return out / denom
147
148
149def segment_argmin(scores, dst_idx, dst_size, randomize: bool = False) -> torch.Tensor:

Callers 9

multi_pose_samplingFunction · 0.90
to_latentMethod · 0.90
forwardMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected