120 std::vector<ttk::DiagramType> &DictDiagrams,
121 const std::vector<std::vector<ttk::MatchingType>> &matchings,
123 const std::vector<Matrix> &gradsLists,
124 const std::vector<int> &checkerAtomsExt,
125 std::vector<std::vector<int>> &projForDiag,
127 std::vector<std::array<double, 2>> &projLocations,
128 std::vector<std::vector<double>> &vectorForProjContrib,
129 std::vector<std::vector<std::array<double, 2>>> &pairToAddGradList,
136 std::vector<double> miniBirth(matchings.size());
137 for(
size_t i = 0; i < matchings.size(); ++i) {
138 auto &t = DictDiagrams[i][0];
139 miniBirth[i] = t.birth.sfValue;
142 std::vector<std::vector<std::array<double, 2>>> gradBuffersList(
144 std::vector<std::vector<double>> projectionsBuffer(Barycenter.size());
146 for(
size_t i = 0; i < Barycenter.size(); ++i) {
147 projectionsBuffer[i].resize(matchings.size());
150 for(
size_t i = 0; i < gradBuffersList.size(); ++i) {
151 gradBuffersList[i].resize(matchings.size());
154 std::vector<std::vector<int>> checker(Barycenter.size());
155 for(
size_t i = 0; i < checker.size(); ++i) {
156 checker[i].resize(matchings.size());
158 std::vector<int> tracker(Barycenter.size(), 0);
159 std::vector<std::vector<int>> trackerDiagonal(Barycenter.size());
160 std::vector<std::vector<int>> trackerMatch(Barycenter.size());
161 for(
size_t i = 0; i < trackerDiagonal.size(); ++i) {
162 trackerDiagonal[i].resize(matchings.size());
164 for(
size_t i = 0; i < trackerMatch.size(); ++i) {
165 trackerMatch[i].resize(matchings.size());
168 for(
size_t i = 0; i < matchings.size(); ++i) {
169 for(
size_t j = 0; j < matchings[i].size(); ++j) {
170 const auto &t = matchings[i][j];
175 if(Id2 < 0 ||
static_cast<SimplexId>(gradBuffersList.size()) <= Id2
176 ||
static_cast<SimplexId>(DictDiagrams[i].size()) <= Id1) {
180 const auto &t3 = Barycenter[Id2];
181 auto &point = gradBuffersList[Id2][i];
182 const double birthBarycenter = t3.birth.sfValue;
183 const double deathBarycenter = t3.death.sfValue;
184 const double birthDeathAtom
185 = birthBarycenter + (deathBarycenter - birthBarycenter) / 2.;
186 point[0] = birthDeathAtom;
187 point[1] = birthDeathAtom;
190 trackerMatch[Id2][i] = Id1;
191 trackerDiagonal[Id2][i] = 1;
192 projectionsBuffer[Id2][i] = birthDeathAtom;
195 const auto &t2 = DictDiagrams[i][Id1];
196 auto &point = gradBuffersList[Id2][i];
197 const double birthAtom = t2.birth.sfValue;
198 const double deathAtom = t2.death.sfValue;
199 point[0] = birthAtom;
200 point[1] = deathAtom;
203 trackerMatch[Id2][i] = Id1;
204 trackerDiagonal[Id2][i] = 0;
205 projectionsBuffer[Id2][i] = 0.;
211 gradBuffersList.insert(
212 gradBuffersList.end(), pairToAddGradList.begin(), pairToAddGradList.end());
213 for(
size_t j = 0; j < pairToAddGradList.size(); ++j) {
214 std::vector<int> temp1(matchings.size(), 1);
215 std::vector<int> temp2(matchings.size(), -1);
216 std::vector<int> temp3(matchings.size());
217 for(
size_t l = 0; l < matchings.size(); ++l) {
218 temp3[l] =
static_cast<int>(l);
220 trackerDiagonal.push_back(temp1);
221 trackerMatch.push_back(temp1);
222 checker.push_back(temp3);
223 tracker.push_back(1);
226 for(
size_t i = 0; i < gradBuffersList.size(); ++i) {
227 if(tracker[i] == 0 || checkerAtomsExt[i] == 0) {
232 std::vector<double> pos(gradBuffersList[i].size(), 0.);
233 for(
size_t j = 0; j < checker[i].size(); ++j) {
234 auto &t = gradBuffersList[i][checker[i][j]];
237 pos[j] = death - birth;
239 std::vector<bool> pos2(pos.size(),
false);
240 std::vector<double> temp2;
241 for(
size_t p = 0; p < checker[i].size(); ++p) {
242 auto &t = gradBuffersList[i][checker[i][p]];
244 pos2[p] = birth == 0.;
246 temp2.push_back(birth);
249 for(
size_t p = 0; p < checker[i].size(); ++p) {
252 auto &t = gradBuffersList[i][checker[i][p]];
254 t[1] = t[1] - (this->
stepAtom_) * gradsLists[i][checker[i][p]][1];
255 }
else if(pos[p] < 1e-7) {
259 auto &t0 = gradBuffersList[i][checker[i][p]];
261 t0[0] = t0[0] - (this->
stepAtom_) * gradsLists[i][checker[i][p]][0];
262 t0[1] = t0[1] - (this->
stepAtom_) * gradsLists[i][checker[i][p]][1];
272 for(
size_t i = 0; i < checker.size(); ++i) {
273 if(tracker[i] == 0 || checkerAtomsExt[i] == 0) {
276 if(i < Barycenter.size()) {
277 for(
size_t j = 0; j < checker[i].size(); ++j) {
278 auto &trackerTemp = trackerMatch[i][j];
279 if(trackerDiagonal[i][j] == 1 || trackerTemp == -1
280 || trackerTemp > 10000) {
281 std::vector<int> projAndIndex(DictDiagrams.size() + 1);
282 for(
size_t m = 0; m < DictDiagrams.size(); ++m) {
283 projAndIndex[m] = trackerMatch[i][m];
287 auto &index = checker[i][j];
288 auto &t2 = gradBuffersList[i][index];
290 auto &t1 = DictDiagrams[index][trackerTemp];
292 if(t2[0] < miniBirth[index]) {
293 t1.birth.sfValue = miniBirth[index];
295 t1.birth.sfValue = t2[0];
298 t1.birth.sfValue = t2[0];
299 t1.death.sfValue = t2[0];
301 t1.death.sfValue = t2[1];
306 const auto &infos = infoToAdd[
static_cast<int>(i)
307 -
static_cast<int>(Barycenter.size())];
309 for(
size_t j = 0; j < checker[i].size(); ++j) {
310 auto &trackerTemp = trackerMatch[i][j];
311 if(trackerDiagonal[i][j] == 1 || trackerTemp == -1
312 || trackerTemp > 10000) {
313 auto &index = checker[i][j];
314 std::vector<int> projAndIndex(DictDiagrams.size() + 1);
315 int atomIndex =
static_cast<int>(index);
316 for(
size_t m = 0; m < DictDiagrams.size(); ++m) {
317 projAndIndex[m] = trackerMatch[i][m];
319 projAndIndex[DictDiagrams.size()] = atomIndex;
320 projForDiag.push_back(projAndIndex);
321 featuresToAdd.push_back(infos);
322 projLocations.push_back(gradBuffersList[i][index]);
323 vectorForProjContrib.push_back(gradsLists[i][index]);
325 auto &index = checker[i][j];
326 auto &t2 = gradBuffersList[i][index];
327 auto &t1 = DictDiagrams[index][trackerTemp];
328 if(t2[0] < miniBirth[index]) {
329 t1.birth.sfValue = miniBirth[index];
331 t1.birth.sfValue = t2[0];
334 t1.birth.sfValue = t2[0];
335 t1.death.sfValue = t2[0];
337 t1.death.sfValue = t2[1];