Fix problem with dtypes

The Python sum function may return a float64 array even if the arguments are float32, so we need to force the result's dtype.

Adding more explicit error messages.