Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include Cython-AFF3CT example documentation. #83

Closed
wants to merge 3 commits into from
Closed

Include Cython-AFF3CT example documentation. #83

wants to merge 3 commits into from

Conversation

SubtleMuffin
Copy link

This PR introduces the accompanying documentation of Cython-AFF3CT example.

@kouchy
Copy link
Member

kouchy commented Oct 20, 2020

Thank you for this complete PR. I have to take the time to check the code. I will do that in the next days.

@@ -966,3 +966,318 @@ modules while in ``u.modules_stats`` the two dimension are switched.

.. note:: The full source code is available here:
https://github.com/aff3ct/my_project_with_aff3ct/blob/master/examples/openmp/src/main.cpp.


Cython-AFF3CT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cython Polar

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

This example serves as a template framework on how to use AFF3CT in Python.
This example is based on the `Cython`_, and steps of compiling this example
is included in the `README` file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main purpose of the cython_polar example is to wrap |AFF3CT| polar code features (frozen bits generation, polar encoding process and polar decoding process) in Python.
This example is based on Cython_ and can be used as a template to bind C++ |AFF3CT| features to Python.
Specific compilation steps are given in the corresponding repository.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done,

vector[vector[int]] polar_decode_multiple(const int, const int, const vector[bool] &, const vector[vector[float]] &)

Lines ``7-9`` support 2-D [ndarray](https://numpy.org/doc/stable/reference/arrays.ndarray.html) arguments, and return 2-D lists.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok!

The polar encoded bits
"""
assert info_bits.shape[1] > 0
return polar_encode_multiple(k, n, frozen_bits, info_bits)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should avoid to mention the py_polar_encode_multiple function.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not agree. Though this function is simple, but it provides a lot of performance gain, especially when user is trying to encode/decode multiple frames in Python. As you know, Python's for-loops are very expensive, not to mention we need to instantiate an encoder/decoder object every time we call it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I see your point so perhaps you can tell in the text the purpose of the multiple function?

The polar decoded bits
"""
assert received.shape[1] > 0
return polar_decode_multiple(k, n, frozen_bits, received)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should avoid to mention the py_polar_decode_multiple function.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No.

Comment on lines 1251 to 1274
.. code-block:: python
:caption: Setup function
:name: setup_py
:emphasize-lines:
:linenos:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize

codec = Extension(
name="codec",
sources=["codec.pyx"],
libraries=["aff3ct-2.3.5-384-gec40f26"],
library_dirs=["../../lib/aff3ct/build/lib"],
include_dirs=["../../lib/aff3ct/include", "../../lib/aff3ct/lib/cli/src", "../../lib/aff3ct/lib/MIPP/src", "../../lib/aff3ct/lib/MIPP/src", "../../lib/aff3ct/lib/rang/include"],
language="c++",
extra_compile_args=["-std=c++14"],
extra_link_args=["-std=c++14"]
)
setup(
name="codec",
ext_modules=cythonize([codec])
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we can remove this code, this is a configuration code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines +1176 to +1199
/**
* @brief Polar encoder for multiple frames
*
* @param k The number of information bits
* @param n The codeword length
* @param frozen_bits std::vector<bool>, frozen bits (length k)
* @param info_bits std::vector<int>, information bits (length k)
* @return auto Encoded codewords, std::vector<int> of length n
*/
auto polar_encode_multiple(const int k, const int n,
const std::vector<bool> &frozen_bits,
const std::vector<std::vector<int>> &info_bits) {
// populate vector
std::vector<std::vector<int>> encoded_bits;

// encode
module::Encoder_polar<int> polar_encoder(k, n, frozen_bits);
for (auto frame : info_bits) {
std::vector<int> encoded(n);
polar_encoder.encode(frame, encoded);
encoded_bits.push_back(encoded);
}
return encoded_bits;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove this code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is too many blocks of code and not so many explanations. If the code is given with no comments, you can simply add a link to the file in the my_project_with_aff3ct repo. The other solution is to keep this code here but to split it in smaller blocks and to explain what you are doing in the text.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Please refer to the newest commit.

Comment on lines +1222 to +1247
/**
* @brief Polar decoder for multiframe
*
* @param k The number of information bits
* @param n The codeword length
* @param frozen_bits std::vector<bool>, frozen bits (length k)
* @param received std::vector<float> soft symbols, BPSK, n_frame rows, n
* columns
* @return auto Decoded information bits, std::vector<std::vector<int>> of
* n_frame rows, k columns
*/
auto polar_decode_multiple(const int k, const int n,
const std::vector<bool> &frozen_bits,
const std::vector<std::vector<float>> &received) {
// populate vectors
std::vector<std::vector<int>> decoded_bits;

// encode
module::Decoder_polar_SC_naive<int> polar_decoder(k, n, frozen_bits);
for (auto frame : received) {
std::vector<int> decoded(k);
polar_decoder.decode_siho(frame, decoded);
decoded_bits.push_back(decoded);
}
return decoded_bits;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove this code too.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No.

@SubtleMuffin
Copy link
Author

Hey @kouchy , shall we wrap this up? Please let me know what else you would like to include!

@kouchy
Copy link
Member

kouchy commented Nov 10, 2020

Hi @SubtleMuffin,

Sry, we had a new lock-down in my country, I did not have the time to focus on this yet, but I do not forget you :-).

Regards.

@SubtleMuffin
Copy link
Author

Hey @kouchy : nothing is paramount than health. Please stay safe!

@kouchy kouchy deleted the branch aff3ct:development May 27, 2024 20:47
@kouchy kouchy closed this May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants