-
-
Notifications
You must be signed in to change notification settings - Fork 316
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
Directly allow zarr arrays as "out" parameter of ufuncs (if possible) #566
Comments
Thanks @s-m-e, this might be one to raise with the numpy folks, I don't know how easy it would be for numpy to allow zarr arrays as out parameters. |
Maybe @rgommers would know? 🙂 |
Interesting. Can you point to an example @s-m-e? Other ufuncs, like in ufuncs aren't going to be writing to disk, I think it requires |
@rgommers I have been wondering about this, too. I have been digging through old code and so far I believe I have been "a victim" of Python functions "pretending" to be a (C-) ufunc and clever duck typing - i.e. something along those lines: a = np.arange(10, 18, dtype = 'f4')
b = zarr.zeros((8,), chunks = (2,), dtype = 'f4')
isarray = lambda var: all((hasattr(var, attr) for attr in ('dtype', 'shape', 'ndim', 'astype')))
isscalar = lambda var: any((isinstance(var, number) for number in (int, float, np.number)))
def multiply_py(x, y, out = None, order = 'K', dtype = None):
assert isarray(x)
assert x.ndim == 1
assert isscalar(y)
assert out is None or isarray(out)
if out is None:
out = np.zeros(x.shape, order = order, dtype = dtype if dtype is not None else x.dtype)
for i in range(x.shape[0]):
out[i] = x[i] * y
return out
multiply_py(a, 2, out = b) I am trying to locate an example in an open source library. |
I just ran into the following "problem":
Some ufuncs (but not those from numpy itself) allow zarr arrays as out-parameters. I.e. the result of the computation is directly written to disk. numpy in fact rejects zarr arrays because they are not of "ArrayType". Could this be changed? I am not entirely sure given the nature of numpy's memory management.
The text was updated successfully, but these errors were encountered: