first array operation test
This commit is contained in:
parent
a4e32416ad
commit
1ab0c21667
10 changed files with 67 additions and 189 deletions
|
@ -11,8 +11,6 @@ else()
|
|||
endif()
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -std=c++17 -Wpedantic -O2 -march=native -faligned-new -funroll-loops -fopenmp")
|
||||
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -std=c++14 -g -Wpedantic -Ofast -march=native -faligned-new -funroll-loops -fopenmp -ftemplate-backtrace-limit=0")
|
||||
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -std=c++14 -g -Wpedantic -O0 -march=native -faligned-new -funroll-loops -fopenmp")
|
||||
|
||||
enable_testing()
|
||||
|
||||
|
|
|
@ -71,19 +71,11 @@ namespace CNORXZ
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
template <class I, typename M>
|
||||
COpRoot<T,I> CArrayBase<T>::operator()(const IndexPtr<I,M>& i) const
|
||||
template <class Index>
|
||||
COpRoot<T,Index> CArrayBase<T>::operator()(const Sptr<Index>& i) const
|
||||
{
|
||||
auto fi = this->cbegin().format( std::static_pointer_cast<I>(i) );
|
||||
return COpRoot<T,I>(*this, fi);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <class I, SizeT L>
|
||||
COpRoot<T,I> CArrayBase<T>::operator()(const Sptr<LIndex<I,L>>& i) const
|
||||
{
|
||||
auto fi = this->cbegin().format( i );
|
||||
return COpRoot<T,LIndex<I,L>>(*this, fi);
|
||||
CXZ_WARNING("FORMAT / BLOCKSIZES!!!");
|
||||
return coproot(*this, i);
|
||||
}
|
||||
|
||||
/*****************
|
||||
|
@ -107,7 +99,7 @@ namespace CNORXZ
|
|||
template <typename I, typename M>
|
||||
T& ArrayBase<T>::at(const IndexInterface<I,M>& i)
|
||||
{
|
||||
CXZ_ASSERT(i.les() < this->size(), "index out of range");
|
||||
CXZ_ASSERT(i.lex() < this->size(), "index out of range");
|
||||
// check further compatibility of index/range format!!!
|
||||
auto ai = this->begin() + i.lex();
|
||||
return *ai;
|
||||
|
@ -136,19 +128,11 @@ namespace CNORXZ
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
template <class I, typename M>
|
||||
OpRoot<T,I> ArrayBase<T>::operator()(const IndexPtr<I,M>& i)
|
||||
template <class Index>
|
||||
OpRoot<T,Index> ArrayBase<T>::operator()(const Sptr<Index>& i)
|
||||
{
|
||||
auto fi = this->cbegin().format( std::static_pointer_cast<I>(i) );
|
||||
return OpRoot<T,I>(*this, fi);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <class I, SizeT L>
|
||||
OpRoot<T,I> ArrayBase<T>::operator()(const Sptr<LIndex<I,L>>& i)
|
||||
{
|
||||
auto fi = this->cbegin().format( i );
|
||||
return OpRoot<T,LIndex<I,L>>(*this, fi);
|
||||
CXZ_WARNING("FORMAT / BLOCKSIZES!!!");
|
||||
return oproot(*this, i);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -49,11 +49,8 @@ namespace CNORXZ
|
|||
|
||||
virtual bool isView() const = 0;
|
||||
|
||||
template <class I, typename M>
|
||||
COpRoot<T,I> operator()(const IndexPtr<I,M>& i) const;
|
||||
|
||||
template <class I, SizeT L>
|
||||
COpRoot<T,I> operator()(const Sptr<LIndex<I,L>>& i) const;
|
||||
template <class Index>
|
||||
COpRoot<T,Index> operator()(const Sptr<Index>& i) const;
|
||||
|
||||
};
|
||||
|
||||
|
@ -91,11 +88,8 @@ namespace CNORXZ
|
|||
virtual iterator begin();
|
||||
virtual iterator end();
|
||||
|
||||
template <class I, typename M>
|
||||
OpRoot<T,I> operator()(const IndexPtr<I,M>& i);
|
||||
|
||||
template <class I, SizeT L>
|
||||
OpRoot<T,I> operator()(const Sptr<LIndex<I,L>>& i);
|
||||
template <class Index>
|
||||
OpRoot<T,Index> operator()(const Sptr<Index>& i);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -3,3 +3,4 @@
|
|||
#include "memory/memory.cc.h"
|
||||
#include "ranges/ranges.cc.h"
|
||||
#include "array/array.cc.h"
|
||||
#include "operation/operation.cc.h"
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#include "base/base.h"
|
||||
#include "memory/memory.h"
|
||||
#include "ranges/ranges.h"
|
||||
#include "array/array.h"
|
||||
#include "operation/operation.h"
|
||||
|
||||
#include "cnorxz.cc.h"
|
||||
|
||||
|
|
|
@ -111,7 +111,12 @@ namespace CNORXZ
|
|||
return mData;
|
||||
}
|
||||
|
||||
|
||||
template <typename T, class IndexT>
|
||||
constexpr decltype(auto) coproot(const CArrayBase<T>& a, const Sptr<IndexT>& ind)
|
||||
{
|
||||
return COpRoot<T,IndexT>(a, ind);
|
||||
}
|
||||
|
||||
/****************
|
||||
* OpCont *
|
||||
****************/
|
||||
|
@ -250,7 +255,7 @@ namespace CNORXZ
|
|||
template <class Op>
|
||||
constexpr OpRoot<T,IndexT>& OpRoot<T,IndexT>::operator=(const Op& o)
|
||||
{
|
||||
a(mIndex, [](auto& a, const auto& b) { a = b; }, o);
|
||||
OI::a(mIndex, [](auto& a, const auto& b) { a = b; }, o);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -258,14 +263,14 @@ namespace CNORXZ
|
|||
template <class Op>
|
||||
constexpr OpRoot<T,IndexT>& OpRoot<T,IndexT>::operator+=(const Op& o)
|
||||
{
|
||||
a(mIndex, [](auto& a, const auto& b) { a += b; }, o);
|
||||
OI::a(mIndex, [](auto& a, const auto& b) { a += b; }, o);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, class IndexT>
|
||||
constexpr OpRoot<T,IndexT>& OpRoot<T,IndexT>::operator=(const OpRoot<T,IndexT>& o)
|
||||
{
|
||||
a(mIndex, [](auto& a, const auto& b) { a = b; }, o);
|
||||
OI::a(mIndex, [](auto& a, const auto& b) { a = b; }, o);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -307,6 +312,12 @@ namespace CNORXZ
|
|||
return mData;
|
||||
}
|
||||
|
||||
template <typename T, class IndexT>
|
||||
constexpr decltype(auto) oproot(ArrayBase<T>& a, const Sptr<IndexT>& ind)
|
||||
{
|
||||
return OpRoot<T,IndexT>(a, ind);
|
||||
}
|
||||
|
||||
/*******************
|
||||
* Operation *
|
||||
*******************/
|
||||
|
|
|
@ -91,6 +91,9 @@ namespace CNORXZ
|
|||
Sptr<IndexT> mIndex;
|
||||
};
|
||||
|
||||
template <typename T, class IndexT>
|
||||
constexpr decltype(auto) coproot(const CArrayBase<T>& a, const Sptr<IndexT>& ind);
|
||||
|
||||
template <typename T, class IndexT>
|
||||
class OpCont : public OpInterface<OpCont<T,IndexT>>
|
||||
{
|
||||
|
@ -169,6 +172,8 @@ namespace CNORXZ
|
|||
|
||||
};
|
||||
|
||||
template <typename T, class IndexT>
|
||||
constexpr decltype(auto) oproot(ArrayBase<T>& a, const Sptr<IndexT>& ind);
|
||||
|
||||
template <class F, class... Ops>
|
||||
class Operation : public OpInterface<Operation<F,Ops...>>
|
||||
|
|
|
@ -1,117 +0,0 @@
|
|||
|
||||
#ifndef __cxz_index_utils_cc_h__
|
||||
#define __cxz_index_utils_cc_h__
|
||||
|
||||
#include "index_utils.h"
|
||||
|
||||
namespace CNORZX
|
||||
{
|
||||
template <class Index>
|
||||
constexpr decltype(auto) getIndexDepth(const Index& ind)
|
||||
{
|
||||
static_assert(is_index<Index>::value, "got non-index type");
|
||||
if constexpr(has_sub<Index>::value){
|
||||
if constexpr(has_static_sub<Index>::value){
|
||||
constexpr SizeT D = index_dim<Index>::value;
|
||||
return iter<0,D>
|
||||
( [&](auto i) { return getIndexDepth(*std::get<i>(ind.pack())); },
|
||||
[](auto... e) {
|
||||
if constexpr( is_integral_constant<decltype(e)>::value and ... ){
|
||||
return std::integral_constant<SizeT,std::max({e...})> {};
|
||||
}
|
||||
else {
|
||||
return std::max({e...});
|
||||
}
|
||||
} );
|
||||
}
|
||||
else {
|
||||
SizeT o = 0;
|
||||
if(ind.dim() == 1){
|
||||
auto p = ind.pack();
|
||||
if(p.size() == 0){
|
||||
o = 1;
|
||||
}
|
||||
else {
|
||||
o = getIndexDepth(*p[0]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(SizeT i = 0; i != ind.dim(); ++i){
|
||||
const SizeT e = getIndexDepth(*ind.pack()[i]);
|
||||
if(e > o){
|
||||
o = e;
|
||||
}
|
||||
}
|
||||
}
|
||||
return o;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return std::integral_constant<SizeT,1> {};
|
||||
}
|
||||
}
|
||||
|
||||
template <class Index, typename IntT>
|
||||
constexpr decltype(auto) getDimension(const Index& ind, IntT depth)
|
||||
{
|
||||
static_assert(is_index<Index>::value, "got non-index type");
|
||||
if constexpr(std::is_same<std::integral_constant<SizeT,0>,IntT>::value) {
|
||||
return std::integral_constant<SizeT,1> {}
|
||||
}
|
||||
else {
|
||||
auto iminus = [](auto i) {
|
||||
if constexpr( is_integral_constant<decltype(i)>::value ) {
|
||||
return std::integral_constant<SizeT,i-1> {}
|
||||
}
|
||||
else {
|
||||
return i-1;
|
||||
}
|
||||
};
|
||||
if constexpr(has_sub<Index>::value){
|
||||
if constexpr(has_static_sub<Index>::value and is_integral_constant<IntT>::value){
|
||||
constexpr SizeT D = index_dim<Index>::value;
|
||||
return iter<0,D>
|
||||
( [&](auto i) { return getDimension(*std::get<i>(ind.pack()),
|
||||
iminus(depth)); },
|
||||
[](auto... e) {
|
||||
if constexpr( is_integral_constant<decltype(e)>::value and ... ){
|
||||
return std::integral_constant<SizeT,(e + ...)> {};
|
||||
}
|
||||
else {
|
||||
return (e + ...);
|
||||
}
|
||||
} );
|
||||
}
|
||||
else {
|
||||
SizeT o = 0;
|
||||
if(depth == 0u){
|
||||
o = 1;
|
||||
}
|
||||
else if(ind.dim() == 1){
|
||||
auto p = ind.pack();
|
||||
if(p.size() == 0){
|
||||
o = 1;
|
||||
}
|
||||
else {
|
||||
o = getDimension(*p[0], iminus(depth));
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(SizeT i = 0; i != ind.dim(); ++i){
|
||||
const SizeT e = getDimension(*ind.pack()[i], iminus(depth));
|
||||
if(e > o){
|
||||
o = e;
|
||||
}
|
||||
}
|
||||
}
|
||||
return o;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return std::integral_constant<SizeT,1> {};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,18 +0,0 @@
|
|||
|
||||
#ifndef __cxz_index_utils_h__
|
||||
#define __cxz_index_utils_h__
|
||||
|
||||
#include "base/base.h"
|
||||
|
||||
namespace CNORZX
|
||||
{
|
||||
template <class Index>
|
||||
constexpr decltype(auto) getIndexDepth(const Index& ind);
|
||||
|
||||
template <class Index, typename IntT>
|
||||
constexpr decltype(auto) getDimension(const Index& ind, IntT depth);
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -21,10 +21,12 @@ namespace
|
|||
{
|
||||
mSize = 7;
|
||||
mCR1 = CRangeFactory(mSize).create();
|
||||
mA = MArray<Double>(mCR1, Numbers::get(0,mSize));
|
||||
}
|
||||
|
||||
SizeT mSize;
|
||||
RangePtr mCR1;
|
||||
MArray<Double> mA;
|
||||
};
|
||||
|
||||
class MA_2D_Test : public ::testing::Test
|
||||
|
@ -37,46 +39,62 @@ namespace
|
|||
mStrMeta = { "another", "test", "string", "vector", "for", "this", "Test" };
|
||||
mCR1 = CRangeFactory(mSize).create();
|
||||
mUR1 = URangeFactory<String>(mStrMeta).create();
|
||||
const SizeT ssize = mStrMeta.size();
|
||||
const SizeT size = mSize * ssize;
|
||||
mA = MArray<Double>(mCR1*mUR1, Numbers::get(0,size));
|
||||
mA2 = MArray<Double>(mUR1*mCR1, Numbers::get(0,size));
|
||||
}
|
||||
|
||||
SizeT mSize;
|
||||
Vector<String> mStrMeta;
|
||||
RangePtr mCR1;
|
||||
RangePtr mUR1;
|
||||
MArray<Double> mA;
|
||||
MArray<Double> mA2;
|
||||
};
|
||||
|
||||
|
||||
TEST_F(MA_1D_Test, Basics)
|
||||
{
|
||||
const MArray<Double> a(mCR1, Numbers::get(0,mSize));
|
||||
auto crx = std::dynamic_pointer_cast<CRange>(mCR1);
|
||||
EXPECT_EQ(a.size(), mSize);
|
||||
EXPECT_FALSE(a.isView());
|
||||
EXPECT_EQ(mA.size(), mSize);
|
||||
EXPECT_FALSE(mA.isView());
|
||||
|
||||
auto ei = crx->end();
|
||||
EXPECT_EQ(ei.lex(), mSize);
|
||||
for(auto i = crx->begin(); i != ei; ++i){
|
||||
EXPECT_EQ(i.lex(), i.pos());
|
||||
EXPECT_EQ(a[i], a.data()[i.lex()]);
|
||||
EXPECT_EQ(a.at(i), a.data()[i.lex()]);
|
||||
EXPECT_EQ(mA[i], mA.data()[i.lex()]);
|
||||
EXPECT_EQ(mA.at(i), mA.data()[i.lex()]);
|
||||
}
|
||||
EXPECT_THROW({a.at(ei);}, std::runtime_error);
|
||||
EXPECT_THROW({mA.at(ei);}, std::runtime_error);
|
||||
}
|
||||
|
||||
TEST_F(MA_2D_Test, Basics)
|
||||
{
|
||||
const SizeT ssize = mStrMeta.size();
|
||||
const SizeT size = mSize * ssize;
|
||||
const MArray<Double> a(mCR1*mUR1, Numbers::get(0,size));
|
||||
EXPECT_EQ(a.range()->dim(), 2u);
|
||||
EXPECT_EQ(a.size(), size);
|
||||
EXPECT_EQ(a.range()->sub(0), mCR1);
|
||||
EXPECT_EQ(a.range()->sub(1), mUR1);
|
||||
EXPECT_EQ(mA.range()->dim(), 2u);
|
||||
EXPECT_EQ(mA.size(), size);
|
||||
EXPECT_EQ(mA.range()->sub(0), mCR1);
|
||||
EXPECT_EQ(mA.range()->sub(1), mUR1);
|
||||
auto cr1x = std::dynamic_pointer_cast<CRange>(mCR1);
|
||||
auto ur1x = std::dynamic_pointer_cast<URange<String>>(mUR1);
|
||||
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( a[ci*ui], a.data()[p] );
|
||||
EXPECT_EQ( mA[ci*ui], mA.data()[p] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(MA_2D_Test, Operation)
|
||||
{
|
||||
auto uip1 = std::make_shared<UIndex<String>>(mUR1);
|
||||
auto cip1 = std::make_shared<CIndex>(mCR1);
|
||||
mA2(uip1*cip1) = mA(cip1*uip1);
|
||||
for(auto ui = mUR1->begin(); ui != mUR1->end(); ++ui){
|
||||
for(auto ci = mCR1->begin(); ci != mCR1->end(); ++ci){
|
||||
EXPECT_EQ(mA2[ui*ci], mA[ci*ui]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue