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 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_RANDOM_H
11 #define EIGEN_RANDOM_H
12 
13 #include "./InternalHeaderCheck.h"
14 
15 namespace Eigen {
16 
17 namespace internal {
18 
19 template<typename Scalar> struct scalar_random_op {
20  inline const Scalar operator() () const { return random<Scalar>(); }
21 };
22 
23 template<typename Scalar>
24 struct functor_traits<scalar_random_op<Scalar> >
25 { enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false, IsRepeatable = false }; };
26 
27 } // end namespace internal
28 
55 template<typename Derived>
56 inline const typename DenseBase<Derived>::RandomReturnType
58 {
59  return NullaryExpr(rows, cols, internal::scalar_random_op<Scalar>());
60 }
61 
86 template<typename Derived>
87 inline const typename DenseBase<Derived>::RandomReturnType
89 {
90  return NullaryExpr(size, internal::scalar_random_op<Scalar>());
91 }
92 
112 template<typename Derived>
113 inline const typename DenseBase<Derived>::RandomReturnType
115 {
116  return NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, internal::scalar_random_op<Scalar>());
117 }
118 
131 template<typename Derived>
133 {
134  return *this = Random(rows(), cols());
135 }
136 
150 template<typename Derived>
151 EIGEN_STRONG_INLINE Derived&
153 {
154  resize(newSize);
155  return setRandom();
156 }
157 
173 template<typename Derived>
174 EIGEN_STRONG_INLINE Derived&
176 {
177  resize(rows, cols);
178  return setRandom();
179 }
180 
192 template<typename Derived>
193 EIGEN_STRONG_INLINE Derived&
195 {
196  return setRandom(rows(), cols);
197 }
198 
210 template<typename Derived>
211 EIGEN_STRONG_INLINE Derived&
213 {
214  return setRandom(rows, cols());
215 }
216 
217 } // end namespace Eigen
218 
219 #endif // EIGEN_RANDOM_H
A setRandom()
IndexedView_or_Block operator()(const RowIndices &rowIndices, const ColIndices &colIndices)
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:883
v resize(3)
Generic expression of a matrix where all coefficients are defined by a functor.
CwiseNullaryOp< internal::scalar_random_op< Scalar >, PlainObject > RandomReturnType
Definition: DenseBase.h:565
Derived & setRandom()
Definition: Random.h:132
static const RandomReturnType Random()
Definition: Random.h:114
Derived & setRandom(Index size)
Definition: Random.h:152
: InteropHeaders
Definition: Core:139
NoChange_t
Definition: Constants.h:362
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:41