mlpack 3.4.2
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
16namespace mlpack {
17namespace math {
18
23template<typename ElemType>
24arma::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
36template<typename ElemType>
37arma::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
49template<typename ElemType>
50arma::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
61template<typename ElemType>
62arma::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
73template<typename ElemType>
74arma::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
85template<typename ElemType>
86arma::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
97template<typename ElemType>
98arma::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
109template<typename ElemType>
110void ClearAlias(arma::Mat<ElemType>& mat)
111{
112 if (mat.mem_state >= 1)
113 mat.reset();
114}
115
120template<typename ElemType>
121void ClearAlias(arma::SpMat<ElemType>& /* mat */)
122{
123 // Nothing to do.
124}
125
126
127} // namespace math
128} // namespace mlpack
129
130#endif
arma::Cube< ElemType > MakeAlias(arma::Cube< ElemType > &input, const bool strict=true)
Make an alias of a dense cube.
Definition: make_alias.hpp:24
void ClearAlias(arma::Mat< ElemType > &mat)
Clear an alias so that no data is overwritten.
Definition: make_alias.hpp:110
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1