2020
2121
2222# TODO: move the function to numcodecs
23- def ensure_ndarray (buf , allow_copy = False , like = np . empty (()) ):
24- """Convenience function to coerce `buf` to numpy array like, if it is not already
25- numpy array like.
23+ def ensure_ndarray (buf ):
24+ """Convenience function to coerce `buf` to numpy array- like, if it is not
25+ already a numpy array- like.
2626
2727 Parameters
2828 ----------
@@ -31,12 +31,13 @@ def ensure_ndarray(buf, allow_copy=False, like=np.empty(())):
3131
3232 Returns
3333 -------
34- arr : ndarray -like
35- A numpy array-like, sharing memory with `buf`.
34+ arr : array -like
35+ A numpy array-like array that shares memory with `buf`.
3636
3737 Notes
3838 -----
39- This function will not create a copy under any circumstances if `allow_copy=False`.
39+ This function will not create a copy under any circumstances, it is guaranteed to
40+ return a view on memory exported by `buf`.
4041 """
4142
4243 if isinstance (buf , np .ndarray ):
@@ -71,11 +72,13 @@ def ensure_ndarray(buf, allow_copy=False, like=np.empty(())):
7172
7273# TODO: move the function to numcodecs
7374def ensure_contiguous_ndarray (buf , max_buffer_size = None ):
74- """Convenience function to coerce `buf` to a numpy array, if it is not already a
75- numpy array. Also ensures that the returned value exports fully contiguous memory,
76- and supports the new-style buffer interface. If the optional max_buffer_size is
77- provided, raise a ValueError if the number of bytes consumed by the returned
78- array exceeds this value.
75+ """Convenience function to coerce `buf` to numpy array-like, if it is not already
76+ numpy array-like.
77+
78+ Also ensures that the returned value exports fully contiguous memory, and supports
79+ the new-style buffer interface. If the optional max_buffer_size is provided, raise
80+ a ValueError if the number of bytes consumed by the returned array exceeds this
81+ value.
7982
8083 Parameters
8184 ----------
@@ -87,8 +90,8 @@ def ensure_contiguous_ndarray(buf, max_buffer_size=None):
8790
8891 Returns
8992 -------
90- arr : ndarray
91- A numpy array, sharing memory with `buf`.
93+ arr : array-like
94+ A numpy array-like array that shares memory with `buf`.
9295
9396 Notes
9497 -----
0 commit comments