Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Complete python interface for enumeration of short vectors.
Browse files Browse the repository at this point in the history
  • Loading branch information
martinra committed Jan 28, 2014
1 parent b7dbede commit 269cc4b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
Expand Up @@ -19,6 +19,7 @@

#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
#include "c_lib/interrupt.h"

#include "enumerate_short_vectors.hpp"

Expand All @@ -28,7 +29,7 @@ using namespace boost::python
{
BOOST_PYTHON_MODULE(enumerate_short_vectors)
{
def("short_vectors", short_vectors);
def("short_vectors", short_vectors, short_vectors_overloads());
}
}

Expand All @@ -41,7 +42,7 @@ short_vectors
python::list lattice,
const long lower_bound,
const long upper_bound,
const bool up_to_sign
const bool up_to_sign = false
)
{
const long dim = lattice.len();
Expand All @@ -55,8 +56,9 @@ short_vectors
if (upper_bound < lower_bound)
return python::dict();
if (upper_bound == 0) {
// todo: add zero vector
result[0] = python::list();
auto vec_lst = python::list();
for (long ix = 0; ix < dim; ++ix) vec_lst.append(0);
result[0] = python::tuple(vec_lst);
return result;
}

Expand All @@ -73,12 +75,15 @@ short_vectors
for (python::object &e : row) lattice.last().emplace_back(python::extract<int>(e));
}

sig_on()

// invoke method
map<unsigned int, vector<vector<int>>> short_vectors;
try {
enumerate_short_vectors( lattice_cpp, lower_bound, upper_bound, short_vectors );
} catch (string &s) {
// todo: raise corresponding python error
PyErr_SetString(PyExc_ValueError, s);
throw_error_already_set();
}

// construct python return value
Expand All @@ -92,9 +97,15 @@ short_vectors
}
}

sig_off()

if (add_zero_vector) {
// todo: add zero vector
auto vec_lst = python::list();
for (long ix = 0; ix < dim; ++ix) vec_lst.append(0);
result[0] = python::tuple(vec_lst);
}

return result;
}

python::tuple
Expand Down
Expand Up @@ -17,9 +17,14 @@
*
*/

#include <boost/python/module.hpp>
#include <boost/python/def.hpp>

boost::python::dict
short_vectors( boost::python::list, const long, const long, const bool );

BOOST_PYTHON_FUNCTION_OVERLOADS(short_vectors_overloads, short_vectors, 3, 4)

boost::python::tuple
to_python_vector( const std::vector<int> & );

Expand Down

0 comments on commit 269cc4b

Please sign in to comment.