def _get_slogdet_diag_walker(a):
 if isinstance(a.dtype, types.Complex):
  @register_jitable
  def cmplx_diag_walker(n, a, sgn):
   csgn = (sgn + 0j)
   acc = 0.0
   for k in range(n):
    absel = np.abs(a[(k, k)])
    csgn = (csgn * (a[(k, k)] / absel))
    acc = (acc + np.log(absel))
   return (csgn, acc)
  return cmplx_diag_walker
 else:
  @register_jitable
  def real_diag_walker(n, a, sgn):
   acc = 0.0
   for k in range(n):
    v = a[(k, k)]
    if (v < 0.0):
     sgn = (- sgn)
     v = (- v)
    acc = (acc + np.log(v))
   return ((sgn + 0.0), acc)
  return real_diag_walker

def _get_slogdet_diag_walker ( a ) : if isinstance ( a . dtype , types . Complex ) : @ register_jitable def cmplx_diag_walker ( n , a , sgn ) : csgn = ( sgn + 0j ) acc = 0.0 for k in range ( n ) : absel = np . abs ( a [ ( k , k ) ] ) csgn = ( csgn * ( a [ ( k , k ) ] / absel ) ) acc = ( acc + np . log ( absel ) ) return ( csgn , acc ) return cmplx_diag_walker else : @ register_jitable def real_diag_walker ( n , a , sgn ) : acc = 0.0 for k in range ( n ) : v = a [ ( k , k ) ] if ( v < 0.0 ) : sgn = ( - sgn ) v = ( - v ) acc = ( acc + np . log ( v ) ) return ( ( sgn + 0.0 ) , acc ) return real_diag_walker
walks the diag of a lup decomposed matrix uses that det(a) = prod(diag(lup(a))) and also that log(a)+log(b) = log the return sign is adjusted based on the values found such that the log stays in the real domain .