-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathtraining.cpp
More file actions
124 lines (113 loc) · 3.71 KB
/
training.cpp
File metadata and controls
124 lines (113 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* Copyright 2025 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "svs/runtime/training.h"
#include "svs_runtime_utils.h"
#ifdef SVS_RUNTIME_HAVE_LVQ_LEANVEC
#include "training_impl.h"
namespace svs {
namespace runtime {
LeanVecTrainingData::~LeanVecTrainingData() = default;
Status LeanVecTrainingData::build(
LeanVecTrainingData** training_data,
size_t dim,
size_t n,
const float* x,
size_t leanvec_dims
) noexcept {
return runtime_error_wrapper([&] {
const auto data = svs::data::ConstSimpleDataView<float>(x, n, dim);
*training_data =
new LeanVecTrainingDataManager{LeanVecTrainingDataImpl{data, leanvec_dims}};
});
}
Status LeanVecTrainingData::build(
LeanVecTrainingData** training_data,
size_t dim,
size_t n,
const float* x,
size_t n_q,
const float* x_q,
size_t leanvec_dims
) noexcept {
if (n_q == 0 || !x_q) {
return build(training_data, dim, n, x, leanvec_dims);
}
return runtime_error_wrapper([&] {
const auto data = svs::data::ConstSimpleDataView<float>(x, n, dim);
const auto queries = svs::data::ConstSimpleDataView<float>(x_q, n_q, dim);
*training_data = new LeanVecTrainingDataManager{
LeanVecTrainingDataImpl{data, queries, leanvec_dims}};
});
}
Status LeanVecTrainingData::destroy(LeanVecTrainingData* training_data) noexcept {
return runtime_error_wrapper([&] { delete training_data; });
}
Status
LeanVecTrainingData::load(LeanVecTrainingData** training_data, std::istream& in) noexcept {
return runtime_error_wrapper([&] {
*training_data = new LeanVecTrainingDataManager{LeanVecTrainingDataImpl::load(in)};
});
}
} // namespace runtime
} // namespace svs
#else // SVS_RUNTIME_HAVE_LVQ_LEANVEC
namespace svs {
namespace runtime {
LeanVecTrainingData::~LeanVecTrainingData() = default;
Status LeanVecTrainingData::build(
LeanVecTrainingData** SVS_UNUSED(training_data),
size_t SVS_UNUSED(dim),
size_t SVS_UNUSED(n),
const float* SVS_UNUSED(x),
size_t SVS_UNUSED(leanvec_dims)
) noexcept {
return Status(
ErrorCode::NOT_IMPLEMENTED,
"LeanVecTrainingData is not supported in this build configuration."
);
}
Status LeanVecTrainingData::build(
LeanVecTrainingData** SVS_UNUSED(training_data),
size_t SVS_UNUSED(dim),
size_t SVS_UNUSED(n),
const float* SVS_UNUSED(x),
size_t SVS_UNUSED(n_q),
const float* SVS_UNUSED(x_q),
size_t SVS_UNUSED(leanvec_dims)
) noexcept {
return Status(
ErrorCode::NOT_IMPLEMENTED,
"LeanVecTrainingData is not supported in this build configuration."
);
}
Status LeanVecTrainingData::destroy(LeanVecTrainingData* SVS_UNUSED(training_data)
) noexcept {
return Status(
ErrorCode::NOT_IMPLEMENTED,
"LeanVecTrainingData is not supported in this build configuration."
);
}
Status LeanVecTrainingData::load(
LeanVecTrainingData** SVS_UNUSED(training_data), std::istream& SVS_UNUSED(in)
) noexcept {
return Status(
ErrorCode::NOT_IMPLEMENTED,
"LeanVecTrainingData is not supported in this build configuration."
);
}
} // namespace runtime
} // namespace svs
#endif // SVS_RUNTIME_HAVE_LVQ_LEANVEC