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-04-28 01:25:40 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          29 : Variable rebin(const Variable &var, const Dim dim, const Variable &oldCoord,
      15             :                const Variable &newCoord, const Masks &masks) {
      16          58 :   if (const auto mask_union = irreducible_mask(masks, dim);
      17          29 :       mask_union.is_valid()) {
      18           2 :     return rebin(where(mask_union, zero_like(var), var), dim, oldCoord,
      19           1 :                  newCoord);
      20          29 :   }
      21          28 :   return rebin(var, dim, oldCoord, newCoord);
      22             : }
      23             : 
      24          29 : DataArray rebin(const DataArray &a, const Dim dim, const Variable &coord) {
      25             :   auto rebinned = apply_to_data_and_drop_dim(
      26          58 :       a, [](auto &&..._) { return rebin(_...); }, dim, a.coords()[dim], coord,
      27          58 :       a.masks());
      28          29 :   rebinned.coords().set(dim, coord);
      29          29 :   return rebinned;
      30           0 : }
      31             : 
      32           3 : Dataset rebin(const Dataset &d, const Dim dim, const Variable &coord) {
      33             :   return apply_to_items(
      34           6 :       d, [](auto &&..._) { return rebin(_...); }, dim, coord);
      35             : }
      36             : 
      37             : } // namespace scipp::dataset

Generated by: LCOV version 1.14