Open tarcieri opened 1 year ago
We ended up solving this with a BatchNormalize
trait which is generic around its input type and therefore supports overlapping impls.
This allows the trait to be impl'd for [ProjectivePoint]
and [ProjectivePoint; N]
as inputs, where the former is gated on the alloc
feature, and the latter supporting heapless usage, with the const generics completely disentangled from the trait definition: https://docs.rs/primeorder/0.13.6/primeorder/struct.ProjectivePoint.html#impl-BatchNormalize%3C%5BProjectivePoint%3CC%3E%5D%3E-for-ProjectivePoint%3CC%3E
batch_normalize
currently documents this caveat:However, with const generics you can construct an output array that matches the input size with compile-time assurances:
This issue is to suggest an addition, rather than a replacement, specifically for use cases where the number of points is fixed at compile-time.
Note that this approach is also useful for stack allocating all intermediate values (since you can size the arrays by
N
), allowing for efficient implementations on heapless targets.