LCOV - code coverage report
Current view: top level - variable - operations_common.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 15 15 100.0 %
Date: 2024-04-28 01:25:40 Functions: 18 18 100.0 %

          Line data    Source code
       1             : // SPDX-License-Identifier: BSD-3-Clause
       2             : // Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
       3             : /// @file
       4             : /// @author Simon Heybrock
       5             : #pragma once
       6             : 
       7             : #include "scipp/core/flags.h"
       8             : #include "scipp/variable/astype.h"
       9             : #include "scipp/variable/reciprocal.h"
      10             : #include "scipp/variable/variable.h"
      11             : #include "scipp/variable/variable_factory.h"
      12             : 
      13             : namespace scipp::variable {
      14             : 
      15             : // Helpers for in-place reductions and reductions with groupby.
      16             : SCIPP_VARIABLE_EXPORT Variable mean_impl(const Variable &var, const Dim dim,
      17             :                                          const Variable &masks_sum);
      18             : SCIPP_VARIABLE_EXPORT Variable nanmean_impl(const Variable &var, const Dim dim,
      19             :                                             const Variable &masks_sum);
      20             : 
      21         316 : template <class T> T normalize_impl(const T &numerator, T denominator) {
      22             :   // Numerator may be an int or a Eigen::Vector3d => use double
      23             :   // This approach would be wrong if we supported vectors of float
      24         316 :   const auto type =
      25         316 :       numerator.dtype() == dtype<float> ? dtype<float> : dtype<double>;
      26         316 :   denominator.setUnit(units::one);
      27             :   return numerator *
      28         316 :          reciprocal(astype(denominator, type, CopyPolicy::TryAvoid));
      29             : }
      30             : 
      31             : SCIPP_VARIABLE_EXPORT void expect_valid_bin_indices(const Variable &indices,
      32             :                                                     const Dim dim,
      33             :                                                     const Sizes &buffer_sizes);
      34             : 
      35             : template <class T>
      36             : Variable make_bins_impl(Variable indices, const Dim dim, T &&buffer);
      37             : 
      38       41959 : template <class T, class Op> auto reduce_all_dims(const T &obj, const Op &op) {
      39       41959 :   if (obj.dims().empty()) {
      40       20592 :     if (is_bins(obj))
      41          29 :       return op(obj, Dim::Invalid);
      42             :     else
      43       20563 :       return copy(obj);
      44             :   }
      45       21367 :   auto out = op(obj, obj.dims().inner());
      46       22129 :   while (!out.dims().empty())
      47         762 :     out = op(out, out.dims().inner());
      48       21367 :   return out;
      49       21367 : }
      50             : 
      51             : } // namespace scipp::variable

Generated by: LCOV version 1.14