Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
lloda committed Nov 20, 2023
1 parent 8d30e6d commit 5a508c4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
4 changes: 2 additions & 2 deletions ra/atom.hh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ constexpr bool inside(dim_t i, dim_t b) { return 0<=i && i<b; }
// assign ops for settable iterators. Might be different for e.g. Views.
// --------------------

// Forward to make sure value y is not misused as ref [ra5].
// Forward to forbid misusing value y as ref [ra5].
#define RA_ASSIGNOPS_LINE(OP) \
for_each([](auto && y, auto && x) { RA_FWD(y) OP x; }, *this, x)
#define RA_ASSIGNOPS(OP) \
Expand All @@ -55,7 +55,7 @@ constexpr bool inside(dim_t i, dim_t b) { return 0<=i && i<b; }
#define RA_ASSIGNOPS_DEFAULT_SET \
FOR_EACH(RA_ASSIGNOPS, =, *=, +=, -=, /=)
// Restate for expression classes since a template doesn't replace the copy assignment op.
#define RA_ASSIGNOPS_SELF(TYPE) \
#define RA_ASSIGNOPS_SELF(TYPE) \
TYPE & operator=(TYPE && x) { RA_ASSIGNOPS_LINE(=); return *this; } \
TYPE & operator=(TYPE const & x) { RA_ASSIGNOPS_LINE(=); return *this; } \
constexpr TYPE(TYPE && x) = default; \
Expand Down
27 changes: 11 additions & 16 deletions ra/big.hh
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ struct Container: public View<typename storage_traits<Store>::T, RANK>

// non-copy assignment operators follow View, but cannot be just using'd because of constness.
#define ASSIGNOPS(OP) \
template <class X> Container & operator OP (X && x) { view() OP x; return *this; }
Container & operator OP (auto && x) { view() OP x; return *this; }
FOR_EACH(ASSIGNOPS, =, *=, +=, -=, /=)
#undef ASSIGNOPS
using ravel_arg = std::conditional_t<RANK==1, noarg, std::initializer_list<T>>;
Expand All @@ -440,7 +440,7 @@ struct Container: public View<typename storage_traits<Store>::T, RANK>
// provided so that {} calls shape_arg constructor below.
Container() requires (ANY==RANK): View({ Dim {0, 1} }, nullptr) {}
Container() requires (ANY!=RANK && 0!=RANK): View(typename View::Dimv(Dim {0, 1}), nullptr) {}
Container() requires (0==RANK): Container({}, ra::none) {}
Container() requires (0==RANK): Container({}, none) {}

// shape_arg overloads handle {...} arguments. Size check is at conversion (if shape_arg is Small) or init().
Container(shape_arg const & s, none_t) { init(s); }
Expand All @@ -463,9 +463,8 @@ struct Container: public View<typename storage_traits<Store>::T, RANK>
#undef RA_BRACES_ANY

// FIXME requires T to be copiable, which conflicts with the semantics of view_.operator=. store(x) avoids it for Big, but doesn't work for Unique. Should construct in place like std::vector does.
template <class Xbegin>
constexpr void
fill1(Xbegin xbegin, dim_t xsize)
fill1(auto xbegin, dim_t xsize)
{
RA_CHECK(size()==xsize, "Mismatched sizes ", size(), " ", xsize, ".");
std::ranges::copy_n(xbegin, xsize, begin());
Expand All @@ -478,22 +477,18 @@ struct Container: public View<typename storage_traits<Store>::T, RANK>
: Container(s, none) { fill1(x.begin(), x.size()); }

// FIXME remove
template <class TT>
Container(shape_arg const & s, TT * p)
Container(shape_arg const & s, auto * p)
: Container(s, none) { fill1(p, size()); } // FIXME fake check
// FIXME remove
template <class P>
Container(shape_arg const & s, P pbegin, dim_t psize)
Container(shape_arg const & s, auto pbegin, dim_t psize)
: Container(s, none) { fill1(pbegin, psize); }

// for SS that doesn't convert implicitly to shape_arg
template <class SS>
Container(SS && s, none_t) { init(RA_FWD(s)); }
template <class SS, class XX>
Container(SS && s, XX && x)
// for shape arguments that doesn't convert implicitly to shape_arg
Container(auto && s, none_t)
{ init(RA_FWD(s)); }
Container(auto && s, auto && x)
: Container(RA_FWD(s), none) { iter() = x; }
template <class SS>
Container(SS && s, std::initializer_list<T> x)
Container(auto && s, std::initializer_list<T> x)
: Container(RA_FWD(s), none) { fill1(x.begin(), x.size()); }

// resize first axis or full shape. Only for some kinds of store.
Expand Down Expand Up @@ -639,7 +634,7 @@ with_same_shape(E && e)
if constexpr (ANY!=size_s<concrete_type<E>>()) {
return concrete_type<E>();
} else {
return concrete_type<E>(ra::shape(e), ra::none);
return concrete_type<E>(ra::shape(e), none);
}
}

Expand Down

0 comments on commit 5a508c4

Please sign in to comment.