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

daisytuner / docc / 22151769687

18 Feb 2026 06:09PM UTC coverage: 64.742%. First build
22151769687

push

github

web-flow
Merge pull request #526 from daisytuner/native-ndarray

Python - Native Tensor Support: Update operations to use tensor type

2783 of 4104 new or added lines in 42 files covered. (67.81%)

23724 of 36644 relevant lines covered (64.74%)

368.06 hits per line

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

96.97
/python/docc/python/functions/math.py
1
from docc.sdfg import (
4✔
2
    Scalar,
3
    PrimitiveType,
4
    CMathFunction,
5
)
6

7

8
class MathHandler:
4✔
9
    """Handler for Python math module functions and built-in math operations."""
10

11
    def __init__(self, expression_visitor):
4✔
12
        self._ev = expression_visitor
4✔
13

14
        # Mapping of math function names to CMathFunction enum values
15
        self.math_funcs = {
4✔
16
            # Trigonometric functions
17
            "sin": CMathFunction.sin,
18
            "cos": CMathFunction.cos,
19
            "tan": CMathFunction.tan,
20
            "asin": CMathFunction.asin,
21
            "acos": CMathFunction.acos,
22
            "atan": CMathFunction.atan,
23
            "atan2": CMathFunction.atan2,
24
            # Hyperbolic functions
25
            "sinh": CMathFunction.sinh,
26
            "cosh": CMathFunction.cosh,
27
            "tanh": CMathFunction.tanh,
28
            "asinh": CMathFunction.asinh,
29
            "acosh": CMathFunction.acosh,
30
            "atanh": CMathFunction.atanh,
31
            # Exponential and logarithmic functions
32
            "exp": CMathFunction.exp,
33
            "exp2": CMathFunction.exp2,
34
            "expm1": CMathFunction.expm1,
35
            "log": CMathFunction.log,
36
            "log2": CMathFunction.log2,
37
            "log10": CMathFunction.log10,
38
            "log1p": CMathFunction.log1p,
39
            # Power functions
40
            "pow": CMathFunction.pow,
41
            "sqrt": CMathFunction.sqrt,
42
            "cbrt": CMathFunction.cbrt,
43
            "hypot": CMathFunction.hypot,
44
            # Rounding and remainder functions
45
            "abs": CMathFunction.fabs,
46
            "fabs": CMathFunction.fabs,
47
            "ceil": CMathFunction.ceil,
48
            "floor": CMathFunction.floor,
49
            "trunc": CMathFunction.trunc,
50
            "fmod": CMathFunction.fmod,
51
            "remainder": CMathFunction.remainder,
52
            # Floating-point manipulation functions
53
            "copysign": CMathFunction.copysign,
54
            # Other functions
55
            "fma": CMathFunction.fma,
56
        }
57

58
    # Expose parent properties for convenience
59
    @property
4✔
60
    def builder(self):
4✔
61
        return self._ev.builder
4✔
62

63
    @property
4✔
64
    def container_table(self):
4✔
65
        return self._ev.container_table
4✔
66

67
    def _add_read(self, block, expr_str, debug_info=None):
4✔
68
        return self._ev._add_read(block, expr_str, debug_info)
4✔
69

70
    def visit(self, node):
4✔
71
        return self._ev.visit(node)
4✔
72

73
    def has_handler(self, func_name):
4✔
74
        """Check if this handler can handle the given function name."""
75
        return func_name in self.math_funcs
4✔
76

77
    def handle_math_call(self, node, func_name):
4✔
78
        """Handle a call to a math function (e.g., sin, cos, sqrt, etc.)."""
79
        if func_name not in self.math_funcs:
4✔
NEW
80
            raise NotImplementedError(f"Math function {func_name} not supported")
×
81

82
        args = [self.visit(arg) for arg in node.args]
4✔
83

84
        tmp_name = self.builder.find_new_name("_tmp_")
4✔
85
        dtype = Scalar(PrimitiveType.Double)
4✔
86
        self.builder.add_container(tmp_name, dtype, False)
4✔
87
        self.container_table[tmp_name] = dtype
4✔
88

89
        block = self.builder.add_block()
4✔
90
        t_out = self.builder.add_access(block, tmp_name)
4✔
91

92
        t_task = self.builder.add_cmath(block, self.math_funcs[func_name])
4✔
93

94
        for i, arg in enumerate(args):
4✔
95
            t_arg, arg_sub = self._add_read(block, arg)
4✔
96
            self.builder.add_memlet(block, t_arg, "void", t_task, f"_in{i+1}", arg_sub)
4✔
97

98
        self.builder.add_memlet(block, t_task, "_out", t_out, "void", "")
4✔
99
        return tmp_name
4✔
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