$darkmode
Eigen  5.0.1-dev
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 // IWYU pragma: private
14 #include "./InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
18 namespace internal {
19 
20 template <typename Scalar>
21 struct scalar_random_op {
22  inline const Scalar operator()() const { return random<Scalar>(); }
23 };
24 
25 template <typename Scalar>
26 struct functor_traits<scalar_random_op<Scalar> > {
27  enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false, IsRepeatable = false };
28 };
29 
30 } // end namespace internal
31 
58 template <typename Derived>
60  return NullaryExpr(rows, cols, internal::scalar_random_op<Scalar>());
61 }
62 
87 template <typename Derived>
89  return NullaryExpr(size, internal::scalar_random_op<Scalar>());
90 }
91 
111 template <typename Derived>
113  return NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, internal::scalar_random_op<Scalar>());
114 }
115 
128 template <typename Derived>
129 EIGEN_DEVICE_FUNC inline Derived& DenseBase<Derived>::setRandom() {
130  return *this = Random(rows(), cols());
131 }
132 
146 template <typename Derived>
147 EIGEN_STRONG_INLINE Derived& PlainObjectBase<Derived>::setRandom(Index newSize) {
148  resize(newSize);
149  return setRandom();
150 }
151 
167 template <typename Derived>
168 EIGEN_STRONG_INLINE Derived& PlainObjectBase<Derived>::setRandom(Index rows, Index cols) {
169  resize(rows, cols);
170  return setRandom();
171 }
172 
184 template <typename Derived>
185 EIGEN_STRONG_INLINE Derived& PlainObjectBase<Derived>::setRandom(NoChange_t, Index cols) {
186  return setRandom(rows(), cols);
187 }
188 
200 template <typename Derived>
201 EIGEN_STRONG_INLINE Derived& PlainObjectBase<Derived>::setRandom(Index rows, NoChange_t) {
202  return setRandom(rows, cols());
203 }
204 
205 } // end namespace Eigen
206 
207 #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:129
Derived & setRandom(Index size)
Definition: Random.h:147
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:43
static const RandomReturnType Random()
Definition: Random.h:112
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82