// @HEADER // ***************************************************************************** // Rapid Optimization Library (ROL) Package // // Copyright 2014 NTESS and the ROL contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #ifndef ROL_OED_L1_PENALTY_DEF_HPP #define ROL_OED_L1_PENALTY_DEF_HPP namespace ROL { namespace OED { template L1Penalty::L1Penalty() : ProfiledClass("OED::L1Penalty") {} template std::vector& L1Penalty::getData(Vector &x) const { return *dynamic_cast&>(x).getVector(); } template const std::vector& L1Penalty::getConstData(const Vector &x) const { return *dynamic_cast&>(x).getVector(); } template void L1Penalty::sumAll(Real *input, Real *output, int size, const Vector &x) const { dynamic_cast&>(x).getBatchManager()->sumAll(input,output,size); } template Real L1Penalty::value( const Vector &x, Real &tol ) { startTimer("value"); const std::vector &xdata = getConstData(x); Real mval(0), gval(0); for (const auto &xi : xdata) mval += xi; sumAll(&mval,&gval,1,x); stopTimer("value"); return gval; } template void L1Penalty::gradient( Vector &g, const Vector &x, Real &tol ) { startTimer("gradient"); g.setScalar(static_cast(1)); stopTimer("gradient"); } template void L1Penalty::hessVec( Vector &hv, const Vector &v, const Vector &x, Real &tol ) { startTimer("hessVec"); hv.zero(); stopTimer("hessVec"); } } // End OED Namespace } // End ROL Namespace #endif