This commit is contained in:
Christian Zimmermann 2022-12-06 19:34:42 +01:00
parent 9938d43f9c
commit 854e1a0533
11 changed files with 141 additions and 13 deletions

View file

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

View file

@ -1,8 +1,8 @@
//#include "access.h"
#include "array_base.h"
#include "marray.h"
#include "aindex.h"
#include "slice.h"
//#include "functional_array.h"
#include "array.cc.h"

View file

@ -33,6 +33,13 @@ namespace CNORXZ
return *ai;
}
template <typename T>
template <typename I, typename M>
Sptr<CArrayBase<T>> CArrayBase<T>::sl(const IndexInterface<I,M>& i) const
{
}
template <typename T>
SizeT CArrayBase<T>::size() const
{
@ -87,7 +94,7 @@ namespace CNORXZ
template <typename I, typename M>
T& ArrayBase<T>::at(const IndexInterface<I,M>& i)
{
CXZ_ASSERT(i.pos() < this->pmax(), "index out of range");
CXZ_ASSERT(i.les() < this->size(), "index out of range");
// check further compatibility of index/range format!!!
auto ai = this->begin() + i.lex();
return *ai;

View file

@ -39,7 +39,6 @@ namespace CNORXZ
Sptr<CArrayBase<T>> sl(const IndexInterface<I,M>& i) const;
virtual const T* data() const = 0;
virtual SizeT pmax() const = 0; // max allocated postion of data() (exclusive!)
virtual SizeT size() const;
virtual RangePtr range() const;

View file

@ -25,12 +25,6 @@ namespace CNORXZ
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
{

View file

@ -22,7 +22,6 @@ namespace CNORXZ
MArray(const RangePtr& range, const Vector<T>& vec);
MArray(const RangePtr& range, Vector<T>&& vec);
virtual SizeT pmax() const override;
virtual const T* data() const override;
virtual T* data() override;
virtual const_iterator cbegin() const override;

View file

@ -0,0 +1,64 @@
#ifndef __cxz_slice_cc_h__
#define __cxz_slice_cc_h__
#include "slice.h"
namespace CNORXZ
{
/**************
* CSlice *
**************/
template <typename T>
CSlice<T>::CSlice(const RangePtr& range, const CArrayBase<T>* parent,
const Vector<SizeT>& blockSizes, SizeT off) :
CArrayBase<T>(range),
mCParent(parent),
mBlockSizes(blockSizes),
mOff(off)
{}
template <typename T>
const T* CSlice<T>::data() const
{
return mCParent->data() + mOff;
}
template <typename T>
typename CSlice<T>::const_iterator CSlice<T>::cbegin() const
{
return const_iterator(YIndex(AB::mRange, mBlockSizes, 0));
}
template <typename T>
typename CSlice<T>::const_iterator CSlice<T>::cend() const
{
return const_iterator(YIndex(AB::mRange, mBlockSizes, AB::mRange->size()));
}
template <typename T>
bool CSlice<T>::isView() const
{
return true;
}
/*************
* Slice *
*************/
template <typename T>
Slice<T>::Slice(const RangePtr& range, ArrayBase<T>* parent,
const Vector<SizeT>& blockSizes, SizeT off) :
CSlice<T>(range, parent, blockSizes, off),
mParent(parent)
{}
template <typename T>
T* Slice<T>::data()
{
return mParent->data();
}
}
#endif

53
src/include/array/slice.h Normal file
View file

@ -0,0 +1,53 @@
#ifndef __cxz_slice_h__
#define __cxz_slice_h__
#include "base/base.h"
#include "array_base.h"
namespace CNORXZ
{
template <typename T>
class CSlice : public CArrayBase<T>
{
public:
typedef CArrayBase<T> AB;
typedef typename AB::const_iterator const_iterator;
protected:
const CArrayBase<T>* mCParent = nullptr;
Vector<SizeT> mBlockSizes;
SizeT mOff = 0;
public:
DEFAULT_MEMBERS(CSlice);
CSlice(const RangePtr& range, const CArrayBase<T>* parent,
const Vector<SizeT>& blockSizes, SizeT off);
virtual const T* data() const override;
virtual const_iterator cbegin() const override;
virtual const_iterator cend() const override;
virtual bool isView() const override final;
};
template <typename T>
class Slice : public virtual ArrayBase<T>,
public virtual CSlice<T>
{
public:
typedef CArrayBase<T> AB;
typedef typename AB::const_iterator const_iterator;
private:
ArrayBase<T>* mParent = nullptr;
public:
DEFAULT_MEMBERS(Slice);
Slice(const RangePtr& range, ArrayBase<T>* parent,
const Vector<SizeT>& blockSizes, SizeT off);
virtual T* data() override;
};
}
#endif

View file

@ -26,7 +26,8 @@ namespace CNORXZ
YIndex(const Vector<XIndexPtr>& is);
YIndex(const Vector<SizeT>& bs, const Vector<XIndexPtr>& is);
YIndex(const RangePtr& range, SizeT lexpos);
YIndex(const RangePtr& range, SizeT lexpos = 0);
YIndex(const RangePtr& range, const Vector<SizeT>& bs, SizeT lexpos = 0);
YIndex& operator=(SizeT lexpos);
YIndex& operator++();

View file

@ -184,6 +184,18 @@ namespace CNORXZ
*this = lexpos;
}
YIndex::YIndex(const RangePtr& range, const Vector<SizeT>& bs, SizeT lexpos) :
IndexInterface<YIndex,DType>(0),
mRange(rangeCast<YRange>(range)),
mIs(mkIndices()),
mBlockSizes(bs),
mLexBlockSizes(mkLexBlockSizes()),
mPMax(mkPMax()),
mLMax(mkLMax())
{
*this = lexpos;
}
YIndex& YIndex::operator=(SizeT lexpos)
{
if(lexpos >= lmax().val()){

View file

@ -69,7 +69,6 @@ namespace
const MArray<Double> a(mCR1*mUR1, Numbers::get(0,size));
EXPECT_EQ(a.range()->dim(), 2u);
EXPECT_EQ(a.size(), size);
EXPECT_EQ(a.pmax(), size);
EXPECT_EQ(a.range()->sub(0), mCR1);
EXPECT_EQ(a.range()->sub(1), mUR1);
auto cr1x = std::dynamic_pointer_cast<CRange>(mCR1);