2222
2323import logging
2424import time
25+ from collections .abc import Mapping
2526from datetime import timedelta
2627from itertools import combinations_with_replacement , product
2728from typing import TYPE_CHECKING , Any
3940 from dataclasses import replace
4041
4142if TYPE_CHECKING :
42- from collections .abc import Mapping , MutableMapping
43+ from collections .abc import MutableMapping
4344
4445 from numpy .typing import ArrayLike , NDArray
4546
@@ -404,15 +405,15 @@ def mixing_matrices(
404405
405406def invert_mixing_matrix (
406407 M ,
407- rtol : float = 1e-5 ,
408+ rcond : float = 1e-5 ,
408409 progress : Progress | None = None ,
409410):
410411 """
411412 Inversion model for the unmixing E/B modes.
412413
413414 Args:
414415 M: Mixing matrix (mapping of keys -> Result objects)
415- rtol : relative tolerance for pseudo-inverse
416+ rcond : relative tolerance for pseudo-inverse
416417 progress: optional progress reporter
417418
418419 Returns:
@@ -432,14 +433,21 @@ def invert_mixing_matrix(
432433 s1 , s2 = value .spin
433434 * _ , _n , _m = _M .shape
434435
436+ if isinstance (rcond , Mapping ):
437+ if key not in rcond :
438+ raise KeyError (f"Missing rcond value for wm key: { key } " )
439+ _rcond = rcond [key ]
440+ else :
441+ _rcond = rcond
442+
435443 with progress .task (f"invert { key } " ):
436444 if (s1 != 0 ) and (s2 != 0 ):
437445 # Cl^EE+Cl^BB and Cl^EE-Cl^BB transformation
438446 # makes the mixing matrix block-diagonal
439447 M_p = _M [0 ] + _M [1 ]
440448 M_m = _M [0 ] - _M [1 ]
441- inv_M_p = np .linalg .pinv (M_p , rcond = rtol )
442- inv_M_m = np .linalg .pinv (M_m , rcond = rtol )
449+ inv_M_p = np .linalg .pinv (M_p , rcond = _rcond )
450+ inv_M_m = np .linalg .pinv (M_m , rcond = _rcond )
443451 _inv_m = np .vstack (
444452 (
445453 np .hstack (((inv_M_p + inv_M_m ) / 2 , (inv_M_p - inv_M_m ) / 2 )),
@@ -448,10 +456,10 @@ def invert_mixing_matrix(
448456 )
449457 _inv_M_EEEE = _inv_m [:_m , :_n ]
450458 _inv_M_EEBB = _inv_m [_m :, :_n ]
451- _inv_M_EBEB = np .linalg .pinv (_M [2 ], rcond = rtol )
459+ _inv_M_EBEB = np .linalg .pinv (_M [2 ], rcond = _rcond )
452460 _inv_M = np .array ([_inv_M_EEEE , _inv_M_EEBB , _inv_M_EBEB ])
453461 else :
454- _inv_M = np .linalg .pinv (_M , rcond = rtol )
462+ _inv_M = np .linalg .pinv (_M , rcond = _rcond )
455463
456464 inv_M [key ] = replace (M [key ], array = _inv_M )
457465 return inv_M
0 commit comments