dpilger26 / NumCpp

C++ implementation of the Python Numpy library
https://dpilger26.github.io/NumCpp
MIT License
3.58k stars 555 forks source link

reshape() should return a new copy instead of modifying #193

Closed TorokLev closed 1 year ago

TorokLev commented 1 year ago

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

reshape modifies the input but numpy doesn't. It would desirable to behave similar.

Describe the solution you'd like A clear and concise description of what you want to happen.

It should not break:

const nc::NdArray array = {1,2,3}; std::cout << array.reshape(-1,1).shape();

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

dpilger26 commented 1 year ago

I disagree, the goal of this library is to be NumPy like, but not necessarily identical. It is more efficient for the default behavior to be an in place reshape and to let the user call the copy() method if they need a copy. I've updated the documentation to be more clear and to reflect this.