import operator_benchmark as op_bench
import torch
import numpy
from . import configs

"""EmbeddingBag Operator Benchmark"""

class EmbeddingBagBenchmark(op_bench.TorchBenchmarkBase):
    def init(self, embeddingbags, dim, mode, input_size, offset, sparse, include_last_offset, device):
        self.embedding = torch.nn.EmbeddingBag(
            num_embeddings=embeddingbags,
            embedding_dim=dim,
            mode=mode,
            include_last_offset=include_last_offset,
            sparse=sparse).to(device=device)
        numpy.random.seed((1 << 32) - 1)
        self.input = torch.tensor(numpy.random.randint(0, embeddingbags, input_size), device=device).long()
        offsets = torch.LongTensor([offset], device=device)
        self.offset = torch.cat((offsets, torch.tensor([self.input.size(0)], dtype=torch.long)), 0)
        self.set_module_name('embeddingbag')

    def forward(self):
        return self.embedding(self.input, self.offset)

op_bench.generate_pt_test(configs.embeddingbag_short_configs, EmbeddingBagBenchmark)
op_bench.generate_pt_gradient_test(configs.embeddingbag_short_configs, EmbeddingBagBenchmark)


if __name__ == "__main__":
    op_bench.benchmark_runner.main()

[(25, 'operator_benchmark.generate_pt_test', 'op_bench.generate_pt_test', True, 'import operator_benchmark as op_bench\n'), (26, 'operator_benchmark.generate_pt_gradient_test', 'op_bench.generate_pt_gradient_test', True, 'import operator_benchmark as op_bench\n'), (30, 'operator_benchmark.benchmark_runner.main', 'op_bench.benchmark_runner.main', True, 'import operator_benchmark as op_bench\n'), (16, 'numpy.random.seed', 'numpy.random.seed', False, 'import numpy\n'), (18, 'torch.LongTensor', 'torch.LongTensor', False, 'import torch\n'), (10, 'torch.nn.EmbeddingBag', 'torch.nn.EmbeddingBag', False, 'import torch\n'), (17, 'numpy.random.randint', 'numpy.random.randint', False, 'import numpy\n')]