Maybe extra spaces around the `==`. Some general notes. This replicates python code, with the upside of avoiding the the exception in some cases, I think I prefer this a bit over the other, but if someone has a preference one way or another we should decide that.

The other code also has exact checks for the (exact) numerical types. So I assume that that would likely make sense for the scalar special case. Likely it is special enough to move it further up, but that could be considered in a later pull request (Exact checks are very fast after all).

This whole code seems to lack tests badly (this has been mentioned also in gh-435 which is yet another slightly different attempt to optimize part of this), so if you have the time it would be awesome if you can look into adding tests, otherwise it is hard to impossible to review code, even if the changes here are pretty straight forward it is a very central part of numpy. As you saw there was a small error which only got found by a single, probably unrelated, test.