Skip to content

Commit

Permalink
Use per-element pow in polynomial_dfs #40
Browse files Browse the repository at this point in the history
  • Loading branch information
x-mass committed May 13, 2024
1 parent cd52cc0 commit 7f48532
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
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

0 comments on commit 7f48532

Please sign in to comment.