From 3d09ee05eaf25d55f9aa7f7c0806469ec0578877 Mon Sep 17 00:00:00 2001 From: Artem Date: Sat, 13 Mar 2021 09:06:09 +0100 Subject: [PATCH] C API corrected, respective makefile and description updated --- makefile_libxmeasures => Makefile_lib | 4 ++-- README.md | 2 +- include/interface_c.h | 10 ++++++---- src/interface_c.cpp | 20 ++++++++++++++++---- 4 files changed, 25 insertions(+), 11 deletions(-) rename makefile_libxmeasures => Makefile_lib (97%) diff --git a/makefile_libxmeasures b/Makefile_lib similarity index 97% rename from makefile_libxmeasures rename to Makefile_lib index bdafa6f..05c397b 100644 --- a/makefile_libxmeasures +++ b/Makefile_lib @@ -27,7 +27,7 @@ LIB_DEBUG = $(LIB)-lasan LDFLAGS_DEBUG = $(LDFLAGS) OBJDIR_DEBUG = obj/Debug DEP_DEBUG = -OUT_DEBUG = bin/Debug/xmeasures.so +OUT_DEBUG = bin/Debug/libxmeasures.so INC_RELEASE = $(INC) CFLAGS_RELEASE = $(CFLAGS) -fomit-frame-pointer -O3 -march=core2 -ftemplate-backtrace-limit=32 -Wno-strict-aliasing -DTRACE=1 -DVALIDATE=1 @@ -38,7 +38,7 @@ LIB_RELEASE = $(LIB) LDFLAGS_RELEASE = $(LDFLAGS) -s OBJDIR_RELEASE = obj/Release DEP_RELEASE = -OUT_RELEASE = bin/Release/xmeasures.so +OUT_RELEASE = bin/Release/libxmeasures.so OBJ_DEBUG = $(OBJDIR_DEBUG)/src/interface.o $(OBJDIR_DEBUG)/src/interface_c.o diff --git a/README.md b/README.md index 0ddcdd1..9cdd822 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ Some core functionality of xmeasures is available as a library with C API, makin The interface is defined in `include/interface_c.h`. To build the library, execute: ``` -$ make -f makefile_libxmeasures release +$ make -f Makefile_lib release ``` # Usage diff --git a/include/interface_c.h b/include/interface_c.h index 99015b4..1b49f9a 100644 --- a/include/interface_c.h +++ b/include/interface_c.h @@ -77,17 +77,19 @@ typedef float Probability; //! \param cn1 const ClusterCollection - first collection of clusters (node relations) //! \param cn2 const ClusterCollection - second collection //! \param kind F1Kind - kind of F1 to be evaluated -//! \param rec Probability& - recall of cn2 relative to the ground-truth cn1 or +//! \param[out] rec Probability* - recall of cn2 relative to the ground-truth cn1 or //! 0 if the matching strategy does not have the precision/recall notations -//! \param prc Probability& - precision of cn2 relative to the ground-truth cn1 or +//! \param[out] prc Probability* - precision of cn2 relative to the ground-truth cn1 or //! 0 if the matching strategy does not have the precision/recall notations //! \param mkind=MATCH_WEIGHTED MatchKind - matching kind //! \param verbose=0 uint8_t - print intermediate results to the stdout //! \return Probability - resulting F1_gm Probability f1x(const ClusterCollection cn1, const ClusterCollection cn2, F1Kind kind - , Probability& rec, Probability& prc, MatchKind mkind, uint8_t verbose); + , Probability* rec, Probability* prc, MatchKind mkind, uint8_t verbose); Probability f1(const ClusterCollection cn1, const ClusterCollection cn2, F1Kind kind - , Probability& rec, Probability& prc); // MATCH_WEIGHTED, false + , Probability* rec, Probability* prc); // MATCH_WEIGHTED, false +Probability f1p(const ClusterCollection cn1, const ClusterCollection cn2); // MATCH_WEIGHTED, false +Probability f1h(const ClusterCollection cn1, const ClusterCollection cn2); // MATCH_WEIGHTED, false //! \brief (Extended) Omega Index evaluation //! diff --git a/src/interface_c.cpp b/src/interface_c.cpp index d136c4f..e888710 100644 --- a/src/interface_c.cpp +++ b/src/interface_c.cpp @@ -158,19 +158,31 @@ Collection loadCollection(const ClusterCollection rcn, bool makeunique } // Interface implementation ---------------------------------------------------- +Probability f1p(const ClusterCollection cn1, const ClusterCollection cn2) +{ + return f1(cn1, cn2, F1_PARTPROB, nullptr, nullptr); +} + +Probability f1h(const ClusterCollection cn1, const ClusterCollection cn2) +{ + return f1(cn1, cn2, F1_HARMONIC, nullptr, nullptr); +} + Probability f1(const ClusterCollection cn1, const ClusterCollection cn2, F1Kind kind - , Probability& rec, Probability& prc) + , Probability* rec, Probability* prc) { - return f1x(cn1, cn2, kind, rec, prc, MATCH_WEIGHTED, 0); + Probability tmp; // Temporary buffer, a placeholder + return f1x(cn1, cn2, kind, rec ? rec : &tmp, prc ? prc : &tmp, MATCH_WEIGHTED, 0); } Probability f1x(const ClusterCollection cn1, const ClusterCollection cn2, F1Kind kind - , Probability& rec, Probability& prc, MatchKind mkind, uint8_t verbose) + , Probability* rec, Probability* prc, MatchKind mkind, uint8_t verbose) { // Load nodes const auto c1 = loadCollection(cn1); const auto c2 = loadCollection(cn2); - return Collection::f1(c1, c2, static_cast(kind), rec, prc, static_cast(mkind), verbose); + assert(rec && prc && "Invalid output arguments"); + return Collection::f1(c1, c2, static_cast(kind), *rec, *prc, static_cast(mkind), verbose); } Probability omega(const ClusterCollection cn1, const ClusterCollection cn2)