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

function to get tensor dimensions

This commit is contained in:
Antonin Portelli 2018-04-20 17:13:34 +01:00
parent 94edf9cf8b
commit 141da3ae71

View File

@ -30,6 +30,48 @@ namespace Grid {
typedef typename std::vector<std::vector<typename TensorToVec<T>::type>> type; typedef typename std::vector<std::vector<typename TensorToVec<T>::type>> type;
}; };
template <typename T>
void tensorDim(std::vector<size_t> &dim, const T &t, const bool wipe = true)
{
if (wipe)
{
dim.clear();
}
}
template <typename T>
void tensorDim(std::vector<size_t> &dim, const iScalar<T> &t, const bool wipe = true)
{
if (wipe)
{
dim.clear();
}
tensorDim(dim, t._internal, false);
}
template <typename T, int N>
void tensorDim(std::vector<size_t> &dim, const iVector<T, N> &t, const bool wipe = true)
{
if (wipe)
{
dim.clear();
}
dim.push_back(N);
tensorDim(dim, t._internal[0], false);
}
template <typename T, int N>
void tensorDim(std::vector<size_t> &dim, const iMatrix<T, N> &t, const bool wipe = true)
{
if (wipe)
{
dim.clear();
}
dim.push_back(N);
dim.push_back(N);
tensorDim(dim, t._internal[0][0], false);
}
template <typename T> template <typename T>
typename TensorToVec<T>::type tensorToVec(const T &t) typename TensorToVec<T>::type tensorToVec(const T &t)
{ {