[Numpy-discussion] switching to float32
Dag Sverre Seljebotn
Sat Jun 27 07:39:48 CDT 2009
Dan Goodman wrote:
> Robert Kern wrote:
>> On Fri, Jun 26, 2009 at 03:39, Christian K.<firstname.lastname@example.org> wrote:
>>> John Schulman <joschu <at> caltech.edu> writes:
>>>> I'm trying to reduce the memory used in a calculation, so I'd like to
>>>> switch my program to float32 instead of float64. Is it possible to
>>>> change the numpy default float size, so I don't have to explicitly
>>>> state dtype=np.float32 everywhere?
>>> Possibly not the nicest way, but
>>> np.float64 = np.float32
>>> somewhere at the beginning should work.
>> No. There is no way to change the default dtype of ones(), zeros(), etc.
> Is there any chance that this will ever be changed or is it considered
> too unpythonic / too much work to implement? I would find this quite a
> useful feature in a project I'm working on, because I want to mixing
> some GPU code in to various places with pycuda, but older GPU cards only
> have support for float32.
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
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)
return np.array(*args, **kw)
and so on in your own codebase, avoiding the problem.
More information about the Numpy-discussion