// @HEADER // ***************************************************************************** // Rapid Optimization Library (ROL) Package // // Copyright 2014 NTESS and the ROL contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #pragma once #ifndef RANDOM_MATRIX_HPP #define RANDOM_MATRIX_HPP #include #include "Teuchos_SerialDenseMatrix.hpp" #include "ROL_Teuchos_LinearOperator.hpp" template ROL::Ptr> random_matrix( Ordinal rows, Ordinal cols, Distribution dist, Generator gen ) { auto M = ROL::makePtr>(rows,cols); for(Ordinal i=0; i ROL::Ptr> randn_matrix( Ordinal rows, Ordinal cols, Real mu=0.0, Real sigma=1.0 ) { std::random_device rd; std::mt19937 gen(rd()); std::normal_distribution dist{mu,sigma}; return random_matrix(rows,cols,dist,gen); } template ROL::Ptr> create_random_operator( Ordinal rows, Ordinal cols ) { auto A = randn_matrix(rows,cols); return ROL::makePtr>(A); } template ROL::Ptr> create_random_vector( Ordinal n ) { ROL::Ptr> v = ROL::makePtr>(n); v->randomize(-1.0,1.0); return v; } #endif // RANDOM_MATRIX_HPP