Essentia  2.1-beta5-dev
tnt2essentiautils.h
Go to the documentation of this file.
1 #ifndef ESSENTIA_TNT2ESSENTIAUTILS_H
2 #define ESSENTIA_TNT2ESSENTIAUTILS_H
3 
4 #include <fstream>
5 #include "tnt.h"
6 
7 namespace essentia {
8 
9  template <typename T>
11  int m = A.dim1();
12  int n = A.dim2();
13 
14  if (k == 0) {
15  throw EssentiaException("Error: Division of an TNT::Array2D by zero");
16  }
17 
18  for (int i=0; i<m; i++)
19  for (int j=0; j<n; j++)
20  A[i][j] /= k;
21  return A;
22  }
23 
24  template <typename T>
25  TNT::Array2D<T> operator/(const TNT::Array2D<T> &A, const T &k) {
26  int m = A.dim1();
27  int n = A.dim2();
28 
29  if (k == 0) {
30  throw EssentiaException("Error: Division of an TNT::Array2D by zero");
31  }
32 
33  if (m == 0 || n == 0 )
34  return TNT::Array2D<T>();
35  TNT::Array2D<T> result(m,n);
36 
37  for (int i=0; i<m; i++)
38  for (int j=0; j<n; j++)
39  result[i][j] = A[i][j] / k;
40 
41  return result;
42  }
43 
44  template <typename T>
46  for (int i = 0; i < A.dim1(); i++) {
47  for (int j = 0; j < A.dim2(); j++) {
48  A[i][j] = 0;
49  }
50  }
51  return A;
52  }
53 
54 } // namespace essentia
55 
56 #endif // ESSENTIA_TNT2ESSENTIAUTILS_H
int dim1() const
Definition: tnt_array2d.h:231
TNT::Array2D< T > & operator/=(TNT::Array2D< T > &A, const T &k)
Definition: tnt2essentiautils.h:10
Definition: tnt_array2d.h:37
TNT::Array2D< T > & matinit(TNT::Array2D< T > &A)
Definition: tnt2essentiautils.h:45
int dim2() const
Definition: tnt_array2d.h:234
Definition: algorithm.h:28
Definition: types.h:76
TNT::Array2D< T > operator/(const TNT::Array2D< T > &A, const T &k)
Definition: tnt2essentiautils.h:25