Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement "low memory" mode in apply() #218

Closed
oesteban opened this issue Jul 30, 2024 · 1 comment
Closed

Implement "low memory" mode in apply() #218

oesteban opened this issue Jul 30, 2024 · 1 comment

Comments

@oesteban
Copy link
Collaborator

We are currently propagating the ArrayProxy reported dtype unless an explicit output_dtype is set.

It would be more efficient to allow the user set a low memory flag such that the data type's itemsize is capped (e.g., float64 is cast into float32 and int64 into int32).

By performing the casting operation at access time, we would be sparing some memory (if I'm not wrong), especially when we arrive at map_coordinates.

WDTY @effigies? what would be an efficient way of capping the itemsize that works generically for any dtype?

@effigies
Copy link
Member

Maybe something like:

def cap_dtype(dt, nbytes):
    return np.dtype(f'{dt.byteorder}{dt.kind}{min(nbytes, dt.itemsize)}')
In [1]: import numpy as np

In [2]: def cap_dtype(dt, nbytes):
   ...:     return np.dtype(f'{dt.byteorder}{dt.kind}{min(nbytes, dt.itemsize)}')
   ...: 

In [3]: cap_dtype(np.dtype('f8'), 4)
Out[3]: dtype('float32')

In [4]: cap_dtype(np.dtype('f8'), 16)
Out[4]: dtype('float64')

In [5]: cap_dtype(np.dtype('i1'), 4)
Out[5]: dtype('int8')

In [6]: cap_dtype(np.dtype('i8'), 4)
Out[6]: dtype('int32')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants