From eb8375c41e5885b4cea23ccacac7431e854c8563 Mon Sep 17 00:00:00 2001 From: conrad Date: Tue, 4 May 2021 00:25:12 +1000 Subject: [PATCH] add .clamp() --- include/armadillo_bits/Cube_bones.hpp | 2 ++ include/armadillo_bits/Cube_meat.hpp | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/armadillo_bits/Cube_bones.hpp b/include/armadillo_bits/Cube_bones.hpp index f48313e2..d01cf080 100644 --- a/include/armadillo_bits/Cube_bones.hpp +++ b/include/armadillo_bits/Cube_bones.hpp @@ -323,6 +323,8 @@ class Cube : public BaseCube< eT, Cube > inline const Cube& clean(const pod_type threshold); + inline const Cube& clamp(const eT min_val, const eT max_val); + inline const Cube& fill(const eT val); inline const Cube& zeros(); diff --git a/include/armadillo_bits/Cube_meat.hpp b/include/armadillo_bits/Cube_meat.hpp index e9d3f0ae..1dd66a26 100644 --- a/include/armadillo_bits/Cube_meat.hpp +++ b/include/armadillo_bits/Cube_meat.hpp @@ -3942,6 +3942,22 @@ Cube::clean(const typename get_pod_type::result threshold) +template +inline +const Cube& +Cube::clamp(const eT min_val, const eT max_val) + { + arma_extra_debug_sigprint(); + + arma_debug_check( (min_val > max_val), "Cube::clamp(): min_val must be less than max_val" ); + + arrayops::clamp(memptr(), n_elem, min_val, max_val); + + return *this; + } + + + //! fill the cube with the specified value template inline