Eigen  3.4.90 (git rev a4098ac676528a83cfb73d4d26ce1b42ec05f47c)
Random.h
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
15namespace Eigen {
16
17namespace internal {
18
19template<typename Scalar> struct scalar_random_op {
20 EIGEN_EMPTY_STRUCT_CTOR(scalar_random_op)
21 inline const Scalar operator() () const { return random<Scalar>(); }
22};
23
24template<typename Scalar>
25struct functor_traits<scalar_random_op<Scalar> >
26{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false, IsRepeatable = false }; };
27
28} // end namespace internal
29
56template<typename Derived>
57inline const typename DenseBase<Derived>::RandomReturnType
59{
60 return NullaryExpr(rows, cols, internal::scalar_random_op<Scalar>());
61}
62
87template<typename Derived>
88inline const typename DenseBase<Derived>::RandomReturnType
90{
91 return NullaryExpr(size, internal::scalar_random_op<Scalar>());
92}
93
113template<typename Derived>
114inline const typename DenseBase<Derived>::RandomReturnType
116{
117 return NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, internal::scalar_random_op<Scalar>());
118}
119
132template<typename Derived>
133EIGEN_DEVICE_FUNC inline Derived& DenseBase<Derived>::setRandom()
134{
135 return *this = Random(rows(), cols());
136}
137
151template<typename Derived>
152EIGEN_STRONG_INLINE Derived&
154{
155 resize(newSize);
156 return setRandom();
157}
158
174template<typename Derived>
175EIGEN_STRONG_INLINE Derived&
177{
178 resize(rows, cols);
179 return setRandom();
180}
181
193template<typename Derived>
194EIGEN_STRONG_INLINE Derived&
196{
197 return setRandom(rows(), cols);
198}
199
211template<typename Derived>
212EIGEN_STRONG_INLINE Derived&
214{
215 return setRandom(rows, cols());
216}
217
218} // end namespace Eigen
219
220#endif // EIGEN_RANDOM_H
Generic expression of a matrix where all coefficients are defined by a functor.
Definition: CwiseNullaryOp.h:63
Derived & setRandom()
Definition: Random.h:133
static const RandomReturnType Random()
Definition: Random.h:115
Derived & setRandom(Index size)
Definition: Random.h:153
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:59
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:41