first tests on index multiplication

This commit is contained in:
Christian Zimmermann 2022-12-04 03:17:29 +01:00
parent b2fd81b764
commit 38e011c979
10 changed files with 50 additions and 16 deletions

View file

@ -13,6 +13,8 @@ namespace CNORXZ
{
public:
typedef IndexInterface<DIndex,DType> IB;
typedef DType MetaType;
typedef RangeBase RangeType;
DEFAULT_C(DIndex);
DIndex(const DIndex& i);
@ -20,6 +22,7 @@ namespace CNORXZ
DIndex& operator=(const DIndex& i);
DIndex& operator=(DIndex&& i);
DIndex(const XIndexPtr& i);
DIndex(const RangePtr& r, SizeT lexpos = 0);
template <class Index, typename Meta>
DIndex(const IndexInterface<Index,Meta>& i);

View file

@ -120,10 +120,12 @@ namespace CNORXZ
constexpr decltype(auto) GMIndex<BlockType,Indices...>::mkIFor(const Xpr& xpr, F&& f) const
{
if constexpr(I == sizeof...(Indices)-1){
return std::get<I>(mIPack)->ifor(xpr,f);
return std::get<I>(mIPack)->ifor(xpr,std::forward<F>(f));
}
else {
return std::get<I>(mIPack)->ifor( mkIFor<I+1>( xpr, f ), f );
auto f1 = f;
auto f2 = f1;
return std::get<I>(mIPack)->ifor( mkIFor<I+1>( xpr, std::move(f1) ), std::move(f2) );
}
}
@ -408,7 +410,7 @@ namespace CNORXZ
template <class Xpr, class F>
constexpr decltype(auto) GMIndex<BlockType,Indices...>::ifor(const Xpr& xpr, F&& f) const
{
return mkIFor<0>(xpr, f);
return mkIFor<0>(xpr, std::forward<F>(f));
}
template <class BlockType, class... Indices>

View file

@ -42,6 +42,7 @@ namespace CNORXZ
class RangeBase
{
public:
typedef DIndex IndexType;
virtual ~RangeBase() = default;

View file

@ -149,9 +149,9 @@ namespace CNORXZ
template <class Index, typename Meta>
DXpr<SizeT> XIndex<Index,Meta>::ifor(const DXpr<SizeT>& xpr,
const std::function<SizeT(SizeT,SizeT)>& f) const
std::function<SizeT(SizeT,SizeT)>&& f) const
{
return DXpr<SizeT>(mI->ifor(xpr, f));
return DXpr<SizeT>(mI->ifor(xpr, std::forward<std::function<SizeT(SizeT,SizeT)>>(f)));
}
}

View file

@ -41,7 +41,7 @@ namespace CNORXZ
virtual XIndexBase& at(const DType& meta) = 0;
virtual DXpr<SizeT> ifor(const DXpr<SizeT>& xpr,
const std::function<SizeT(SizeT,SizeT)>& f) const = 0;
std::function<SizeT(SizeT,SizeT)>&& f) const = 0;
};
//Sptr<XIndexBase>& operator++(Sptr<XIndexBase>& i);
@ -89,7 +89,7 @@ namespace CNORXZ
virtual XIndexBase& at(const DType& meta) override final;
virtual DXpr<SizeT> ifor(const DXpr<SizeT>& xpr,
const std::function<SizeT(SizeT,SizeT)>& f) const override final;
std::function<SizeT(SizeT,SizeT)>&& f) const override final;
private:
IndexPtr<Index,Meta> mI;

View file

@ -51,7 +51,7 @@ namespace CNORXZ
DType meta() const;
YIndex& at(const DType& meta);
DXpr<SizeT> ifor(const DXpr<SizeT>& xpr, const std::function<SizeT(SizeT,SizeT)>& f) const;
DXpr<SizeT> ifor(const DXpr<SizeT>& xpr, std::function<SizeT(SizeT,SizeT)>&& f) const;
YIndex& operator()(const Sptr<YIndex>& i);
YIndex& operator()();
@ -69,7 +69,7 @@ namespace CNORXZ
inline void up(SizeT i);
inline void down(SizeT i);
inline decltype(auto) mkIFor(SizeT i, const DXpr<SizeT>& xpr,
const std::function<SizeT(SizeT,SizeT)>& f) const;
std::function<SizeT(SizeT,SizeT)>&& f) const;
inline SizeT mkPMax() const;
inline SizeT mkLMax() const;

View file

@ -36,7 +36,14 @@ namespace CNORXZ
IndexInterface<DIndex,DType>(i->pos()),
mI(i)
{}
DIndex::DIndex(const RangePtr& r, SizeT lexpos) :
IndexInterface<DIndex,DType>(0)
{
*this = r->begin();
*this = lexpos;
}
DIndex& DIndex::operator=(SizeT lexpos)
{
*mI = lexpos;

View file

@ -92,13 +92,15 @@ namespace CNORXZ
}
inline decltype(auto) YIndex::mkIFor(SizeT i, const DXpr<SizeT>& xpr,
const std::function<SizeT(SizeT,SizeT)>& f) const
std::function<SizeT(SizeT,SizeT)>&& f) const
{
if(i == mIs.size()-1){
return mIs[i]->ifor( xpr, f );
return mIs[i]->ifor( xpr, std::forward<std::function<SizeT(SizeT,SizeT)>>(f) );
}
else {
return mIs[i]->ifor( mkIFor(i+1, xpr, f), f );
auto f1 = f;
auto f2 = f1;
return mIs[i]->ifor( mkIFor(i+1, xpr, std::move(f1)), std::move(f2) );
}
}
@ -325,9 +327,9 @@ namespace CNORXZ
return *this;
}
DXpr<SizeT> YIndex::ifor(const DXpr<SizeT>& xpr, const std::function<SizeT(SizeT,SizeT)>& f) const
DXpr<SizeT> YIndex::ifor(const DXpr<SizeT>& xpr, std::function<SizeT(SizeT,SizeT)>&& f) const
{
return mkIFor(0, xpr, f);
return mkIFor(0, xpr, std::forward<std::function<SizeT(SizeT,SizeT)>>(f));
}
YIndex& YIndex::operator()(const Sptr<YIndex>& i)

View file

@ -77,7 +77,6 @@ namespace
for(auto ci = cr1x->begin(); ci != cr1x->end(); ++ci){
for(auto ui = ur1x->begin(); ui != ur1x->end(); ++ui){
const SizeT p = ci.lex()*ssize + ui.lex();
EXPECT_EQ((ci*ui).lex(), p); // test this in rutest!!!
EXPECT_EQ( a[ci*ui], a.data()[p] );
}
}

View file

@ -409,6 +409,26 @@ namespace
EXPECT_EQ(yi.lex(), 0u);
EXPECT_EQ(yi.pos(), 0u);
}
TEST_F(YR_Test, IndexMultiplication)
{
const SizeT ssize = mMeta.size();
auto crx = std::dynamic_pointer_cast<CRange>(cr);
auto urx = std::dynamic_pointer_cast<URange<String>>(ur);
for(auto cix = crx->begin(); cix != crx->end(); ++cix){
for(auto uix = urx->begin(); uix != urx->end(); ++uix){
const SizeT p = cix.lex()*ssize + uix.lex();
EXPECT_EQ((cix*uix).lex(), p);
}
}
for(auto ci = cr->begin(); ci != cr->end(); ++ci){
for(auto ui = ur->begin(); ui != ur->end(); ++ui){
const SizeT p = ci.lex()*ssize + ui.lex();
EXPECT_EQ((ci*ui).lex(), p);
}
}
}
// RCast_Test
}