11 #ifndef FAISS_ASSERT_INCLUDED
12 #define FAISS_ASSERT_INCLUDED
14 #include "FaissException.h"
23 #define FAISS_ASSERT(X) \
26 fprintf(stderr, "Faiss assertion '%s' failed in %s " \
28 #X, __PRETTY_FUNCTION__, __FILE__, __LINE__); \
33 #define FAISS_ASSERT_MSG(X, MSG) \
36 fprintf(stderr, "Faiss assertion '%s' failed in %s " \
37 "at %s:%d; details: " MSG "\n", \
38 #X, __PRETTY_FUNCTION__, __FILE__, __LINE__); \
43 #define FAISS_ASSERT_FMT(X, FMT, ...) \
46 fprintf(stderr, "Faiss assertion '%s' failed in %s " \
47 "at %s:%d; details: " FMT "\n", \
48 #X, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); \
57 #define FAISS_THROW_MSG(MSG) \
59 throw FaissException(MSG, __PRETTY_FUNCTION__, __FILE__, __LINE__); \
62 #define FAISS_THROW_FMT(FMT, ...) \
65 int __size = snprintf(nullptr, 0, FMT, __VA_ARGS__); \
66 __s.resize(__size + 1); \
67 snprintf(&__s[0], __s.size(), FMT, __VA_ARGS__); \
68 throw FaissException(__s, __PRETTY_FUNCTION__, __FILE__, __LINE__); \
75 #define FAISS_THROW_IF_NOT(X) \
78 FAISS_THROW_FMT("Error: '%s' failed", #X); \
82 #define FAISS_THROW_IF_NOT_MSG(X, MSG) \
85 FAISS_THROW_FMT("Error: '%s' failed: " MSG, #X); \
89 #define FAISS_THROW_IF_NOT_FMT(X, FMT, ...) \
92 FAISS_THROW_FMT("Error: '%s' failed: " FMT, #X, __VA_ARGS__); \