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
13namespace Eigen {
14
15namespace internal {
16
17template<typename Scalar> struct scalar_random_op {
18 EIGEN_EMPTY_STRUCT_CTOR(scalar_random_op)
19 template<typename Index>
20 inline const Scalar operator() (Index, Index = 0) const { return random<Scalar>(); }
21};
22
23template<typename Scalar>
24struct functor_traits<scalar_random_op<Scalar> >
25{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false, IsRepeatable = false }; };
26
27} // end namespace internal
28
47template<typename Derived>
50{
51 return NullaryExpr(rows, cols, internal::scalar_random_op<Scalar>());
52}
53
74template<typename Derived>
77{
78 return NullaryExpr(size, internal::scalar_random_op<Scalar>());
79}
80
95template<typename Derived>
98{
99 return NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, internal::scalar_random_op<Scalar>());
100}
101
109template<typename Derived>
111{
112 return *this = Random(rows(), cols());
113}
114
124template<typename Derived>
125EIGEN_STRONG_INLINE Derived&
127{
128 resize(size);
129 return setRandom();
130}
131
142template<typename Derived>
143EIGEN_STRONG_INLINE Derived&
145{
146 resize(rows, cols);
147 return setRandom();
148}
149
150} // end namespace Eigen
151
152#endif // EIGEN_RANDOM_H
Generic expression of a matrix where all coefficients are defined by a functor.
Definition CwiseNullaryOp.h:51
static const CwiseNullaryOp< CustomNullaryOp, Derived > NullaryExpr(Index rows, Index cols, const CustomNullaryOp &func)
Definition CwiseNullaryOp.h:117
internal::traits< Derived >::Index Index
The type of indices.
Definition DenseBase.h:51
static const CwiseNullaryOp< internal::scalar_random_op< Scalar >, Derived > Random(Index rows, Index cols)
Definition Random.h:49
static const CwiseNullaryOp< internal::scalar_random_op< Scalar >, Derived > Random()
Definition Random.h:97
Derived & setRandom()
Definition Random.h:110
@ RowsAtCompileTime
Definition DenseBase.h:92
@ ColsAtCompileTime
Definition DenseBase.h:98
void resize(Index rows, Index cols)
Definition PlainObjectBase.h:219
Derived & setRandom(Index size)
Definition Random.h:126
Definition LDLT.h:18