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_ones
20 //! @{
21
22
23
24 arma_warn_unused
25 arma_inline
26 const Gen<vec, gen_ones>
ones(const uword n_elem)27 ones(const uword n_elem)
28 {
29 arma_extra_debug_sigprint();
30
31 return Gen<vec, gen_ones>(n_elem, 1);
32 }
33
34
35
36 template<typename obj_type>
37 arma_warn_unused
38 arma_inline
39 const Gen<obj_type, gen_ones>
ones(const uword n_elem,const arma_empty_class junk1=arma_empty_class (),const typename arma_Mat_Col_Row_only<obj_type>::result * junk2=nullptr)40 ones(const uword n_elem, const arma_empty_class junk1 = arma_empty_class(), const typename arma_Mat_Col_Row_only<obj_type>::result* junk2 = nullptr)
41 {
42 arma_extra_debug_sigprint();
43 arma_ignore(junk1);
44 arma_ignore(junk2);
45
46 if(is_Row<obj_type>::value)
47 {
48 return Gen<obj_type, gen_ones>(1, n_elem);
49 }
50 else
51 {
52 return Gen<obj_type, gen_ones>(n_elem, 1);
53 }
54 }
55
56
57
58 arma_warn_unused
59 arma_inline
60 const Gen<mat, gen_ones>
ones(const uword n_rows,const uword n_cols)61 ones(const uword n_rows, const uword n_cols)
62 {
63 arma_extra_debug_sigprint();
64
65 return Gen<mat, gen_ones>(n_rows, n_cols);
66 }
67
68
69
70 arma_warn_unused
71 arma_inline
72 const Gen<mat, gen_ones>
ones(const SizeMat & s)73 ones(const SizeMat& s)
74 {
75 arma_extra_debug_sigprint();
76
77 return Gen<mat, gen_ones>(s.n_rows, s.n_cols);
78 }
79
80
81
82 template<typename obj_type>
83 arma_warn_unused
84 inline
85 const Gen<obj_type, gen_ones>
ones(const uword n_rows,const uword n_cols,const typename arma_Mat_Col_Row_only<obj_type>::result * junk=nullptr)86 ones(const uword n_rows, const uword n_cols, const typename arma_Mat_Col_Row_only<obj_type>::result* junk = nullptr)
87 {
88 arma_extra_debug_sigprint();
89 arma_ignore(junk);
90
91 if(is_Col<obj_type>::value)
92 {
93 arma_debug_check( (n_cols != 1), "ones(): incompatible size" );
94 }
95 else
96 if(is_Row<obj_type>::value)
97 {
98 arma_debug_check( (n_rows != 1), "ones(): incompatible size" );
99 }
100
101 return Gen<obj_type, gen_ones>(n_rows, n_cols);
102 }
103
104
105
106 template<typename obj_type>
107 arma_warn_unused
108 inline
109 const Gen<obj_type, gen_ones>
ones(const SizeMat & s,const typename arma_Mat_Col_Row_only<obj_type>::result * junk=nullptr)110 ones(const SizeMat& s, const typename arma_Mat_Col_Row_only<obj_type>::result* junk = nullptr)
111 {
112 arma_extra_debug_sigprint();
113 arma_ignore(junk);
114
115 return ones<obj_type>(s.n_rows, s.n_cols);
116 }
117
118
119
120 arma_warn_unused
121 arma_inline
122 const GenCube<cube::elem_type, gen_ones>
ones(const uword n_rows,const uword n_cols,const uword n_slices)123 ones(const uword n_rows, const uword n_cols, const uword n_slices)
124 {
125 arma_extra_debug_sigprint();
126
127 return GenCube<cube::elem_type, gen_ones>(n_rows, n_cols, n_slices);
128 }
129
130
131
132 arma_warn_unused
133 arma_inline
134 const GenCube<cube::elem_type, gen_ones>
ones(const SizeCube & s)135 ones(const SizeCube& s)
136 {
137 arma_extra_debug_sigprint();
138
139 return GenCube<cube::elem_type, gen_ones>(s.n_rows, s.n_cols, s.n_slices);
140 }
141
142
143
144 template<typename cube_type>
145 arma_warn_unused
146 arma_inline
147 const GenCube<typename cube_type::elem_type, gen_ones>
ones(const uword n_rows,const uword n_cols,const uword n_slices,const typename arma_Cube_only<cube_type>::result * junk=nullptr)148 ones(const uword n_rows, const uword n_cols, const uword n_slices, const typename arma_Cube_only<cube_type>::result* junk = nullptr)
149 {
150 arma_extra_debug_sigprint();
151 arma_ignore(junk);
152
153 return GenCube<typename cube_type::elem_type, gen_ones>(n_rows, n_cols, n_slices);
154 }
155
156
157
158 template<typename cube_type>
159 arma_warn_unused
160 arma_inline
161 const GenCube<typename cube_type::elem_type, gen_ones>
ones(const SizeCube & s,const typename arma_Cube_only<cube_type>::result * junk=nullptr)162 ones(const SizeCube& s, const typename arma_Cube_only<cube_type>::result* junk = nullptr)
163 {
164 arma_extra_debug_sigprint();
165 arma_ignore(junk);
166
167 return GenCube<typename cube_type::elem_type, gen_ones>(s.n_rows, s.n_cols, s.n_slices);
168 }
169
170
171
172 //! @}
173