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

daisytuner / sdfglib / 15044057891

15 May 2025 11:42AM UTC coverage: 59.37% (+1.8%) from 57.525%
15044057891

push

github

web-flow
Merge pull request #14 from daisytuner/sanitizers

enables sanitizer on unit tests

63 of 67 new or added lines in 47 files covered. (94.03%)

570 existing lines in 62 files now uncovered.

7356 of 12390 relevant lines covered (59.37%)

505.93 hits per line

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

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

3
#include "sdfg/symbolic/symbolic.h"
4

5
namespace sdfg {
6
namespace symbolic {
7

8
Assumption::Assumption()
8,062✔
9
    : symbol_(symbolic::symbol("")),
4,031✔
10
      lower_bound_(symbolic::infty(-1)),
4,031✔
11
      upper_bound_(symbolic::infty(1)) {
4,031✔
12

13
      };
4,031✔
14

15
Assumption::Assumption(const Symbol& symbol)
2,390✔
16
    : symbol_(symbol), lower_bound_(symbolic::infty(-1)), upper_bound_(symbolic::infty(1)) {
1,195✔
17

18
      };
1,195✔
19

20
Assumption::Assumption(const Assumption& a)
12,514✔
21
    : symbol_(a.symbol_), lower_bound_(a.lower_bound_), upper_bound_(a.upper_bound_) {
6,257✔
22

23
      };
6,257✔
24

25
Assumption& Assumption::operator=(const Assumption& a) {
3,943✔
26
    symbol_ = a.symbol_;
3,943✔
27
    lower_bound_ = a.lower_bound_;
3,943✔
28
    upper_bound_ = a.upper_bound_;
3,943✔
29
    map_ = a.map_;
3,943✔
30
    return *this;
3,943✔
31
};
32

33
const Symbol& Assumption::symbol() const { return symbol_; };
16✔
34

35
const Expression& Assumption::lower_bound() const { return lower_bound_; };
9,264✔
36

37
void Assumption::lower_bound(const Expression& lower_bound) {
1,302✔
38
    lower_bound_ = symbolic::simplify(lower_bound);
1,302✔
39
};
1,302✔
40

41
const Expression& Assumption::upper_bound() const { return upper_bound_; };
9,308✔
42

43
void Assumption::upper_bound(const Expression& upper_bound) {
1,343✔
44
    upper_bound_ = symbolic::simplify(upper_bound);
1,343✔
45
};
1,343✔
46

47
const Integer Assumption::integer_value() const {
9✔
48
    if (eq(upper_bound_, lower_bound_)) {
9✔
49
        if (is_a<SymEngine::Integer>(*upper_bound_)) {
9✔
50
            return rcp_static_cast<const SymEngine::Integer>(upper_bound_);
9✔
51
        }
UNCOV
52
    }
×
53
    return SymEngine::null;
×
54
};
9✔
55

56
const Expression& Assumption::map() const { return map_; };
3,583✔
57

58
void Assumption::map(const Expression& map) {
1,165✔
59
    if (map == SymEngine::null) {
1,165✔
60
        map_ = map;
704✔
61
        return;
704✔
62
    }
63
    map_ = symbolic::simplify(map);
461✔
64
};
1,165✔
65

66
bool Assumption::is_positive() const {
27✔
67
    if (SymEngine::is_a<SymEngine::Integer>(*lower_bound_)) {
27✔
68
        auto lower_bound = SymEngine::rcp_static_cast<const SymEngine::Integer>(lower_bound_);
22✔
69
        if (lower_bound->as_int() > 0) {
22✔
70
            return true;
17✔
71
        }
72
    }
22✔
73
    return false;
10✔
74
};
27✔
75

76
bool Assumption::is_negative() const {
12✔
77
    if (SymEngine::is_a<SymEngine::Integer>(*upper_bound_)) {
12✔
78
        auto upper_bound = SymEngine::rcp_static_cast<const SymEngine::Integer>(upper_bound_);
4✔
79
        if (upper_bound->as_int() < 0) {
4✔
80
            return true;
3✔
81
        }
82
    }
4✔
83
    return false;
9✔
84
};
12✔
85

86
bool Assumption::is_nonnegative() const {
5✔
87
    if (SymEngine::is_a<SymEngine::Integer>(*lower_bound_)) {
5✔
88
        auto upper_bound = SymEngine::rcp_static_cast<const SymEngine::Integer>(lower_bound_);
4✔
89
        if (upper_bound->as_int() >= 0) {
4✔
90
            return true;
3✔
91
        }
92
    }
4✔
93
    return false;
2✔
94
};
5✔
95

96
bool Assumption::is_nonpositive() const {
5✔
97
    if (SymEngine::is_a<SymEngine::Integer>(*upper_bound_)) {
5✔
98
        auto upper_bound = SymEngine::rcp_static_cast<const SymEngine::Integer>(upper_bound_);
2✔
99
        if (upper_bound->as_int() <= 0) {
2✔
100
            return true;
1✔
101
        }
102
    }
2✔
103
    return false;
4✔
104
};
5✔
105

106
Assumption Assumption::create(const symbolic::Symbol& symbol, const types::IType& type) {
704✔
107
    if (auto scalar_type = dynamic_cast<const types::Scalar*>(&type)) {
704✔
108
        auto assum = Assumption(symbol);
704✔
109
        assum.map(SymEngine::null);
704✔
110

111
        types::PrimitiveType primitive_type = scalar_type->primitive_type();
704✔
112
        switch (primitive_type) {
704✔
113
            case types::PrimitiveType::Bool: {
114
                assum.lower_bound(symbolic::zero());
8✔
115
                assum.upper_bound(symbolic::one());
8✔
116
                break;
8✔
117
            }
118
            case types::PrimitiveType::UInt8: {
119
                assum.lower_bound(symbolic::integer(std::numeric_limits<uint8_t>::min()));
3✔
120
                assum.upper_bound(symbolic::integer(std::numeric_limits<uint8_t>::max()));
3✔
121
                break;
3✔
122
            }
123
            case types::PrimitiveType::UInt16: {
124
                assum.lower_bound(symbolic::integer(std::numeric_limits<uint16_t>::min()));
2✔
125
                assum.upper_bound(symbolic::integer(std::numeric_limits<uint16_t>::max()));
2✔
126
                break;
2✔
127
            }
128
            case types::PrimitiveType::UInt32: {
129
                assum.lower_bound(symbolic::integer(std::numeric_limits<uint32_t>::min()));
91✔
130
                assum.upper_bound(symbolic::integer(std::numeric_limits<uint32_t>::max()));
91✔
131
                break;
91✔
132
            }
133
            case types::PrimitiveType::UInt64: {
134
                assum.lower_bound(symbolic::integer(std::numeric_limits<uint64_t>::min()));
387✔
135
                assum.upper_bound(symbolic::infty(1));
387✔
136
                break;
387✔
137
            }
138
            case types::PrimitiveType::Int8: {
139
                assum.lower_bound(symbolic::integer(std::numeric_limits<int8_t>::min()));
6✔
140
                assum.upper_bound(symbolic::integer(std::numeric_limits<int8_t>::max()));
6✔
141
                break;
6✔
142
            }
143
            case types::PrimitiveType::Int16: {
144
                assum.lower_bound(symbolic::integer(std::numeric_limits<int16_t>::min()));
4✔
145
                assum.upper_bound(symbolic::integer(std::numeric_limits<int16_t>::max()));
4✔
146
                break;
4✔
147
            }
148
            case types::PrimitiveType::Int32: {
149
                assum.lower_bound(symbolic::integer(std::numeric_limits<int32_t>::min()));
197✔
150
                assum.upper_bound(symbolic::integer(std::numeric_limits<int32_t>::max()));
197✔
151
                break;
197✔
152
            }
153
            case types::PrimitiveType::Int64: {
154
                assum.lower_bound(symbolic::infty(-1));
6✔
155
                assum.upper_bound(symbolic::infty(1));
6✔
156
                break;
6✔
157
            }
158
            default: {
159
                throw std::runtime_error("Unsupported type");
×
160
            }
161
        };
162
        return std::move(assum);
704✔
163
    } else {
704✔
164
        throw std::runtime_error("Unsupported type");
×
165
    }
166
};
704✔
167

168
void upper_bounds(const symbolic::Symbol& sym, const Assumptions& assumptions,
122✔
169
                  symbolic::SymbolicSet& ubs, symbolic::SymbolicSet& visited) {
170
    if (visited.find(sym) != visited.end()) {
122✔
171
        return;
×
172
    }
173
    visited.insert(sym);
122✔
174

175
    auto ub = assumptions.at(sym).upper_bound();
122✔
176
    if (SymEngine::is_a<SymEngine::Integer>(*ub)) {
122✔
177
        ubs.insert(ub);
×
178
    } else if (SymEngine::is_a<SymEngine::Symbol>(*ub)) {
122✔
179
        auto ub_sym = SymEngine::rcp_static_cast<const SymEngine::Symbol>(ub);
3✔
180
        ubs.insert(ub_sym);
3✔
181

182
        upper_bounds(ub_sym, assumptions, ubs, visited);
3✔
183
    } else if (SymEngine::is_a<SymEngine::Min>(*ub)) {
122✔
184
        auto ub_min = SymEngine::rcp_static_cast<const SymEngine::Min>(ub);
1✔
185
        for (auto& arg : ub_min->get_args()) {
3✔
186
            if (SymEngine::is_a<SymEngine::Integer>(*ub)) {
2✔
187
                ubs.insert(ub);
×
188
            } else if (SymEngine::is_a<SymEngine::Symbol>(*ub)) {
2✔
189
                auto ub_sym = SymEngine::rcp_static_cast<const SymEngine::Symbol>(ub);
×
190
                ubs.insert(ub_sym);
×
191

192
                upper_bounds(ub_sym, assumptions, ubs, visited);
×
193
            } else {
×
194
                ubs.insert(arg);
2✔
195
            }
196
        }
197
    } else {
1✔
198
        ubs.insert(ub);
118✔
199
    }
200
};
122✔
201

202
void upper_bounds(const symbolic::Symbol& sym, const Assumptions& assumptions,
119✔
203
                  symbolic::SymbolicSet& ubs) {
204
    symbolic::SymbolicSet visited;
119✔
205
    upper_bounds(sym, assumptions, ubs, visited);
119✔
206
};
119✔
207

208
void lower_bounds(const symbolic::Symbol& sym, const Assumptions& assumptions,
122✔
209
                  symbolic::SymbolicSet& lbs, symbolic::SymbolicSet& visited) {
210
    if (visited.find(sym) != visited.end()) {
122✔
211
        return;
×
212
    }
213
    visited.insert(sym);
122✔
214

215
    auto lb = assumptions.at(sym).lower_bound();
122✔
216
    if (SymEngine::is_a<SymEngine::Integer>(*lb)) {
122✔
217
        lbs.insert(lb);
120✔
218
    } else if (SymEngine::is_a<SymEngine::Symbol>(*lb)) {
122✔
219
        auto lb_sym = SymEngine::rcp_static_cast<const SymEngine::Symbol>(lb);
1✔
220
        lbs.insert(lb_sym);
1✔
221

222
        lower_bounds(lb_sym, assumptions, lbs, visited);
1✔
223
    } else if (SymEngine::is_a<SymEngine::Max>(*lb)) {
2✔
224
        auto lb_max = SymEngine::rcp_static_cast<const SymEngine::Max>(lb);
1✔
225
        for (auto& arg : lb_max->get_args()) {
3✔
226
            if (SymEngine::is_a<SymEngine::Integer>(*lb)) {
2✔
227
                lbs.insert(lb);
×
228
            } else if (SymEngine::is_a<SymEngine::Symbol>(*lb)) {
2✔
229
                auto lb_sym = SymEngine::rcp_static_cast<const SymEngine::Symbol>(lb);
×
230
                lbs.insert(lb_sym);
×
231

232
                lower_bounds(lb_sym, assumptions, lbs, visited);
×
233
            } else {
×
234
                lbs.insert(arg);
2✔
235
            }
236
        }
237
    } else {
1✔
238
        lbs.insert(lb);
×
239
    }
240
};
122✔
241

242
void lower_bounds(const symbolic::Symbol& sym, const Assumptions& assumptions,
121✔
243
                  symbolic::SymbolicSet& lbs) {
244
    symbolic::SymbolicSet visited;
121✔
245
    lower_bounds(sym, assumptions, lbs, visited);
121✔
246
};
121✔
247

248
}  // namespace symbolic
249
}  // 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

© 2026 Coveralls, Inc