rename darray_base -> carray_base, mdarray_base -> array_base, darray -> marray + rename corresponding files/tests

This commit is contained in:
Christian Zimmermann 2022-12-06 14:48:44 +01:00
parent 9aba24cf01
commit 9938d43f9c
11 changed files with 141 additions and 141 deletions

View file

@ -1,6 +1,6 @@
//#include "access.cc.h" //#include "access.cc.h"
#include "darray_base.cc.h" #include "array_base.cc.h"
#include "darray.cc.h" #include "marray.cc.h"
#include "aindex.cc.h" #include "aindex.cc.h"
//#include "functional_array.cc.h" //#include "functional_array.cc.h"

View file

@ -1,7 +1,7 @@
//#include "access.h" //#include "access.h"
#include "darray_base.h" #include "array_base.h"
#include "darray.h" #include "marray.h"
#include "aindex.h" #include "aindex.h"
//#include "functional_array.h" //#include "functional_array.h"

View file

@ -1,23 +1,23 @@
#ifndef __cxz_darray_base_cc_h__ #ifndef __cxz_array_base_cc_h__
#define __cxz_darray_base_cc_h__ #define __cxz_array_base_cc_h__
#include "darray_base.h" #include "array_base.h"
namespace CNORXZ namespace CNORXZ
{ {
/****************** /******************
* DArrayBase * * CArrayBase *
******************/ ******************/
template <typename T> template <typename T>
DArrayBase<T>::DArrayBase(const RangePtr& range) : CArrayBase<T>::CArrayBase(const RangePtr& range) :
mRange(rangeCast<YRange>(range)) mRange(rangeCast<YRange>(range))
{} {}
template <typename T> template <typename T>
template <typename I, typename M> template <typename I, typename M>
const T& DArrayBase<T>::operator[](const IndexInterface<I,M>& i) const const T& CArrayBase<T>::operator[](const IndexInterface<I,M>& i) const
{ {
auto ai = this->begin() + i.lex(); auto ai = this->begin() + i.lex();
return *ai; return *ai;
@ -25,7 +25,7 @@ namespace CNORXZ
template <typename T> template <typename T>
template <typename I, typename M> template <typename I, typename M>
const T& DArrayBase<T>::at(const IndexInterface<I,M>& i) const const T& CArrayBase<T>::at(const IndexInterface<I,M>& i) const
{ {
CXZ_ASSERT(i.lex() < this->size(), "index out of range"); CXZ_ASSERT(i.lex() < this->size(), "index out of range");
// check further compatibility of index/range format!!! // check further compatibility of index/range format!!!
@ -34,25 +34,25 @@ namespace CNORXZ
} }
template <typename T> template <typename T>
SizeT DArrayBase<T>::size() const SizeT CArrayBase<T>::size() const
{ {
return mRange->size(); return mRange->size();
} }
template <typename T> template <typename T>
RangePtr DArrayBase<T>::range() const RangePtr CArrayBase<T>::range() const
{ {
return mRange; return mRange;
} }
template <typename T> template <typename T>
typename DArrayBase<T>::const_iterator DArrayBase<T>::begin() const typename CArrayBase<T>::const_iterator CArrayBase<T>::begin() const
{ {
return this->cbegin(); return this->cbegin();
} }
template <typename T> template <typename T>
typename DArrayBase<T>::const_iterator DArrayBase<T>::end() const typename CArrayBase<T>::const_iterator CArrayBase<T>::end() const
{ {
return this->cend(); return this->cend();
} }
@ -60,24 +60,24 @@ namespace CNORXZ
/* /*
template <typename T> template <typename T>
template <typename I, typename M> template <typename I, typename M>
ConstOperationRoot<T,I> DArrayBase<T>::operator()(const IndexPtr<I,M>& i) const ConstOperationRoot<T,I> CArrayBase<T>::operator()(const IndexPtr<I,M>& i) const
{ {
return ConstOperationRoot<T,I>(); return ConstOperationRoot<T,I>();
} }
*/ */
/******************* /*****************
* MDArrayBase * * ArrayBase *
*******************/ *****************/
template <typename T> template <typename T>
MDArrayBase<T>::MDArrayBase(const RangePtr& range) : ArrayBase<T>::ArrayBase(const RangePtr& range) :
DArrayBase<T>(range) CArrayBase<T>(range)
{} {}
template <typename T> template <typename T>
template <typename I, typename M> template <typename I, typename M>
T& MDArrayBase<T>::operator[](const IndexInterface<I,M>& i) T& ArrayBase<T>::operator[](const IndexInterface<I,M>& i)
{ {
auto ai = this->begin() + i.lex(); auto ai = this->begin() + i.lex();
return *ai; return *ai;
@ -85,7 +85,7 @@ namespace CNORXZ
template <typename T> template <typename T>
template <typename I, typename M> template <typename I, typename M>
T& MDArrayBase<T>::at(const IndexInterface<I,M>& i) T& ArrayBase<T>::at(const IndexInterface<I,M>& i)
{ {
CXZ_ASSERT(i.pos() < this->pmax(), "index out of range"); CXZ_ASSERT(i.pos() < this->pmax(), "index out of range");
// check further compatibility of index/range format!!! // check further compatibility of index/range format!!!
@ -94,13 +94,13 @@ namespace CNORXZ
} }
template <typename T> template <typename T>
typename MDArrayBase<T>::iterator MDArrayBase<T>::begin() typename ArrayBase<T>::iterator ArrayBase<T>::begin()
{ {
return iterator(this->data(), this->cbegin()); return iterator(this->data(), this->cbegin());
} }
template <typename T> template <typename T>
typename MDArrayBase<T>::iterator MDArrayBase<T>::end() typename ArrayBase<T>::iterator ArrayBase<T>::end()
{ {
return iterator(this->data(), this->cend()); return iterator(this->data(), this->cend());
} }
@ -108,7 +108,7 @@ namespace CNORXZ
/* /*
template <typename T> template <typename T>
template <typename I, typename M> template <typename I, typename M>
OperationRoot<T,I> MDArrayBase<T>::operator()(const IndexPtr<I,M>& i) OperationRoot<T,I> ArrayBase<T>::operator()(const IndexPtr<I,M>& i)
{ {
return OperationRoot<T,I>(); return OperationRoot<T,I>();
} }

View file

@ -1,6 +1,6 @@
#ifndef __cxz_darray_base_h__ #ifndef __cxz_array_base_h__
#define __cxz_darray_base_h__ #define __cxz_array_base_h__
#include <cstdlib> #include <cstdlib>
#include <vector> #include <vector>
@ -14,7 +14,7 @@
namespace CNORXZ namespace CNORXZ
{ {
template <typename T> template <typename T>
class DArrayBase class CArrayBase
{ {
public: public:
typedef AIndex<T> const_iterator; typedef AIndex<T> const_iterator;
@ -24,10 +24,10 @@ namespace CNORXZ
public: public:
DArrayBase(const RangePtr& range); CArrayBase(const RangePtr& range);
DEFAULT_MEMBERS(DArrayBase); DEFAULT_MEMBERS(CArrayBase);
virtual ~DArrayBase() = default; virtual ~CArrayBase() = default;
template <typename I, typename M> template <typename I, typename M>
const T& operator[](const IndexInterface<I,M>& i) const; const T& operator[](const IndexInterface<I,M>& i) const;
@ -36,7 +36,7 @@ namespace CNORXZ
const T& at(const IndexInterface<I,M>& i) const; const T& at(const IndexInterface<I,M>& i) const;
template <typename I, typename M> template <typename I, typename M>
Sptr<DArrayBase<T>> sl(const IndexInterface<I,M>& i) const; Sptr<CArrayBase<T>> sl(const IndexInterface<I,M>& i) const;
virtual const T* data() const = 0; virtual const T* data() const = 0;
virtual SizeT pmax() const = 0; // max allocated postion of data() (exclusive!) virtual SizeT pmax() const = 0; // max allocated postion of data() (exclusive!)
@ -55,24 +55,24 @@ namespace CNORXZ
}; };
template <typename T> template <typename T>
class MDArrayBase : public DArrayBase<T> class ArrayBase : public CArrayBase<T>
{ {
public: public:
typedef DArrayBase<T> DAB; typedef CArrayBase<T> CAB;
typedef typename DAB::const_iterator const_iterator; typedef typename CAB::const_iterator const_iterator;
typedef BIndex<T> iterator; typedef BIndex<T> iterator;
using DAB::operator[]; using CAB::operator[];
using DAB::at; using CAB::at;
using DAB::data; using CAB::data;
using DAB::begin; using CAB::begin;
using DAB::end; using CAB::end;
using DAB::cbegin; using CAB::cbegin;
using DAB::cend; using CAB::cend;
//using DAB::operator(); //using CAB::operator();
MDArrayBase(const RangePtr& range); ArrayBase(const RangePtr& range);
DEFAULT_MEMBERS(MDArrayBase); DEFAULT_MEMBERS(ArrayBase);
template <typename I, typename M> template <typename I, typename M>
T& operator[](const IndexInterface<I,M>& i); T& operator[](const IndexInterface<I,M>& i);
@ -81,7 +81,7 @@ namespace CNORXZ
T& at(const IndexInterface<I,M>& i); T& at(const IndexInterface<I,M>& i);
template <typename I, typename M> template <typename I, typename M>
Sptr<MDArrayBase<T>> sl(const IndexInterface<I,M>& i); Sptr<ArrayBase<T>> sl(const IndexInterface<I,M>& i);
virtual T* data() = 0; virtual T* data() = 0;

View file

@ -1,66 +0,0 @@
#ifndef __cxz_darray_cc_h__
#define __cxz_darray_cc_h__
#include "darray.h"
namespace CNORXZ
{
/****************
* DArray *
***************/
template <typename T>
DArray<T>::DArray(const RangePtr& range) :
MDArrayBase<T>(range), mCont(range->size())
{}
template <typename T>
DArray<T>::DArray(const RangePtr& range, const Vector<T>& vec) :
MDArrayBase<T>(range), mCont(vec)
{}
template <typename T>
DArray<T>::DArray(const RangePtr& range, Vector<T>&& vec) :
MDArrayBase<T>(range), mCont(vec)
{}
template <typename T>
SizeT DArray<T>::pmax() const
{
return mCont.size();
}
template <typename T>
const T* DArray<T>::data() const
{
return mCont.data();
}
template <typename T>
T* DArray<T>::data()
{
return mCont.data();
}
template <typename T>
typename DArray<T>::const_iterator DArray<T>::cbegin() const
{
return const_iterator(mCont.data(), AB::mRange);
}
template <typename T>
typename DArray<T>::const_iterator DArray<T>::cend() const
{
return const_iterator(mCont.data(), AB::mRange, mCont.size());
}
template <typename T>
bool DArray<T>::isView() const
{
return false;
}
}
#endif

View file

@ -0,0 +1,66 @@
#ifndef __cxz_marray_cc_h__
#define __cxz_marray_cc_h__
#include "marray.h"
namespace CNORXZ
{
/****************
* MArray *
***************/
template <typename T>
MArray<T>::MArray(const RangePtr& range) :
ArrayBase<T>(range), mCont(range->size())
{}
template <typename T>
MArray<T>::MArray(const RangePtr& range, const Vector<T>& vec) :
ArrayBase<T>(range), mCont(vec)
{}
template <typename T>
MArray<T>::MArray(const RangePtr& range, Vector<T>&& vec) :
ArrayBase<T>(range), mCont(vec)
{}
template <typename T>
SizeT MArray<T>::pmax() const
{
return mCont.size();
}
template <typename T>
const T* MArray<T>::data() const
{
return mCont.data();
}
template <typename T>
T* MArray<T>::data()
{
return mCont.data();
}
template <typename T>
typename MArray<T>::const_iterator MArray<T>::cbegin() const
{
return const_iterator(mCont.data(), AB::mRange);
}
template <typename T>
typename MArray<T>::const_iterator MArray<T>::cend() const
{
return const_iterator(mCont.data(), AB::mRange, mCont.size());
}
template <typename T>
bool MArray<T>::isView() const
{
return false;
}
}
#endif

View file

@ -1,26 +1,26 @@
#ifndef __cxz_darray_h__ #ifndef __cxz_marray_h__
#define __cxz_darray_h__ #define __cxz_marray_h__
#include "darray_base.h" #include "array_base.h"
namespace CNORXZ namespace CNORXZ
{ {
template <typename T> template <typename T>
class DArray : public MDArrayBase<T> class MArray : public ArrayBase<T>
{ {
public: public:
typedef DArrayBase<T> AB; typedef CArrayBase<T> AB;
typedef typename AB::const_iterator const_iterator; typedef typename AB::const_iterator const_iterator;
using DArrayBase<T>::operator[]; using CArrayBase<T>::operator[];
using MDArrayBase<T>::operator[]; using ArrayBase<T>::operator[];
DEFAULT_MEMBERS(DArray); DEFAULT_MEMBERS(MArray);
DArray(const RangePtr& range); MArray(const RangePtr& range);
DArray(const RangePtr& range, const Vector<T>& vec); MArray(const RangePtr& range, const Vector<T>& vec);
DArray(const RangePtr& range, Vector<T>&& vec); MArray(const RangePtr& range, Vector<T>&& vec);
virtual SizeT pmax() const override; virtual SizeT pmax() const override;
virtual const T* data() const override; virtual const T* data() const override;

View file

@ -61,7 +61,7 @@ namespace CNORXZ
***************/ ***************/
template <typename T, class IndexT> template <typename T, class IndexT>
constexpr COpRoot<T,IndexT>::COpRoot(const DArrayBase<T>& a, const Sptr<IndexT>& ind) : constexpr COpRoot<T,IndexT>::COpRoot(const CArrayBase<T>& a, const Sptr<IndexT>& ind) :
mData(a.data()), mData(a.data()),
mIndex(ind) mIndex(ind)
{} {}
@ -227,7 +227,7 @@ namespace CNORXZ
****************/ ****************/
template <typename T, class IndexT> template <typename T, class IndexT>
constexpr OpRoot<T,IndexT>::OpRoot(MDArrayBase<T>& a, const Sptr<IndexT>& ind) : constexpr OpRoot<T,IndexT>::OpRoot(ArrayBase<T>& a, const Sptr<IndexT>& ind) :
mData(a.data()), mData(a.data()),
mIndex(ind) mIndex(ind)
{} {}

View file

@ -5,7 +5,7 @@
#include "base/base.h" #include "base/base.h"
#include "xpr/xpr_base.h" #include "xpr/xpr_base.h"
#include "array/darray_base.h" #include "array/array_base.h"
namespace CNORXZ namespace CNORXZ
{ {
@ -72,7 +72,7 @@ namespace CNORXZ
constexpr COpRoot() = default; constexpr COpRoot() = default;
constexpr COpRoot(const DArrayBase<T>& a, const Sptr<IndexT>& ind); constexpr COpRoot(const CArrayBase<T>& a, const Sptr<IndexT>& ind);
constexpr COpRoot(const T* data, const Sptr<IndexT>& ind); constexpr COpRoot(const T* data, const Sptr<IndexT>& ind);
constexpr COpRoot& init(const T* data, const Sptr<IndexT>& ind); constexpr COpRoot& init(const T* data, const Sptr<IndexT>& ind);
@ -141,7 +141,7 @@ namespace CNORXZ
constexpr OpRoot() = default; constexpr OpRoot() = default;
constexpr OpRoot(MDArrayBase<T>& a, const Sptr<IndexT>& ind); constexpr OpRoot(ArrayBase<T>& a, const Sptr<IndexT>& ind);
constexpr OpRoot(T* data, const Sptr<IndexT>& ind); constexpr OpRoot(T* data, const Sptr<IndexT>& ind);
constexpr OpRoot& init(T* data, const Sptr<IndexT>& ind); constexpr OpRoot& init(T* data, const Sptr<IndexT>& ind);

View file

@ -17,10 +17,10 @@ add_dependencies(rutest cnorxz)
target_link_libraries(rutest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz test_lib) target_link_libraries(rutest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz test_lib)
add_test(NAME rutest COMMAND rutest) add_test(NAME rutest COMMAND rutest)
add_executable(dautest darray_unit_test.cc) add_executable(mautest marray_unit_test.cc)
add_dependencies(dautest cnorxz) add_dependencies(mautest cnorxz)
target_link_libraries(dautest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz test_lib) target_link_libraries(mautest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz test_lib)
add_test(NAME dautest COMMAND dautest) add_test(NAME mautest COMMAND mautest)
add_executable(oputest operation_unit_test.cc) add_executable(oputest operation_unit_test.cc)
add_dependencies(oputest cnorxz) add_dependencies(oputest cnorxz)

View file

@ -13,11 +13,11 @@ namespace
using namespace CNORXZ; using namespace CNORXZ;
using Test::Numbers; using Test::Numbers;
class DA_1D_Test : public ::testing::Test class MA_1D_Test : public ::testing::Test
{ {
protected: protected:
DA_1D_Test() MA_1D_Test()
{ {
mSize = 7; mSize = 7;
mCR1 = CRangeFactory(mSize).create(); mCR1 = CRangeFactory(mSize).create();
@ -27,11 +27,11 @@ namespace
RangePtr mCR1; RangePtr mCR1;
}; };
class DA_2D_Test : public ::testing::Test class MA_2D_Test : public ::testing::Test
{ {
protected: protected:
DA_2D_Test() MA_2D_Test()
{ {
mSize = 5; mSize = 5;
mStrMeta = { "another", "test", "string", "vector", "for", "this", "Test" }; mStrMeta = { "another", "test", "string", "vector", "for", "this", "Test" };
@ -45,9 +45,9 @@ namespace
RangePtr mUR1; RangePtr mUR1;
}; };
TEST_F(DA_1D_Test, Basics) TEST_F(MA_1D_Test, Basics)
{ {
const DArray<Double> a(mCR1, Numbers::get(0,mSize)); const MArray<Double> a(mCR1, Numbers::get(0,mSize));
auto crx = std::dynamic_pointer_cast<CRange>(mCR1); auto crx = std::dynamic_pointer_cast<CRange>(mCR1);
EXPECT_EQ(a.size(), mSize); EXPECT_EQ(a.size(), mSize);
EXPECT_FALSE(a.isView()); EXPECT_FALSE(a.isView());
@ -62,11 +62,11 @@ namespace
EXPECT_THROW({a.at(ei);}, std::runtime_error); EXPECT_THROW({a.at(ei);}, std::runtime_error);
} }
TEST_F(DA_2D_Test, Basics) TEST_F(MA_2D_Test, Basics)
{ {
const SizeT ssize = mStrMeta.size(); const SizeT ssize = mStrMeta.size();
const SizeT size = mSize * ssize; const SizeT size = mSize * ssize;
const DArray<Double> a(mCR1*mUR1, Numbers::get(0,size)); const MArray<Double> a(mCR1*mUR1, Numbers::get(0,size));
EXPECT_EQ(a.range()->dim(), 2u); EXPECT_EQ(a.range()->dim(), 2u);
EXPECT_EQ(a.size(), size); EXPECT_EQ(a.size(), size);
EXPECT_EQ(a.pmax(), size); EXPECT_EQ(a.pmax(), size);