[Numpy-discussion] switching to float32
Dan Goodman
dg.gmane at thesamovar.net
Sat Jun 27 20:31:21 EDT 2009
Dag Sverre Seljebotn wrote:
> Well, such a mechanism would mean that your code could not be reused
> reliably by other code (because, what if two different codebases sets
> different defaults...). So requiring any such mechanism would make it
> easier to write non-reusable code, which is generally considered a bad
> thing...
>
> Note that it is relatively easy for you to do e.g.
>
> default_dtype = np.float32
>
> def array(*args, **kw):
> if 'dtype' not in kw.keys():
> return np.array(*args, **kw, dtype=default_dtype)
> else:
> return np.array(*args, **kw)
>
> and so on in your own codebase, avoiding the problem.
>
Neat trick - I think I'll do exactly that. I'll also need to cover a few
other cases, like zeros(), ones(), etc., but I think it should work. One
could even write a little macro that generates wrappers like this for
all numpy/scipy functions that have a 'dtype' argument.
Thanks for an excellent idea!
Dan
More information about the NumPy-Discussion
mailing list