Skip to content

Commit

Permalink
Doc update for examples
Browse files Browse the repository at this point in the history
  • Loading branch information
hschreiber committed Jun 3, 2024
1 parent 3773d2c commit f64342e
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,9 @@ namespace persistence_fields {
*
* \subsection fieldsexamples Examples
*
* Here is a list of examples using the module: TODO:
* \li \gudhi_example_link{Zigzag_persistence,example_simple_zigzag_filtration.cpp} - A simple example to showcase how
* to use the \ref Zigzag_persistence class.
*
* \li \gudhi_example_link{Zigzag_persistence,example_zzfiltration_from_file.cpp} - An example of a "stream-like" usage
* by reading of the filtration from a file.
* Here is a list of examples using the module:
* \li \gudhi_example_link{Persistence_field,example_field_operations.cpp} - A simple example to showcase how
* to use the different field element and operator classes.
*
* @}
*/
Expand Down
10 changes: 5 additions & 5 deletions src/Persistence_matrix/doc/Intro_persistence_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ namespace persistence_matrix {
*
* \subsection matrixexamples Examples
*
* Here is a list of examples using the module: TODO:
* \li \gudhi_example_link{Zigzag_persistence,example_simple_zigzag_filtration.cpp} - A simple example to showcase how
* to use the \ref Zigzag_persistence class.
* Here is a list of examples using the module:
* \li \gudhi_example_link{Persistence_matrix,representative_cycles_from_matrix.cpp} - A simple example on how to
* use the matrix to compute representative cycles.
*
* \li \gudhi_example_link{Zigzag_persistence,example_zzfiltration_from_file.cpp} - An example of a "stream-like" usage
* by reading of the filtration from a file.
* \li \gudhi_example_link{Persistence_matrix,simplex_tree_to_matrix.cpp} - A simplex example on how to build
* a the different matrices from a simplex tree.
*
* @}
*/
Expand Down
5 changes: 5 additions & 0 deletions src/Persistence_matrix/example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ if(TARGET TBB::tbb)
endif()
add_test(NAME Matrix_examples_simplex_tree_matrix COMMAND $<TARGET_FILE:Matrix_examples_simplex_tree_matrix>)

add_executable(Matrix_examples_field_operations example_field_operations.cpp)
if(TARGET TBB::tbb)
target_link_libraries(Matrix_examples_field_operations TBB::tbb)
endif()
add_test(NAME Matrix_examples_field_operations COMMAND $<TARGET_FILE:Matrix_examples_field_operations>)
91 changes: 91 additions & 0 deletions src/Persistence_matrix/example/example_field_operations.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
* See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
* Author(s): Hannah Schreiber
*
* Copyright (C) 2024 Inria
*
* Modification(s):
* - YYYY/MM Author: Description of the modification
*/

#include <iostream>

#include <gudhi/Fields/Z2_field.h>
#include <gudhi/Fields/Z2_field_operators.h>
#include <gudhi/Fields/Zp_field.h>
#include <gudhi/Fields/Zp_field_shared.h>
#include <gudhi/Fields/Zp_field_operators.h>

using Gudhi::persistence_fields::Z2_field_element;
using Gudhi::persistence_fields::Z2_field_operators;
using Gudhi::persistence_fields::Zp_field_element;
using Gudhi::persistence_fields::Shared_Zp_field_element;
using Gudhi::persistence_fields::Zp_field_operators;

template<class Field_element>
void field_element_example(int ini){
Field_element e = ini;
std::cout << "Element e initialized with " << ini << "\n";
std::cout << "Characteristic: " << e.get_characteristic() << "\n";
std::cout << "e: " << e << "\n";
std::cout << "e + 3: " << (e + 3) << "\n";
std::cout << "3 + e: " << (3 + e) << "\n";
e += 3;
std::cout << "e += 3: " << e << "\n";
int t = 3;
t += e; //standard integer addition
std::cout << "3 += e: " << t << " //standard integer addition\n";
std::cout << "e - 4: " << (e - 4) << "\n";
std::cout << "4 - e: " << (4 - e) << "\n";
e -= 4;
std::cout << "e -= 4: " << e << "\n";
t = 4;
t -= e; //standard integer addition
std::cout << "4 -= e: " << t << " //standard integer substraction\n";
std::cout << "e * 6: " << (e * 6) << "\n";
std::cout << "6 * e: " << (6 * e) << "\n";
e *= 6;
std::cout << "e *= 6: " << e << "\n";
t = 6;
t *= e; //standard integer addition
std::cout << "6 *= e: " << t << " //standard integer multiplication\n";
std::cout << "Inverse: " << e.get_inverse() << "\n";
}

template<class Field_operator>
void field_operator_example(const Field_operator& op){
std::cout << "Characteristic: " << op.get_characteristic() << "\n";
std::cout << "2 + 3: " << op.add(2u, 3u) << "\n";
std::cout << "3 + 2: " << op.add(3u, 2u) << "\n";
std::cout << "10 - 4: " << op.substract(10u, 4u) << "\n";
std::cout << "4 - 10: " << op.substract(4u, 10u) << "\n";
std::cout << "3 * 6: " << op.multiply(3u, 6u) << "\n";
std::cout << "6 * 3: " << op.multiply(6u, 3u) << "\n";
std::cout << "Value of 7: " << op.get_value(7u) << "\n";
std::cout << "Inverse of 7: " << op.get_inverse(7u) << "\n";
}

int main() {
std::cout << "=== Example for Z2 field elements ===\n\n";
field_element_example<Z2_field_element>(2);

std::cout << "\n=== Example for Z3 field elements ===\n\n";
field_element_example<Zp_field_element<3> >(5);

std::cout << "\n=== Example for Z5 field elements ===\n\n";
Shared_Zp_field_element<>::initialize(5);
field_element_example<Shared_Zp_field_element<> >(4);

std::cout << "\n+++ Example for Z2 field operator +++\n\n";
Z2_field_operators z2op;
field_operator_example(z2op);

std::cout << "\n+++ Example for Z3 field operator +++\n\n";
Zp_field_operators zpop;
zpop.set_characteristic(3);
field_operator_example(zpop);

std::cout << "\n+++ Example for Z5 field operator +++\n\n";
zpop.set_characteristic(5);
field_operator_example(zpop);
}
5 changes: 5 additions & 0 deletions src/common/doc/examples.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,10 @@
* @example example_one_skeleton_rips_from_distance_matrix.cpp
* @example example_one_skeleton_rips_from_points.cpp
* @example example_rips_complex_from_off_file.cpp
* \section Persistence_matrix_example_section Persistence_matrix
* @example representative_cycles_from_matrix.cpp
* @example simplex_tree_to_matrix.cpp
* \section Persistence_fields_example_section Persistence_field
* @example example_field_operations.cpp
*/

0 comments on commit f64342e

Please sign in to comment.