arma_util.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_BINDINGS_GO_GONUM_ARMA_UTIL_HPP
13 #define MLPACK_BINDINGS_GO_GONUM_ARMA_UTIL_HPP
14 
15 // Include Armadillo via mlpack.
16 #include <mlpack/core/util/cli.hpp>
17 #include <mlpack/core.hpp>
18 
19 namespace mlpack {
20 
24 template<typename T>
25 void SetMemState(T& t, int state)
26 {
27  const_cast<arma::uhword&>(t.mem_state) = state;
28 }
29 
30 
34 template<typename T>
35 size_t GetMemState(T& t)
36 {
37  // Fake the memory state if we are using preallocated memory---since we will
38  // end up copying that memory, NumPy can own it.
39  if (t.mem && t.n_elem <= arma::arma_config::mat_prealloc)
40  return 0;
41 
42  return (size_t) t.mem_state;
43 }
44 
50 template<typename T>
51 inline typename T::elem_type* GetMemory(T& m)
52 {
53  if (m.mem && m.n_elem <= arma::arma_config::mat_prealloc)
54  {
55  // We need to allocate new memory.
56  typename T::elem_type* mem =
57  arma::memory::acquire<typename T::elem_type>(m.n_elem);
58  arma::arrayops::copy(mem, m.memptr(), m.n_elem);
59  return mem;
60  }
61  else
62  {
63  arma::access::rw(m.mem_state) = 1;
64  return m.memptr();
65  }
66 }
67 
68 
69 } // namespace mlpack
70 
71 #endif
strip_type.hpp
Definition: add_to_po.hpp:21
void SetMemState(T &t, int state)
Set the memory state of the given Armadillo object.
Definition: arma_util.hpp:25
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:51
Include all of the base components required to write mlpack methods, and the main mlpack Doxygen docu...
size_t GetMemState(T &t)
Get the memory state of the given Armadillo object.
Definition: arma_util.hpp:35