@@ -23,6 +23,7 @@ def __init__(
2323 self ,
2424 positions_likelihood_list : Optional [List [PositionsLH ]] = None ,
2525 cosmology : ag .cosmo .LensingCosmology = None ,
26+ use_jax : bool = True ,
2627 ):
2728 """
2829 Analysis classes are used by PyAutoFit to fit a model to a dataset via a non-linear search.
@@ -44,6 +45,15 @@ def __init__(
4445 self .cosmology = cosmology or Planck15 ()
4546 self .positions_likelihood_list = positions_likelihood_list
4647
48+ self ._use_jax = use_jax
49+
50+ @property
51+ def _xp (self ):
52+ if self ._use_jax :
53+ import jax .numpy as jnp
54+ return jnp
55+ return np
56+
4757 def tracer_via_instance_from (
4858 self ,
4959 instance : af .ModelInstance ,
@@ -72,8 +82,9 @@ def tracer_via_instance_from(
7282 subhalo_centre = tracer_util .grid_2d_at_redshift_from (
7383 galaxies = instance .galaxies ,
7484 redshift = instance .galaxies .subhalo .redshift ,
75- grid = aa .Grid2DIrregular (values = [instance .galaxies .subhalo .mass .centre ]),
85+ grid = aa .Grid2DIrregular (values = [instance .galaxies .subhalo .mass .centre ], xp = self . _xp ),
7686 cosmology = self .cosmology ,
87+ xp = self ._xp
7788 )
7889
7990 instance .galaxies .subhalo .mass .centre = tuple (subhalo_centre .in_list [0 ])
@@ -95,7 +106,7 @@ def tracer_via_instance_from(
95106 )
96107
97108 def log_likelihood_penalty_from (
98- self , instance : af .ModelInstance , xp = np
109+ self , instance : af .ModelInstance ,
99110 ) -> Optional [float ]:
100111 """
101112 Call the positions overwrite log likelihood function, which add a penalty term to the likelihood if the
@@ -116,7 +127,7 @@ def log_likelihood_penalty_from(
116127 The penalty value of the positions log likelihood, if the positions do not trace close in the source plane,
117128 else a None is returned to indicate there is no penalty.
118129 """
119- log_likelihood_penalty = xp .array (0.0 )
130+ log_likelihood_penalty = self . _xp .array (0.0 )
120131
121132 if self .positions_likelihood_list is not None :
122133
@@ -126,7 +137,7 @@ def log_likelihood_penalty_from(
126137
127138 log_likelihood_penalty = (
128139 positions_likelihood .log_likelihood_penalty_from (
129- instance = instance , analysis = self , xp = xp
140+ instance = instance , analysis = self , xp = self . _xp
130141 )
131142 )
132143
0 commit comments