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

Dealing with division and element-wise operations on Vector3d #140

Open
din14970 opened this issue Nov 15, 2020 · 1 comment
Open

Dealing with division and element-wise operations on Vector3d #140

din14970 opened this issue Nov 15, 2020 · 1 comment
Labels
dev Package maintenance
Milestone

Comments

@din14970
Copy link
Contributor

After the discussion in PR #138, it seems a more detailed discussion on how to deal with element-wise operations on data structures is handled. The point of contention was:

>>> 1/vector

If vector, a Vector3d object, were to behave like the array data it contains, then this would imply an element-wise operation, i.e. taking the inverse of each element. However, mathematically, division by a vector is undefined. This leads to the dilemma: should the behavior be more maths-like or more array like? The maths definition would better reflect "real life", but a user may expect array-like behavior, and be put off by doing element wise division like:

>>> vector = Vector3d(1/vector.data)

The issue could be avoided with more operators like the ./ operator in Matlab. However, this operator does not exist in Python and it is not possible to add custom operators - they are baked into the language.

Alternatively, one could overload operators which are unused. One could perhaps make use of **, // and ^, which are all valid operators. // could be used to represent Matlab's ./, but it might confuse users who expect // to mean floor division. In the same vein, ** could be used for element-wise multiplication, but again it might confuse users who expect it to mean power.

@pc494
Copy link
Member

pc494 commented Dec 1, 2020

https://numpy.org/doc/stable/user/basics.broadcasting.html might be relevant here, but I think in the short term this development will be postponed until after the main pyxem components have been worked through.

@pc494 pc494 mentioned this issue Dec 8, 2020
9 tasks
@pc494 pc494 added this to the v0.6.0 milestone May 8, 2021
@pc494 pc494 removed this from the v0.6.0 milestone May 23, 2021
@hakonanes hakonanes added this to the v1.0.0 milestone Feb 14, 2022
@harripj harripj added dev Package maintenance discussion labels Feb 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev Package maintenance
Projects
None yet
Development

No branches or pull requests

4 participants