Skip to content

Do not compare arrays with strings in make_initial_point_expression #5133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions pymc/initial_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,15 @@ def make_initial_point_expression(
if strategy is None:
strategy = default_strategy

if strategy == "moment":
value = get_moment(variable)
elif strategy == "prior":
value = variable
if isinstance(strategy, str):
if strategy == "moment":
value = get_moment(variable)
elif strategy == "prior":
value = variable
else:
raise ValueError(
f'Invalid string strategy: {strategy}. It must be one of ["moment", "prior"]'
)
else:
value = at.as_tensor(strategy, dtype=variable.dtype).astype(variable.dtype)

Expand Down
6 changes: 6 additions & 0 deletions pymc/tests/test_initial_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ def test_new_warnings(self):
assert not hasattr(rv.tag, "test_value")
pass

def test_valid_string_strategy(self):
with pm.Model() as pmodel:
pm.Uniform("x", 0, 1, size=2, initval="unknown")
with pytest.raises(ValueError, match="Invalid string strategy: unknown"):
pmodel.recompute_initial_point(seed=0)


class TestInitvalEvaluation:
def test_make_initial_point_fns_per_chain_checks_kwargs(self):
Expand Down