MOAB
4.9.3pre
|
00001 // This file is part of Eigen, a lightweight C++ template library 00002 // for linear algebra. 00003 // 00004 // Copyright (C) 2008 Gael Guennebaud <[email protected]> 00005 // 00006 // This Source Code Form is subject to the terms of the Mozilla 00007 // Public License v. 2.0. If a copy of the MPL was not distributed 00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 00009 00010 #ifndef EIGEN_RANDOM_H 00011 #define EIGEN_RANDOM_H 00012 00013 namespace Eigen { 00014 00015 namespace internal { 00016 00017 template<typename Scalar> struct scalar_random_op { 00018 EIGEN_EMPTY_STRUCT_CTOR(scalar_random_op) 00019 template<typename Index> 00020 inline const Scalar operator() (Index, Index = 0) const { return random<Scalar>(); } 00021 }; 00022 00023 template<typename Scalar> 00024 struct functor_traits<scalar_random_op<Scalar> > 00025 { enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false, IsRepeatable = false }; }; 00026 00027 } // end namespace internal 00028 00055 template<typename Derived> 00056 inline const typename DenseBase<Derived>::RandomReturnType 00057 DenseBase<Derived>::Random(Index rows, Index cols) 00058 { 00059 return NullaryExpr(rows, cols, internal::scalar_random_op<Scalar>()); 00060 } 00061 00086 template<typename Derived> 00087 inline const typename DenseBase<Derived>::RandomReturnType 00088 DenseBase<Derived>::Random(Index size) 00089 { 00090 return NullaryExpr(size, internal::scalar_random_op<Scalar>()); 00091 } 00092 00112 template<typename Derived> 00113 inline const typename DenseBase<Derived>::RandomReturnType 00114 DenseBase<Derived>::Random() 00115 { 00116 return NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, internal::scalar_random_op<Scalar>()); 00117 } 00118 00131 template<typename Derived> 00132 inline Derived& DenseBase<Derived>::setRandom() 00133 { 00134 return *this = Random(rows(), cols()); 00135 } 00136 00150 template<typename Derived> 00151 EIGEN_STRONG_INLINE Derived& 00152 PlainObjectBase<Derived>::setRandom(Index newSize) 00153 { 00154 resize(newSize); 00155 return setRandom(); 00156 } 00157 00173 template<typename Derived> 00174 EIGEN_STRONG_INLINE Derived& 00175 PlainObjectBase<Derived>::setRandom(Index rows, Index cols) 00176 { 00177 resize(rows, cols); 00178 return setRandom(); 00179 } 00180 00181 } // end namespace Eigen 00182 00183 #endif // EIGEN_RANDOM_H