1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-11-10 07:55:35 +00:00

Reverse dim ordering lexico support

This commit is contained in:
paboyle 2017-10-30 00:03:15 +00:00
parent 84b441800f
commit 689323f4ee

View File

@ -26,6 +26,25 @@ namespace Grid{
}
}
static inline void IndexFromCoorReversed (const std::vector<int>& coor,int &index,const std::vector<int> &dims){
int nd=dims.size();
int stride=1;
index=0;
for(int d=nd-1;d>=0;d--){
index = index+stride*coor[d];
stride=stride*dims[d];
}
}
static inline void CoorFromIndexReversed (std::vector<int>& coor,int index,const std::vector<int> &dims){
int nd= dims.size();
coor.resize(nd);
for(int d=nd-1;d>=0;d--){
coor[d] = index % dims[d];
index = index / dims[d];
}
}
};
}