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::Cube<ElemType> MakeAlias(arma::Cube<ElemType>& input,
25  const bool strict = true)
26 {
27  // Use the advanced constructor.
28  return arma::Cube<ElemType>(input.memptr(), input.n_rows, input.n_cols,
29  input.n_slices, false, strict);
30 }
31 
36 template<typename ElemType>
37 arma::Mat<ElemType> MakeAlias(arma::Mat<ElemType>& input,
38  const bool strict = true)
39 {
40  // Use the advanced constructor.
41  return arma::Mat<ElemType>(input.memptr(), input.n_rows, input.n_cols, false,
42  strict);
43 }
44 
49 template<typename ElemType>
50 arma::Row<ElemType> MakeAlias(arma::Row<ElemType>& input,
51  const bool strict = true)
52 {
53  // Use the advanced constructor.
54  return arma::Row<ElemType>(input.memptr(), input.n_elem, false, strict);
55 }
56 
61 template<typename ElemType>
62 arma::Col<ElemType> MakeAlias(arma::Col<ElemType>& input,
63  const bool strict = true)
64 {
65  // Use the advanced constructor.
66  return arma::Col<ElemType>(input.memptr(), input.n_elem, false, strict);
67 }
68 
73 template<typename ElemType>
74 arma::SpMat<ElemType> MakeAlias(const arma::SpMat<ElemType>& input,
75  const bool /* strict */ = true)
76 {
77  // Make a copy...
78  return arma::SpMat<ElemType>(input);
79 }
80 
85 template<typename ElemType>
86 arma::SpRow<ElemType> MakeAlias(const arma::SpRow<ElemType>& input,
87  const bool /* strict */ = true)
88 {
89  // Make a copy...
90  return arma::SpRow<ElemType>(input);
91 }
92 
97 template<typename ElemType>
98 arma::SpCol<ElemType> MakeAlias(const arma::SpCol<ElemType>& input,
99  const bool /* strict */ = true)
100 {
101  // Make a copy...
102  return arma::SpCol<ElemType>(input);
103 }
104 
109 template<typename ElemType>
110 void ClearAlias(arma::Mat<ElemType>& mat)
111 {
112  if (mat.mem_state >= 1)
113  mat.reset();
114 }
115 
120 template<typename ElemType>
121 void ClearAlias(arma::SpMat<ElemType>& /* mat */)
122 {
123  // Nothing to do.
124 }
125 
126 
127 } // namespace math
128 } // namespace mlpack
129 
130 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
void ClearAlias(arma::Mat< ElemType > &mat)
Clear an alias so that no data is overwritten.
Definition: make_alias.hpp:110
arma::Cube< ElemType > MakeAlias(arma::Cube< ElemType > &input, const bool strict=true)
Make an alias of a dense cube.
Definition: make_alias.hpp:24