// SPDX-License-Identifier: Apache-2.0 // // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au) // Copyright 2008-2016 National ICT Australia (NICTA) // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // ------------------------------------------------------------------------ //! \addtogroup fn_clamp //! @{ template arma_warn_unused inline typename enable_if2 < is_arma_type::value && is_cx::no, const mtOp >::result clamp(const T1& X, const typename T1::elem_type min_val, const typename T1::elem_type max_val) { arma_extra_debug_sigprint(); return mtOp(mtOp_dual_aux_indicator(), X, min_val, max_val); } template arma_warn_unused inline typename enable_if2 < is_arma_type::value && is_cx::yes, const mtOp >::result clamp(const T1& X, const typename T1::elem_type min_val, const typename T1::elem_type max_val) { arma_extra_debug_sigprint(); return mtOp(mtOp_dual_aux_indicator(), X, min_val, max_val); } template arma_warn_unused inline const mtOpCube clamp(const BaseCube& X, const typename T1::elem_type min_val, const typename T1::elem_type max_val, typename arma_not_cx::result* junk = nullptr) { arma_extra_debug_sigprint(); arma_ignore(junk); return mtOpCube(mtOpCube_dual_aux_indicator(), X.get_ref(), min_val, max_val); } template arma_warn_unused inline const mtOpCube clamp(const BaseCube& X, const typename T1::elem_type min_val, const typename T1::elem_type max_val, typename arma_cx_only::result* junk = nullptr) { arma_extra_debug_sigprint(); arma_ignore(junk); return mtOpCube(mtOpCube_dual_aux_indicator(), X.get_ref(), min_val, max_val); } template arma_warn_unused inline SpMat clamp(const SpBase& X, const typename T1::elem_type min_val, const typename T1::elem_type max_val) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; if(is_cx::no) { arma_debug_check( (access::tmp_real(min_val) > access::tmp_real(max_val)), "clamp(): min_val must be less than max_val" ); } else { arma_debug_check( (access::tmp_real(min_val) > access::tmp_real(max_val)), "clamp(): real(min_val) must be less than real(max_val)" ); arma_debug_check( (access::tmp_imag(min_val) > access::tmp_imag(max_val)), "clamp(): imag(min_val) must be less than imag(max_val)" ); } SpMat out = X.get_ref(); out.clamp(min_val, max_val); return out; } //! @}