make_alias.hpp
Go to the documentation of this file.
1 
9 #ifndef MLPACK_METHODS_ANN_MAKE_ALIAS_HPP
10 #define MLPACK_METHODS_ANN_MAKE_ALIAS_HPP
11 
12 #include <mlpack/prereqs.hpp>
13 
14 namespace mlpack {
15 namespace ann {
16 
21 template<typename MatType>
22 void MakeAlias(MatType& m,
23  typename MatType::elem_type* newMem,
24  const size_t numRows,
25  const size_t numCols)
26 {
27  // We use placement new to reinitialize the object, since the copy and move
28  // assignment operators in Armadillo will end up copying memory instead of
29  // making an alias.
30  m.~MatType();
31  new (&m) MatType(newMem, numRows, numCols, false, true);
32 }
33 
38 template<typename CubeType>
39 void MakeAlias(CubeType& c,
40  typename CubeType::elem_type* newMem,
41  const size_t numRows,
42  const size_t numCols,
43  const size_t numSlices)
44 {
45  // We use placement new to reinitialize the object, since the copy and move
46  // assignment operators in Armadillo will end up copying memory instead of
47  // making an alias.
48  c.~CubeType();
49  new (&c) CubeType(newMem, numRows, numCols, numSlices, false, true);
50 }
51 
52 } // namespace ann
53 } // namespace mlpack
54 
55 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes, Armadillo, cereal, and a few basic mlpa...
void MakeAlias(MatType &m, typename MatType::elem_type *newMem, const size_t numRows, const size_t numCols)
Reconstruct m as an alias around the memory newMem, with size numRows x numCols.
Definition: make_alias.hpp:22