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

problem with adding to numpy.float64, ufunc issue? #2

Closed
arsenovic opened this issue Sep 3, 2016 · 6 comments
Closed

problem with adding to numpy.float64, ufunc issue? #2

arsenovic opened this issue Sep 3, 2016 · 6 comments

Comments

@arsenovic
Copy link
Member

arsenovic commented Sep 3, 2016

i am working on changing the operators (on this branch) to match those in galgebra: ie &->* and from *->|

however, i am getting some strange behavior which i dont undertand, which seems to be related to some operator overloads with numpy dtypes. it appears as though the float64.__add__ is taking precedence over cliffords MultiVector.__radd__. not sure why the operator changes created this problem.

@moble, @rkern perhaps you all have some ideas on how to solve this?

here is demo of error,
https://gist.github.com/13b0ee10dde76817c79aab567b682efa

@rkern
Copy link
Contributor

rkern commented Sep 4, 2016

The left operand gets the first shot at implementing the operation. Only if it fails does the right operand attempt with its __radd__ method. Because MultiVector implements the Sequence interface, np.asarray() knows how to convert it to a numpy array via np.asarray(). The numpy scalar types will attempt to convert the other operand to a numpy array via np.asarray(). Since this succeeds, np.float64.__add__() succeeds, and MultiVector.__radd__() does not get a chance to run.

I don't have a good idea offhand how to get around this.

@arsenovic
Copy link
Member Author

thanks very much for the info.

is it clear to you that the operator change would cause this? the exp() function operating on a MultiVector now fails also, which i suspect is related.

a similar question is raised in this SO post. after looking at their suggestions the __array_priority__ does not work, but __array_wrap__ does. however this hook seems to be after the numpy __add__ has happened...

they also suggest to subclassing ndarray. however, i am not sure that i have the time/ability to make this change to the whole class, or to decide whether it is a good idea.

@arsenovic
Copy link
Member Author

arsenovic commented Sep 4, 2016

so if the left hand operator fails, the right operand attempt with its __radd__ method, then would it be possible to make the ufunc 'fail' by doing something in __array_prepare__

@arsenovic
Copy link
Member Author

arsenovic@bd3bb72 . . . embarrasing

@hugohadfield
Copy link
Member

@arsenovic is this now fixed or still a problem?

@arsenovic
Copy link
Member Author

i think we can close

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

3 participants