MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / randperm

Function randperm

python/paddle/tensor/random.py:2237–2336  ·  view source on GitHub ↗

Returns a 1-D Tensor filled with random permutation values from 0 to n-1, with ``dtype``. Args: n (int): The upper bound (exclusive), and it should be greater than 0. dtype (str|np.dtype|paddle.dtype|None, optional): The data type of the output Tensor. Suppo

(
    n: int,
    dtype: DTypeLike = "int64",
    name: str | None = None,
    *,
    out: paddle.Tensor | None = None,
    device: PlaceLike | None = None,
    pin_memory: bool = False,
    requires_grad: bool = False,
)

Source from the content-addressed store, hash-verified

2235
2236
2237def randperm(
2238 n: int,
2239 dtype: DTypeLike = "int64",
2240 name: str | None = None,
2241 *,
2242 out: paddle.Tensor | None = None,
2243 device: PlaceLike | None = None,
2244 pin_memory: bool = False,
2245 requires_grad: bool = False,
2246) -> Tensor:
2247 """
2248 Returns a 1-D Tensor filled with random permutation values from 0
2249 to n-1, with ``dtype``.
2250
2251 Args:
2252 n (int): The upper bound (exclusive), and it should be greater than 0.
2253 dtype (str|np.dtype|paddle.dtype|None, optional): The data type of
2254 the output Tensor. Supported data types: int32, int64, float32,
2255 float64. Default is int64.
2256 name (str|None, optional): The default value is None. Normally there is no
2257 need for user to set this property. For more information, please
2258 refer to :ref:`api_guide_Name`.
2259 out(Tensor, optional): The output tensor.
2260 device(PlaceLike|None, optional): The desired device of returned tensor.
2261 pin_memory(bool, optional): If set, return tensor would be allocated in the pinned memory. Works only for CPU tensors. Default: False
2262 requires_grad(bool, optional): If autograd should record operations on the returned tensor. Default: False.
2263
2264 Returns:
2265 Tensor, A 1-D Tensor filled with random permutation values from 0
2266 to n-1, with ``dtype``.
2267
2268 Examples:
2269 .. code-block:: pycon
2270
2271 >>> import paddle
2272
2273 >>> out1 = paddle.randperm(5)
2274 >>> print(out1)
2275 >>> # doctest: +SKIP("Random output")
2276 Tensor(shape=[5], dtype=int64, place=Place(cpu), stop_gradient=True,
2277 [3, 0, 1, 4, 2])
2278 >>> # doctest: -SKIP
2279
2280 >>> out2 = paddle.randperm(7, 'int32')
2281 >>> print(out2)
2282 >>> # doctest: +SKIP("Random output")
2283 Tensor(shape=[7], dtype=int32, place=Place(cpu), stop_gradient=True,
2284 [3, 2, 0, 6, 5, 4, 1])
2285 >>> # doctest: -SKIP
2286
2287 """
2288 device = (
2289 _get_paddle_place(device)
2290 if device is not None
2291 else _current_expected_place()
2292 )
2293 if (
2294 pin_memory

Callers 1

__iter__Method · 0.85

Calls 12

append_opMethod · 0.95
_current_expected_placeFunction · 0.90
in_dynamic_or_pir_modeFunction · 0.90
_get_paddle_placeFunction · 0.85
RuntimeErrorClass · 0.85
ValueErrorClass · 0.85
LayerHelperClass · 0.85
XPUPinnedPlaceMethod · 0.80
pin_memoryMethod · 0.80
check_dtypeFunction · 0.50

Tested by

no test coverage detected