qimpy.math.accum_norm_

accum_norm_(f, x, out, start_dim, safe_mode=False)

Accumulate \(f |x|^2\) to out in-place. The result is accumulated over dimensions start_dim to number of dimensions of f. Dimensions of f must match the starting dimensions of x. Dimensions of out must match f up to start_dim, and then equal to those of x beyond the dimensions of f. This is equivalent to performing:

out += (f[…, #] * abs_squared(x)).sum(dim=(start_dim … len(f.shape)))

where f[…, #] indicates broadcasting f to match initial dimensions of x. This pattern is used in density computation, and is extremely inefficient as written due to multiple passes through the data of x. If safe_mode is set to True, this function returns the above naive implementation for checking correctness conveniently. This function optimizes this evaluation as much as possible while staying in pure Python, and is a prime candidate for C++ re-implementation.

Parameters:
  • f (Tensor) –

  • x (Tensor) –

  • out (Tensor) –

  • start_dim (int) –

  • safe_mode (bool) –

Return type:

None