VAPOR3 3.9.4
utils.h
Go to the documentation of this file.
1
2#include <cstring>
3#include <vector>
4#include <limits>
5#include <vapor/common.h>
6
7#pragma once
8
9namespace Wasp {
10
12public:
14 {
15 _buf = NULL;
16 _buf_sz = 0;
17 };
18
19 SmartBuf(size_t size)
20 {
21 _buf = new unsigned char[size];
22 _buf_sz = size;
23 };
24
25 SmartBuf(const SmartBuf &rhs)
26 {
27 _buf = new unsigned char[rhs._buf_sz];
28 _buf_sz = rhs._buf_sz;
29 memcpy(_buf, rhs._buf, rhs._buf_sz);
30 }
31
33 {
34 _buf = new unsigned char[rhs._buf_sz];
35 _buf_sz = rhs._buf_sz;
36 memcpy(_buf, rhs._buf, rhs._buf_sz);
37 return *this;
38 }
39
41 {
42 if (_buf) delete[] _buf;
43 };
44 void * Alloc(size_t size);
45 void * GetBuf() const { return (_buf); }
46 size_t GetBufSize() const { return (_buf_sz); }
47
48private:
49 unsigned char *_buf;
50 size_t _buf_sz;
51};
52
67//
68COMMON_API size_t LinearizeCoords(const size_t *coords, const size_t *dims, size_t n);
69COMMON_API size_t LinearizeCoords(const std::vector<size_t> &coords, const std::vector<size_t> &dims);
70
85COMMON_API size_t LinearizeCoords(const size_t *coords, const size_t *min, const size_t *max, size_t n);
86COMMON_API size_t LinearizeCoords(const std::vector<size_t> &coords, const std::vector<size_t> &min, const std::vector<size_t> &max);
87
94//
95COMMON_API void IncrementCoords(const size_t *min, const size_t *max, size_t *counter, size_t n, int dim);
96COMMON_API std::vector<size_t> IncrementCoords(const std::vector<size_t> &min, const std::vector<size_t> &max, std::vector<size_t> counter, int dim = 0);
97
101//
102COMMON_API std::vector<size_t> Dims(const std::vector<size_t> &min, const std::vector<size_t> &max);
103
106COMMON_API size_t VProduct(const size_t *a, size_t n);
107COMMON_API size_t VProduct(const std::vector<size_t> &a);
108
111COMMON_API void VectorizeCoords(size_t offset, const size_t *min, const size_t *max, size_t *coords, size_t n);
112COMMON_API std::vector<size_t> VectorizeCoords(size_t offset, const std::vector<size_t> &min, const std::vector<size_t> &max);
113
116COMMON_API void VectorizeCoords(size_t offset, const size_t *dims, size_t *coords, size_t n);
117COMMON_API std::vector<size_t> VectorizeCoords(size_t offset, const std::vector<size_t> &dims);
118
119//
120// blocked submatrix Transpose suitable for multithreading
121// *a : pointer to input matrix
122// *b : pointer to output matrix
123// p1,p2: starting index of submatrix (row,col)
124// m1,m2: size of submatrix (row,col)
125// s1,s2: size of entire matrix (row,col)
126//
127COMMON_API void Transpose(const float *a, float *b, size_t p1, size_t m1, size_t s1, size_t p2, size_t m2, size_t s2);
128
129//
130// blocked matrix Transpose single threaded
131// *a : pointer to input matrix
132// *b : pointer to output matrix
133// s1,s2: size of entire matrix (row,col)
134//
135COMMON_API void Transpose(const float *a, float *b, size_t s1, size_t s2);
136
137// Perform a binary search in a sorted (increasing or decreasing) 1D
138// vector of values for the
139// intervale that contains 'x'. Return the offset 'i' of start of the
140// interval containing 'x' in 'sorted'.
141//
142COMMON_API bool BinarySearchRange(const std::vector<double> &sorted, double x, size_t &i);
143
155//
156//
157COMMON_API bool NearlyEqual(float a, float b, float epsilon = std::numeric_limits<float>::epsilon(), float abs_th = std::numeric_limits<float>::epsilon());
158
159}; // namespace Wasp
void * Alloc(size_t size)
void * GetBuf() const
Definition: utils.h:45
SmartBuf & operator=(const SmartBuf &rhs)
Definition: utils.h:32
SmartBuf(size_t size)
Definition: utils.h:19
SmartBuf(const SmartBuf &rhs)
Definition: utils.h:25
size_t GetBufSize() const
Definition: utils.h:46
#define COMMON_API
Definition: common.h:72
Definition: CFuncs.h:31
COMMON_API void Transpose(const float *a, float *b, size_t p1, size_t m1, size_t s1, size_t p2, size_t m2, size_t s2)
COMMON_API bool BinarySearchRange(const std::vector< double > &sorted, double x, size_t &i)
COMMON_API void IncrementCoords(const size_t *min, const size_t *max, size_t *counter, size_t n, int dim)
COMMON_API size_t VProduct(const size_t *a, size_t n)
COMMON_API size_t LinearizeCoords(const size_t *coords, const size_t *dims, size_t n)
COMMON_API void VectorizeCoords(size_t offset, const size_t *min, const size_t *max, size_t *coords, size_t n)
COMMON_API std::vector< size_t > Dims(const std::vector< size_t > &min, const std::vector< size_t > &max)
COMMON_API bool NearlyEqual(float a, float b, float epsilon=std::numeric_limits< float >::epsilon(), float abs_th=std::numeric_limits< float >::epsilon())