Essentia  2.1-beta6-dev
output.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_OUTPUT_H
21 #define ESSENTIA_OUTPUT_H
22 
23 #include <fstream>
24 
25 namespace essentia {
26 
27  void outputYAMLArray(std::ostream& out, const std::vector<Real>& v) {
28  out.precision(10);
29 
30  if (v.empty()) {
31  out << "[]\n";
32  return;
33  }
34 
35  if (v.size() == 1) {
36  out << v[0] << '\n';
37  return;
38  }
39 
40  // print 4 values/line
41  out << "[ ";
42  out.width(12);
43  out << v[0];
44  for (int i=1; i<(int)v.size(); i++) {
45  // to newline or not to newline, that is the question...
46  if (i%4 == 0) {
47  out << ",\n ";
48  }
49  else {
50  out << ", ";
51  }
52  out.width(12);
53  out << v[i];
54  }
55  out << "]";
56  }
57 
58  void outputYAMLMatrix(std::ostream& out, const std::vector<std::vector<Real> >& v) {
59  out.precision(10);
60 
61  out << "[ [ ";
62  out.width(12);
63  out << v[0][0];
64  for (int j=1; j<(int)v[0].size(); j++) {
65  out << ", ";
66  out.width(12);
67  out << v[0][j];
68  }
69  out << "]";
70 
71  for (int i=1; i<(int)v.size(); i++) {
72  out << ",\n [ ";
73  out.width(12);
74  out << v[i][0];
75  for (int j=1; j<(int)v[i].size(); j++) {
76  out << ", ";
77  out.width(12);
78  out << v[i][j];
79  }
80  out << "]";
81  }
82  out << " ]\n";
83 
84  }
85 
86 } // namespace essentia
87 
88 #endif // ESSENTIA_OUTPUT_H
Definition: algorithm.h:28
void outputYAMLMatrix(std::ostream &out, const std::vector< std::vector< Real > > &v)
Definition: output.h:58
void outputYAMLArray(std::ostream &out, const std::vector< Real > &v)
Definition: output.h:27