Skip to content

Commit c6d2a1b

Browse files
committed
Clear spurious (?) warning in filldimv()
* ra/expr.hh (filldimv): Resize, take Iterator, manually fill dimv[..].len. (default_dims): Adapt user. (Ptr::mov, Cell::mov): Remove aggressive-optimizations diagnostic override, caused by Seq<int>. * ra/big.hh: Adapt users. * test/wrank.c, test/small-1.cc: Don't use Seq<int>. * ra/ra.hh: Add binary op %.
1 parent 8a08f22 commit c6d2a1b

File tree

9 files changed

+49
-53
lines changed

9 files changed

+49
-53
lines changed

TODO

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ checkbox [C-ct] flip TODO
77

88
* TODO [1/7]
99
- [-] Bugs [5/16]
10+
- [ ] We shouldn't need ra::iota(3, ra::dim_t(4)) to get iota to use Seq<dim_t> instead of Seq<int>.
1011
- [ ] Fix reduction-1.cc: "real_part(iter<1>(m)) = real_part(iter<1>(c))"
1112
- [ ] Invalid expressions that aren't caught by Match, either bc it makes assumptions, or bc
1213
Match isn't even involved. See checks.cc.

examples/maxwell.cc

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,16 @@ int main()
6363
auto time_A = Benchmark::clock::now()-t0;
6464

6565
// FIXME should try to traverse the array once, e.g. explode() = pack(...), but we need to wrap around boundaries.
66-
auto diff = [&DA, &A, &delta](auto k_, real factor)
67-
{
68-
constexpr int k = k_;
69-
const int o = DA.len(k);
70-
if (o>=2) {
71-
DA(HH<k>, iota(o-2, 1), HH<4-k>, k) = (A(HH<k>, iota(o-2, 2)) - A(HH<k>, iota(o-2, 0)));
72-
DA(HH<k>, 0, HH<4-k>, k) = (A(HH<k>, 1) - A(HH<k>, o-1));
73-
DA(HH<k>, o-1, HH<4-k>, k) = (A(HH<k>, 0) - A(HH<k>, o-2));
74-
DA(HH<5>, k) *= factor;
75-
}
76-
};
66+
auto diff = [&DA, &A, &delta](auto k_, real factor) {
67+
constexpr int k = k_;
68+
const int o = DA.len(k);
69+
if (o>=2) {
70+
DA(HH<k>, iota(o-2, 1), HH<4-k>, k) = (A(HH<k>, iota(o-2, 2)) - A(HH<k>, iota(o-2, 0)));
71+
DA(HH<k>, 0, HH<4-k>, k) = (A(HH<k>, 1) - A(HH<k>, o-1));
72+
DA(HH<k>, o-1, HH<4-k>, k) = (A(HH<k>, 0) - A(HH<k>, o-2));
73+
DA(HH<5>, k) *= factor;
74+
}
75+
};
7776

7877
t0 = Benchmark::clock::now();
7978
diff(ic<0>, +1/(2*delta));

ra/big.hh

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,6 @@ braces_shape(braces<T, r> const & l)
4545
return [&l]<int ... i>(ilist_t<i ...>){ return std::array { braces_len<i, T, r>(l) ... }; }(mp::iota<r>{});
4646
}
4747

48-
constexpr void
49-
resize(auto & a, dim_t s)
50-
{
51-
if constexpr (ANY==size_s(a)) {
52-
RA_CK(s>=0, "Bad resize ", s, ".");
53-
a.resize(s);
54-
} else {
55-
RA_CK(s==start(a).len(0) || UNB==s, "Bad resize ", s, ", need ", start(a).len(0), ".");
56-
}
57-
}
58-
5948
// FIXME avoid duplicating cp, dimv from Container without being parent. Parameterize on Dimv, like Cell.
6049
// FIXME constructor checks (lens>=0, steps inside, etc.).
6150
template <class P, rank_t RANK>
@@ -81,11 +70,11 @@ struct ViewBig
8170
constexpr ViewBig(Dimv const & dimv_, P cp_): dimv(dimv_), cp(cp_) {} // [ra36]
8271
constexpr ViewBig(auto const & s, P cp_): cp(cp_)
8372
{
84-
ra::resize(dimv, ra::size(s)); // [ra37]
8573
if constexpr (std::is_convertible_v<value_t<decltype(s)>, Dim>) {
74+
ra::resize(dimv, ra::size(s)); // [ra37]
8675
start(dimv) = s;
8776
} else {
88-
filldimv(s, dimv);
77+
filldimv(start(s), dimv);
8978
}
9079
}
9180
constexpr ViewBig(std::initializer_list<dim_t> s, P cp_): ViewBig(start(s), cp_) {}
@@ -228,8 +217,7 @@ struct Container: public ViewBig<typename storage_traits<Store>::T *, RANK>
228217
static_assert(!std::is_convertible_v<value_t<decltype(s)>, Dim>);
229218
RA_CK(1==ra::rank(s), "Rank mismatch for init shape.");
230219
static_assert(ANY==RANK || ANY==size_s(s) || RANK==size_s(s) || UNB==size_s(s), "Bad shape for rank.");
231-
ra::resize(dimv, ra::size(s)); // [ra37]
232-
store = storage_traits<Store>::create(filldimv(s, dimv));
220+
store = storage_traits<Store>::create(filldimv(start(s), dimv));
233221
cp = storage_traits<Store>::data(store);
234222
}
235223
constexpr void init(dim_t s) { init(std::array {s}); } // scalar allowed as shape if rank is 1.
@@ -287,8 +275,7 @@ struct Container: public ViewBig<typename storage_traits<Store>::T *, RANK>
287275
}
288276
constexpr void resize(auto const & s) requires (1==rank_s(s))
289277
{
290-
ra::resize(dimv, 0==rank_s(s) ? 1 : ra::size(s));
291-
store.resize(filldimv(s, dimv)); cp = store.data();
278+
store.resize(filldimv(start(s), dimv)); cp = store.data();
292279
}
293280
// template + RA_FW wouldn't work for push_back(brace-enclosed-list).
294281
constexpr void push_back(T && t)
@@ -470,7 +457,7 @@ reshape(ViewBig<P, RANK> const & a, S && sb_)
470457
if (sa[a.rank()-i-1]!=sb[b.rank()-i-1]) {
471458
RA_CK(is_c_order(a, false) && la>=lb, "Reshape with copy not implemented.");
472459
// FIXME ViewBig(SS const & s, T * p). Cf [ra37].
473-
filldimv(sb, b.dimv);
460+
filldimv(start(sb), b.dimv);
474461
for (int j=0; j!=b.rank(); ++j) {
475462
b.dimv[j].step *= a.step(a.rank()-1);
476463
}

ra/expr.hh

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ maybe_len(auto const & v, K k) { if constexpr (is_constant<K> && (ANY!=v.len_s(k
105105

106106
// Sequence iterator.
107107

108-
template <class I>
108+
template <class I=dim_t>
109109
struct Seq
110110
{
111111
I i;
@@ -232,25 +232,33 @@ struct Dim { dim_t len, step; };
232232
inline std::ostream &
233233
operator<<(std::ostream & o, Dim const & dim) { std::print(o, "[Dim {} {}]", dim.len, dim.step); return o; }
234234

235+
constexpr void
236+
resize(auto & a, dim_t s)
237+
{
238+
if constexpr (ANY==size_s(a)) {
239+
RA_CK(s>=0, "Bad resize ", s, ".");
240+
a.resize(s);
241+
} else {
242+
RA_CK(s==start(a).len(0) || UNB==s, "Bad resize ", s, ", need ", start(a).len(0), ".");
243+
}
244+
}
245+
235246
constexpr dim_t
236-
filldimv(auto const & shape, auto & dimv)
247+
filldimv(Iterator auto && p, auto & dimv)
237248
{
238-
map(&Dim::len, dimv) = shape;
249+
ra::resize(dimv, 0==rank_s(p) ? 1 : ra::size(p)); // [ra37]
250+
for (rank_t k=0; k<ra::size(dimv); ++k, p.mov(p.step(0))) { dimv[k].len = *p; }
239251
dim_t s = 1;
240252
for (int k=ra::size(dimv); --k>=0;) {
241253
dimv[k].step = s;
242254
RA_CK(dimv[k].len>=0, "Bad len[", k, "] ", dimv[k].len, ".");
243-
// gcc 14.2, no warning with sanitizers
244-
#pragma GCC diagnostic push
245-
#pragma GCC diagnostic warning "-Wmaybe-uninitialized"
246255
s *= dimv[k].len;
247-
#pragma GCC diagnostic pop
248256
}
249257
return s;
250258
}
251259

252260
consteval auto
253-
default_dims(auto const & lv) { std::array<Dim, ra::size(lv)> dv; filldimv(lv, dv); return dv; };
261+
default_dims(auto const & lv) { std::array<Dim, ra::size(lv)> dv; filldimv(start(lv), dv); return dv; };
254262

255263
constexpr rank_t rank_sum(rank_t a, rank_t b) { return ANY==a || ANY==b ? ANY : a+b; }
256264
constexpr rank_t rank_diff(rank_t a, rank_t b) { return ANY==a || ANY==b ? ANY : a-b; }
@@ -325,10 +333,7 @@ struct Cell: public std::conditional_t<is_constant<Dimv>, CellSmall<P, Dimv, Spe
325333
constexpr operator decltype(*c.cp) () const { return to_scalar(*this); }
326334
constexpr auto save() const { return c.cp; }
327335
constexpr void load(P p) { c.cp=p; }
328-
#pragma GCC diagnostic push
329-
#pragma GCC diagnostic warning "-Waggressive-loop-optimizations" // gcc14.3/15.1 -O3 only
330336
constexpr void mov(dim_t d) { std::ranges::advance(c.cp, d); }
331-
#pragma GCC diagnostic pop
332337
};
333338

334339
// rank 1 special case for fovs or iota. FIXME make Ptr a Slice with iter() -> Cell.
@@ -365,10 +370,7 @@ struct Ptr final
365370
constexpr decltype(*cp) operator*() const { return *cp; }
366371
constexpr auto save() const { return cp; }
367372
constexpr void load(P p) { cp=p; }
368-
#pragma GCC diagnostic push
369-
#pragma GCC diagnostic warning "-Waggressive-loop-optimizations" // gcc14.3/15.1 -O3 only
370373
constexpr void mov(dim_t d) { std::ranges::advance(cp, d); }
371-
#pragma GCC diagnostic pop
372374
};
373375

374376
template <class X> using sarg = std::conditional_t<is_constant<std::decay_t<X>> || is_scalar<X>, std::decay_t<X>, X>;
@@ -496,9 +498,10 @@ reframe(A && a, Dest)
496498
}
497499
}
498500

501+
// I != dim_t may warn "-Waggressive-loop-optimizations" in std::advance(i, ...) in gcc14/15.1 -O3
499502
template <int w=0, class I=dim_t, class N=ic_t<dim_t(UNB)>, class S=ic_t<dim_t(1)>>
500503
constexpr auto
501-
iota(N && n=N {}, I && i=0, S && s=S(maybe_step<S>))
504+
iota(N && n=N {}, I && i=dim_t(0), S && s=S(maybe_step<S>))
502505
{
503506
return reframe(Ptr<Seq<sarg<I>>, sarg<N>, sarg<S>> { {RA_FW(i)}, RA_FW(n), RA_FW(s) }, ilist_t<w> {});
504507
}

ra/ra.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ DEF_NAMED_BINARY_OP(<, std::less<>) DEF_NAMED_BINARY_OP(>=, std::greate
223223
DEF_NAMED_BINARY_OP(<=, std::less_equal<>) DEF_NAMED_BINARY_OP(!=, std::not_equal_to<>)
224224
DEF_NAMED_BINARY_OP(|, std::bit_or<>) DEF_NAMED_BINARY_OP(&, std::bit_and<>)
225225
DEF_NAMED_BINARY_OP(^, std::bit_xor<>) DEF_NAMED_BINARY_OP(<=>, std::compare_three_way)
226+
DEF_NAMED_BINARY_OP(%, std::modulus<>)
226227
#undef DEF_NAMED_BINARY_OP
227228

228229
// FIXME address sanitizer complains in bench-optimize.cc if we use std::identity. Maybe false positive

ra/small.hh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,12 @@ fromb(auto pl, auto ds, auto && bv, int bk, auto && a, int ak)
156156
{
157157
if constexpr (dobv) {
158158
#pragma GCC diagnostic push
159-
#pragma GCC diagnostic warning "-Waggressive-loop-optimizations" // gcc14.3/15.2 -DRA_CHECK=0 -O3
159+
#pragma GCC diagnostic warning "-Waggressive-loop-optimizations" // gcc14/15.2 -DRA_CHECK=0 -O3
160160
for (; ak<ra::rank(a); ++ak, ++bk) {
161161
#pragma GCC diagnostic pop
162162
#pragma GCC diagnostic push
163-
#pragma GCC diagnostic warning "-Warray-bounds" // gcc14.3/15.2 --no-sanitize -O2 -O3
164-
#pragma GCC diagnostic warning "-Wstringop-overflow" // gcc14.3/15.2 --no-sanitize -O2 -O3
163+
#pragma GCC diagnostic warning "-Warray-bounds" // gcc14/15.2 --no-sanitize -O2 -O3
164+
#pragma GCC diagnostic warning "-Wstringop-overflow" // gcc14/15.2 --no-sanitize -O2 -O3
165165
bv[bk] = a.dimv[ak];
166166
#pragma GCC diagnostic pop
167167
}
@@ -426,13 +426,13 @@ struct ViewSmall
426426
// T not is_scalar [ra44]
427427
constexpr ViewSmall const & operator=(T const & t) const { start(*this)=ra::scalar(t); return *this; }
428428
// cf RA_ASSIGNOPS_ITER [ra38] [ra34]
429-
ViewSmall const & operator=(ViewSmall const & x) const { start(*this) = x; return *this; }
429+
ViewSmall const & operator=(ViewSmall const & x) const { start(*this)=x; return *this; }
430430
#define ASSIGNOPS(OP) \
431431
constexpr ViewSmall const & operator OP(Iterator auto && x) const { start(*this) OP RA_FW(x); return *this; } \
432432
constexpr ViewSmall const & operator OP(auto const & x) const { start(*this) OP x; return *this; }
433433
FOR_EACH(ASSIGNOPS, =, *=, +=, -=, /=)
434434
#undef ASSIGNOPS
435-
template <int s, int o=0> constexpr auto as() const { return from(*this, ra::iota(ra::ic<s>, o)); }
435+
template <dim_t s, dim_t o=0> constexpr auto as() const { return from(*this, ra::iota(ic<s>, o)); }
436436
template <rank_t c=0> constexpr auto iter() const { return Cell<P, ic_t<dimv>, ic_t<c>>(cp); }
437437
constexpr auto iter(rank_t c) const { return Cell<P, decltype(dimv) const &, dim_t>(cp, dimv, c); }
438438
constexpr auto begin() const { if constexpr (is_c_order_dimv(dimv)) return cp; else return STLIterator(iter()); }
@@ -503,8 +503,8 @@ SmallArray<T, Dimv, std::tuple<nested_args ...>>
503503
{
504504
view() = { x ... };
505505
}
506-
constexpr SmallArray(auto const & x) { view() = x; }
507-
constexpr SmallArray(Iterator auto && x) { view() = RA_FW(x); }
506+
constexpr SmallArray(auto const & x) { view()=x; }
507+
constexpr SmallArray(Iterator auto && x) { view()=RA_FW(x); }
508508
#define ASSIGNOPS(OP) \
509509
constexpr SmallArray & operator OP(auto const & x) { view() OP x; return *this; } \
510510
constexpr SmallArray & operator OP(Iterator auto && x) { view() OP RA_FW(x); return *this; }

test/iota.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,10 @@ int main()
116116
tr.test_eq(-2, j.s);
117117
tr.strict().test_eq(ra::start({-1, -3, -5}), j);
118118
}
119+
tr.section("truncated sequence");
120+
{
121+
auto i = ra::ii({7, 7, 7}, uint8_t(0));
122+
tr.strict().test_eq(ra::ii({7, 7, 7}) % 256, i);
123+
}
119124
return tr.summary();
120125
}

test/small-1.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ int main()
461461
}
462462
tr.section("ViewSmall of Seq");
463463
{
464-
ra::ViewSmall<ra::Seq<int>, ra::ic_t<std::array {ra::Dim {3, 2}, ra::Dim {2, 1}}>> a(ra::Seq {1});
464+
ra::ViewSmall<ra::Seq<>, ra::ic_t<std::array {ra::Dim {3, 2}, ra::Dim {2, 1}}>> a(ra::Seq<> {1});
465465
std::println(cout, "{:c:2}\n", transpose(a));
466466
tr.test_eq(a, 1+ra::Small<int, 3, 2> {{0, 1}, {2, 3}, {4, 5}});
467467
}

test/wrank.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ int main()
355355
}
356356
tr.section("Reframe as transpose");
357357
{
358-
ra::ViewSmall<ra::Seq<int>, ra::ic_t<ra::default_dims(std::array<int, 3> {2, 3, 4})>> a(ra::Seq<int> {0});
358+
ra::ViewSmall<ra::Seq<>, ra::ic_t<ra::default_dims(std::array<int, 3> {2, 3, 4})>> a(ra::Seq<> {0});
359359
auto test = [&](auto dest) { tr.strict().test_eq(transpose(a, dest), reframe(start(a), dest)); };
360360
test(ra::ilist_t<0, 1, 2> {});
361361
test(ra::ilist_t<1, 2, 0> {});

0 commit comments

Comments
 (0)