Skip to content

Commit

Permalink
Revert "Use a safer expression to set N lowest bits of an integer"
Browse files Browse the repository at this point in the history
This reverts commit 32371cf.
  • Loading branch information
krivenko committed Jul 18, 2024
1 parent 8860314 commit 1dc15be
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 24 deletions.
14 changes: 7 additions & 7 deletions include/libcommute/loperator/monomial_action_boson.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ template <> class monomial_action<boson> {
bit_range_t const& bit_range = hs.bit_range(es);
int shift = bit_range.first;
int n_bits = bit_range.second - bit_range.first + 1;
sv_index_type n_max = (~sv_index_type(0)) >> (sv_index_width - n_bits);
sv_index_type n_max = (sv_index_type(1) << n_bits) - 1;

sqr_roots_size = std::max(sqr_roots_size, n_max + 1);

Expand All @@ -108,12 +108,12 @@ template <> class monomial_action<boson> {
auto n_change = static_cast<std::int64_t>(dagger ? power : -power);
std::int64_t state_change = n_change * (std::int64_t(1) << shift);

updates_.emplace_back(single_boson_update_t{
shift,
(~sv_index_type(0)) >> (sv_index_width - n_bits),
n_change,
n_max,
state_change});
updates_.emplace_back(
single_boson_update_t{shift,
(sv_index_type(1) << n_bits) - 1,
n_change,
n_max,
state_change});

power = 1;
} else
Expand Down
12 changes: 6 additions & 6 deletions include/libcommute/loperator/monomial_action_spin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ template <> class monomial_action<spin> {
g.multiplicity() % 2 == 0 ? (s + 0.5) * (s + 0.5) : s * (s + 1);
sqr_roots_size = std::max(sqr_roots_size, ss + 1);

updates_.emplace_back(single_spin_update_t{
sv_index_type(2 * s),
shift,
(~sv_index_type(0)) >> (sv_index_width - n_bits),
g.component(),
power});
updates_.emplace_back(
single_spin_update_t{sv_index_type(2 * s),
shift,
(sv_index_type(1) << n_bits) - 1,
g.component(),
power});

power = 1;
} else
Expand Down
5 changes: 0 additions & 5 deletions include/libcommute/loperator/state_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#include <algorithm>
#include <cstdint>
#include <limits>
#include <utility>
#include <vector>

Expand All @@ -26,10 +25,6 @@ namespace libcommute {
// Type of index into a state vector
using sv_index_type = std::uint64_t;

// Bit width of the state index type
static constexpr int sv_index_width =
std::numeric_limits<sv_index_type>::digits;

//
// Implementation of the StateVector interface for std::vector
//
Expand Down
3 changes: 1 addition & 2 deletions test/monomial_action_boson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ TEST_CASE("Action of a bosonic monomial on an index",

std::vector<sv_index_type> in_index_list(1 << n_op_bits);
for(unsigned int i = 0; i < in_index_list.size(); i++)
in_index_list[i] = (i << n_pad_bits) +
(~sv_index_type(0) >> (sv_index_width - n_pad_bits));
in_index_list[i] = (i << n_pad_bits) + (1 << n_pad_bits) - 1;

SECTION("No operators") {
mon_type mon;
Expand Down
3 changes: 1 addition & 2 deletions test/monomial_action_fermion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ TEST_CASE("Action of a fermionic monomial on an index",

std::vector<sv_index_type> in_index_list(1 << n_ops);
for(unsigned int i = 0; i < in_index_list.size(); i++)
in_index_list[i] = (i << n_pad_bits) +
(~sv_index_type(0) >> (sv_index_width - n_pad_bits));
in_index_list[i] = (i << n_pad_bits) + (1 << n_pad_bits) - 1;

SECTION("No operators") {
mon_type mon;
Expand Down
3 changes: 1 addition & 2 deletions test/monomial_action_spin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ TEST_CASE("Action of a spin monomial on an index", "[monomial_action_spin]") {
for(sv_index_type n12 : {0, 1}) {
for(sv_index_type n1 : {0, 1, 2}) {
for(sv_index_type n32 : {0, 1, 2, 3}) {
sv_index_type index =
~sv_index_type(0) >> (sv_index_width - n_pad_bits);
sv_index_type index = (1 << n_pad_bits) - 1;
index += n12 << n_pad_bits;
index += n1 << (n_pad_bits + 1);
index += n32 << (n_pad_bits + 3);
Expand Down

0 comments on commit 1dc15be

Please sign in to comment.