20 #ifndef ESSENTIA_UTILS_H
21 #define ESSENTIA_UTILS_H
36 #define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(*(arr)))
42 #define NOWARN_UNUSED(expr) do { (void)(expr); } while (0)
48 template <
typename T,
typename Array>
51 std::vector<T> result(size);
52 for (
int i=0; i<size; i++) {
65 int indexOf(
const std::vector<T>& v,
const T& elem) {
66 const int size = (int)v.size();
67 for (
int i=0; i<size; i++) {
68 if (v[i] == elem)
return i;
81 bool contains(
const std::vector<T>& v,
const T& elem) {
82 return (
indexOf(v, elem) != -1);
85 inline bool contains(
const std::vector<std::string>& v,
const char* str) {
86 return contains(v, std::string(str));
92 template <
typename T,
typename U>
93 bool contains(
const std::map<T, U>& m,
const T& key) {
94 return m.find(key) != m.end();
99 const int size = (int)m.
size();
100 for (
int i=0; i<size; i++) {
101 if (m[i].first == key)
return true;
106 template <
typename T>
108 return contains(m, std::string(key));
116 template <
typename T>
118 if (std::isinf(value) || std::isnan(value))
return false;
122 template <
typename T>
136 template <
typename T>
137 inline bool isValid(
const std::vector<T>& v) {
138 typename std::vector<T>::const_iterator it = v.begin();
139 while (it != v.end() &&
isValid(*it)) ++it;
140 return it == v.end();
143 template <
typename T>
144 inline bool isValid(
const std::vector<std::vector<T> >& mat) {
145 typename std::vector<std::vector<T> >::const_iterator it = mat.begin();
146 while (it != mat.end() &&
isValid(*it)) ++it;
147 return it == mat.end();
150 template <
typename T>
152 for (
int row=0; row<mat.
dim1(); ++row) {
153 for (
int col=0; col<mat.
dim2(); ++col) {
154 if (!
isValid(mat[row][col]))
return false;
160 template <
typename T>
162 for (
const T* i = tensor.data(); i < (tensor.data() + tensor.size()); ++i){
163 if (!
isValid(*i))
return false;
169 int mkstemp(
char *tmpl);
179 template <
typename T>
180 inline void fastcopy(T* dest,
const T* src,
int n) {
181 for (
int i=0; i<n; i++) {
188 memcpy(dest, src, n*
sizeof(
Real));
198 memcpy(dest, src, n*
sizeof(
int));
202 inline void fastcopy(std::vector<Real>::iterator dest, std::vector<Real>::const_iterator src,
int n) {
209 inline void fastcopy(std::vector<StereoSample>::iterator dest, std::vector<StereoSample>::const_iterator src,
int n) {
Definition: tnt_array2d.h:38
int dim1() const
Definition: tnt_array2d.h:231
int dim2() const
Definition: tnt_array2d.h:234
int size() const
Definition: types.h:133
const T & right() const
Definition: types.h:358
const T & left() const
Definition: types.h:357
#define ARRAY_SIZE(arr)
Definition: essentiautil.h:36
Definition: algorithm.h:28
void fastcopy< Real >(Real *dest, const Real *src, int n)
Definition: essentiautil.h:187
void fastcopy< int >(int *dest, const int *src, int n)
Definition: essentiautil.h:197
bool isValid(const T &value)
Definition: essentiautil.h:117
void fastcopy(T *dest, const T *src, int n)
Definition: essentiautil.h:180
std::vector< T > arrayToVector(const Array &array)
Definition: essentiautil.h:49
int indexOf(const std::vector< T > &v, const T &elem)
Definition: essentiautil.h:65
float Real
Definition: types.h:69
void fastcopy< StereoSample >(StereoSample *dest, const StereoSample *src, int n)
Definition: essentiautil.h:192
Eigen::Tensor< T, 4, Eigen::RowMajor > Tensor
Definition: types.h:384
bool contains(const std::vector< T > &v, const T &elem)
Definition: essentiautil.h:81