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

np.dot is not supported by scimath #89

Open
amine-aboufirass opened this issue Jul 23, 2019 · 1 comment
Open

np.dot is not supported by scimath #89

amine-aboufirass opened this issue Jul 23, 2019 · 1 comment

Comments

@amine-aboufirass
Copy link

amine-aboufirass commented Jul 23, 2019

I came from he pint package, disappointed with its numpy support to scimath in hopes that the UnitArray could present some interesting possibilities. Unfortunately this is not the case. I would like to run a unit-aware dot product using 2 unit arrays, but this won't work:

a = UnitArray(np.linspace(0, 5, 6), units="cm")
b = UnitArray(np.linspace(0, 9, 6), units="sec")
c = np.dot(a,b)

type(c) shows that this is a numpy.float64 object and not a UnitArray of length 0 or a UnitScalar as I would expect. This makes it difficult for me to see the use of UnitArrays since they currently only appear to support element wise multiplication in numpy...

Is there a concise way of doing a unit-aware dot product with scimath? If so how? If not how to implement it?

@corranwebster
Copy link
Contributor

We didn't have the use-case for dot with UnitArrays when we wrote the code, but you are right that it makes sense. Fixing would be just a matter of adding a dot method to the UnitArray class that did the right thing with the units. Unfortunately at Enthought we don't have bandwidth for working on SciMath in the near-term, but we would happily accept a pull request implementing this feature.

In the interim, the best work-around for you in your own code is possibly to monkeypatch UnitArray with a dot product method:

def dot(self, b):
    ...

UnitArray.dot = dot

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

2 participants