You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So far ndarray_create creates a wrapper of the Fortran array that is passed to the function and uses the Fortran array as memory buffer for the numpy ndarray. This has the advantage that ndarray creation is fast and saves memory.
However, there are many caveats (see Working with arrays) for the user:
the user must make sure that the buffer is valid as long as the ndarray exists (tricky when one wants to return a ndarray from a subroutine),
make sure that no temporary array is passed to the ndarray_create
Especially for new or casual users this is not ideal. Solutions to this issue could be:
Let ndarray_create make a copy of the passed array. Offer previous functionality by providing a new function ndarray_create_nocopy for users who want efficiency
Advantages: safer for the reasons stated above, list_create(a_list, some_object) etc. also create copies, the safe alternative would be default (could pass temporaries, no need to manage lifetime of buffer), option for efficiency for experienced users
Disadvantages: existing code that relies on changes to the Fortran array affecting the ndarray and vice versa breaks, existing code runs slower/uses more memory due to additional copies
Will change API to variant 1)
In existing code, change ndarray_create to ndarray_create_nocopy, when copies should be avoided. When using ndarray_create_nocopy, add the Fortran asynchronous attribute to the declaration of the underlying buffer. (see #3)
So far ndarray_create creates a wrapper of the Fortran array that is passed to the function and uses the Fortran array as memory buffer for the numpy ndarray. This has the advantage that ndarray creation is fast and saves memory.
However, there are many caveats (see Working with arrays) for the user:
Especially for new or casual users this is not ideal. Solutions to this issue could be:
Let ndarray_create make a copy of the passed array. Offer previous functionality by providing a new function
ndarray_create_nocopy
for users who want efficiencyAdvantages: safer for the reasons stated above, list_create(a_list, some_object) etc. also create copies, the safe alternative would be default (could pass temporaries, no need to manage lifetime of buffer), option for efficiency for experienced users
Disadvantages: existing code that relies on changes to the Fortran array affecting the ndarray and vice versa breaks, existing code runs slower/uses more memory due to additional copies
OR: keep the existing
ndarray_create
, introducendarray_create_copy
with the safer behaviourAdvantages: no api change, existing code works as usual (but might be affected by issue Compiler optimization related issues when Fortran array is indirectly modified by ndarray or pointer to ndarray data #3)
Disadvantages: not as intuitive, unsafe variant is default, list_create etc. creates copy but ndarray_create does not
Comments on this issue to let me know, what you prefer
The text was updated successfully, but these errors were encountered: