patrick-kidger / patrick-kidger/diffrax

replace_nans_at_start overwrite existing values

Open
#324 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
2.1k
Forks
189
Avg merge
3d 18h
Merged PRs (30d)
1

Description

Hello, I am not sure if the behavior of replace_nans_at_start in backward_hermite_coefficients is expected when we have initial values that aren't all NaNs.

The documentation proposes that "replace_nans_at_start" will change the NaN values at the start by the ones given.

I believe that this parameter is only useful if ALL the values at the start are NaNs. I give an example below (based again on get_data from the NCDE example) where the dataset has no NaN values. It actually raises an assertion error because values are being switched to "means" regardless wether they're NaNs or not.

snap

I think the problem is that in _backward_hermite_coefficients the following line:

y0 = jnp.broadcast_to(replace_nans_at_start, ys[0].shape)

doesn't consider if the values are NaNs and switches them automatically. In my opinion, the logic behind the parameter would be to only switch the NaN values and not overwrite the already existing ones. I would propose either mentioning in the docstring if this is the expected behvaior or adjusting the proposed line to consider if values are actually NaNs or not.

Thank you in advance! The library is great!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at _backward_hermite_coefficients and inspect how replace_nans_at_start is applied to ys[0], especially the y0 broadcast line mentioned in the issue. Compare that behavior with the parameter documentation and the provided example; the work is done when the documented behavior and handling of existing versus NaN initial values agree.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.