8000 User-defined dtype: `np.copy` always uses `memcopy` / `memset`, rather than `copyswapn` · Issue #10897 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

User-defined dtype: np.copy always uses memcopy / memset, rather than copyswapn #10897

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

Closed
EricCousineau-TRI opened this issue Apr 12, 2018 · 0 comments

Comments

@EricCousineau-TRI
Copy link
Contributor
EricCousineau-TRI commented Apr 12, 2018

It seems odd to me that for a user-defined dtype, you must specify copyswap (which can be used to provide a default implementation of copyswapn), but the default behavior of np.copy (PyArray_GetDTypeTransferFunction) will end up providing a transfer method that uses memmove / memcpy.

This creates an issue when implementing dtypes that owns data which is heap-allocated, e.g. variable-size autodiff scalars.

It'd be nice if the default behavior were to leverage the user-defined copyswapn; while it would impact performance for user dtypes by default, authors could always make the implementation use something akin to what PyArray_GetStridedCopyFn returns.

Relates #10721: That issue, however, does not impact functionality per se, but more of performance since it creates memory leak. This issue, however, is a blocker for implementing these types of dtypes.

I was able to implement almost all of the features I need to make it possible to expose Eigen::AutoDiffScalar<Eigen::VectorXd> as a scalar type using pybind11 in C++; I believe this is the only main blocker for the functionality:
RobotLocomotion/drake#8452
RobotLocomotion/pybind11#12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0