Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change ndarray_create default to create a copy of the array that is passed? #4

Closed
ylikx opened this issue Dec 8, 2018 · 2 comments
Closed
Labels
enhancement New feature or request question Further information is requested

Comments

@ylikx
Copy link
Owner

ylikx commented Dec 8, 2018

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:

  1. 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

  2. OR: keep the existing ndarray_create, introduce ndarray_create_copy with the safer behaviour
    Advantages: 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

@ylikx ylikx added enhancement New feature or request question Further information is requested labels Dec 8, 2018
@ylikx
Copy link
Owner Author

ylikx commented Jan 2, 2019

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)

@ylikx
Copy link
Owner Author

ylikx commented Jan 4, 2019

Changed in 5a14ca6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant