From 1c836a17a0ab0c15ddd6aab6208aa308775ff7a9 Mon Sep 17 00:00:00 2001 From: David Tschumperle Date: Fri, 13 Dec 2024 10:54:56 +0100 Subject: [PATCH] Add command 'softmin' and math parser function 'softmin()'. --- CImg.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/CImg.h b/CImg.h index 9e761056..e5ec705b 100644 --- a/CImg.h +++ b/CImg.h @@ -30335,7 +30335,19 @@ namespace cimg_library { //! Softmin operator \newinstance. CImg get_softmin(const float temperature=1) const { - return get_softmax(-temperature); + if (is_empty()) return CImg(); + CImg res(_width,_height,_depth,_spectrum); + const T val_min = min(); + Tfloat sum = 0; + cimg_pragma_openmp(parallel reduction(+:sum) cimg_openmp_if_size(size(),4096)) { + cimg_pragma_openmp(for) + cimg_rofoff(*this,off) { + const Tfloat val = std::exp((-(Tfloat)_data[off] + val_min)/temperature); + res[off] = val; + sum+=val; + } + } + return res/=sum; } //! Pointwise min operator between instance image and a value.