31 #ifndef __TASMANIAN_SPARSE_GRID_UTILS_HPP
32 #define __TASMANIAN_SPARSE_GRID_UTILS_HPP
65 template<
typename scalar_type>
66 void transpose(
long long M,
long long N, scalar_type
const A[], scalar_type B[]);
68 template<
typename scalar_type>
69 std::vector<scalar_type>
transpose(
long long M,
long long N, scalar_type
const A[]){
70 std::vector<scalar_type> B(M * N);
81 template<
typename IntA,
typename IntB>
82 inline size_t size_mult(IntA a, IntB b){
return static_cast<size_t>(a) *
static_cast<size_t>(b); }
91 template<
typename T,
typename I>
92 std::vector<typename std::remove_const<T>::type>
copyArray(T* x, I size){
93 return (x ==
nullptr) ? std::vector<typename std::remove_const<T>::type>() :
94 std::vector<
typename std::remove_const<T>::type>(x, x +
static_cast<size_t>(size));
106 size_t total_size = 0;
107 for(
auto const &v : vec) total_size += v.size();
108 std::vector<T> result;
109 result.reserve(total_size);
110 for(
auto const &v : vec) result.insert(result.end(), v.begin(), v.end());
130 Wrapper2D(
int stride_size, T *raw_data) : stride(static_cast<size_t>(stride_size)), data(raw_data){}
146 template<
bool condition>
147 using use_if =
typename std::enable_if<condition, void>::type;
153 template<
typename T,
typename U> T
exchange(T& x, U new_x){
155 x =
static_cast<T
>(new_x);
163 template<
typename T,
typename... Args>
165 return std::unique_ptr<T>(
new T(std::forward<Args>(args)...));
Wraps around a C-style of an array and mimics 2D data-structure.
Definition: tsgUtils.hpp:127
Wrapper2D(int stride_size, T *raw_data)
Wrap around raw_data with the given stride_size.
Definition: tsgUtils.hpp:130
T * getStrip(int i)
Return a pointer to the i-th strip.
Definition: tsgUtils.hpp:135
~Wrapper2D()
Default destructor, raw_data has to be deleted elsewhere.
Definition: tsgUtils.hpp:132
std::unique_ptr< T > make_unique(Args &&... args)
Equivalent to C++14 make_unique.
Definition: tsgUtils.hpp:164
std::vector< T > mergeVectors(std::vector< std::vector< T >> const &vec)
Takes a vector of vectors and returns a single contiguous vector.
Definition: tsgUtils.hpp:105
size_t size_mult(IntA a, IntB b)
Converts two integer-like variables to size_t and returns the product..
Definition: tsgUtils.hpp:82
std::vector< typename std::remove_const< T >::type > copyArray(T *x, I size)
Copies an array into a vector, returns empty vector if the input is nullpntr.
Definition: tsgUtils.hpp:92
T exchange(T &x, U new_x)
Equivalent to C++14 exchange, but works with simpler types (int, double, float*).
Definition: tsgUtils.hpp:153
typename std::enable_if< condition, void >::type use_if
Equivalent to C++14 enable_if_t<condition, void>
Definition: tsgUtils.hpp:147
void transpose(long long M, long long N, scalar_type const A[], scalar_type B[])
Constructs the transpose of an M by N matrix A in column major format, result is stored in B (impleme...
Encapsulates the Tasmanian Sparse Grid module.
Definition: TasmanianSparseGrid.hpp:68
Math functions and constants.