orion
orion copied to clipboard
Refactor Fixed Point Representation to Use Native Signed Integers
Currently, fixed points in Orion are represented by a struct defined as follows:
FP {
mag: usize,
sign: bool
}
The mag field represents the magnitude, and the sign field indicates the sign of the number, with false being positive and true being negative. This structure was initially chosen because Cairo did not natively support signed integers at the time. Presently, we support four fixed point types: FP16x16, FP8x23, FP32x32, and FP64x64. The last two types were adopted from the Cubit library.
Given that Cairo now natively supports signed integers, we should update our fixed point implementation to use native signed integers instead of the current struct-based approach.
Given the extensive changes required, an initial PR could focus on the FP16x16 implementation. Since the Tensor and NN libraries heavily rely on FP16x16, we can start by introducing a new implementation in the fixed point directory named f16x16. This will allow us to refactor without removing the existing FP16x16 implementation and plan further updates in the Tensor and NN libraries in subsequent PRs.
Hi @raphaelDkhn I would like to work on this
Hola I'm Tobias. I would like to take over this issue. I've already contributed to some projects recently since I just learned Rust and Cairo. I also have experience with js and typescript from web app projects in uni
May I take care of this?
I'd like to work on this issue! I'll refactor the existing FP struct to improve clarity and efficiency while maintaining compatibility with existing fixed-point types (FP16x16, FP8x23, FP32x32, and FP64x64).
My approach will involve:
Exploring the possibility of replacing FP with a more standardized representation now that Cairo supports signed integers. Ensuring backward compatibility with current implementations to avoid breaking changes. Optimizing operations on fixed-point values for improved precision and performance. Writing unit tests to validate correctness across all supported types.