Skip to content

Commit cb493b5

Browse files
committed
Short-circuit metric properties to None when fixed param
1 parent 4a40ef7 commit cb493b5

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

cmdstanpy/stanfit/mcmc.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,13 @@ def metric_type(self) -> str | None:
219219
to CmdStan arg 'metric'.
220220
When sampler algorithm 'fixed_param' is specified, metric_type is None.
221221
"""
222+
if self._is_fixed_param:
223+
return None
224+
222225
if not self._metric_info_parsed:
223226
self._parse_metric_info()
224-
return self._metric_type if not self._is_fixed_param else None
227+
228+
return self._metric_type
225229

226230
@property
227231
def inv_metric(self) -> np.ndarray | None:
@@ -231,10 +235,13 @@ def inv_metric(self) -> np.ndarray | None:
231235
a ``nchains x nparams x nparams`` array when metric_type is 'dense_e',
232236
or ``None`` when metric_type is 'unit_e' or algorithm is 'fixed_param'.
233237
"""
238+
if self._is_fixed_param:
239+
return None
240+
234241
if not self._metric_info_parsed:
235242
self._parse_metric_info()
236243

237-
if self._is_fixed_param or self.metric_type == 'unit_e':
244+
if self.metric_type == 'unit_e':
238245
return None
239246

240247
return self._metric
@@ -245,10 +252,13 @@ def step_size(self) -> np.ndarray | None:
245252
Step size used by sampler for each chain.
246253
When sampler algorithm 'fixed_param' is specified, step size is None.
247254
"""
255+
if self._is_fixed_param:
256+
return None
257+
248258
if not self._metric_info_parsed:
249259
self._parse_metric_info()
250260

251-
return self._step_size if not self._is_fixed_param else None
261+
return self._step_size
252262

253263
@property
254264
def thin(self) -> int:

0 commit comments

Comments
 (0)