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_normalise
20 //! @{
21
22
23
24 template<typename T1>
25 arma_warn_unused
26 inline
27 typename
28 enable_if2
29 <
30 is_arma_type<T1>::value && resolves_to_vector<T1>::yes,
31 const Op<T1, op_normalise_vec>
32 >::result
normalise(const T1 & X,const uword p=uword (2),const arma_empty_class junk1=arma_empty_class (),const typename arma_real_or_cx_only<typename T1::elem_type>::result * junk2=nullptr)33 normalise
34 (
35 const T1& X,
36 const uword p = uword(2),
37 const arma_empty_class junk1 = arma_empty_class(),
38 const typename arma_real_or_cx_only<typename T1::elem_type>::result* junk2 = nullptr
39 )
40 {
41 arma_extra_debug_sigprint();
42 arma_ignore(junk1);
43 arma_ignore(junk2);
44
45 return Op<T1, op_normalise_vec>(X, p, 0);
46 }
47
48
49
50 template<typename T1>
51 arma_warn_unused
52 inline
53 typename
54 enable_if2
55 <
56 is_arma_type<T1>::value && resolves_to_vector<T1>::no,
57 const Op<T1, op_normalise_mat>
58 >::result
normalise(const T1 & X,const uword p=uword (2),const uword dim=0,const typename arma_real_or_cx_only<typename T1::elem_type>::result * junk=nullptr)59 normalise
60 (
61 const T1& X,
62 const uword p = uword(2),
63 const uword dim = 0,
64 const typename arma_real_or_cx_only<typename T1::elem_type>::result* junk = nullptr
65 )
66 {
67 arma_extra_debug_sigprint();
68 arma_ignore(junk);
69
70 return Op<T1, op_normalise_mat>(X, p, dim);
71 }
72
73
74
75 template<typename T1>
76 arma_warn_unused
77 inline
78 const SpOp<T1, spop_normalise>
normalise(const SpBase<typename T1::elem_type,T1> & expr,const uword p=uword (2),const uword dim=0,const typename arma_real_or_cx_only<typename T1::elem_type>::result * junk=nullptr)79 normalise
80 (
81 const SpBase<typename T1::elem_type, T1>& expr,
82 const uword p = uword(2),
83 const uword dim = 0,
84 const typename arma_real_or_cx_only<typename T1::elem_type>::result* junk = nullptr
85 )
86 {
87 arma_extra_debug_sigprint();
88 arma_ignore(junk);
89
90 return SpOp<T1, spop_normalise>(expr.get_ref(), p, dim);
91 }
92
93
94
95 //! for compatibility purposes: allows compiling user code designed for earlier versions of Armadillo
96 template<typename T>
97 arma_warn_unused
98 arma_inline
99 typename
100 enable_if2
101 <
102 is_supported_blas_type<T>::value,
103 Col<T>
104 >::result
normalise(const T & val)105 normalise(const T& val)
106 {
107 Col<T> out(1, arma_nozeros_indicator());
108
109 out[0] = (val != T(0)) ? T(val / (std::abs)(val)) : T(val);
110
111 return out;
112 }
113
114
115
116 //! @}
117