From 5b3d81bed46330b7194f096d56e03c4d4be1d111 Mon Sep 17 00:00:00 2001 From: James Melville Date: Sun, 17 Sep 2023 16:05:56 -0700 Subject: [PATCH 1/4] define a macro for error stream --- hnswlib/hnswlib.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hnswlib/hnswlib.h b/hnswlib/hnswlib.h index 402c6d8c..1e67a8be 100644 --- a/hnswlib/hnswlib.h +++ b/hnswlib/hnswlib.h @@ -1,4 +1,11 @@ #pragma once + +#ifndef HNSWLIB_ERR_OVERRIDE + #define HNSWERR std::cerr +#else + #define HNSWERR HNSWLIB_ERR_OVERRIDE +#endif + #ifndef NO_MANUAL_VECTORIZATION #if (defined(__SSE__) || _M_IX86_FP > 0 || defined(_M_AMD64) || defined(_M_X64)) #define USE_SSE From f7ec14739984725466a5763a544595497116e3f5 Mon Sep 17 00:00:00 2001 From: James Melville Date: Sun, 17 Sep 2023 16:06:21 -0700 Subject: [PATCH 2/4] use HNSWERR instead of std::cerr directly --- hnswlib/hnswalg.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hnswlib/hnswalg.h b/hnswlib/hnswalg.h index b4a22e2a..8bdca40c 100644 --- a/hnswlib/hnswalg.h +++ b/hnswlib/hnswalg.h @@ -105,8 +105,8 @@ class HierarchicalNSW : public AlgorithmInterface { if ( M <= 10000 ) { M_ = M; } else { - std::cerr << "warning: M parameter exceeds 10000 which may lead to adverse effects." << std::endl; - std::cerr << " Cap to 10000 will be applied for the rest of the processing." << std::endl; + HNSWERR << "warning: M parameter exceeds 10000 which may lead to adverse effects." << std::endl; + HNSWERR << " Cap to 10000 will be applied for the rest of the processing." << std::endl; M_ = 10000; } maxM_ = M_; From 92e053a1c51e21b5d1de6af2893361bed30b0dbb Mon Sep 17 00:00:00 2001 From: James Melville Date: Sun, 17 Sep 2023 16:12:18 -0700 Subject: [PATCH 3/4] Add a comment --- hnswlib/hnswlib.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hnswlib/hnswlib.h b/hnswlib/hnswlib.h index 1e67a8be..393dbd8d 100644 --- a/hnswlib/hnswlib.h +++ b/hnswlib/hnswlib.h @@ -1,5 +1,7 @@ #pragma once +// This allows others to provide their own error stream. +// See RcppHNSW for a use case. #ifndef HNSWLIB_ERR_OVERRIDE #define HNSWERR std::cerr #else From a9e62cbaefd5f604a1b73ec8a691648a6029b1ee Mon Sep 17 00:00:00 2001 From: James Melville Date: Thu, 28 Sep 2023 20:54:35 -0700 Subject: [PATCH 4/4] Add link to PR in comment --- hnswlib/hnswlib.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hnswlib/hnswlib.h b/hnswlib/hnswlib.h index 393dbd8d..127a4d68 100644 --- a/hnswlib/hnswlib.h +++ b/hnswlib/hnswlib.h @@ -1,7 +1,7 @@ #pragma once -// This allows others to provide their own error stream. -// See RcppHNSW for a use case. +// https://github.com/nmslib/hnswlib/pull/508 +// This allows others to provide their own error stream (e.g. RcppHNSW) #ifndef HNSWLIB_ERR_OVERRIDE #define HNSWERR std::cerr #else