/root/doris/contrib/faiss/faiss/impl/FaissException.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) Meta Platforms, Inc. and affiliates. |
3 | | * |
4 | | * This source code is licensed under the MIT license found in the |
5 | | * LICENSE file in the root directory of this source tree. |
6 | | */ |
7 | | |
8 | | // -*- c++ -*- |
9 | | |
10 | | #ifndef FAISS_EXCEPTION_INCLUDED |
11 | | #define FAISS_EXCEPTION_INCLUDED |
12 | | |
13 | | #include <exception> |
14 | | #include <string> |
15 | | #include <utility> |
16 | | #include <vector> |
17 | | |
18 | | namespace faiss { |
19 | | |
20 | | /// Base class for Faiss exceptions |
21 | | class FaissException : public std::exception { |
22 | | public: |
23 | | explicit FaissException(const std::string& msg); |
24 | | |
25 | | FaissException( |
26 | | const std::string& msg, |
27 | | const char* funcName, |
28 | | const char* file, |
29 | | int line); |
30 | | |
31 | | /// from std::exception |
32 | | const char* what() const noexcept override; |
33 | | |
34 | | std::string msg; |
35 | | }; |
36 | | |
37 | | /// Handle multiple exceptions from worker threads, throwing an appropriate |
38 | | /// exception that aggregates the information |
39 | | /// The pair int is the thread that generated the exception |
40 | | void handleExceptions( |
41 | | std::vector<std::pair<int, std::exception_ptr>>& exceptions); |
42 | | |
43 | | /** RAII object for a set of possibly transformed vectors (deallocated only if |
44 | | * they are indeed transformed) |
45 | | */ |
46 | | struct TransformedVectors { |
47 | | const float* x; |
48 | | bool own_x; |
49 | 0 | TransformedVectors(const float* x_orig, const float* x) : x(x) { |
50 | 0 | own_x = x_orig != x; |
51 | 0 | } |
52 | | |
53 | 0 | ~TransformedVectors() { |
54 | 0 | if (own_x) { |
55 | 0 | delete[] x; |
56 | 0 | } |
57 | 0 | } |
58 | | }; |
59 | | |
60 | | /// make typeids more readable |
61 | | std::string demangle_cpp_symbol(const char* name); |
62 | | |
63 | | } // namespace faiss |
64 | | |
65 | | #endif |