From bc16cdd063486891f22e386114bae30fb9e925f2 Mon Sep 17 00:00:00 2001 From: zhujun98 Date: Fri, 19 Feb 2021 11:26:13 +0100 Subject: [PATCH] Fix performance issue with nanstd and nanvar --- include/xtensor/xmath.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/xtensor/xmath.hpp b/include/xtensor/xmath.hpp index 37d61500f..9d80f243b 100644 --- a/include/xtensor/xmath.hpp +++ b/include/xtensor/xmath.hpp @@ -2610,8 +2610,8 @@ namespace detail { XTL_REQUIRES(is_reducer_options)> inline auto nanvar(E&& e, EVS es = EVS()) { - decltype(auto) sc = detail::shared_forward(e); - return nanmean(square(sc - nanmean(sc)), es); + auto cached_mean = nanmean(e, es)(); + return nanmean(square(std::forward(e) - cached_mean), es); } template ::value, double, T>; - auto inner_mean = nanmean(sc, std::move(axes_copy)); + auto inner_mean = eval(nanmean(sc, std::move(axes_copy), evaluation_strategy::immediate)); // fake keep_dims = 1 auto keep_dim_shape = e.shape();