Random.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
5 //
6 // Eigen is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 3 of the License, or (at your option) any later version.
10 //
11 // Alternatively, you can redistribute it and/or
12 // modify it under the terms of the GNU General Public License as
13 // published by the Free Software Foundation; either version 2 of
14 // the License, or (at your option) any later version.
15 //
16 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
17 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License and a copy of the GNU General Public License along with
23 // Eigen. If not, see <http://www.gnu.org/licenses/>.
24 
25 #ifndef EIGEN_RANDOM_H
26 #define EIGEN_RANDOM_H
27 
28 namespace Eigen {
29 
30 namespace internal {
31 
32 template<typename Scalar> struct scalar_random_op {
33  EIGEN_EMPTY_STRUCT_CTOR(scalar_random_op)
34  template<typename Index>
35  inline const Scalar operator() (Index, Index = 0) const { return random<Scalar>(); }
36 };
37 
38 template<typename Scalar>
39 struct functor_traits<scalar_random_op<Scalar> >
40 { enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false, IsRepeatable = false }; };
41 
42 } // end namespace internal
43 
62 template<typename Derived>
63 inline const CwiseNullaryOp<internal::scalar_random_op<typename internal::traits<Derived>::Scalar>, Derived>
65 {
66  return NullaryExpr(rows, cols, internal::scalar_random_op<Scalar>());
67 }
68 
89 template<typename Derived>
92 {
93  return NullaryExpr(size, internal::scalar_random_op<Scalar>());
94 }
95 
110 template<typename Derived>
113 {
114  return NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, internal::scalar_random_op<Scalar>());
115 }
116 
124 template<typename Derived>
126 {
127  return *this = Random(rows(), cols());
128 }
129 
139 template<typename Derived>
140 EIGEN_STRONG_INLINE Derived&
142 {
143  resize(size);
144  return setRandom();
145 }
146 
157 template<typename Derived>
158 EIGEN_STRONG_INLINE Derived&
160 {
161  resize(rows, cols);
162  return setRandom();
163 }
164 
165 } // end namespace Eigen
166 
167 #endif // EIGEN_RANDOM_H