Giter Site home page Giter Site logo

Comments (5)

craffel avatar craffel commented on September 28, 2024

Well, technically a np.float64 is a float, in the isinstance sense:

>>> a = np.float64(3.3)
>>> type(a)
numpy.float64
>>> isinstance(a, float)
True

In order to stay sane I usually make the assumption that np.float64 can be used interchangeably with float. Code which doesn't do make this assumption bums me out but does exist (Theano is a good example). I don't think it would do any harm to be more explicit about casting things to float, if that would fix the issue you're experiencing. But, I'd also gently suggest that the other code you're using which considers np.float64 and float different should maybe be changed too.

from pretty-midi.

douglaseck avatar douglaseck commented on September 28, 2024

I can fix this on my side by treating note timings as c++ doubles not
floats.

That said, the documentation error stands :-) The time is documented as a
float. Then you explicitly raise an exception if a float is passed in.

On Wed, Apr 13, 2016 at 3:38 PM, Colin Raffel [email protected]
wrote:

Well, technically a np.float64 is a float, in the isinstance sense:

a = np.float64(3.3)>>> type(a)
numpy.float64>>> isinstance(a, float)True

In order to stay sane I usually make the assumption that np.float64 can
be used interchangeably with float. Code which doesn't do make this
assumption bums me out but does exist (Theano is a good example). I don't
think it would do any harm to be more explicit about casting things to
float, if that would fix the issue you're experiencing. But, I'd also
gently suggest that the other code you're using which considers np.float64
and float different should maybe be changed too.


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#63 (comment)

from pretty-midi.

craffel avatar craffel commented on September 28, 2024

That said, the documentation error stands :-) The time is documented as a
float.

Well, my policy is usually that the specified type in the docstring implies that the actual type will satisfy isinstance(thing, type).

Then you explicitly raise an exception if a float is passed in.

Which exception do you mean? If it's raising an Exception when a float is passed in, that's definitely a bug!

from pretty-midi.

douglaseck avatar douglaseck commented on September 28, 2024

I misunderstood something about floats. I thought an np.float32 was a
python float. It turns out it's not. Only 64-bit floats evaluate to true
for isinstance(x, float). So your code is fine. I just need to switch my
code to use c++ doubles, not c++ floats.

Sorry for the confusion.

On Wed, Apr 13, 2016 at 4:58 PM, Colin Raffel [email protected]
wrote:

That said, the documentation error stands :-) The time is documented as a
float.

Well, my policy is usually that the specified type in the docstring
implies that the actual type will satisfy isinstance(thing, type).

Then you explicitly raise an exception if a float is passed in.

Which exception do you mean? If it's raising an Exception when a float is
passed in, that's definitely a bug!


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#63 (comment)

from pretty-midi.

craffel avatar craffel commented on September 28, 2024

I thought an np.float32 was a python float. It turns out it's not.

That's interesting, I also didn't realize isinstance(np.float32(3.1), float) evaluates to False. I guess it makes sense. I'll close this issue, feel free to reopen if you find any other problems here.

from pretty-midi.

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.