mirror of
https://github.com/wassname/scikit-image.git
synced 2026-09-12 12:50:49 +08:00
Do not allow view_as_* to return copies (closes #866)
This commit is contained in:
+11
-7
@@ -11,16 +11,16 @@ def view_as_blocks(arr_in, block_shape):
|
||||
|
||||
Parameters
|
||||
----------
|
||||
arr_in: ndarray
|
||||
The n-dimensional input array.
|
||||
arr_in : ndarray
|
||||
Contiguous N-d input array.
|
||||
|
||||
block_shape: tuple
|
||||
block_shape : tuple
|
||||
The shape of the block. Each dimension must divide evenly into the
|
||||
corresponding dimensions of `arr_in`.
|
||||
|
||||
Returns
|
||||
-------
|
||||
arr_out: ndarray
|
||||
arr_out : ndarray
|
||||
Block view of the input array.
|
||||
|
||||
Examples
|
||||
@@ -70,8 +70,6 @@ def view_as_blocks(arr_in, block_shape):
|
||||
[[[76, 77],
|
||||
[82, 83]]]])
|
||||
"""
|
||||
|
||||
# -- basic checks on arguments
|
||||
if not isinstance(block_shape, tuple):
|
||||
raise TypeError('block needs to be a tuple')
|
||||
|
||||
@@ -88,6 +86,9 @@ def view_as_blocks(arr_in, block_shape):
|
||||
raise ValueError("'block_shape' is not compatible with 'arr_in'")
|
||||
|
||||
# -- restride the array to build the block view
|
||||
if not arr_in.flags.contiguous:
|
||||
raise ValueError("Cannot provide views on a non-contiguous input array")
|
||||
|
||||
arr_in = np.ascontiguousarray(arr_in)
|
||||
|
||||
new_shape = tuple(arr_shape / block_shape) + tuple(block_shape)
|
||||
@@ -107,7 +108,7 @@ def view_as_windows(arr_in, window_shape, step=1):
|
||||
Parameters
|
||||
----------
|
||||
arr_in: ndarray
|
||||
The n-dimensional input array.
|
||||
Contiguous N-d input array.
|
||||
window_shape: tuple
|
||||
Defines the shape of the elementary n-dimensional orthotope
|
||||
(better know as hyperrectangle [1]_) of the rolling window view.
|
||||
@@ -228,6 +229,9 @@ def view_as_windows(arr_in, window_shape, step=1):
|
||||
raise ValueError("`window_shape` is too small")
|
||||
|
||||
# -- build rolling window view
|
||||
if not arr_in.flags.contiguous:
|
||||
raise ValueError("Cannot provide views on a non-contiguous input array")
|
||||
|
||||
arr_in = np.ascontiguousarray(arr_in)
|
||||
|
||||
new_shape = tuple((arr_shape - window_shape) // step + 1) + \
|
||||
|
||||
Reference in New Issue
Block a user