LCOV - code coverage report
Current view: top level - core - strides.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 27 27 100.0 %
Date: 2024-04-28 01:25:40 Functions: 10 10 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/core/strides.h"
       6             : 
       7             : namespace scipp::core {
       8             : 
       9      188400 : Strides::Strides(const scipp::span<const scipp::index> &strides)
      10      188400 :     : m_strides(strides.begin(), strides.end()) {}
      11             : 
      12         139 : Strides::Strides(const std::initializer_list<scipp::index> strides)
      13         278 :     : m_strides(strides) {}
      14             : 
      15     2564463 : Strides::Strides(const Dimensions &dims) {
      16     2564463 :   scipp::index offset{1};
      17     2564463 :   resize(dims.ndim());
      18     3762426 :   for (scipp::index i = dims.ndim() - 1; i >= 0; --i) {
      19     1197963 :     m_strides[i] = offset;
      20     1197963 :     offset *= dims.size(i);
      21             :   }
      22     2564463 : }
      23             : 
      24       82250 : bool Strides::operator==(const Strides &other) const noexcept {
      25      164500 :   return m_strides == other.m_strides;
      26             : }
      27             : 
      28       75994 : bool Strides::operator!=(const Strides &other) const noexcept {
      29       75994 :   return !operator==(other);
      30             : }
      31             : 
      32       70632 : void Strides::push_back(const scipp::index i) { m_strides.push_back(i); }
      33             : 
      34       81217 : void Strides::clear() { m_strides.clear(); }
      35             : 
      36     6081305 : void Strides::resize(const scipp::index size) { m_strides.resize(size); }
      37             : 
      38      131679 : void Strides::erase(const scipp::index i) {
      39      263358 :   m_strides.erase(m_strides.begin() + i);
      40      131679 : }
      41             : 
      42        5894 : Strides transpose(const Strides &strides, Dimensions from,
      43             :                   const scipp::span<const Dim> order) {
      44        5894 :   scipp::index i = 0;
      45       25409 :   for (const auto &dim : from)
      46       13621 :     from.resize(dim, strides[i++]);
      47        5894 :   from = core::transpose(from, order);
      48       11772 :   return Strides(from.shape());
      49             : }
      50             : 
      51             : } // namespace scipp::core

Generated by: LCOV version 1.14