Skip to content

Implemented class ADDVerifier#728

Open
unfadingDawn wants to merge 4 commits into
Desbordante:mainfrom
unfadingDawn:implement_add_verifier
Open

Implemented class ADDVerifier#728
unfadingDawn wants to merge 4 commits into
Desbordante:mainfrom
unfadingDawn:implement_add_verifier

Conversation

@unfadingDawn

Copy link
Copy Markdown
Contributor

Implemented class ADDVerifier.
Implemented tests and Python bindings for this class.
Implemented code of the ADD validation example on Python.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Comment thread src/core/algorithms/dd/add_verifier/add_verifier.cpp
@unfadingDawn unfadingDawn force-pushed the implement_add_verifier branch from c1bc49a to cb1e34f Compare April 21, 2026 11:37
@unfadingDawn unfadingDawn force-pushed the implement_add_verifier branch from cb1e34f to 63294a0 Compare April 21, 2026 11:51
@chernishev chernishev assigned py-cyber and unassigned py-cyber May 24, 2026
@chernishev chernishev requested a review from py-cyber May 24, 2026 20:54

@py-cyber py-cyber left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's enough for now, maybe I'll look again later

@@ -0,0 +1,91 @@
#include "core/algorithms/dd/add_verifier/add_verifier.h"

#include "core/algorithms/dd/dd_verifier/dd_verifier.h"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its does not suppose to be here because u have it in header. I write it only because i want u to fix CMakeLists.txt (read about PUBLIC in wiki)

void CheckDFOnRhs(std::vector<std::pair<std::size_t, std::size_t>> const &lhs);
virtual void CheckDFOnRhs(std::vector<std::pair<std::size_t, std::size_t>> const& lhs);

void VerifyDD();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why didn't this virtual?

Comment on lines +29 to +30
void ADDVerifier::CheckDFOnRhs(std::vector<std::pair<std::size_t, std::size_t>> const& lhs) {
double min_dist = -1.;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void ADDVerifier::CheckDFOnRhs(std::vector<std::pair<std::size_t, std::size_t>> const& lhs) {
double min_dist = -1.;
void ADDVerifier::CheckDFOnRhs(std::vector<std::pair<std::size_t, std::size_t>> const& lhs) {
if (lhs.empty()) {
error_ = 0.0; // or 1.0 idk
return;
}
double min_dist = -1.;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

division by zero

Comment on lines +71 to +89
void ADDVerifier::CheckCorrectnessDd() const {
auto check_constraint = [](auto const& constraint) {
if (constraint.constraint.upper_bound < constraint.constraint.lower_bound) {
throw std::invalid_argument("Invalid constraint bounds for column: " +
constraint.column_name);
}
if (constraint.constraint.lower_bound < 0 || constraint.constraint.upper_bound < 0) {
throw std::invalid_argument("Constraint bounds cannot be negative for column: " +
constraint.column_name);
}
};

std::ranges::for_each(dd_.left, check_constraint);
std::ranges::for_each(dd_.right, check_constraint);
if (dd_.right.size() > 1) {
throw std::invalid_argument(
"The RHS of an ADD must have a differential function on a single attribute.");
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i suggest do all exceptions in begins of methods so it will not waste time

Comment on lines +29 to +42
void ADDVerifier::CheckDFOnRhs(std::vector<std::pair<std::size_t, std::size_t>> const& lhs) {
double min_dist = -1.;
for (auto const& pair : lhs) {
auto curr_constraint = dd_.right.cbegin();
for (auto const column_index : rhs_column_indices_) {
double const dif = CalculateDistance(column_index, pair);
if (!curr_constraint->constraint.Contains(dif)) {
highlights_.emplace_back(column_index, pair, dif);
++num_error_rhs_;
}
min_dist = min_dist == -1 ? dif : std::min(min_dist, dif);
++curr_constraint;
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i believe -O3 optimize this but probably u should change

Suggested change
void ADDVerifier::CheckDFOnRhs(std::vector<std::pair<std::size_t, std::size_t>> const& lhs) {
double min_dist = -1.;
for (auto const& pair : lhs) {
auto curr_constraint = dd_.right.cbegin();
for (auto const column_index : rhs_column_indices_) {
double const dif = CalculateDistance(column_index, pair);
if (!curr_constraint->constraint.Contains(dif)) {
highlights_.emplace_back(column_index, pair, dif);
++num_error_rhs_;
}
min_dist = min_dist == -1 ? dif : std::min(min_dist, dif);
++curr_constraint;
}
}
void ADDVerifier::CheckDFOnRhs(std::vector<std::pair<std::size_t, std::size_t>> const& lhs) {
double min_dist = std::numeric_limits<double>::max();
for (auto const& pair : lhs) {
auto curr_constraint = dd_.right.cbegin();
for (auto const column_index : rhs_column_indices_) {
double const dif = CalculateDistance(column_index, pair);
if (!curr_constraint->constraint.Contains(dif)) {
highlights_.emplace_back(column_index, pair, dif);
++num_error_rhs_;
}
min_dist = std::min(min_dist, dif);
++curr_constraint;
}
}

auto curr_constraint = dd_.right.cbegin();
for (auto const column_index : rhs_column_indices_) {
double const dif = CalculateDistance(column_index, pair);
if (dif == min_dist) {

@py-cyber py-cyber May 30, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't know about that, we should compare double like (dif - min_dist < epsilon)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants