healpix_analyse.LocalizedAlm_optimized_v13_fixed#

LocalizedAlm_optimized_v13_fixed.py

CRITICAL FIX from v12: - PLM is now kept as REAL (float32) instead of being converted to complex - Output dtype matches the original (float32 instead of float64) - Uses element-wise multiply + sum instead of matmul (matches original gradient flow)

These changes ensure proper gradient flow through the real * complex multiplication, which is essential for correct optimization dynamics in synthesis.

Strategy: Precompute all Legendre polynomials on CPU using numpy (which is fast for sequential operations), store in CPU memory, and transfer to GPU on-demand during anafast_localized.

Classes#

LocalizedAlm

Localized spherical harmonic analysis with CPU-precomputed PLM.

Functions#

get_or_compute_coefficients(lmax, device[, dtype])

Dummy for compatibility.

precompute_all_plm_numpy(co_th_np, lmax, nside[, ...])

Precompute all P_lm on CPU using numpy.

test_localized_anafast()

Module Contents#

healpix_analyse.LocalizedAlm_optimized_v13_fixed.get_or_compute_coefficients(lmax, device, dtype=None)#

Dummy for compatibility.

healpix_analyse.LocalizedAlm_optimized_v13_fixed.precompute_all_plm_numpy(co_th_np, lmax, nside, limit_range=10000000000.0)#

Precompute all P_lm on CPU using numpy.

Returns list of numpy arrays (one per m value). This is MUCH faster than computing on GPU with Python loops.

class healpix_analyse.LocalizedAlm_optimized_v13_fixed.LocalizedAlm(level, patch_idx_ring, backend, lmax=None, lmax_compute=None)#

Bases: foscat.alm.alm

Localized spherical harmonic analysis with CPU-precomputed PLM.

PLM is precomputed on CPU (fast numpy), stored in CPU RAM, and transferred to GPU on-demand.

level#
nside#
patch_idx_ring#
device#
dtype#
lmax_full#
lmax_compute#
active_shift_ph#
plm_list_cpu = []#
comp_tf_localized(u_patch)#

Compute FFT on active rings.

anafast_localized(u_patch, map2_patch=None, bandpowers_binning=None)#

Compute pseudo-Cl using CPU-precomputed PLM.

Transfers PLM to GPU on-demand, uses it, then deletes.

IMPORTANT: PLM is kept as REAL (float32), matching the original LocalizedAlm.py behavior. This ensures proper gradient flow through the real * complex multiplication.

healpix_analyse.LocalizedAlm_optimized_v13_fixed.test_localized_anafast()#