Skip to content

Commit

Permalink
Merge pull request #818 from htm-community/pypi_cibuildwheel
Browse files Browse the repository at this point in the history
pybind Random: fix cast signedness
  • Loading branch information
breznak authored Jun 1, 2020
2 parents 342d716 + 1fccbab commit 8ef7e79
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions bindings/py/cpp_src/bindings/math/py_Random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ namespace htm_ext {
Random.def(py::init<htm::UInt64>(), py::arg("seed") = 0)
.def("getUInt32", &Random_t::getUInt32, py::arg("max") = (htm::UInt32)-1l)
.def("getReal64", &Random_t::getReal64)
.def("getSeed", &Random_t::getSeed)
.def("getSeed", &Random_t::getSeed)
.def("max", &Random_t::max)
.def("min", &Random_t::min)
.def("__eq__", [](Random_t const & self, Random_t const & other) {//wrapping operator==
.def("__eq__", [](Random_t const & self, Random_t const & other) {//wrapping operator==
return self == other;
}, py::is_operator());
}, py::is_operator());

Random.def_property_readonly_static("MAX32", [](py::object) {
return Random_t::MAX32;
Expand All @@ -60,8 +60,7 @@ namespace htm_ext {
/////////////////


Random.def("sample",
[](Random_t& r, py::array& population, const htm::UInt32 nSelect)
Random.def("sample", [](Random_t& r, py::array& population, const htm::UInt32 nSelect)
{
if (population.ndim() != 1 )
{
Expand Down Expand Up @@ -98,8 +97,8 @@ namespace htm_ext {
{
auto array_data = get_it<htm::UInt32>(a);

for (htm::UInt32 i = 0; i != a.size(); ++i)
array_data[i] = self.getUInt32() % max_value;
for (auto i = a.size()-1; i >= 0; --i)
array_data[i] = self.getUInt32(max_value);

});

Expand All @@ -110,7 +109,7 @@ namespace htm_ext {
{
auto array_data = get_it<htm::Real64>(a);

for (htm::UInt32 i = 0; i != a.size(); ++i)
for (auto i = a.size()-1; i >=0; --i)
array_data[i] = self.getReal64();

});
Expand All @@ -122,8 +121,8 @@ namespace htm_ext {
Random.def("saveToFile", [](Random_t& self, const std::string& name, int fmt) {
htm::SerializableFormat fmt1;
switch(fmt) {
case 0: fmt1 = htm::SerializableFormat::BINARY; break;
case 1: fmt1 = htm::SerializableFormat::PORTABLE; break;
case 0: fmt1 = htm::SerializableFormat::BINARY; break;
case 1: fmt1 = htm::SerializableFormat::PORTABLE; break;
case 2: fmt1 = htm::SerializableFormat::JSON; break;
case 3: fmt1 = htm::SerializableFormat::XML; break;
default: NTA_THROW << "unknown serialization format.";
Expand Down

0 comments on commit 8ef7e79

Please sign in to comment.