mtrc 0.3.4__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.
Files changed (338) hide show
  1. mtrc-0.3.4/CMakeLists.txt +152 -0
  2. mtrc-0.3.4/MANIFEST.in +3 -0
  3. mtrc-0.3.4/PKG-INFO +159 -0
  4. mtrc-0.3.4/README.md +129 -0
  5. mtrc-0.3.4/cmake_ext.py +95 -0
  6. mtrc-0.3.4/metric_cpp/metric/3rdparty/DCT/fast-dct-lee.c +107 -0
  7. mtrc-0.3.4/metric_cpp/metric/3rdparty/DCT/fast-dct-lee.h +39 -0
  8. mtrc-0.3.4/metric_cpp/metric/3rdparty/libedm/C45.cpp +918 -0
  9. mtrc-0.3.4/metric_cpp/metric/3rdparty/libedm/C45.h +228 -0
  10. mtrc-0.3.4/metric_cpp/metric/3rdparty/libedm/Classifier.h +66 -0
  11. mtrc-0.3.4/metric_cpp/metric/3rdparty/libedm/DataSet.cpp +967 -0
  12. mtrc-0.3.4/metric_cpp/metric/3rdparty/libedm/DataSet.h +216 -0
  13. mtrc-0.3.4/metric_cpp/metric/3rdparty/libedm/Prediction.cpp +87 -0
  14. mtrc-0.3.4/metric_cpp/metric/3rdparty/libedm/Prediction.h +67 -0
  15. mtrc-0.3.4/metric_cpp/metric/3rdparty/libedm/RandSequence.cpp +78 -0
  16. mtrc-0.3.4/metric_cpp/metric/3rdparty/libedm/RandSequence.h +93 -0
  17. mtrc-0.3.4/metric_cpp/metric/3rdparty/libedm/b-svm.cpp +315 -0
  18. mtrc-0.3.4/metric_cpp/metric/3rdparty/libedm/b-svm.h +185 -0
  19. mtrc-0.3.4/metric_cpp/metric/3rdparty/libedm/bpnn.cpp +1267 -0
  20. mtrc-0.3.4/metric_cpp/metric/3rdparty/libedm/bpnn.h +149 -0
  21. mtrc-0.3.4/metric_cpp/metric/3rdparty/libedm/svm.cpp +2782 -0
  22. mtrc-0.3.4/metric_cpp/metric/3rdparty/libedm/svm.h +100 -0
  23. mtrc-0.3.4/metric_cpp/metric/compat/aliases.hpp +32 -0
  24. mtrc-0.3.4/metric_cpp/metric/compat/legacy_space_adapters.hpp +51 -0
  25. mtrc-0.3.4/metric_cpp/metric/concepts.hpp +62 -0
  26. mtrc-0.3.4/metric_cpp/metric/core/concepts.hpp +141 -0
  27. mtrc-0.3.4/metric_cpp/metric/core/metric_space.hpp +152 -0
  28. mtrc-0.3.4/metric_cpp/metric/core/metric_traits.hpp +44 -0
  29. mtrc-0.3.4/metric_cpp/metric/core/neighbor.hpp +25 -0
  30. mtrc-0.3.4/metric_cpp/metric/core/parameters.hpp +20 -0
  31. mtrc-0.3.4/metric_cpp/metric/core/record_id.hpp +39 -0
  32. mtrc-0.3.4/metric_cpp/metric/core/result.hpp +201 -0
  33. mtrc-0.3.4/metric_cpp/metric/core/version.hpp +26 -0
  34. mtrc-0.3.4/metric_cpp/metric/correlation/entropy.cpp +855 -0
  35. mtrc-0.3.4/metric_cpp/metric/correlation/entropy.hpp +128 -0
  36. mtrc-0.3.4/metric_cpp/metric/correlation/epmgp.cpp +505 -0
  37. mtrc-0.3.4/metric_cpp/metric/correlation/epmgp.hpp +55 -0
  38. mtrc-0.3.4/metric_cpp/metric/correlation/estimator_helpers.cpp +248 -0
  39. mtrc-0.3.4/metric_cpp/metric/correlation/estimator_helpers.hpp +39 -0
  40. mtrc-0.3.4/metric_cpp/metric/correlation/mgc.cpp +515 -0
  41. mtrc-0.3.4/metric_cpp/metric/correlation/mgc.hpp +240 -0
  42. mtrc-0.3.4/metric_cpp/metric/correlation.hpp +29 -0
  43. mtrc-0.3.4/metric_cpp/metric/distance/d-spaced/Riemannian.cpp +466 -0
  44. mtrc-0.3.4/metric_cpp/metric/distance/d-spaced/Riemannian.hpp +27 -0
  45. mtrc-0.3.4/metric_cpp/metric/distance/k-random/CramervonMises.cpp +43 -0
  46. mtrc-0.3.4/metric_cpp/metric/distance/k-random/CramervonMises.hpp +57 -0
  47. mtrc-0.3.4/metric_cpp/metric/distance/k-random/KolmogorovSmirnov.cpp +41 -0
  48. mtrc-0.3.4/metric_cpp/metric/distance/k-random/KolmogorovSmirnov.hpp +47 -0
  49. mtrc-0.3.4/metric_cpp/metric/distance/k-random/RandomEMD.cpp +43 -0
  50. mtrc-0.3.4/metric_cpp/metric/distance/k-random/RandomEMD.hpp +58 -0
  51. mtrc-0.3.4/metric_cpp/metric/distance/k-related/L1.cpp +113 -0
  52. mtrc-0.3.4/metric_cpp/metric/distance/k-related/L1.hpp +86 -0
  53. mtrc-0.3.4/metric_cpp/metric/distance/k-related/Standards.cpp +239 -0
  54. mtrc-0.3.4/metric_cpp/metric/distance/k-related/Standards.hpp +369 -0
  55. mtrc-0.3.4/metric_cpp/metric/distance/k-structured/EMD.cpp +1130 -0
  56. mtrc-0.3.4/metric_cpp/metric/distance/k-structured/EMD.hpp +87 -0
  57. mtrc-0.3.4/metric_cpp/metric/distance/k-structured/Edit.cpp +63 -0
  58. mtrc-0.3.4/metric_cpp/metric/distance/k-structured/Edit.hpp +50 -0
  59. mtrc-0.3.4/metric_cpp/metric/distance/k-structured/Kohonen.cpp +300 -0
  60. mtrc-0.3.4/metric_cpp/metric/distance/k-structured/Kohonen.hpp +268 -0
  61. mtrc-0.3.4/metric_cpp/metric/distance/k-structured/SSIM.cpp +159 -0
  62. mtrc-0.3.4/metric_cpp/metric/distance/k-structured/SSIM.hpp +56 -0
  63. mtrc-0.3.4/metric_cpp/metric/distance/k-structured/TWED.cpp +149 -0
  64. mtrc-0.3.4/metric_cpp/metric/distance/k-structured/TWED.hpp +50 -0
  65. mtrc-0.3.4/metric_cpp/metric/distance.hpp +41 -0
  66. mtrc-0.3.4/metric_cpp/metric/engine.hpp +54 -0
  67. mtrc-0.3.4/metric_cpp/metric/intent/compare.hpp +99 -0
  68. mtrc-0.3.4/metric_cpp/metric/intent/compress.hpp +137 -0
  69. mtrc-0.3.4/metric_cpp/metric/intent/denoise.hpp +104 -0
  70. mtrc-0.3.4/metric_cpp/metric/intent/describe.hpp +126 -0
  71. mtrc-0.3.4/metric_cpp/metric/intent/embed.hpp +55 -0
  72. mtrc-0.3.4/metric_cpp/metric/intent/groups.hpp +116 -0
  73. mtrc-0.3.4/metric_cpp/metric/intent/map.hpp +92 -0
  74. mtrc-0.3.4/metric_cpp/metric/intent/neighbors.hpp +246 -0
  75. mtrc-0.3.4/metric_cpp/metric/intent/outliers.hpp +155 -0
  76. mtrc-0.3.4/metric_cpp/metric/intent/reduce.hpp +121 -0
  77. mtrc-0.3.4/metric_cpp/metric/intent/representatives.hpp +147 -0
  78. mtrc-0.3.4/metric_cpp/metric/mapping/DSPCC.cpp +535 -0
  79. mtrc-0.3.4/metric_cpp/metric/mapping/DSPCC.hpp +316 -0
  80. mtrc-0.3.4/metric_cpp/metric/mapping/ESN.cpp +323 -0
  81. mtrc-0.3.4/metric_cpp/metric/mapping/ESN.hpp +146 -0
  82. mtrc-0.3.4/metric_cpp/metric/mapping/KOC.cpp +278 -0
  83. mtrc-0.3.4/metric_cpp/metric/mapping/KOC.hpp +319 -0
  84. mtrc-0.3.4/metric_cpp/metric/mapping/PCFA.cpp +348 -0
  85. mtrc-0.3.4/metric_cpp/metric/mapping/PCFA.hpp +329 -0
  86. mtrc-0.3.4/metric_cpp/metric/mapping/Redif.cpp +376 -0
  87. mtrc-0.3.4/metric_cpp/metric/mapping/Redif.hpp +187 -0
  88. mtrc-0.3.4/metric_cpp/metric/mapping/SOM.cpp +236 -0
  89. mtrc-0.3.4/metric_cpp/metric/mapping/SOM.hpp +227 -0
  90. mtrc-0.3.4/metric_cpp/metric/mapping/affprop.cpp +247 -0
  91. mtrc-0.3.4/metric_cpp/metric/mapping/affprop.hpp +64 -0
  92. mtrc-0.3.4/metric_cpp/metric/mapping/autoencoder.cpp +166 -0
  93. mtrc-0.3.4/metric_cpp/metric/mapping/autoencoder.hpp +141 -0
  94. mtrc-0.3.4/metric_cpp/metric/mapping/dbscan.cpp +113 -0
  95. mtrc-0.3.4/metric_cpp/metric/mapping/dbscan.hpp +44 -0
  96. mtrc-0.3.4/metric_cpp/metric/mapping/deterministic_switch_detector.cpp +93 -0
  97. mtrc-0.3.4/metric_cpp/metric/mapping/deterministic_switch_detector.hpp +64 -0
  98. mtrc-0.3.4/metric_cpp/metric/mapping/ensembles/DT/DT.cpp +364 -0
  99. mtrc-0.3.4/metric_cpp/metric/mapping/ensembles/DT/correlation_weighted_accuracy.cpp +145 -0
  100. mtrc-0.3.4/metric_cpp/metric/mapping/ensembles/DT/correlation_weighted_accuracy.hpp +33 -0
  101. mtrc-0.3.4/metric_cpp/metric/mapping/ensembles/DT/dimension.hpp +69 -0
  102. mtrc-0.3.4/metric_cpp/metric/mapping/ensembles/DT/edm_wrappers.cpp +243 -0
  103. mtrc-0.3.4/metric_cpp/metric/mapping/ensembles/DT/edm_wrappers.hpp +207 -0
  104. mtrc-0.3.4/metric_cpp/metric/mapping/ensembles/DT.hpp +115 -0
  105. mtrc-0.3.4/metric_cpp/metric/mapping/ensembles/ensembles.cpp +611 -0
  106. mtrc-0.3.4/metric_cpp/metric/mapping/ensembles.hpp +375 -0
  107. mtrc-0.3.4/metric_cpp/metric/mapping/esn_switch_detector.cpp +369 -0
  108. mtrc-0.3.4/metric_cpp/metric/mapping/esn_switch_detector.hpp +206 -0
  109. mtrc-0.3.4/metric_cpp/metric/mapping/hierarchClustering.cpp +139 -0
  110. mtrc-0.3.4/metric_cpp/metric/mapping/hierarchClustering.hpp +125 -0
  111. mtrc-0.3.4/metric_cpp/metric/mapping/kmeans.cpp +248 -0
  112. mtrc-0.3.4/metric_cpp/metric/mapping/kmeans.hpp +49 -0
  113. mtrc-0.3.4/metric_cpp/metric/mapping/kmedoids.cpp +291 -0
  114. mtrc-0.3.4/metric_cpp/metric/mapping/kmedoids.hpp +31 -0
  115. mtrc-0.3.4/metric_cpp/metric/mapping.hpp +37 -0
  116. mtrc-0.3.4/metric_cpp/metric/mappings/clustered_space.hpp +208 -0
  117. mtrc-0.3.4/metric_cpp/metric/mappings/koc.hpp +77 -0
  118. mtrc-0.3.4/metric_cpp/metric/mappings/mapping.hpp +26 -0
  119. mtrc-0.3.4/metric_cpp/metric/mappings/native_autoencoder.hpp +197 -0
  120. mtrc-0.3.4/metric_cpp/metric/mappings/native_phate_autoencoder.hpp +264 -0
  121. mtrc-0.3.4/metric_cpp/metric/mappings/pcfa.hpp +141 -0
  122. mtrc-0.3.4/metric_cpp/metric/metric.hpp +33 -0
  123. mtrc-0.3.4/metric_cpp/metric/operators/clustering.hpp +567 -0
  124. mtrc-0.3.4/metric_cpp/metric/operators/correlation.hpp +94 -0
  125. mtrc-0.3.4/metric_cpp/metric/operators/entropy.hpp +48 -0
  126. mtrc-0.3.4/metric_cpp/metric/operators/nearest.hpp +201 -0
  127. mtrc-0.3.4/metric_cpp/metric/operators/sparsify.hpp +13 -0
  128. mtrc-0.3.4/metric_cpp/metric/operators.hpp +843 -0
  129. mtrc-0.3.4/metric_cpp/metric/representations/cover_tree_index.hpp +138 -0
  130. mtrc-0.3.4/metric_cpp/metric/representations/diagnostics.hpp +76 -0
  131. mtrc-0.3.4/metric_cpp/metric/representations/graph_topology.hpp +122 -0
  132. mtrc-0.3.4/metric_cpp/metric/representations/implicit.hpp +56 -0
  133. mtrc-0.3.4/metric_cpp/metric/representations/knn_graph_index.hpp +246 -0
  134. mtrc-0.3.4/metric_cpp/metric/representations/matrix_cache.hpp +156 -0
  135. mtrc-0.3.4/metric_cpp/metric/representations/strategy.hpp +50 -0
  136. mtrc-0.3.4/metric_cpp/metric/runtime/cache.hpp +39 -0
  137. mtrc-0.3.4/metric_cpp/metric/runtime/execution.hpp +252 -0
  138. mtrc-0.3.4/metric_cpp/metric/runtime/policy.hpp +168 -0
  139. mtrc-0.3.4/metric_cpp/metric/space/knn_graph.cpp +494 -0
  140. mtrc-0.3.4/metric_cpp/metric/space/knn_graph.hpp +211 -0
  141. mtrc-0.3.4/metric_cpp/metric/space/matrix.cpp +206 -0
  142. mtrc-0.3.4/metric_cpp/metric/space/matrix.hpp +244 -0
  143. mtrc-0.3.4/metric_cpp/metric/space/tree.cpp +1487 -0
  144. mtrc-0.3.4/metric_cpp/metric/space/tree.hpp +522 -0
  145. mtrc-0.3.4/metric_cpp/metric/space.hpp +129 -0
  146. mtrc-0.3.4/metric_cpp/metric/strategies/clustering.hpp +52 -0
  147. mtrc-0.3.4/metric_cpp/metric/strategies/correlation.hpp +15 -0
  148. mtrc-0.3.4/metric_cpp/metric/strategies/reduction.hpp +65 -0
  149. mtrc-0.3.4/metric_cpp/metric/strategies/representation.hpp +20 -0
  150. mtrc-0.3.4/metric_cpp/metric/strategies/representatives.hpp +25 -0
  151. mtrc-0.3.4/metric_cpp/metric/strategies/search.hpp +34 -0
  152. mtrc-0.3.4/metric_cpp/metric/transform/discrete_cosine.cpp +113 -0
  153. mtrc-0.3.4/metric_cpp/metric/transform/discrete_cosine.hpp +27 -0
  154. mtrc-0.3.4/metric_cpp/metric/transform/distance_potential_minimization.cpp +965 -0
  155. mtrc-0.3.4/metric_cpp/metric/transform/distance_potential_minimization.hpp +32 -0
  156. mtrc-0.3.4/metric_cpp/metric/transform/energy_encoder.cpp +158 -0
  157. mtrc-0.3.4/metric_cpp/metric/transform/energy_encoder.hpp +43 -0
  158. mtrc-0.3.4/metric_cpp/metric/transform/helper_functions.cpp +719 -0
  159. mtrc-0.3.4/metric_cpp/metric/transform/hog.cpp +260 -0
  160. mtrc-0.3.4/metric_cpp/metric/transform/hog.hpp +34 -0
  161. mtrc-0.3.4/metric_cpp/metric/transform/wavelet.cpp +1234 -0
  162. mtrc-0.3.4/metric_cpp/metric/transform/wavelet.hpp +420 -0
  163. mtrc-0.3.4/metric_cpp/metric/transform/wavelet2d.hpp +129 -0
  164. mtrc-0.3.4/metric_cpp/metric/transform.hpp +28 -0
  165. mtrc-0.3.4/metric_cpp/metric/utils/Semaphore.h +52 -0
  166. mtrc-0.3.4/metric_cpp/metric/utils/ThreadPool.cpp +68 -0
  167. mtrc-0.3.4/metric_cpp/metric/utils/ThreadPool.hpp +39 -0
  168. mtrc-0.3.4/metric_cpp/metric/utils/auto_detect_metric/auto_detect_metric 2.cpp +145 -0
  169. mtrc-0.3.4/metric_cpp/metric/utils/auto_detect_metric/auto_detect_metric.cpp +142 -0
  170. mtrc-0.3.4/metric_cpp/metric/utils/auto_detect_metric.hpp +48 -0
  171. mtrc-0.3.4/metric_cpp/metric/utils/datasets.hpp +198 -0
  172. mtrc-0.3.4/metric_cpp/metric/utils/dnn/Activation/Identity.h +43 -0
  173. mtrc-0.3.4/metric_cpp/metric/utils/dnn/Activation/ReLU.h +74 -0
  174. mtrc-0.3.4/metric_cpp/metric/utils/dnn/Activation/Sigmoid.h +40 -0
  175. mtrc-0.3.4/metric_cpp/metric/utils/dnn/Activation/Softmax.h +42 -0
  176. mtrc-0.3.4/metric_cpp/metric/utils/dnn/AutoencoderArtifact.h +95 -0
  177. mtrc-0.3.4/metric_cpp/metric/utils/dnn/AutoencoderModel.h +396 -0
  178. mtrc-0.3.4/metric_cpp/metric/utils/dnn/Callback/VerboseCallback.h +99 -0
  179. mtrc-0.3.4/metric_cpp/metric/utils/dnn/Callback.h +57 -0
  180. mtrc-0.3.4/metric_cpp/metric/utils/dnn/Dataset.h +227 -0
  181. mtrc-0.3.4/metric_cpp/metric/utils/dnn/Initializer/NormalInitializer.h +37 -0
  182. mtrc-0.3.4/metric_cpp/metric/utils/dnn/Initializer/ZeroInitializer.h +22 -0
  183. mtrc-0.3.4/metric_cpp/metric/utils/dnn/Initializer.h +18 -0
  184. mtrc-0.3.4/metric_cpp/metric/utils/dnn/Layer/Conv2d-transpose.h +64 -0
  185. mtrc-0.3.4/metric_cpp/metric/utils/dnn/Layer/Conv2d.h +433 -0
  186. mtrc-0.3.4/metric_cpp/metric/utils/dnn/Layer/FullyConnected.h +217 -0
  187. mtrc-0.3.4/metric_cpp/metric/utils/dnn/Layer/MaxPooling.h +153 -0
  188. mtrc-0.3.4/metric_cpp/metric/utils/dnn/Layer.h +163 -0
  189. mtrc-0.3.4/metric_cpp/metric/utils/dnn/Loss.h +243 -0
  190. mtrc-0.3.4/metric_cpp/metric/utils/dnn/M_Assert.h +21 -0
  191. mtrc-0.3.4/metric_cpp/metric/utils/dnn/Network.h +655 -0
  192. mtrc-0.3.4/metric_cpp/metric/utils/dnn/Optimizer/AdaGrad.h +54 -0
  193. mtrc-0.3.4/metric_cpp/metric/utils/dnn/Optimizer/RMSProp.h +108 -0
  194. mtrc-0.3.4/metric_cpp/metric/utils/dnn/Optimizer/SGD.h +32 -0
  195. mtrc-0.3.4/metric_cpp/metric/utils/dnn/Optimizer.h +55 -0
  196. mtrc-0.3.4/metric_cpp/metric/utils/dnn/Output/BinaryClassEntropy.h +105 -0
  197. mtrc-0.3.4/metric_cpp/metric/utils/dnn/Output/MultiClassEntropy.h +136 -0
  198. mtrc-0.3.4/metric_cpp/metric/utils/dnn/Output/RegressionMSE.h +52 -0
  199. mtrc-0.3.4/metric_cpp/metric/utils/dnn/Output.h +69 -0
  200. mtrc-0.3.4/metric_cpp/metric/utils/dnn/Utils/Convolution.h +35 -0
  201. mtrc-0.3.4/metric_cpp/metric/utils/dnn/Utils/FindMax.h +136 -0
  202. mtrc-0.3.4/metric_cpp/metric/utils/dnn/Utils/Random.h +77 -0
  203. mtrc-0.3.4/metric_cpp/metric/utils/dnn/dnn-includes.h +37 -0
  204. mtrc-0.3.4/metric_cpp/metric/utils/dnn.hpp +6 -0
  205. mtrc-0.3.4/metric_cpp/metric/utils/dsv.hpp +10 -0
  206. mtrc-0.3.4/metric_cpp/metric/utils/genetic/Chromosome.hpp +349 -0
  207. mtrc-0.3.4/metric_cpp/metric/utils/genetic/Parameter.hpp +113 -0
  208. mtrc-0.3.4/metric_cpp/metric/utils/genetic/Population.hpp +409 -0
  209. mtrc-0.3.4/metric_cpp/metric/utils/genetic/dist_sampling.hpp +101 -0
  210. mtrc-0.3.4/metric_cpp/metric/utils/genetic/evolution_methods.hpp +425 -0
  211. mtrc-0.3.4/metric_cpp/metric/utils/genetic/genetic_impl.hpp +411 -0
  212. mtrc-0.3.4/metric_cpp/metric/utils/genetic.hpp +41 -0
  213. mtrc-0.3.4/metric_cpp/metric/utils/graph/connected_components.cpp +226 -0
  214. mtrc-0.3.4/metric_cpp/metric/utils/graph/connected_components.hpp +90 -0
  215. mtrc-0.3.4/metric_cpp/metric/utils/graph/graph.cpp +690 -0
  216. mtrc-0.3.4/metric_cpp/metric/utils/graph/sparsify.cpp +253 -0
  217. mtrc-0.3.4/metric_cpp/metric/utils/graph/sparsify.hpp +64 -0
  218. mtrc-0.3.4/metric_cpp/metric/utils/graph.hpp +357 -0
  219. mtrc-0.3.4/metric_cpp/metric/utils/image_processing/convolution.cpp +71 -0
  220. mtrc-0.3.4/metric_cpp/metric/utils/image_processing/convolution.hpp +37 -0
  221. mtrc-0.3.4/metric_cpp/metric/utils/image_processing/image_filter.cpp +344 -0
  222. mtrc-0.3.4/metric_cpp/metric/utils/image_processing/image_filter.hpp +382 -0
  223. mtrc-0.3.4/metric_cpp/metric/utils/metric_err.hpp +84 -0
  224. mtrc-0.3.4/metric_cpp/metric/utils/poor_mans_quantum/distributions/Binomial.cpp +174 -0
  225. mtrc-0.3.4/metric_cpp/metric/utils/poor_mans_quantum/distributions/Binomial.hpp +60 -0
  226. mtrc-0.3.4/metric_cpp/metric/utils/poor_mans_quantum/distributions/Discrete.cpp +106 -0
  227. mtrc-0.3.4/metric_cpp/metric/utils/poor_mans_quantum/distributions/Discrete.hpp +107 -0
  228. mtrc-0.3.4/metric_cpp/metric/utils/poor_mans_quantum/distributions/Normal.cpp +237 -0
  229. mtrc-0.3.4/metric_cpp/metric/utils/poor_mans_quantum/distributions/Normal.hpp +104 -0
  230. mtrc-0.3.4/metric_cpp/metric/utils/poor_mans_quantum/distributions/Weibull.cpp +371 -0
  231. mtrc-0.3.4/metric_cpp/metric/utils/poor_mans_quantum/distributions/Weibull.hpp +87 -0
  232. mtrc-0.3.4/metric_cpp/metric/utils/poor_mans_quantum/math_functions.cpp +154 -0
  233. mtrc-0.3.4/metric_cpp/metric/utils/poor_mans_quantum/math_functions.hpp +69 -0
  234. mtrc-0.3.4/metric_cpp/metric/utils/poor_mans_quantum/poor_mans_quantum.cpp +559 -0
  235. mtrc-0.3.4/metric_cpp/metric/utils/poor_mans_quantum.hpp +203 -0
  236. mtrc-0.3.4/metric_cpp/metric/utils/solver/approxchol/approxchol.cpp +578 -0
  237. mtrc-0.3.4/metric_cpp/metric/utils/solver/approxchol.hpp +710 -0
  238. mtrc-0.3.4/metric_cpp/metric/utils/solver/helper/graphalgs/graphalgs.cpp +862 -0
  239. mtrc-0.3.4/metric_cpp/metric/utils/solver/helper/graphalgs.hpp +551 -0
  240. mtrc-0.3.4/metric_cpp/metric/utils/solver/helper/ijvstruct/ijvstruct.cpp +188 -0
  241. mtrc-0.3.4/metric_cpp/metric/utils/solver/helper/ijvstruct.hpp +261 -0
  242. mtrc-0.3.4/metric_cpp/metric/utils/solver/helper/lapwrapper/lapwrappers.cpp +339 -0
  243. mtrc-0.3.4/metric_cpp/metric/utils/solver/helper/lapwrappers.hpp +251 -0
  244. mtrc-0.3.4/metric_cpp/metric/utils/solver/helper/solvertypes.hpp +337 -0
  245. mtrc-0.3.4/metric_cpp/metric/utils/solver/helper/sparsecsc/sparsecsc.cpp +88 -0
  246. mtrc-0.3.4/metric_cpp/metric/utils/solver/helper/sparsecsc.hpp +90 -0
  247. mtrc-0.3.4/metric_cpp/metric/utils/solver/pcg/pcg.cpp +209 -0
  248. mtrc-0.3.4/metric_cpp/metric/utils/solver/pcg.hpp +158 -0
  249. mtrc-0.3.4/metric_cpp/metric/utils/solver/solver.hpp +16 -0
  250. mtrc-0.3.4/metric_cpp/metric/utils/type_traits.hpp +138 -0
  251. mtrc-0.3.4/metric_cpp/metric/utils/types/BFloat16.h +4826 -0
  252. mtrc-0.3.4/metric_cpp/metric/utils/visualizer.cpp +125 -0
  253. mtrc-0.3.4/metric_cpp/metric/utils/visualizer.hpp +36 -0
  254. mtrc-0.3.4/metric_cpp/metric/utils/wrappers/lapack.hpp +32 -0
  255. mtrc-0.3.4/pkg/metric/__init__.py +105 -0
  256. mtrc-0.3.4/pkg/metric/_common.py +35 -0
  257. mtrc-0.3.4/pkg/metric/_impl/__init__.py +2 -0
  258. mtrc-0.3.4/pkg/metric/compat/__init__.py +37 -0
  259. mtrc-0.3.4/pkg/metric/core.py +34 -0
  260. mtrc-0.3.4/pkg/metric/correlation/__init__.py +2 -0
  261. mtrc-0.3.4/pkg/metric/correlation/entropy.py +6 -0
  262. mtrc-0.3.4/pkg/metric/correlation/mgc.py +15 -0
  263. mtrc-0.3.4/pkg/metric/distance/__init__.py +20 -0
  264. mtrc-0.3.4/pkg/metric/distance/emd.py +0 -0
  265. mtrc-0.3.4/pkg/metric/exceptions.py +80 -0
  266. mtrc-0.3.4/pkg/metric/intent.py +58 -0
  267. mtrc-0.3.4/pkg/metric/mapping/__init__.py +8 -0
  268. mtrc-0.3.4/pkg/metric/mapping/koc.py +10 -0
  269. mtrc-0.3.4/pkg/metric/mappings.py +213 -0
  270. mtrc-0.3.4/pkg/metric/metrics.py +70 -0
  271. mtrc-0.3.4/pkg/metric/operators.py +2720 -0
  272. mtrc-0.3.4/pkg/metric/representations.py +166 -0
  273. mtrc-0.3.4/pkg/metric/runtime.py +289 -0
  274. mtrc-0.3.4/pkg/metric/space/__init__.py +7 -0
  275. mtrc-0.3.4/pkg/metric/space/matrix.py +37 -0
  276. mtrc-0.3.4/pkg/metric/spaces.py +807 -0
  277. mtrc-0.3.4/pkg/metric/strategies.py +111 -0
  278. mtrc-0.3.4/pkg/metric/transform/__init__.py +1 -0
  279. mtrc-0.3.4/pkg/metric/transforms.py +35 -0
  280. mtrc-0.3.4/pkg/metric/utils/__init__.py +1 -0
  281. mtrc-0.3.4/pkg/metric/utils/misc.py +22 -0
  282. mtrc-0.3.4/pkg/mtrc.egg-info/PKG-INFO +159 -0
  283. mtrc-0.3.4/pkg/mtrc.egg-info/SOURCES.txt +88 -0
  284. mtrc-0.3.4/pkg/mtrc.egg-info/dependency_links.txt +1 -0
  285. mtrc-0.3.4/pkg/mtrc.egg-info/requires.txt +1 -0
  286. mtrc-0.3.4/pkg/mtrc.egg-info/top_level.txt +2 -0
  287. mtrc-0.3.4/pyproject.toml +59 -0
  288. mtrc-0.3.4/setup.cfg +7 -0
  289. mtrc-0.3.4/setup.py +30 -0
  290. mtrc-0.3.4/src/CMakeLists.txt +15 -0
  291. mtrc-0.3.4/src/blaze.cpp +75 -0
  292. mtrc-0.3.4/src/correlation/CMakeLists.txt +11 -0
  293. mtrc-0.3.4/src/correlation/entropy.cpp +76 -0
  294. mtrc-0.3.4/src/correlation/mgc.cpp +112 -0
  295. mtrc-0.3.4/src/distance/CMakeLists.txt +17 -0
  296. mtrc-0.3.4/src/distance/EMD.cpp +54 -0
  297. mtrc-0.3.4/src/distance/Edit.cpp +34 -0
  298. mtrc-0.3.4/src/distance/RandomEMD.cpp +38 -0
  299. mtrc-0.3.4/src/distance/SSIM.cpp +31 -0
  300. mtrc-0.3.4/src/distance/TWED.cpp +25 -0
  301. mtrc-0.3.4/src/distance/custom.hpp +49 -0
  302. mtrc-0.3.4/src/distance/init.cpp +33 -0
  303. mtrc-0.3.4/src/distance/kohonen.cpp +47 -0
  304. mtrc-0.3.4/src/distance/sorensen.cpp +30 -0
  305. mtrc-0.3.4/src/distance/subs/CMakeLists.txt +11 -0
  306. mtrc-0.3.4/src/distance/subs/standards.cpp +93 -0
  307. mtrc-0.3.4/src/init.cpp +78 -0
  308. mtrc-0.3.4/src/mapping/CMakeLists.txt +8 -0
  309. mtrc-0.3.4/src/mapping/DSPCC.cpp +34 -0
  310. mtrc-0.3.4/src/mapping/autoencoder.cpp +24 -0
  311. mtrc-0.3.4/src/mapping/init.cpp +22 -0
  312. mtrc-0.3.4/src/mapping/kmeans.cpp +24 -0
  313. mtrc-0.3.4/src/mapping/kmedoids.cpp +20 -0
  314. mtrc-0.3.4/src/mapping/subs/CMakeLists.txt +11 -0
  315. mtrc-0.3.4/src/mapping/subs/ESN.cpp +38 -0
  316. mtrc-0.3.4/src/mapping/subs/KOC.cpp +120 -0
  317. mtrc-0.3.4/src/mapping/subs/affprop.cpp +44 -0
  318. mtrc-0.3.4/src/mapping/subs/dbscan.cpp +21 -0
  319. mtrc-0.3.4/src/mapping/subs/dt.cpp +113 -0
  320. mtrc-0.3.4/src/mapping/subs/ensembles.cpp +101 -0
  321. mtrc-0.3.4/src/mapping/subs/redif.cpp +35 -0
  322. mtrc-0.3.4/src/metric_converters.hpp +193 -0
  323. mtrc-0.3.4/src/metric_types.hpp +49 -0
  324. mtrc-0.3.4/src/space/CMakeLists.txt +6 -0
  325. mtrc-0.3.4/src/space/init.cpp +18 -0
  326. mtrc-0.3.4/src/space/matrix.cpp +117 -0
  327. mtrc-0.3.4/src/space/tree.cpp +105 -0
  328. mtrc-0.3.4/src/stl_wrappers.hpp +75 -0
  329. mtrc-0.3.4/src/transform/CMakeLists.txt +6 -0
  330. mtrc-0.3.4/src/transform/init.cpp +16 -0
  331. mtrc-0.3.4/src/transform/wavelet.cpp +19 -0
  332. mtrc-0.3.4/src/utils/CMakeLists.txt +6 -0
  333. mtrc-0.3.4/src/utils/dataset.cpp +19 -0
  334. mtrc-0.3.4/src/utils/dimension.cpp +63 -0
  335. mtrc-0.3.4/src/utils/distribution.cpp +25 -0
  336. mtrc-0.3.4/src/utils/graph.cpp +60 -0
  337. mtrc-0.3.4/src/utils/init.cpp +24 -0
  338. mtrc-0.3.4/src/utils/sparsify.cpp +26 -0
@@ -0,0 +1,152 @@
1
+ cmake_minimum_required(VERSION 3.15)
2
+
3
+ if (POLICY CMP0025)
4
+ cmake_policy(SET CMP0025 NEW)
5
+ endif ()
6
+ if (POLICY CMP0074)
7
+ cmake_policy(SET CMP0074 NEW)
8
+ endif()
9
+ if (POLICY CMP0169)
10
+ cmake_policy(SET CMP0169 OLD)
11
+ endif ()
12
+ if (POLICY CMP0167)
13
+ cmake_policy(SET CMP0167 OLD)
14
+ endif ()
15
+
16
+ # TODO
17
+ if(CMAKE_SYSTEM_NAME MATCHES Windows)
18
+ if(CMAKE_SYSTEM_PROCESSOR MATCHES ".*64$")
19
+ message("Build architecture: x64")
20
+ set(CMAKE_GENERATOR_PLATFORM x64)
21
+ else()
22
+ message("Build architecture: x86")
23
+ set(CMAKE_GENERATOR_PLATFORM Win32)
24
+ endif()
25
+ endif()
26
+
27
+ # TODO: check compiler, not OS
28
+ project(metric_py DESCRIPTION "metric python binding" LANGUAGES CXX)
29
+
30
+ set(CMAKE_CXX_STANDARD 17)
31
+ set(CMAKE_CXX_STANDARD_REQUIRED ON)
32
+ set(CMAKE_CXX_EXTENSIONS OFF)
33
+ include(FetchContent)
34
+ option(METRIC_PYTHON_BUILD_FULL "Build legacy mapping and correlation Python bindings that require Boost" OFF)
35
+ option(METRIC_PYTHON_FETCH_DEPS "Fetch missing C++ header dependencies for Python bindings" ON)
36
+ option(METRIC_PYTHON_USE_BLAS "Link Python bindings to BLAS when available" ON)
37
+
38
+ # Keep paths relative to this file so the Python build works both standalone and
39
+ # when included by the top-level METRIC project.
40
+ SET(SOURCE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/src)
41
+ if(NOT DEFINED ENV{METRIC_SOURCE_PATH})
42
+ if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/metric_cpp/metric")
43
+ SET(METRIC_SOURCE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/metric_cpp)
44
+ else ()
45
+ SET(METRIC_SOURCE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/..)
46
+ endif ()
47
+ else ()
48
+ SET(METRIC_SOURCE_PATH $ENV{METRIC_SOURCE_PATH})
49
+ endif()
50
+
51
+ if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.18")
52
+ find_package(Python3 COMPONENTS Interpreter Development.Module REQUIRED)
53
+ else ()
54
+ find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
55
+ endif ()
56
+ if (METRIC_PYTHON_USE_BLAS)
57
+ find_package(BLAS QUIET)
58
+ endif ()
59
+
60
+ find_package(nlohmann_json QUIET)
61
+ if (NOT nlohmann_json_FOUND AND METRIC_PYTHON_FETCH_DEPS)
62
+ FetchContent_Declare(
63
+ nlohmann_json
64
+ GIT_REPOSITORY https://github.com/nlohmann/json.git
65
+ GIT_TAG v3.11.3
66
+ GIT_SHALLOW TRUE)
67
+ FetchContent_GetProperties(nlohmann_json)
68
+ if (NOT nlohmann_json_POPULATED)
69
+ FetchContent_Populate(nlohmann_json)
70
+ endif ()
71
+ set(METRIC_PYTHON_NLOHMANN_JSON_INCLUDE_DIR ${nlohmann_json_SOURCE_DIR}/include)
72
+ endif ()
73
+
74
+ find_package(blaze 3.8 QUIET)
75
+ if (NOT blaze_FOUND AND METRIC_PYTHON_FETCH_DEPS)
76
+ FetchContent_Declare(
77
+ blaze
78
+ GIT_REPOSITORY https://bitbucket.org/blaze-lib/blaze.git
79
+ GIT_TAG v3.8
80
+ GIT_SHALLOW TRUE)
81
+ FetchContent_GetProperties(blaze)
82
+ if (NOT blaze_POPULATED)
83
+ FetchContent_Populate(blaze)
84
+ endif ()
85
+ set(METRIC_PYTHON_BLAZE_INCLUDE_DIR ${blaze_SOURCE_DIR})
86
+ endif ()
87
+
88
+ find_package(cereal QUIET)
89
+ if (NOT cereal_FOUND AND METRIC_PYTHON_FETCH_DEPS)
90
+ FetchContent_Declare(
91
+ cereal
92
+ GIT_REPOSITORY https://github.com/USCiLab/cereal.git
93
+ GIT_TAG v1.3.2
94
+ GIT_SHALLOW TRUE)
95
+ FetchContent_GetProperties(cereal)
96
+ if (NOT cereal_POPULATED)
97
+ FetchContent_Populate(cereal)
98
+ endif ()
99
+ set(METRIC_PYTHON_CEREAL_INCLUDE_DIR ${cereal_SOURCE_DIR}/include)
100
+ endif ()
101
+
102
+ if (METRIC_PYTHON_BUILD_FULL)
103
+ find_package(Boost REQUIRED)
104
+ endif ()
105
+
106
+ add_library(base_python_module INTERFACE)
107
+ target_include_directories(base_python_module INTERFACE
108
+ ${SOURCE_PATH}
109
+ ${METRIC_SOURCE_PATH}
110
+ )
111
+ if (METRIC_PYTHON_NLOHMANN_JSON_INCLUDE_DIR)
112
+ target_include_directories(base_python_module INTERFACE ${METRIC_PYTHON_NLOHMANN_JSON_INCLUDE_DIR})
113
+ endif ()
114
+ if (TARGET nlohmann_json::nlohmann_json)
115
+ target_link_libraries(base_python_module INTERFACE nlohmann_json::nlohmann_json)
116
+ endif ()
117
+ if (METRIC_PYTHON_BLAZE_INCLUDE_DIR)
118
+ target_include_directories(base_python_module INTERFACE ${METRIC_PYTHON_BLAZE_INCLUDE_DIR})
119
+ endif ()
120
+ if (TARGET blaze::blaze)
121
+ target_link_libraries(base_python_module INTERFACE blaze::blaze)
122
+ endif ()
123
+ if (METRIC_PYTHON_CEREAL_INCLUDE_DIR)
124
+ target_include_directories(base_python_module INTERFACE ${METRIC_PYTHON_CEREAL_INCLUDE_DIR})
125
+ endif ()
126
+ if (TARGET cereal::cereal)
127
+ target_link_libraries(base_python_module INTERFACE cereal::cereal)
128
+ endif ()
129
+ if (Boost_FOUND)
130
+ target_include_directories(base_python_module INTERFACE ${Boost_INCLUDE_DIR})
131
+ endif ()
132
+
133
+ if (BLAS_FOUND)
134
+ target_link_libraries(base_python_module INTERFACE ${BLAS_LIBRARIES})
135
+ endif ()
136
+
137
+ if (MSVC)
138
+ target_compile_options(base_python_module INTERFACE
139
+ /wd"4267" /wd"4305" /wd"4244" /wd"4996"
140
+ )
141
+ endif ()
142
+
143
+ find_package(pybind11 CONFIG QUIET)
144
+ if (NOT pybind11_FOUND)
145
+ FetchContent_Declare(
146
+ pybind11
147
+ GIT_REPOSITORY https://github.com/pybind/pybind11.git
148
+ GIT_TAG v3.0.1
149
+ GIT_SHALLOW TRUE)
150
+ FetchContent_MakeAvailable(pybind11)
151
+ endif ()
152
+ add_subdirectory(src)
mtrc-0.3.4/MANIFEST.in ADDED
@@ -0,0 +1,3 @@
1
+ include CMakeLists.txt
2
+ include cmake_ext.py
3
+ graft src
mtrc-0.3.4/PKG-INFO ADDED
@@ -0,0 +1,159 @@
1
+ Metadata-Version: 2.4
2
+ Name: mtrc
3
+ Version: 0.3.4
4
+ Summary: Python bindings and helpers for finite metric-space numerics
5
+ Author: METRIC contributors
6
+ License-Expression: MPL-2.0
7
+ Project-URL: Documentation, https://metric-space-ai.github.io/metric/docs.html
8
+ Project-URL: Source, https://github.com/metric-space-ai/metric
9
+ Project-URL: Release checklist, https://github.com/metric-space-ai/metric/blob/master/docs/release-checklist.md
10
+ Keywords: distance-metrics,finite-metric-space,metric-space,mtrc,numerical-computing
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Operating System :: MacOS
15
+ Classifier: Operating System :: Microsoft :: Windows
16
+ Classifier: Operating System :: Unix
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3 :: Only
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Programming Language :: Python :: 3.14
24
+ Classifier: Programming Language :: Python :: Implementation :: CPython
25
+ Classifier: Topic :: Scientific/Engineering
26
+ Classifier: Topic :: Software Development
27
+ Requires-Python: >=3.10
28
+ Description-Content-Type: text/markdown
29
+ Requires-Dist: numpy>=1.23
30
+
31
+ # METRIC Python Package
32
+
33
+ Python bindings for METRIC metric-space numerics.
34
+
35
+ The public Python distribution name is `mtrc`. The import package remains
36
+ `metric`.
37
+
38
+ The revived core package exposes the project concepts explicitly:
39
+
40
+ - `metric.metrics`: metric constructors such as `Edit`
41
+ - `metric.Space`: minimal intent-first finite metric space facade
42
+ - `metric.spaces`: finite metric-space helpers such as `FiniteMetricSpace`
43
+ - `metric.operators`: pairwise-distance, nearest-neighbor, range-neighbor, exact graph-result, graph-connectivity-diagnostics, graph-degree-diagnostics, graph-stretch-diagnostics, graph-symmetrization, graph-out-degree-pruning, exact graph-edge, representative-selection, medoid, separated-representative, and radius-coverage helpers
44
+ - `metric.mappings`: beta compatibility bridge for installed mapping bindings
45
+ - `metric.transforms`: beta compatibility bridge for installed transform bindings
46
+
47
+ The same objects are also available as convenience imports from `metric` for short examples.
48
+
49
+ # Installation
50
+
51
+ The Python package is in revival. The current supported CPython targets for the core wheel are 3.10, 3.11, 3.12, 3.13, and 3.14.
52
+
53
+ After the package is published to PyPI, install the core package with:
54
+
55
+ ```shell
56
+ python -m pip install mtrc
57
+ ```
58
+
59
+ Until PyPI publishing is completed, build from source with the instructions below.
60
+
61
+ Packaging now uses `pyproject.toml` with isolated PEP 517 builds and PEP 621 project metadata. `setup.py` provides the CMake extension build hook and the source-distribution hook that carries the required C++ headers into the Python sdist. The build prefers the `pybind11` package from the build environment (`pybind11>=3.0.0`) and falls back to a current FetchContent copy when no CMake package is available.
62
+
63
+ CI builds core wheel artifacts for Linux, macOS, and Windows across the supported CPython versions.
64
+
65
+ # Build from the source
66
+
67
+ ```
68
+ git clone --recurse-submodules https://github.com/metric-space-ai/metric
69
+ ```
70
+
71
+ ## Install Prerequisites
72
+
73
+ ### Ubuntu
74
+
75
+ ```
76
+ sudo apt-get install cmake
77
+ sudo apt-get install libboost-all-dev
78
+ ```
79
+
80
+ OpenBLAS or another BLAS implementation is optional for the revived core wheel. It can improve broader linear-algebra paths, but the CI core wheel builds with `METRIC_PYTHON_USE_BLAS=OFF`.
81
+
82
+ ### Windows
83
+
84
+ Install [Miniconda](https://docs.conda.io/en/latest/miniconda.html).
85
+ In Conda CLI initialize your virtual environment with desired Python version:
86
+
87
+ ```bash
88
+ conda create --name my_env -y python=3.12
89
+ conda activate my_env
90
+ ```
91
+
92
+ OpenBLAS is optional for the revived core wheel. For legacy full bindings or broader linear-algebra paths, install it from conda-forge:
93
+
94
+ ```bash
95
+ conda config --add channels conda-forge
96
+ conda update -n base conda -y
97
+ conda install -c conda-forge libopenblas openblas -y
98
+ ```
99
+
100
+ ## Build package
101
+
102
+ At least 2GB of RAM is required
103
+
104
+ ```
105
+ python -m pip wheel . --no-deps -w dist
106
+ ```
107
+
108
+ By default this builds the revived core bindings. At this stage the default wheel exposes the `Edit` distance binding, space bindings, transform bindings, and the pure Python package surface. The legacy standard-distance, utils, mapping, and correlation bindings still require restoration and can be attempted with:
109
+
110
+ ```shell
111
+ CMAKE_COMMON_VARIABLES="-DMETRIC_PYTHON_BUILD_FULL=ON" python -m pip wheel . --no-deps -w dist
112
+ ```
113
+
114
+ To force the portable core-wheel mode used by CI:
115
+
116
+ ```shell
117
+ CMAKE_COMMON_VARIABLES="-DMETRIC_PYTHON_USE_BLAS=OFF" python -m pip wheel . --no-deps -w dist
118
+ ```
119
+
120
+ ### Install module
121
+
122
+ ```
123
+ python -m pip install dist/*
124
+ ```
125
+
126
+ ## Examples
127
+
128
+ ```python
129
+ from metric import Edit, Space
130
+
131
+ records = ["cat", "cot", "coat", "dog"]
132
+ space = Space(records, Edit())
133
+
134
+ print("distance(cat, cot) =", space(0, 1))
135
+ print("nearest:", space.neighbors("cut", 2))
136
+ ```
137
+
138
+ The core-wheel example is also available at `examples/metric_space/string_edit_space.py`. Full correlation, mapping, and standard-distance examples remain part of the broader restoration path until their bindings are promoted into the default wheel.
139
+
140
+ Small tutorial notebooks live under `notebooks/`. They are paired with
141
+ `notebooks/smoke_notebooks.py`, which executes their code cells in CI after the
142
+ wheel is installed.
143
+
144
+ `metric.mappings` and `metric.transforms` are importable beta namespaces. They expose `available()` and `legacy_module()` so callers can inspect whether a wheel includes the broader legacy bindings without making those bindings part of the core-wheel contract.
145
+
146
+ ## NumPy records
147
+
148
+ The revived Python facade treats NumPy rows as records when the metric callable accepts them:
149
+
150
+ ```python
151
+ import numpy as np
152
+ from metric import Space
153
+
154
+ records = np.array([[0.0, 0.0], [3.0, 4.0], [6.0, 8.0]])
155
+ space = Space(records, lambda lhs, rhs: float(np.linalg.norm(lhs - rhs)))
156
+ print(space.distance(0, 1))
157
+ ```
158
+
159
+ Pairwise distance helpers return Python lists of lists; call `np.asarray(...)` if an ndarray result is required.
mtrc-0.3.4/README.md ADDED
@@ -0,0 +1,129 @@
1
+ # METRIC Python Package
2
+
3
+ Python bindings for METRIC metric-space numerics.
4
+
5
+ The public Python distribution name is `mtrc`. The import package remains
6
+ `metric`.
7
+
8
+ The revived core package exposes the project concepts explicitly:
9
+
10
+ - `metric.metrics`: metric constructors such as `Edit`
11
+ - `metric.Space`: minimal intent-first finite metric space facade
12
+ - `metric.spaces`: finite metric-space helpers such as `FiniteMetricSpace`
13
+ - `metric.operators`: pairwise-distance, nearest-neighbor, range-neighbor, exact graph-result, graph-connectivity-diagnostics, graph-degree-diagnostics, graph-stretch-diagnostics, graph-symmetrization, graph-out-degree-pruning, exact graph-edge, representative-selection, medoid, separated-representative, and radius-coverage helpers
14
+ - `metric.mappings`: beta compatibility bridge for installed mapping bindings
15
+ - `metric.transforms`: beta compatibility bridge for installed transform bindings
16
+
17
+ The same objects are also available as convenience imports from `metric` for short examples.
18
+
19
+ # Installation
20
+
21
+ The Python package is in revival. The current supported CPython targets for the core wheel are 3.10, 3.11, 3.12, 3.13, and 3.14.
22
+
23
+ After the package is published to PyPI, install the core package with:
24
+
25
+ ```shell
26
+ python -m pip install mtrc
27
+ ```
28
+
29
+ Until PyPI publishing is completed, build from source with the instructions below.
30
+
31
+ Packaging now uses `pyproject.toml` with isolated PEP 517 builds and PEP 621 project metadata. `setup.py` provides the CMake extension build hook and the source-distribution hook that carries the required C++ headers into the Python sdist. The build prefers the `pybind11` package from the build environment (`pybind11>=3.0.0`) and falls back to a current FetchContent copy when no CMake package is available.
32
+
33
+ CI builds core wheel artifacts for Linux, macOS, and Windows across the supported CPython versions.
34
+
35
+ # Build from the source
36
+
37
+ ```
38
+ git clone --recurse-submodules https://github.com/metric-space-ai/metric
39
+ ```
40
+
41
+ ## Install Prerequisites
42
+
43
+ ### Ubuntu
44
+
45
+ ```
46
+ sudo apt-get install cmake
47
+ sudo apt-get install libboost-all-dev
48
+ ```
49
+
50
+ OpenBLAS or another BLAS implementation is optional for the revived core wheel. It can improve broader linear-algebra paths, but the CI core wheel builds with `METRIC_PYTHON_USE_BLAS=OFF`.
51
+
52
+ ### Windows
53
+
54
+ Install [Miniconda](https://docs.conda.io/en/latest/miniconda.html).
55
+ In Conda CLI initialize your virtual environment with desired Python version:
56
+
57
+ ```bash
58
+ conda create --name my_env -y python=3.12
59
+ conda activate my_env
60
+ ```
61
+
62
+ OpenBLAS is optional for the revived core wheel. For legacy full bindings or broader linear-algebra paths, install it from conda-forge:
63
+
64
+ ```bash
65
+ conda config --add channels conda-forge
66
+ conda update -n base conda -y
67
+ conda install -c conda-forge libopenblas openblas -y
68
+ ```
69
+
70
+ ## Build package
71
+
72
+ At least 2GB of RAM is required
73
+
74
+ ```
75
+ python -m pip wheel . --no-deps -w dist
76
+ ```
77
+
78
+ By default this builds the revived core bindings. At this stage the default wheel exposes the `Edit` distance binding, space bindings, transform bindings, and the pure Python package surface. The legacy standard-distance, utils, mapping, and correlation bindings still require restoration and can be attempted with:
79
+
80
+ ```shell
81
+ CMAKE_COMMON_VARIABLES="-DMETRIC_PYTHON_BUILD_FULL=ON" python -m pip wheel . --no-deps -w dist
82
+ ```
83
+
84
+ To force the portable core-wheel mode used by CI:
85
+
86
+ ```shell
87
+ CMAKE_COMMON_VARIABLES="-DMETRIC_PYTHON_USE_BLAS=OFF" python -m pip wheel . --no-deps -w dist
88
+ ```
89
+
90
+ ### Install module
91
+
92
+ ```
93
+ python -m pip install dist/*
94
+ ```
95
+
96
+ ## Examples
97
+
98
+ ```python
99
+ from metric import Edit, Space
100
+
101
+ records = ["cat", "cot", "coat", "dog"]
102
+ space = Space(records, Edit())
103
+
104
+ print("distance(cat, cot) =", space(0, 1))
105
+ print("nearest:", space.neighbors("cut", 2))
106
+ ```
107
+
108
+ The core-wheel example is also available at `examples/metric_space/string_edit_space.py`. Full correlation, mapping, and standard-distance examples remain part of the broader restoration path until their bindings are promoted into the default wheel.
109
+
110
+ Small tutorial notebooks live under `notebooks/`. They are paired with
111
+ `notebooks/smoke_notebooks.py`, which executes their code cells in CI after the
112
+ wheel is installed.
113
+
114
+ `metric.mappings` and `metric.transforms` are importable beta namespaces. They expose `available()` and `legacy_module()` so callers can inspect whether a wheel includes the broader legacy bindings without making those bindings part of the core-wheel contract.
115
+
116
+ ## NumPy records
117
+
118
+ The revived Python facade treats NumPy rows as records when the metric callable accepts them:
119
+
120
+ ```python
121
+ import numpy as np
122
+ from metric import Space
123
+
124
+ records = np.array([[0.0, 0.0], [3.0, 4.0], [6.0, 8.0]])
125
+ space = Space(records, lambda lhs, rhs: float(np.linalg.norm(lhs - rhs)))
126
+ print(space.distance(0, 1))
127
+ ```
128
+
129
+ Pairwise distance helpers return Python lists of lists; call `np.asarray(...)` if an ndarray result is required.
@@ -0,0 +1,95 @@
1
+ import os
2
+ import subprocess
3
+ import shutil
4
+ import sys
5
+ from setuptools import Extension
6
+ from setuptools.command.build_ext import build_ext
7
+
8
+ CMAKE_EXE = os.environ.get('CMAKE_EXE', shutil.which('cmake'))
9
+
10
+
11
+ def check_for_cmake():
12
+ if not CMAKE_EXE:
13
+ print('cmake executable not found. '
14
+ 'Set CMAKE_EXE environment or update your path')
15
+ sys.exit(1)
16
+
17
+
18
+ def pybind11_cmake_dir():
19
+ try:
20
+ import pybind11
21
+ except ImportError:
22
+ return None
23
+
24
+ get_cmake_dir = getattr(pybind11, 'get_cmake_dir', None)
25
+ if get_cmake_dir:
26
+ return get_cmake_dir()
27
+
28
+ try:
29
+ return subprocess.check_output(
30
+ [sys.executable, '-m', 'pybind11', '--cmakedir'],
31
+ text=True
32
+ ).strip()
33
+ except (subprocess.CalledProcessError, OSError):
34
+ return None
35
+
36
+
37
+ class CMakeExtension(Extension):
38
+ """
39
+ setuptools.Extension for cmake
40
+ """
41
+
42
+ def __init__(self, name, source_dir='', output_dir=''):
43
+ check_for_cmake()
44
+ Extension.__init__(self, name, sources=[])
45
+ self.source_dir = os.path.abspath(source_dir)
46
+ self.output_dir = output_dir
47
+
48
+
49
+ class CMakeBuildExt(build_ext):
50
+ """
51
+ setuptools build_exit which builds using cmake & make
52
+ You can add cmake args with the CMAKE_COMMON_VARIABLES environment variable
53
+ """
54
+
55
+ def build_extension(self, ext):
56
+ check_for_cmake()
57
+ if isinstance(ext, CMakeExtension):
58
+ output_dir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
59
+
60
+ build_type = 'Debug' if self.debug else 'Release'
61
+ cmake_args = [CMAKE_EXE,
62
+ ext.source_dir,
63
+ '-DPYTHON_EXECUTABLE:FILEPATH=' + sys.executable,
64
+ '-DPython_EXECUTABLE:FILEPATH=' + sys.executable,
65
+ '-DPython3_EXECUTABLE:FILEPATH=' + sys.executable,
66
+ '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + os.path.join(output_dir, ext.output_dir),
67
+ '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG=' + os.path.join(output_dir, ext.output_dir),
68
+ '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=' + os.path.join(output_dir, ext.output_dir),
69
+ '-DCMAKE_BUILD_TYPE=' + build_type]
70
+ pybind11_dir = pybind11_cmake_dir()
71
+ if pybind11_dir:
72
+ cmake_args.append('-Dpybind11_DIR:PATH=' + pybind11_dir)
73
+ cmake_args.extend(
74
+ [x for x in
75
+ os.environ.get('CMAKE_COMMON_VARIABLES', '').split(' ')
76
+ if x])
77
+
78
+ env = os.environ.copy()
79
+ if not os.path.exists(self.build_temp):
80
+ os.makedirs(self.build_temp)
81
+
82
+ subprocess.check_call(cmake_args,
83
+ cwd=self.build_temp,
84
+ env=env)
85
+ build_args = [CMAKE_EXE, '--build', '.', '--config', build_type]
86
+ if ext.name != 'all':
87
+ build_args.extend(['--target', ext.name])
88
+ subprocess.check_call(build_args,
89
+ cwd=self.build_temp,
90
+ env=env)
91
+ else:
92
+ super().build_extension(ext)
93
+
94
+
95
+ __all__ = ['CMakeBuildExt', 'CMakeExtension']
@@ -0,0 +1,107 @@
1
+ /*
2
+ * Fast discrete cosine transform algorithms (C)
3
+ *
4
+ * Copyright (c) 2019 Project Nayuki. (MIT License)
5
+ * https://www.nayuki.io/page/fast-discrete-cosine-transform-algorithms
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
8
+ * this software and associated documentation files (the "Software"), to deal in
9
+ * the Software without restriction, including without limitation the rights to
10
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11
+ * the Software, and to permit persons to whom the Software is furnished to do so,
12
+ * subject to the following conditions:
13
+ * - The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ * - The Software is provided "as is", without warranty of any kind, express or
16
+ * implied, including but not limited to the warranties of merchantability,
17
+ * fitness for a particular purpose and noninfringement. In no event shall the
18
+ * authors or copyright holders be liable for any claim, damages or other
19
+ * liability, whether in an action of contract, tort or otherwise, arising from,
20
+ * out of or in connection with the Software or the use or other dealings in the
21
+ * Software.
22
+ */
23
+
24
+ #include "fast-dct-lee.h"
25
+ #include <math.h>
26
+ #include <stdint.h>
27
+ #include <stdlib.h>
28
+
29
+ static void forwardTransform(double vector[], double temp[], size_t len);
30
+ static void inverseTransform(double vector[], double temp[], size_t len);
31
+
32
+ // DCT type II, unscaled. Algorithm by Byeong Gi Lee, 1984.
33
+ // See: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.118.3056&rep=rep1&type=pdf#page=34
34
+ inline bool FastDctLee_transform(double vector[], size_t len)
35
+ {
36
+ if (len <= 0 || (len & (len - 1)) != 0)
37
+ return false; // Length is not power of 2
38
+ if (SIZE_MAX / sizeof(double) < len)
39
+ return false;
40
+ // double *temp = malloc(len * sizeof(double));
41
+ double *temp = (double *)malloc(len * sizeof(double)); // added by Max F for compatibility with c++
42
+ if (temp == NULL)
43
+ return false;
44
+ forwardTransform(vector, temp, len);
45
+ free(temp);
46
+ return true;
47
+ }
48
+
49
+ static void forwardTransform(double vector[], double temp[], size_t len)
50
+ {
51
+ if (len == 1)
52
+ return;
53
+ size_t halfLen = len / 2;
54
+ for (size_t i = 0; i < halfLen; i++) {
55
+ double x = vector[i];
56
+ double y = vector[len - 1 - i];
57
+ temp[i] = x + y;
58
+ temp[i + halfLen] = (x - y) / (cos((i + 0.5) * M_PI / len) * 2);
59
+ }
60
+ forwardTransform(temp, vector, halfLen);
61
+ forwardTransform(&temp[halfLen], vector, halfLen);
62
+ for (size_t i = 0; i < halfLen - 1; i++) {
63
+ vector[i * 2 + 0] = temp[i];
64
+ vector[i * 2 + 1] = temp[i + halfLen] + temp[i + halfLen + 1];
65
+ }
66
+ vector[len - 2] = temp[halfLen - 1];
67
+ vector[len - 1] = temp[len - 1];
68
+ }
69
+
70
+ // DCT type III, unscaled. Algorithm by Byeong Gi Lee, 1984.
71
+ // See: https://www.nayuki.io/res/fast-discrete-cosine-transform-algorithms/lee-new-algo-discrete-cosine-transform.pdf
72
+ inline bool FastDctLee_inverseTransform(double vector[], size_t len)
73
+ {
74
+ if (len <= 0 || (len & (len - 1)) != 0)
75
+ return false; // Length is not power of 2
76
+ if (SIZE_MAX / sizeof(double) < len)
77
+ return false;
78
+ // double *temp = malloc(len * sizeof(double));
79
+ double *temp = (double *)malloc(len * sizeof(double)); // added by Max F for compatibility with c++
80
+ if (temp == NULL)
81
+ return false;
82
+ vector[0] /= 2;
83
+ inverseTransform(vector, temp, len);
84
+ free(temp);
85
+ return true;
86
+ }
87
+
88
+ static void inverseTransform(double vector[], double temp[], size_t len)
89
+ {
90
+ if (len == 1)
91
+ return;
92
+ size_t halfLen = len / 2;
93
+ temp[0] = vector[0];
94
+ temp[halfLen] = vector[1];
95
+ for (size_t i = 1; i < halfLen; i++) {
96
+ temp[i] = vector[i * 2];
97
+ temp[i + halfLen] = vector[i * 2 - 1] + vector[i * 2 + 1];
98
+ }
99
+ inverseTransform(temp, vector, halfLen);
100
+ inverseTransform(&temp[halfLen], vector, halfLen);
101
+ for (size_t i = 0; i < halfLen; i++) {
102
+ double x = temp[i];
103
+ double y = temp[i + halfLen] / (cos((i + 0.5) * M_PI / len) * 2);
104
+ vector[i] = x + y;
105
+ vector[len - 1 - i] = x - y;
106
+ }
107
+ }
@@ -0,0 +1,39 @@
1
+ /*
2
+ * Fast discrete cosine transform algorithms (C)
3
+ *
4
+ * Copyright (c) 2018 Project Nayuki. (MIT License)
5
+ * https://www.nayuki.io/page/fast-discrete-cosine-transform-algorithms
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
8
+ * this software and associated documentation files (the "Software"), to deal in
9
+ * the Software without restriction, including without limitation the rights to
10
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11
+ * the Software, and to permit persons to whom the Software is furnished to do so,
12
+ * subject to the following conditions:
13
+ * - The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ * - The Software is provided "as is", without warranty of any kind, express or
16
+ * implied, including but not limited to the warranties of merchantability,
17
+ * fitness for a particular purpose and noninfringement. In no event shall the
18
+ * authors or copyright holders be liable for any claim, damages or other
19
+ * liability, whether in an action of contract, tort or otherwise, arising from,
20
+ * out of or in connection with the Software or the use or other dealings in the
21
+ * Software.
22
+ */
23
+
24
+ #pragma once
25
+
26
+ #include <stdbool.h>
27
+ #include <stddef.h>
28
+
29
+ #ifdef __cplusplus
30
+ extern "C" {
31
+ #endif
32
+
33
+ bool FastDctLee_transform(double vector[], size_t len);
34
+
35
+ bool FastDctLee_inverseTransform(double vector[], size_t len);
36
+
37
+ #ifdef __cplusplus
38
+ }
39
+ #endif