Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I believe this change resolves the issue originally seen in #166, again in #173, and investigated in #174, #175, #176.
After a pointer (pun intended) from @TomMelt towards initialising as null in #176 I conducted further investigations in #174
Checking the Fortran standards declaring a pointer has the default association state is undefined.
This is what we were doing in the autograd example with
out_data
.When it is passed to
torch_tensor_to array
it could be unassociated, in which case the example runs as expected, registering this, and assigning/allocating the array.However, it could also be associated, in which case this is picked up in
torch_tensor_to_array
, a mismatch in sizes registered, and an error raised.The solution here is to ensure that we declare the pointer as
null()
at initialisation so that we avoid undefined behaviour.This PR should fix the autograd example where it crashes in CI above, but future work by @jwallwork23 as he finalises this feature will need to make sure that there is good documentation to warn users that they need to be careful with pointers, and avoid undefined initialisation.