Eigen  3.4.90 (git rev 9589cc4e7fd8e4538bedef80dd36c7738977a8be)
 
Loading...
Searching...
No Matches
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
16namespace Eigen {
17
18namespace internal {
19
20template <typename Scalar>
21struct scalar_random_op {
22 inline const Scalar operator()() const { return random<Scalar>(); }
23};
24
25template <typename Scalar>
26struct functor_traits<scalar_random_op<Scalar> > {
27 enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false, IsRepeatable = false };
28};
29
30} // end namespace internal
31
58template <typename Derived>
59inline const typename DenseBase<Derived>::RandomReturnType DenseBase<Derived>::Random(Index rows, Index cols) {
60 return NullaryExpr(rows, cols, internal::scalar_random_op<Scalar>());
61}
62
87template <typename Derived>
88inline const typename DenseBase<Derived>::RandomReturnType DenseBase<Derived>::Random(Index size) {
89 return NullaryExpr(size, internal::scalar_random_op<Scalar>());
90}
91
111template <typename Derived>
112inline const typename DenseBase<Derived>::RandomReturnType DenseBase<Derived>::Random() {
113 return NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, internal::scalar_random_op<Scalar>());
114}
115
128template <typename Derived>
129EIGEN_DEVICE_FUNC inline Derived& DenseBase<Derived>::setRandom() {
130 return *this = Random(rows(), cols());
131}
132
146template <typename Derived>
147EIGEN_STRONG_INLINE Derived& PlainObjectBase<Derived>::setRandom(Index newSize) {
148 resize(newSize);
149 return setRandom();
150}
151
167template <typename Derived>
168EIGEN_STRONG_INLINE Derived& PlainObjectBase<Derived>::setRandom(Index rows, Index cols) {
169 resize(rows, cols);
170 return setRandom();
171}
172
184template <typename Derived>
185EIGEN_STRONG_INLINE Derived& PlainObjectBase<Derived>::setRandom(NoChange_t, Index cols) {
186 return setRandom(rows(), cols);
187}
188
200template <typename Derived>
201EIGEN_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
static const CwiseNullaryOp< CustomNullaryOp, PlainObject > NullaryExpr(Index rows, Index cols, const CustomNullaryOp &func)
Definition CwiseNullaryOp.h:112
@ ColsAtCompileTime
Definition DenseBase.h:102
@ RowsAtCompileTime
Definition DenseBase.h:96
Derived & setRandom()
Definition Random.h:129
static const RandomReturnType Random()
Definition Random.h:112
static const RandomReturnType Random(Index rows, Index cols)
Definition Random.h:59
Derived & setRandom(Index size)
Definition Random.h:147
constexpr void resize(Index rows, Index cols)
Definition PlainObjectBase.h:268
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:82