Skip to content

Commit 1995bd7

Browse files
committed
feat: use signed integers for integer storages
1 parent bb1de5c commit 1995bd7

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

include/bh_python/storage.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
namespace storage {
2323

2424
// Names match Python names
25-
using int64 = bh::dense_storage<uint64_t>;
26-
using atomic_int64 = bh::dense_storage<bh::accumulators::count<uint64_t, true>>;
25+
using int64 = bh::dense_storage<int64_t>;
26+
using atomic_int64 = bh::dense_storage<bh::accumulators::count<int64_t, true>>;
2727
using double_ = bh::dense_storage<double>;
2828
using unlimited = bh::unlimited_storage<>;
2929
using weight = bh::dense_storage<accumulators::weighted_sum<double>>;
@@ -80,7 +80,7 @@ template <class Archive>
8080
void save(Archive& ar, const storage::atomic_int64& s, unsigned /* version */) {
8181
// We cannot view the memory as a numpy array, because the internal layout of
8282
// std::atomic is undefined. So no reinterpret_casts are allowed.
83-
py::array_t<std::uint64_t> a(static_cast<py::ssize_t>(s.size()));
83+
py::array_t<std::int64_t> a(static_cast<py::ssize_t>(s.size()));
8484

8585
auto in_ptr = s.begin();
8686
auto out_ptr = a.mutable_data();
@@ -191,15 +191,15 @@ struct type_caster<storage::atomic_int64::value_type> {
191191
auto ptr = PyNumber_Long(src.ptr());
192192
if(!ptr)
193193
return false;
194-
value = PyLong_AsUnsignedLongLong(ptr);
194+
value = PyLong_AsLongLong(ptr);
195195
Py_DECREF(ptr);
196196
return !PyErr_Occurred();
197197
}
198198

199199
static handle cast(storage::atomic_int64::value_type src,
200200
return_value_policy /* policy */,
201201
handle /* parent */) {
202-
return PyLong_FromUnsignedLongLong(src.value());
202+
return PyLong_FromLongLong(src.value());
203203
}
204204
};
205205
} // namespace detail

0 commit comments

Comments
 (0)