// (c) 2021-2024 The Johns Hopkins University Applied Physics Laboratory LLC (JHU/APL). #ifndef OpenFHE_PYTHON_UTILS_H #define OpenFHE_PYTHON_UTILS_H #include #include #include "boost/multi_array.hpp" #include #include using namespace boost::python; using namespace boost::python::numpy; namespace pyOpenFHE { // TODO do these really belong in utils.hpp rather than he-cnn.hpp? // for kernel slicing typedef typename boost::multi_array boost_vector2d; typedef typename boost::multi_array boost_vector4d; typedef boost::multi_array_types::index_range srange; typedef typename boost_vector4d::array_view<4>::type boost_vector4d_slice; boost::python::list make_list(const std::size_t n, boost::python::object item = boost::python::object() /* none */); // converts std::vector to python list, O(n) time list cppVectorToPythonList(const std::vector &); list cppLongIntVectorToPythonList(const std::vector &vector); // O(n) std::vector to numpy array // could be faster if we didn't have use complex // in that case we could just copy the vector contents to the numpy array // that's probably optimized or something, better than iteration ndarray cppDoubleVectorToNumpyList(const std::vector &); ndarray cppLongIntVectorToNumpyList(const std::vector &vector); // these two are used for converting lists of indices for EvalAtIndexKeyGen // since they have to be ints, and we're on the static typing side of things std::vector pythonListToCppIntVector(const list &); std::vector numpyListToCppIntVector(const ndarray &); boost_vector4d numpyArrayToCppArray4D(const ndarray &nplist); boost_vector2d numpyArrayToCppArray2D(const ndarray &nplist); // conversion for complex // for numpy arrays, the dtype must be specified to float/double or else C++ // will throw a fit std::vector numpyListToCppDoubleVector(const ndarray &); std::vector pythonListToCppDoubleVector(const list &); std::vector pythonListToCppLongIntVector(const list &pylist); std::vector numpyListToCppLongIntVector(const ndarray &nplist); } // namespace pyOpenFHE std::vector sumOfPo2s(int); void tileVector(std::vector &vals, unsigned int n); void tileVector(std::vector &vals, unsigned int n); void tileVector(std::vector &vals, unsigned int n); template void print_vector(std::vector vec); #endif /* OpenFHE_PYTHON_UTILS_H */