dynamic ranges + dynamic index operation works

This commit is contained in:
Christian Zimmermann 2018-11-01 22:11:08 +01:00
parent e5792bcf7b
commit 307a714996
12 changed files with 361 additions and 123 deletions

View file

@ -0,0 +1,39 @@
#include "expressions.h"
namespace MultiArrayTools
{
template <class Expr>
inline ExpressionHolder<Expr> Expressions1::ifor(size_t step,
ExpressionHolder<Expr> ex) const
{
return iforx(step, ex);
}
template <class Expr>
inline ExpressionHolder<Expr> Expressions1::iforh(size_t step,
ExpressionHolder<Expr> ex) const
{
return iforhx(step, ex);
}
template <class Expr>
inline ExpressionHolder<Expr> Expressions1::ifori(size_t step, Expr ex) const
{
return iforxi(step, ex);
}
template <class Expr>
inline ExpressionHolder<Expr> Expressions1::iforhi(size_t step, Expr ex) const
{
return iforhxi(step, ex);
}
template <class EC, class Index>
std::shared_ptr<EC> makeec(const std::shared_ptr<Index>& i)
{
return std::make_shared<EC>(i);
}
} // namespace MultiArrayTools

View file

@ -21,13 +21,32 @@ namespace MultiArrayTools
using DDMMA = MutableMultiArrayBase<double,DynamicRange<EC>>;
template <class EC, class MA>
using oo = decltype(std::declval<MA>()(std::declval<std::shared_ptr<DynamicIndex<EC>>>()));
using oo = decltype(std::declval<MA>()(std::declval<const std::shared_ptr<DynamicIndex<EC>>&>()));
template <template <class> class OpF, class... oos>
using OO = Operation<double,OpF<double>,oos...>;
template <class EC, template <class> class OpF, class... MAs>
using OX = Operation<double,OpF<double>,oo<EC,MAs>...>;
template <class EC, class Second>
using AEXT = typename OperationMaster<double,Second,DynamicRange<EC>>::AssignmentExpr;
template <class EC, template <class> class OpF, class... MAs>
using AEX = AEXT<EC,OX<EC,OpF,MAs...>>;
template <class EC, template <class> class OpF>
using AEX_B_MM = AEX<EC,OpF,DDMMA<EC>,DDMMA<EC>>;
template <class EC, template <class> class OpF>
using AEX_B_MC = AEX<EC,OpF,DDMMA<EC>,DDMA<EC>>;
template <class EC, template <class> class OpF>
using AEX_B_CM = AEX<EC,OpF,DDMA<EC>,DDMMA<EC>>;
template <class EC, template <class> class OpF>
using AEX_B_CC = AEX<EC,OpF,DDMA<EC>,DDMA<EC>>;
/*
template <class EC>
class ECInterface
@ -53,57 +72,74 @@ namespace MultiArrayTools
};
*/
template <class EC, class Index>
EC makeec(const std::shared_ptr<Index>& i);
std::shared_ptr<EC> makeec(const std::shared_ptr<Index>& i);
#define V_IFOR_X(Expr) \
virtual ExpressionHolder<Expr> iforx(size_t step, Expr ex) const = 0; \
virtual ExpressionHolder<Expr> iforhx(size_t step, Expr ex) const = 0
virtual ExpressionHolder<Expr> iforx(size_t step, ExpressionHolder<Expr> ex) const = 0; \
virtual ExpressionHolder<Expr> iforhx(size_t step, ExpressionHolder<Expr> ex) const = 0; \
virtual ExpressionHolder<Expr> iforxi(size_t step, Expr ex) const = 0; \
virtual ExpressionHolder<Expr> iforhxi(size_t step, Expr ex) const = 0
#define V_IFOR_A(EC,OpF) \
V_IFOR_X(AEX_B_MM<EC Y() OpF>); \
V_IFOR_X(AEX_B_MC<EC Y() OpF>); \
V_IFOR_X(AEX_B_CM<EC Y() OpF>); \
V_IFOR_X(AEX_B_CC<EC Y() OpF>)
template <class Index>
class E1;
class Expressions1 //: public ECInterface<Expressions1<X>>
{
public:
typedef Expressions1 EX;
template <class Index>
template <class Index>
static auto make(const std::shared_ptr<Index>& i)
-> decltype(makeec<E1<Index>>(i))
{
return makeec<E1<Index>>(i);
}
private:
V_IFOR_X(OX<EX Y() plus Y() DDMA<EX> Y() DDMA<EX>>);
V_IFOR_X(OX<EX Y() minus Y() DDMA<EX> Y() DDMA<EX>>);
V_IFOR_X(OX<EX Y() multiplies Y() DDMA<EX> Y() DDMA<EX>>);
V_IFOR_X(OX<EX Y() divides Y() DDMA<EX> Y() DDMA<EX>>);
V_IFOR_A(EX,plus);
V_IFOR_A(EX,minus);
V_IFOR_A(EX,multiplies);
V_IFOR_A(EX,divides);
public:
template <class Expr>
auto ifor(size_t step, Expr ex) const
-> decltype(iforx(step, ex))
{
return iforx(step, ex);
}
inline ExpressionHolder<Expr> ifor(size_t step, ExpressionHolder<Expr> ex) const;
template <class Expr>
auto iforh(size_t step, Expr ex) const
-> decltype(iforhx(step, ex))
{
return iforhx(step, ex);
}
inline ExpressionHolder<Expr> iforh(size_t step, ExpressionHolder<Expr> ex) const;
template <class Expr>
inline ExpressionHolder<Expr> ifori(size_t step, Expr ex) const;
template <class Expr>
inline ExpressionHolder<Expr> iforhi(size_t step, Expr ex) const;
};
#define O_IFOR_X(Expr,Ind) \
virtual ExpressionHolder<Expr> iforx(size_t step, Expr ex) const override final \
#define D_IFOR_X(Expr,Ind) \
ExpressionHolder<Expr> iforx(size_t step, ExpressionHolder<Expr> ex) const \
{ return ExpressionHolder<Expr>(Ind->ifor(step, ex)); } \
virtual ExpressionHolder<Expr> iforhx(size_t step, Expr ex) const override final \
ExpressionHolder<Expr> iforhx(size_t step, ExpressionHolder<Expr> ex) const \
{ return ExpressionHolder<Expr>(Ind->iforh(step, ex)); } \
ExpressionHolder<Expr> iforxi(size_t step, Expr ex) const \
{ return ExpressionHolder<Expr>(Ind->ifor(step, ex)); } \
ExpressionHolder<Expr> iforhxi(size_t step, Expr ex) const \
{ return ExpressionHolder<Expr>(Ind->iforh(step, ex)); }
#define D_IFOR_A(EC,OpF,Ind) \
D_IFOR_X(AEX_B_MM<EC Y() OpF>,Ind); \
D_IFOR_X(AEX_B_MC<EC Y() OpF>,Ind); \
D_IFOR_X(AEX_B_CM<EC Y() OpF>,Ind); \
D_IFOR_X(AEX_B_CC<EC Y() OpF>,Ind)
template <class Index>
class E1 : public Expressions1
{
@ -115,10 +151,10 @@ namespace MultiArrayTools
std::shared_ptr<Index> mI;
O_IFOR_X(OX<EX Y() plus Y() DDMA<EX> Y() DDMA<EX>>, mI);
O_IFOR_X(OX<EX Y() minus Y() DDMA<EX> Y() DDMA<EX>>, mI);
O_IFOR_X(OX<EX Y() multiplies Y() DDMA<EX> Y() DDMA<EX>>, mI);
O_IFOR_X(OX<EX Y() divides Y() DDMA<EX> Y() DDMA<EX>>, mI);
D_IFOR_A(EX,plus,mI);
D_IFOR_A(EX,minus,mI);
D_IFOR_A(EX,multiplies,mI);
D_IFOR_A(EX,divides,mI);
public:
E1(const E1& in) = default;
@ -129,12 +165,6 @@ namespace MultiArrayTools
E1(const std::shared_ptr<Index>& i) : mI(i) {}
};
template <class EC, class Index>
EC makeec(const std::shared_ptr<Index>& i)
{
return EC(i);
}
} // namespace MultiArrayTools

View file

@ -114,4 +114,21 @@ namespace MultiArrayTools
}
template <class EC, class MArray>
auto dynamic(const MArray& ma, bool slice)
-> std::shared_ptr<MultiArrayBase<typename MArray::value_type,DynamicRange<EC>>>
{
DynamicRangeFactory<EC> drf(ma.range()->space());
if(slice){
return std::make_shared<ConstSlice<typename MArray::value_type,DynamicRange<EC>>>
( std::dynamic_pointer_cast<DynamicRange<EC>>( drf.create() ),
ma.data() );
}
else {
return std::make_shared<MultiArray<typename MArray::value_type,DynamicRange<EC>>>
( std::dynamic_pointer_cast<DynamicRange<EC>>( drf.create() ),
ma.vdata() );
}
}
}

View file

@ -59,6 +59,10 @@ namespace MultiArrayTools
auto prtr(const MArray& ma)
-> decltype(ma.template getRangePtr<N>());
template <class EC, class MArray>
auto dynamic(const MArray& ma, bool slice = false)
-> std::shared_ptr<MultiArrayBase<typename MArray::value_type,DynamicRange<EC>>>;
template <class IndexType>
inline void For(const std::shared_ptr<IndexType>& ind, const std::function<void(void)>& ll)
{

View file

@ -6,5 +6,6 @@
#include "multi_array_base.cc.h"
#include "multi_array.cc.h"
#include "slice.cc.h"
#include "expressions.cc.h"
#include "ranges/dynamic_range.cc.h"

View file

@ -9,6 +9,32 @@ namespace MultiArrayTools
{
typedef std::pair<const char*,size_t> DynamicMetaElem;
template <size_t N>
struct DynamicMetaSetter
{
template <typename... Us>
static inline void set(const std::tuple<Us...>& in, std::vector<DynamicMetaElem>& meta)
{
typedef typename std::tuple_element<N,std::tuple<Us...>>::type elemtype;
meta[N].first = reinterpret_cast<const char*>( &std::get<N>(in) );
meta[N].second = sizeof(elemtype);
DynamicMetaSetter<N-1>::set(in,meta);
}
};
template <>
struct DynamicMetaSetter<0>
{
template <typename... Us>
static inline void set(const std::tuple<Us...>& in, std::vector<DynamicMetaElem>& meta)
{
typedef typename std::tuple_element<0,std::tuple<Us...>>::type elemtype;
meta[0].first = reinterpret_cast<const char*>( &std::get<0>(in) );
meta[0].second = sizeof(elemtype);
}
};
class DynamicMetaT
{
@ -23,9 +49,9 @@ namespace MultiArrayTools
DynamicMetaT& operator=(DynamicMetaT&& in) = default;
template <typename... Us>
DynamicMetaT(const std::tuple<Us...>& meta)
DynamicMetaT(const std::tuple<Us...>* meta) : mMeta(sizeof...(Us))
{
DynamicMetaSetter<sizeof...(Us)-1>::set(*meta,mMeta);
}
bool operator==(const DynamicMetaT& in) const;

View file

@ -10,6 +10,48 @@ namespace MultiArrayTools
{
using namespace MultiArrayHelper;
}
/*************************
* IndexWrapperBase *
*************************/
template <class ExpressionCollection>
template <class Expr>
ExpressionHolder<Expr>
IndexWrapperBase<ExpressionCollection>::ifor(size_t step, ExpressionHolder<Expr> ex) const
{
return mEc->ifor(step, ex);
}
template <class ExpressionCollection>
template <class Expr>
ExpressionHolder<Expr>
IndexWrapperBase<ExpressionCollection>::iforh(size_t step, ExpressionHolder<Expr> ex) const
{
return mEc->iforh(step, ex);
}
template <class ExpressionCollection>
template <class Expr>
ExpressionHolder<Expr>
IndexWrapperBase<ExpressionCollection>::ifori(size_t step, Expr ex) const
{
return mEc->ifori(step, ex);
}
template <class ExpressionCollection>
template <class Expr>
ExpressionHolder<Expr>
IndexWrapperBase<ExpressionCollection>::iforhi(size_t step, Expr ex) const
{
return mEc->iforhi(step, ex);
}
template <class Index, class ExpressionCollection>
size_t IndexWrapper<Index,ExpressionCollection>::getStepSizeComp(std::intptr_t j) const
{
return MultiArrayHelper::getStepSize(*mI, j);
}
/****************************
* DynamicRangeFactory *
@ -101,9 +143,16 @@ namespace MultiArrayTools
template <class EC>
DynamicIndex<EC>::DynamicIndex(const std::shared_ptr<DynamicRange<EC> >& range) :
IndexInterface<DynamicIndex,MetaType>(range, 0)//,
//mExplicitRangePtr(std::dynamic_pointer_cast<RangeType>(IB::mRangePtr)),
{}
IndexInterface<DynamicIndex,MetaType>(range, 0),
mIVec(range->dim())
{
size_t xx = 1;
for(size_t i = mIVec.size()-1; i != 0; --i){
mIVec[i].second = xx;
xx *= range->sub(i)->size();
}
mIVec[0].second = xx;
}
template <class EC>
IndexType DynamicIndex<EC>::type() const
@ -152,6 +201,20 @@ namespace MultiArrayTools
mIVec = ivec;
return *this;
}
template <class EC>
template <class... Indices>
DynamicIndex<EC>& DynamicIndex<EC>::operator()(const std::shared_ptr<Indices>&... is)
{
std::vector<std::shared_ptr<IndexW<EC>>> tmp =
{ std::make_shared<IndexWrapper<Indices,EC>>(is)... };
assert(mIVec.size() == tmp.size());
for(size_t i = 0; i != mIVec.size(); ++i){
mIVec[i].first = tmp[i];
}
return *this;
}
template <class EC>
int DynamicIndex<EC>::pp(std::intptr_t idxPtrNum)
@ -207,7 +270,7 @@ namespace MultiArrayTools
template <class EC>
size_t DynamicIndex<EC>::dim() const // = 1
{
return 1;
return mIVec.size();
}
template <class EC>
@ -261,10 +324,37 @@ namespace MultiArrayTools
std::cout << id() << "[" << reinterpret_cast<std::intptr_t>(this)
<< "](" << IB::mRangePtr << "): " /*<< meta().first*/ << std::endl;
}
template <class Expr>
struct ForMaker
{
template <class IVecT>
static inline auto mk(size_t i, size_t step, ExpressionHolder<Expr> ex,
const IVecT& ivec, bool hidden = false)
-> ExpressionHolder<Expr>
{
if(i != 0){
auto& ii = *ivec[i].first;
return mk(i-1, step,
(hidden ? ii.iforh(step*ivec[i].second, ex) :
ii.ifor(step*ivec[i].second, ex)),
ivec, hidden);
}
else {
auto& ii = *ivec[0].first;
return hidden ? ii.iforh(step*ivec[i].second, ex) :
ii.ifor(step*ivec[i].second, ex);
}
}
};
/*
template <class EC>
inline DynamicExpression DynamicIndex<EC>::mkFor(size_t i, size_t step,
DynamicExpression ex, bool hidden) const
template <class Expr>
inline auto DynamicIndex<EC>::mkFor(size_t i, size_t step,
ExpressionHolder<Expr> ex,
bool hidden) const
-> ExpressionHolder<Expr>
{
if(i != 0){
auto& ii = *mIVec[i].first;
@ -275,23 +365,21 @@ namespace MultiArrayTools
return hidden ? ii.iforh(step, ex) : ii.ifor(step, ex);
}
}
*/
template <class EC>
template <class Expr>
auto DynamicIndex<EC>::ifor(size_t step, Expr ex) const
-> DynamicExpression
ExpressionHolder<Expr> DynamicIndex<EC>::ifor(size_t step, Expr ex) const
{
DynamicExpression expr(std::make_shared<Expr>(ex));
return mkFor(mIVec.size()-1, step, expr);
return ForMaker<Expr>::mk(mIVec.size()-2, step, mIVec.back().first->ifori(step,ex),
mIVec);
}
template <class EC>
template <class Expr>
auto DynamicIndex<EC>::iforh(size_t step, Expr ex) const
-> DynamicExpression
ExpressionHolder<Expr> DynamicIndex<EC>::iforh(size_t step, Expr ex) const
{
DynamicExpression expr(std::make_shared<Expr>(ex));
return mkFor(mIVec.size()-1, step, expr, true);
return ForMaker<Expr>::mk(mIVec.size()-2, step, mIVec.back().first->iforhi(step,ex),
mIVec, true);
}

View file

@ -19,9 +19,14 @@
namespace MultiArrayTools
{
namespace
{
using namespace MultiArrayHelper;
}
//using MultiArrayHelper::DynamicExpression;
using MultiArrayHelper::DynamicExpression;
//using MultiArrayHelper::ExpressionHolder;
template <class ExpressionCollection>
class IndexWrapperBase
{
@ -46,7 +51,7 @@ namespace MultiArrayTools
virtual std::string stringMeta() const = 0;
//virtual DynamicMetaT meta() const = 0;
virtual const DynamicMetaT* metaPtr() const = 0;
//virtual const DynamicMetaT* metaPtr() const = 0;
//virtual IndexWrapperBase& at(const U& metaPos) = 0;
//virtual size_t posAt(const U& metaPos) const = 0;
@ -64,16 +69,19 @@ namespace MultiArrayTools
virtual size_t getStepSizeComp(std::intptr_t j) const = 0;
virtual std::intptr_t get() const = 0;
virtual std::intptr_t ptrNum() const = 0;
template <class Expr>
ExpressionHolder<Expr> ifor(size_t step, ExpressionHolder<Expr> ex) const;
template <class Expr>
auto ifor(size_t step, Expr ex) const
-> decltype(mEc->ifor(step, ex))
{ return mEc->ifor(step, ex); }
ExpressionHolder<Expr> iforh(size_t step, ExpressionHolder<Expr> ex) const;
template <class Expr>
ExpressionHolder<Expr> ifori(size_t step, Expr ex) const;
template <class Expr>
auto iforh(size_t step, Expr ex) const
-> decltype(mEc->iforh(step, ex))
{ return mEc->iforh(step, ex); }
ExpressionHolder<Expr> iforhi(size_t step, Expr ex) const;
};
@ -85,6 +93,10 @@ namespace MultiArrayTools
{
public:
typedef IndexWrapperBase<ExpressionCollection> IWB;
typedef typename Index::MetaType MetaType;
static constexpr IndexType sType() { return IndexType::SINGLE; }
protected:
IndexWrapper() = default;
@ -113,8 +125,8 @@ namespace MultiArrayTools
virtual int mm(std::intptr_t idxPtrNum) final { return mI->mm(idxPtrNum); }
virtual std::string stringMeta() const final { return mI->stringMeta(); }
virtual DynamicMetaT meta() const final { return DynamicMetaT(mI->meta()); }
virtual const DynamicMetaT* metaPtr() const final { return nullptr; }
//virtual DynamicMetaT meta() const final { return DynamicMetaT(mI->meta()); }
//virtual const DynamicMetaT* metaPtr() const final { return nullptr; }
IndexWrapper& at(const typename Index::MetaType& metaPos) { mI->at(metaPos); return *this; }
size_t posAt(const typename Index::MetaType& metaPos) const { return mI->posAt(metaPos); }
@ -127,9 +139,10 @@ namespace MultiArrayTools
virtual std::shared_ptr<RangeBase> range() const final { return mI->range(); }
virtual size_t getStepSize(size_t n) const final { return mI->getStepSize(n); }
virtual size_t getStepSizeComp(std::intptr_t j) const final { return getStepSize(*this, j); }
virtual size_t getStepSizeComp(std::intptr_t j) const final;
virtual std::intptr_t get() const final { return reinterpret_cast<std::intptr_t>(mI.get()); }
virtual std::intptr_t ptrNum() const final { return mI->ptrNum(); }
};
@ -143,9 +156,6 @@ namespace MultiArrayTools
IVecT mIVec;
inline DynamicExpression mkFor(size_t i, size_t step,
DynamicExpression ex, bool hidden = false) const;
public:
typedef IndexInterface<DynamicIndex<EC>,DynamicMetaT> IB;
typedef DynamicMetaT MetaType;
@ -167,6 +177,9 @@ namespace MultiArrayTools
DynamicIndex& operator--();
DynamicIndex& operator()(const IVecT& ivec);
template <class... Indices>
DynamicIndex& operator()(const std::shared_ptr<Indices>&... is);
int pp(std::intptr_t idxPtrNum);
int mm(std::intptr_t idxPtrNum);
@ -196,12 +209,10 @@ namespace MultiArrayTools
void print(size_t offset);
template <class Expr>
auto ifor(size_t step, Expr ex) const
-> DynamicExpression;
ExpressionHolder<Expr> ifor(size_t step, Expr ex) const;
template <class Expr>
auto iforh(size_t step, Expr ex) const
-> DynamicExpression;
ExpressionHolder<Expr> iforh(size_t step, Expr ex) const;
};
@ -335,7 +346,8 @@ namespace MultiArrayHelper
{
size_t ss = 0;
size_t sx = 1;
for(size_t i = ii.dim(); i != 0; --i){
for(size_t k = ii.dim(); k != 0; --k){
const size_t i = k-1;
const auto& ni = ii.get(i);
const size_t max = ni.max();
const size_t tmp = ni.getStepSizeComp(j);
@ -347,6 +359,6 @@ namespace MultiArrayHelper
}
#include "dynamic_range.cc.h"
//#include "dynamic_range.cc.h"
#endif

View file

@ -5,6 +5,17 @@
#include <cstdlib>
#include <iostream>
#ifndef CHECK
#define CHECK std::cout << __FILE__ << ": @" << __LINE__ << " in " << __func__ << std::endl;
#endif
#ifndef VCHECK
#define VCHECK(a) std::cout << __FILE__ << ": @" << __LINE__ \
<< " in " << __func__ << ": " << #a << " = " << a << std::endl;
#endif
namespace MultiArrayTools
{

View file

@ -584,8 +584,6 @@ namespace MultiArrayHelper
template <class Index>
static inline size_t getStepSize(const Index& ii, std::intptr_t j)
{
//VCHECK(ii.ptrNum());
//VCHECK(j);
return ii.ptrNum() == j ? 1 : 0;
}
};

View file

@ -9,6 +9,9 @@
#include "xfor/for_utils.h"
#include "xfor/exttype.h"
#define VCHECK(a) std::cout << __FILE__ << ": @" << __LINE__ \
<< " in " << __func__ << ": " << #a << " = " << a << std::endl;
namespace MultiArrayHelper
{
@ -271,8 +274,6 @@ namespace MultiArrayHelper
mExpr(expr), mExt(mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )))
{
assert(mIndPtr != nullptr);
//VCHECK(mIndPtr->id());
//VCHECK(mIndPtr->max());
}
template <class IndexClass, class Expr, ForType FT>
@ -282,8 +283,6 @@ namespace MultiArrayHelper
mExpr(expr), mExt(mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )))
{
assert(mIndPtr != nullptr);
//VCHECK(mIndPtr->id());
//VCHECK(mIndPtr->max());
}
template <class IndexClass, class Expr, ForType FT>
@ -501,14 +500,14 @@ namespace MultiArrayHelper
auto ExpressionHolder<Expr>::rootSteps(std::intptr_t iPtrNum) const
-> ExtType
{
return *reinterpret_cast<ExtType*>( mExpr.dRootSteps(iPtrNum).first );
return *reinterpret_cast<ExtType const*>( mExpr.dRootSteps(iPtrNum).first );
}
template <class Expr>
auto ExpressionHolder<Expr>::extension() const
-> ExtType
{
return *reinterpret_cast<ExtType*>( mExpr.dExtension().first );
return *reinterpret_cast<ExtType const*>( mExpr.dExtension().first );
}

View file

@ -64,6 +64,8 @@ namespace {
return std::make_tuple(static_cast<size_t>( ts )...);
}
typedef Expressions1 EC1;
template <typename T>
struct Pow
{
@ -153,6 +155,8 @@ namespace {
std::vector<double> v2 = { 8.870, 4.790 };
std::vector<double> v3 = { 0.353, 4.005, 1.070, 2.310, 9.243, 2.911 };
std::vector<double> v4 = { 1.470, 2.210 };
std::vector<double> v5 = { 30.932, -33.693, -26.205, -15.504, 21.227, 17.829,
-14.364, -1.868, -25.703, 13.836, 23.563, 41.339 };
};
class MapTest : public ::testing::Test
@ -485,46 +489,7 @@ namespace {
<< std::endl;
std::cout << "ratio: " << static_cast<double>( end - begin ) / static_cast<double>( end2 - begin2 ) << std::endl;
}
/*
TEST_F(OpTest_Performance, PCheck)
{
MultiArray<double,MRange> ma2(mrptr, cv2);
MultiArray<double,SRange> ma1(sr1ptr, cv1);
MultiArray<double,MRange> res(mrptr);
auto si1 = MAT::getIndex(sr1ptr);
auto si2 = MAT::getIndex(sr2ptr);
auto mi = MAT::getIndex(mrptr);
(*mi)(si2, si1);
std::clock_t begin = std::clock();
res(mi) = ma2(mi) * ma1(si1);
std::clock_t end = std::clock();
std::cout << "MultiArray time: " << static_cast<double>( end - begin ) / CLOCKS_PER_SEC
<< std::endl;
std::vector<double> res2(vs1*vs2);
std::clock_t begin2 = std::clock();
for(size_t i = 0; i != vs2; ++i){
for(size_t j = 0; j != vs1; ++j){
res2[i*vs1 + j] = cv1[j] * cv2[i*vs1 + j];
}
}
std::clock_t end2 = std::clock();
std::cout << "std::vector - for loop time: " << static_cast<double>( end2 - begin2 ) / CLOCKS_PER_SEC
<< std::endl;
std::cout << "ratio: " << static_cast<double>( end - begin ) / static_cast<double>( end2 - begin2 ) << std::endl;
EXPECT_EQ( xround( res.at(mkt(7,9)) ), xround(res2[7*vs1 + 9]) );
//EXPECT_EQ( xround( res.at(mkt(700,900)) ), xround(res2[700*vs1 + 900]) );
}
*/
TEST_F(OpTest_1Dim, ExecOp)
{
MultiArray<double,SRange> ma1(srptr, v1);
@ -681,6 +646,53 @@ namespace {
EXPECT_EQ( xround( res.at(mkt(mkt('3','b'),'B')) ), xround(2.911 / ( 1 + 4.790 / 2.210) ) );
}
TEST_F(OpTest_MDim, ExecDOp)
{
//typedef MultiArray<double,AnonymousRange> AMA;
typedef MultiArray<double,DynamicRange<EC1> > DMA;
MultiArray<double,MRange,SRange> ma1(mr1ptr,sr4ptr,v5);
MultiArray<double,SRange> ma2(sr2ptr,v1);
MultiArray<double,SRange,MRange> res(sr4ptr,mr1ptr);
DMA dma1 = *std::dynamic_pointer_cast<DMA>( dynamic<EC1>( ma1 ) );
DMA dma2 = *std::dynamic_pointer_cast<DMA>( dynamic<EC1>( ma2 ) );
DMA dres = *std::dynamic_pointer_cast<DMA>( dynamic<EC1>( res ) );
auto si2 = MAT::getIndex( sr2ptr );
auto si3 = MAT::getIndex( sr3ptr );
auto si4 = MAT::getIndex( sr4ptr );
auto mi = MAT::getIndex( mr1ptr );
(*mi)(si2,si3);
auto di1 = MAT::getIndex( MAT::rptr<0>( dma1 ) );
auto di2 = MAT::getIndex( MAT::rptr<0>( dma2 ) );
auto dir = MAT::getIndex( MAT::rptr<0>( dres ) );
(*di1)(mi,si4);
(*di2)(si2);
(*dir)(si4,mi);
dres(dir) = dma1(di1) + dma2(di2);
MultiArray<double,SRange,MRange> res2(sr4ptr,mr1ptr,dres.vdata());
EXPECT_EQ( xround( res2.at( mkt('A',mkt('1','a')) ) ), xround( 30.932 + 2.917 ) );
EXPECT_EQ( xround( res2.at( mkt('A',mkt('1','b')) ) ), xround( -26.205 + 2.917 ) );
EXPECT_EQ( xround( res2.at( mkt('A',mkt('2','a')) ) ), xround( 21.227 + 9.436 ) );
EXPECT_EQ( xround( res2.at( mkt('A',mkt('2','b')) ) ), xround( -14.364 + 9.436 ) );
EXPECT_EQ( xround( res2.at( mkt('A',mkt('3','a')) ) ), xround( -25.703 + 0.373 ) );
EXPECT_EQ( xround( res2.at( mkt('A',mkt('3','b')) ) ), xround( 23.563 + 0.373 ) );
EXPECT_EQ( xround( res2.at( mkt('B',mkt('1','a')) ) ), xround( -33.693 + 2.917 ) );
EXPECT_EQ( xround( res2.at( mkt('B',mkt('1','b')) ) ), xround( -15.504 + 2.917 ) );
EXPECT_EQ( xround( res2.at( mkt('B',mkt('2','a')) ) ), xround( 17.829 + 9.436 ) );
EXPECT_EQ( xround( res2.at( mkt('B',mkt('2','b')) ) ), xround( -1.868 + 9.436 ) );
EXPECT_EQ( xround( res2.at( mkt('B',mkt('3','a')) ) ), xround( 13.836 + 0.373 ) );
EXPECT_EQ( xround( res2.at( mkt('B',mkt('3','b')) ) ), xround( 41.339 + 0.373 ) );
}
TEST_F(OpTest_MDim, ExecOp3)
{
MultiArray<double,MRange,SRange> res(mr1ptr,sr4ptr);
@ -762,6 +774,7 @@ namespace {
EXPECT_EQ( xround( ma7.at(mkt('3','B')).at(mkt('l','b')) ),
xround( ma4.at(mkt('l','3','b','B')) ) );
}
/*
TEST_F(OpTest_MDim, ExecAnonOp1)
{