delete old/unused code
This commit is contained in:
parent
0570a502c0
commit
b75f2b4cf8
13 changed files with 2 additions and 1348 deletions
|
@ -9,7 +9,7 @@
|
|||
|
||||
#include "base_def.h"
|
||||
#include "range_base.h"
|
||||
#include "name.h"
|
||||
|
||||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
|
|
|
@ -1,96 +0,0 @@
|
|||
// -*- C++ -*-
|
||||
|
||||
#include "ma_functional.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
|
||||
template <class InRange, class OutRange>
|
||||
IndexMapFunction<InRange,OutRange>::
|
||||
IndexMapFunction(const MultiArrayBase<typename OutRange::IndexType,InRange>& ma,
|
||||
const OutRange& outRange,
|
||||
const Name& inName, const Name& outName) : mMap(ma, inName),
|
||||
mOutRange(new OutRange( outRange )),
|
||||
mOIndex(mOutRange->begin())
|
||||
{
|
||||
//CHECK;
|
||||
mOIndex.name(outName);
|
||||
}
|
||||
|
||||
template <class InRange, class OutRange>
|
||||
void IndexMapFunction<InRange,OutRange>::linkIndicesTo(IndefinitIndexBase* target)
|
||||
{
|
||||
mMap.linkIndicesTo(target);
|
||||
}
|
||||
|
||||
template <class InRange, class OutRange>
|
||||
void IndexMapFunction<InRange,OutRange>::eval() const
|
||||
{
|
||||
mOIndex.copyPos( mMap.get() );
|
||||
}
|
||||
|
||||
template <class InRange, class OutRange>
|
||||
IndefinitIndexBase& IndexMapFunction<InRange,OutRange>::index() const
|
||||
{
|
||||
return mOIndex;
|
||||
}
|
||||
|
||||
|
||||
|
||||
vec3d2Function::vec3d2Function(const OutRange& outRange) : mOutRange(new OutRange( outRange )),
|
||||
out(mOutRange->begin()) {}
|
||||
|
||||
vec3d2Function::OutIndex vec3d2Function::operator()(const InIndex& i) const
|
||||
{
|
||||
OutSubIndex& osi = out.template getIndex<0>();
|
||||
|
||||
osi.atMeta( i.template getIndex<0>().getMetaPos() * i.template getIndex<0>().getMetaPos() +
|
||||
i.template getIndex<1>().getMetaPos() * i.template getIndex<1>().getMetaPos() +
|
||||
i.template getIndex<2>().getMetaPos() * i.template getIndex<2>().getMetaPos() );
|
||||
return out;
|
||||
}
|
||||
|
||||
pyProjFunction::pyProjFunction(const OutRange& outRange) : mOutRange(new OutRange( outRange )),
|
||||
out(mOutRange->begin()) {}
|
||||
|
||||
pyProjFunction::OutIndex pyProjFunction::operator()(const InIndex& i) const
|
||||
{
|
||||
DistIndex& di = out.template getIndex<0>();
|
||||
ScalProdIndex& si = out.template getIndex<1>();
|
||||
const int xx = i.template getIndex<1>().getMetaPos();
|
||||
const int yy = i.template getIndex<2>().getMetaPos();
|
||||
const int zz = i.template getIndex<3>().getMetaPos();
|
||||
if(xx == 0 or yy == 0 or zz == 0){ // anistotropy in C2
|
||||
di.atMeta(0);
|
||||
si.atMeta(0);
|
||||
}
|
||||
|
||||
di.atMeta( xx * xx + yy * yy + zz * zz );
|
||||
si.atMeta( abs( xx * i.template getIndex<0>().getMetaPos()[0] +
|
||||
yy * i.template getIndex<0>().getMetaPos()[1] +
|
||||
zz * i.template getIndex<0>().getMetaPos()[2] ) );
|
||||
return out;
|
||||
}
|
||||
|
||||
pyProjNoSymFunction::pyProjNoSymFunction(const OutRange& outRange) : mOutRange(new OutRange( outRange )),
|
||||
out(mOutRange->begin()) {}
|
||||
|
||||
pyProjNoSymFunction::OutIndex pyProjNoSymFunction::operator()(const InIndex& i) const
|
||||
{
|
||||
DistIndex& di = out.template getIndex<0>();
|
||||
ScalProdIndex& si = out.template getIndex<1>();
|
||||
const int xx = i.template getIndex<1>().getMetaPos();
|
||||
const int yy = i.template getIndex<2>().getMetaPos();
|
||||
const int zz = i.template getIndex<3>().getMetaPos();
|
||||
if(xx == 0 or yy == 0 or zz == 0){ // anistotropy in C2
|
||||
di.atMeta(0);
|
||||
si.atMeta(0);
|
||||
}
|
||||
|
||||
di.atMeta( xx * xx + yy * yy + zz * zz );
|
||||
si.atMeta( xx * i.template getIndex<0>().getMetaPos()[0] +
|
||||
yy * i.template getIndex<0>().getMetaPos()[1] +
|
||||
zz * i.template getIndex<0>().getMetaPos()[2] );
|
||||
return out;
|
||||
}
|
||||
}
|
|
@ -1,114 +0,0 @@
|
|||
// -*- C++ -*-
|
||||
|
||||
#ifndef __ma_functional_h__
|
||||
#define __ma_functional_h__
|
||||
|
||||
#include <cstdlib>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
|
||||
#include "base_def.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
|
||||
// Map is a ConstMultiArrayOperationRoot where the corresponding MultiArray defines the map
|
||||
template <class InRange, class OutRange>
|
||||
class IndexMapFunction
|
||||
{
|
||||
public:
|
||||
|
||||
typedef OutRange OR;
|
||||
typedef typename OutRange::IndexType OutIndex;
|
||||
|
||||
//IndexMapFunction() = default;
|
||||
|
||||
IndexMapFunction(const MultiArrayBase<typename OutRange::IndexType,InRange>& ma,
|
||||
const OutRange& outRange,
|
||||
const Name& inName, const Name& outName);
|
||||
|
||||
IndexMapFunction(const IndexMapFunction& in) = default;
|
||||
|
||||
void linkIndicesTo(IndefinitIndexBase* target);
|
||||
void eval() const;
|
||||
|
||||
IndefinitIndexBase& index() const;
|
||||
|
||||
private:
|
||||
|
||||
ConstMultiArrayOperationRoot<typename OutRange::IndexType,InRange> mMap;
|
||||
std::shared_ptr<OutRange> mOutRange;
|
||||
mutable typename OutRange::IndexType mOIndex;
|
||||
};
|
||||
|
||||
class vec3d2Function
|
||||
{
|
||||
public:
|
||||
|
||||
typedef SingleIndex<int,RangeType::SPACE> CoordIndex;
|
||||
typedef MultiIndex<CoordIndex,CoordIndex,CoordIndex> InIndex;
|
||||
typedef SingleIndex<size_t,RangeType::DISTANCE> OutSubIndex;
|
||||
typedef MultiIndex<OutSubIndex> OutIndex;
|
||||
typedef MultiRange<SingleRange<size_t,RangeType::DISTANCE> > OutRange;
|
||||
|
||||
DEFAULT_MEMBERS(vec3d2Function);
|
||||
|
||||
vec3d2Function(const OutRange& outRange);
|
||||
//vec3d2Function& operator=(const vec3d2Function& in) = default;
|
||||
|
||||
OutIndex operator()(const InIndex& i) const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<OutRange> mOutRange;
|
||||
mutable OutIndex out;
|
||||
};
|
||||
|
||||
class pyProjFunction
|
||||
{
|
||||
public:
|
||||
typedef SingleIndex<int,RangeType::SPACE> CoordIndex;
|
||||
typedef SingleIndex<std::array<int,3>,RangeType::MOMENTUM> MomIndex;
|
||||
typedef MultiIndex<MomIndex,CoordIndex,CoordIndex,CoordIndex> InIndex;
|
||||
typedef SingleIndex<size_t,RangeType::DISTANCE> DistIndex;
|
||||
typedef SingleIndex<int,RangeType::SPACE> ScalProdIndex;
|
||||
typedef MultiIndex<DistIndex,ScalProdIndex> OutIndex;
|
||||
typedef MultiRange<SingleRange<size_t,RangeType::DISTANCE>,
|
||||
SingleRange<int,RangeType::SPACE> > OutRange;
|
||||
|
||||
DEFAULT_MEMBERS(pyProjFunction);
|
||||
|
||||
pyProjFunction(const OutRange& outRange);
|
||||
OutIndex operator()(const InIndex& i) const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<OutRange> mOutRange;
|
||||
mutable OutIndex out;
|
||||
};
|
||||
|
||||
class pyProjNoSymFunction
|
||||
{
|
||||
public:
|
||||
typedef SingleIndex<int,RangeType::SPACE> CoordIndex;
|
||||
typedef SingleIndex<std::array<int,3>,RangeType::MOMENTUM> MomIndex;
|
||||
typedef MultiIndex<MomIndex,CoordIndex,CoordIndex,CoordIndex> InIndex;
|
||||
typedef SingleIndex<size_t,RangeType::DISTANCE> DistIndex;
|
||||
typedef SingleIndex<int,RangeType::SPACE> ScalProdIndex;
|
||||
typedef MultiIndex<DistIndex,ScalProdIndex> OutIndex;
|
||||
typedef MultiRange<SingleRange<size_t,RangeType::DISTANCE>,
|
||||
SingleRange<int,RangeType::SPACE> > OutRange;
|
||||
|
||||
DEFAULT_MEMBERS(pyProjNoSymFunction);
|
||||
|
||||
pyProjNoSymFunction(const OutRange& outRange);
|
||||
OutIndex operator()(const InIndex& i) const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<OutRange> mOutRange;
|
||||
mutable OutIndex out;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#include "ma_functional.cc"
|
||||
|
||||
#endif
|
|
@ -13,7 +13,7 @@
|
|||
#include "multi_range.h"
|
||||
//#include "multi_array_operation.h"
|
||||
//#include "manipulator.h"
|
||||
//#include "name.h"
|
||||
//
|
||||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
|
|
95
src/name.cc
95
src/name.cc
|
@ -1,95 +0,0 @@
|
|||
|
||||
#include "name.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
struct Naming
|
||||
{
|
||||
static void giveNames(std::vector<Name>& nvec)
|
||||
{
|
||||
nvec.clear();
|
||||
}
|
||||
|
||||
static void giveNames(std::vector<Name>& nvec, const Name& name)
|
||||
{
|
||||
nvec.push_back(name);
|
||||
}
|
||||
|
||||
template <class... NameTypes>
|
||||
static void giveNames(std::vector<Name>& nvec, const Name& name1,
|
||||
const Name& name2, const NameTypes&... names)
|
||||
{
|
||||
nvec.push_back(name1);
|
||||
giveNames(nvec, name2, names...);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
template <class... NameTypes>
|
||||
Name::Name(const std::string& mainName, const NameTypes&... names) : mMain(mainName)
|
||||
{
|
||||
mSub.reserve(sizeof...(NameTypes));
|
||||
Naming::giveNames(mSub, names...);
|
||||
}
|
||||
|
||||
template <class... NameTypes>
|
||||
Name::Name(char const* mainName, const NameTypes&... names) : mMain(mainName)
|
||||
{
|
||||
mSub.reserve(sizeof...(NameTypes));
|
||||
Naming::giveNames(mSub, names...);
|
||||
}
|
||||
|
||||
const std::string& Name::own() const
|
||||
{
|
||||
return mMain;
|
||||
}
|
||||
|
||||
const Name& Name::get(size_t n) const
|
||||
{
|
||||
return mSub.at(n);
|
||||
}
|
||||
|
||||
void Name::autoName(size_t newSize)
|
||||
{
|
||||
size_t oldSize = mSub.size();
|
||||
mSub.resize(newSize);
|
||||
if(oldSize < newSize){
|
||||
for(size_t i = oldSize; i != newSize; ++i){
|
||||
mSub[i] = Name( mMain + std::to_string( i ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Name::remove(const std::string& s)
|
||||
{
|
||||
for(size_t i = 0; i != mSub.size(); ++i){
|
||||
if(mSub[i].own() == s){
|
||||
mSub.erase(mSub.begin()+i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_t Name::size() const
|
||||
{
|
||||
return mSub.size();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const MultiArrayTools::Name& name)
|
||||
{
|
||||
if(name.size() != 0){
|
||||
for(size_t i = 0; i != name.size(); ++i){
|
||||
os << name.get(i) << '\t';
|
||||
}
|
||||
}
|
||||
else {
|
||||
os << name.own();
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
44
src/name.h
44
src/name.h
|
@ -1,44 +0,0 @@
|
|||
// -*- C++ -*-
|
||||
|
||||
#ifndef __name_h__
|
||||
#define __name_h__
|
||||
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <ostream>
|
||||
|
||||
#include "base_def.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
class Name
|
||||
{
|
||||
public:
|
||||
|
||||
DEFAULT_MEMBERS(Name);
|
||||
|
||||
template <class... NameTypes>
|
||||
Name(const std::string& mainName, const NameTypes&... names);
|
||||
|
||||
template <class... NameTypes>
|
||||
Name(char const* mainName, const NameTypes&... names);
|
||||
|
||||
const std::string& own() const;
|
||||
const Name& get(size_t n) const;
|
||||
|
||||
void autoName(size_t newSize);
|
||||
void remove(const std::string& s);
|
||||
size_t size() const;
|
||||
|
||||
private:
|
||||
std::string mMain;
|
||||
std::vector<Name> mSub;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const MultiArrayTools::Name& name);
|
||||
|
||||
#include "name.cc"
|
||||
|
||||
#endif
|
|
@ -1,34 +0,0 @@
|
|||
// -*- C++ -*-
|
||||
|
||||
#include "range_transformer.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
|
||||
template <class... Ranges>
|
||||
MultiRange<Ranges...> makeRange(const std::tuple<Ranges...>& rangeTuple)
|
||||
{
|
||||
return MultiRange<Ranges...>( rangeTuple );
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
MultiRange<Ranges...> combine(const Ranges&... ranges)
|
||||
{
|
||||
return MultiRange<Ranges...>(ranges...);
|
||||
}
|
||||
|
||||
template <class Range, class... Ranges>
|
||||
auto extend(const Range& r, const MultiRange<Ranges...>& mr)
|
||||
-> decltype( MultiRange<Range,Ranges...>(std::tuple_cat( std::make_tuple(r), mr.space() ) ) )
|
||||
{
|
||||
return MultiRange<Range,Ranges...>(std::tuple_cat( std::make_tuple(r), mr.space() ) );
|
||||
}
|
||||
|
||||
template <class MultiRange1, class MultiRange2>
|
||||
auto merge(const MultiRange1& mr1, const MultiRange2& mr2)
|
||||
-> decltype( makeRange( std::tuple_cat( mr1.space(), mr2.space() ) ) )
|
||||
{
|
||||
return makeRange( std::tuple_cat( mr1.space(), mr2.space() ) );
|
||||
}
|
||||
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
// -*- C++ -*-
|
||||
|
||||
#ifndef __range_transformer_h__
|
||||
#define __range_transformer_h__
|
||||
|
||||
#include <cstdlib>
|
||||
#include "base_def.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
|
||||
template <class... Ranges>
|
||||
MultiRange<Ranges...> makeRange(const std::tuple<Ranges...>& rangeTuple);
|
||||
|
||||
template <class... Ranges>
|
||||
MultiRange<Ranges...> combine(const Ranges&... ranges);
|
||||
|
||||
template <class Range, class... Ranges>
|
||||
auto extend(const Range& r, const MultiRange<Ranges...>& mr)
|
||||
-> decltype( MultiRange<Range,Ranges...>(std::tuple_cat( std::make_tuple(r), mr.space() ) ) );
|
||||
|
||||
template <class MultiRange1, class MultiRange2>
|
||||
auto merge(const MultiRange1& mr1, const MultiRange2& mr2)
|
||||
-> decltype(makeRange( std::tuple_cat( mr1.space(), mr2.space() ) ) );
|
||||
}
|
||||
|
||||
#include "range_transformer.cc"
|
||||
|
||||
#endif
|
181
src/slice.cc
181
src/slice.cc
|
@ -1,181 +0,0 @@
|
|||
// -*- C++ -*-
|
||||
|
||||
#include "slice.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
|
||||
template <typename T, class Range, class MARange>
|
||||
Slice<T,Range,MARange>::
|
||||
Slice(const Range& range,
|
||||
const Name& ownNm, // for correct linkage
|
||||
MutableMultiArrayBase<T,MARange>& multiArrayRef,
|
||||
const typename MARange::IndexType& MAIdx, // for desired slice position
|
||||
const Name& MANm) :
|
||||
MutableMultiArrayBase<T,Range>(range),
|
||||
mOwnName(ownNm), mMAName(MANm), mMultiArrayPtr(&multiArrayRef),
|
||||
mMAIdx(MAIdx), mBeginIndex(range.begin()), mEndIndex(range.end())
|
||||
{
|
||||
MAB::mInit = true;
|
||||
mOwnIdx = MAB::mRange->begin();
|
||||
mMAIdx.name(MANm);
|
||||
mOwnIdx.name(ownNm);
|
||||
mMAIdx.linkTo(&mOwnIdx);
|
||||
}
|
||||
|
||||
template <typename T, class Range, class MARange>
|
||||
Slice<T,Range,MARange>::
|
||||
Slice(const Range& range,
|
||||
const Name& ownNm,
|
||||
MultiArrayOperationRoot<T,MARange>& mor,
|
||||
const typename MARange::IndexType& MAIdx) :
|
||||
MutableMultiArrayBase<T,Range>(range),
|
||||
mOwnName(ownNm), mMAName(mor.name()), mMultiArrayPtr(&(*mor)),
|
||||
mMAIdx(MAIdx), mBeginIndex(range.begin()), mEndIndex(range.end())
|
||||
{
|
||||
MAB::mInit = true;
|
||||
mOwnIdx = MAB::mRange->begin();
|
||||
mMAIdx.name(mMAName);
|
||||
mOwnIdx.name(ownNm);
|
||||
mMAIdx.linkTo(&mOwnIdx);
|
||||
}
|
||||
|
||||
template <typename T, class Range, class MARange>
|
||||
bool Slice<T,Range,MARange>::isSlice() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T, class Range, class MARange>
|
||||
auto Slice<T,Range,MARange>::beginIndex() const -> decltype(Range().begin())
|
||||
{
|
||||
return mBeginIndex;
|
||||
}
|
||||
|
||||
template <typename T, class Range, class MARange>
|
||||
auto Slice<T,Range,MARange>::endIndex() const -> decltype(Range().end())
|
||||
{
|
||||
return mEndIndex;
|
||||
}
|
||||
|
||||
// slow!!
|
||||
template <typename T, class Range, class MARange>
|
||||
T& Slice<T,Range,MARange>::operator[](const typename Range::IndexType& i)
|
||||
{
|
||||
mOwnIdx.copyPos(i);
|
||||
return (*mMultiArrayPtr)[ mMAIdx ];
|
||||
}
|
||||
|
||||
// slow!!
|
||||
template <typename T, class Range, class MARange>
|
||||
const T& Slice<T,Range,MARange>::operator[](const typename Range::IndexType& i) const
|
||||
{
|
||||
mOwnIdx.copyPos(i);
|
||||
return (*mMultiArrayPtr)[ mMAIdx ];
|
||||
}
|
||||
|
||||
template <typename T, class Range, class MARange>
|
||||
bool Slice<T,Range,MARange>::isConst() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename T, class Range, class MARange>
|
||||
void Slice<T,Range,MARange>::link(IndefinitIndexBase* iibPtr) const
|
||||
{
|
||||
mMAIdx.linkTo(iibPtr);
|
||||
}
|
||||
|
||||
template <typename T, class Range, class MARange>
|
||||
ConstSlice<T,Range,MARange>::
|
||||
ConstSlice(const Range& range,
|
||||
const Name& ownNm, // for correct linkage
|
||||
const MultiArrayBase<T,MARange>& multiArrayRef,
|
||||
const typename MARange::IndexType& MAIdx, // for desired slice position
|
||||
const Name& MANm) :
|
||||
MultiArrayBase<T,Range>(range),
|
||||
mMultiArrayPtr(&multiArrayRef),
|
||||
mMAIdx(MAIdx), mBeginIndex(range.begin()), mEndIndex(range.end())
|
||||
{
|
||||
MAB::mInit = true;
|
||||
mOwnIdx = MAB::mRange->begin();
|
||||
mMAIdx.name(MANm);
|
||||
mOwnIdx.name(ownNm);
|
||||
mMAIdx.linkTo(&mOwnIdx);
|
||||
}
|
||||
|
||||
template <typename T, class Range, class MARange>
|
||||
ConstSlice<T,Range,MARange>::
|
||||
ConstSlice(const Range& range,
|
||||
const Name& ownNm,
|
||||
const ConstMultiArrayOperationRoot<T,MARange>& mor,
|
||||
const typename MARange::IndexType& MAIdx) :
|
||||
MultiArrayBase<T,Range>(range),
|
||||
mMultiArrayPtr(&(*mor)),
|
||||
mMAIdx(MAIdx), mBeginIndex(range.begin()), mEndIndex(range.end())
|
||||
{
|
||||
MAB::mInit = true;
|
||||
mOwnIdx = MAB::mRange->begin();
|
||||
mMAIdx.name(mor.name());
|
||||
mOwnIdx.name(ownNm);
|
||||
mMAIdx.linkTo(&mOwnIdx);
|
||||
}
|
||||
|
||||
template <typename T, class Range, class MARange>
|
||||
ConstSlice<T,Range,MARange>::
|
||||
ConstSlice(const Slice<T,Range,MARange>& slice) :
|
||||
MultiArrayBase<T,Range>(slice.range()),
|
||||
mOwnIdx(slice.mOwnIdx),
|
||||
mMAIdx(slice.mMAIdx), mBeginIndex(slice.mBeginIndex), mEndIndex(slice.mEndIndex)
|
||||
{
|
||||
if(slice.mInit){
|
||||
MAB::mInit = true;
|
||||
mMultiArrayPtr = slice.mConstMultiArrayPtr;
|
||||
mMAIdx = slice.mMAIdx;
|
||||
mOwnIdx = MAB::mRange->begin();
|
||||
mMAIdx.name(slice.mMAName);
|
||||
mOwnIdx.name(slice.mOwnName);
|
||||
mMAIdx.linkTo(&mOwnIdx);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename T, class Range, class MARange>
|
||||
bool ConstSlice<T,Range,MARange>::isSlice() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T, class Range, class MARange>
|
||||
bool ConstSlice<T,Range,MARange>::isConst() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T, class Range, class MARange>
|
||||
void ConstSlice<T,Range,MARange>::link(IndefinitIndexBase* iibPtr) const
|
||||
{
|
||||
mMAIdx.linkTo(iibPtr);
|
||||
}
|
||||
|
||||
template <typename T, class Range, class MARange>
|
||||
auto ConstSlice<T,Range,MARange>::beginIndex() const -> decltype(Range().begin())
|
||||
{
|
||||
return mBeginIndex;
|
||||
}
|
||||
|
||||
template <typename T, class Range, class MARange>
|
||||
auto ConstSlice<T,Range,MARange>::endIndex() const -> decltype(Range().end())
|
||||
{
|
||||
return mEndIndex;
|
||||
}
|
||||
|
||||
// slow!!
|
||||
template <typename T, class Range, class MARange>
|
||||
const T& ConstSlice<T,Range,MARange>::operator[](const typename Range::IndexType& i) const
|
||||
{
|
||||
mOwnIdx.copyPos(i);
|
||||
//mOwnIdx = i.pos();
|
||||
return (*mMultiArrayPtr)[ mMAIdx ];
|
||||
}
|
||||
}
|
108
src/slice.h
108
src/slice.h
|
@ -1,108 +0,0 @@
|
|||
// -*- C++ -*-
|
||||
|
||||
#ifndef __slice_h__
|
||||
#define __slice_h__
|
||||
|
||||
#include <cstdlib>
|
||||
#include "base_def.h"
|
||||
#include "multi_array.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
|
||||
// T = data type
|
||||
// Range = range of slice
|
||||
// MARange = original range of multi array of which this is the slice
|
||||
// Index = index which determines the slice position (remnant of MARange w.o. Range)
|
||||
template <typename T, class Range, class MARange/*, class Index*/>
|
||||
class Slice : public MutableMultiArrayBase<T,Range> // yes, 'Range' is correct !!!
|
||||
{
|
||||
public:
|
||||
|
||||
typedef MultiArrayBase<T,Range> MAB;
|
||||
|
||||
Slice(const Range& range,
|
||||
const Name& ownNm,
|
||||
MutableMultiArrayBase<T,MARange>& multiArrayRef,
|
||||
const typename MARange::IndexType& MAIdx,
|
||||
const Name& MANm);
|
||||
|
||||
Slice(const Range& range,
|
||||
const Name& ownNm,
|
||||
MultiArrayOperationRoot<T,MARange>& mor,
|
||||
const typename MARange::IndexType& MAIdx);
|
||||
|
||||
|
||||
virtual T& operator[](const typename Range::IndexType& i) override;
|
||||
virtual const T& operator[](const typename Range::IndexType& i) const override;
|
||||
|
||||
// link given Index to mMAPtr which is index of total array
|
||||
virtual auto beginIndex() const -> decltype(Range().begin()) override;
|
||||
virtual auto endIndex() const -> decltype(Range().end()) override;
|
||||
|
||||
virtual bool isSlice() const override;
|
||||
virtual bool isConst() const override;
|
||||
|
||||
virtual void link(IndefinitIndexBase* iibPtr) const override;
|
||||
|
||||
template <typename U, class RangeX, class MARangeX>
|
||||
friend class ConstSlice;
|
||||
|
||||
private:
|
||||
|
||||
Name mOwnName;
|
||||
Name mMAName;
|
||||
MutableMultiArrayBase<T,MARange>* mMultiArrayPtr = nullptr;
|
||||
mutable typename Range::IndexType mOwnIdx;
|
||||
mutable typename MARange::IndexType mMAIdx;
|
||||
typename Range::IndexType mBeginIndex;
|
||||
typename Range::IndexType mEndIndex;
|
||||
};
|
||||
|
||||
template <typename T, class Range, class MARange/*, class Index*/>
|
||||
class ConstSlice : public MultiArrayBase<T,Range> // yes, 'Range' is correct !!!
|
||||
{
|
||||
public:
|
||||
|
||||
typedef MultiArrayBase<T,Range> MAB;
|
||||
|
||||
//ConstSlice(const Range& range);
|
||||
ConstSlice(const Range& range,
|
||||
const Name& ownNm,
|
||||
const MultiArrayBase<T,MARange>& multiArrayRef,
|
||||
const typename MARange::IndexType& MAIdx,
|
||||
const Name& MANm);
|
||||
|
||||
ConstSlice(const Range& range,
|
||||
const Name& ownNm,
|
||||
const ConstMultiArrayOperationRoot<T,MARange>& mor,
|
||||
const typename MARange::IndexType& MAIdx);
|
||||
|
||||
ConstSlice(const Slice<T,Range,MARange>& slice);
|
||||
|
||||
virtual const T& operator[](const typename Range::IndexType& i) const override;
|
||||
|
||||
// link given Index to mMAPtr which is index of total array
|
||||
virtual auto beginIndex() const -> decltype(Range().begin()) override;
|
||||
virtual auto endIndex() const -> decltype(Range().end()) override;
|
||||
|
||||
virtual bool isSlice() const override;
|
||||
virtual bool isConst() const override;
|
||||
|
||||
virtual void link(IndefinitIndexBase* iibPtr) const override;
|
||||
|
||||
private:
|
||||
|
||||
MultiArrayBase<T,MARange> const* mMultiArrayPtr = nullptr;
|
||||
mutable typename Range::IndexType mOwnIdx;
|
||||
mutable typename MARange::IndexType mMAIdx;
|
||||
typename Range::IndexType mBeginIndex;
|
||||
typename Range::IndexType mEndIndex;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#include "slice.cc"
|
||||
|
||||
#endif
|
|
@ -1,46 +0,0 @@
|
|||
|
||||
#include "tuple_helper.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
|
||||
template <class Tuple, size_t N>
|
||||
auto make_left_x(const Tuple& tp) -> decltype(std::tuple_cat(make_left<Tuple,N-1>(tp),
|
||||
std::make_tuple(get<N>(tp))))
|
||||
{
|
||||
return std::tuple_cat(make_left<Tuple,N-1>(tp), std::make_tuple(get<N>(tp)));
|
||||
}
|
||||
|
||||
template <class Tuple>
|
||||
auto make_left_x<Tuple, 0>(const Tuple& tp) -> decltype(std::make_tuple(get<N>(tp)))
|
||||
{
|
||||
return std::make_tuple(get<N>(tp));
|
||||
}
|
||||
|
||||
template <class Tuple, size_t N>
|
||||
auto make_right_x(const Tuple& tp) -> decltype(std::tuple_cat(std::make_tuple(get<std::tuple_size(tp)-N>(tp)),
|
||||
make_left<Tuple,std::tuple_size(tp)-N+1>(tp)))
|
||||
{
|
||||
const size_t M = std::tuple_size(tp) - N;
|
||||
return std::tuple_cat(std::make_tuple(get<M>(tp)), make_left<Tuple,M+1>(tp));
|
||||
}
|
||||
|
||||
template <class Tuple>
|
||||
auto make_right_x<Tuple, 0>(const Tuple& tp) -> decltype(std::make_tuple(get<std::tuple_size(tp)>(tp)))
|
||||
{
|
||||
const size_t M = std::tuple_size(tp);
|
||||
return std::make_tuple(get<M>(tp));
|
||||
}
|
||||
|
||||
template <class Tuple, size_t N>
|
||||
auto make_left(const Tuple& tp) -> decltype(make_left_x<Tuple, N>(tp))
|
||||
{
|
||||
return make_left_x<Tuple, N>(tp);
|
||||
}
|
||||
|
||||
template <class Tuple, size_t N>
|
||||
auto make_right(const Tuple& tp) -> decltype(make_right_x<Tuple, std::tuple_size(Tuple)-N>(tp))
|
||||
{
|
||||
return make_right_x<Tuple, std::tuple_size(Tuple)-N>(tp);
|
||||
}
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
// -*- C++ -*-
|
||||
|
||||
#ifndef __tuple_helper_h__
|
||||
#define __tuple_helper_h__
|
||||
|
||||
#include <cstdlib>
|
||||
#include <tuple>
|
||||
|
||||
#include "base_def.h"
|
||||
|
||||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
|
||||
template <class Tuple, size_t N>
|
||||
auto make_left_x(const Tuple& tp) -> decltype(std::tuple_cat(make_left<Tuple,N-1>(tp),
|
||||
std::make_tuple(get<N>(tp))));
|
||||
|
||||
template <class Tuple>
|
||||
auto make_left_x<Tuple, 0>(const Tuple& tp) -> decltype(std::make_tuple(get<N>(tp)));
|
||||
|
||||
template <class Tuple, size_t N>
|
||||
auto make_right_x(const Tuple& tp) -> decltype(std::tuple_cat(std::make_tuple(get<std::tuple_size(tp)-N>(tp)),
|
||||
make_left<Tuple,std::tuple_size(tp)-N+1>(tp)));
|
||||
|
||||
template <class Tuple>
|
||||
auto make_right_x<Tuple, 0>(const Tuple& tp) -> decltype(std::make_tuple(get<std::tuple_size(tp)>(tp)));
|
||||
|
||||
template <class Tuple, size_t N>
|
||||
auto make_left(const Tuple& tp) -> decltype(make_left_x<Tuple, N>(tp));
|
||||
|
||||
template <class Tuple, size_t N>
|
||||
auto make_right(const Tuple& tp) -> decltype(make_right_x<Tuple, std::tuple_size(Tuple)-N>(tp));
|
||||
|
||||
}
|
||||
|
||||
#include "tuple_helper.cc"
|
||||
|
||||
#endif
|
560
src/unit_test.cc
560
src/unit_test.cc
|
@ -1,560 +0,0 @@
|
|||
// -*- C++ -*-
|
||||
|
||||
#include <cstdlib>
|
||||
#include "gtest/gtest.h"
|
||||
#include <iostream>
|
||||
|
||||
#include "multi_array_header.h"
|
||||
|
||||
namespace MAT = MultiArrayTools;
|
||||
|
||||
namespace {
|
||||
|
||||
template <typename T>
|
||||
struct sum
|
||||
{
|
||||
public:
|
||||
sum() = default;
|
||||
|
||||
T& operator()() const
|
||||
{
|
||||
return res;
|
||||
}
|
||||
|
||||
T& operator()(const T& a) const
|
||||
{
|
||||
return res += a;
|
||||
}
|
||||
|
||||
void endOp() const {}
|
||||
|
||||
void reset() const
|
||||
{
|
||||
res = static_cast<T>(0);
|
||||
}
|
||||
|
||||
private:
|
||||
mutable T res = static_cast<T>(0);
|
||||
};
|
||||
|
||||
class OneDimTest : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
|
||||
typedef MAT::SingleRange<char,MAT::RangeType::ANY> Range1dAny;
|
||||
typedef MAT::MultiArray<int,Range1dAny> MultiArray1dAny;
|
||||
|
||||
OneDimTest() : r({'a','b','c','d','e'}), ma(r, {-5,6,2,1,9}) {}
|
||||
|
||||
//virtual void SetUp();
|
||||
|
||||
Range1dAny r;
|
||||
MultiArray1dAny ma;
|
||||
|
||||
};
|
||||
|
||||
class TwoDimTest : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
|
||||
typedef MAT::SingleRange<char,MAT::RangeType::ANY> Range1dAny;
|
||||
typedef MAT::MultiRange<Range1dAny,Range1dAny> Range2dAny;
|
||||
typedef MAT::MultiArray<int,Range2dAny> MultiArray2dAny;
|
||||
|
||||
TwoDimTest() : r1({'a','b','c'}),
|
||||
r2({'a','b','c','d'}),
|
||||
r(r1,r2),
|
||||
ma(r, {-5,6,2,1,9,54,27,-7,-13,32,90,-67}) {}
|
||||
|
||||
//virtual void SetUp();
|
||||
|
||||
Range1dAny r1;
|
||||
Range1dAny r2;
|
||||
Range2dAny r;
|
||||
MultiArray2dAny ma;
|
||||
|
||||
};
|
||||
|
||||
class ReorderTest : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
|
||||
typedef MAT::SingleRange<char,MAT::RangeType::ANY> Range1dAny;
|
||||
typedef MAT::MultiRange<Range1dAny,Range1dAny> Range2dAny;
|
||||
typedef MAT::MultiRange<Range1dAny,Range1dAny,Range1dAny> Range3dAny;
|
||||
typedef MAT::MultiArray<int,Range2dAny> MultiArray2dAny;
|
||||
typedef MAT::MultiArray<int,Range3dAny> MultiArray3dAny;
|
||||
|
||||
ReorderTest() : r1({'a','b','c'}), r2({'a','b','c','d'}), r3({'a','b'}),
|
||||
ra(r1,r2), rb(r2,r1),
|
||||
r3da(r1,r2,r3), r3db(r1,r3,r2), r3dc(r3,r1,r2),
|
||||
ma(ra, {-5,6,2,1,9,54,27,-7,-13,32,90,-67}),
|
||||
ma3d(r3da, {-5,6,2,1,9,54,27,-7,-13,32,90,-67,
|
||||
-10,16,-2,101,39,-64,81,-22,14,34,95,-62}) {}
|
||||
|
||||
Range1dAny r1;
|
||||
Range1dAny r2;
|
||||
Range1dAny r3;
|
||||
Range2dAny ra;
|
||||
Range2dAny rb;
|
||||
Range3dAny r3da;
|
||||
Range3dAny r3db;
|
||||
Range3dAny r3dc;
|
||||
MultiArray2dAny ma;
|
||||
MultiArray3dAny ma3d;
|
||||
};
|
||||
|
||||
class OperationTest : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
|
||||
typedef MAT::SingleRange<char,MAT::RangeType::ANY> Range1dAny;
|
||||
typedef MAT::MultiRange<Range1dAny> RangeAny;
|
||||
typedef MAT::MultiRange<Range1dAny,Range1dAny> Range2dAny;
|
||||
typedef MAT::MultiRange<Range1dAny,Range1dAny,Range1dAny> Range3dAny;
|
||||
typedef MAT::MultiArray<int,RangeAny> MultiArray1dAny;
|
||||
typedef MAT::MultiArray<int,Range2dAny> MultiArray2dAny;
|
||||
typedef MAT::MultiArray<int,Range3dAny> MultiArray3dAny;
|
||||
|
||||
OperationTest() : r1({'a','b','c'}), r2({'a','b','c','d'}), r3({'a','b'}),
|
||||
r11(r1),
|
||||
ra(r1,r2),
|
||||
r3d(r1,r2,r3),
|
||||
ma1d(r11, {-5,6,2}),
|
||||
ma(ra, {-5,6,2,1,9,54,27,-7,-13,32,90,-67}),
|
||||
ma3d(r3d, {-5,6,2,1,9,54,27,-7,-13,32,90,-67,
|
||||
-10,16,-2,101,39,-64,81,-22,14,34,95,-62}) {}
|
||||
|
||||
Range1dAny r1;
|
||||
Range1dAny r2;
|
||||
Range1dAny r3;
|
||||
RangeAny r11;
|
||||
Range2dAny ra;
|
||||
Range3dAny r3d;
|
||||
MultiArray1dAny ma1d;
|
||||
MultiArray2dAny ma;
|
||||
MultiArray3dAny ma3d;
|
||||
};
|
||||
|
||||
class SliceTest : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
|
||||
typedef MAT::SingleRange<char,MAT::RangeType::ANY> Range1dAny;
|
||||
typedef MAT::MultiRange<Range1dAny,Range1dAny> Range2dAny;
|
||||
typedef MAT::MultiRange<Range1dAny,Range1dAny,Range1dAny> Range3dAny;
|
||||
typedef MAT::MultiArray<int,Range3dAny> MultiArray3dAny;
|
||||
typedef MAT::Slice<int,Range2dAny,Range3dAny> Slice2d3dAny;
|
||||
|
||||
SliceTest() : r1({'a','b','c'}), r2({'a','b','c','d'}), r3({'a','b'}),
|
||||
ra(r1,r3),
|
||||
rb(r1,r2),
|
||||
r3d(r1,r2,r3),
|
||||
ma(r3d, {-5,6,2,1,9,54,27,-7,-13,32,90,-67,
|
||||
-10,16,-2,101,39,-64,81,-22,14,34,95,-62}) {}
|
||||
|
||||
Range1dAny r1;
|
||||
Range1dAny r2;
|
||||
Range1dAny r3;
|
||||
Range2dAny ra;
|
||||
Range2dAny rb;
|
||||
Range3dAny r3d;
|
||||
MultiArray3dAny ma;
|
||||
//Slice2d3dAny sl;
|
||||
};
|
||||
|
||||
class ContractionTest : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
typedef MAT::SingleRange<char,MAT::RangeType::ANY> Range1dAny;
|
||||
typedef MAT::MultiRange<Range1dAny,Range1dAny> Range2dAny;
|
||||
typedef MAT::MultiRange<Range1dAny,Range1dAny,Range1dAny> Range3dAny;
|
||||
typedef MAT::MultiArray<int,Range3dAny> MultiArray3dAny;
|
||||
typedef MAT::Slice<int,Range2dAny,Range3dAny> Slice2d3dAny;
|
||||
typedef MAT::MultiArray<int,Range2dAny> MultiArray2dAny;
|
||||
|
||||
ContractionTest() : r1({'a','b','c'}), r2({'a','b','c','d'}), r3({'a','b'}),
|
||||
ra(r1,r3),
|
||||
rb(r1,r2),
|
||||
r3d(r1,r2,r3),
|
||||
ma(r3d, {-5,6,2,1,9,54,27,-7,-13,32,90,-67,
|
||||
-10,16,-2,101,39,-64,81,-22,14,34,95,-62}),
|
||||
max(ra, {-5,6,2,1,9,54}){}
|
||||
|
||||
Range1dAny r1;
|
||||
Range1dAny r2;
|
||||
Range1dAny r3;
|
||||
Range2dAny ra;
|
||||
Range2dAny rb;
|
||||
Range3dAny r3d;
|
||||
MultiArray3dAny ma;
|
||||
MultiArray2dAny max;
|
||||
};
|
||||
|
||||
TEST_F(OneDimTest, CorrectExtensions)
|
||||
{
|
||||
EXPECT_EQ(ma.size(), 5);
|
||||
}
|
||||
|
||||
TEST_F(OneDimTest, CorrectAssigned)
|
||||
{
|
||||
auto i = ma.beginIndex();
|
||||
EXPECT_EQ(ma[i = 0], -5);
|
||||
EXPECT_EQ(ma[i = 1], 6);
|
||||
EXPECT_EQ(ma[i = 2], 2);
|
||||
EXPECT_EQ(ma[i = 3], 1);
|
||||
EXPECT_EQ(ma[i = 4], 9);
|
||||
}
|
||||
|
||||
TEST_F(TwoDimTest, CorrectExtensions)
|
||||
{
|
||||
auto i = ma.beginIndex();
|
||||
auto i1 = i.template getIndex<0>();
|
||||
auto i2 = i.template getIndex<1>();
|
||||
EXPECT_EQ(ma.size(), 12);
|
||||
EXPECT_EQ(i1.max(), 3);
|
||||
EXPECT_EQ(i1.majorStep(), 4);
|
||||
EXPECT_EQ(i2.max(), 4);
|
||||
EXPECT_EQ(i2.majorStep(), 1);
|
||||
}
|
||||
|
||||
TEST_F(TwoDimTest, CorrectAssigned)
|
||||
{
|
||||
auto i = ma.beginIndex();
|
||||
auto i1 = i.template getIndex<0>();
|
||||
auto i2 = i.template getIndex<1>();
|
||||
|
||||
EXPECT_EQ(ma[i(i1 = 0, i2 = 0)], -5);
|
||||
EXPECT_EQ(ma[i(i1 = 0, i2 = 1)], 6);
|
||||
EXPECT_EQ(ma[i(i1 = 0, i2 = 2)], 2);
|
||||
EXPECT_EQ(ma[i(i1 = 0, i2 = 3)], 1);
|
||||
EXPECT_EQ(ma[i(i1 = 1, i2 = 0)], 9);
|
||||
EXPECT_EQ(ma[i(i1 = 1, i2 = 1)], 54);
|
||||
EXPECT_EQ(ma[i(i1 = 1, i2 = 2)], 27);
|
||||
EXPECT_EQ(ma[i(i1 = 1, i2 = 3)], -7);
|
||||
EXPECT_EQ(ma[i(i1 = 2, i2 = 0)], -13);
|
||||
EXPECT_EQ(ma[i(i1 = 2, i2 = 1)], 32);
|
||||
EXPECT_EQ(ma[i(i1 = 2, i2 = 2)], 90);
|
||||
EXPECT_EQ(ma[i(i1 = 2, i2 = 3)], -67);
|
||||
}
|
||||
|
||||
TEST_F(ReorderTest, ReorderingWorks2d)
|
||||
{
|
||||
MultiArray2dAny ma2(rb);
|
||||
auto i = ma2.beginIndex();
|
||||
auto i1 = i.template getIndex<0>();
|
||||
auto i2 = i.template getIndex<1>();
|
||||
ma2("alpha","beta") = ma("beta","alpha");
|
||||
|
||||
EXPECT_EQ(ma2[i(i1 = 0,i2 = 0)],-5);
|
||||
EXPECT_EQ(ma2[i(i1 = 1,i2 = 0)],6);
|
||||
EXPECT_EQ(ma2[i(i1 = 2,i2 = 0)],2);
|
||||
EXPECT_EQ(ma2[i(i1 = 3,i2 = 0)],1);
|
||||
|
||||
EXPECT_EQ(ma2[i(i1 = 0,i2 = 1)],9);
|
||||
EXPECT_EQ(ma2[i(i1 = 1,i2 = 1)],54);
|
||||
EXPECT_EQ(ma2[i(i1 = 2,i2 = 1)],27);
|
||||
EXPECT_EQ(ma2[i(i1 = 3,i2 = 1)],-7);
|
||||
|
||||
EXPECT_EQ(ma2[i(i1 = 0,i2 = 2)],-13);
|
||||
EXPECT_EQ(ma2[i(i1 = 1,i2 = 2)],32);
|
||||
EXPECT_EQ(ma2[i(i1 = 2,i2 = 2)],90);
|
||||
EXPECT_EQ(ma2[i(i1 = 3,i2 = 2)],-67);
|
||||
}
|
||||
|
||||
TEST_F(ReorderTest, ReorderingWorks3d_Test1)
|
||||
{
|
||||
MultiArray3dAny ma3d2(r3db);
|
||||
auto i = ma3d2.beginIndex();
|
||||
auto i1 = i.template getIndex<0>();
|
||||
auto i2 = i.template getIndex<1>();
|
||||
auto i3 = i.template getIndex<2>();
|
||||
|
||||
EXPECT_EQ(i1.max(), 3);
|
||||
EXPECT_EQ(i1.majorStep(), 8);
|
||||
EXPECT_EQ(i2.max(), 2);
|
||||
EXPECT_EQ(i2.majorStep(), 4);
|
||||
EXPECT_EQ(i3.max(), 4);
|
||||
EXPECT_EQ(i3.majorStep(), 1);
|
||||
|
||||
ma3d2("alpha","beta","gamma") = ma3d("alpha","gamma","beta");
|
||||
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 0,i3 = 0)],-5);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 1,i3 = 0)],6);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 0,i3 = 1)],2);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 1,i3 = 1)],1);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 0,i3 = 2)],9);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 1,i3 = 2)],54);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 0,i3 = 3)],27);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 1,i3 = 3)],-7);
|
||||
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 0,i3 = 0)],-13);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 1,i3 = 0)],32);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 0,i3 = 1)],90);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 1,i3 = 1)],-67);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 0,i3 = 2)],-10);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 1,i3 = 2)],16);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 0,i3 = 3)],-2);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 1,i3 = 3)],101);
|
||||
|
||||
EXPECT_EQ(ma3d2[i(i1 = 2,i2 = 0,i3 = 0)],39);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 2,i2 = 1,i3 = 0)],-64);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 2,i2 = 0,i3 = 1)],81);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 2,i2 = 1,i3 = 1)],-22);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 2,i2 = 0,i3 = 2)],14);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 2,i2 = 1,i3 = 2)],34);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 2,i2 = 0,i3 = 3)],95);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 2,i2 = 1,i3 = 3)],-62);
|
||||
}
|
||||
|
||||
TEST_F(ReorderTest, ReorderingWorks3d_Test2)
|
||||
{
|
||||
MultiArray3dAny ma3d2(r3dc);
|
||||
auto i = ma3d2.beginIndex();
|
||||
auto i1 = i.template getIndex<0>();
|
||||
auto i2 = i.template getIndex<1>();
|
||||
auto i3 = i.template getIndex<2>();
|
||||
|
||||
ma3d2("gamma","alpha","beta") = ma3d("alpha","beta","gamma");
|
||||
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 0,i3 = 0)],-5);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 0,i3 = 0)],6);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 0,i3 = 1)],2);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 0,i3 = 1)],1);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 0,i3 = 2)],9);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 0,i3 = 2)],54);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 0,i3 = 3)],27);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 0,i3 = 3)],-7);
|
||||
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 1,i3 = 0)],-13);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 1,i3 = 0)],32);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 1,i3 = 1)],90);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 1,i3 = 1)],-67);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 1,i3 = 2)],-10);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 1,i3 = 2)],16);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 1,i3 = 3)],-2);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 1,i3 = 3)],101);
|
||||
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 2,i3 = 0)],39);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 2,i3 = 0)],-64);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 2,i3 = 1)],81);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 2,i3 = 1)],-22);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 2,i3 = 2)],14);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 2,i3 = 2)],34);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 2,i3 = 3)],95);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 2,i3 = 3)],-62);
|
||||
}
|
||||
|
||||
TEST_F(OperationTest, CorrectlyAdded)
|
||||
{
|
||||
MultiArray3dAny ma3d2(r3d);
|
||||
auto i = ma3d2.beginIndex();
|
||||
auto i1 = i.template getIndex<0>();
|
||||
auto i2 = i.template getIndex<1>();
|
||||
auto i3 = i.template getIndex<2>();
|
||||
|
||||
ma3d2("alpha","beta","gamma") = ma3d("alpha","beta","gamma") + ma("alpha","beta");
|
||||
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0, i2 = 0, i3 = 0)], -10);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0, i2 = 0, i3 = 1)], 1);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0, i2 = 1, i3 = 0)], 8);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0, i2 = 1, i3 = 1)], 7);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0, i2 = 2, i3 = 0)], 11);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0, i2 = 2, i3 = 1)], 56);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0, i2 = 3, i3 = 0)], 28);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0, i2 = 3, i3 = 1)], -6);
|
||||
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1, i2 = 0, i3 = 0)], -4);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1, i2 = 0, i3 = 1)], 41);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1, i2 = 1, i3 = 0)], 144);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1, i2 = 1, i3 = 1)], -13);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1, i2 = 2, i3 = 0)], 17);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1, i2 = 2, i3 = 1)], 43);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1, i2 = 3, i3 = 0)], -9);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1, i2 = 3, i3 = 1)], 94);
|
||||
|
||||
EXPECT_EQ(ma3d2[i(i1 = 2, i2 = 0, i3 = 0)], 26);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 2, i2 = 0, i3 = 1)], -77);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 2, i2 = 1, i3 = 0)], 113);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 2, i2 = 1, i3 = 1)], 10);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 2, i2 = 2, i3 = 0)], 104);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 2, i2 = 2, i3 = 1)], 124);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 2, i2 = 3, i3 = 0)], 28);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 2, i2 = 3, i3 = 1)], -129);
|
||||
}
|
||||
|
||||
TEST_F(OperationTest, CorrectlyAdded2)
|
||||
{
|
||||
//MultiArray3dAny ma3d2(r3d);
|
||||
auto i = ma3d.beginIndex();
|
||||
auto i1 = i.template getIndex<0>();
|
||||
auto i2 = i.template getIndex<1>();
|
||||
auto i3 = i.template getIndex<2>();
|
||||
|
||||
ma3d("alpha","beta","gamma") += ma("alpha","beta");
|
||||
|
||||
EXPECT_EQ(ma3d[i(i1 = 0, i2 = 0, i3 = 0)], -10);
|
||||
EXPECT_EQ(ma3d[i(i1 = 0, i2 = 0, i3 = 1)], 1);
|
||||
EXPECT_EQ(ma3d[i(i1 = 0, i2 = 1, i3 = 0)], 8);
|
||||
EXPECT_EQ(ma3d[i(i1 = 0, i2 = 1, i3 = 1)], 7);
|
||||
EXPECT_EQ(ma3d[i(i1 = 0, i2 = 2, i3 = 0)], 11);
|
||||
EXPECT_EQ(ma3d[i(i1 = 0, i2 = 2, i3 = 1)], 56);
|
||||
EXPECT_EQ(ma3d[i(i1 = 0, i2 = 3, i3 = 0)], 28);
|
||||
EXPECT_EQ(ma3d[i(i1 = 0, i2 = 3, i3 = 1)], -6);
|
||||
|
||||
EXPECT_EQ(ma3d[i(i1 = 1, i2 = 0, i3 = 0)], -4);
|
||||
EXPECT_EQ(ma3d[i(i1 = 1, i2 = 0, i3 = 1)], 41);
|
||||
EXPECT_EQ(ma3d[i(i1 = 1, i2 = 1, i3 = 0)], 144);
|
||||
EXPECT_EQ(ma3d[i(i1 = 1, i2 = 1, i3 = 1)], -13);
|
||||
EXPECT_EQ(ma3d[i(i1 = 1, i2 = 2, i3 = 0)], 17);
|
||||
EXPECT_EQ(ma3d[i(i1 = 1, i2 = 2, i3 = 1)], 43);
|
||||
EXPECT_EQ(ma3d[i(i1 = 1, i2 = 3, i3 = 0)], -9);
|
||||
EXPECT_EQ(ma3d[i(i1 = 1, i2 = 3, i3 = 1)], 94);
|
||||
|
||||
EXPECT_EQ(ma3d[i(i1 = 2, i2 = 0, i3 = 0)], 26);
|
||||
EXPECT_EQ(ma3d[i(i1 = 2, i2 = 0, i3 = 1)], -77);
|
||||
EXPECT_EQ(ma3d[i(i1 = 2, i2 = 1, i3 = 0)], 113);
|
||||
EXPECT_EQ(ma3d[i(i1 = 2, i2 = 1, i3 = 1)], 10);
|
||||
EXPECT_EQ(ma3d[i(i1 = 2, i2 = 2, i3 = 0)], 104);
|
||||
EXPECT_EQ(ma3d[i(i1 = 2, i2 = 2, i3 = 1)], 124);
|
||||
EXPECT_EQ(ma3d[i(i1 = 2, i2 = 3, i3 = 0)], 28);
|
||||
EXPECT_EQ(ma3d[i(i1 = 2, i2 = 3, i3 = 1)], -129);
|
||||
}
|
||||
|
||||
TEST_F(OperationTest, CorrectlyAdded_3args)
|
||||
{
|
||||
MultiArray3dAny ma3d2(r3d);
|
||||
//MultiArray2dAny ma2(ra);
|
||||
auto i = ma3d2.beginIndex();
|
||||
auto i1 = i.template getIndex<0>();
|
||||
auto i2 = i.template getIndex<1>();
|
||||
auto i3 = i.template getIndex<2>();
|
||||
|
||||
//ma2("alpha","beta") = ma("alpha","beta") + ma1d("alpha");
|
||||
ma3d2("alpha","beta","gamma") = ma3d("alpha","beta","gamma") + ma("alpha","beta") + ma1d("alpha");
|
||||
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0, i2 = 0, i3 = 0)], -15);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0, i2 = 0, i3 = 1)], -4);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0, i2 = 1, i3 = 0)], 3);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0, i2 = 1, i3 = 1)], 2);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0, i2 = 2, i3 = 0)], 6);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0, i2 = 2, i3 = 1)], 51);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0, i2 = 3, i3 = 0)], 23);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 0, i2 = 3, i3 = 1)], -11);
|
||||
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1, i2 = 0, i3 = 0)], 2);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1, i2 = 0, i3 = 1)], 47);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1, i2 = 1, i3 = 0)], 150);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1, i2 = 1, i3 = 1)], -7);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1, i2 = 2, i3 = 0)], 23);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1, i2 = 2, i3 = 1)], 49);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1, i2 = 3, i3 = 0)], -3);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 1, i2 = 3, i3 = 1)], 100);
|
||||
|
||||
EXPECT_EQ(ma3d2[i(i1 = 2, i2 = 0, i3 = 0)], 28);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 2, i2 = 0, i3 = 1)], -75);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 2, i2 = 1, i3 = 0)], 115);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 2, i2 = 1, i3 = 1)], 12);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 2, i2 = 2, i3 = 0)], 106);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 2, i2 = 2, i3 = 1)], 126);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 2, i2 = 3, i3 = 0)], 30);
|
||||
EXPECT_EQ(ma3d2[i(i1 = 2, i2 = 3, i3 = 1)], -127);
|
||||
}
|
||||
|
||||
TEST_F(SliceTest, CorrectSize)
|
||||
{
|
||||
auto i = ma.beginIndex();
|
||||
auto i1 = i.template getIndex<0>();
|
||||
auto i2 = i.template getIndex<1>();
|
||||
auto i3 = i.template getIndex<2>();
|
||||
|
||||
Slice2d3dAny sl(ra, MAT::Name("master", "alpha", "gamma"), ma,
|
||||
i(i1 = 0, i2 = 2, i3 = 0),
|
||||
MAT::Name("master", "alpha","beta","gamma"));
|
||||
|
||||
//Slice2d3dAny sl(ra);
|
||||
//sl("alpha","gamma") = ma("alpha","beta","gamma")[i(i1 = 0, i2 = 2, i3 = 0)];
|
||||
EXPECT_EQ(sl.size(), 6);
|
||||
|
||||
Slice2d3dAny sl2(rb, MAT::Name("master", "alpha", "beta"), ma,
|
||||
i(i1 = 0, i2 = 0, i3 = 1),
|
||||
MAT::Name("master", "alpha","beta","gamma"));
|
||||
|
||||
//Slice2d3dAny sl2(rb);
|
||||
//sl2("alpha","beta") = ma("alpha","beta","gamma")[i(i1 = 0, i2 = 0, i3 = 1)];
|
||||
EXPECT_EQ(sl2.size(), 12);
|
||||
}
|
||||
|
||||
TEST_F(SliceTest, CorrectContent)
|
||||
{
|
||||
auto i = ma.beginIndex();
|
||||
auto i1 = i.template getIndex<0>();
|
||||
auto i2 = i.template getIndex<1>();
|
||||
auto i3 = i.template getIndex<2>();
|
||||
Slice2d3dAny sl(ra, MAT::Name("master", "alpha", "gamma"), ma,
|
||||
i(i1 = 0, i2 = 2, i3 = 0),
|
||||
MAT::Name("master", "alpha","beta","gamma"));
|
||||
//sl("alpha","gamma") = ma("alpha","beta","gamma")[i(i1 = 0, i2 = 2, i3 = 0)];
|
||||
|
||||
auto j = sl.beginIndex();
|
||||
auto j1 = j.template getIndex<0>();
|
||||
auto j2 = j.template getIndex<1>();
|
||||
|
||||
EXPECT_EQ(sl[j(j1 = 0, j2 = 0)], 9);
|
||||
EXPECT_EQ(sl[j(j1 = 0, j2 = 1)], 54);
|
||||
|
||||
EXPECT_EQ(sl[j(j1 = 1, j2 = 0)], -10);
|
||||
EXPECT_EQ(sl[j(j1 = 1, j2 = 1)], 16);
|
||||
|
||||
EXPECT_EQ(sl[j(j1 = 2, j2 = 0)], 14);
|
||||
EXPECT_EQ(sl[j(j1 = 2, j2 = 1)], 34);
|
||||
}
|
||||
|
||||
TEST_F(ContractionTest, ContractionWorks)
|
||||
{
|
||||
MultiArray2dAny ma2(ra);
|
||||
|
||||
ma2("alpha","gamma") = ma("alpha","beta","gamma").contract<Range1dAny>(sum<int>(),"beta");
|
||||
|
||||
auto i = ma2.beginIndex();
|
||||
auto i1 = i.template getIndex<0>();
|
||||
auto i2 = i.template getIndex<1>();
|
||||
|
||||
EXPECT_EQ(ma2[i(i1 = 0, i2 = 0)], 33);
|
||||
EXPECT_EQ(ma2[i(i1 = 0, i2 = 1)], 54);
|
||||
|
||||
EXPECT_EQ(ma2[i(i1 = 1, i2 = 0)], 65);
|
||||
EXPECT_EQ(ma2[i(i1 = 1, i2 = 1)], 82);
|
||||
|
||||
EXPECT_EQ(ma2[i(i1 = 2, i2 = 0)], 229);
|
||||
EXPECT_EQ(ma2[i(i1 = 2, i2 = 1)], -114);
|
||||
}
|
||||
|
||||
TEST_F(ContractionTest, ContractionWorks_2)
|
||||
{
|
||||
MultiArray2dAny ma2(ra);
|
||||
|
||||
ma2("alpha","gamma") = ma("alpha","beta","gamma").contract<Range1dAny>(sum<int>(),"beta")
|
||||
* max("alpha","gamma");
|
||||
|
||||
auto i = ma2.beginIndex();
|
||||
auto i1 = i.template getIndex<0>();
|
||||
auto i2 = i.template getIndex<1>();
|
||||
|
||||
EXPECT_EQ(ma2[i(i1 = 0, i2 = 0)], -165);
|
||||
EXPECT_EQ(ma2[i(i1 = 0, i2 = 1)], 324);
|
||||
|
||||
EXPECT_EQ(ma2[i(i1 = 1, i2 = 0)], 130);
|
||||
EXPECT_EQ(ma2[i(i1 = 1, i2 = 1)], 82);
|
||||
|
||||
EXPECT_EQ(ma2[i(i1 = 2, i2 = 0)], 2061);
|
||||
EXPECT_EQ(ma2[i(i1 = 2, i2 = 1)], -6156);
|
||||
}
|
||||
|
||||
} // end namespace
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
Loading…
Reference in a new issue