Skip to content

Commit 24056a1

Browse files
committedJul 18, 2024·
n_fermion_sector_view: Avoid using static_assert(false)
1 parent 1dc15be commit 24056a1

File tree

1 file changed

+25
-55
lines changed

1 file changed

+25
-55
lines changed
 

‎include/libcommute/loperator/n_fermion_sector_view.hpp

+25-55
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include <utility>
3636
#include <vector>
3737

38-
#if (defined(__GNUC__) || defined(__clang__)) && defined(__BMI2__)
38+
#if(defined(__GNUC__) || defined(__clang__)) && defined(__BMI2__)
3939
#include <immintrin.h>
4040
#endif
4141

@@ -117,7 +117,7 @@ inline unsigned int popcount(sv_index_type i) {
117117

118118
// Parallel bits deposit
119119
inline sv_index_type deposit_bits(sv_index_type src, sv_index_type mask) {
120-
#if (defined(__GNUC__) || defined(__clang__)) && defined(__BMI2__)
120+
#if(defined(__GNUC__) || defined(__clang__)) && defined(__BMI2__)
121121
return _pdep_u64(src, mask);
122122
#else
123123
// https://www.chessprogramming.org/BMI2#Serial_Implementation
@@ -132,7 +132,7 @@ inline sv_index_type deposit_bits(sv_index_type src, sv_index_type mask) {
132132

133133
// Parallel bits extract
134134
inline sv_index_type extract_bits(sv_index_type val, sv_index_type mask) {
135-
#if (defined(__GNUC__) || defined(__clang__)) && defined(__BMI2__)
135+
#if(defined(__GNUC__) || defined(__clang__)) && defined(__BMI2__)
136136
return _pext_u64(val, mask);
137137
#else
138138
// From https://www.chessprogramming.org/BMI2#Serial_Implementation_2
@@ -606,7 +606,12 @@ inline auto get_element(
606606

607607
// Add a constant to a state amplitude stored in the adapted StateVector object
608608
// at index view.map_index(n)
609-
template <typename StateVector, bool Ref, typename RankingAlgorithm, typename T>
609+
template <typename StateVector,
610+
bool Ref,
611+
typename RankingAlgorithm,
612+
typename T,
613+
typename =
614+
typename std::enable_if<!std::is_const<StateVector>::value>::type>
610615
inline void update_add_element(
611616
n_fermion_sector_view<StateVector, Ref, RankingAlgorithm>& view,
612617
sv_index_type n,
@@ -616,37 +621,17 @@ inline void update_add_element(
616621
std::forward<T>(value));
617622
}
618623

619-
// update_add_element() is not defined for constant views
620-
template <typename StateVector, bool Ref, typename RankingAlgorithm, typename T>
621-
inline void update_add_element(
622-
n_fermion_sector_view<StateVector const, Ref, RankingAlgorithm>&,
623-
sv_index_type,
624-
T&&) { // NOLINT(cppcoreguidelines-missing-std-forward)
625-
static_assert(false,
626-
"update_add_element() is not supported for constant views");
627-
}
628-
629-
// zeros_like() is not defined for views
630-
template <typename StateVector, bool Ref, typename RankingAlgorithm>
631-
inline StateVector
632-
zeros_like(n_fermion_sector_view<StateVector, Ref, RankingAlgorithm> const&) {
633-
static_assert(false, "zeros_like() is not supported for views");
634-
}
635-
636624
// Set all amplitudes stored in the adapted StateVector object to zero
637-
template <typename StateVector, bool Ref, typename RankingAlgorithm>
625+
template <typename StateVector,
626+
bool Ref,
627+
typename RankingAlgorithm,
628+
typename =
629+
typename std::enable_if<!std::is_const<StateVector>::value>::type>
638630
inline void
639631
set_zeros(n_fermion_sector_view<StateVector, Ref, RankingAlgorithm>& view) {
640632
set_zeros(view.state_vector);
641633
}
642634

643-
// set_zeros() is not defined for constant views
644-
template <typename StateVector, bool Ref, typename RankingAlgorithm>
645-
inline void
646-
set_zeros(n_fermion_sector_view<StateVector const, Ref, RankingAlgorithm>&) {
647-
static_assert(false, "set_zeros() is not supported for constant views");
648-
}
649-
650635
// Apply functor `f` to all index/non-zero amplitude pairs
651636
// in the adapted StateVector object
652637
template <typename StateVector,
@@ -1009,7 +994,12 @@ inline auto get_element(
1009994

1010995
// Add a constant to a state amplitude stored in the adapted StateVector object
1011996
// at index view.map_index(n)
1012-
template <typename StateVector, bool Ref, typename RankingAlgorithm, typename T>
997+
template <typename StateVector,
998+
bool Ref,
999+
typename RankingAlgorithm,
1000+
typename T,
1001+
typename =
1002+
typename std::enable_if<!std::is_const<StateVector>::value>::type>
10131003
inline void update_add_element(
10141004
n_fermion_multisector_view<StateVector, Ref, RankingAlgorithm>& view,
10151005
sv_index_type n,
@@ -1019,37 +1009,17 @@ inline void update_add_element(
10191009
std::forward<T>(value));
10201010
}
10211011

1022-
// update_add_element() is not defined for constant views
1023-
template <typename StateVector, bool Ref, typename RankingAlgorithm, typename T>
1024-
inline void update_add_element(
1025-
n_fermion_multisector_view<StateVector const, Ref, RankingAlgorithm>&,
1026-
sv_index_type,
1027-
T&&) { // NOLINT(cppcoreguidelines-missing-std-forward)
1028-
static_assert(false,
1029-
"update_add_element() is not supported for constant views");
1030-
}
1031-
1032-
// zeros_like() is not defined for views
1033-
template <typename StateVector, bool Ref, typename RankingAlgorithm>
1034-
inline StateVector zeros_like(
1035-
n_fermion_multisector_view<StateVector, Ref, RankingAlgorithm> const&) {
1036-
static_assert(false, "zeros_like() is not supported for views");
1037-
}
1038-
10391012
// Set all amplitudes stored in the adapted StateVector object to zero
1040-
template <typename StateVector, bool Ref, typename RankingAlgorithm>
1013+
template <typename StateVector,
1014+
bool Ref,
1015+
typename RankingAlgorithm,
1016+
typename =
1017+
typename std::enable_if<!std::is_const<StateVector>::value>::type>
10411018
inline void set_zeros(
10421019
n_fermion_multisector_view<StateVector, Ref, RankingAlgorithm>& view) {
10431020
set_zeros(view.state_vector);
10441021
}
10451022

1046-
// set_zeros() is not defined for constant views
1047-
template <typename StateVector, bool Ref, typename RankingAlgorithm>
1048-
inline void set_zeros(
1049-
n_fermion_multisector_view<StateVector const, Ref, RankingAlgorithm>&) {
1050-
static_assert(false, "set_zeros() is not supported for constant views");
1051-
}
1052-
10531023
// Apply functor `f` to all index/non-zero amplitude pairs
10541024
// in the adapted StateVector object
10551025
template <typename StateVector,

0 commit comments

Comments
 (0)
Please sign in to comment.