Random.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 //
00006 // Eigen is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 3 of the License, or (at your option) any later version.
00010 //
00011 // Alternatively, you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License as
00013 // published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00017 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License and a copy of the GNU General Public License along with
00023 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00024 
00025 #ifndef EIGEN_RANDOM_H
00026 #define EIGEN_RANDOM_H
00027 
00028 namespace Eigen { 
00029 
00030 namespace internal {
00031 
00032 template<typename Scalar> struct scalar_random_op {
00033   EIGEN_EMPTY_STRUCT_CTOR(scalar_random_op)
00034   template<typename Index>
00035   inline const Scalar operator() (Index, Index = 0) const { return random<Scalar>(); }
00036 };
00037 
00038 template<typename Scalar>
00039 struct functor_traits<scalar_random_op<Scalar> >
00040 { enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false, IsRepeatable = false }; };
00041 
00042 } // end namespace internal
00043 
00062 template<typename Derived>
00063 inline const CwiseNullaryOp<internal::scalar_random_op<typename internal::traits<Derived>::Scalar>, Derived>
00064 DenseBase<Derived>::Random(Index rows, Index cols)
00065 {
00066   return NullaryExpr(rows, cols, internal::scalar_random_op<Scalar>());
00067 }
00068 
00089 template<typename Derived>
00090 inline const CwiseNullaryOp<internal::scalar_random_op<typename internal::traits<Derived>::Scalar>, Derived>
00091 DenseBase<Derived>::Random(Index size)
00092 {
00093   return NullaryExpr(size, internal::scalar_random_op<Scalar>());
00094 }
00095 
00110 template<typename Derived>
00111 inline const CwiseNullaryOp<internal::scalar_random_op<typename internal::traits<Derived>::Scalar>, Derived>
00112 DenseBase<Derived>::Random()
00113 {
00114   return NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, internal::scalar_random_op<Scalar>());
00115 }
00116 
00124 template<typename Derived>
00125 inline Derived& DenseBase<Derived>::setRandom()
00126 {
00127   return *this = Random(rows(), cols());
00128 }
00129 
00139 template<typename Derived>
00140 EIGEN_STRONG_INLINE Derived&
00141 PlainObjectBase<Derived>::setRandom(Index size)
00142 {
00143   resize(size);
00144   return setRandom();
00145 }
00146 
00157 template<typename Derived>
00158 EIGEN_STRONG_INLINE Derived&
00159 PlainObjectBase<Derived>::setRandom(Index rows, Index cols)
00160 {
00161   resize(rows, cols);
00162   return setRandom();
00163 }
00164 
00165 } // end namespace Eigen
00166 
00167 #endif // EIGEN_RANDOM_H