make_alias.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_CORE_MATH_MAKE_ALIAS_HPP
14 #define MLPACK_CORE_MATH_MAKE_ALIAS_HPP
15 
16 namespace mlpack {
17 namespace math {
18 
23 template<typename ElemType>
24 arma::Mat<ElemType> MakeAlias(arma::Mat<ElemType>& input,
25  const bool strict = true)
26 {
27  // Use the advanced constructor.
28  return arma::Mat<ElemType>(input.memptr(), input.n_rows, input.n_cols, false,
29  strict);
30 }
31 
36 template<typename ElemType>
37 arma::Row<ElemType> MakeAlias(arma::Row<ElemType>& input,
38  const bool strict = true)
39 {
40  // Use the advanced constructor.
41  return arma::Row<ElemType>(input.memptr(), input.n_elem, false, strict);
42 }
43 
48 template<typename ElemType>
49 arma::Col<ElemType> MakeAlias(arma::Col<ElemType>& input,
50  const bool strict = true)
51 {
52  // Use the advanced constructor.
53  return arma::Col<ElemType>(input.memptr(), input.n_elem, false, strict);
54 }
55 
60 template<typename ElemType>
61 arma::SpMat<ElemType> MakeAlias(const arma::SpMat<ElemType>& input,
62  const bool /* strict */ = true)
63 {
64  // Make a copy...
65  return arma::SpMat<ElemType>(input);
66 }
67 
72 template<typename ElemType>
73 arma::SpRow<ElemType> MakeAlias(const arma::SpRow<ElemType>& input,
74  const bool /* strict */ = true)
75 {
76  // Make a copy...
77  return arma::SpRow<ElemType>(input);
78 }
79 
84 template<typename ElemType>
85 arma::SpCol<ElemType> MakeAlias(const arma::SpCol<ElemType>& input,
86  const bool /* strict */ = true)
87 {
88  // Make a copy...
89  return arma::SpCol<ElemType>(input);
90 }
91 
96 template<typename ElemType>
97 void ClearAlias(arma::Mat<ElemType>& mat)
98 {
99  if (mat.mem_state >= 1)
100  mat.reset();
101 }
102 
107 template<typename ElemType>
108 void ClearAlias(arma::SpMat<ElemType>& /* mat */)
109 {
110  // Nothing to do.
111 }
112 
113 
114 } // namespace math
115 } // namespace mlpack
116 
117 #endif
.hpp
Definition: add_to_po.hpp:21
void ClearAlias(arma::Mat< ElemType > &mat)
Clear an alias so that no data is overwritten.
Definition: make_alias.hpp:97
arma::Mat< ElemType > MakeAlias(arma::Mat< ElemType > &input, const bool strict=true)
Make an alias of a dense matrix.
Definition: make_alias.hpp:24