array base: slice + op
This commit is contained in:
parent
b86ea957ba
commit
a4e32416ad
2 changed files with 22 additions and 185 deletions
|
@ -7,120 +7,6 @@
|
|||
|
||||
namespace CNORXZ
|
||||
{
|
||||
/******************************
|
||||
* CArrayBase (protected) *
|
||||
******************************/
|
||||
|
||||
template <typename T>
|
||||
template <class Index>
|
||||
YIndex CArrayBase<T>::mkSliceIndex(const YIndex& yi, const Index& ind) const
|
||||
{
|
||||
// TODO: if ind.dim() < iy.dim: assume Null-Indices on missing positions;
|
||||
static_assert(has_sub<Index>::value, "got non-mutliple index");
|
||||
CXZ_ASSERT(yi.dim() == ind.dim(), "got index of incompatible dimension = "
|
||||
<< ind.dim() << ", expected: " << yi.dim());
|
||||
Vector<XIndexPtr> npack;
|
||||
Vector<SizeT> nbs;
|
||||
auto ypack = yi.pack();
|
||||
auto ipack = ind.pack();
|
||||
const auto& bs = yi.blockSizes();
|
||||
if constexpr(has_static_sub<Index>::value){
|
||||
constexpr SizeT ID = index_dim<Index>::value;
|
||||
npack.reserve(ID);
|
||||
nbs.reserve(ID);
|
||||
iter<0,ID>( [&](auto i) {
|
||||
const auto& ii1 = ypack[i];
|
||||
const auto& ii2 = std::get<i>(ipack);
|
||||
if(ii2->dim() != 0){
|
||||
npack.push_back( mkSliceIndex(ii1, ii2) );
|
||||
nbs.push_back(bs[i]);
|
||||
}
|
||||
}, NoF {} );
|
||||
}
|
||||
else {
|
||||
const SizeT idim = ind.dim();
|
||||
npack.reserve(idim);
|
||||
nbs.reserve(idim);
|
||||
for(SizeT i = 0; i != idim; ++i){
|
||||
const auto& ii1 = ypack[i];
|
||||
const auto& ii2 = ipack[i];
|
||||
if(ii2->dim() != 0){
|
||||
npack.push_back( mkSliceIndex(ii1, ii2) );
|
||||
nbs.push_back(bs[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return yindex(npack);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <class Index>
|
||||
XIndexPtr CArrayBase<T>::mkSliceIndex(const XIndexPtr& xi, const Sptr<Index>& ind) const
|
||||
{
|
||||
// TODO: if ind.dim() < iy.dim: assume Null-Indices on missing positions;
|
||||
CXZ_ASSERT(xi->dim() == ind->dim(), "got index of incompatible dimension = "
|
||||
<< ind->dim() << ", expected: " << xi->dim());
|
||||
Vector<XIndexPtr> npack;
|
||||
Vector<SizeT> nbs;
|
||||
auto xpack = xi->pack();
|
||||
const auto& bs = xi->blockSizes();
|
||||
if constexpr(has_static_sub<Index>::value){
|
||||
auto ipack = ind->pack();
|
||||
constexpr SizeT ID = index_dim<Index>::value;
|
||||
npack.reserve(ID);
|
||||
nbs.reserve(ID);
|
||||
iter<0,ID>( [&](auto i) {
|
||||
const auto& ii1 = xpack[i];
|
||||
const auto& ii2 = std::get<i>(ipack);
|
||||
const XIndexPtr si = mkSliceIndex(ii1, ii2);
|
||||
if(si != nullptr){
|
||||
npack.push_back( si );
|
||||
nbs.push_back(bs[i]);
|
||||
}
|
||||
}, NoF {} );
|
||||
}
|
||||
else if constexpr(has_static_sub<Index>::value){
|
||||
auto ipack = ind->pack();
|
||||
const SizeT idim = ind->dim();
|
||||
const SizeT xdim = xi->dim();
|
||||
const SizeT isize = ipack.size();
|
||||
const SizeT xsize = xpack.size();
|
||||
if(isize == 0 or xsize == 0){
|
||||
if(idim == 0){
|
||||
return xi->copy();
|
||||
}
|
||||
else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
CXZ_ASSERT(isize == idim and xsize == xdim, "index error");
|
||||
npack.reserve(idim);
|
||||
nbs.reserve(idim);
|
||||
for(SizeT i = 0; i != idim; ++i){
|
||||
const auto& ii1 = xpack[i];
|
||||
const auto& ii2 = ipack[i];
|
||||
const XIndexPtr si = mkSliceIndex(ii1, ii2);
|
||||
if(si != nullptr){
|
||||
npack.push_back( si );
|
||||
nbs.push_back(bs[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
const SizeT idim = ind->dim();
|
||||
if(idim == 0){
|
||||
return xi->copy();
|
||||
}
|
||||
else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
if(npack.size() == 0){
|
||||
return nullptr;
|
||||
}
|
||||
return xindexPtr(yindexPtr(npack));
|
||||
}
|
||||
|
||||
/******************
|
||||
* CArrayBase *
|
||||
******************/
|
||||
|
@ -154,11 +40,10 @@ namespace CNORXZ
|
|||
template <typename I, typename M>
|
||||
Sptr<CArrayBase<T>> CArrayBase<T>::sl(const IndexInterface<I,M>& i) const
|
||||
{
|
||||
auto beg = this->begin();
|
||||
auto si = mkSliceIndex(beg, i);
|
||||
auto it = beg + i.lex();
|
||||
return std::make_shared<CSlice>(this, si, it.pos());
|
||||
//return std::make_shared<CSlice>();
|
||||
auto beg = std::make_shared<const_iterator>(this->begin());
|
||||
auto si = i.slice(beg);
|
||||
auto it = *beg + i.lex();
|
||||
return std::make_shared<CSlice>(this, *si, it.pos());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
@ -189,32 +74,16 @@ namespace CNORXZ
|
|||
template <class I, typename M>
|
||||
COpRoot<T,I> CArrayBase<T>::operator()(const IndexPtr<I,M>& i) const
|
||||
{
|
||||
CXZ_ASSERT(false, "BLOCKSIZES!!");
|
||||
return COpRoot<T,I>(*this, std::static_pointer_cast<I>(i));
|
||||
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 LIndex<I,L>& i) const
|
||||
COpRoot<T,I> CArrayBase<T>::operator()(const Sptr<LIndex<I,L>>& i) const
|
||||
{
|
||||
CXZ_ASSERT(false, "BLOCKSIZES!!");
|
||||
return COpRoot<T,LIndex<I,L>>(*this, i);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <class I, typename M>
|
||||
COpRoot<T,I> CArrayBase<T>::op(const IndexPtr<I,M>& i) const
|
||||
{
|
||||
CXZ_ASSERT(false, "IMPLEMENT CHECKS!!");
|
||||
return COpRoot<T,I>(*this, std::static_pointer_cast<I>(i));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <class I, SizeT L>
|
||||
COpRoot<T,I> CArrayBase<T>::op(const LIndex<I,L>& i) const
|
||||
{
|
||||
CXZ_ASSERT(false, "IMPLEMENT CHECKS!!");
|
||||
return COpRoot<T,LIndex<I,L>>(*this, i);
|
||||
auto fi = this->cbegin().format( i );
|
||||
return COpRoot<T,LIndex<I,L>>(*this, fi);
|
||||
}
|
||||
|
||||
/*****************
|
||||
|
@ -248,11 +117,10 @@ namespace CNORXZ
|
|||
template <typename I, typename M>
|
||||
Sptr<ArrayBase<T>> ArrayBase<T>::sl(const IndexInterface<I,M>& i)
|
||||
{
|
||||
auto r = mkSliceRange(i);
|
||||
auto beg = this->begin();
|
||||
auto bs = mkSliceBlockSizes(i, beg);
|
||||
auto it = beg + i.lex();
|
||||
return std::make_shared<Slice>(r, this, bs, it.pos());
|
||||
auto beg = std::make_shared<const_iterator>(this->cbegin());
|
||||
auto si = i.slice(beg);
|
||||
auto it = *beg + i.lex();
|
||||
return std::make_shared<Slice>(this, *si, it.pos());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
@ -269,35 +137,20 @@ namespace CNORXZ
|
|||
|
||||
template <typename T>
|
||||
template <class I, typename M>
|
||||
OpRoot<T,I> ArrayBase<T>::operator()(const IndexPtr<I,M>& i) const
|
||||
OpRoot<T,I> ArrayBase<T>::operator()(const IndexPtr<I,M>& i)
|
||||
{
|
||||
CXZ_ASSERT(false, "BLOCKSIZES!!");
|
||||
return OpRoot<T,I>(*this, std::static_pointer_cast<I>(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 LIndex<I,L>& i) const
|
||||
OpRoot<T,I> ArrayBase<T>::operator()(const Sptr<LIndex<I,L>>& i)
|
||||
{
|
||||
CXZ_ASSERT(false, "BLOCKSIZES!!");
|
||||
return OpRoot<T,LIndex<I,L>>(*this, i);
|
||||
auto fi = this->cbegin().format( i );
|
||||
return OpRoot<T,LIndex<I,L>>(*this, fi);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <class I, typename M>
|
||||
OpRoot<T,I> ArrayBase<T>::op(const IndexPtr<I,M>& i) const
|
||||
{
|
||||
CXZ_ASSERT(false, "IMPLEMENT CHECKS!!");
|
||||
return OpRoot<T,I>(*this, std::static_pointer_cast<I>(i));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <class I, SizeT L>
|
||||
OpRoot<T,I> ArrayBase<T>::op(const LIndex<I,L>& i) const
|
||||
{
|
||||
CXZ_ASSERT(false, "IMPLEMENT CHECKS!!");
|
||||
return OpRoot<T,LIndex<I,L>>(*this, i);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -21,12 +21,6 @@ namespace CNORXZ
|
|||
|
||||
protected:
|
||||
RangePtr mRange;
|
||||
|
||||
template <class Index>
|
||||
YIndex mkSliceIndex(const YIndex& yi, const Index& i) const;
|
||||
|
||||
template <class Index>
|
||||
XIndexPtr mkSliceIndex(const XIndexPtr& xi, const Sptr<Index>& i) const;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -59,13 +53,8 @@ namespace CNORXZ
|
|||
COpRoot<T,I> operator()(const IndexPtr<I,M>& i) const;
|
||||
|
||||
template <class I, SizeT L>
|
||||
COpRoot<T,I> operator()(const LIndex<I,L>& i) const;
|
||||
COpRoot<T,I> operator()(const Sptr<LIndex<I,L>>& i) const;
|
||||
|
||||
template <class I, typename M>
|
||||
COpRoot<T,I> op(const IndexPtr<I,M>& i) const;
|
||||
|
||||
template <class I, SizeT L>
|
||||
COpRoot<T,I> op(const LIndex<I,L>& i) const;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
@ -103,16 +92,11 @@ namespace CNORXZ
|
|||
virtual iterator end();
|
||||
|
||||
template <class I, typename M>
|
||||
OpRoot<T,I> operator()(const IndexPtr<I,M>& i) const;
|
||||
OpRoot<T,I> operator()(const IndexPtr<I,M>& i);
|
||||
|
||||
template <class I, SizeT L>
|
||||
OpRoot<T,I> operator()(const LIndex<I,L>& i) const;
|
||||
OpRoot<T,I> operator()(const Sptr<LIndex<I,L>>& i);
|
||||
|
||||
template <class I, typename M>
|
||||
OpRoot<T,I> op(const IndexPtr<I,M>& i) const;
|
||||
|
||||
template <class I, SizeT L>
|
||||
OpRoot<T,I> op(const LIndex<I,L>& i) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue