MCPcopy
hub / github.com/OpenPPL/ppq / generate_indexer

Function generate_indexer

ppq/utils/fetch.py:4–24  ·  view source on GitHub ↗

Sample with a given seed. This function will generates a indexer based on your seed. Args: num_of_fetches (int): [description] num_of_elements (int): [description] seed (int, optional): [description]. Defaults to 0x20211230. Returns: torch.Tensor: [descr

(
    num_of_fetches: int,
    num_of_elements: int,
    seed: int = 0x20211230)

Source from the content-addressed store, hash-verified

2
3
4def generate_indexer(
5 num_of_fetches: int,
6 num_of_elements: int,
7 seed: int = 0x20211230) -> torch.Tensor:
8 """Sample with a given seed. This function will generates a indexer based
9 on your seed.
10
11 Args:
12 num_of_fetches (int): [description]
13 num_of_elements (int): [description]
14 seed (int, optional): [description]. Defaults to 0x20211230.
15
16 Returns:
17 torch.Tensor: [description]
18 """
19
20 indexer = []
21 for i in range(num_of_fetches):
22 indexer.append(seed % num_of_elements)
23 seed = (0x343FD * seed + 0x269EC3) % (2 << 31)
24 return torch.tensor(indexer, dtype=torch.int32)
25
26def generate_torch_indexer(
27 num_of_fetches: int,

Callers 3

tensor_random_fetchFunction · 0.85
channel_random_fetchFunction · 0.85
batch_random_fetchFunction · 0.85

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected