1 // SPDX-License-Identifier: Apache-2.0
2 //
3 // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
4 // Copyright 2008-2016 National ICT Australia (NICTA)
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 // ------------------------------------------------------------------------
17 
18 
19 //! \addtogroup fn_diagvec
20 //! @{
21 
22 
23 //! extract main diagonal from matrix
24 template<typename T1>
25 arma_warn_unused
26 arma_inline
27 const Op<T1, op_diagvec>
diagvec(const Base<typename T1::elem_type,T1> & X)28 diagvec(const Base<typename T1::elem_type,T1>& X)
29   {
30   arma_extra_debug_sigprint();
31 
32   return Op<T1, op_diagvec>(X.get_ref());
33   }
34 
35 
36 
37 //! extract arbitrary diagonal from matrix
38 template<typename T1>
39 arma_warn_unused
40 arma_inline
41 const Op<T1, op_diagvec2>
diagvec(const Base<typename T1::elem_type,T1> & X,const sword diag_id)42 diagvec(const Base<typename T1::elem_type,T1>& X, const sword diag_id)
43   {
44   arma_extra_debug_sigprint();
45 
46   return Op<T1, op_diagvec2>(X.get_ref(), ((diag_id < 0) ? -diag_id : diag_id), ((diag_id < 0) ? 1 : 0) );
47   }
48 
49 
50 
51 template<typename T1>
52 arma_warn_unused
53 arma_inline
54 const SpOp<T1, spop_diagvec>
diagvec(const SpBase<typename T1::elem_type,T1> & X,const sword diag_id=0)55 diagvec(const SpBase<typename T1::elem_type,T1>& X, const sword diag_id = 0)
56   {
57   arma_extra_debug_sigprint();
58 
59   return SpOp<T1, spop_diagvec>(X.get_ref(), ((diag_id < 0) ? -diag_id : diag_id), ((diag_id < 0) ? 1 : 0) );
60   }
61 
62 
63 
64 //! @}
65