-
Notifications
You must be signed in to change notification settings - Fork 43
Linalg 4 - Added trait bounded generics as example (not hacspec compliant!) #275
base: master
Are you sure you want to change the base?
Conversation
- Added header comments/description - Added matrix type alias - Added repeat function - Changed identity function to better reflect nalgebra
More specifically: - Indexing - Transposition - Slicing - Scaling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look too bad. See inline comments.
type DimType = usize; | ||
type Dims = (DimType, DimType); | ||
type MatRes<T> = Result<Matrix<T>, u8>; | ||
type ScalRes<T> = Result<T, u8>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the type of generics we would need a lot.
type MatRes<T> = Result<Matrix<T>, u8>; | ||
type ScalRes<T> = Result<T, u8>; | ||
|
||
pub type Matrix<T> = (Dims, Seq<T>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if we could restrict T
here for the translation.
/// Generate a n*m matrix filled with a given scalar. | ||
pub fn repeat<T>(n: DimType, m: DimType, scalar: T) -> Matrix<T> | ||
where | ||
T: hacspec_lib::Integer, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that we need this here. But it would be nice if we could get away without where
clauses.
The question is what is the easiest and tightest bound we could put on T
in general here.
Generalized the linear algebra library using trait bounded generics. This should be seen as an example of how traits could eventually be used in hacspec. Feel free to comment/review.