10 #ifndef FAISS_ASSERT_INCLUDED
11 #define FAISS_ASSERT_INCLUDED
13 #include "FaissException.h"
22 #define FAISS_ASSERT(X) \
25 fprintf(stderr, "Faiss assertion '%s' failed in %s " \
27 #X, __PRETTY_FUNCTION__, __FILE__, __LINE__); \
32 #define FAISS_ASSERT_MSG(X, MSG) \
35 fprintf(stderr, "Faiss assertion '%s' failed in %s " \
36 "at %s:%d; details: " MSG "\n", \
37 #X, __PRETTY_FUNCTION__, __FILE__, __LINE__); \
42 #define FAISS_ASSERT_FMT(X, FMT, ...) \
45 fprintf(stderr, "Faiss assertion '%s' failed in %s " \
46 "at %s:%d; details: " FMT "\n", \
47 #X, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); \
56 #define FAISS_THROW_MSG(MSG) \
58 throw faiss::FaissException(MSG, __PRETTY_FUNCTION__, __FILE__, __LINE__); \
61 #define FAISS_THROW_FMT(FMT, ...) \
64 int __size = snprintf(nullptr, 0, FMT, __VA_ARGS__); \
65 __s.resize(__size + 1); \
66 snprintf(&__s[0], __s.size(), FMT, __VA_ARGS__); \
67 throw faiss::FaissException(__s, __PRETTY_FUNCTION__, __FILE__, __LINE__); \
74 #define FAISS_THROW_IF_NOT(X) \
77 FAISS_THROW_FMT("Error: '%s' failed", #X); \
81 #define FAISS_THROW_IF_NOT_MSG(X, MSG) \
84 FAISS_THROW_FMT("Error: '%s' failed: " MSG, #X); \
88 #define FAISS_THROW_IF_NOT_FMT(X, FMT, ...) \
91 FAISS_THROW_FMT("Error: '%s' failed: " FMT, #X, __VA_ARGS__); \