Skip to content

Commit

Permalink
Check input args
Browse files Browse the repository at this point in the history
  • Loading branch information
famura committed Jul 9, 2024
1 parent 082ce51 commit e5dc21e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions neuralfields/potential_based.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ def __init__(

# Initialize the potential dynamics' time constant.
self.tau_learnable = tau_learnable
if tau_init <= 0:
raise ValueError("The time constant tau must be initialized positive.")
self._log_tau_init = torch.log(
torch.as_tensor(tau_init, device=device, dtype=torch.get_default_dtype()).reshape(-1)
)
Expand All @@ -98,6 +100,8 @@ def __init__(

# Initialize the potential dynamics' cubic decay.
self.kappa_learnable = kappa_learnable
if kappa_init <= 0:
raise ValueError("The cubic decay kappa must be initialized positive.")
self._log_kappa_init = torch.log(
torch.as_tensor(kappa_init, device=device, dtype=torch.get_default_dtype()).reshape(-1)
)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_simple_neural_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ def test_simple_neural_fields_fail():
with pytest.raises(ValueError):
SimpleNeuralField(input_size=6, output_size=3, potentials_dyn_fcn=pd_capacity_21, activation_nonlin=torch.sqrt)

with pytest.raises(ValueError):
SimpleNeuralField(input_size=6, output_size=3, potentials_dyn_fcn=pd_capacity_21, tau_init=0)

with pytest.raises(ValueError):
SimpleNeuralField(input_size=6, output_size=3, potentials_dyn_fcn=pd_capacity_21, kappa_init=0)

with pytest.raises(ValueError):
pd_linear(
p=torch.randn(3), s=torch.randn(3), h=torch.randn(3), tau=torch.tensor(-1.0), kappa=None, capacity=None
Expand Down

0 comments on commit e5dc21e

Please sign in to comment.