• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

neuml / txtai / 11062719915

27 Sep 2024 01:06AM CUT coverage: 99.946%. Remained the same
11062719915

push

github

davidmezzetti
Update documentation

7406 of 7410 relevant lines covered (99.95%)

1.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/python/txtai/ann/torch.py
1
"""
2
PyTorch module
3
"""
4

5
import numpy as np
1✔
6
import torch
1✔
7

8
from .numpy import NumPy
1✔
9

10

11
class Torch(NumPy):
1✔
12
    """
13
    Builds an ANN index backed by a PyTorch array.
14
    """
15

16
    def __init__(self, config):
1✔
17
        super().__init__(config)
1✔
18

19
        # Define array functions
20
        self.all, self.cat, self.dot, self.zeros = torch.all, torch.cat, torch.mm, torch.zeros
1✔
21
        self.argsort, self.xor = torch.argsort, torch.bitwise_xor
1✔
22

23
    def tensor(self, array):
1✔
24
        # Convert array to Tensor
25
        if isinstance(array, np.ndarray):
1✔
26
            array = torch.from_numpy(array)
1✔
27

28
        # Load to GPU device, if available
29
        return array.cuda() if torch.cuda.is_available() else array
1✔
30

31
    def numpy(self, array):
1✔
32
        return array.cpu().numpy()
1✔
33

34
    def totype(self, array, dtype):
1✔
35
        return array.long() if dtype == np.int64 else array
1✔
36

37
    def settings(self):
1✔
38
        return {"torch": torch.__version__}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc