LCOV - code coverage report
Current view: top level - common/include/scipp/common - initialization.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 4 4 100.0 %
Date: 2024-04-28 01:25:40 Functions: 17 50 34.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 Owen Arnold
       5             : #pragma once
       6             : #include <Eigen/Core>
       7             : namespace scipp {
       8             : template <class T> struct default_init {
       9       37557 :   static T value() { return T{}; }
      10             : };
      11             : // Eigen does not zero-initialize matrices (vectors), which is a recurrent
      12             : // source of bugs. Variable does zero-init instead.
      13             : template <class T, int Rows, int Cols>
      14             : struct default_init<Eigen::Matrix<T, Rows, Cols>> {
      15          17 :   static Eigen::Matrix<T, Rows, Cols> value() {
      16          17 :     return Eigen::Matrix<T, Rows, Cols>::Zero();
      17             :   }
      18             : };
      19             : 
      20             : template <class T> struct zero_init {
      21     1220350 :   static T value() { return T{0}; }
      22             : };
      23             : 
      24             : template <class T, int Rows, int Cols>
      25             : struct zero_init<Eigen::Matrix<T, Rows, Cols>>
      26             :     : default_init<Eigen::Matrix<T, Rows, Cols>> {};
      27             : } // namespace scipp

Generated by: LCOV version 1.14