sqrt() #1

Closed
petigura opened this Issue Feb 23, 2012 · 2 comments

Comments

Projects
None yet
2 participants

Following your example in the README, I tried to use Kepler's third law:

PP = 4*pi**2 / G / mass_sun * distance**3
PP.convert_to_cgs()
9.95860849489e+14 s**2

However

sqrt(PP)

Fails

@ghost ghost assigned caseywstark Feb 23, 2012

Owner

caseywstark commented Feb 23, 2012

Hey Erik.

I tried to reproduce:

from dimensionful import *
from numpy import sqrt, pi

distance = Quantity(1.0, "AU")
mass_sun = Quantity(1.0, "Msun")
PP = 4 * pi**2 / G / mass_sun * distance**3
PP.convert_to_cgs()
sqrt(PP)

This throws AttributeError: sqrt. This is because numpy.sqrt is a ufunc, so it makes an array([PP], dtype=object), and tries to call PP.sqrt(). Quantities currently have no sqrt attribute, and this is the reason for the cryptic error.

This is definitely a design issue I came across and wasn't sure what to do about. I can't possibly cover every operation, but I think the best thing to do is to attach common operation methods to Quantity. Thoughts on this are very welcome.

For now, PP**(1.0/2) works and I will drop a sqrt method in soon.

Owner

caseywstark commented Feb 23, 2012

Fixed in 8710910.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment