[Numpy-discussion] Help needed with numpy 10.5 release blockers

James Philbin philbinj at gmail.com
Sun Mar 23 17:43:58 EDT 2008


Well that's fine for binops with the same types, but it's not so
obvious which type to cast to when mixing signed and unsigned types.
Should the type of N.int32(10)+N.uint32(10) be int32, uint32 or int64?
Given your answer what should the type of N.int64(10)+N.uint64(10) be
(which is the case in the bug)?

The current casting rules for the unsigned + signed integral types in
numpy seems to be:
	int32	uint32	int64	uint64
int32	int32	int64	int64	float64
uint32		uint32	int64	uint64
int64			int64	float64
uint64				uint64

This does seem slightly barmy in cases. For reference here is what C uses:
	int32	uint32	int64	uint64
int32	int32	uint32	int64	uint64
uint32		uint32	uint64	uint64
int64			int64	uint64
uint64				uint64

So numpy currently seems to prefer to keep sign preserved and extends
the width of the result when it can. C prefers to keep overflows
minimized and never extends the width of the result.

James



More information about the NumPy-Discussion mailing list