shift index multiplication to separate file + extend to Sptr

This commit is contained in:
Christian Zimmermann 2022-11-29 01:46:53 +01:00
parent a3a25af289
commit 1bd51ee700
11 changed files with 218 additions and 89 deletions

View file

@ -3,6 +3,7 @@
#define __cxz_crange_cc_h__ #define __cxz_crange_cc_h__
#include "crange.h" #include "crange.h"
#include "index_mul.h"
namespace CNORXZ namespace CNORXZ
{ {
@ -11,6 +12,12 @@ namespace CNORXZ
{ {
return For<0,Xpr,F>(this->pmax().val(), this->id(), xpr, std::forward<F>(f)); return For<0,Xpr,F>(this->pmax().val(), this->id(), xpr, std::forward<F>(f));
} }
template <class I>
decltype(auto) operator*(const Sptr<CIndex>& a, const Sptr<I>& b)
{
return iptrMul(a, b);
}
} }
#endif #endif

View file

@ -49,6 +49,8 @@ namespace CNORXZ
Sptr<RangeType> mRangePtr; Sptr<RangeType> mRangePtr;
}; };
template <class I>
decltype(auto) operator*(const Sptr<CIndex>& a, const Sptr<I>& b);
class CRangeFactory : public RangeFactoryBase class CRangeFactory : public RangeFactoryBase
{ {

View file

@ -0,0 +1,132 @@
#ifndef __cxz_index_mul_cc_h__
#define __cxz_index_mul_cc_h__
#include "index_mul.h"
namespace CNORXZ
{
/*****************
* MIndexMul *
*****************/
template <class BlockT, class... Indices, class I, typename Meta, SizeT... Is>
constexpr decltype(auto) MIndexMul::evalMX(const GMIndex<BlockT,Indices...>& a,
const IndexInterface<I,Meta>& b,
Isq<Is...> is)
{
static_assert(sizeof...(Is) == sizeof...(Indices), "inconsistent index sequence");
return MIndex<Indices...,I>( std::get<Is>(a.pack())..., b.THIS() );
}
template <class BlockT, class... Indices, class I, typename Meta, SizeT... Js>
constexpr decltype(auto) MIndexMul::evalXM(const IndexInterface<I,Meta>& a,
const GMIndex<BlockT,Indices...>& b,
Isq<Js...> js)
{
static_assert(sizeof...(Js) == sizeof...(Indices), "inconsistent index sequence");
return MIndex<Indices...,I>( a.THIS(), std::get<Js>(b.pack())... );
}
template <class BlockT1, class... Indices1, class BlockT2, class... Indices2,
SizeT... Is, SizeT... Js>
constexpr decltype(auto) MIndexMul::evalMM(const GMIndex<BlockT1,Indices1...>& a,
const GMIndex<BlockT2,Indices2...>& b,
Isq<Is...> is, Isq<Js...> js)
{
static_assert(sizeof...(Is) == sizeof...(Indices1), "inconsistent index sequence");
static_assert(sizeof...(Js) == sizeof...(Indices2), "inconsistent index sequence");
return MIndex<Indices1...,Indices2...>( std::get<Is>(a.pack())...,
std::get<Js>(b.pack())... );
}
/*********************
* MIndexSptrMul *
*********************/
template <class BlockT, class... Indices, class I, SizeT... Is>
decltype(auto) MIndexSptrMul::evalMX(const Sptr<GMIndex<BlockT,Indices...>>& a,
const Sptr<I>& b, Isq<Is...> is)
{
static_assert(sizeof...(Is) == sizeof...(Indices), "inconsistent index sequence");
return std::make_shared<MIndex<Indices...,I>>( std::get<Is>(a->pack())..., b );
}
template <class BlockT, class... Indices, class I, typename Meta, SizeT... Js>
decltype(auto) MIndexSptrMul::evalXM(const Sptr<I>& a,
const Sptr<GMIndex<BlockT,Indices...>>& b,
Isq<Js...> js)
{
static_assert(sizeof...(Js) == sizeof...(Indices), "inconsistent index sequence");
return std::make_shared<MIndex<I,Indices...>>( a, std::get<Js>(b->pack())... );
}
template <class BlockT1, class... Indices1, class BlockT2, class... Indices2,
SizeT... Is, SizeT... Js>
decltype(auto) MIndexSptrMul::evalMM(const Sptr<GMIndex<BlockT1,Indices1...>>& a,
const Sptr<GMIndex<BlockT2,Indices2...>>& b,
Isq<Is...> is, Isq<Js...> js)
{
static_assert(sizeof...(Is) == sizeof...(Indices1), "inconsistent index sequence");
static_assert(sizeof...(Js) == sizeof...(Indices2), "inconsistent index sequence");
return MIndex<Indices1...,Indices2...>( std::get<Is>(a->pack())...,
std::get<Js>(b->pack())... );
}
/*****************
* operator* *
*****************/
template <class I1, typename Meta1, class I2, typename Meta2>
constexpr decltype(auto) operator*(const IndexInterface<I1,Meta1>& a,
const IndexInterface<I2,Meta2>& b)
{
// special operations for DIndex / YIndex
if constexpr(index_dim<I1>::value == 1){
if constexpr(index_dim<I2>::value == 1){
return MIndex<I1,I2>(a.THIS(),b.THIS());
}
else {
return MIndexMul::evalXM(a, b.THIS());
}
}
else {
if constexpr(index_dim<I2>::value == 1){
return MIndexMul::evalMX(a.THIS(), b);
}
else {
return MIndexMul::evalMM(a.THIS(), b.THIS());
}
}
}
/***************
* iptrMul *
***************/
template <class I1, class I2>
decltype(auto) iptrMul(const Sptr<I1>& a, const Sptr<I2>& b)
{
// special operations for DIndex / YIndex
if constexpr(index_dim<I1>::value == 1){
if constexpr(index_dim<I2>::value == 1){
return std::make_shared<MIndex<I1,I2>>(a, b);
}
else {
return MIndexSptrMul::evalXM(a, b);
}
}
else {
if constexpr(index_dim<I2>::value == 1){
return MIndexSptrMul::evalMX(a, b);
}
else {
return MIndexSptrMul::evalMM(a, b);
}
}
}
}
#endif

View file

@ -0,0 +1,54 @@
#ifndef __cxz_index_mul_h__
#define __cxz_index_mul_h__
#include "base/base.h"
#include "index_base.h"
namespace CNORXZ
{
struct MIndexMul
{
template <class BlockT, class... Indices, class I, typename Meta, SizeT... Is>
static constexpr decltype(auto) evalMX(const GMIndex<BlockT,Indices...>& a,
const IndexInterface<I,Meta>& b,
Isq<Is...> is);
template <class BlockT, class... Indices, class I, typename Meta, SizeT... Js>
static constexpr decltype(auto) evalXM(const IndexInterface<I,Meta>& a,
const GMIndex<BlockT,Indices...>& b,
Isq<Js...> js);
template <class BlockT1, class... Indices1, class BlockT2, class... Indices2,
SizeT... Is, SizeT... Js>
static constexpr decltype(auto) evalMM(const GMIndex<BlockT1,Indices1...>& a,
const GMIndex<BlockT2,Indices2...>& b,
Isq<Is...> is, Isq<Js...> js);
};
struct MIndexSptrMul
{
template <class BlockT, class... Indices, class I, SizeT... Is>
static decltype(auto) evalMX(const Sptr<GMIndex<BlockT,Indices...>>& a,
const Sptr<I>& b, Isq<Is...> is);
template <class BlockT, class... Indices, class I, typename Meta, SizeT... Js>
static decltype(auto) evalXM(const Sptr<I>& a, const Sptr<GMIndex<BlockT,Indices...>>& b,
Isq<Js...> js);
template <class BlockT1, class... Indices1, class BlockT2, class... Indices2,
SizeT... Is, SizeT... Js>
static decltype(auto) evalMM(const Sptr<GMIndex<BlockT1,Indices1...>>& a,
const Sptr<GMIndex<BlockT2,Indices2...>>& b,
Isq<Is...> is, Isq<Js...> js);
};
template <class I1, typename Meta1, class I2, typename Meta2>
constexpr decltype(auto) operator*(const IndexInterface<I1,Meta1>& a,
const IndexInterface<I2,Meta2>& b);
template <class I1, class I2>
decltype(auto) iptrMul(const Sptr<I1>& a, const Sptr<I2>& b);
}
#endif

View file

@ -449,69 +449,18 @@ namespace CNORXZ
return mLexBlockSizes; return mLexBlockSizes;
} }
template <class BT1, class... Is1, class BT2, class... Is2>
decltype(auto) operator*(const Sptr<GMIndex<BT1,Is1...>>& a, const Sptr<GMIndex<BT2,Is2...>>& b)
{
return iptrMul(a, b);
}
template <class... Indices> template <class... Indices>
constexpr decltype(auto) mindex(const Sptr<Indices>&... is) constexpr decltype(auto) mindex(const Sptr<Indices>&... is)
{ {
return MIndex<Indices...>(is...); return MIndex<Indices...>(is...);
} }
/*****************
* MIndexMul *
*****************/
template <class BlockT, class... Indices, class I, typename Meta, SizeT... Is>
constexpr decltype(auto) MIndexMul::evalMX(const GMIndex<BlockT,Indices...>& a,
const IndexInterface<I,Meta>& b,
Isq<Is...> is)
{
static_assert(sizeof...(Is) == sizeof...(Indices), "inconsistent index sequence");
return MIndex<Indices...,I>( std::get<Is>(a.pack())..., b.THIS() );
}
template <class BlockT, class... Indices, class I, typename Meta, SizeT... Js>
constexpr decltype(auto) MIndexMul::evalXM(const IndexInterface<I,Meta>& a,
const GMIndex<BlockT,Indices...>& b,
Isq<Js...> js)
{
static_assert(sizeof...(Js) == sizeof...(Indices), "inconsistent index sequence");
return MIndex<Indices...,I>( a.THIS(), std::get<Js>(b.pack())... );
}
template <class BlockT1, class... Indices1, class BlockT2, class... Indices2, SizeT... Is, SizeT... Js>
constexpr decltype(auto) MIndexMul::evalMM(const GMIndex<BlockT1,Indices1...>& a,
const GMIndex<BlockT2,Indices2...>& b,
Isq<Is...> is, Isq<Js...> js)
{
static_assert(sizeof...(Is) == sizeof...(Indices1), "inconsistent index sequence");
static_assert(sizeof...(Js) == sizeof...(Indices2), "inconsistent index sequence");
return MIndex<Indices1...,Indices2...>( std::get<Is>(a.pack())...,
std::get<Js>(b.pack())... );
}
// move to separate file!!!
template <class I1, typename Meta1, class I2, typename Meta2>
constexpr decltype(auto) operator*(const IndexInterface<I1,Meta1>& a,
const IndexInterface<I2,Meta2>& b)
{
// special operations for DIndex / YIndex
if constexpr(index_dim<I1>::value == 1){
if constexpr(index_dim<I2>::value == 1){
return MIndex<I1,I2>(a.THIS(),b.THIS());
}
else {
return MIndexMul::evalXM(a, b.THIS());
}
}
else {
if constexpr(index_dim<I2>::value == 1){
return MIndexMul::evalMX(a.THIS(), b);
}
else {
return MIndexMul::evalMM(a.THIS(), b.THIS());
}
}
}
/********************* /*********************
* MRangeFactory * * MRangeFactory *

View file

@ -111,6 +111,9 @@ namespace CNORXZ
PMaxT mPMax; PMaxT mPMax;
}; };
template <class BT1, class... Is1, class BT2, class... Is2>
decltype(auto) operator*(const Sptr<GMIndex<BT1,Is1...>>& a, const Sptr<GMIndex<BT2,Is2...>>& b);
//template <class... Indices> //template <class... Indices>
//using MIndex = GMIndex<None,Indices...>; //using MIndex = GMIndex<None,Indices...>;
template <class... Indices> template <class... Indices>
@ -128,33 +131,6 @@ namespace CNORXZ
template <class... Indices> template <class... Indices>
constexpr decltype(auto) mindex(const Sptr<Indices>&... is); constexpr decltype(auto) mindex(const Sptr<Indices>&... is);
struct MIndexMul
{
template <class BlockT, class... Indices, class I, typename Meta, SizeT... Is>
static constexpr decltype(auto) evalMX(const GMIndex<BlockT,Indices...>& a,
const IndexInterface<I,Meta>& b,
Isq<Is...> is);
template <class BlockT, class... Indices, class I, typename Meta, SizeT... Js>
static constexpr decltype(auto) evalXM(const IndexInterface<I,Meta>& a,
const GMIndex<BlockT,Indices...>& b,
Isq<Js...> js);
template <class BlockT1, class... Indices1, class BlockT2, class... Indices2, SizeT... Is, SizeT... Js>
static constexpr decltype(auto) evalMM(const GMIndex<BlockT1,Indices1...>& a,
const GMIndex<BlockT2,Indices2...>& b,
Isq<Is...> is, Isq<Js...> js);
};
// move to separate file!!!
template <class I1, typename Meta1, class I2, typename Meta2>
constexpr decltype(auto) operator*(const IndexInterface<I1,Meta1>& a,
const IndexInterface<I2,Meta2>& b);
//template <class BlockT, class... Indices2, SizeT... Is, SizeT... Js>
//constexpr decltype(auto) mindex(const GMIndex<BlockT,Indices2...>& a,
// Isq<Is...> is, Isq<Js...> js) const;
template <class... Ranges> template <class... Ranges>
class MRangeFactory : public RangeFactoryBase class MRangeFactory : public RangeFactoryBase

View file

@ -6,3 +6,4 @@
#include "urange.cc.h" #include "urange.cc.h"
#include "crange.cc.h" #include "crange.cc.h"
#include "dindex.cc.h" #include "dindex.cc.h"
#include "index_mul.cc.h"

View file

@ -2,12 +2,12 @@
#include "range_base.h" #include "range_base.h"
#include "index_base.h" #include "index_base.h"
#include "mrange.h" #include "mrange.h"
//#include "range_helper.h"
#include "crange.h" #include "crange.h"
//#include "subrange.h" //#include "subrange.h"
//#include "value_range.h" //#include "value_range.h"
#include "xindex.h" #include "xindex.h"
#include "yrange.h" #include "yrange.h"
#include "dindex.h" #include "dindex.h"
#include "index_mul.h"
#include "ranges.cc.h" #include "ranges.cc.h"

View file

@ -6,6 +6,7 @@
#include <algorithm> #include <algorithm>
#include "urange.h" #include "urange.h"
#include "index_mul.h"
#include "xpr/for.h" #include "xpr/for.h"
namespace CNORXZ namespace CNORXZ
@ -143,6 +144,12 @@ namespace CNORXZ
return For<0,Xpr,F>(this->pmax().val(), this->id(), xpr, std::forward<F>(f)); return For<0,Xpr,F>(this->pmax().val(), this->id(), xpr, std::forward<F>(f));
} }
template <typename MetaType, class I1>
decltype(auto) operator*(const Sptr<UIndex<MetaType>>& a, const Sptr<I1>& b)
{
return iptrMul(a, b);
}
/********************** /**********************
* URangeFactory * * URangeFactory *
**********************/ **********************/

View file

@ -55,6 +55,9 @@ namespace CNORXZ
const MetaT* mMetaPtr; const MetaT* mMetaPtr;
}; };
template <typename MetaType, class I1>
decltype(auto) operator*(const Sptr<UIndex<MetaType>>& a, const Sptr<I1>& b);
template <typename MetaType> template <typename MetaType>
class URangeFactory : public RangeFactoryBase class URangeFactory : public RangeFactoryBase
{ {

View file

@ -63,10 +63,8 @@ namespace
mCIa2 = std::make_shared<CIndex>(cra); mCIa2 = std::make_shared<CIndex>(cra);
mCIb1 = std::make_shared<CIndex>(crb); mCIb1 = std::make_shared<CIndex>(crb);
mCIb2 = std::make_shared<CIndex>(crb); mCIb2 = std::make_shared<CIndex>(crb);
mCCa1a2 = std::make_shared<MCCI>(mCIa1,mCIa2); mCCa1a2 = mCIa1*mCIa2;
mCCa2a1 = std::make_shared<MCCI>(mCIa2,mCIa1); mCCa2a1 = mCIa2*mCIa1;
//mCCa1a2 = mCIa1*mCIa2;
//mCCa2a1 = mCIa2*mCIa1;
mOCa1a2.init(mCCa1a2); mOCa1a2.init(mCCa1a2);
mORa2a1.init(mData12.data(), mCCa2a1); mORa2a1.init(mData12.data(), mCCa2a1);
} }