Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use field element pow func inside DFS polynomial pow #86

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/nil/crypto3/math/detail/field_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ namespace nil {
n |= n >> 4;
n |= n >> 8;
n |= n >> 16;
n |= n >> 32;
n++;

return n;
Expand Down
33 changes: 17 additions & 16 deletions include/nil/crypto3/math/polynomial/polynomial_dfs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,24 +636,21 @@ namespace nil {
}

polynomial_dfs pow(size_t power) const {
polynomial_dfs result = *this;

if (power == 1) {
return *this;
return result;
}

polynomial_dfs power_of_2 = *this;
size_t expected_size = detail::power_of_two(
std::max({this->size(), this->degree() * power + 1}));
power_of_2.resize(expected_size);
polynomial_dfs result(0, expected_size, FieldValueType::one());
while (power) {
if (power % 2 == 1) {
result *= power_of_2;
}
power /= 2;
if (power == 0)
break;
power_of_2 *= power_of_2;
result.resize(expected_size);
result._d = _d * power;

for (std::size_t i = 0; i < result.size(); ++i) {
result[i] = result[i].pow(power);
}

return result;
}

Expand Down Expand Up @@ -753,10 +750,14 @@ namespace nil {
} else {
os << "[Polynomial DFS, size " << poly.size()
<< " degree " << poly.degree() << " values ";
for( auto it = poly.begin(); it != poly.end(); it++ ){
os << "0x" << std::hex << it->data << ", ";
os << std::hex;
for(auto it = poly.begin(); it != poly.end(); ++it) {
os << "0x" << it->data;
if (it != std::prev(poly.end())) {
os << ", ";
}
}
os << "]";
os << std::dec << "]";
}
return os;
}
Expand Down Expand Up @@ -784,7 +785,7 @@ namespace nil {
needed_domain_sizes.push_back(i);
// On the next line I want to create the tree structure, then create the evaluation domains.
// This way filling of this structure can be done in parallel.
domain_cache[i] = nullptr;
domain_cache[i] = nullptr;
}

// This loop will run in parallel.
Expand Down
Loading