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 <string> 8 : #include <vector> 9 : 10 : #include "scipp-core_export.h" 11 : #include "scipp/common/index.h" 12 : #include "scipp/common/initialization.h" 13 : 14 : namespace scipp::core { 15 : 16 : /// Helper of `bin` for representing rows of a sparse subbin-size array. 17 : class SCIPP_CORE_EXPORT SubbinSizes { 18 : public: 19 : using container_type = std::vector<scipp::index>; 20 1308735 : SubbinSizes() = default; 21 : SubbinSizes(const scipp::index offset, container_type &&sizes); 22 611875 : const auto &offset() const noexcept { return m_offset; } 23 60498642 : const auto &sizes() const noexcept { return m_sizes; } 24 : void operator=(const scipp::index value); 25 : SubbinSizes &operator+=(const SubbinSizes &other); 26 : SubbinSizes &operator-=(const SubbinSizes &other); 27 : 28 : SubbinSizes cumsum_exclusive() const; 29 : scipp::index sum() const; 30 : SubbinSizes &add_intersection(const SubbinSizes &other); 31 : void exclusive_scan(SubbinSizes &x); 32 : 33 : private: 34 : scipp::index m_offset{0}; 35 : container_type m_sizes; 36 : }; 37 : 38 : [[nodiscard]] SCIPP_CORE_EXPORT bool operator==(const SubbinSizes &a, 39 : const SubbinSizes &b); 40 : 41 : [[nodiscard]] SCIPP_CORE_EXPORT SubbinSizes operator+(const SubbinSizes &a, 42 : const SubbinSizes &b); 43 : 44 : [[nodiscard]] SCIPP_CORE_EXPORT SubbinSizes operator-(const SubbinSizes &a, 45 : const SubbinSizes &b); 46 : 47 : } // namespace scipp::core 48 : 49 : namespace scipp { 50 : // This is used by `sum` to initialize the output. By default we want a length-0 51 : // size vector. 52 : template <> struct zero_init<core::SubbinSizes> { 53 7548 : static core::SubbinSizes value() { return core::SubbinSizes(); } 54 : }; 55 : 56 : } // namespace scipp