Cambridge-ICCS / FTorch

A library for directly calling PyTorch ML models from Fortran.
https://cambridge-iccs.github.io/FTorch/
MIT License
79 stars 16 forks source link

add subroutine to delete arrays of tensors #155

Closed TomMelt closed 4 months ago

TomMelt commented 5 months ago

This PR adds a subroutine (torch_tensor_array_delete) to delete arrays of tensors. This eliminate the need to manually loop over all elements of the array calling torch_tensor_delete, see e.g.,

https://github.com/Cambridge-ICCS/FTorch/blob/490272ef5662936be26697d496b14f6a281214fa/examples/4_MultiIO/multiionet_infer_fortran.f90#L57-L60

Which now becomes,

https://github.com/Cambridge-ICCS/FTorch/blob/e24c38024e0ec8b03ecd0f8a3e6c269e42ac2a0c/examples/4_MultiIO/multiionet_infer_fortran.f90#L57-L58

TomMelt commented 5 months ago

@TomMelt First glance looks good.

However, we'll need any examples in the documentation and readme also updating if you can go through these as well please?

done

jatkinson1000 commented 5 months ago

@TomMelt Thanks - I wonder if an addition to the API changes page to point out this new option might be useful, though not essential as the old function is preserved?

Also I added a comment above with an edit for your thoughts:

I also wonder if your original suggestion of having an interface to delete both an array or a single tensor is a better to simplify the subroutine options. However, I also see that the explicitness of two different routines is more 'Fortranic'.

jatkinson1000 commented 4 months ago

A new thought on looking at some code today - perhaps we could have an interface torch_delete() that can take a model, tensor, or array of tensors and call the relevant deletion subroutine?