LCOV - code coverage report
Current view: top level - src/ket - KetPair.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 23 25 92.0 %
Date: 2026-10-14 13:16:16 Functions: 9 10 90.0 %

          Line data    Source code
       1             : // SPDX-FileCopyrightText: 2024 PairInteraction Developers
       2             : // SPDX-License-Identifier: LGPL-3.0-or-later
       3             : 
       4             : #include "pairinteraction/ket/KetPair.hpp"
       5             : 
       6             : #include "pairinteraction/basis/BasisAtom.hpp"
       7             : #include "pairinteraction/ket/KetAtom.hpp"
       8             : #include "pairinteraction/utils/hash.hpp"
       9             : 
      10             : #include <string>
      11             : 
      12             : namespace pairinteraction {
      13             : template <typename Scalar>
      14     2608378 : KetPair<Scalar>::KetPair(
      15             :     Private /*unused*/, std::initializer_list<size_t> atomic_indices,
      16             :     std::initializer_list<std::shared_ptr<const BasisAtom<Scalar>>> atomic_bases, real_t energy,
      17             :     std::unordered_map<std::string, double> quantum_numbers)
      18     2608378 :     : Ket(energy, std::move(quantum_numbers)), atomic_indices(atomic_indices),
      19     5216756 :       atomic_bases(atomic_bases) {
      20     2608378 :     if (atomic_indices.size() != atomic_bases.size()) {
      21           0 :         throw std::invalid_argument(
      22             :             "The number of atomic indices, and atomic bases must be the same.");
      23             :     }
      24     2608378 : }
      25             : 
      26             : template <typename Scalar>
      27         652 : std::vector<std::shared_ptr<const BasisAtom<Scalar>>> KetPair<Scalar>::get_atomic_states() const {
      28         652 :     std::vector<std::shared_ptr<const BasisAtom<Scalar>>> atomic_states;
      29         652 :     atomic_states.reserve(atomic_indices.size());
      30        1956 :     for (size_t atom_index = 0; atom_index < atomic_indices.size(); ++atom_index) {
      31        1304 :         atomic_states.push_back(atomic_bases[atom_index]->get_state(atomic_indices[atom_index]));
      32             :     }
      33         652 :     return atomic_states;
      34           0 : }
      35             : 
      36             : template <typename Scalar>
      37         302 : bool KetPair<Scalar>::operator==(const KetPair<Scalar> &other) const {
      38         602 :     return Ket::operator==(other) && atomic_indices == other.atomic_indices &&
      39         602 :         atomic_bases == other.atomic_bases;
      40             : }
      41             : 
      42             : template <typename Scalar>
      43           2 : bool KetPair<Scalar>::operator!=(const KetPair<Scalar> &other) const {
      44           2 :     return !(*this == other);
      45             : }
      46             : 
      47             : template <typename Scalar>
      48         224 : size_t KetPair<Scalar>::hash::operator()(const KetPair<Scalar> &k) const {
      49         224 :     size_t seed = typename Ket::hash()(k);
      50         672 :     for (const auto &index : k.atomic_indices) {
      51         448 :         utils::hash_combine(seed, index);
      52             :     }
      53         672 :     for (const auto &basis : k.atomic_bases) {
      54         448 :         utils::hash_combine(seed, reinterpret_cast<std::uintptr_t>(basis.get()));
      55             :     }
      56         224 :     return seed;
      57             : }
      58             : 
      59             : // Explicit instantiations
      60             : template class KetPair<double>;
      61             : template class KetPair<std::complex<double>>;
      62             : } // namespace pairinteraction

Generated by: LCOV version 1.16