I have an example that fails on linux boxes while it works on Mac OS X's python and protobuf implementation.
The used protobuf version (both python lib and protoc compiler) is 3.3. The python version doesn't really seem to make any difference (tried 2.7.10, 2.7.12 & 2.7.13 on mac os & linux).
Minimal example i could come up with:
message FloatPrecisionTest {
float im_a_single_precision_float = 1;
}
py.test
def test_minimal():
python_float_which_means_c_double = 0.2
float_precision_test_proto = FloatPrecisionTest(im_a_single_precision_float=python_float_which_means_c_double)
# this assert should fail, but it doesn't on MacOS X
assert float_precision_test_proto.im_a_single_precision_float == python_float_which_means_c_double
so the presented test_minimal should fail in my opinion and it does so on linux - not so on Mac OS :/
Whats going on here?
Pure python is using double precision for float. However python cpp implementation calls our c++ code thus float is float precision. This is a known behavior difference that we are currently hard to change.
I guess your linux is using cpp implementation and Mac OS is using pure python?
Hi! Thanks for the answer - yeah ok that makes sense - but why is one using a pure python implementation and the other one uses the cpp implementation.
Can i force it somehow to use the cpp implementation?
You can set the environment PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp
This is a known behavior difference that we are currently hard to change.
i guess you don't want to pay for the performance penalty of doing the conversion in python (inside the creating program)?
i'm just wondering what protobuf with the python implementation does when you are sending that message over the wire - i hope the float conversion does happen in this case? :)
Most helpful comment
You can set the environment PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp
https://github.com/google/protobuf/blob/c44ca26fe89ed8a81d3ee475a2ccc1797141dbce/python/google/protobuf/pyext/README