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

FEniCS / ffcx / 11642291501

02 Nov 2024 11:16AM UTC coverage: 81.168% (+0.5%) from 80.657%
11642291501

push

github

web-flow
Upload to coveralls and docs from CI job running against python 3.12 (#726)

3474 of 4280 relevant lines covered (81.17%)

0.81 hits per line

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

84.38
/ffcx/codegeneration/utils.py
1
# Copyright (C) 2020-2024 Michal Habera, Chris Richardson and Garth N. Wells
2
#
3
# This file is part of FFCx.(https://www.fenicsproject.org)
4
#
5
# SPDX-License-Identifier:    LGPL-3.0-or-later
6
"""Utilities."""
7

8
import typing
1✔
9

10
import numpy as np
1✔
11
import numpy.typing as npt
1✔
12

13

14
def dtype_to_c_type(dtype: typing.Union[npt.DTypeLike, str]) -> str:
1✔
15
    """For a NumPy dtype, return the corresponding C type.
16

17
    Args:
18
        dtype: Numpy data type,
19

20
    Returns:
21
        Corresponding C type.
22
    """
23
    # Note: Possible aliases, e.g. numpy.longdouble, should test against char ID
24
    if np.dtype(dtype).char == "g":
1✔
25
        return "long double"
×
26
    if np.dtype(dtype) == np.intc:
1✔
27
        return "int"
1✔
28
    elif np.dtype(dtype).char == "f":
1✔
29
        return "float"
1✔
30
    elif np.dtype(dtype).char == "d":
1✔
31
        return "double"
1✔
32
    elif np.dtype(dtype) == np.complex64:
1✔
33
        return "float _Complex"
1✔
34
    elif np.dtype(dtype) == np.complex128:
1✔
35
        return "double _Complex"
1✔
36
    else:
37
        raise RuntimeError(f"Unknown NumPy type for: {dtype}")
×
38

39

40
def dtype_to_scalar_dtype(dtype: typing.Union[npt.DTypeLike, str]) -> np.dtype:
1✔
41
    """For a NumPy dtype, return the corresponding real dtype.
42

43
    Args:
44
        dtype: Numpy data type
45

46
    Returns:
47
        ``numpy.dtype`` for the real component of ``dtype``.
48
    """
49
    if np.issubdtype(dtype, np.floating):
1✔
50
        return np.dtype(dtype)
1✔
51
    elif np.issubdtype(dtype, np.complexfloating):
1✔
52
        return np.dtype(dtype).type(0).real.dtype
1✔
53
    elif np.issubdtype(dtype, np.integer):
1✔
54
        return np.dtype(dtype)
1✔
55
    else:
56
        raise RuntimeError(f"Cannot get value dtype for '{dtype}'. ")
×
57

58

59
def numba_ufcx_kernel_signature(dtype: npt.DTypeLike, xdtype: npt.DTypeLike):
1✔
60
    """Return a Numba C signature for the UFCx ``tabulate_tensor`` interface.
61

62
    Args:
63
        dtype: The scalar type for the finite element data.
64
        xdtype: The geometry float type.
65

66
    Returns:
67
        A Numba signature (``numba.core.typing.templates.Signature``).
68

69
    Raises:
70
        ImportError: If ``numba`` cannot be imported.
71
    """
72
    try:
1✔
73
        import numba.types as types
1✔
74
        from numba import from_dtype
1✔
75

76
        return types.void(
1✔
77
            types.CPointer(from_dtype(dtype)),
78
            types.CPointer(from_dtype(dtype)),
79
            types.CPointer(from_dtype(dtype)),
80
            types.CPointer(from_dtype(xdtype)),
81
            types.CPointer(types.intc),
82
            types.CPointer(types.uint8),
83
        )
84
    except ImportError as e:
×
85
        raise e
×
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

© 2026 Coveralls, Inc