mlpack  3.4.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
arma_util.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_BINDINGS_PYTHON_CYTHON_ARMA_UTIL_HPP
13 #define MLPACK_BINDINGS_PYTHON_CYTHON_ARMA_UTIL_HPP
14 
15 // Include Armadillo via mlpack.
16 #include <mlpack/core.hpp>
17 
21 template<typename T>
22 void SetMemState(T& t, int state)
23 {
24  const_cast<arma::uhword&>(t.mem_state) = state;
25 }
26 
30 template<typename T>
31 size_t GetMemState(T& t)
32 {
33  // Fake the memory state if we are using preallocated memory---since we will
34  // end up copying that memory, NumPy can own it.
35  if (t.mem && t.n_elem <= arma::arma_config::mat_prealloc)
36  return 0;
37 
38  return (size_t) t.mem_state;
39 }
40 
46 template<typename T>
47 inline typename T::elem_type* GetMemory(T& m)
48 {
49  if (m.mem && m.n_elem <= arma::arma_config::mat_prealloc)
50  {
51  // We need to allocate new memory.
52  typename T::elem_type* mem =
53  arma::memory::acquire<typename T::elem_type>(m.n_elem);
54  arma::arrayops::copy(mem, m.memptr(), m.n_elem);
55  return mem;
56  }
57  else
58  {
59  return m.memptr();
60  }
61 }
62 
63 #endif
void SetMemState(T &t, int state)
Set the memory state of the given Armadillo object.
Definition: arma_util.hpp:22
T::elem_type * GetMemory(T &m)
Return the matrix&#39;s allocated memory pointer, unless the matrix is using its internal preallocated me...
Definition: arma_util.hpp:47
size_t GetMemState(T &t)
Get the memory state of the given Armadillo object.
Definition: arma_util.hpp:31
Include all of the base components required to write mlpack methods, and the main mlpack Doxygen docu...