mtlearn 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of mtlearn might be problematic. Click here for more details.

Files changed (138) hide show
  1. mtlearn-0.1.1/.gitignore +8 -0
  2. mtlearn-0.1.1/.gitmodules +3 -0
  3. mtlearn-0.1.1/CMakeLists.txt +92 -0
  4. mtlearn-0.1.1/PKG-INFO +83 -0
  5. mtlearn-0.1.1/Pipfile +11 -0
  6. mtlearn-0.1.1/README.md +67 -0
  7. mtlearn-0.1.1/bindings/CMakeLists.txt +224 -0
  8. mtlearn-0.1.1/bindings/module.cpp +37 -0
  9. mtlearn-0.1.1/cmake/README.md +1 -0
  10. mtlearn-0.1.1/external/MorphologicalAttributeFilters/.git +1 -0
  11. mtlearn-0.1.1/external/MorphologicalAttributeFilters/.gitignore +17 -0
  12. mtlearn-0.1.1/external/MorphologicalAttributeFilters/.vscode/c_cpp_properties.json +24 -0
  13. mtlearn-0.1.1/external/MorphologicalAttributeFilters/.vscode/extensions.json +5 -0
  14. mtlearn-0.1.1/external/MorphologicalAttributeFilters/.vscode/launch.json +104 -0
  15. mtlearn-0.1.1/external/MorphologicalAttributeFilters/.vscode/settings.json +86 -0
  16. mtlearn-0.1.1/external/MorphologicalAttributeFilters/.vscode/tasks.json +43 -0
  17. mtlearn-0.1.1/external/MorphologicalAttributeFilters/CMakeLists.txt +91 -0
  18. mtlearn-0.1.1/external/MorphologicalAttributeFilters/LICENSE +674 -0
  19. mtlearn-0.1.1/external/MorphologicalAttributeFilters/MANIFEST.in +11 -0
  20. mtlearn-0.1.1/external/MorphologicalAttributeFilters/README.md +38 -0
  21. mtlearn-0.1.1/external/MorphologicalAttributeFilters/dat/article-2.png +0 -0
  22. mtlearn-0.1.1/external/MorphologicalAttributeFilters/dat/attr.png +0 -0
  23. mtlearn-0.1.1/external/MorphologicalAttributeFilters/dat/believe.pgm +4 -0
  24. mtlearn-0.1.1/external/MorphologicalAttributeFilters/dat/brain2.pgm +0 -0
  25. mtlearn-0.1.1/external/MorphologicalAttributeFilters/dat/cable.png +0 -0
  26. mtlearn-0.1.1/external/MorphologicalAttributeFilters/dat/images/cameraman.tif +0 -0
  27. mtlearn-0.1.1/external/MorphologicalAttributeFilters/dat/images/house.tif +0 -0
  28. mtlearn-0.1.1/external/MorphologicalAttributeFilters/dat/images/jetplane.tif +0 -0
  29. mtlearn-0.1.1/external/MorphologicalAttributeFilters/dat/images/lake.tif +0 -0
  30. mtlearn-0.1.1/external/MorphologicalAttributeFilters/dat/images/lena_gray_512.tif +0 -0
  31. mtlearn-0.1.1/external/MorphologicalAttributeFilters/dat/images/livingroom.tif +0 -0
  32. mtlearn-0.1.1/external/MorphologicalAttributeFilters/dat/images/mandril_gray.tif +0 -0
  33. mtlearn-0.1.1/external/MorphologicalAttributeFilters/dat/images/peppers_gray.tif +0 -0
  34. mtlearn-0.1.1/external/MorphologicalAttributeFilters/dat/images/pirate.tif +0 -0
  35. mtlearn-0.1.1/external/MorphologicalAttributeFilters/dat/images/walkbridge.tif +0 -0
  36. mtlearn-0.1.1/external/MorphologicalAttributeFilters/dat/images/woman_blonde.tif +0 -0
  37. mtlearn-0.1.1/external/MorphologicalAttributeFilters/dat/images/woman_darkhair.tif +0 -0
  38. mtlearn-0.1.1/external/MorphologicalAttributeFilters/dat/imgObjetos.png +0 -0
  39. mtlearn-0.1.1/external/MorphologicalAttributeFilters/dat/imgTeste-2.png +0 -0
  40. mtlearn-0.1.1/external/MorphologicalAttributeFilters/dat/imgTeste-inv.png +0 -0
  41. mtlearn-0.1.1/external/MorphologicalAttributeFilters/dat/imgTeste.png +0 -0
  42. mtlearn-0.1.1/external/MorphologicalAttributeFilters/dat/imgTeste.txt +500 -0
  43. mtlearn-0.1.1/external/MorphologicalAttributeFilters/dat/knee.pgm +0 -0
  44. mtlearn-0.1.1/external/MorphologicalAttributeFilters/dat/lena.pgm +4 -0
  45. mtlearn-0.1.1/external/MorphologicalAttributeFilters/dat/mesa-wonder.jpeg +0 -0
  46. mtlearn-0.1.1/external/MorphologicalAttributeFilters/dat/mesa.png +0 -0
  47. mtlearn-0.1.1/external/MorphologicalAttributeFilters/dat/synthetic.pgm +15424 -0
  48. mtlearn-0.1.1/external/MorphologicalAttributeFilters/dat/synthetic.png +0 -0
  49. mtlearn-0.1.1/external/MorphologicalAttributeFilters/dat/val_000.png +0 -0
  50. mtlearn-0.1.1/external/MorphologicalAttributeFilters/dat/wrist.pgm +0 -0
  51. mtlearn-0.1.1/external/MorphologicalAttributeFilters/external/stb/stb_image.cpp +5 -0
  52. mtlearn-0.1.1/external/MorphologicalAttributeFilters/external/stb/stb_image.h +7987 -0
  53. mtlearn-0.1.1/external/MorphologicalAttributeFilters/external/stb/stb_image_write.h +1724 -0
  54. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/CMakeLists.txt +95 -0
  55. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/attributes/AreaComputer.hpp +25 -0
  56. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/attributes/AttributeComputedIncrementally.cpp +477 -0
  57. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/attributes/AttributeComputedIncrementally.hpp +58 -0
  58. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/attributes/AttributeComputer.hpp +38 -0
  59. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/attributes/AttributeFactory.hpp +128 -0
  60. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/attributes/AttributeNames.hpp +554 -0
  61. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/attributes/BitquadsComputer.hpp +71 -0
  62. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/attributes/BoundingBoxComputer.hpp +113 -0
  63. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/attributes/ComputerAttributeBasedBitQuads.hpp +833 -0
  64. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/attributes/ComputerMSER.hpp +104 -0
  65. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/attributes/GrayLevelStatsComputer.hpp +97 -0
  66. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/attributes/MomentBasedAttributeComputer.hpp +304 -0
  67. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/attributes/TreeTopologyComputer.hpp +135 -0
  68. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/attributes/VolumeComputer.hpp +54 -0
  69. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/contours/ContoursComputedIncrementally.hpp +559 -0
  70. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/dataStructure/FastQueue.hpp +67 -0
  71. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/dataStructure/FastStack.hpp +74 -0
  72. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/filters/AttributeFilters.cpp +72 -0
  73. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/filters/AttributeFilters.hpp +368 -0
  74. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/filters/AttributeOpeningPrimitivesFamily.cpp +119 -0
  75. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/filters/AttributeOpeningPrimitivesFamily.hpp +71 -0
  76. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/filters/ExtinctionValues.hpp +154 -0
  77. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/filters/UltimateAttributeOpening.hpp +171 -0
  78. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/trees/BuilderMorphologicalTreeByUnionFind.hpp +851 -0
  79. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/trees/MorphologicalTree.cpp +264 -0
  80. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/trees/MorphologicalTree.hpp +912 -0
  81. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/trees/MorphologicalTree.tpp +81 -0
  82. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/trees/NodeMT.hpp +357 -0
  83. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/trees/NodeMTArena.hpp +303 -0
  84. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/trees/NodeRes.hpp +97 -0
  85. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/trees/ResidualTree.hpp +400 -0
  86. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/utils/AdjacencyRelation.hpp +361 -0
  87. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/utils/Common.hpp +146 -0
  88. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/utils/ComputerDerivatives.hpp +78 -0
  89. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/utils/Image.hpp +188 -0
  90. mtlearn-0.1.1/external/MorphologicalAttributeFilters/mmcfilters/utils/PixelSetManager.hpp +387 -0
  91. mtlearn-0.1.1/external/MorphologicalAttributeFilters/notebooks/Attribute_Filters.ipynb +622 -0
  92. mtlearn-0.1.1/external/MorphologicalAttributeFilters/notebooks/Exemplo_ToS_Contorno.ipynb +416 -0
  93. mtlearn-0.1.1/external/MorphologicalAttributeFilters/notebooks/Filter.ipynb +243 -0
  94. mtlearn-0.1.1/external/MorphologicalAttributeFilters/notebooks/SimpleExamples.ipynb +1547 -0
  95. mtlearn-0.1.1/external/MorphologicalAttributeFilters/notebooks/SimpleExamples2.ipynb +2296 -0
  96. mtlearn-0.1.1/external/MorphologicalAttributeFilters/notebooks/ToS.ipynb +692 -0
  97. mtlearn-0.1.1/external/MorphologicalAttributeFilters/notebooks/UAO_Exemplos.ipynb +642 -0
  98. mtlearn-0.1.1/external/MorphologicalAttributeFilters/old_setup.py +165 -0
  99. mtlearn-0.1.1/external/MorphologicalAttributeFilters/pybind11.cmake +11 -0
  100. mtlearn-0.1.1/external/MorphologicalAttributeFilters/pybinds/AttributeComputedIncrementallyPybind.hpp +153 -0
  101. mtlearn-0.1.1/external/MorphologicalAttributeFilters/pybinds/AttributeFiltersPybind.hpp +115 -0
  102. mtlearn-0.1.1/external/MorphologicalAttributeFilters/pybinds/AttributeOpeningPrimitivesFamilyPybind.hpp +45 -0
  103. mtlearn-0.1.1/external/MorphologicalAttributeFilters/pybinds/ContoursComputedIncrementallyPybind.hpp +18 -0
  104. mtlearn-0.1.1/external/MorphologicalAttributeFilters/pybinds/ExtinctionValuesPybind.hpp +59 -0
  105. mtlearn-0.1.1/external/MorphologicalAttributeFilters/pybinds/MorphologicalTreePybind.hpp +171 -0
  106. mtlearn-0.1.1/external/MorphologicalAttributeFilters/pybinds/PybindUtils.hpp +109 -0
  107. mtlearn-0.1.1/external/MorphologicalAttributeFilters/pybinds/ResidualTreePybind.hpp +55 -0
  108. mtlearn-0.1.1/external/MorphologicalAttributeFilters/pybinds/UltimateAttributeOpeningPybind.hpp +45 -0
  109. mtlearn-0.1.1/external/MorphologicalAttributeFilters/pybinds/mmcfilters.cpp +403 -0
  110. mtlearn-0.1.1/external/MorphologicalAttributeFilters/pyproject.toml +77 -0
  111. mtlearn-0.1.1/external/MorphologicalAttributeFilters/python/mmcfilters/__init__.py +45 -0
  112. mtlearn-0.1.1/external/MorphologicalAttributeFilters/python/mmcfilters/test.py +48 -0
  113. mtlearn-0.1.1/external/MorphologicalAttributeFilters/tests/CMakeLists.txt +54 -0
  114. mtlearn-0.1.1/external/MorphologicalAttributeFilters/tests/TestMorphologicalTree.cpp +39 -0
  115. mtlearn-0.1.1/external/MorphologicalAttributeFilters/tests/TesteAdjacencyUC.cpp +27 -0
  116. mtlearn-0.1.1/external/MorphologicalAttributeFilters/tests/TesteBitQuads.cpp +48 -0
  117. mtlearn-0.1.1/external/MorphologicalAttributeFilters/tests/TesteContours.cpp +207 -0
  118. mtlearn-0.1.1/external/MorphologicalAttributeFilters/tests/TesteContours2.cpp +106 -0
  119. mtlearn-0.1.1/external/MorphologicalAttributeFilters/tests/TesteContours3.cpp +107 -0
  120. mtlearn-0.1.1/external/MorphologicalAttributeFilters/tests/Tests.hpp +1198 -0
  121. mtlearn-0.1.1/external/MorphologicalAttributeFilters/tests/testeComputerAllAttributes.cpp +64 -0
  122. mtlearn-0.1.1/external/MorphologicalAttributeFilters/tests/testeComputerAttribute.cpp +107 -0
  123. mtlearn-0.1.1/external/MorphologicalAttributeFilters/tests/testeResidualTree.cpp +74 -0
  124. mtlearn-0.1.1/external/MorphologicalAttributeFilters/tests/testeTreeOfShapes.cpp +92 -0
  125. mtlearn-0.1.1/external/MorphologicalAttributeFilters/tmp/output_windows.txt +170 -0
  126. mtlearn-0.1.1/notebooks/.ipynb_checkpoints/Untitled-checkpoint.ipynb +6 -0
  127. mtlearn-0.1.1/notebooks/Untitled.ipynb +64 -0
  128. mtlearn-0.1.1/pyproject.toml +50 -0
  129. mtlearn-0.1.1/python/mtlearn/__init__.py +17 -0
  130. mtlearn-0.1.1/python/mtlearn/__pycache__/__init__.cpython-312.pyc +0 -0
  131. mtlearn-0.1.1/src/CMakeLists.txt +43 -0
  132. mtlearn-0.1.1/src/main.cpp +13 -0
  133. mtlearn-0.1.1/src/mtlearn/core.cpp +36 -0
  134. mtlearn-0.1.1/src/mtlearn/core.hpp +21 -0
  135. mtlearn-0.1.1/tests/CMakeLists.txt +104 -0
  136. mtlearn-0.1.1/tests/basic.cpp +14 -0
  137. mtlearn-0.1.1/tests/python/test_bindings.py +30 -0
  138. mtlearn-0.1.1/tests/test_interpreter.cpp +93 -0
@@ -0,0 +1,8 @@
1
+ build/
2
+ dist/
3
+ __pycache__/
4
+ *.egg-info/
5
+ .pytest_cache/
6
+ .scannerwork/
7
+ .idea/
8
+ .vscode/
@@ -0,0 +1,3 @@
1
+ [submodule "external/MorphologicalAttributeFilters"]
2
+ path = external/MorphologicalAttributeFilters
3
+ url = https://github.com/wonderalexandre/MorphologicalAttributeFilters
@@ -0,0 +1,92 @@
1
+ cmake_minimum_required(VERSION 3.20)
2
+
3
+ # ---------------------------------------------------------------------------
4
+ # Projeto principal do mtlearn
5
+ # ---------------------------------------------------------------------------
6
+ # Este arquivo prepara o ambiente CMake para compilar tanto a biblioteca C++
7
+ # quanto os bindings Python e executáveis de teste. Ele pressupõe que o
8
+ # repositório MorphologicalAttributeFilters esteja disponível como submódulo em
9
+ # external/MorphologicalAttributeFilters.
10
+
11
+ project(mtlearn LANGUAGES CXX)
12
+
13
+ # Opções expostas para quem consome o projeto via CMake ou pyproject.toml.
14
+ # - MTLEARN_BUILD_PYTHON : habilita o módulo pybind11 exportado para Python.
15
+ # - MTLEARN_BUILD_TESTS : compila os testes C++ e scripts auxiliares.
16
+ # - MTLEARN_ENABLE_ASSERTS: controla o uso de asserts na biblioteca base.
17
+ # - MTLEARN_ENABLE_EMBED : ativa testes que inicializam o interpretador Python
18
+ # embutido (útil apenas em ambientes com PyTorch completo).
19
+ option(MTLEARN_BUILD_PYTHON "Build pybind11 bindings" ON)
20
+ option(MTLEARN_BUILD_TESTS "Build C++ tests" OFF)
21
+ option(MTLEARN_ENABLE_ASSERTS "Keep runtime asserts even in Release" OFF)
22
+ option(MTLEARN_ENABLE_EMBED "Enable embedded Python interpreter tests" OFF)
23
+
24
+ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
25
+ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
26
+ set(CMAKE_CXX_STANDARD 20)
27
+ set(CMAKE_CXX_STANDARD_REQUIRED ON)
28
+ set(CMAKE_CXX_EXTENSIONS OFF)
29
+
30
+ # Diretório extra para macros utilitárias do projeto.
31
+ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
32
+
33
+ # Respeita variáveis fornecidas via linha de comando/pyproject para localizar o
34
+ # mesmo interpretador Python em todos os subprojetos.
35
+ if(DEFINED PYTHON_EXECUTABLE AND NOT DEFINED Python3_EXECUTABLE)
36
+ set(Python3_EXECUTABLE "${PYTHON_EXECUTABLE}" CACHE FILEPATH "Python interpreter" FORCE)
37
+ endif()
38
+ if(DEFINED PYTHON_LIBRARY_DIR AND NOT DEFINED Python3_LIBRARY_DIR)
39
+ set(Python3_LIBRARY_DIR "${PYTHON_LIBRARY_DIR}" CACHE PATH "Python library directory" FORCE)
40
+ endif()
41
+ if(DEFINED Python3_EXECUTABLE AND NOT DEFINED Python3_ROOT_DIR)
42
+ get_filename_component(_mtlearn_py_bin "${Python3_EXECUTABLE}" DIRECTORY)
43
+ get_filename_component(_mtlearn_py_root "${_mtlearn_py_bin}" DIRECTORY)
44
+ set(Python3_ROOT_DIR "${_mtlearn_py_root}" CACHE PATH "Python root" FORCE)
45
+ endif()
46
+
47
+ set(MTLEARN_MMCFILTERS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/MorphologicalAttributeFilters")
48
+ # Garante que o submódulo do mmcfilters está disponível (obrigatório).
49
+ if(NOT EXISTS "${MTLEARN_MMCFILTERS_DIR}/CMakeLists.txt")
50
+ message(FATAL_ERROR "Dependência mmcfilters não encontrada em ${MTLEARN_MMCFILTERS_DIR}. Adicione como submódulo ou ajuste o caminho.")
51
+ endif()
52
+
53
+ add_subdirectory(${MTLEARN_MMCFILTERS_DIR} mmcfilters)
54
+
55
+ set(_mmc_target "")
56
+ if(TARGET mmcfilters_lib)
57
+ set(_mmc_target mmcfilters_lib)
58
+ elseif(TARGET mmcfilters::core)
59
+ set(_mmc_target mmcfilters::core)
60
+ endif()
61
+
62
+ if(NOT _mmc_target)
63
+ message(FATAL_ERROR "Não foi possível localizar o alvo principal do mmcfilters.")
64
+ endif()
65
+
66
+ # O mmcfilters oferece o alvo principal de algoritmos morfológicos. Ajustamos as
67
+ # flags globais de asserts dependendo da opção fornecida ao projeto.
68
+ if(MTLEARN_ENABLE_ASSERTS)
69
+ target_compile_definitions(${_mmc_target} PUBLIC MMCFILTERS_ENABLE_ASSERTS)
70
+ target_compile_options(${_mmc_target}
71
+ PUBLIC
72
+ $<$<CXX_COMPILER_ID:MSVC>:/UNDEBUG>
73
+ $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-UNDEBUG>
74
+ )
75
+ else()
76
+ target_compile_definitions(${_mmc_target} PUBLIC NDEBUG)
77
+ endif()
78
+
79
+ # Diretório com as bibliotecas/aplicações C++ próprias do mtlearn.
80
+ add_subdirectory(src)
81
+
82
+ if(MTLEARN_BUILD_PYTHON)
83
+ # Inclui os bindings pybind11 que produzem o módulo _mtlearn e o pacote
84
+ # Python correspondente.
85
+ add_subdirectory(bindings)
86
+ endif()
87
+
88
+ if(MTLEARN_BUILD_TESTS)
89
+ enable_testing()
90
+ # Suite de testes C++ (smoke tests e interpretador python embutido).
91
+ add_subdirectory(tests)
92
+ endif()
mtlearn-0.1.1/PKG-INFO ADDED
@@ -0,0 +1,83 @@
1
+ Metadata-Version: 2.2
2
+ Name: mtlearn
3
+ Version: 0.1.1
4
+ Summary: Morphological tree learning utilities built on top of mmcfilters
5
+ Author-Email: Wonder Alexandre Luz Alves <worderalexandre@gmail.com>
6
+ Classifier: Programming Language :: Python
7
+ Classifier: Programming Language :: C++
8
+ Classifier: Topic :: Scientific/Engineering :: Image Processing
9
+ Classifier: Operating System :: MacOS
10
+ Classifier: Operating System :: Microsoft :: Windows
11
+ Classifier: Operating System :: POSIX :: Linux
12
+ Requires-Python: >=3.9
13
+ Requires-Dist: mmcfilters>=0.1.20
14
+ Requires-Dist: torch>=2.0
15
+ Description-Content-Type: text/markdown
16
+
17
+ # MTLearn
18
+
19
+ Projeto C++/Python que reutiliza o núcleo `mmcfilters::core` para experimentos
20
+ de aprendizado em árvores morfológicas.
21
+
22
+ ## Organização
23
+
24
+ - `cmake/` — utilitários e módulos adicionais.
25
+ - `external/` — dependências de código fonte (submódulos ou vendorizadas).
26
+ - `src/` — código-fonte C++ da aplicação/biblioteca.
27
+ - `bindings/` — módulo pybind11 com integração PyTorch específica do projeto.
28
+ - `python/mtlearn/` — pacote Python puro.
29
+ - `tests/` — testes C++ (compilados apenas se habilitados via CMake).
30
+
31
+ ## Dependência principal
32
+
33
+ Adicionar `MorphologicalAttributeFilters` como submódulo:
34
+
35
+ ```bash
36
+ git submodule add https://github.com/wonderalexandre/MorphologicalAttributeFilters external/MorphologicalAttributeFilters
37
+ ```
38
+
39
+ ## Build C++
40
+
41
+ Instale previamente PyTorch (CPU ou CUDA) e exponha o caminho CMake, por exemplo:
42
+
43
+ ```bash
44
+ python -c "import torch; print(torch.utils.cmake_prefix_path)"
45
+ export Torch_DIR=$(python -c "import torch; print(torch.utils.cmake_prefix_path)")
46
+ cmake -S . -B build -DMTLEARN_BUILD_TESTS=ON
47
+ cmake --build build
48
+ ```
49
+
50
+ - `MTLEARN_BUILD_TESTS` controla se a pasta `tests/` é adicionada ao build
51
+ (padrão `OFF`, recomendado para empacotamento via `pyproject.toml`).
52
+ - `MTLEARN_ENABLE_EMBED` habilita testes que inicializam o interpretador
53
+ embutido; por padrão permanece `OFF` para evitar dependências extras do
54
+ PyTorch.
55
+ - `MTLEARN_ENABLE_ASSERTS` mantém asserts do núcleo C++ ativos mesmo em build
56
+ Release (padrão `OFF`).
57
+
58
+ Para rodar o teste com interpretador embutido:
59
+
60
+ ```bash
61
+ cmake -S . -B build -DMTLEARN_BUILD_TESTS=ON -DMTLEARN_ENABLE_EMBED=ON \
62
+ -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") \
63
+ -DPYTHON_LIBRARY_DIR=$(python3 -c "import sysconfig; print(sysconfig.get_config_var('LIBDIR'))")
64
+ cmake --build build
65
+ ctest --test-dir build -R mtl_interpreter_test --output-on-failure
66
+ ```
67
+
68
+ > Antes de habilitar `MTLEARN_ENABLE_EMBED`, verifique se o ambiente consegue
69
+ > importar o PyTorch desejado (`python -c 'import torch'`). Caso contrário o
70
+ > teste será ignorado (ou o próprio PyTorch precisará ser reinstalado com um
71
+ > build compatível com o seu hardware).
72
+
73
+ ## Build Python (wheel)
74
+
75
+ ```bash
76
+ pip install scikit-build-core pybind11 torch
77
+ python -m build
78
+ pip install -e .
79
+ ```
80
+
81
+ Para uma instalação limpa via `pyproject.toml` não são necessários argumentos
82
+ extras: os valores padrão já deixam asserts, testes e interpretador embutido
83
+ desativados.
mtlearn-0.1.1/Pipfile ADDED
@@ -0,0 +1,11 @@
1
+ [[source]]
2
+ url = "https://pypi.org/simple"
3
+ verify_ssl = true
4
+ name = "pypi"
5
+
6
+ [packages]
7
+
8
+ [dev-packages]
9
+
10
+ [requires]
11
+ python_version = "3.13"
@@ -0,0 +1,67 @@
1
+ # MTLearn
2
+
3
+ Projeto C++/Python que reutiliza o núcleo `mmcfilters::core` para experimentos
4
+ de aprendizado em árvores morfológicas.
5
+
6
+ ## Organização
7
+
8
+ - `cmake/` — utilitários e módulos adicionais.
9
+ - `external/` — dependências de código fonte (submódulos ou vendorizadas).
10
+ - `src/` — código-fonte C++ da aplicação/biblioteca.
11
+ - `bindings/` — módulo pybind11 com integração PyTorch específica do projeto.
12
+ - `python/mtlearn/` — pacote Python puro.
13
+ - `tests/` — testes C++ (compilados apenas se habilitados via CMake).
14
+
15
+ ## Dependência principal
16
+
17
+ Adicionar `MorphologicalAttributeFilters` como submódulo:
18
+
19
+ ```bash
20
+ git submodule add https://github.com/wonderalexandre/MorphologicalAttributeFilters external/MorphologicalAttributeFilters
21
+ ```
22
+
23
+ ## Build C++
24
+
25
+ Instale previamente PyTorch (CPU ou CUDA) e exponha o caminho CMake, por exemplo:
26
+
27
+ ```bash
28
+ python -c "import torch; print(torch.utils.cmake_prefix_path)"
29
+ export Torch_DIR=$(python -c "import torch; print(torch.utils.cmake_prefix_path)")
30
+ cmake -S . -B build -DMTLEARN_BUILD_TESTS=ON
31
+ cmake --build build
32
+ ```
33
+
34
+ - `MTLEARN_BUILD_TESTS` controla se a pasta `tests/` é adicionada ao build
35
+ (padrão `OFF`, recomendado para empacotamento via `pyproject.toml`).
36
+ - `MTLEARN_ENABLE_EMBED` habilita testes que inicializam o interpretador
37
+ embutido; por padrão permanece `OFF` para evitar dependências extras do
38
+ PyTorch.
39
+ - `MTLEARN_ENABLE_ASSERTS` mantém asserts do núcleo C++ ativos mesmo em build
40
+ Release (padrão `OFF`).
41
+
42
+ Para rodar o teste com interpretador embutido:
43
+
44
+ ```bash
45
+ cmake -S . -B build -DMTLEARN_BUILD_TESTS=ON -DMTLEARN_ENABLE_EMBED=ON \
46
+ -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") \
47
+ -DPYTHON_LIBRARY_DIR=$(python3 -c "import sysconfig; print(sysconfig.get_config_var('LIBDIR'))")
48
+ cmake --build build
49
+ ctest --test-dir build -R mtl_interpreter_test --output-on-failure
50
+ ```
51
+
52
+ > Antes de habilitar `MTLEARN_ENABLE_EMBED`, verifique se o ambiente consegue
53
+ > importar o PyTorch desejado (`python -c 'import torch'`). Caso contrário o
54
+ > teste será ignorado (ou o próprio PyTorch precisará ser reinstalado com um
55
+ > build compatível com o seu hardware).
56
+
57
+ ## Build Python (wheel)
58
+
59
+ ```bash
60
+ pip install scikit-build-core pybind11 torch
61
+ python -m build
62
+ pip install -e .
63
+ ```
64
+
65
+ Para uma instalação limpa via `pyproject.toml` não são necessários argumentos
66
+ extras: os valores padrão já deixam asserts, testes e interpretador embutido
67
+ desativados.
@@ -0,0 +1,224 @@
1
+ # ---------------------------------------------------------------------------
2
+ # Configuração do módulo pybind11 (_mtlearn) com integração ao PyTorch.
3
+ # ---------------------------------------------------------------------------
4
+
5
+ # Em alguns ambientes (ex.: pip editable) Torch_DIR pode apontar para um local
6
+ # inválido. O trecho abaixo invalida a cache caso não exista o TorchConfig.
7
+ if(Torch_DIR AND NOT EXISTS "${Torch_DIR}/TorchConfig.cmake")
8
+ unset(Torch_DIR CACHE)
9
+ endif()
10
+
11
+ # Preferimos uma instalação existente do pybind11, mas usamos FetchContent
12
+ # caso não haja configuração previamente instalada.
13
+ find_package(pybind11 CONFIG QUIET)
14
+
15
+ if(NOT pybind11_FOUND)
16
+ include(FetchContent)
17
+ FetchContent_Declare(
18
+ pybind11
19
+ URL https://github.com/pybind/pybind11/archive/refs/tags/v2.13.1.tar.gz
20
+ DOWNLOAD_EXTRACT_TIMESTAMP TRUE
21
+ )
22
+ FetchContent_MakeAvailable(pybind11)
23
+ endif()
24
+
25
+ find_package(Python3 COMPONENTS Interpreter QUIET)
26
+
27
+ # Tentamos descobrir o Torch_DIR a partir do Python ativo, da site-packages do
28
+ # usuário ou de variáveis de ambiente (útil para builds dentro do pip).
29
+ if(NOT Torch_DIR)
30
+ if(Python3_Interpreter_FOUND)
31
+ execute_process(
32
+ COMMAND "${Python3_EXECUTABLE}" "-c" "import torch, sys; sys.stdout.write(torch.utils.cmake_prefix_path)"
33
+ OUTPUT_VARIABLE _torch_cmake_prefix
34
+ RESULT_VARIABLE _torch_query_result
35
+ OUTPUT_STRIP_TRAILING_WHITESPACE
36
+ ERROR_QUIET
37
+ )
38
+ if(_torch_query_result EQUAL 0 AND _torch_cmake_prefix)
39
+ set(Torch_DIR "${_torch_cmake_prefix}" CACHE PATH "Torch CMake config path" FORCE)
40
+ endif()
41
+ endif()
42
+ endif()
43
+
44
+ if((NOT Torch_DIR) AND Python3_Interpreter_FOUND)
45
+ execute_process(
46
+ COMMAND "${Python3_EXECUTABLE}" "-c" "import site, sys; paths = []\nfor p in site.getsitepackages():\n if p not in paths:\n paths.append(p)\nusr = site.getusersitepackages()\nif usr and usr not in paths:\n paths.append(usr)\nsys.stdout.write('\n'.join(paths))"
47
+ OUTPUT_VARIABLE _torch_site_paths
48
+ RESULT_VARIABLE _torch_site_result
49
+ OUTPUT_STRIP_TRAILING_WHITESPACE
50
+ ERROR_QUIET
51
+ )
52
+ if(_torch_site_result EQUAL 0 AND _torch_site_paths)
53
+ string(REPLACE "\r\n" ";" _torch_site_paths "${_torch_site_paths}")
54
+ string(REPLACE "\n" ";" _torch_site_paths "${_torch_site_paths}")
55
+ foreach(_site_path IN LISTS _torch_site_paths)
56
+ if(EXISTS "${_site_path}/torch/share/cmake/Torch/TorchConfig.cmake")
57
+ set(Torch_DIR "${_site_path}/torch/share/cmake/Torch" CACHE PATH "Torch CMake config path" FORCE)
58
+ break()
59
+ endif()
60
+ endforeach()
61
+ endif()
62
+ endif()
63
+
64
+ find_package(Torch REQUIRED)
65
+
66
+ pybind11_add_module(_mtlearn module.cpp)
67
+
68
+ target_link_libraries(_mtlearn PRIVATE mtlearn::core)
69
+
70
+ # Começamos com os includes propagados pelo Torch e, em seguida, adicionamos
71
+ # manualmente caminhos detectados em diferentes variantes de instalação
72
+ # (conda/venv/libtorch standalone). Essa lista é compartilhada com os testes.
73
+ set(_mtlearn_torch_includes ${TORCH_INCLUDE_DIRS})
74
+ set(_mtlearn_torch_valid_includes "")
75
+ foreach(_inc IN LISTS _mtlearn_torch_includes)
76
+ if(EXISTS "${_inc}")
77
+ list(APPEND _mtlearn_torch_valid_includes "${_inc}")
78
+ if(EXISTS "${_inc}/torch/csrc/api/include")
79
+ list(APPEND _mtlearn_torch_valid_includes "${_inc}/torch/csrc/api/include")
80
+ endif()
81
+ if(EXISTS "${_inc}/ATen")
82
+ list(APPEND _mtlearn_torch_valid_includes "${_inc}/ATen")
83
+ endif()
84
+ endif()
85
+ endforeach()
86
+ set(_mtlearn_torch_includes ${_mtlearn_torch_valid_includes})
87
+
88
+ if(TORCH_INSTALL_PREFIX)
89
+ file(GLOB _mtlearn_torch_site_includes "${TORCH_INSTALL_PREFIX}/lib/python*/site-packages/torch/include")
90
+ file(GLOB _mtlearn_torch_pkg_includes "${TORCH_INSTALL_PREFIX}/pkgs/libtorch*/include")
91
+ foreach(_cand IN LISTS _mtlearn_torch_site_includes _mtlearn_torch_pkg_includes)
92
+ if(EXISTS "${_cand}" AND NOT "${_cand}" IN_LIST _mtlearn_torch_includes)
93
+ list(APPEND _mtlearn_torch_includes "${_cand}")
94
+ endif()
95
+ if(EXISTS "${_cand}/torch/csrc/api/include" AND NOT "${_cand}/torch/csrc/api/include" IN_LIST _mtlearn_torch_includes)
96
+ list(APPEND _mtlearn_torch_includes "${_cand}/torch/csrc/api/include")
97
+ endif()
98
+ if(EXISTS "${_cand}/ATen" AND NOT "${_cand}/ATen" IN_LIST _mtlearn_torch_includes)
99
+ list(APPEND _mtlearn_torch_includes "${_cand}/ATen")
100
+ endif()
101
+ endforeach()
102
+ endif()
103
+
104
+ if(DEFINED ENV{CONDA_PREFIX})
105
+ file(GLOB _mtlearn_conda_pkg_includes "$ENV{CONDA_PREFIX}/pkgs/libtorch*/include")
106
+ list(APPEND _mtlearn_torch_includes ${_mtlearn_conda_pkg_includes})
107
+ foreach(_cand IN LISTS _mtlearn_conda_pkg_includes)
108
+ if(EXISTS "${_cand}/torch/csrc/api/include")
109
+ list(APPEND _mtlearn_torch_includes "${_cand}/torch/csrc/api/include")
110
+ endif()
111
+ if(EXISTS "${_cand}/ATen")
112
+ list(APPEND _mtlearn_torch_includes "${_cand}/ATen")
113
+ endif()
114
+ endforeach()
115
+ endif()
116
+
117
+ if(Python3_Interpreter_FOUND)
118
+ execute_process(
119
+ COMMAND "${Python3_EXECUTABLE}" "-c" "import torch, sys; sys.stdout.write('\n'.join(torch.utils.cpp_extension.include_paths()))"
120
+ OUTPUT_VARIABLE _torch_extra_includes
121
+ RESULT_VARIABLE _torch_extra_result
122
+ OUTPUT_STRIP_TRAILING_WHITESPACE
123
+ ERROR_QUIET
124
+ )
125
+ if(_torch_extra_result EQUAL 0 AND _torch_extra_includes)
126
+ string(REPLACE "\r\n" ";" _torch_extra_includes "${_torch_extra_includes}")
127
+ string(REPLACE "\n" ";" _torch_extra_includes "${_torch_extra_includes}")
128
+ foreach(_extra_inc IN LISTS _torch_extra_includes)
129
+ if(EXISTS "${_extra_inc}" AND NOT "${_extra_inc}" IN_LIST _mtlearn_torch_includes)
130
+ list(APPEND _mtlearn_torch_includes "${_extra_inc}")
131
+ if(EXISTS "${_extra_inc}/torch/csrc/api/include" AND NOT "${_extra_inc}/torch/csrc/api/include" IN_LIST _mtlearn_torch_includes)
132
+ list(APPEND _mtlearn_torch_includes "${_extra_inc}/torch/csrc/api/include")
133
+ endif()
134
+ endif()
135
+ endforeach()
136
+ endif()
137
+ endif()
138
+
139
+ if(Python3_Interpreter_FOUND)
140
+ get_filename_component(_mtlearn_py_bindir "${Python3_EXECUTABLE}" DIRECTORY)
141
+ get_filename_component(_mtlearn_py_prefix "${_mtlearn_py_bindir}" DIRECTORY)
142
+ file(GLOB _mtlearn_py_pkg_includes "${_mtlearn_py_prefix}/pkgs/libtorch*/include")
143
+ list(APPEND _mtlearn_torch_includes ${_mtlearn_py_pkg_includes})
144
+ foreach(_cand IN LISTS _mtlearn_py_pkg_includes)
145
+ if(EXISTS "${_cand}/torch/csrc/api/include")
146
+ list(APPEND _mtlearn_torch_includes "${_cand}/torch/csrc/api/include")
147
+ endif()
148
+ if(EXISTS "${_cand}/ATen")
149
+ list(APPEND _mtlearn_torch_includes "${_cand}/ATen")
150
+ endif()
151
+ endforeach()
152
+ endif()
153
+
154
+ # Broaden search for Torch headers (extension.h, all.h) across typical prefixes.
155
+ set(_mtlearn_torch_hint_paths)
156
+ if(TORCH_INSTALL_PREFIX)
157
+ list(APPEND _mtlearn_torch_hint_paths "${TORCH_INSTALL_PREFIX}" "${TORCH_INSTALL_PREFIX}/include")
158
+ set(_mtlearn_prefix_step "${TORCH_INSTALL_PREFIX}")
159
+ foreach(_i RANGE 1 4)
160
+ get_filename_component(_mtlearn_prefix_step "${_mtlearn_prefix_step}" DIRECTORY)
161
+ if(_mtlearn_prefix_step)
162
+ list(APPEND _mtlearn_torch_hint_paths "${_mtlearn_prefix_step}")
163
+ endif()
164
+ endforeach()
165
+ endif()
166
+ if(DEFINED ENV{CONDA_PREFIX})
167
+ list(APPEND _mtlearn_torch_hint_paths "$ENV{CONDA_PREFIX}" "$ENV{CONDA_PREFIX}/pkgs")
168
+ endif()
169
+ if(Python3_SITEARCH)
170
+ list(APPEND _mtlearn_torch_hint_paths "${Python3_SITEARCH}")
171
+ endif()
172
+ if(Python3_SITELIB)
173
+ list(APPEND _mtlearn_torch_hint_paths "${Python3_SITELIB}")
174
+ endif()
175
+ list(APPEND _mtlearn_torch_hint_paths ${CMAKE_PREFIX_PATH})
176
+
177
+ find_path(_mtlearn_torch_extension_dir
178
+ NAMES torch/extension.h
179
+ HINTS ${_mtlearn_torch_hint_paths}
180
+ PATH_SUFFIXES include torch/include)
181
+ if(_mtlearn_torch_extension_dir)
182
+ list(APPEND _mtlearn_torch_includes "${_mtlearn_torch_extension_dir}")
183
+ endif()
184
+
185
+ find_path(_mtlearn_torch_all_dir
186
+ NAMES torch/all.h
187
+ HINTS ${_mtlearn_torch_hint_paths}
188
+ PATH_SUFFIXES include/torch/csrc/api/include torch/csrc/api/include)
189
+ if(_mtlearn_torch_all_dir)
190
+ list(APPEND _mtlearn_torch_includes "${_mtlearn_torch_all_dir}")
191
+ endif()
192
+
193
+ find_path(_mtlearn_torch_aten_dir
194
+ NAMES ATen/ATen.h
195
+ HINTS ${_mtlearn_torch_hint_paths}
196
+ PATH_SUFFIXES include include/ATen)
197
+ if(_mtlearn_torch_aten_dir)
198
+ list(APPEND _mtlearn_torch_includes "${_mtlearn_torch_aten_dir}")
199
+ endif()
200
+
201
+ # Deduplicate include list
202
+ if(_mtlearn_torch_includes)
203
+ list(REMOVE_DUPLICATES _mtlearn_torch_includes)
204
+ set(MTLEARN_TORCH_INCLUDE_DIRS "${_mtlearn_torch_includes}" CACHE INTERNAL "Resolved Torch include directories for mtlearn")
205
+ endif()
206
+
207
+ # Diretórios de include do projeto (src/) mais os includes do Torch.
208
+ target_include_directories(_mtlearn PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../src)
209
+ if(_mtlearn_torch_includes)
210
+ target_include_directories(_mtlearn PRIVATE ${_mtlearn_torch_includes})
211
+ endif()
212
+
213
+ # Configurações padrão do módulo pybind11.
214
+ set_target_properties(_mtlearn PROPERTIES OUTPUT_NAME "_mtlearn")
215
+ set_property(TARGET _mtlearn PROPERTY CXX_STANDARD 20)
216
+ set_property(TARGET _mtlearn PROPERTY CXX_STANDARD_REQUIRED ON)
217
+ set_property(TARGET _mtlearn PROPERTY CXX_EXTENSIONS OFF)
218
+ target_compile_definitions(_mtlearn PRIVATE TORCH_API_INCLUDE_EXTENSION_H)
219
+ set_target_properties(_mtlearn PROPERTIES POSITION_INDEPENDENT_CODE ON)
220
+
221
+ install(TARGETS _mtlearn
222
+ LIBRARY DESTINATION mtlearn
223
+ ARCHIVE DESTINATION mtlearn
224
+ RUNTIME DESTINATION mtlearn)
@@ -0,0 +1,37 @@
1
+ #include <pybind11/pybind11.h>
2
+ #include <pybind11/stl.h>
3
+
4
+ #include "mtlearn/core.hpp"
5
+
6
+ namespace py = pybind11;
7
+
8
+ PYBIND11_MODULE(_mtlearn, m)
9
+ {
10
+ m.doc() = "Python bindings for MTLearn built on top of mmcfilters";
11
+
12
+ py::class_<mtlearn::TreeStats>(m, "TreeStats")
13
+ .def(py::init<>())
14
+ .def_readwrite("num_nodes", &mtlearn::TreeStats::numNodes)
15
+ .def("describe", [](const mtlearn::TreeStats& stats) {
16
+ return mtlearn::describeTree(stats);
17
+ });
18
+
19
+ m.def(
20
+ "make_tree_stats",
21
+ [](int numNodes) {
22
+ return mtlearn::makeTreeStats(numNodes);
23
+ },
24
+ py::arg("num_nodes"),
25
+ "Create a simple TreeStats instance using a node count.");
26
+
27
+ m.def(
28
+ "make_tree_tensor",
29
+ [](int numNodes) {
30
+ auto stats = mtlearn::makeTreeStats(numNodes);
31
+ py::object torch = py::module::import("torch");
32
+ py::object tensor = torch.attr("arange")(numNodes, py::arg("dtype") = torch.attr("float32"));
33
+ return py::make_tuple(stats, tensor);
34
+ },
35
+ py::arg("num_nodes"),
36
+ "Return TreeStats and a torch tensor with a simple range (em Python)." );
37
+ }
@@ -0,0 +1 @@
1
+ Diretório reservado para módulos CMake auxiliares do projeto.
@@ -0,0 +1 @@
1
+ gitdir: ../../.git/modules/external/MorphologicalAttributeFilters
@@ -0,0 +1,17 @@
1
+ build/*
2
+ mmcfilters.egg-info/*
3
+ mmcfilters/__pycache__/*
4
+ .eggs/*
5
+ dist/*
6
+ build_setup_py/*
7
+ .DS_Store
8
+ .virtual_documents/*
9
+ Pipfile
10
+ *.d
11
+ *.o
12
+ notebooks/.ipynb_checkpoints/*
13
+ notebooks/.virtual_documents/*
14
+ /tests/build
15
+ /tests/build
16
+ mmcfilters.cpython-312-darwin.so
17
+ python/mmcfilters/_version.py
@@ -0,0 +1,24 @@
1
+ {
2
+ "configurations": [
3
+ {
4
+ "name": "Mac",
5
+ "includePath": [
6
+ "${workspaceFolder}/**",
7
+ "/opt/anaconda3/include/python3.9",
8
+ "/opt/anaconda3/include/python3.9/pybind11-global/pybind11",
9
+ "${workspaceFolder}/mmcfilters/include"
10
+ ],
11
+ "defines": [],
12
+ "macFrameworkPath": [
13
+ "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks",
14
+ "/System/Library/Frameworks",
15
+ "/Library/Frameworks"
16
+ ],
17
+ "compilerPath": "/usr/bin/clang++",
18
+ "cStandard": "c17",
19
+ "cppStandard": "c++17",
20
+ "intelliSenseMode": "macos-clang-x64"
21
+ }
22
+ ],
23
+ "version": 4
24
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "recommendations": [
3
+ "openai.openai-chatgpt-adhoc"
4
+ ]
5
+ }