resolve merge conflict
This commit is contained in:
commit
3f20bc1f07
6 changed files with 106 additions and 9 deletions
|
@ -50,8 +50,9 @@ namespace MultiArrayTools
|
|||
|
||||
virtual const T* data() const override;
|
||||
virtual T* data() override;
|
||||
|
||||
virtual std::vector<T>& vdata() { return mCont; }
|
||||
|
||||
operator T() const;
|
||||
|
||||
template <typename U, class... SRanges2>
|
||||
friend class MultiArray;
|
||||
|
@ -59,6 +60,9 @@ namespace MultiArrayTools
|
|||
private:
|
||||
std::vector<T> mCont;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
using Scalar = MultiArray<T>;
|
||||
|
||||
}
|
||||
|
||||
|
@ -195,6 +199,13 @@ namespace MultiArrayTools
|
|||
{
|
||||
return mCont.data();
|
||||
}
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
MultiArray<T,SRanges...>::operator T() const
|
||||
{
|
||||
static_assert( sizeof...(SRanges) == 0, "try to cast non-scalar type into scalar" );
|
||||
return mCont[0];
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -248,6 +248,7 @@ namespace MultiArrayTools
|
|||
typedef decltype(PackNum<sizeof...(Ops)-1>::template mkSteps<Ops...>(0, mOps)) ETuple;
|
||||
|
||||
Operation(const Ops&... ops);
|
||||
Operation(std::shared_ptr<OpFunction> ff, const Ops&... ops);
|
||||
|
||||
template <class ET>
|
||||
inline T get(ET pos) const;
|
||||
|
@ -522,7 +523,19 @@ namespace MultiArrayTools
|
|||
|
||||
template <typename T, class OpFunction, class... Ops>
|
||||
Operation<T,OpFunction,Ops...>::Operation(const Ops&... ops) :
|
||||
mOps(ops...) {}
|
||||
mOps(ops...)
|
||||
{
|
||||
static_assert( FISSTATIC, "need function instance for non-static function" );
|
||||
}
|
||||
|
||||
template <typename T, class OpFunction, class... Ops>
|
||||
Operation<T,OpFunction,Ops...>::Operation(std::shared_ptr<OpFunction> ff,
|
||||
const Ops&... ops) :
|
||||
mOps(ops...),
|
||||
mF(ff)
|
||||
{
|
||||
static_assert( not FISSTATIC, "using instance of function supposed to be static" );
|
||||
}
|
||||
|
||||
template <typename T, class OpFunction, class... Ops>
|
||||
template <class ET>
|
||||
|
@ -530,7 +543,7 @@ namespace MultiArrayTools
|
|||
{
|
||||
typedef std::tuple<Ops...> OpTuple;
|
||||
return PackNum<sizeof...(Ops)-1>::
|
||||
template mkOpExpr<SIZE,T,ET,OpTuple,OpFunction>(pos, mOps);
|
||||
template mkOpExpr<SIZE,T,ET,OpTuple,OpFunction>(mF, pos, mOps);
|
||||
}
|
||||
|
||||
template <typename T, class OpFunction, class... Ops>
|
||||
|
|
|
@ -13,6 +13,26 @@
|
|||
|
||||
namespace MultiArrayHelper
|
||||
{
|
||||
template <bool ISSTATIC>
|
||||
struct Application
|
||||
{
|
||||
template <class OpFunction, typename T, typename... Ts>
|
||||
static inline T apply(std::shared_ptr<OpFunction> f, T a, Ts... as)
|
||||
{
|
||||
return (*f)(a, as...);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Application<true>
|
||||
{
|
||||
template <class OpFunction, typename T, typename... Ts>
|
||||
static inline T apply(std::shared_ptr<OpFunction> f, T a, Ts... as)
|
||||
{
|
||||
return OpFunction::apply(a, as...);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <size_t N>
|
||||
struct PackNum
|
||||
|
@ -41,13 +61,13 @@ namespace MultiArrayHelper
|
|||
}
|
||||
|
||||
template <size_t LAST, typename T, class ETuple, class OpTuple, class OpFunction, typename... Args>
|
||||
static inline T mkOpExpr(const ETuple& pos, const OpTuple& ops, const Args&... args)
|
||||
static inline T mkOpExpr(std::shared_ptr<OpFunction> f, const ETuple& pos, const OpTuple& ops, const Args&... args)
|
||||
{
|
||||
typedef typename std::remove_reference<decltype(std::get<N>(ops))>::type NextOpType;
|
||||
static_assert(LAST > NextOpType::SIZE, "inconsistent array positions");
|
||||
static constexpr size_t NEXT = LAST - NextOpType::SIZE;
|
||||
return PackNum<N-1>::template mkOpExpr<NEXT,T,ETuple,OpTuple,OpFunction,T,Args...>
|
||||
( pos, ops, std::get<N>(ops).get(Getter<NEXT>::template getX<ETuple>( pos )), args...);
|
||||
( f, pos, ops, std::get<N>(ops).get(Getter<NEXT>::template getX<ETuple>( pos )), args...);
|
||||
}
|
||||
|
||||
template <class OpTuple, class Expr>
|
||||
|
@ -94,14 +114,15 @@ namespace MultiArrayHelper
|
|||
{
|
||||
std::get<0>(out) = second.rootSteps( std::get<0>(siar) );
|
||||
}
|
||||
|
||||
|
||||
template <size_t LAST, typename T, class ETuple, class OpTuple, class OpFunction, typename... Args>
|
||||
static inline T mkOpExpr(const ETuple& pos, const OpTuple& ops, const Args&... args)
|
||||
static inline T mkOpExpr(std::shared_ptr<OpFunction> f, const ETuple& pos, const OpTuple& ops, const Args&... args)
|
||||
{
|
||||
typedef typename std::remove_reference<decltype(std::get<0>(ops))>::type NextOpType;
|
||||
static constexpr size_t NEXT = LAST - NextOpType::SIZE;
|
||||
static_assert(NEXT == 0, "inconsistent array positions");
|
||||
return OpFunction::apply(std::get<0>(ops).get(Getter<0>::template getX<ETuple>( pos )), args...);
|
||||
return Application<OpFunction::FISSTATIC>::apply(f, std::get<0>(ops).get(Getter<0>::template getX<ETuple>( pos )), args...);
|
||||
//return OpFunction::apply(std::get<0>(ops).get(Getter<0>::template getX<ETuple>( pos )), args...);
|
||||
}
|
||||
|
||||
template <class OpTuple, class Expr>
|
||||
|
|
|
@ -51,7 +51,12 @@ namespace MultiArrayTools
|
|||
|
||||
virtual IndexType begin() const override;
|
||||
virtual IndexType end() const override;
|
||||
|
||||
|
||||
std::shared_ptr<RangeBase> sub(size_t num) const;
|
||||
|
||||
template <class Range>
|
||||
std::shared_ptr<Range> fullsub(size_t num) const;
|
||||
|
||||
friend AnonymousRangeFactory;
|
||||
|
||||
protected:
|
||||
|
@ -118,6 +123,12 @@ namespace MultiArrayTools
|
|||
//RPackNum<sizeof...(RangeTypes)-1>::getSize( rst );
|
||||
}
|
||||
|
||||
template <class Range>
|
||||
std::shared_ptr<Range> AnonymousRange::fullsub(size_t num) const
|
||||
{
|
||||
return std::dynamic_pointer_cast<Range>( mOrig.at(num) );
|
||||
}
|
||||
|
||||
/*****************
|
||||
* Functions *
|
||||
*****************/
|
||||
|
|
|
@ -54,6 +54,11 @@ namespace MultiArrayTools
|
|||
i = size();
|
||||
return i;
|
||||
}
|
||||
|
||||
std::shared_ptr<RangeBase> AnonymousRange::sub(size_t num) const
|
||||
{
|
||||
return mOrig.at(num);
|
||||
}
|
||||
|
||||
/*****************
|
||||
* Functions *
|
||||
|
|
|
@ -15,6 +15,7 @@ namespace {
|
|||
|
||||
double xround(double arg)
|
||||
{
|
||||
if(std::isnan(arg)) { return 0.; }
|
||||
return roundf(arg * 100000.) / 100000.;
|
||||
}
|
||||
|
||||
|
@ -265,6 +266,15 @@ namespace {
|
|||
|
||||
std::vector<double> mv1;
|
||||
std::vector<double> mv2;
|
||||
|
||||
double vcontract(size_t i)
|
||||
{
|
||||
double res = 0.;
|
||||
for(auto& x: mv2){
|
||||
res += pow(mv1[i],x);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -276,6 +286,32 @@ namespace {
|
|||
|
||||
EXPECT_EQ( xround( fma[ i.at( mkt(9.665, -0.0765) ) ] ), xround( pow(9.665, -0.0765) ) );
|
||||
}
|
||||
|
||||
TEST_F(MetaOp_Test, Operation)
|
||||
{
|
||||
FunctionalMultiArray<double,Pow<double>,SR,SR> fma(sr1ptr, sr2ptr);
|
||||
MultiArray<double,SR> res( sr1ptr );
|
||||
|
||||
auto i1 = MAT::getIndex(sr1ptr);
|
||||
auto i2 = MAT::getIndex(sr2ptr);
|
||||
|
||||
res(i1) = fma(i1,i2).c(i2);
|
||||
|
||||
auto i = res.begin();
|
||||
|
||||
EXPECT_EQ( xround( res[ i.at( 2.476 ) ] ), xround( vcontract(0) ) );
|
||||
EXPECT_EQ( xround( res[ i.at( 9.665 ) ] ), xround( vcontract(1) ) );
|
||||
EXPECT_EQ( xround( res[ i.at( 1.289 ) ] ), xround( vcontract(2) ) );
|
||||
EXPECT_EQ( xround( res[ i.at( 2.89 ) ] ), xround( vcontract(3) ) );
|
||||
EXPECT_EQ( xround( res[ i.at( 77.04 ) ] ), xround( vcontract(4) ) );
|
||||
|
||||
EXPECT_EQ( xround( res[ i.at( -11.09 ) ] ), xround( vcontract(5) ) );
|
||||
EXPECT_EQ( xround( res[ i.at( 100.4 ) ] ), xround( vcontract(6) ) );
|
||||
EXPECT_EQ( xround( res[ i.at( 2.0 ) ] ), xround( vcontract(7) ) );
|
||||
EXPECT_EQ( xround( res[ i.at( -26.5 ) ] ), xround( vcontract(8) ) );
|
||||
EXPECT_EQ( xround( res[ i.at( -0.001 ) ] ), xround( vcontract(9) ) );
|
||||
}
|
||||
|
||||
|
||||
TEST_F(OpTest_Spin, Contract)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue