Skip to content

Commit

Permalink
Fix performance issue with nanstd and nanvar
Browse files Browse the repository at this point in the history
  • Loading branch information
zhujun98 committed Feb 19, 2021
1 parent 54dbb82 commit bc16cdd
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions include/xtensor/xmath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2610,8 +2610,8 @@ namespace detail {
XTL_REQUIRES(is_reducer_options<EVS>)>
inline auto nanvar(E&& e, EVS es = EVS())
{
decltype(auto) sc = detail::shared_forward<E>(e);
return nanmean<T>(square(sc - nanmean<T>(sc)), es);
auto cached_mean = nanmean<T>(e, es)();
return nanmean<T>(square(std::forward<E>(e) - cached_mean), es);
}

template <class T = void, class E, class EVS = DEFAULT_STRATEGY_REDUCERS,
Expand Down Expand Up @@ -2648,7 +2648,7 @@ namespace detail {
// note: forcing copy of first axes argument -- is there a better solution?
auto axes_copy = axes;
using result_type = typename std::conditional_t<std::is_same<T, void>::value, double, T>;
auto inner_mean = nanmean<result_type>(sc, std::move(axes_copy));
auto inner_mean = eval(nanmean<result_type>(sc, std::move(axes_copy), evaluation_strategy::immediate));

// fake keep_dims = 1
auto keep_dim_shape = e.shape();
Expand Down

0 comments on commit bc16cdd

Please sign in to comment.