Repository navigation
BUG: NaT now casts to NaN float64 - #11890
tylerjereddy wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Ought to handle other sizes of float too
3ad7b75 to
91a1601
Compare
|
I tried to revise accordingly. Some notes / thoughts:
|
There was a problem hiding this comment.
Just use NPY_HALF, NPY_FLOAT, NPY_DOUBLE, NPY_LONGDOUBLE here, or whatever the names really are. Never used the sized types when writing type-generic code.
There was a problem hiding this comment.
Is it safe to dispense with the preprocessor guards if I do that?
There was a problem hiding this comment.
Yes, I think it is - I think long double is always defined, even if its just the same size as double.
91a1601 to
d1a727e
Compare
|
I updated the type specifications and tried removing the preprocessor guards -- that works locally anyway. |
There was a problem hiding this comment.
This ought to be after you're done with it, not before (although strictly it doesn't matter)
d1a727e to
3c8afb0
Compare
|
Revised to move the decref, but I may need some guidance on the |
|
May need clarification re: revision requested by @eric-wieser |
3c8afb0 to
4726163
Compare
|
Rebased & ping @shoyer for guidance |
|
I have two concerns here:
|
4726163 to
778d254
Compare
|
Revised based on feedback from @shoyer -- I migrated the casting code right down to the inner type-type conversion loops that are code generated in "C++ style." |
There was a problem hiding this comment.
Note that a large amount of code duplication is introduced because of this specialization, but I think the choice is always going to be between highly-specialized loops for type-type conversion & more general loops where bystander type conversions suffer a performance hit from NaT checking.
There was a problem hiding this comment.
What are you trying to do with these ifs? You shouldn't ever read op, only write to it.
There was a problem hiding this comment.
A form of type checking; I think I had issues using the template @type@ style things in comparison operators for some reason.
There was a problem hiding this comment.
Is there a nice / clean way to inspect types on inner loops in our template language? I guess something involving PyArray_DESCR or similar might be cooked up, although the "ugly" way seems to work.
There was a problem hiding this comment.
We could do with a better way of attaching traits to types at loop-expansion time, for sure.
One approach we've used elsewhere is just to introduce another parallel variable containing 1/0 for each branch.
Another approach I'd like to investigate, but we have no precedent for, is to use something like:
#define float64_is_float64
And then in the loop use
# ifdef @type@_is_float64
...
#endifThere was a problem hiding this comment.
The highest performing approach is probably just to hard code the loops by type so that no check is needed at all, as alluded to above. Just means more code.
There was a problem hiding this comment.
For now - can't you just write a separate loop for the non-floating point cases? I don't think that you need to distinguish between the different types of NaN anyway - C will cast for you just fine, although perhaps with a warning that makes travis unhappy.
There was a problem hiding this comment.
Yeah, I think that's the debate I was having with myself in the comments above.
There was a problem hiding this comment.
Right - but you were looking at it as a performance optimization, whereas in fact its required for correctness.
|
I was having a debate with myself in #8325 over whether we should even allow float <-> datetime casts at all. But I guess after reading this issue, and the example of converting to float and dividing by 356 to get years, maybe it's useful. Then it does seem like we should separate it out into a separate loop as suggested above, and strictly check that the float value is in the range MAX_INT64 to MIN_INT64 and set it to NaT if not. |
778d254 to
b8f6c75
Compare
|
Revised based on feedback to:
One other thought--I think we're limited to |
| ]) | ||
| def test_float_cast_limits(self, float_type, cast_type): | ||
| arr = np.array([[np.iinfo(np.int64).max + 1], | ||
| [np.iinfo(np.int64).min - 1]], dtype=float_type) |
There was a problem hiding this comment.
This test feels a bit tangential to my changes in this PR -- maybe I need an example for where usage of those max integer limits currently causes undesirable behavior in master or in my feature branch.
|
Architecture specific test failure -- interesting! Looks like the max integer related test. |
|
@tylerjereddy Do you want to pursue this? I suppose it is reasonable to ask why one would convert a datetime type to float when the units will disappear. Needs a rebase in any case. |
|
@charris this one may be less exciting but I don't mind trying to wrap it up once the current SciPy |
|
Let me close this, priority may not be high, and I should perhaps focus on smaller things on the NumPy side for now. |
Fixes #8449.
I think I used the "older" array iteration API if I'm reading the docs correctly; seems like this is still used in source though.