LCOV - code coverage report
Current view: top level - dataset - rebin.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 14 15 93.3 %
Date: 2024-11-24 01:48:31 Functions: 5 5 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             : #include "scipp/dataset/rebin.h"
       6             : #include "scipp/variable/creation.h"
       7             : #include "scipp/variable/rebin.h"
       8             : #include "scipp/variable/util.h"
       9             : 
      10             : #include "dataset_operations_common.h"
      11             : 
      12             : namespace scipp::dataset {
      13             : 
      14          25 : Variable rebin(const Variable &var, const Dim dim, const Variable &oldCoord,
      15             :                const Variable &newCoord, const Masks &masks) {
      16          50 :   if (const auto mask_union = irreducible_mask(masks, dim);
      17          25 :       mask_union.is_valid()) {
      18           2 :     return rebin(where(mask_union, zero_like(var), var), dim, oldCoord,
      19           1 :                  newCoord);
      20          25 :   }
      21          24 :   return rebin(var, dim, oldCoord, newCoord);
      22             : }
      23             : 
      24          25 : DataArray rebin(const DataArray &a, const Dim dim, const Variable &coord) {
      25             :   auto rebinned = apply_to_data_and_drop_dim(
      26          50 :       a, [](auto &&..._) { return rebin(_...); }, dim, a.coords()[dim], coord,
      27          50 :       a.masks());
      28          25 :   rebinned.coords().set(dim, coord);
      29          25 :   return rebinned;
      30           0 : }
      31             : 
      32           3 : Dataset rebin(const Dataset &d, const Dim dim, const Variable &coord) {
      33           6 :   return apply_to_items(d, [](auto &&..._) { return rebin(_...); }, dim, coord);
      34             : }
      35             : 
      36             : } // namespace scipp::dataset

Generated by: LCOV version 1.14