Use a strided 1-element array as dummy filter out

When using generic_filter to build a graph, the numerical filter
output is actually ignored. Building a full array, even of the
smallest dtype, was wasteful. Using stride_tricks solves this by
creating a single-element buffer into which all output is fed.
This commit is contained in:
Juan Nunez-Iglesias
2015-12-14 18:57:29 +11:00
parent 49aa7cf999
commit 53d3154f09
+4 -1
View File
@@ -1,5 +1,6 @@
import networkx as nx
import numpy as np
from numpy.lib.stride_tricks import as_strided
from scipy import ndimage as ndi
import math
from ... import draw, measure, segmentation, util, color
@@ -124,7 +125,9 @@ class RAG(nx.Graph):
function=_add_edge_filter,
footprint=fp,
mode='nearest',
output=np.empty(label_image.shape, dtype=np.uint8),
output=as_strided(np.empty((1,), dtype=np.float_),
shape=label_image.shape,
strides=((0,) * label_image.ndim)),
extra_arguments=(self,))
try: