Comments (5)
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.
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)TrueIn 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.
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.
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.
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)
- Wrong tempo HOT 1
- get piano roll with the right sampling rate HOT 10
- Create python wheels for package
- Trim Silence HOT 3
- Is there any way to split a MIDI files into smaller segements based on time in secods/ milliseconds? HOT 1
- _load_metadata does not load lyrics correctly HOT 5
- Numpy type error for int loading midi HOT 3
- Bump version + new pip package HOT 3
- "program_change" event on any channel only effects the current track HOT 5
- Type Mismatch in Calling `fluidsynth.py` HOT 2
- Multitude of set_tempo messages after PrettyMIDI.adjust_times HOT 1
- PrettyMIDI.write error in align_midi.py (ValueError: attribute must be in range 0..16777215) HOT 4
- ValueError when trying to read certain .mid files HOT 1
- Pitch-bend range HOT 5
- Note starting point can be greater than its ending point HOT 1
- complete note conversion feature HOT 1
- fluidsynth: error: Unknown integer parameter 'synth.sample-rate' HOT 5
- Docs apperance HOT 3
- get_piano_roll sustains some notes too long HOT 3
- Midi Markers HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pretty-midi.