SpECTRE Documentation Coverage Report
Current view: top level - NumericalAlgorithms/SpinWeightedSphericalHarmonics/Python - InterleavedHelpers.hpp Coverage Total Hit
Commit: 0d1d717af84a81fb1284a20c4013708fe85cc2f0 Lines: 0.0 % 1 0
Test Date: 2026-10-22 17:29:42
Legend: Lines:     hit not hit

            Line data    Source code
       1            0 : // Distributed under the MIT License.
       2              : // See LICENSE.txt for details.
       3              : 
       4              : #pragma once
       5              : 
       6              : #include <complex>
       7              : #include <cstddef>
       8              : #include <stdexcept>
       9              : #include <string>
      10              : 
      11              : #include "DataStructures/DataVector.hpp"
      12              : 
      13              : namespace py_bindings::detail {
      14              : // The bindings pass spin-weighted complex data as real, interleaved
      15              : // [re, im, re, im, ...] arrays so they can be constructed directly from numpy.
      16              : 
      17              : template <typename ComplexVector>
      18              : ComplexVector interleaved_to_complex(const DataVector& interleaved) {
      19              :   if (interleaved.size() % 2 != 0) {
      20              :     throw std::invalid_argument(
      21              :         "Interleaved [re, im, ...] array must have an even number of "
      22              :         "entries, not " +
      23              :         std::to_string(interleaved.size()) + ".");
      24              :   }
      25              :   ComplexVector result{interleaved.size() / 2};
      26              :   for (size_t i = 0; i < result.size(); ++i) {
      27              :     result[i] =
      28              :         std::complex<double>(interleaved[2 * i], interleaved[2 * i + 1]);
      29              :   }
      30              :   return result;
      31              : }
      32              : 
      33              : template <typename ComplexVector>
      34              : DataVector complex_to_interleaved(const ComplexVector& complex_values) {
      35              :   DataVector result{2 * complex_values.size()};
      36              :   for (size_t i = 0; i < complex_values.size(); ++i) {
      37              :     result[2 * i] = complex_values[i].real();
      38              :     result[2 * i + 1] = complex_values[i].imag();
      39              :   }
      40              :   return result;
      41              : }
      42              : }  // namespace py_bindings::detail
        

Generated by: LCOV version 2.0-1