Automatic casting of *64 values

Issue #98 resolved
Eric Harper created an issue

We should automatically cast np.float64, etc. values to np.float32, etc. values.

Comments (3)

  1. Eric Harper reporter

    Possible Soltions:

    1. Leave behavior as is, and make the error message more useful:
    raise RuntimeError("positions must be of type np.float32. Please use np.asarray(pos, dtype=np.float32) or pos.astype(np.float32) to cast" 
    
    1. Template all functions so that both 32 and 64 are able to be used. Problem with this is that the memory usage and speed benefits would disappear for most users as numpy defaults float64, etc.

    2. Template all functions, but use cython to wrap as follows:

    def accumulate(box, pos, useDouble=False):
        if (pos.dtype != np.float32):
            if (pos.dtype != np.float64):
                raise ValueError()
            elif not useDouble:
                raise RuntimeWarning("Casting pos to float32. Please use useDouble=True to use double precision calculation")
                pos = pos.astype(dtype=np.float32)
    
  2. Log in to comment