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

Add generic FFT implementation over curve scalars #155

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open

Conversation

MatanHamilis
Copy link
Contributor

Added a generic implementation for FFTs.
Further explanation I've written about FFTs and the implemented algorithms can be found here:
https://hackmd.io/@matan/ffts

}
}
}
impl<T: Curve> Iterator for PowerIterator<T> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a size_hint implementation? this will improve the perf of collect by allowing it to preallocate

Comment on lines +40 to +42
if self.next_idx == self.max_idx {
return None;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, you can replace next_idx with remaining_idx and return None when it is equal to zero (that way you save just a single usize and not 2 usizes)

Comment on lines +60 to +69
fn new(factors: &'a [(usize, usize)]) -> FactorizationIterator {
let max = factors
.iter()
.fold(1usize, |acc, (_, count)| acc * (count + 1));
FactorizationIterator {
factorization: factors,
index: 0usize,
max,
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you maybe use more a more descriptive name? what's max? it looks like the product of all the k+1?

Comment on lines +116 to +118
self.slice
.get((self.step * (self.next_index)) % self.slice.len())
.unwrap(),
Copy link
Contributor

Choose a reason for hiding this comment

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

why get and unwrap and not indexing? did it fail due to the self.slice.len()?

.map(|&(f, _)| {
usize::from_be_bytes(
f.to_bytes_array()
.expect("The bit length should fit in 8-byte array here!"),
Copy link
Contributor

Choose a reason for hiding this comment

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

note that usize is 4 bytes on 32bit machines

Scalar::<T>::multiplicative_group_order_factorization()
.iter()
.filter(|(num, _)| num.bit_length() < SMALL_FACTOR_BITLENGTH)
.collect();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can skip the collect, as you're mapping it immediately afterwards, just keep it as an iterator

usize::from_be_bytes(
big_int
.to_bytes_array()
.expect("The small factor should fit in a 8 byte array"),
Copy link
Contributor

Choose a reason for hiding this comment

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

usize is 4 bytes on 32 bit machines

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