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

peleiden / pelutils / 29704263093

19 Jul 2026 09:23PM UTC coverage: 97.599% (+0.3%) from 97.27%
29704263093

Pull #247

github

asgerius
Cleanup
Pull Request #247: Blob

105 of 107 new or added lines in 6 files covered. (98.13%)

4 existing lines in 1 file now uncovered.

1423 of 1458 relevant lines covered (97.6%)

0.98 hits per line

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

94.74
/pelutils/array/_utils.py
1
import ctypes
1✔
2

3
import numpy as np
1✔
4
import numpy.typing as npt
1✔
5

6
from pelutils.misc._conditional_import import import_torch
1✔
7

8
torch = import_torch()
1✔
9

10

11
def array_ptr(arr: npt.ArrayLike) -> ctypes.c_void_p:
1✔
12
    """Return a pointer to a numpy array or torch tensor which can be used to interact with it in low-level languages like C/C++/Rust.
13

14
    This function is mostly useful when not using Python's C api and instead interfacing with .so files directly with ctypes.
15
    """
16
    if torch is not None and isinstance(arr, torch.Tensor):
1✔
17
        return ctypes.c_void_p(arr.data_ptr())
1✔
18
    if not isinstance(arr, np.ndarray):
1✔
19
        raise TypeError(f"Array should be of type np.ndarray or torch.Tensor, not {type(arr)}")
1✔
20
    if not arr.flags.c_contiguous:
1✔
21
        raise ValueError("Array must be C-contiguous")
1✔
22
    return ctypes.c_void_p(arr.ctypes.data)
1✔
23

24

25
def array_bytes(x: npt.ArrayLike) -> int:
1✔
26
    """Calculate the size of a numpy array or torch tensor in bytes."""
27
    if torch is not None and isinstance(x, torch.Tensor):
1✔
28
        x = x.numpy()
1✔
29
    if isinstance(x, np.ndarray):
1✔
30
        return x.nbytes
1✔
NEW
31
    raise TypeError(f"`x` of type {type(x)} is not a numpy array or torch tensor")
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc