MCPcopy Index your code
hub / github.com/numpy/numpy / _get_linear_ramps

Function _get_linear_ramps

numpy/lib/_arraypad_impl.py:187–228  ·  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

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

Callers 1

padFunction · 0.85

Calls 5

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…