Skip to content

Commit 86a2ae8

Browse files
committed
Simplify Cell
* ra/expr.hh (Cell): Minimize base classes. Use the same static/nonstatic pattern for all Iterator functions.
1 parent 69740f8 commit 86a2ae8

File tree

17 files changed

+91
-98
lines changed

17 files changed

+91
-98
lines changed

TODO

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ checkbox [C-ct] flip TODO
8383
is that len_s lets me return ANY for some axes and finite for others and to do that with just
8484
len() would require len(integral constant) overloads possibly -- len(int k) cannot be static
8585
or not depending on k.
86-
- Looked at this again on <2025-09-19 Fri>, added Match::len(is_constant) overload.
86+
- Looked at this again on <2025-09-19 Fri>, added Match::len(is_ctype) overload.
8787
- [ ] Use if consteval to replace rank/rank_s/size/size_s with just rank/size.
8888
- [ ] Support tuple as a kind of foreign vector
8989
- [ ] Iterator type for tuple (like Vector for std::vector).
@@ -123,8 +123,8 @@ Some of these aren't bugs in the sense that I expect to solve them, but more lik
123123
be registered as scalar, but that clashes with how std::ranges sees it. OTOH we don't want
124124
format(std::string_view) to print it as a foreign vector, so we have an exception for it
125125
there. As things stand, you can register it as scalar or not.
126-
13. [ ] CellBig needs to copy its Dimv in some cases, which also complicates ViewBig::iter<>. Problem
127-
is demonstrated in ra-5.cc.
126+
13. [ ] Cell needs to copy its Dimv in some dynamic cases, which also complicates
127+
ViewBig::iter<>. Problem is demonstrated in ra-5.cc.
128128
14. [X] Conversion-to-scalar operators for dynamic-rank ViewBig(). I thought this could be
129129
https://wg21.link/cwg976 but gcc 14 doesn't fix it. There are two issues here, 1) why isn't
130130
const conversion enough and 2) ambiguity with Small's 'any' constructor (cf 'c++ converting
@@ -208,12 +208,12 @@ Some of these aren't bugs in the sense that I expect to solve them, but more lik
208208
- [X] make View be View<pointer> and not View<value_type>
209209
- [X] Support operator <=> <2020-09-15 Tue 13:50>
210210
- https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96278 is annoying
211-
- [X] `*(it.flat())` is inefficient for some it, eg CellBig, because we need to create/copy flat
212-
in case it gets modified, and then it isn't. Do we need Iterator::operator* ?
211+
- [X] `*(it.flat())` is inefficient for some it, eg dynamic dimv Cell, because we need to
212+
create/copy flat in case it gets modified, and then it isn't. Do we need Iterator::operator* ?
213213
- [X] During traversal (ply) the pattern loc = save_location(it); move flat;
214214
it.set_location(loc); would allow flat to modify the original it. Loc is often just a pointer
215215
so this would be cheap. The current design is that move flat can't modify it so it has to be a
216-
new object. CellBig is one case where that is costly, because dimv has to be copied along with
216+
new object. Var rank Cell is one case where that is costly, because dimv has to be copied along with
217217
the pointer to make up a View, even though dimv is constant all through traversal.
218218
- [X] Review Container constructors. Why do we need (&) when we have (const &)?
219219
- <2025-07-24 Thu 11:35> was caused by auto && x constructor interfereing.

bench/bench-at.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ int main(int argc, char * * argv)
7575
ra::Big<int> bigdi({100, 4}, ra::none);
7676
ra::Small<int, 100, 4> smoli;
7777
test2(smola, smoli, reps, "warmup");
78-
// regression in b40c2d412be04c4c2b4758a332424c05257f71ff due to CellSmall copy ctor.
78+
// regression in b40c2d412be04c4c2b4758a332424c05257f71ff due to copy ctor in static dimv Cell.
7979
test2(smola, smoli, reps, "small/small");
8080
test2(bigsa, smoli, reps, "bigs/small");
8181
test2(bigda, smoli, reps, "bigd/small");

docs/index.html

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/ra-ra.texi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,9 +2018,9 @@ These are array types that own their data in one way or another.
20182018

20192019
These are array views into data in memory, which may be writable. Any of the @b{Container} types can be treated as a @b{View}, but one may also create @b{View}s into memory that has been allocated independently.
20202020

2021-
@item @b{Iterator} --- @code{CellBig}, @code{CellSmall}, @code{Ptr}, @code{Scalar}, @code{Map}, @code{Pick}
2021+
@item @b{Iterator} --- @code{Cell}, @code{Scalar}, @code{Map}, @code{Pick}
20222022

2023-
This is a traversable object. @b{Iterator}s are accepted by all the array functions such as @code{map}, @code{for_each}, etc. @code{map} produces an @b{Iterator} itself, so most array expressions are @b{Iterator}s. @b{Iterator}s are created from @b{View}s and from certain foreign array-like types primarily through the function @code{iter}. This is done automatically when those types are used in array expressions.
2023+
These are traversable objects. @b{Iterator}s are accepted by all the array functions such as @code{map}, @code{for_each}, etc. @code{map} produces an @b{Iterator} itself, so most array expressions are @b{Iterator}s. @b{Iterator}s are created from @b{View}s and from certain foreign array-like types primarily through the function @code{iter}. This is done automatically when those types are used in array expressions.
20242024

20252025
@b{Iterator}s have two traversal functions: @code{.adv(k, d)}, moves the iterator along any dimension @var{k}, and @code{.mov(d)}, is used on linearized views of the array. The methods @code{len()}, @code{step()}, @code{keep()} are used to determine the extent of these linearized views. In this way, a loop involving @b{Iterator}s can have its inner loop unfolded, which is faster than a nested loop, especially if the inner dimensions of the loop are small.
20262026

ra/arrays.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// -*- mode: c++; coding: utf-8 -*-
22
// ra-ra - Views and containers.
33

4-
// (c) Daniel Llorens - 2013-2025
4+
// (c) Daniel Llorens - 2013-2026
55
// This library is free software; you can redistribute it and/or modify it under
66
// the terms of the GNU Lesser General Public License as published by the Free
77
// Software Foundation; either version 3 of the License, or (at your option) any

ra/base.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ namespace ra {
6262

6363
template <auto V> using ic_t = std::integral_constant<std::remove_const_t<decltype(V)>, V>;
6464
template <auto V> constexpr std::integral_constant<std::remove_const_t<decltype(V)>, V> ic {};
65-
template <class A> concept is_constant = requires (A a) { []<auto X>(ic_t<X> const &){}(a); };
65+
template <class A> concept is_ctype = requires (A a) { []<auto X>(ic_t<X> const &){}(a); };
6666
template <int ... I> using ilist_t = std::tuple<ic_t<I> ...>;
6767
template <int ... I> constexpr ilist_t<I ...> ilist {};
6868

@@ -371,7 +371,7 @@ concept Slice = requires (A a)
371371
template <class A> constexpr bool RA_JOIN(NAME, _def) = requires { requires PRED; }; \
372372
template <class A> concept NAME = RA_JOIN(NAME, _def)<std::decay_t< A >>;
373373

374-
RA_IS_DEF(is_scalar, !std::is_pointer_v<A> && std::is_scalar_v<A> || is_constant<A>)
374+
RA_IS_DEF(is_scalar, !std::is_pointer_v<A> && std::is_scalar_v<A> || is_ctype<A>)
375375
template <> constexpr bool is_scalar_def<std::strong_ordering> = true;
376376
template <> constexpr bool is_scalar_def<std::weak_ordering> = true;
377377
template <> constexpr bool is_scalar_def<std::partial_ordering> = true;

0 commit comments

Comments
 (0)