Debian Codegraph @

c_api/VectorTransform_c.h

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 #ifndef FAISS_VECTOR_TRANSFORM_C_H
11 #define FAISS_VECTOR_TRANSFORM_C_H
12
13 /** Defines a few objects that apply transformations to a set of
14 * vectors Often these are pre-processing steps.
15 */
16
17 #include "faiss_c.h"
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 /// Opaque type for referencing to a VectorTransform object
24 FAISS_DECLARE_CLASS(VectorTransform)
25 FAISS_DECLARE_DESTRUCTOR(VectorTransform)
26
27 /// Getter for is_trained
28 FAISS_DECLARE_GETTER(VectorTransform, int, is_trained)
29
30 /// Getter for input dimension
31 FAISS_DECLARE_GETTER(VectorTransform, int, d_in)
32
33 /// Getter for output dimension
34 FAISS_DECLARE_GETTER(VectorTransform, int, d_out)
35
36 /** Perform training on a representative set of vectors
37 *
38 * @param vt opaque pointer to VectorTransform object
39 * @param n nb of training vectors
40 * @param x training vectors, size n * d
41 */
42 int faiss_VectorTransform_train(
43 FaissVectorTransform* vt,
44 idx_t n,
45 const float* x);
46
47 /** apply the random rotation, return new allocated matrix
48 * @param x size n * d_in
49 * @return size n * d_out
50 */
51 float* faiss_VectorTransform_apply(
52 const FaissVectorTransform* vt,
53 idx_t n,
54 const float* x);
55
56 /** apply transformation and result is pre-allocated
57 * @param x size n * d_in
58 * @param xt size n * d_out
59 */
60 void faiss_VectorTransform_apply_noalloc(
61 const FaissVectorTransform* vt,
62 idx_t n,
63 const float* x,
64 float* xt);
65
66 /// reverse transformation. May not be implemented or may return
67 /// approximate result
68 void faiss_VectorTransform_reverse_transform(
69 const FaissVectorTransform* vt,
70 idx_t n,
71 const float* xt,
72 float* x);
73
74 /// Opaque type for referencing to a LinearTransform object
75 FAISS_DECLARE_CLASS_INHERITED(LinearTransform, VectorTransform)
76 FAISS_DECLARE_DESTRUCTOR(LinearTransform)
77
78 /// compute x = A^T * (x - b)
79 /// is reverse transform if A has orthonormal lines
80 void faiss_LinearTransform_transform_transpose(
81 const FaissLinearTransform* vt,
82 idx_t n,
83 const float* y,
84 float* x);
85
86 /// compute A^T * A to set the is_orthonormal flag
87 void faiss_LinearTransform_set_is_orthonormal(FaissLinearTransform* vt);
88
89 /// Getter for have_bias
90 FAISS_DECLARE_GETTER(LinearTransform, int, have_bias)
91
92 /// Getter for is_orthonormal
93 FAISS_DECLARE_GETTER(LinearTransform, int, is_orthonormal)
94
95 FAISS_DECLARE_CLASS_INHERITED(RandomRotationMatrix, VectorTransform)
96 FAISS_DECLARE_DESTRUCTOR(RandomRotationMatrix)
97
98 int faiss_RandomRotationMatrix_new_with(
99 FaissRandomRotationMatrix** p_vt,
100 int d_in,
101 int d_out);
102
103 FAISS_DECLARE_CLASS_INHERITED(PCAMatrix, VectorTransform)
104 FAISS_DECLARE_DESTRUCTOR(PCAMatrix)
105
106 int faiss_PCAMatrix_new_with(
107 FaissPCAMatrix** p_vt,
108 int d_in,
109 int d_out,
110 float eigen_power,
111 int random_rotation);
112
113 /// Getter for eigen_power
114 FAISS_DECLARE_GETTER(PCAMatrix, float, eigen_power)
115
116 /// Getter for random_rotation
117 FAISS_DECLARE_GETTER(PCAMatrix, int, random_rotation)
118
119 /// Getter for balanced_bins
120 FAISS_DECLARE_GETTER(PCAMatrix, int, balanced_bins)
121
122 /// Setter for balanced_bins
123 FAISS_DECLARE_SETTER(PCAMatrix, int, balanced_bins)
124
125 FAISS_DECLARE_CLASS_INHERITED(ITQMatrix, VectorTransform)
126 FAISS_DECLARE_DESTRUCTOR(ITQMatrix)
127
128 int faiss_ITQMatrix_new_with(FaissITQMatrix** p_vt, int d);
129
130 FAISS_DECLARE_CLASS_INHERITED(ITQTransform, VectorTransform)
131 FAISS_DECLARE_DESTRUCTOR(ITQTransform)
132
133 int faiss_ITQTransform_new_with(
134 FaissITQTransform** p_vt,
135 int d_in,
136 int d_out,
137 int do_pca);
138
139 /// Getter for do_pca
140 FAISS_DECLARE_GETTER(ITQTransform, int, do_pca)
141
142 FAISS_DECLARE_CLASS_INHERITED(OPQMatrix, VectorTransform)
143 FAISS_DECLARE_DESTRUCTOR(OPQMatrix)
144
145 int faiss_OPQMatrix_new_with(FaissOPQMatrix** p_vt, int d, int M, int d2);
146
147 FAISS_DECLARE_GETTER_SETTER(OPQMatrix, int, verbose)
148 FAISS_DECLARE_GETTER_SETTER(OPQMatrix, int, niter)
149 FAISS_DECLARE_GETTER_SETTER(OPQMatrix, int, niter_pq)
150
151 FAISS_DECLARE_CLASS_INHERITED(RemapDimensionsTransform, VectorTransform)
152 FAISS_DECLARE_DESTRUCTOR(RemapDimensionsTransform)
153
154 int faiss_RemapDimensionsTransform_new_with(
155 FaissRemapDimensionsTransform** p_vt,
156 int d_in,
157 int d_out,
158 int uniform);
159
160 FAISS_DECLARE_CLASS_INHERITED(NormalizationTransform, VectorTransform)
161 FAISS_DECLARE_DESTRUCTOR(NormalizationTransform)
162
163 int faiss_NormalizationTransform_new_with(
164 FaissNormalizationTransform** p_vt,
165 int d,
166 float norm);
167
168 FAISS_DECLARE_GETTER(NormalizationTransform, float, norm)
169
170 FAISS_DECLARE_CLASS_INHERITED(CenteringTransform, VectorTransform)
171 FAISS_DECLARE_DESTRUCTOR(CenteringTransform)
172
173 int faiss_CenteringTransform_new_with(FaissCenteringTransform** p_vt, int d);
174
175 #ifdef __cplusplus
176 }
177 #endif
178
179 #endif