Huelse / SEAL-Python

Microsoft SEAL 4.X For Python
MIT License
310 stars 66 forks source link

Python2.7封装后,使用PlainModulus.Batching()初始化plain_modulus出现错误 #23

Closed yuntaobc closed 4 years ago

yuntaobc commented 4 years ago

下面是报错的提示.

File "5_rotation.py", line 12, in example_rotation_bfv
    parms.set_plain_modulus(PlainModulus.Batching(poly_modulus_degree, 20))
TypeError: unbound method Batching() must be called with PlainModulus instance as first argument (got int instance instead)

定位到这句话

parms.set_plain_modulus(PlainModulus.Batching(poly_modulus_degree, 20))

请问老哥,你觉得这问题是因为 1.Python2.7封装时就不能支持这个操作 还是因为 2.Python版本差异,参数传递方式不同,需要修改5_rotation.py.

如果是原因2的话,是不是可以修改修改,来支持Python2.7啊?可以往哪方面搜?

另外python2.7运行1_bfv_basic.py以及2_encoders.pyexample_integer_encoder()倒是没什么问题.

Huelse commented 4 years ago

可能和python2.7的库不支持lambda函数有关,你可以在wrapper.cpp的120行看到,这里是用lambda函数包装的,尝试把这里改为和其他普通函数绑定的那样子试试。

yuntaobc commented 4 years ago

仔细看了看120行定义,翻了下seal的modulus.h,发现这个Batching()是个静态函数

//modulus.h,
SEAL_NODISCARD static inline SmallModulus Batching(

于是改了下wrapper.cpp120和121行,把 .def换成了.def_static,python2.7和python3封装都后,5_rotation.py都可以正常运行了,没报错.

//wrapper.cpp
.def_static("Batching", [](std::size_t poly_modulus_degree, int bit_size) { return PlainModulus::Batching(poly_modulus_degree, bit_size); })
.def_static("Batching", [](std::size_t poly_modulus_degree, std::vector<int> bit_sizes) { return PlainModulus::Batching(poly_modulus_degree, bit_sizes); });

谢谢解答奥