diff --git a/doc/libkissinference.doxygen.in b/doc/libkissinference.doxygen.in index a9d556fb80f62afbc19be542025566d2393b0ce2..d8f515bbf13e43523c10a8991d9dd868efa19918 100644 --- a/doc/libkissinference.doxygen.in +++ b/doc/libkissinference.doxygen.in @@ -38,7 +38,7 @@ PROJECT_NAME = @PROJECT_NAME@ # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 1.0.x +PROJECT_NUMBER = 1.1.x # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/examples/classify.cpp b/examples/classify.cpp index 3eaedb7f89644093406cbae01db91bba12c90ca4..113057e8578d5046d394f32dd00349a90811bc4a 100644 --- a/examples/classify.cpp +++ b/examples/classify.cpp @@ -7,6 +7,7 @@ #include <condition_variable> #include <mutex> #include <limits> +#include <algorithm> #include "kissinference/kissinference.h" @@ -113,11 +114,15 @@ static void resultCallback(float* data, struct kiss_network* net, void* userData } else { + std::vector<std::pair<std::string, float>> results; + for(size_t i = 0; i < net->output_size; ++i) + results.push_back({net->output_labels[i], data[i]}); + std::sort(results.begin(), results.end(), [](std::pair<std::string, float> a, std::pair<std::string, float> b){return a.second > b.second;}); printmtx.lock(); OUTSTREAM<<"\nResult for "<<rq->path<<'\n'; OUTSTREAM<<"Classes:\nNumber\tName\tLikelyhood\n"; for(size_t i = 0; i < net->output_size; ++i) - OUTSTREAM<<i<<'\t'<<net->output_labels[i]<<'\t'<<data[i]<<'\n'; + OUTSTREAM<<i<<'\t'<<results[i].first<<'\t'<<results[i].second<<'\n'; printmtx.unlock(); } diff --git a/kissinference.c b/kissinference.c index 8fdbfd5348decafc0b67a4e81ad3aa5293421aa3..cef71e266900c491b86e86770d5a9e2007293a26 100644 --- a/kissinference.c +++ b/kissinference.c @@ -47,7 +47,7 @@ void kiss_inference_req_free(struct kiss_inference_req *req) const struct kiss_version_fixed kiss_get_version(void) { - static const struct kiss_version_fixed version = {1, 0, 0}; + static const struct kiss_version_fixed version = {1, 1, 0}; return version; } @@ -654,6 +654,12 @@ const char *kiss_get_strerror(struct kiss_network *net) return net->priv->err; } +bool kiss_float_eq(float a, float b, unsigned int ulp) +{ + float epsilon = (nextafterf(1.0f, INFINITY) - 1.0f)*fabs(a+b)*ulp; + return a - epsilon <= b && a + epsilon >= b; +} + void kiss_free(void *data) { free(data); diff --git a/kissinference/kissinference.h b/kissinference/kissinference.h index 305d4a1d8a19c309bab87f4ce54621b502ada326..9b3ed602efa4401c4c270ffc2a6035871ef1b1c6 100644 --- a/kissinference/kissinference.h +++ b/kissinference/kissinference.h @@ -222,6 +222,21 @@ const char *kiss_get_strerror(struct kiss_network *net); */ void kiss_softmax(float *data, size_t input_length); +/** + * @brief Checks the given floats for equality with a tollerance of ulp epsilons around the sum of the inputs. + * + * @param a The first input. + * @param b The second input to be compared with the first. + * @param ulp number of epsilons of tollerance. + * @return True if the value of b is within ulp epsilons of a, false otherwise. + */ +bool kiss_float_eq(float a, float b, unsigned int ulp); + +/** + * @brief Frees the data with the same allocateor libkissinference was compiled against. + * + * @param data A pointer to the data to free + */ void kiss_free(void *data); /**