Coder Social home page Coder Social logo

Comments (2)

mdickinson avatar mdickinson commented on August 20, 2024

So the issue is really in numpy: if c is of type numpy.float64, then c.__mul__ incorrectly accepts a UnitArray instance and returns a result without units, rather than delegating responsibility for the multiplication to UnitArray.__rmul__ as we'd like it to.

The only way I see to fix this in scimath.units would be to not have UnitArray inherit from ndarray any more, but that's a bit of a drastic move that would almost certainly break a lot of existing code. [From a purity point of view, I think that it's actually the right move: a UnitArray is a product of an array with a unit, and for me it's a stretch to regard that as an ndarray in its own right. I remember seeing similar difficulties from people trying to create a 'Money' class that inherited from the standard library 'Decimal' type.]

from scimath.

rupertnash avatar rupertnash commented on August 20, 2024

I think this isn't the whole story though. I tried running c*a under pdb and the __array_wrap__ method is called afterwards. My understanding of the numpy API is that this method is called on the object involved which has the highest __array_priority__ attribute. So this method might be suitable for sorting out the units?

from scimath.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.