Essentia  2.1-beta6-dev
tnt2vector.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2021 Music Technology Group - Universitat Pompeu Fabra
3  *
4  * This file is part of Essentia
5  *
6  * Essentia is free software: you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License as published by the Free
8  * Software Foundation (FSF), either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the Affero GNU General Public License
17  * version 3 along with this program. If not, see http://www.gnu.org/licenses/
18  */
19 
20 #ifndef ESSENTIA_TNT2VECTOR_H
21 #define ESSENTIA_TNT2VECTOR_H
22 
23 #include <fstream>
24 #include "tnt.h"
25 
26 namespace essentia {
27 
28  inline TNT::Array2D<Real> vecvecToArray2D(const std::vector<std::vector<Real> >& v) {
29 
30  if (v.size() == 0) {
31  throw EssentiaException("You are trying to convert an empty vector of vector into a Array2D.");
32  }
33 
34  TNT::Array2D<Real> v2D((int)v.size(), (int)v[0].size());
35  for (int i=0; i<v2D.dim1(); i++) {
36  for (int j=0; j<v2D.dim2(); j++) {
37  v2D[i][j] = v[i][j];
38  }
39  }
40 
41  return v2D;
42  }
43 
44  inline std::vector<std::vector<Real> > array2DToVecvec(const TNT::Array2D<Real>& v2D) {
45 
46  if (v2D.dim1() == 0) {
47  throw EssentiaException("You are trying to convert an empty Array2D into a vector of vector.");
48  }
49 
50  std::vector<std::vector<Real> > v;
51  v.resize(v2D.dim1());
52 
53  for (uint i=0; i<v.size(); i++) {
54  v[i].resize(v2D.dim2());
55  for (uint j=0; j<v[i].size(); j++) {
56  v[i][j] = v2D[(int)i][(int)j];
57  }
58  }
59 
60  return v;
61  }
62 
63 } // namespace essentia
64 
65 #endif // ESSENTIA_TNT2VECTOR_H
int dim1() const
Definition: tnt_array2d.h:231
int dim2() const
Definition: tnt_array2d.h:234
Definition: types.h:77
Definition: algorithm.h:28
std::vector< std::vector< Real > > array2DToVecvec(const TNT::Array2D< Real > &v2D)
Definition: tnt2vector.h:44
TNT::Array2D< Real > vecvecToArray2D(const std::vector< std::vector< Real > > &v)
Definition: tnt2vector.h:28
unsigned int uint
Definition: types.h:49