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

less bound checks and only need to check half the elements on symmetric. #108

Closed
Closed
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
14 changes: 8 additions & 6 deletions manta-pay/src/crypto/hash/poseidon/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ where
if !self.is_square() {
return false;
}
for i in 0..self.num_rows() {
for j in 0..self.num_columns() {
if !F::eq(&self.0[i][j], &kronecker_delta(i, j)) {
for (i, element) in self.0.iter().enumerate() {
for (j, inner_element) in element.iter().enumerate() {
if !F::eq(&inner_element, &kronecker_delta(i, j)) {
Comment on lines +130 to +132
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
for (i, element) in self.0.iter().enumerate() {
for (j, inner_element) in element.iter().enumerate() {
if !F::eq(&inner_element, &kronecker_delta(i, j)) {
for (i, element) in self.0.iter().enumerate() {
for (j, inner_element) in element.iter().enumerate() {
if inner_element != &kronecker_delta(i, j) {

return false;
}
}
Expand All @@ -145,9 +145,10 @@ where
if self.num_rows() != self.num_columns() {
return false;
}
for i in 0..self.num_rows() {
for j in 0..self.num_columns() {
if !F::eq(&self.0[i][j], &self.0[j][i]) {
// Check the lower triangle against the upper triangle
for (i, element) in self.0.iter().enumerate() {
for (j, inner_element) in element.iter().enumerate().skip(i + 1) {
if !F::eq(&inner_element, &self.0[j][i]) {
Comment on lines +148 to +151
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Check the lower triangle against the upper triangle
for (i, element) in self.0.iter().enumerate() {
for (j, inner_element) in element.iter().enumerate().skip(i + 1) {
if !F::eq(&inner_element, &self.0[j][i]) {
for (i, element) in self.0.iter().enumerate() {
for (j, inner_element) in element.iter().enumerate().skip(i + 1) {
if inner_element != &self.0[j][i] {

return false;
}
}
Expand Down Expand Up @@ -564,6 +565,7 @@ where
}

/// Returns the kronecker delta of `i` and `j`.
#[inline]
pub fn kronecker_delta<F>(i: usize, j: usize) -> F
where
F: Field,
Expand Down