Eigen  5.0.1
 
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// SPDX-License-Identifier: MPL-2.0
10
11#ifndef EIGEN_RANDOM_H
12#define EIGEN_RANDOM_H
13
14// IWYU pragma: private
15#include "./InternalHeaderCheck.h"
16
17namespace Eigen {
18
19namespace internal {
20
21template <typename Scalar>
22struct scalar_random_op {
23 inline Scalar operator()() const { return random<Scalar>(); }
24};
25
26template <typename Scalar>
27struct functor_traits<scalar_random_op<Scalar> > {
28 enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false, IsRepeatable = false };
29};
30
31} // end namespace internal
32
59template <typename Derived>
60inline const typename DenseBase<Derived>::RandomReturnType DenseBase<Derived>::Random(Index rows, Index cols) {
61 return NullaryExpr(rows, cols, internal::scalar_random_op<Scalar>());
62}
63
88template <typename Derived>
89inline const typename DenseBase<Derived>::RandomReturnType DenseBase<Derived>::Random(Index size) {
90 return NullaryExpr(size, internal::scalar_random_op<Scalar>());
91}
92
112template <typename Derived>
113inline const typename DenseBase<Derived>::RandomReturnType DenseBase<Derived>::Random() {
114 return NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, internal::scalar_random_op<Scalar>());
115}
116
129template <typename Derived>
130EIGEN_DEVICE_FUNC inline Derived& DenseBase<Derived>::setRandom() {
131 return *this = Random(rows(), cols());
132}
133
147template <typename Derived>
148EIGEN_STRONG_INLINE Derived& PlainObjectBase<Derived>::setRandom(Index newSize) {
149 resize(newSize);
150 return setRandom();
151}
152
168template <typename Derived>
169EIGEN_STRONG_INLINE Derived& PlainObjectBase<Derived>::setRandom(Index rows, Index cols) {
170 resize(rows, cols);
171 return setRandom();
172}
173
185template <typename Derived>
186EIGEN_STRONG_INLINE Derived& PlainObjectBase<Derived>::setRandom(NoChange_t, Index cols) {
187 return setRandom(rows(), cols);
188}
189
201template <typename Derived>
202EIGEN_STRONG_INLINE Derived& PlainObjectBase<Derived>::setRandom(Index rows, NoChange_t) {
203 return setRandom(rows, cols());
204}
205
206} // end namespace Eigen
207
208#endif // EIGEN_RANDOM_H
static const CwiseNullaryOp< CustomNullaryOp, PlainObject > NullaryExpr(Index rows, Index cols, const CustomNullaryOp &func)
Definition CwiseNullaryOp.h:113
@ ColsAtCompileTime
Definition DenseBase.h:103
@ RowsAtCompileTime
Definition DenseBase.h:97
Derived & setRandom()
Definition Random.h:130
static const RandomReturnType Random()
Definition Random.h:113
static const RandomReturnType Random(Index rows, Index cols)
Definition Random.h:60
Derived & setRandom(Index size)
Definition Random.h:148
constexpr void resize(Index rows, Index cols)
Definition PlainObjectBase.h:282