MCPcopy Create free account
hub / github.com/numpy/numpy / _get_linear_ramps

Function _get_linear_ramps

numpy/lib/arraypad.py:186–227  ·  view source on GitHub ↗

Construct linear ramps for empty-padded array in given dimension. Parameters ---------- padded : ndarray Empty-padded array. axis : int Dimension in which the ramps are constructed. width_pair : (int, int) Pair of widths that mark the pad area on bot

(padded, axis, width_pair, end_value_pair)

Source from the content-addressed store, hash-verified

184
185
186def _get_linear_ramps(padded, axis, width_pair, end_value_pair):
187 """
188 Construct linear ramps for empty-padded array in given dimension.
189
190 Parameters
191 ----------
192 padded : ndarray
193 Empty-padded array.
194 axis : int
195 Dimension in which the ramps are constructed.
196 width_pair : (int, int)
197 Pair of widths that mark the pad area on both sides in the given
198 dimension.
199 end_value_pair : (scalar, scalar)
200 End values for the linear ramps which form the edge of the fully padded
201 array. These values are included in the linear ramps.
202
203 Returns
204 -------
205 left_ramp, right_ramp : ndarray
206 Linear ramps to set on both sides of `padded`.
207 """
208 edge_pair = _get_edges(padded, axis, width_pair)
209
210 left_ramp, right_ramp = (
211 np.linspace(
212 start=end_value,
213 stop=edge.squeeze(axis), # Dimension is replaced by linspace
214 num=width,
215 endpoint=False,
216 dtype=padded.dtype,
217 axis=axis
218 )
219 for end_value, edge, width in zip(
220 end_value_pair, edge_pair, width_pair
221 )
222 )
223
224 # Reverse linear space in appropriate dimension
225 right_ramp = right_ramp[_slice_at_axis(slice(None, None, -1), axis)]
226
227 return left_ramp, right_ramp
228
229
230def _get_stats(padded, axis, width_pair, length_pair, stat_func):

Callers 1

padFunction · 0.85

Calls 4

_get_edgesFunction · 0.85
_slice_at_axisFunction · 0.85
linspaceMethod · 0.80
squeezeMethod · 0.45

Tested by

no test coverage detected