Debian Codegraph @

c_api/IndexPreTransform_c.cpp

raw
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 #include "IndexPreTransform_c.h"
11 #include <faiss/IndexPreTransform.h>
12 #include <faiss/VectorTransform.h>
13 #include "macros_impl.h"
14
15 using faiss::Index;
16 using faiss::IndexPreTransform;
17 using faiss::VectorTransform;
18
19 extern "C" {
20
21 DEFINE_DESTRUCTOR(IndexPreTransform)
22 DEFINE_INDEX_DOWNCAST(IndexPreTransform)
23
24 DEFINE_GETTER_PERMISSIVE(IndexPreTransform, FaissIndex*, index)
25
26 DEFINE_GETTER(IndexPreTransform, int, own_fields)
27 DEFINE_SETTER(IndexPreTransform, int, own_fields)
28
29 int faiss_IndexPreTransform_new(FaissIndexPreTransform** p_index) {
30 try {
31 *p_index = reinterpret_cast<FaissIndexPreTransform*>(
32 new IndexPreTransform());
33 }
34 CATCH_AND_HANDLE
35 }
36
37 int faiss_IndexPreTransform_new_with(
38 FaissIndexPreTransform** p_index,
39 FaissIndex* index) {
40 try {
41 auto ind = reinterpret_cast<Index*>(index);
42 *p_index = reinterpret_cast<FaissIndexPreTransform*>(
43 new IndexPreTransform(ind));
44 }
45 CATCH_AND_HANDLE
46 }
47
48 int faiss_IndexPreTransform_new_with_transform(
49 FaissIndexPreTransform** p_index,
50 FaissVectorTransform* ltrans,
51 FaissIndex* index) {
52 try {
53 auto lt = reinterpret_cast<VectorTransform*>(ltrans);
54 auto ind = reinterpret_cast<Index*>(index);
55 *p_index = reinterpret_cast<FaissIndexPreTransform*>(
56 new IndexPreTransform(lt, ind));
57 }
58 CATCH_AND_HANDLE
59 }
60
61 int faiss_IndexPreTransform_prepend_transform(
62 FaissIndexPreTransform* index,
63 FaissVectorTransform* ltrans) {
64 try {
65 auto lt = reinterpret_cast<VectorTransform*>(ltrans);
66 reinterpret_cast<IndexPreTransform*>(index)->prepend_transform(lt);
67 }
68 CATCH_AND_HANDLE
69 }
70 }