LCOV - code coverage report
Current view: top level - core - view_index.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 17 17 100.0 %
Date: 2024-04-28 01:25:40 Functions: 1 1 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 Jan-Lukas Wynen
       5             : #include "scipp/core/view_index.h"
       6             : 
       7             : #include "scipp/core/except.h"
       8             : 
       9             : namespace scipp::core {
      10             : 
      11     2544358 : ViewIndex::ViewIndex(const Dimensions &target_dimensions,
      12     2544358 :                      const Strides &strides) {
      13     2544358 :   scipp::index rewind = 0;
      14     2544358 :   scipp::index dim_write = 0;
      15     7585876 :   for (scipp::index dim_read = target_dimensions.ndim() - 1; dim_read >= 0;
      16             :        --dim_read) {
      17     5041518 :     const auto stride = strides[dim_read];
      18     5041518 :     const auto delta = stride - rewind;
      19     5041518 :     const auto size = target_dimensions.size(dim_read);
      20     5041518 :     rewind = size * stride;
      21     5041518 :     if (delta != 0 || stride == 0) {
      22     3307320 :       m_shape[dim_write] = size;
      23     3307320 :       m_delta[dim_write] = delta;
      24     3307320 :       m_strides[dim_write] = stride;
      25     3307320 :       ++dim_write;
      26             :     } else {
      27             :       // The memory for this dimension is contiguous with the previous dim,
      28             :       // so we flatten them into one dimension.
      29             :       // This cannot happen in the innermost dim because if stride != 0,
      30             :       // delta != 0 because rewind == 0.
      31     1734198 :       m_shape[dim_write - 1] *= size;
      32             :     }
      33             :   }
      34     2544358 :   m_ndim = dim_write;
      35     2544358 : }
      36             : 
      37             : } // namespace scipp::core

Generated by: LCOV version 1.14