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

daisytuner / sdfglib / 17656823807

11 Sep 2025 08:42PM UTC coverage: 60.447% (+1.1%) from 59.335%
17656823807

Pull #219

github

web-flow
Merge d5416236f into 6c1992b40
Pull Request #219: stdlib Library Nodes and ConstantNodes

460 of 1635 new or added lines in 81 files covered. (28.13%)

93 existing lines in 35 files now uncovered.

9385 of 15526 relevant lines covered (60.45%)

107.21 hits per line

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

59.15
/src/symbolic/symbolic.cpp
1
#include "sdfg/symbolic/symbolic.h"
2

3
#include <string>
4

5
#include "sdfg/exceptions.h"
6
#include "sdfg/types/type.h"
7
#include "symengine/functions.h"
8
#include "symengine/logic.h"
9

10
namespace sdfg {
11
namespace symbolic {
12

13
Symbol symbol(const std::string& name) {
9,771✔
14
    if (name == "null") {
9,771✔
15
        throw InvalidSDFGException("null is not a valid symbol");
×
16
    } else if (name == "NULL") {
9,771✔
17
        throw InvalidSDFGException("NULL is not a valid symbol");
×
18
    } else if (name == "nullptr") {
9,771✔
19
        throw InvalidSDFGException("nullptr is not a valid symbol");
×
20
    }
21

22
    return SymEngine::symbol(name);
9,771✔
23
};
×
24

25
Integer integer(int64_t value) { return SymEngine::integer(value); };
4,319✔
26

27
Integer zero() { return symbolic::integer(0); };
1,450✔
28

29
Integer one() { return symbolic::integer(1); };
675✔
30

31
Infty infty(int direction) { return SymEngine::infty(direction); };
3,403✔
32

33
Condition __false__() { return SymEngine::boolean(false); };
75✔
34

35
Condition __true__() { return SymEngine::boolean(true); };
24✔
36

37
Symbol __nullptr__() { return SymEngine::symbol("__daisy_nullptr"); };
5✔
38

39
bool is_nullptr(const Symbol& symbol) { return symbol->get_name() == "__daisy_nullptr"; };
2,060✔
40

41
bool is_pointer(const Symbol& symbol) { return is_nullptr(symbol); };
429✔
42

UNCOV
43
bool is_nv(const Symbol& symbol) {
×
UNCOV
44
    if (symbol == threadIdx_x() || symbol == threadIdx_y() || symbol == threadIdx_z() || symbol == blockIdx_x() ||
×
UNCOV
45
        symbol == blockIdx_y() || symbol == blockIdx_z() || symbol == blockDim_x() || symbol == blockDim_y() ||
×
UNCOV
46
        symbol == blockDim_z() || symbol == gridDim_x() || symbol == gridDim_y() || symbol == gridDim_z()) {
×
47
        return true;
×
48
    } else {
UNCOV
49
        return false;
×
50
    }
UNCOV
51
};
×
52

53
/***** Logical Expressions *****/
54

55
Condition And(const Condition& lhs, const Condition& rhs) { return SymEngine::logical_and({lhs, rhs}); };
32✔
56

57
Condition Or(const Condition& lhs, const Condition& rhs) { return SymEngine::logical_or({lhs, rhs}); };
95✔
58

59
Condition Not(const Condition& expr) { return expr->logical_not(); };
9✔
60

61
bool is_true(const Expression& expr) { return SymEngine::eq(*SymEngine::boolTrue, *expr); };
1,001✔
62

63
bool is_false(const Expression& expr) { return SymEngine::eq(*SymEngine::boolFalse, *expr); };
6✔
64

65
/***** Integer Functions *****/
66

67
Expression add(const Expression& lhs, const Expression& rhs) { return SymEngine::add(lhs, rhs); };
3,508✔
68

69
Expression sub(const Expression& lhs, const Expression& rhs) { return SymEngine::sub(lhs, rhs); };
299✔
70

71
Expression mul(const Expression& lhs, const Expression& rhs) { return SymEngine::mul(lhs, rhs); };
3,987✔
72

73
Expression div(const Expression& lhs, const Expression& rhs) {
1✔
74
    if (eq(rhs, integer(1))) {
1✔
75
        return lhs;
×
76
    } else if (SymEngine::is_a<SymEngine::Integer>(*lhs) && SymEngine::is_a<SymEngine::Integer>(*rhs)) {
1✔
77
        auto a = SymEngine::rcp_static_cast<const SymEngine::Integer>(lhs)->as_int();
×
78
        auto b = SymEngine::rcp_static_cast<const SymEngine::Integer>(rhs)->as_int();
×
79
        return integer(a / b);
×
80
    }
81
    auto idiv = SymEngine::function_symbol("idiv", {lhs, rhs});
1✔
82
    return idiv;
1✔
83
};
2✔
84

85
Expression min(const Expression& lhs, const Expression& rhs) { return SymEngine::min({lhs, rhs}); };
2,908✔
86

87
Expression max(const Expression& lhs, const Expression& rhs) { return SymEngine::max({lhs, rhs}); };
2,037✔
88

89
Expression mod(const Expression& lhs, const Expression& rhs) {
×
90
    if (SymEngine::is_a<SymEngine::Integer>(*lhs) && SymEngine::is_a<SymEngine::Integer>(*rhs)) {
×
91
        auto a = SymEngine::rcp_static_cast<const SymEngine::Integer>(lhs)->as_int();
×
92
        auto b = SymEngine::rcp_static_cast<const SymEngine::Integer>(rhs)->as_int();
×
93
        return integer(a % b);
×
94
    }
95
    auto imod = SymEngine::function_symbol("imod", {lhs, rhs});
×
96
    return imod;
×
97
};
×
98

99
Expression pow(const Expression& base, const Expression& exp) { return SymEngine::pow(base, exp); };
3✔
100

101
Expression size_of_type(const types::IType& type) {
6✔
102
    auto so = SymEngine::make_rcp<SizeOfTypeFunction>(type);
6✔
103
    return so;
6✔
104
}
6✔
105

106
/***** Comparisions *****/
107

108
Condition Eq(const Expression& lhs, const Expression& rhs) { return SymEngine::Eq(lhs, rhs); };
24✔
109

110
Condition Ne(const Expression& lhs, const Expression& rhs) { return SymEngine::Ne(lhs, rhs); };
13✔
111

112
Condition Lt(const Expression& lhs, const Expression& rhs) { return SymEngine::Lt(lhs, rhs); };
223✔
113

114
Condition Gt(const Expression& lhs, const Expression& rhs) { return SymEngine::Gt(lhs, rhs); };
264✔
115

116
Condition Le(const Expression& lhs, const Expression& rhs) { return SymEngine::Le(lhs, rhs); };
420✔
117

118
Condition Ge(const Expression& lhs, const Expression& rhs) { return SymEngine::Ge(lhs, rhs); };
1,215✔
119

120
/***** Modification *****/
121

122
Expression expand(const Expression& expr) {
166✔
123
    auto new_expr = SymEngine::expand(expr);
166✔
124
    return new_expr;
166✔
125
};
166✔
126

127
Expression simplify(const Expression& expr) {
178✔
128
    if (SymEngine::is_a<SymEngine::FunctionSymbol>(*expr)) {
178✔
129
        auto func_sym = SymEngine::rcp_static_cast<const SymEngine::FunctionSymbol>(expr);
×
130
        auto func_id = func_sym->get_name();
×
131
        if (func_id == "idiv") {
×
132
            auto lhs = func_sym->get_args()[0];
×
133
            auto rhs = func_sym->get_args()[1];
×
134
            if (SymEngine::is_a<SymEngine::Mul>(*lhs) && SymEngine::is_a<SymEngine::Integer>(*rhs)) {
×
135
                auto lhs_mul = SymEngine::rcp_static_cast<const SymEngine::Mul>(lhs);
×
136
                auto rhs_int = SymEngine::rcp_static_cast<const SymEngine::Integer>(rhs);
×
137
                auto lhs_args = lhs_mul->get_args();
×
138

139
                bool skipped = false;
×
140
                Expression new_mul = SymEngine::integer(1);
×
141
                for (auto& arg : lhs_args) {
×
142
                    if (eq(arg, rhs_int) && !skipped) {
×
143
                        skipped = true;
×
144
                    } else {
×
145
                        new_mul = SymEngine::mul(new_mul, arg);
×
146
                    }
147
                }
148
                if (skipped) {
×
149
                    return new_mul;
×
150
                }
151
            } else if (SymEngine::is_a<SymEngine::Integer>(*lhs) && SymEngine::is_a<SymEngine::Integer>(*rhs)) {
×
152
                auto a = SymEngine::rcp_static_cast<const SymEngine::Integer>(lhs)->as_int();
×
153
                auto b = SymEngine::rcp_static_cast<const SymEngine::Integer>(rhs)->as_int();
×
154
                return integer(a / b);
×
155
            }
156
        } else if (func_id == "imod") {
×
157
            auto lhs = func_sym->get_args()[0];
×
158
            auto rhs = func_sym->get_args()[1];
×
159
            if (SymEngine::is_a<SymEngine::Integer>(*lhs) && SymEngine::is_a<SymEngine::Integer>(*rhs)) {
×
160
                auto a = SymEngine::rcp_static_cast<const SymEngine::Integer>(lhs)->as_int();
×
161
                auto b = SymEngine::rcp_static_cast<const SymEngine::Integer>(rhs)->as_int();
×
162
                return integer(a % b);
×
163
            }
164
        }
×
165
    }
×
166

167
    try {
168
        auto new_expr = SymEngine::simplify(expr);
178✔
169
        return new_expr;
178✔
170
    } catch (const SymEngine::SymEngineException& e) {
178✔
171
        std::cout << "Error simplifying expression: " << e.what() << std::endl;
×
172
        return expr;
×
173
    }
×
174
};
178✔
175

176
bool eq(const Expression& lhs, const Expression& rhs) { return SymEngine::eq(*lhs, *rhs); };
2,310✔
177

178
bool uses(const Expression& expr, const Symbol& sym) { return SymEngine::has_symbol(*expr, *sym); };
196✔
179

180
bool uses(const Expression& expr, const std::string& name) { return symbolic::uses(expr, symbol(name)); };
23✔
181

182
SymbolSet atoms(const Expression& expr) {
4,248✔
183
    SymbolSet atoms;
4,248✔
184
    for (auto& atom : SymEngine::atoms<const SymEngine::Basic>(*expr)) {
16,059✔
185
        if (SymEngine::is_a<SymEngine::Symbol>(*atom)) {
11,811✔
186
            atoms.insert(SymEngine::rcp_static_cast<const SymEngine::Symbol>(atom));
4,858✔
187
        }
4,858✔
188
    }
189
    return atoms;
4,248✔
190
};
4,248✔
191

192
ExpressionSet muls(const Expression& expr) { return SymEngine::atoms<const SymEngine::Mul>(*expr); };
×
193

194
Expression subs(const Expression& expr, const Expression& old_expr, const Expression& new_expr) {
1,862✔
195
    SymEngine::map_basic_basic d;
1,862✔
196
    d[old_expr] = new_expr;
1,862✔
197

198
    return expr->subs(d);
1,862✔
199
};
1,862✔
200

201
Condition subs(const Condition& expr, const Expression& old_expr, const Expression& new_expr) {
19✔
202
    SymEngine::map_basic_basic d;
19✔
203
    d[old_expr] = new_expr;
19✔
204

205
    return SymEngine::rcp_static_cast<const SymEngine::Boolean>(expr->subs(d));
19✔
206
};
19✔
207

208
/***** NV Symbols *****/
209

210
Symbol threadIdx_x() { return symbol("threadIdx.x"); };
8✔
211

212
Symbol threadIdx_y() { return symbol("threadIdx.y"); };
8✔
213

214
Symbol threadIdx_z() { return symbol("threadIdx.z"); };
8✔
215

216
Symbol blockDim_x() { return symbol("blockDim.x"); };
8✔
217

218
Symbol blockDim_y() { return symbol("blockDim.y"); };
8✔
219

220
Symbol blockDim_z() { return symbol("blockDim.z"); };
8✔
221

222
Symbol blockIdx_x() { return symbol("blockIdx.x"); };
8✔
223

224
Symbol blockIdx_y() { return symbol("blockIdx.y"); };
8✔
225

226
Symbol blockIdx_z() { return symbol("blockIdx.z"); };
8✔
227

228
Symbol gridDim_x() { return symbol("gridDim.x"); };
8✔
229

230
Symbol gridDim_y() { return symbol("gridDim.y"); };
8✔
231

232
Symbol gridDim_z() { return symbol("gridDim.z"); };
8✔
233

234
} // namespace symbolic
235
} // namespace sdfg
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