faiss 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +1 -1
- data/README.md +1 -1
- data/ext/faiss/extconf.rb +9 -2
- data/ext/faiss/index.cpp +1 -1
- data/ext/faiss/index_binary.cpp +2 -2
- data/ext/faiss/product_quantizer.cpp +1 -1
- data/lib/faiss/version.rb +1 -1
- data/vendor/faiss/faiss/AutoTune.cpp +7 -7
- data/vendor/faiss/faiss/AutoTune.h +0 -1
- data/vendor/faiss/faiss/Clustering.cpp +4 -18
- data/vendor/faiss/faiss/Clustering.h +31 -21
- data/vendor/faiss/faiss/IVFlib.cpp +22 -11
- data/vendor/faiss/faiss/Index.cpp +1 -1
- data/vendor/faiss/faiss/Index.h +20 -5
- data/vendor/faiss/faiss/Index2Layer.cpp +7 -7
- data/vendor/faiss/faiss/IndexAdditiveQuantizer.cpp +176 -166
- data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.cpp +15 -15
- data/vendor/faiss/faiss/IndexBinary.cpp +9 -4
- data/vendor/faiss/faiss/IndexBinary.h +8 -19
- data/vendor/faiss/faiss/IndexBinaryFromFloat.cpp +2 -1
- data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +24 -31
- data/vendor/faiss/faiss/IndexBinaryHash.cpp +25 -50
- data/vendor/faiss/faiss/IndexBinaryIVF.cpp +106 -187
- data/vendor/faiss/faiss/IndexFastScan.cpp +90 -159
- data/vendor/faiss/faiss/IndexFastScan.h +9 -8
- data/vendor/faiss/faiss/IndexFlat.cpp +195 -3
- data/vendor/faiss/faiss/IndexFlat.h +20 -1
- data/vendor/faiss/faiss/IndexFlatCodes.cpp +11 -0
- data/vendor/faiss/faiss/IndexFlatCodes.h +3 -1
- data/vendor/faiss/faiss/IndexHNSW.cpp +112 -316
- data/vendor/faiss/faiss/IndexHNSW.h +12 -48
- data/vendor/faiss/faiss/IndexIDMap.cpp +69 -28
- data/vendor/faiss/faiss/IndexIDMap.h +24 -2
- data/vendor/faiss/faiss/IndexIVF.cpp +159 -53
- data/vendor/faiss/faiss/IndexIVF.h +37 -5
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.cpp +18 -26
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.h +3 -2
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.cpp +19 -46
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.h +4 -3
- data/vendor/faiss/faiss/IndexIVFFastScan.cpp +433 -405
- data/vendor/faiss/faiss/IndexIVFFastScan.h +56 -26
- data/vendor/faiss/faiss/IndexIVFFlat.cpp +15 -5
- data/vendor/faiss/faiss/IndexIVFFlat.h +3 -2
- data/vendor/faiss/faiss/IndexIVFIndependentQuantizer.cpp +172 -0
- data/vendor/faiss/faiss/IndexIVFIndependentQuantizer.h +56 -0
- data/vendor/faiss/faiss/IndexIVFPQ.cpp +78 -122
- data/vendor/faiss/faiss/IndexIVFPQ.h +6 -7
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +18 -50
- data/vendor/faiss/faiss/IndexIVFPQFastScan.h +4 -3
- data/vendor/faiss/faiss/IndexIVFPQR.cpp +45 -29
- data/vendor/faiss/faiss/IndexIVFPQR.h +5 -2
- data/vendor/faiss/faiss/IndexIVFSpectralHash.cpp +25 -27
- data/vendor/faiss/faiss/IndexIVFSpectralHash.h +6 -6
- data/vendor/faiss/faiss/IndexLSH.cpp +14 -16
- data/vendor/faiss/faiss/IndexNNDescent.cpp +3 -4
- data/vendor/faiss/faiss/IndexNSG.cpp +11 -27
- data/vendor/faiss/faiss/IndexNSG.h +10 -10
- data/vendor/faiss/faiss/IndexPQ.cpp +72 -88
- data/vendor/faiss/faiss/IndexPQ.h +1 -4
- data/vendor/faiss/faiss/IndexPQFastScan.cpp +1 -1
- data/vendor/faiss/faiss/IndexPreTransform.cpp +25 -31
- data/vendor/faiss/faiss/IndexRefine.cpp +49 -19
- data/vendor/faiss/faiss/IndexRefine.h +7 -0
- data/vendor/faiss/faiss/IndexReplicas.cpp +23 -26
- data/vendor/faiss/faiss/IndexScalarQuantizer.cpp +22 -16
- data/vendor/faiss/faiss/IndexScalarQuantizer.h +6 -4
- data/vendor/faiss/faiss/IndexShards.cpp +21 -29
- data/vendor/faiss/faiss/IndexShardsIVF.cpp +1 -2
- data/vendor/faiss/faiss/MatrixStats.cpp +17 -32
- data/vendor/faiss/faiss/MatrixStats.h +21 -9
- data/vendor/faiss/faiss/MetaIndexes.cpp +35 -35
- data/vendor/faiss/faiss/VectorTransform.cpp +13 -26
- data/vendor/faiss/faiss/VectorTransform.h +7 -7
- data/vendor/faiss/faiss/clone_index.cpp +15 -10
- data/vendor/faiss/faiss/clone_index.h +3 -0
- data/vendor/faiss/faiss/gpu/GpuCloner.cpp +87 -4
- data/vendor/faiss/faiss/gpu/GpuCloner.h +22 -0
- data/vendor/faiss/faiss/gpu/GpuClonerOptions.h +7 -0
- data/vendor/faiss/faiss/gpu/GpuDistance.h +46 -38
- data/vendor/faiss/faiss/gpu/GpuIndex.h +28 -4
- data/vendor/faiss/faiss/gpu/GpuIndexFlat.h +4 -4
- data/vendor/faiss/faiss/gpu/GpuIndexIVF.h +8 -9
- data/vendor/faiss/faiss/gpu/GpuIndexIVFFlat.h +18 -3
- data/vendor/faiss/faiss/gpu/GpuIndexIVFPQ.h +22 -11
- data/vendor/faiss/faiss/gpu/GpuIndexIVFScalarQuantizer.h +1 -3
- data/vendor/faiss/faiss/gpu/GpuResources.cpp +24 -3
- data/vendor/faiss/faiss/gpu/GpuResources.h +39 -11
- data/vendor/faiss/faiss/gpu/StandardGpuResources.cpp +117 -17
- data/vendor/faiss/faiss/gpu/StandardGpuResources.h +57 -3
- data/vendor/faiss/faiss/gpu/perf/PerfClustering.cpp +1 -1
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexBinaryFlat.cpp +25 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexFlat.cpp +129 -9
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +267 -40
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFPQ.cpp +299 -208
- data/vendor/faiss/faiss/gpu/test/TestGpuMemoryException.cpp +1 -0
- data/vendor/faiss/faiss/gpu/utils/RaftUtils.h +75 -0
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.cpp +3 -1
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.h +5 -5
- data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +1 -1
- data/vendor/faiss/faiss/impl/AuxIndexStructures.h +1 -2
- data/vendor/faiss/faiss/impl/DistanceComputer.h +24 -1
- data/vendor/faiss/faiss/impl/FaissException.h +13 -34
- data/vendor/faiss/faiss/impl/HNSW.cpp +321 -70
- data/vendor/faiss/faiss/impl/HNSW.h +9 -8
- data/vendor/faiss/faiss/impl/IDSelector.h +4 -4
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +3 -1
- data/vendor/faiss/faiss/impl/NNDescent.cpp +29 -19
- data/vendor/faiss/faiss/impl/NSG.h +1 -1
- data/vendor/faiss/faiss/impl/PolysemousTraining.cpp +14 -12
- data/vendor/faiss/faiss/impl/ProductAdditiveQuantizer.h +1 -1
- data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +24 -22
- data/vendor/faiss/faiss/impl/ProductQuantizer.h +1 -1
- data/vendor/faiss/faiss/impl/Quantizer.h +1 -1
- data/vendor/faiss/faiss/impl/ResidualQuantizer.cpp +27 -1015
- data/vendor/faiss/faiss/impl/ResidualQuantizer.h +5 -63
- data/vendor/faiss/faiss/impl/ResultHandler.h +232 -176
- data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +444 -104
- data/vendor/faiss/faiss/impl/ScalarQuantizer.h +0 -8
- data/vendor/faiss/faiss/impl/code_distance/code_distance-avx2.h +280 -42
- data/vendor/faiss/faiss/impl/code_distance/code_distance-generic.h +21 -14
- data/vendor/faiss/faiss/impl/code_distance/code_distance.h +22 -12
- data/vendor/faiss/faiss/impl/index_read.cpp +45 -19
- data/vendor/faiss/faiss/impl/index_write.cpp +60 -41
- data/vendor/faiss/faiss/impl/io.cpp +10 -10
- data/vendor/faiss/faiss/impl/lattice_Zn.cpp +1 -1
- data/vendor/faiss/faiss/impl/platform_macros.h +18 -1
- data/vendor/faiss/faiss/impl/pq4_fast_scan.cpp +3 -0
- data/vendor/faiss/faiss/impl/pq4_fast_scan.h +7 -6
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_1.cpp +52 -38
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_qbs.cpp +40 -49
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.cpp +960 -0
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.h +176 -0
- data/vendor/faiss/faiss/impl/simd_result_handlers.h +374 -202
- data/vendor/faiss/faiss/index_factory.cpp +10 -7
- data/vendor/faiss/faiss/invlists/DirectMap.cpp +1 -1
- data/vendor/faiss/faiss/invlists/InvertedLists.cpp +27 -9
- data/vendor/faiss/faiss/invlists/InvertedLists.h +12 -3
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +3 -3
- data/vendor/faiss/faiss/python/python_callbacks.cpp +1 -1
- data/vendor/faiss/faiss/utils/Heap.cpp +3 -1
- data/vendor/faiss/faiss/utils/WorkerThread.h +1 -0
- data/vendor/faiss/faiss/utils/distances.cpp +128 -74
- data/vendor/faiss/faiss/utils/distances.h +81 -4
- data/vendor/faiss/faiss/utils/distances_fused/avx512.cpp +5 -5
- data/vendor/faiss/faiss/utils/distances_fused/avx512.h +2 -2
- data/vendor/faiss/faiss/utils/distances_fused/distances_fused.cpp +2 -2
- data/vendor/faiss/faiss/utils/distances_fused/distances_fused.h +1 -1
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based.cpp +5 -5
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based.h +1 -1
- data/vendor/faiss/faiss/utils/distances_simd.cpp +428 -70
- data/vendor/faiss/faiss/utils/fp16-arm.h +29 -0
- data/vendor/faiss/faiss/utils/fp16.h +2 -0
- data/vendor/faiss/faiss/utils/hamming.cpp +162 -110
- data/vendor/faiss/faiss/utils/hamming.h +58 -0
- data/vendor/faiss/faiss/utils/hamming_distance/avx2-inl.h +16 -89
- data/vendor/faiss/faiss/utils/hamming_distance/common.h +1 -0
- data/vendor/faiss/faiss/utils/hamming_distance/generic-inl.h +15 -87
- data/vendor/faiss/faiss/utils/hamming_distance/hamdis-inl.h +57 -0
- data/vendor/faiss/faiss/utils/hamming_distance/neon-inl.h +14 -104
- data/vendor/faiss/faiss/utils/partitioning.cpp +3 -4
- data/vendor/faiss/faiss/utils/prefetch.h +77 -0
- data/vendor/faiss/faiss/utils/quantize_lut.cpp +0 -14
- data/vendor/faiss/faiss/utils/simdlib_avx2.h +0 -6
- data/vendor/faiss/faiss/utils/simdlib_neon.h +72 -77
- data/vendor/faiss/faiss/utils/sorting.cpp +140 -5
- data/vendor/faiss/faiss/utils/sorting.h +27 -0
- data/vendor/faiss/faiss/utils/utils.cpp +112 -6
- data/vendor/faiss/faiss/utils/utils.h +57 -20
- metadata +10 -3
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its 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
|
+
* Copyright (c) 2023, NVIDIA CORPORATION.
|
|
9
|
+
*
|
|
10
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
11
|
+
* you may not use this file except in compliance with the License.
|
|
12
|
+
* You may obtain a copy of the License at
|
|
13
|
+
*
|
|
14
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
* See the License for the specific language governing permissions and
|
|
20
|
+
* limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
#pragma once
|
|
24
|
+
|
|
25
|
+
#include <faiss/MetricType.h>
|
|
26
|
+
#include <faiss/gpu/GpuResources.h>
|
|
27
|
+
#include <faiss/gpu/utils/Tensor.cuh>
|
|
28
|
+
|
|
29
|
+
#include <raft/distance/distance_types.hpp>
|
|
30
|
+
|
|
31
|
+
#pragma GCC visibility push(default)
|
|
32
|
+
namespace faiss {
|
|
33
|
+
namespace gpu {
|
|
34
|
+
|
|
35
|
+
inline raft::distance::DistanceType metricFaissToRaft(
|
|
36
|
+
MetricType metric,
|
|
37
|
+
bool exactDistance) {
|
|
38
|
+
switch (metric) {
|
|
39
|
+
case MetricType::METRIC_INNER_PRODUCT:
|
|
40
|
+
return raft::distance::DistanceType::InnerProduct;
|
|
41
|
+
case MetricType::METRIC_L2:
|
|
42
|
+
return raft::distance::DistanceType::L2Expanded;
|
|
43
|
+
case MetricType::METRIC_L1:
|
|
44
|
+
return raft::distance::DistanceType::L1;
|
|
45
|
+
case MetricType::METRIC_Linf:
|
|
46
|
+
return raft::distance::DistanceType::Linf;
|
|
47
|
+
case MetricType::METRIC_Lp:
|
|
48
|
+
return raft::distance::DistanceType::LpUnexpanded;
|
|
49
|
+
case MetricType::METRIC_Canberra:
|
|
50
|
+
return raft::distance::DistanceType::Canberra;
|
|
51
|
+
case MetricType::METRIC_BrayCurtis:
|
|
52
|
+
return raft::distance::DistanceType::BrayCurtis;
|
|
53
|
+
case MetricType::METRIC_JensenShannon:
|
|
54
|
+
return raft::distance::DistanceType::JensenShannon;
|
|
55
|
+
default:
|
|
56
|
+
RAFT_FAIL("Distance type not supported");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/// Identify matrix rows containing non NaN values. validRows[i] is false if row
|
|
61
|
+
/// i contains a NaN value and true otherwise.
|
|
62
|
+
void validRowIndices(
|
|
63
|
+
GpuResources* res,
|
|
64
|
+
Tensor<float, 2, true>& vecs,
|
|
65
|
+
bool* validRows);
|
|
66
|
+
|
|
67
|
+
/// Filter out matrix rows containing NaN values. The vectors and indices are
|
|
68
|
+
/// updated in-place.
|
|
69
|
+
idx_t inplaceGatherFilteredRows(
|
|
70
|
+
GpuResources* res,
|
|
71
|
+
Tensor<float, 2, true>& vecs,
|
|
72
|
+
Tensor<idx_t, 1, true>& indices);
|
|
73
|
+
} // namespace gpu
|
|
74
|
+
} // namespace faiss
|
|
75
|
+
#pragma GCC visibility pop
|
|
@@ -261,7 +261,7 @@ void AdditiveQuantizer::decode(const uint8_t* code, float* x, size_t n) const {
|
|
|
261
261
|
is_trained, "The additive quantizer is not trained yet.");
|
|
262
262
|
|
|
263
263
|
// standard additive quantizer decoding
|
|
264
|
-
#pragma omp parallel for if (n >
|
|
264
|
+
#pragma omp parallel for if (n > 100)
|
|
265
265
|
for (int64_t i = 0; i < n; i++) {
|
|
266
266
|
BitstringReader bsr(code + i * code_size, code_size);
|
|
267
267
|
float* xi = x + i * d;
|
|
@@ -370,6 +370,8 @@ void AdditiveQuantizer::compute_LUT(
|
|
|
370
370
|
|
|
371
371
|
namespace {
|
|
372
372
|
|
|
373
|
+
/* compute inner products of one query with all centroids, given a look-up
|
|
374
|
+
* table of all inner producst with codebook entries */
|
|
373
375
|
void compute_inner_prod_with_LUT(
|
|
374
376
|
const AdditiveQuantizer& aq,
|
|
375
377
|
const float* LUT,
|
|
@@ -49,11 +49,11 @@ struct AdditiveQuantizer : Quantizer {
|
|
|
49
49
|
/// encode a norm into norm_bits bits
|
|
50
50
|
uint64_t encode_norm(float norm) const;
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
/// encode norm by non-uniform scalar quantization
|
|
53
|
+
uint32_t encode_qcint(float x) const;
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
/// decode norm by non-uniform scalar quantization
|
|
56
|
+
float decode_qcint(uint32_t c) const;
|
|
57
57
|
|
|
58
58
|
/// Encodes how search is performed and how vectors are encoded
|
|
59
59
|
enum Search_type_t {
|
|
@@ -203,4 +203,4 @@ struct AdditiveQuantizer : Quantizer {
|
|
|
203
203
|
virtual ~AdditiveQuantizer();
|
|
204
204
|
};
|
|
205
205
|
|
|
206
|
-
}
|
|
206
|
+
} // namespace faiss
|
|
@@ -230,7 +230,7 @@ bool InterruptCallback::is_interrupted() {
|
|
|
230
230
|
|
|
231
231
|
size_t InterruptCallback::get_period_hint(size_t flops) {
|
|
232
232
|
if (!instance.get()) {
|
|
233
|
-
return
|
|
233
|
+
return (size_t)1 << 30; // never check
|
|
234
234
|
}
|
|
235
235
|
// for 10M flops, it is reasonable to check once every 10 iterations
|
|
236
236
|
return std::max((size_t)10 * 10 * 1000 * 1000 / (flops + 1), (size_t)1);
|
|
@@ -41,7 +41,6 @@ struct RangeSearchResult {
|
|
|
41
41
|
|
|
42
42
|
/// called when lims contains the nb of elements result entries
|
|
43
43
|
/// for each query
|
|
44
|
-
|
|
45
44
|
virtual void do_allocation();
|
|
46
45
|
|
|
47
46
|
virtual ~RangeSearchResult();
|
|
@@ -165,7 +164,7 @@ struct FAISS_API InterruptCallback {
|
|
|
165
164
|
/// set implementation optimized for fast access.
|
|
166
165
|
struct VisitedTable {
|
|
167
166
|
std::vector<uint8_t> visited;
|
|
168
|
-
|
|
167
|
+
uint8_t visno;
|
|
169
168
|
|
|
170
169
|
explicit VisitedTable(int size) : visited(size), visno(1) {}
|
|
171
170
|
|
|
@@ -30,6 +30,29 @@ struct DistanceComputer {
|
|
|
30
30
|
/// compute distance of vector i to current query
|
|
31
31
|
virtual float operator()(idx_t i) = 0;
|
|
32
32
|
|
|
33
|
+
/// compute distances of current query to 4 stored vectors.
|
|
34
|
+
/// certain DistanceComputer implementations may benefit
|
|
35
|
+
/// heavily from this.
|
|
36
|
+
virtual void distances_batch_4(
|
|
37
|
+
const idx_t idx0,
|
|
38
|
+
const idx_t idx1,
|
|
39
|
+
const idx_t idx2,
|
|
40
|
+
const idx_t idx3,
|
|
41
|
+
float& dis0,
|
|
42
|
+
float& dis1,
|
|
43
|
+
float& dis2,
|
|
44
|
+
float& dis3) {
|
|
45
|
+
// compute first, assign next
|
|
46
|
+
const float d0 = this->operator()(idx0);
|
|
47
|
+
const float d1 = this->operator()(idx1);
|
|
48
|
+
const float d2 = this->operator()(idx2);
|
|
49
|
+
const float d3 = this->operator()(idx3);
|
|
50
|
+
dis0 = d0;
|
|
51
|
+
dis1 = d1;
|
|
52
|
+
dis2 = d2;
|
|
53
|
+
dis3 = d3;
|
|
54
|
+
}
|
|
55
|
+
|
|
33
56
|
/// compute distance between two stored vectors
|
|
34
57
|
virtual float symmetric_dis(idx_t i, idx_t j) = 0;
|
|
35
58
|
|
|
@@ -49,7 +72,7 @@ struct FlatCodesDistanceComputer : DistanceComputer {
|
|
|
49
72
|
|
|
50
73
|
FlatCodesDistanceComputer() : codes(nullptr), code_size(0) {}
|
|
51
74
|
|
|
52
|
-
float operator()(idx_t i)
|
|
75
|
+
float operator()(idx_t i) override {
|
|
53
76
|
return distance_to_code(codes + i * code_size);
|
|
54
77
|
}
|
|
55
78
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
/**
|
|
2
3
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
4
|
*
|
|
@@ -40,42 +41,20 @@ class FaissException : public std::exception {
|
|
|
40
41
|
void handleExceptions(
|
|
41
42
|
std::vector<std::pair<int, std::exception_ptr>>& exceptions);
|
|
42
43
|
|
|
43
|
-
/**
|
|
44
|
-
*
|
|
45
|
-
|
|
46
|
-
struct
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
void set(const T* ptr_in) {
|
|
53
|
-
ptr = ptr_in;
|
|
54
|
-
}
|
|
55
|
-
void swap(ScopeDeleter<T>& other) {
|
|
56
|
-
std::swap(ptr, other.ptr);
|
|
57
|
-
}
|
|
58
|
-
~ScopeDeleter() {
|
|
59
|
-
delete[] ptr;
|
|
44
|
+
/** RAII object for a set of possibly transformed vectors (deallocated only if
|
|
45
|
+
* they are indeed transformed)
|
|
46
|
+
*/
|
|
47
|
+
struct TransformedVectors {
|
|
48
|
+
const float* x;
|
|
49
|
+
bool own_x;
|
|
50
|
+
TransformedVectors(const float* x_orig, const float* x) : x(x) {
|
|
51
|
+
own_x = x_orig != x;
|
|
60
52
|
}
|
|
61
|
-
};
|
|
62
53
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
explicit ScopeDeleter1(const T* ptr = nullptr) : ptr(ptr) {}
|
|
68
|
-
void release() {
|
|
69
|
-
ptr = nullptr;
|
|
70
|
-
}
|
|
71
|
-
void set(const T* ptr_in) {
|
|
72
|
-
ptr = ptr_in;
|
|
73
|
-
}
|
|
74
|
-
void swap(ScopeDeleter1<T>& other) {
|
|
75
|
-
std::swap(ptr, other.ptr);
|
|
76
|
-
}
|
|
77
|
-
~ScopeDeleter1() {
|
|
78
|
-
delete ptr;
|
|
54
|
+
~TransformedVectors() {
|
|
55
|
+
if (own_x) {
|
|
56
|
+
delete[] x;
|
|
57
|
+
}
|
|
79
58
|
}
|
|
80
59
|
};
|
|
81
60
|
|